click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r932337 - in /click/trunk/click/framework/src/org/apache/click: Control.java Page.java control/AbstractContainer.java control/AbstractControl.java control/FieldSet.java util/ClickUtils.java util/PageImports.java
Date Fri, 09 Apr 2010 10:20:25 GMT
Author: sabob
Date: Fri Apr  9 10:20:25 2010
New Revision: 932337

URL: http://svn.apache.org/viewvc?rev=932337&view=rev
Log:
removed getHtmlImports. CLK-647

Modified:
    click/trunk/click/framework/src/org/apache/click/Control.java
    click/trunk/click/framework/src/org/apache/click/Page.java
    click/trunk/click/framework/src/org/apache/click/control/AbstractContainer.java
    click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java
    click/trunk/click/framework/src/org/apache/click/control/FieldSet.java
    click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java
    click/trunk/click/framework/src/org/apache/click/util/PageImports.java

Modified: click/trunk/click/framework/src/org/apache/click/Control.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/Control.java?rev=932337&r1=932336&r2=932337&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/Control.java (original)
+++ click/trunk/click/framework/src/org/apache/click/Control.java Fri Apr  9 10:20:25 2010
@@ -146,39 +146,6 @@ public interface Control extends Seriali
     public Context getContext();
 
     /**
-     * Return the HTML import string to be included in the page.
-     * <p/>
-     * Implement this method to specify JavaScript and CSS includes for the
-     * page. For example:
-     *
-     * <pre class="codeJava">
-     * <span class="kw">protected static final</span> String HTML_IMPORT =
-     *     <span class="st">"&lt;script type=\"text/javascript\" src=\"{0}/click/custom.js\"&gt;&lt;/script&gt;"</span>;
-     *
-     * <span class="kw">public</span> String getHtmlImports() {
-     *     <span class="kw">return</span> ClickUtils.createHtmlImport(HTML_IMPORTS,
getResourceVersionIndicator(), getContext());
-     * } </pre>
-     *
-     * <b>Note</b> multiple import lines should be separated by a
-     * <tt>'\n'</tt> char, as the {@link org.apache.click.util.PageImports} will
-     * parse multiple import lines on the <tt>'\n'</tt> char and ensure that
-     * imports are not included twice.
-     * <p/>
-     * The order in which JS and CSS files are included will be preserved in the
-     * page.
-     * <p/>
-     * <b>Also note:</b> a common problem when overriding getHtmlImports in
-     * subclasses is forgetting to call <em>super.getHtmlImports</em>. Consider
-     * carefully whether you should call <em>super.getHtmlImports</em> or not.
-     *
-     * @deprecated use the new {@link #getHeadElements()} instead
-     *
-     * @return the HTML includes statements for the control stylesheet and
-     * JavaScript files, or null if no includes are available
-     */
-    public String getHtmlImports();
-
-    /**
      * Return the list of HEAD {@link org.apache.click.element.Element elements}
      * to be included in the page. Example HEAD elements include
      * {@link org.apache.click.element.JsImport JsImport},

Modified: click/trunk/click/framework/src/org/apache/click/Page.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/Page.java?rev=932337&r1=932336&r2=932337&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/Page.java (original)
+++ click/trunk/click/framework/src/org/apache/click/Page.java Fri Apr  9 10:20:25 2010
@@ -616,50 +616,13 @@ public class Page implements Serializabl
     }
 
     /**
-     * Return the HTML import string to include in the page, by default
-     * this method returns null.
-     * <p/>
-     * Override this method to specify JavaScript and CSS includes for the
-     * page. For example:
-     *
-     * <pre class="prettyprint">
-     * public MyPage extends Page {
-     *
-     *     // Define a constant for the Page Javascript import.
-     *     protected static final String JAVASCRIPT_IMPORT =
-     *         "&lt;script type='text/javascript' src='{0}/click/my-page.js'&gt;&lt;/script&gt;\n";
-     *
-     *     // Define a constant for the Page CSS import
-     *     protected static final String CSS_IMPORT =
-     *         "&lt;link type='text/css' rel='stylesheet' href='text/css' src='{0}/click/my-page.css'/&gt;\n";
-     *
-     *     ...
-     *
-     *     // Override getHtmlImports and return the Javascript and CSS imports.
-     *     public String getHtmlImports() {
-     *         Context context = getContext();
-     *
-     *         // Concatenate Javascript and CSS imports
-     *         return ClickUtils.createHtmlImport(MyPage.JAVASCRIPT_IMPORT, ClickUtils.getResourceVersionIndicator(),
context)
-     *         + ClickUtils.createHtmlImport(MyPage.CSS_IMPORT, ClickUtils.getResourceVersionIndicator(),
context);
-     *     }
-     * } </pre>
-     *
-     * <b>Note</b> multiple import lines should be separated by a
-     * <tt>'\n'</tt> char, as the {@link org.apache.click.util.PageImports} will
-     * parse multiple import lines on the <tt>'\n'</tt> char and ensure that
-     * imports are not included twice.
-     * <p/>
-     * The order in which JS and CSS files are included will be preserved in the
-     * page.
+     * @deprecated use the new {@link #getHeadElements()} instead
      *
      * @return the HTML includes statements for the control stylesheet and
-     * JavaScript files, by default this method returns null
-     *
-     * @deprecated use the new {@link #getHeadElements()} instead
+     * JavaScript files
      */
