click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r786550 - /incubator/click/trunk/click/framework/src/org/apache/click/util/PageImports.java
Date Fri, 19 Jun 2009 15:36:22 GMT
Author: sabob
Date: Fri Jun 19 15:36:22 2009
New Revision: 786550

URL: http://svn.apache.org/viewvc?rev=786550&view=rev
Log:
fixed PageImports to remove version indicator from src and href attributes. The version indicator
is set on the ResourceElement itself

Modified:
    incubator/click/trunk/click/framework/src/org/apache/click/util/PageImports.java

Modified: incubator/click/trunk/click/framework/src/org/apache/click/util/PageImports.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/util/PageImports.java?rev=786550&r1=786549&r2=786550&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/org/apache/click/util/PageImports.java (original)
+++ incubator/click/trunk/click/framework/src/org/apache/click/util/PageImports.java Fri Jun
19 15:36:22 2009
@@ -35,6 +35,7 @@
 import org.apache.click.element.Element;
 import org.apache.click.element.JsImport;
 import org.apache.click.element.JsScript;
+import org.apache.click.element.ResourceElement;
 import org.apache.click.service.LogService;
 
 import org.apache.commons.lang.StringUtils;
@@ -197,6 +198,10 @@
             String line = lines[i].trim().toLowerCase();
             if (line.startsWith("<link") && line.indexOf("text/css") != -1) {
                 CssImport cssImport = asCssImport(lines[i]);
+
+                // Remove Click's version indicator from src attribute
+                removeVersionIndicator(cssImport, "href");
+
                 add(cssImport);
 
             } else if (line.startsWith("<style") && line.indexOf("text/css") !=
-1) {
@@ -207,6 +212,9 @@
             } else if (line.startsWith("<script")) {
                 if (line.indexOf(" src=") != -1) {
                     JsImport jsImport = asJsImport(lines[i]);
+
+                    // Remove Click's version indicator from src attribute
+                    removeVersionIndicator(jsImport, "src");
                     add(jsImport);
 
                 } else {
@@ -814,4 +822,48 @@
             element.setId(Integer.toString(hash));
         }
     }
+
+    /**
+     * Removes all occurrences of a substring from within the source string.
+     *
+     * @deprecated use {@link org.apache.click.element.Element)} instead
+     *
+     * @param source the source String to search
+     * @param remove the string to remove
+     * @return the substring with the string removed if found
+     */
+    private String remove(String source, String remove) {
+        int start = source.lastIndexOf(remove);
+        if (start == -1) {
+            return source;
+        }
+        int end = start + remove.length();
+        HtmlStringBuffer buffer = new HtmlStringBuffer(source.length());
+        buffer.append(source.substring(0, start));
+        buffer.append(source.substring(end));
+        return buffer.toString();
+    }
+
+    /**
+     * Remove Click's version indicator from the attribute of the given element.
+     *
+     * @deprecated use {@link org.apache.click.element.Element)} instead
+     *
+     * @param element the element
+     * @param attribute the attribute to remove the version indicator from
+     */
+    private void removeVersionIndicator(ResourceElement element, String attribute) {
+        String value = element.getAttribute(attribute);
+
+        // Store current length of value before removing version indicator
+        int length = value.length();
+
+        value = remove(value, ClickUtils.RESOURCE_VERSION_INDICATOR);
+
+        // Check if Click version indicator was removed from value
+        if (value.length() != length) {
+            element.setAttribute(attribute, value);
+            element.setVersionIndicator(ClickUtils.RESOURCE_VERSION_INDICATOR);
+        }
+    }
 }



Mime
View raw message