click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r794701 - /incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java
Date Thu, 16 Jul 2009 14:51:22 GMT
Author: sabob
Date: Thu Jul 16 14:51:22 2009
New Revision: 794701

URL: http://svn.apache.org/viewvc?rev=794701&view=rev
Log:
promoted method #getPageClass to protected and refactored isJsp to be more generic

Modified:
    incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java

Modified: incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java?rev=794701&r1=794700&r2=794701&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java
(original)
+++ incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java
Thu Jul 16 14:51:22 2009
@@ -393,8 +393,15 @@
      * @return true if JSP exists for the given ".htm" path
      */
     public boolean isJspPage(String path) {
-        String jspPath = StringUtils.replace(path, ".htm", ".jsp");
-        return pageByPathMap.containsKey(jspPath);
+        HtmlStringBuffer buffer = new HtmlStringBuffer();
+        int index = StringUtils.lastIndexOf(path, ".");
+        if (index > 0) {
+            buffer.append(path.substring(0, index));
+        } else {
+            buffer.append(path);
+        }
+        buffer.append(".jsp");
+        return pageByPathMap.containsKey(buffer.toString());
     }
 
     /**
@@ -663,7 +670,125 @@
         }
     }
 
-    // -------------------------------------------------------- Package Private Methods
+    // ------------------------------------------------------ Protected Methods
+
+    /**
+     * Find and return the page class for the specified pagePath and
+     * pagesPackage.
+     * <p/>
+     * For example if the pagePath is <tt>'/edit-customer.htm'</tt> and
+     * package is <tt>'com.mycorp'</tt>, the matching page class will be:
+     * <tt>com.mycorp.EditCustomer</tt> or <tt>com.mycorp.EditCustomerPage</tt>.
+     * <p/>
+     * If the page path is <tt>'/admin/add-customer.htm'</tt> and package is
+     * <tt>'com.mycorp'</tt>, the matching page class will be:
+     * <tt>com.mycorp.admin.AddCustomer</tt> or
+     * <tt>com.mycorp.admin.AddCustomerPage</tt>.
+     *
+     * @param pagePath the path used for matching against a page class name
+     * @param pagesPackage the package of the page class
+     * @return the page class for the specified pagePath and pagesPackage
+     */
+    protected Class getPageClass(String pagePath, String pagesPackage) {
+        // To understand this method lets walk through an example as the
+        // code plays out. Imagine this method is called with the arguments:
+        // pagePath='/pages/edit-customer.htm'
+        // pagesPackage='org.apache.click'
+
+        // Add period at end.
+        // packageName = 'org.apache.click.'
+        String packageName = pagesPackage + ".";
+        String className = "";
+
+        // Strip off extension.
+        // path = '/pages/edit-customer'
+        String path = pagePath.substring(0, pagePath.lastIndexOf("."));
+
+        // If page is excluded return the excluded class
+        Class excludePageClass = getExcludesPageClass(path);
+        if (excludePageClass != null) {
+            return excludePageClass;
+        }
+
+        // Build complete packageName.
+        // packageName = 'org.apache.click.pages.'
+        // className = 'edit-customer'
+        if (path.indexOf("/") != -1) {
+            StringTokenizer tokenizer = new StringTokenizer(path, "/");
+            while (tokenizer.hasMoreTokens()) {
+                String token = tokenizer.nextToken();
+                if (tokenizer.hasMoreTokens()) {
+                    packageName = packageName + token + ".";
+                } else {
+                    className = token;
+                }
+            }
+        } else {
+            className = path;
+        }
+
+        // CamelCase className.
+        // className = 'EditCustomer'
+        StringTokenizer tokenizer = new StringTokenizer(className, "_-");
+        className = "";
+        while (tokenizer.hasMoreTokens()) {
+            String token = tokenizer.nextToken();
+            token = Character.toUpperCase(token.charAt(0)) + token.substring(1);
+            className += token;
+        }
+
+        // className = 'org.apache.click.pages.EditCustomer'
+        className = packageName + className;
+
+        Class pageClass = null;
+        try {
+            // Attempt to load class.
+            pageClass = ClickUtils.classForName(className);
+
+            if (!Page.class.isAssignableFrom(pageClass)) {
+                String msg = "Automapped page class " + className
+                             + " is not a subclass of org.apache.click.Page";
+                throw new RuntimeException(msg);
+            }
+
+        } catch (ClassNotFoundException cnfe) {
+
+            boolean classFound = false;
+
+            // Append "Page" to className and attempt to load class again.
+            // className = 'org.apache.click.pages.EditCustomerPage'
+            if (!className.endsWith("Page")) {
+                String classNameWithPage = className + "Page";
+                try {
+                    // Attempt to load class.
+                    pageClass = ClickUtils.classForName(classNameWithPage);
+
+                    if (!Page.class.isAssignableFrom(pageClass)) {
+                        String msg = "Automapped page class " + classNameWithPage
+                                     + " is not a subclass of org.apache.click.Page";
+                        throw new RuntimeException(msg);
+                    }
+
+                    classFound = true;
+
+                } catch (ClassNotFoundException cnfe2) {
+                }
+            }
+
+            if (!classFound) {
+                if (logService.isDebugEnabled()) {
+                    logService.debug(pagePath + " -> CLASS NOT FOUND");
+                }
+                if (logService.isTraceEnabled()) {
+                    logService.trace("class not found: " + className);
+                }
+            }
+        }
+
+        return pageClass;
+    }
+
+    // ------------------------------------------------ Package Private Methods
 
     /**
      * Loads all Click Pages defined in the <tt>click.xml</tt> file, including
@@ -925,122 +1050,6 @@
         return headersMap;
     }
 
-    /**
-     * Find and return the page class for the specified pagePath and
-     * pagesPackage.
-     * <p/>
-     * For example if the pagePath is <tt>'/edit-customer.htm'</tt> and
-     * package is <tt>'com.mycorp'</tt>, the matching page class will be:
-     * <tt>com.mycorp.EditCustomer</tt> or <tt>com.mycorp.EditCustomerPage</tt>.
-     * <p/>
-     * If the page path is <tt>'/admin/add-customer.htm'</tt> and package is
-     * <tt>'com.mycorp'</tt>, the matching page class will be:
-     * <tt>com.mycorp.admin.AddCustomer</tt> or
-     * <tt>com.mycorp.admin.AddCustomerPage</tt>.
-     *
-     * @param pagePath the path used for matching against a page class name
-     * @param pagesPackage the package of the page class
-     * @return the page class for the specified pagePath and pagesPackage
-     */
-    Class getPageClass(String pagePath, String pagesPackage) {
-        // To understand this method lets walk through an example as the
-        // code plays out. Imagine this method is called with the arguments:
-        // pagePath='/pages/edit-customer.htm'
-        // pagesPackage='org.apache.click'
-
-        // Add period at end.
-        // packageName = 'org.apache.click.'
-        String packageName = pagesPackage + ".";
-        String className = "";
-
-        // Strip off extension.
-        // path = '/pages/edit-customer'
-        String path = pagePath.substring(0, pagePath.lastIndexOf("."));
-
-        // If page is excluded return the excluded class
-        Class excludePageClass = getExcludesPageClass(path);
-        if (excludePageClass != null) {
-            return excludePageClass;
-        }
-
-        // Build complete packageName.
-        // packageName = 'org.apache.click.pages.'
-        // className = 'edit-customer'
-        if (path.indexOf("/") != -1) {
-            StringTokenizer tokenizer = new StringTokenizer(path, "/");
-            while (tokenizer.hasMoreTokens()) {
-                String token = tokenizer.nextToken();
-                if (tokenizer.hasMoreTokens()) {
-                    packageName = packageName + token + ".";
-                } else {
-                    className = token;
-                }
-            }
-        } else {
-            className = path;
-        }
-
-        // CamelCase className.
-        // className = 'EditCustomer'
-        StringTokenizer tokenizer = new StringTokenizer(className, "_-");
-        className = "";
-        while (tokenizer.hasMoreTokens()) {
-            String token = tokenizer.nextToken();
-            token = Character.toUpperCase(token.charAt(0)) + token.substring(1);
-            className += token;
-        }
-
-        // className = 'org.apache.click.pages.EditCustomer'
-        className = packageName + className;
-
-        Class pageClass = null;
-        try {
-            // Attempt to load class.
-            pageClass = ClickUtils.classForName(className);
-
-            if (!Page.class.isAssignableFrom(pageClass)) {
-                String msg = "Automapped page class " + className
-                             + " is not a subclass of org.apache.click.Page";
-                throw new RuntimeException(msg);
-            }
-
-        } catch (ClassNotFoundException cnfe) {
-
-            boolean classFound = false;
-
-            // Append "Page" to className and attempt to load class again.
-            // className = 'org.apache.click.pages.EditCustomerPage'
-            if (!className.endsWith("Page")) {
-                String classNameWithPage = className + "Page";
-                try {
-                    // Attempt to load class.
-                    pageClass = ClickUtils.classForName(classNameWithPage);
-
-                    if (!Page.class.isAssignableFrom(pageClass)) {
-                        String msg = "Automapped page class " + classNameWithPage
-                                     + " is not a subclass of org.apache.click.Page";
-                        throw new RuntimeException(msg);
-                    }
-
-                    classFound = true;
-
-                } catch (ClassNotFoundException cnfe2) {
-                }
-            }
-
-            if (!classFound) {
-                if (logService.isDebugEnabled()) {
-                    logService.debug(pagePath + " -> CLASS NOT FOUND");
-                }
-                if (logService.isTraceEnabled()) {
-                    logService.trace("class not found: " + className);
-                }
-            }
-        }
-
-        return pageClass;
-    }
-
     // -------------------------------------------------------- Private Methods
 
     private Element getResourceRootElement(String path) throws IOException {



Mime
View raw message