Author: gvanmatre
Date: Fri Nov 10 12:30:12 2006
New Revision: 473459
URL: http://svn.apache.org/viewvc?view=rev&rev=473459
Log:
Limited jspx mapping support that will help with lazy reuse of markup. This
might be handy for leveraging existing component demo's (SHALE-330).
Added:
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/JspIncludeDirectiveBuilder.java
(with props)
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/LimitedJspxTestCase.java
(with props)
shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/limited-jspx.html
(with props)
Modified:
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/AbstractCommand.java
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/OutputLinkBuilder.java
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/chain/DirectiveBuilderRule.java
shale/framework/trunk/shale-clay/src/main/resources/org/apache/shale/clay/parser/builder/chain/shale-builder-config.xml
Modified:
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/AbstractCommand.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/AbstractCommand.java?view=diff&rev=473459&r1=473458&r2=473459
==============================================================================
---
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/AbstractCommand.java
(original)
+++
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/component/chain/AbstractCommand.java
Fri Nov 10 12:30:12 2006
@@ -78,7 +78,7 @@
/**
* <p>
- * Returns the [EMAIL PROTECTED] Catalog} from the
+ * Returns the [EMAIL PROTECTED] Catalog} with a name of
* <code>Globals.CLAY_CATALOG_NAME</code> in the
* <code>Globals.CLAY_RESOURCE_NAME</code> configuration file.
* </p>
@@ -111,9 +111,8 @@
/**
* <p>
- * Returns the [EMAIL PROTECTED] Catalog} from the
- * <code>Globals.CLAY_CUSTOMIZATION_CATALOG_NAME</code> in the
- * <code>Globals.CLAY_RESOURCE_NAME</code> configuration file.
+ * Returns the [EMAIL PROTECTED] Catalog} with a name identified by the
+ * constant <code>Globals.CLAY_CUSTOMIZATION_CATALOG_NAME</code>.
* </p>
*
* @return commons chains customizations catalog
Added:
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/JspIncludeDirectiveBuilder.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/JspIncludeDirectiveBuilder.java?view=auto&rev=473459
==============================================================================
---
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/JspIncludeDirectiveBuilder.java
(added)
+++
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/JspIncludeDirectiveBuilder.java
Fri Nov 10 12:30:12 2006
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * $Id$
+ */
+package org.apache.shale.clay.parser.builder;
+
+import java.util.Iterator;
+
+import org.apache.shale.clay.config.beans.AttributeBean;
+import org.apache.shale.clay.config.beans.ComponentBean;
+import org.apache.shale.clay.config.beans.ElementBean;
+import org.apache.shale.clay.config.beans.SymbolBean;
+import org.apache.shale.clay.parser.Node;
+
+
+/**
+ * <p>Simulates a JSP include directive.include using the
+ * [EMAIL PROTECTED] org.apache.shale.clay.component.Clay} component.
+ * For a "jsp:include" node, the child "param" nodes
+ * will be converted into symbols.</p>
+ */
+public class JspIncludeDirectiveBuilder extends Builder {
+
+
+
+ /**
+ * <p>
+ * Returns the <code>jsfid</code> associated with the [EMAIL PROTECTED]
ElementBean}
+ * being build.
+ * </p>
+ *
+ * @param node markup
+ * @return jsfid
+ */
+ protected String getJsfid(Node node) {
+ return "clay";
+ }
+
+ /**
+ * <p>
+ * Returns the JSF component type of
+ * <code>org.apache.shale.clay.component.Clay</code> that will populate the
+ * componentType property of the [EMAIL PROTECTED] ElementBean} being
created.
+ * </p>
+ *
+ * @param node markup
+ * @return component type
+ */
+ protected String getComponentType(Node node) {
+ return "org.apache.shale.clay.component.Clay";
+ }
+
+ /**
+ * <p>
+ * Returns a boolean value that will indicate if the target JSF component
+ * will support children.
+ * </p>
+ *
+ * @return <code>true</code>
+ */
+ public boolean isChildrenAllowed() {
+ return true;
+ }
+
+ /**
+ * <p>Calls super to populate the <code>target</code> config bean with the
+ * html <code>node</code>'s values.
+ * When processing a "jsp:directive.include", the "file" attribute doesn't
have a
+ * corresponding clay value so it will become a symbol aliased to
+ * clay's "clayJsfid" attribute. The same goes for the "jsp:include". The
+ * "page" symbol is aliased to the "clayJsfid" attribute. Nested "param"
+ * nodes are converted into symbols.</p>
+ *
+ * @param node markup node
+ * @param target config bean
+ * @param root parent config bean
+ */
+ protected void encodeBegin(Node node, ElementBean target, ComponentBean
root) {
+ super.encodeBegin(node, target, root);
+
+ if (node.getName().equals("directive.include")) {
+ AttributeBean attr = target.getAttribute("clayJsfid");
+ SymbolBean symbol = target.getSymbol("file");
+ if (symbol != null && attr != null) {
+ createAttribute(attr, "@file", target);
+ }
+ } else if (node.getName().equals("include")) {
+ AttributeBean attr = target.getAttribute("clayJsfid");
+ SymbolBean symbol = target.getSymbol("@page");
+ if (symbol != null && attr != null) {
+ createAttribute(attr, "@page", target);
+ }
+ Iterator ai = node.getChildren().iterator();
+ while (ai.hasNext()) {
+ Node child = (Node) ai.next();
+ if (child.getName() != null &&
child.getName().equals("param")) {
+ String name = (String) child.getAttributes().get("name");
+ String value = (String) child.getAttributes().get("value");
+
+ SymbolBean paramSymbol = new SymbolBean();
+ paramSymbol.setName(name);
+ paramSymbol.setValue(value);
+ target.addSymbol(paramSymbol);
+ }
+ }
+ // remove the children, don't waste any more time processing
+ node.getChildren().clear();
+ }
+ }
+
+ /**
+ * <p>This builder handles converting the <code>nodes</code>'s
children.</p>
+ * @param node markup node
+ * @param target config bean
+ * @return <code>true</code> indicating that children of the
<code>node</code>
+ * should be ignored.
+ */
+ protected boolean getBuildNodeBody(Node node, ElementBean target) {
+ return true;
+ }
+
+}
Propchange:
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/JspIncludeDirectiveBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/JspIncludeDirectiveBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified:
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/OutputLinkBuilder.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/OutputLinkBuilder.java?view=diff&rev=473459&r1=473458&r2=473459
==============================================================================
---
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/OutputLinkBuilder.java
(original)
+++
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/OutputLinkBuilder.java
Fri Nov 10 12:30:12 2006
@@ -91,7 +91,7 @@
SymbolBean symbol = target.getSymbol("href");
if ((symbol != null && attr != null)
&& (attr.getValue() == null || attr.getValue().length() == 0)) {
- attr.setValue("@href");
+ createAttribute(attr, "@href", target);
}
}
Modified:
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/chain/DirectiveBuilderRule.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/chain/DirectiveBuilderRule.java?view=diff&rev=473459&r1=473458&r2=473459
==============================================================================
---
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/chain/DirectiveBuilderRule.java
(original)
+++
shale/framework/trunk/shale-clay/src/main/java/org/apache/shale/clay/parser/builder/chain/DirectiveBuilderRule.java
Fri Nov 10 12:30:12 2006
@@ -25,12 +25,18 @@
import org.apache.shale.clay.parser.Node;
import org.apache.shale.clay.parser.builder.Builder;
import org.apache.shale.clay.parser.builder.IgnoreBuilder;
+import org.apache.shale.clay.parser.builder.JspIncludeDirectiveBuilder;
import org.apache.shale.clay.parser.builder.VoidBuilder;
/**
* <p>This builder will be ordered first in the rule registration list.
* If the node has a <code>jsfid</code> attribute, and its value is
- * "ignore", or "void" then special assumptions will be made.</p>
+ * "ignore", or "void" then special assumptions will be made.
+ * Beside the clay "ignore" and "void" directives, handles
+ * all "jsp:" nodes. Most are are assigned to the clay "void"
+ * directive except the "jsp:include" and "jsp:directive.include"
+ * elements. The include and directive.include are
+ * converted into a nested clay components.
*/
public class DirectiveBuilderRule implements Command {
@@ -39,7 +45,8 @@
* [EMAIL PROTECTED] Builder}.
* <p>
*/
- private static final Builder[] BUILDERS = {new IgnoreBuilder(), new
VoidBuilder()};
+ private static final Builder[] BUILDERS = {new IgnoreBuilder(),
+ new VoidBuilder(), new JspIncludeDirectiveBuilder()};
/**
* <p>If the node has a <code>jsfid</code> attribute, and its value is
@@ -47,7 +54,13 @@
* content. The enclosing tag will not be rendered in the document,
* only it's children. If the <code>jsfid</code> is "void",
* the element will not be rendered but its children will
- * keep their original characteristics.</p>
+ * keep their original characteristics.<br/><br/>
+ * All "jsp:" nodes are assigned to the clay void directive except the
+ * "jsp:include" and "jsp:directive.include". These are converted into a
+ * nested clay component. Nodes with a jsp prefix must be in the
+ * "http://java.sun.com/JSP/Page" namespace to be eligible for this
+ * processing.
+ * </p>
*
* @param context commons chains
* @return <code>true</code> if the command ends the chain
@@ -68,6 +81,18 @@
builderRuleContext.setBuilder(BUILDERS[1]);
isFinal = true;
}
+ } else if (node.getQname() != null) {
+ String uri = node.getNamespaceURI(node.getQname());
+ if (uri != null && uri.equals("http://java.sun.com/JSP/Page"))
{
+ if (node.getName().equals("directive.include")
+ || node.getName().equals("include")) {
+ builderRuleContext.setBuilder(BUILDERS[2]);
+ isFinal = true;
+ } else {
+ builderRuleContext.setBuilder(BUILDERS[1]);
+ isFinal = true;
+ }
+ }
}
}
Modified:
shale/framework/trunk/shale-clay/src/main/resources/org/apache/shale/clay/parser/builder/chain/shale-builder-config.xml
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/main/resources/org/apache/shale/clay/parser/builder/chain/shale-builder-config.xml?view=diff&rev=473459&r1=473458&r2=473459
==============================================================================
---
shale/framework/trunk/shale-clay/src/main/resources/org/apache/shale/clay/parser/builder/chain/shale-builder-config.xml
(original)
+++
shale/framework/trunk/shale-clay/src/main/resources/org/apache/shale/clay/parser/builder/chain/shale-builder-config.xml
Fri Nov 10 12:30:12 2006
@@ -41,7 +41,8 @@
catalogName = "clayCustomization"
name = "#{requestScope.XMLNS}"
optional = "true"/>
-
+
+ <command
className="org.apache.shale.clay.parser.builder.chain.DirectiveBuilderRule"/>
<command
className="org.apache.shale.clay.parser.builder.chain.DefaultBuilderRule"/>
</chain>
Added:
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/LimitedJspxTestCase.java
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/LimitedJspxTestCase.java?view=auto&rev=473459
==============================================================================
---
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/LimitedJspxTestCase.java
(added)
+++
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/LimitedJspxTestCase.java
Fri Nov 10 12:30:12 2006
@@ -0,0 +1,106 @@
+package org.apache.shale.clay.config;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.shale.clay.config.beans.AttributeBean;
+import org.apache.shale.clay.config.beans.ComponentBean;
+import org.apache.shale.clay.config.beans.SymbolBean;
+
+public class LimitedJspxTestCase extends AbstractTestCaseConfig {
+
+ // Construct a new instance of this test case.
+ public LimitedJspxTestCase(String name) {
+ super(name);
+ }
+
+ // Return the tests included in this test case.
+ public static Test suite() {
+
+ return (new TestSuite(LimitedJspxTestCase.class));
+ }
+
+ public void testJpx() {
+ loadConfigFile(null);
+
+ ComponentBean document =
htmlTemplateConfigBean.getElement("/org/apache/shale/clay/config/limited-jspx.html");
+ assertNotNull(document);
+
+ assertEquals("void component count", 2, countVoidComponents(document));
+
+ List clayIncludes = findClayJspxInclude(document);
+ assertEquals("includes", 2, clayIncludes.size());
+
+ Iterator ci = clayIncludes.iterator();
+ while (ci.hasNext()) {
+ ComponentBean clayInclude = (ComponentBean) ci.next();
+ if (clayInclude.getSymbol("@file") != null) {
+
+ SymbolBean symbol = clayInclude.getSymbol("@file");
+ assertNotNull("file symbol", symbol);
+ assertEquals("/org/apache/shale/clay/config/address1.html",
symbol.getValue());
+
+ AttributeBean attr = clayInclude.getAttribute("clayJsfid");
+ assertNotNull("clayJsfid", attr);
+ assertEquals("@file", attr.getValue());
+
+
+ } else if (clayInclude.getSymbol("@page") != null) {
+
+ SymbolBean symbol = clayInclude.getSymbol("@page");
+ assertNotNull("file symbol", symbol);
+ assertEquals("/org/apache/shale/clay/config/address1.html",
symbol.getValue());
+
+ AttributeBean attr = clayInclude.getAttribute("clayJsfid");
+ assertNotNull("clayJsfid", attr);
+ assertEquals("@page", attr.getValue());
+
+ for (int i = 0; i < 5; i++) {
+ symbol = clayInclude.getSymbol("@symbol" + i);
+ assertNotNull("@symbol" + i, symbol);
+ assertEquals("value" + i, symbol.getValue());
+ }
+
+ } else {
+ assertFalse("invalid include mapping", true);
+ }
+ }
+
+ }
+
+ // counts the number of void components in the tree
+ public int countVoidComponents(ComponentBean bean) {
+ int voidcnt = 0;
+
+ if (bean.getJsfid().equals("void")) {
+ voidcnt++;
+ }
+
+ Iterator ci = bean.getChildren().iterator();
+ while (ci.hasNext()) {
+ ComponentBean child = (ComponentBean) ci.next();
+ voidcnt += countVoidComponents(child);
+ }
+
+ return voidcnt;
+ }
+
+ // find beans with a jsfid equal to "clay"
+ public List findClayJspxInclude(ComponentBean bean) {
+ List beans = new ArrayList();
+
+ if (bean.getJsfid().equals("clay")) {
+ beans.add(bean);
+ }
+ Iterator ci = bean.getChildren().iterator();
+ while (ci.hasNext()) {
+ beans.addAll(findClayJspxInclude((ComponentBean) ci.next()));
+ }
+
+ return beans;
+ }
+}
Propchange:
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/LimitedJspxTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
shale/framework/trunk/shale-clay/src/test/java/org/apache/shale/clay/config/LimitedJspxTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/limited-jspx.html
URL:
http://svn.apache.org/viewvc/shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/limited-jspx.html?view=auto&rev=473459
==============================================================================
---
shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/limited-jspx.html
(added)
+++
shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/limited-jspx.html
Fri Nov 10 12:30:12 2006
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="iso-8859-1" standalone="yes" ?>
+<!-- ### clay:remove ### -->
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to you under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- ### /clay:remove ### -->
+<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
+ xmlns:f="http://java.sun.com/jsf/core"
+ version="1.2">
+<jsp:directive.page contentType="text/html;charset=utf-8"/>
+<html>
+ <h:outputText id="hello" value="hello"/>
+ <jsp:directive.include file="/org/apache/shale/clay/config/address1.html"/>
+ <jsp:include page="/org/apache/shale/clay/config/address1.html">
+ <jsp:param name="symbol0" value="value0"/>
+ <jsp:param name="symbol1" value="value1"/>
+ <jsp:param name="symbol2" value="value2"/>
+ <jsp:param name="symbol3" value="value3"/>
+ <jsp:param name="symbol4" value="value4"/>
+ </jsp:include>
+</html>
+</jsp:root>
Propchange:
shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/limited-jspx.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
shale/framework/trunk/shale-clay/src/test/resources/org/apache/shale/clay/config/limited-jspx.html
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL