You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2009/06/15 09:38:09 UTC

svn commit: r784676 - /myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java

Author: lofwyr
Date: Mon Jun 15 07:38:09 2009
New Revision: 784676

URL: http://svn.apache.org/viewvc?rev=784676&view=rev
Log:
Refactorings
 * merge doublicated code into a method
 * add @Override annotation
 * enhance log debug messages

Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java?rev=784676&r1=784675&r2=784676&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java Mon Jun 15 07:38:09 2009
@@ -75,8 +75,7 @@
     return getImage(viewRoot, name, false);
   }
 
-  public String getImage(UIViewRoot viewRoot, String name,
-      boolean ignoreMissing) {
+  public String getImage(UIViewRoot viewRoot, String name, boolean ignoreMissing) {
     String result = null;
     if (name != null) {
       int dot = name.lastIndexOf('.');
@@ -178,10 +177,10 @@
     return result;
   }
 
-  private List getPaths(ClientProperties clientProperties, Locale locale, String prefix,
-      String subDir, String name, String suffix,
-      boolean reverseOrder, boolean single, boolean returnKey,
-      String key, boolean returnStrings, boolean ignoreMissing) {
+  private List getPaths(
+      ClientProperties clientProperties, Locale locale, String prefix, String subDir, String name, String suffix,
+      boolean reverseOrder, boolean single, boolean returnKey, String key, boolean returnStrings,
+      boolean ignoreMissing) {
     List matches = new ArrayList();
     String contentType = clientProperties.getContentType();
     Theme theme = clientProperties.getTheme();
@@ -204,33 +203,8 @@
                 localeSuffix,
                 suffix,
                 key);
-            if (LOG.isDebugEnabled()) {
-              LOG.debug("testing path: " + path);
-            }
-            if (returnStrings && resourceList.containsKey(path)) {
-              String result =
-                  returnKey
-                      ? prefix + path
-                      : prefix + resourceList.get(path);
-
-              if (reverseOrder) {
-                matches.add(0, result);
-              } else {
-                matches.add(result);
-              }
-
-              if (single) {
-                return matches;
-              }
-            } else if (!returnStrings) {
-              try {
-                path = path.substring(1).replace('/', '.');
-                Class clazz = Class.forName(path);
-                matches.add(clazz);
-                return matches;
-              } catch (ClassNotFoundException e) {
-                // not found
-              }
+            if (checkPath(prefix, reverseOrder, single, returnKey, returnStrings, matches, path)) {
+              return matches;
             }
           }
         }
@@ -238,33 +212,8 @@
     }
     for (String localeSuffix : locales) { // locale loop
       path = makePath(name, localeSuffix, suffix, key);
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("testing path: " + path);
-      }
-      if (returnStrings && resourceList.containsKey(path)) {
-        String result =
-            returnKey
-                ? prefix + path
-                : prefix + resourceList.get(path);
-
-        if (reverseOrder) {
-          matches.add(0, result);
-        } else {
-          matches.add(result);
-        }
-
-        if (single) {
-          return matches;
-        }
-      } else if (!returnStrings) {
-        try {
-          path = path.substring(1).replace('/', '.');
-          Class clazz = Class.forName(path);
-          matches.add(clazz);
-          return matches;
-        } catch (ClassNotFoundException e) {
-          // not found
-        }
+      if (checkPath(prefix, reverseOrder, single, returnKey, returnStrings, matches, path)) {
+        return matches;
       }
     }
     if (matches.isEmpty()) {
@@ -286,10 +235,53 @@
     }
   }
 
-  private String makePath(String project,
-      String language, Theme theme, String browser,
-      String subDir, String name, String localeSuffix, String extension,
-      String key) {
+  private boolean checkPath(
+      String prefix, boolean reverseOrder, boolean single, boolean returnKey, boolean returnStrings,
+      List matches, String path) {
+    if (returnStrings && resourceList.containsKey(path)) {
+      String result =
+          returnKey
+              ? prefix + path
+              : prefix + resourceList.get(path);
+
+      if (reverseOrder) {
+        matches.add(0, result);
+      } else {
+        matches.add(result);
+      }
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("testing path: " + path + " *"); // match
+      }
+
+      if (single) {
+        return true;
+      }
+    } else if (!returnStrings) {
+      try {
+        path = path.substring(1).replace('/', '.');
+        Class clazz = Class.forName(path);
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("testing path: " + path + " *"); // match
+        }
+        matches.add(clazz);
+        return true;
+      } catch (ClassNotFoundException e) {
+        // not found
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("testing path: " + path); // no match
+        }
+      }
+    } else {
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("testing path: " + path); // no match
+      }
+    }
+    return false;
+  }
+
+  private String makePath(
+      String project, String language, Theme theme, String browser,
+      String subDir, String name, String localeSuffix, String extension, String key) {
     StringBuilder searchtext = new StringBuilder(64);
 
     searchtext.append('/');
@@ -416,8 +408,7 @@
     return result;
   }
 
-  public String getThemeProperty(UIViewRoot viewRoot,
-      String bundle, String propertyKey) {
+  public String getThemeProperty(UIViewRoot viewRoot, String bundle, String propertyKey) {
     String result = null;
     if (bundle != null && propertyKey != null) {
       CacheKey key = getCacheKey(viewRoot);
@@ -455,6 +446,7 @@
       hashCode = calcHashCode();
     }
 
+    @Override
     public boolean equals(Object o) {
       if (this == o) {
         return true;
@@ -476,6 +468,7 @@
       return result;
     }
 
+    @Override
     public int hashCode() {
       return hashCode;
     }
@@ -492,6 +485,7 @@
       hashCode = calcHashCode();
     }
 
+    @Override
     public boolean equals(Object o) {
       if (this == o) {
         return true;
@@ -513,6 +507,7 @@
       return result;
     }
 
+    @Override
     public int hashCode() {
       return hashCode;
     }
@@ -531,6 +526,7 @@
       hashCode = calcHashCode();
     }
 
+    @Override
     public boolean equals(Object o) {
       if (this == o) {
         return true;
@@ -553,6 +549,7 @@
       return result;
     }
 
+    @Override
     public int hashCode() {
       return hashCode;
     }
@@ -569,6 +566,7 @@
       hashCode = calcHashCode();
     }
 
+    @Override
     public boolean equals(Object o) {
       if (this == o) {
         return true;
@@ -590,6 +588,7 @@
       return result;
     }
 
+    @Override
     public int hashCode() {
       return hashCode;
     }
@@ -606,6 +605,7 @@
       hashCode = calcHashCode();
     }
 
+    @Override
     public boolean equals(Object o) {
       if (this == o) {
         return true;
@@ -627,6 +627,7 @@
       return result;
     }
 
+    @Override
     public int hashCode() {
       return hashCode;
     }
@@ -659,6 +660,7 @@
       return locale;
     }
 
+    @Override
     public boolean equals(Object o) {
       if (this == o) {
         return true;
@@ -680,9 +682,9 @@
       return result;
     }
 
+    @Override
     public int hashCode() {
       return hashCode;
     }
   }
 }
-