-    public String getHtmlImports() {
-        return null;
+    public final String getHtmlImports() {
+        throw new UnsupportedOperationException("Use getHeadElements instead");
     }
 
     /**

Modified: click/trunk/click/framework/src/org/apache/click/control/AbstractContainer.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/AbstractContainer.java?rev=932337&r1=932336&r2=932337&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/AbstractContainer.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/AbstractContainer.java Fri Apr
 9 10:20:25 2010
@@ -264,29 +264,6 @@ public abstract class AbstractContainer 
     }
 
     /**
-     * @see org.apache.click.Control#getHtmlImports()
-     *
-     * @deprecated use the new {@link #getHeadElements()} instead
-     *
-     * @return the HTML includes statements for the container and child Controls,
-     * or null if no includes are available
-     */
-    @Override
-    public String getHtmlImports() {
-        if (hasControls()) {
-            HtmlStringBuffer buffer = new HtmlStringBuffer(0);
-            for (Control control : getControls()) {
-                String htmlImports = control.getHtmlImports();
-                if (htmlImports != null) {
-                    buffer.append(htmlImports);
-                }
-            }
-            return buffer.toString();
-        }
-        return null;
-    }
-
-    /**
      * Render the HTML representation of the container and all its child
      * controls to the specified buffer.
      * <p/>

Modified: click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java?rev=932337&r1=932336&r2=932337&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/AbstractControl.java Fri Apr
 9 10:20:25 2010
@@ -533,15 +533,13 @@ public abstract class AbstractControl im
     }
 
     /**
-     * @see org.apache.click.Control#getHtmlImports()
-     *
      * @deprecated use the new {@link #getHeadElements()} instead
      *
      * @return the HTML includes statements for the control stylesheet and
      * JavaScript files
      */
-    public String getHtmlImports() {
-        return null;
+    public final String getHtmlImports() {
+        throw new UnsupportedOperationException("Use getHeadElements instead");
     }
 
     /**
@@ -951,9 +949,9 @@ public abstract class AbstractControl im
             if (token.charAt(keyEnd + 1) == ';') {
                 continue;
             }
-            String name = token.substring(0, keyEnd);
-            String value = token.substring(keyEnd + 1);
-            stylesMap.put(name, value);
+            String styleName = token.substring(0, keyEnd);
+            String styleValue = token.substring(keyEnd + 1);
+            stylesMap.put(styleName, styleValue);
         }
 
         return stylesMap;

Modified: click/trunk/click/framework/src/org/apache/click/control/FieldSet.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/FieldSet.java?rev=932337&r1=932336&r2=932337&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/FieldSet.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/FieldSet.java Fri Apr  9 10:20:25
2010
@@ -609,34 +609,6 @@ public class FieldSet extends Field impl
     }
 
     /**
-     * Return the HTML head import statements for contained fields.
-     *
-     * @see org.apache.click.Control#getHtmlImports()
-     *
-     * @deprecated use {@link #getHeadElements()} instead
-     *
-     * @return the HTML head import statements for the contained field stylesheet
-     * and JavaScript files
-     */
-    @Override
-    public String getHtmlImports() {
-        if (hasControls()) {
-            HtmlStringBuffer buffer = new HtmlStringBuffer(512);
-
-            for (int i = 0, size = getControls().size(); i < size; i++) {
-                Control control = (Control) getControls().get(i);
-                String htmlImports = control.getHtmlImports();
-                if (htmlImports != null) {
-                    buffer.append(htmlImports);
-                }
-            }
-            return buffer.toString();
-        }
-
-        return null;
-    }
-
-    /**
      * Return the fieldset Legend element value: &lt;legend&gt;
      * <p/>
      * If the legend value is null, this method will attempt to find a

Modified: click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java?rev=932337&r1=932336&r2=932337&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java Fri Apr  9 10:20:25
2010
@@ -37,7 +37,6 @@ import java.net.URL;
 import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.security.MessageDigest;
-import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -93,12 +92,11 @@ public class ClickUtils {
      * <tt>enable-resource-version</tt>.
      * <p/>
      * If this attribute is set to <tt>true</tt> and Click is running in
-     * <tt>production</tt> or <tt>profile</tt> mode, resources returned
from
-     * {@link org.apache.click.Control#getHtmlImports()} will have a
+     * <tt>production</tt> or <tt>profile</tt> mode, Click resources
returned
+     * from {@link org.apache.click.Control#getHeadElements()} will have a
      * <tt>version indicator</tt> added to their path.
      *
-     * @see org.apache.click.Control#getHtmlImports()
-     * @see org.apache.click.util.ClickUtils#createHtmlImport(String, Context)
+     * @see org.apache.click.Control#getHeadElements()
      * @see org.apache.click.util.ClickUtils#getResourceVersionIndicator(Context)
      */
     public static final String ENABLE_RESOURCE_VERSION = "enable-resource-version";
@@ -831,28 +829,6 @@ public class ClickUtils {
     }
 
     /**
-     * Create an HTML import statement from the given string pattern and
-     * versionIndicator, formatted with the request context path.
-     * <p/>
-     * <b>Remember</b>: the version indicator will only be added in
-     * <tt>production</tt> and <tt>profile</tt> modes, and only if
the
-     * request attribute {@link #ENABLE_RESOURCE_VERSION}
-     * is set to <tt>"true"</tt>.
-     *
-     * @param pattern the HTML import pattern string to format
-     * @param context the request context
-     * @return the formatted HTML import statement
-     */
-    public static String createHtmlImport(String pattern, Context context) {
-        Object[] args = {
-            context.getRequest().getContextPath(),
-            getResourceVersionIndicator(context)
-        };
-
-        return MessageFormat.format(pattern, args);
-    }
-
-    /**
      * Creates a template model of key/value pairs which can be used by template
      * engines such as Velocity and Freemarker.
      * <p/>

Modified: click/trunk/click/framework/src/org/apache/click/util/PageImports.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/PageImports.java?rev=932337&r1=932336&r2=932337&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/PageImports.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/PageImports.java Fri Apr  9 10:20:25
2010
@@ -21,7 +21,6 @@ package org.apache.click.util;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.util.StringTokenizer;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -35,9 +34,7 @@ import org.apache.click.element.CssStyle
 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;
 
 /**
  * Provides a utility object for rendering a Page's HEAD elements and
@@ -198,56 +195,6 @@ public class PageImports {
     }
 
     /**
-     * Add the given HTML import line to the Page HTML imports.
-     *
-     * @deprecated use the new {@link #add(org.apache.click.element.Element)}
-     * instead
-     *
-     * @param value the HTML import line to add
-     */
-    public void addImport(String value) {
-        if (value == null || value.length() == 0) {
-            return;
-        }
-
-        String[] lines = StringUtils.split(value, '\n');
-
-        for (int i = 0; i  < lines.length; i++) {
-            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) {
-                CssStyle cssStyle = asCssStyle(lines[i]);
-                setUnique(cssStyle, cssStyle.getContent().toString());
-                add(cssStyle);
-
-            } 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 {
-                    JsScript jsScript = asJsScript(lines[i]);
-                    setUnique(jsScript, jsScript.getContent().toString());
-                    add(jsScript);
-
-                }
-            } else {
-                throw new IllegalArgumentException("Unknown include type: " + lines[i]);
-            }
-        }
-    }
-
-    /**
      * Return true if the page imports have been initialized.
      *
      * @return true if the page imports have been initialized
@@ -394,9 +341,6 @@ public class PageImports {
     public void processControls(List<Control> controls) {
         for (Control control : controls) {
 
-            // import from getHtmlImports
-            addImport(control.getHtmlImports());
-
             // import from getHeadElement
             processControl(control);
         }
@@ -557,8 +501,6 @@ public class PageImports {
             }
         }
 
-        addImport(page.getHtmlImports());
-
         processHeadElements(page.getHeadElements());
     }
 
@@ -591,6 +533,7 @@ public class PageImports {
          *
          * @return a string representing miscellaneous head and CSS elements
          */
