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/03/28 12:58:04 UTC
svn commit: r759457 -
/incubator/click/trunk/click/framework/src/org/apache/click/util/PageImports.java
Author: sabob
Date: Sat Mar 28 11:58:03 2009
New Revision: 759457
URL: http://svn.apache.org/viewvc?rev=759457&view=rev
Log:
Enhanced PageImports to be used standalone by passing in a list of controls to be processed. Once processing is finished the list of elements can be retrieved.
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=759457&r1=759456&r2=759457&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 Sat Mar 28 11:58:03 2009
@@ -354,6 +354,53 @@
}
}
+ /**
+ * Process the HEAD elements of the given list of Controls. You can retrieve
+ * the processed HEAD elements through {@link #getHeadElements} and
+ * {@link #getJsElements()}.
+ * <p/>
+ * This method delegates to {@link #processControl(org.apache.click.Control)}
+ * to add the given Control's HEAD elements to the Page imports.
+ *
+ * @param list the list of Controls which HEAD elements to process
+ */
+ public void processControls(List controls) {
+ for (int i = 0; i < controls.size(); i++) {
+ Control control = (Control) controls.get(i);
+
+ // import from getHtmlImports
+ addImport(control.getHtmlImports());
+
+ // import from getHeadElement
+ processControl(control);
+ }
+ }
+
+ /**
+ * Return the list of processed HEAD elements, excluding any JavaScript
+ * elements. To retrieve JavaScript elements please see
+ * {@link #getJsElements()}.
+ *
+ * @return the list of processed HEAD elements
+ */
+ public final List getHeadElements() {
+ List result = new ArrayList(headElements);
+ result.addAll(cssImports);
+ result.addAll(cssStyles);
+ return result;
+ }
+
+ /**
+ * Return the list of processed JavaScript elements.
+ *
+ * @return the list of processed JavaScript elements
+ */
+ public final List getJsElements() {
+ List result = new ArrayList(jsImports);
+ result.addAll(jsScripts);
+ return result;
+ }
+
// ------------------------------------------------------ Protected Methods
/**
@@ -443,15 +490,7 @@
setInitialized(true);
if (page.hasControls()) {
- for (int i = 0; i < page.getControls().size(); i++) {
- Control control = (Control) page.getControls().get(i);
-
- // import from getHtmlImports
- addImport(control.getHtmlImports());
-
- // import from getHeadElement
- processControl(control);
- }
+ processControls(page.getControls());
}
addImport(page.getHtmlImports());
@@ -506,12 +545,12 @@
Iterator it = elements.iterator();
while (it.hasNext()) {
- Object element = it.next();
- if (!(element instanceof Element)) {
- throw new IllegalStateException("non Element object added to"
- + " head elements.");
+ Object item = it.next();
+ if (!(item instanceof Element)) {
+ throw new IllegalStateException(item.getClass() + " is not"
+ + " of type " + Element.class);
}
- add((Element) element);
+ add((Element) item);
}
}
@@ -519,7 +558,7 @@
/**
* This class enables lazy, on demand importing for
- * {@link #renderAllIncludes(org.apache.click.util.HtmlStringBuffer)}.
+ * {@link #renderHeadElements(org.apache.click.util.HtmlStringBuffer)}.
*/
class HeadElements {
@@ -588,6 +627,8 @@
/**
* This class enables lazy, on demand importing for
* {@link #renderCssElements(org.apache.click.util.HtmlStringBuffer)}.
+ *
+ * @deprecated use {@link HeadElements} instead
*/
class CssElements {