You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2009/06/19 17:32:32 UTC

svn commit: r786547 - in /incubator/click/trunk/click/framework/src/org/apache/click/element: CssImport.java JsImport.java ResourceElement.java

Author: sabob
Date: Fri Jun 19 15:32:32 2009
New Revision: 786547

URL: http://svn.apache.org/viewvc?rev=786547&view=rev
Log:
fixed elements to render version indicator instead of adding the indicator to their attributes as this leads to multiple indicators applied in stateful pages

Modified:
    incubator/click/trunk/click/framework/src/org/apache/click/element/CssImport.java
    incubator/click/trunk/click/framework/src/org/apache/click/element/JsImport.java
    incubator/click/trunk/click/framework/src/org/apache/click/element/ResourceElement.java

Modified: incubator/click/trunk/click/framework/src/org/apache/click/element/CssImport.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/element/CssImport.java?rev=786547&r1=786546&r2=786547&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/org/apache/click/element/CssImport.java (original)
+++ incubator/click/trunk/click/framework/src/org/apache/click/element/CssImport.java Fri Jun 19 15:32:32 2009
@@ -153,7 +153,8 @@
     }
 
     /**
-     * Sets the <tt>href</tt> attribute.
+     * Sets the <tt>href</tt> attribute. If the given href argument is
+     * <tt>null</tt>, the <tt>href</tt> attribute will be removed.
      * <p/>
      * If the given <tt>href</tt> begins with a <tt class="wr">"/"</tt> character
      * the href will be prefixed with the web applications <tt>context path</tt>.
@@ -201,16 +202,23 @@
      * @param buffer the buffer to render output to
      */
     public void render(HtmlStringBuffer buffer) {
-        // Add version indicator to the href
-        setHref(addVersionIndicator(getHref()));
-
         renderConditionalCommentPrefix(buffer);
 
         buffer.elementStart(getTag());
 
         buffer.appendAttribute("id", getId());
+
+        String href = getHref();
+        renderResourcePath(buffer, "href", href);
+
+        // Temporarily remove href attribute while other attributes are rendered
+        setAttribute("href", null);
+
         appendAttributes(buffer);
 
+        // Restore href attribute
+        setAttribute("href", href);
+
         buffer.elementEnd();
 
         renderConditionalCommentSuffix(buffer);

Modified: incubator/click/trunk/click/framework/src/org/apache/click/element/JsImport.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/element/JsImport.java?rev=786547&r1=786546&r2=786547&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/org/apache/click/element/JsImport.java (original)
+++ incubator/click/trunk/click/framework/src/org/apache/click/element/JsImport.java Fri Jun 19 15:32:32 2009
@@ -152,10 +152,11 @@
     }
 
     /**
-     * Sets the <tt>src</tt> attribute.
+     * Sets the <tt>src</tt> attribute. If the given src argument is
+     * <tt>null</tt>, the <tt>src</tt> attribute will be removed.
      * <p/>
      * If the given <tt>src</tt> begins with a <tt class="wr">"/"</tt> character
-     * the sr will be prefixed with the web application <tt>context path</tt>.
+     * the src will be prefixed with the web application <tt>context path</tt>.
      * Note if the given src is already prefixed with the <tt>context path</tt>,
      * Click won't add it a second time.
      *
@@ -200,16 +201,23 @@
      * @param buffer the buffer to render output to
      */
     public void render(HtmlStringBuffer buffer) {
-        // Add version indicator to the href
-        setSrc(addVersionIndicator(getSrc()));
-
         renderConditionalCommentPrefix(buffer);
 
         buffer.elementStart(getTag());
 
         buffer.appendAttribute("id", getId());
+
+        String src = getSrc();
+        renderResourcePath(buffer, "src", src);
+
+        // Temporarily remove src attribute while other attributes are rendered
+        setAttribute("src", null);
+
         appendAttributes(buffer);
 
+        // Restore src attribute
+        setAttribute("src", src);
+
         buffer.closeTag();
 
         buffer.elementEnd(getTag());

Modified: incubator/click/trunk/click/framework/src/org/apache/click/element/ResourceElement.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/element/ResourceElement.java?rev=786547&r1=786546&r2=786547&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/org/apache/click/element/ResourceElement.java (original)
+++ incubator/click/trunk/click/framework/src/org/apache/click/element/ResourceElement.java Fri Jun 19 15:32:32 2009
@@ -297,31 +297,44 @@
     // ------------------------------------------------ Package Private Methods
 
     /**
-     * Add the {@link #getApplicationResourceVersionIndicator(org.apache.click.Context)}
-     * to the specified resourcePath. If the version indicator is not defined
-     * this method will return the resourcePath unchanged.
+     * Render the given attribute and resourcePath and append the
+     * {@link #getVersionIndicator()} to the resourcePath, if it was set.
+     * If the version indicator is not defined this method will only render the
+     * resourcePath.
      *
-     * @param resourcePath the resource path to add the version indicator to
+     * @param buffer the buffer to render to
+     * @param attribute the attribute name to render
+     * @param resourcePath the resource path to render
      */
-    String addVersionIndicator(String resourcePath) {
+    void renderResourcePath(HtmlStringBuffer buffer, String attribute,
+        String resourcePath) {
         String versionIndicator = getVersionIndicator();
 
-        // If no resourcePath or version indicator is defined, exit early
-        if (resourcePath == null || StringUtils.isBlank(versionIndicator)) {
-            return resourcePath;
+        // If resourcePath is null exit early
+        if (resourcePath == null) {
+            return;
         }
 
+        // If version indicator is not defined render resource path only
+        if (StringUtils.isBlank(versionIndicator)) {
+            buffer.appendAttribute(attribute, resourcePath);
+            return;
+        }
+
+        // If the resourcePath has no extension render the resource path only
         int start = resourcePath.lastIndexOf(".");
-        // Exit early if extension is not found
         if (start < 0) {
-            return resourcePath;
+            buffer.appendAttribute(attribute, resourcePath);
+            return;
         }
 
-        HtmlStringBuffer buffer = new HtmlStringBuffer();
+        buffer.append(" ");
+        buffer.append(attribute);
+        buffer.append("=\"");
         buffer.append(resourcePath.substring(0, start));
         buffer.append(versionIndicator);
         buffer.append(resourcePath.substring(start));
-        return buffer.toString();
+        buffer.append("\"");
     }
 
     /**