+        @Override
         public String toString() {
             processPageControls();
             HtmlStringBuffer buffer = new HtmlStringBuffer(
@@ -615,6 +558,7 @@ public class PageImports {
          *
          * @return a string representing all includes
          */
+        @Override
         public String toString() {
             processPageControls();
             HtmlStringBuffer buffer = new HtmlStringBuffer(
@@ -638,6 +582,7 @@ public class PageImports {
          *
          * @return a string representing all JavaScript elements
          */
+        @Override
         public String toString() {
             processPageControls();
             HtmlStringBuffer buffer = new HtmlStringBuffer(
@@ -661,6 +606,7 @@ public class PageImports {
          *
          * @return a string representing all CSS elements
          */
+        @Override
         public String toString() {
             processPageControls();
             HtmlStringBuffer buffer = new HtmlStringBuffer(
@@ -670,214 +616,4 @@ public class PageImports {
             return buffer.toString();
         }
     }
-
-    // -------------------------------------------------------- Private Methods
-
-    /**
-     * Convert the given HTML import line to a {@link CssImport} instance.
-     *
-     * @param line the HTML import line to convert to a CssImport instance
-     * @return a CssImport instance
-     */
-    private CssImport asCssImport(String line) {
-        CssImport cssImport = new CssImport();
-        copyAttributes(cssImport, line);
-        return cssImport;
-    }
-
-    /**
-     * Convert the given HTML import line to a {@link CssStyle} instance.
-     *
-     * @param line the HTML import line to convert to a Css instance
-     * @return a Css instance
-     */
-    private CssStyle asCssStyle(String line) {
-        CssStyle cssStyle = new CssStyle();
-        copyAttributes(cssStyle, line);
-        cssStyle.setContent(extractCssContent(line));
-        return cssStyle;
-    }
-
-    /**
-     * Convert the given HTML import line to a {@link JsImport} instance.
-     *
-     * @param line the HTML import line to convert to a JavaScriptImport instance
-     * @return a JsImport instance
-     */
-    private JsImport asJsImport(String line) {
-        JsImport jsImport = new JsImport();
-        copyAttributes(jsImport, line);
-        return jsImport;
-    }
-
-    /**
-     * Convert the given HTML import line to a {@link JsScript} instance.
-     *
-     * @param line the HTML import line to convert to a JavaScript instance
-     * @return a JsScript instance
-     */
-    private JsScript asJsScript(String line) {
-        JsScript jsScript = new JsScript();
-        copyAttributes(jsScript, line);
-        jsScript.setContent(extractJsContent(line, jsScript));
-        return jsScript;
-    }
-
-    /**
-     * Extract the CSS content from the given HTML import line.
-     *
-     * @param line the HTML import line
-     * @return the CSS content contained in the HTML import line
-     */
-    private String extractCssContent(String line) {
-        if (line.endsWith("/>")) {
-            // If tag has no content, exit early
-            return "";
-        }
-
-        // Find index where tag ends
-        int start = line.indexOf('>');
-        if (start == -1) {
-            throw new IllegalArgumentException(line + " is not a valid element");
-        }
-        int end = line.lastIndexOf("</style>");
-        if (end == -1) {
-            return "";
-        }
-        return line.substring(start + 1, end);
-    }
-
-    /**
-     * Extract the JavaScript content from the given HTML import line.
-     *
-     * @param line the HTML import line
-     * @param jsScript the JsScript to replace the line with
-     */
-    private String extractJsContent(String line, JsScript jsScript) {
-        if (line.endsWith("/>")) {
-            // If tag has no content, exit early
-            return "";
-        }
-
-        // Find index where tag ends
-        int start = line.indexOf('>');
-        if (start == -1) {
-            throw new IllegalArgumentException(line + " is not a valid element");
-        }
-        int end = line.lastIndexOf("</script>");
-        if (end == -1) {
-            return "";
-        }
-        line = line.substring(start + 1, end).trim();
-
-        // Strip addLoadEvent function
-        int addLoadEventStart = line.indexOf("addLoadEvent");
-        if (addLoadEventStart == 0) {
-            start = line.indexOf("{", addLoadEventStart);
-            line = line.substring(start + 1);
-            end = line.lastIndexOf("});");
-            line = line.substring(0, end);
-            jsScript.setExecuteOnDomReady(true);
-        }
-
-        return line;
-    }
-
-    /**
-     * Copy all available attributes from HTML import line to the Element
-     * instance.
-     *
-     * @param element the HTML head element to copy the attributes to
-     * @param line the HTML import line to copy attributes from
-     */
-    private void copyAttributes(Element element, String line) {
-        // Find index where attributes start: the first space
-        int start = line.indexOf(' ');
-        if (start == -1) {
-            // If no attributes found, exit early
-            return;
-        }
-
-        // Find index where attributes end: closing tag
-        int end = line.indexOf("/>");
-        if (end == -1) {
-            end = line.indexOf(">");
-        }
-        if (end == -1) {
-            throw new IllegalArgumentException(line + " is not a valid HTML import");
-        }
-
-        line = line.substring(start, end);
-        StringTokenizer tokens = new StringTokenizer(line, " ");
-        while (tokens.hasMoreTokens()) {
-            String token = tokens.nextToken();
-            StringTokenizer attribute = new StringTokenizer(token, "=");
-            String key = attribute.nextToken();
-            String value = attribute.nextToken();
-            element.setAttribute(key, StringUtils.strip(value, "'\""));
-        }
-    }
-
-    /**
-     * Ensure the given element and content will be unique.
-     *
-     * @deprecated use {@link org.apache.click.element.Element#setId(java.lang.String) ID}
-     * instead
-     *
-     * @param element sets whether the HEAD element should be unique or not
-     * @param content sets whether the HEAD element should be unique or not
-     */
-    private void setUnique(Element element, String content) {
-        String id = element.getId();
-        // If Element is unique and ID is not defined, derive the ID from the
-        // content
-        if (StringUtils.isBlank(id) && content.length() > 0) {
-            int hash = Math.abs(content.hashCode());
-            element.setId("c_" + 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