You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by gv...@apache.org on 2006/05/23 05:48:48 UTC
svn commit: r408825 - in /struts/shale/trunk/clay-plugin/src:
java/org/apache/shale/clay/config/ java/org/apache/shale/clay/parser/builder/
java/org/apache/shale/clay/parser/builder/chain/
test/org/apache/shale/clay/config/
Author: gvanmatre
Date: Mon May 22 20:48:47 2006
New Revision: 408825
URL: http://svn.apache.org/viewvc?rev=408825&view=rev
Log:
Added better xml namespace support to the clay html template parsing.
Added:
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/ElementBuilder.java (with props)
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/chain/ClayNamespaceBuilderRule.java (with props)
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address1.html
- copied, changed from r405826, struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address.html
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address2.html (with props)
Removed:
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address.html
Modified:
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/BuilderFactory.java
struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/chain/shale-builder-config.xml
struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java
URL: http://svn.apache.org/viewvc/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java?rev=408825&r1=408824&r2=408825&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/Globals.java Mon May 22 20:48:47 2006
@@ -196,10 +196,21 @@
/**
* <p> Command name in the BUILDER_CATALOG_NAME used to invoke a command
- * chain of rule commands that locates a {@link org.apache.shale.clay.parser.builder.Builder}.
+ * chain of rule commands that locates a {@link org.apache.shale.clay.parser.builder.Builder}
+ * for the default namespace.
* </p>
*/
- public static final String FIND_BUILDER_COMMAND_NAME = "findBuilder";
+ public static final String FIND_DEFAULT_BUILDER_COMMAND_NAME = "default-namespace";
+
+
+ /**
+ * <p> Command name in the BUILDER_CATALOG_NAME used to invoke a command
+ * chain of rule commands that locates a {@link org.apache.shale.clay.parser.builder.Builder}
+ * for a unknown namespace.
+ * </p>
+ */
+ public static final String FIND_UNKNOWN_BUILDER_COMMAND_NAME = "unknown-namespace";
+
/**
* <p>The config file used by {@link org.apache.shale.clay.component.Clay} component to
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/BuilderFactory.java
URL: http://svn.apache.org/viewvc/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/BuilderFactory.java?rev=408825&r1=408824&r2=408825&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/BuilderFactory.java (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/BuilderFactory.java Mon May 22 20:48:47 2006
@@ -90,7 +90,24 @@
context.setNode(node);
try {
Catalog catalog = getCatalog();
- Command command = catalog.getCommand(Globals.FIND_BUILDER_COMMAND_NAME);
+
+ Command command = null;
+ if (node.getQname() == null) {
+ command = catalog.getCommand(Globals.FIND_DEFAULT_BUILDER_COMMAND_NAME);
+ } else {
+ String prefix = node.getQname();
+ String uri = node.getNamespaceURI(prefix);
+ if (uri != null) {
+ command = catalog.getCommand(uri);
+ if (command == null) {
+ command = catalog.getCommand(Globals.FIND_UNKNOWN_BUILDER_COMMAND_NAME);
+ }
+ } else {
+ command = catalog.getCommand(Globals.FIND_UNKNOWN_BUILDER_COMMAND_NAME);
+ }
+
+ }
+
command.execute(context);
} catch (Exception e) {
Added: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/ElementBuilder.java
URL: http://svn.apache.org/viewvc/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/ElementBuilder.java?rev=408825&view=auto
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/ElementBuilder.java (added)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/ElementBuilder.java Mon May 22 20:48:47 2006
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+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.parser.Node;
+
+/**
+ * <p>This class handles building the {@link org.apache.shale.clay.config.beans.ElementBean}'s
+ * from the html markup resembling the <attributes> node in the clay
+ * DTD, http://struts.apache.org/dtds/shale-clay-config_1_0.dtd.</p>
+ */
+public class ElementBuilder extends Builder {
+
+ /**
+ * <p>Returns the <code>jsfid</code> from the target HTML
+ * {@link org.apache.shale.clay.parser.Node}.</p>
+ */
+ protected String getJsfid(Node node) {
+ String jsfid = (String) node.getAttributes().get("jsfid");
+ return jsfid;
+ }
+
+ /**
+ * <p>Returns the <code>componentType</code> from the target HTML
+ * {@link org.apache.shale.clay.parser.Node}.</p>
+ */
+ protected String getComponentType(Node node) {
+ String componentType = (String) node.getAttributes().get("componentType");
+ return componentType;
+ }
+
+ /**
+ * <p>Looks for <set/> nodes within a <attributes> node and
+ * converting them to {@link org.apache.shale.clay.config.beans.AttributeBean}'s
+ * on the <code>target</code> {@link org.apache.shale.clay.config.beans.ElementBean}.
+ * </p>
+ */
+ protected void addAttributes(Node attributesNode, ElementBean target) {
+ Iterator ci = attributesNode.getChildren().iterator();
+ while (ci.hasNext()) {
+ Node child = (Node) ci.next();
+ if (child.getName() != null && child.getName().equals("set")) {
+ String name = (String) child.getAttributes().get("name");
+ String value = (String) child.getAttributes().get("value");
+ String bindingType = (String) child.getAttributes().get("bindingType");
+
+ AttributeBean attr = null;
+ if ((attr = target.getAttribute(name)) != null) {
+ createAttribute(attr, value, target);
+ } else {
+ attr = new AttributeBean();
+ attr.setName(name);
+ attr.setValue(value);
+ attr.setBindingType(bindingType);
+ target.addAttribute(attr);
+ }
+ }
+ }
+ }
+
+
+ /**
+ * <p>Adds markup <code>symbols</code> to the <code>target</code>
+ * {@link org.apache.shale.clay.config.beans.ElementBean}.
+ * </p>
+ */
+ protected void addSymbols(Node symbolsNode, ElementBean target) {
+ Iterator si = symbolsNode.getChildren().iterator();
+ while (si.hasNext()) {
+ Node child = (Node) si.next();
+ if (child.getName() != null && child.getName().equals("set")) {
+ String name = (String) child.getAttributes().get("name");
+ String value = (String) child.getAttributes().get("value");
+
+ if (name != null && name.length() > 0)
+ target.addSymbol(name, value);
+ }
+ }
+ }
+
+ /**
+ * <p>Handles converting markup resembling the <element> node
+ * in the clay DTD, http://struts.apache.org/dtds/shale-clay-config_1_0.dtd,
+ * to the target {@link org.apache.shale.clay.config.beans.ElementBean}.</p>
+ */
+ protected void encodeBegin(Node node, ElementBean target, ComponentBean root) {
+ super.encodeBegin(node, target, root);
+
+ List deleteList = new ArrayList();
+ Iterator ci = node.getChildren().iterator();
+ while (ci.hasNext()) {
+ Node child = (Node) ci.next();
+ if (child.isWellFormed() && child.getName() != null) {
+ if (child.getName().equals("attributes")) {
+ addAttributes(child, target);
+ deleteList.add(child);
+ } else if (child.getName().equals("symbols")) {
+ addSymbols(child, target);
+ deleteList.add(child);
+ }
+ } else {
+ // remove white space
+ deleteList.add(child);
+ }
+ }
+
+ ci = deleteList.iterator();
+ while (ci.hasNext())
+ node.getChildren().remove(ci.next());
+
+ }
+
+
+ /**
+ * <p>
+ * This override returns <code>true</code> indicating that the from JSF
+ * component can have children.
+ * </p>
+ */
+ public boolean isChildrenAllowed() {
+ return true;
+ }
+
+}
Propchange: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/ElementBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/ElementBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/chain/ClayNamespaceBuilderRule.java
URL: http://svn.apache.org/viewvc/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/chain/ClayNamespaceBuilderRule.java?rev=408825&view=auto
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/chain/ClayNamespaceBuilderRule.java (added)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/chain/ClayNamespaceBuilderRule.java Mon May 22 20:48:47 2006
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.chain;
+
+import org.apache.commons.chain.Command;
+import org.apache.commons.chain.Context;
+import org.apache.shale.clay.parser.Node;
+import org.apache.shale.clay.parser.builder.Builder;
+import org.apache.shale.clay.parser.builder.ElementBuilder;
+
+/**
+ * This class defines the rules that bind HTML
+ * {@link org.apache.shale.clay.parser.Node}'s resembling
+ * the {@link org.apache.shale.clay.component.Clay} DTD into
+ * corresponding {@link Builder}'s. The html nodes will be
+ * defined in their own namespace.</p>
+ */
+public class ClayNamespaceBuilderRule implements Command {
+
+ /**
+ * <p>A list of {@link Builder}'s used to handle converting
+ * the xhtml clay namespace into {@link org.apache.shale.clay.config.beans.ElementBean}'s
+ * used by the {@link org.apache.shale.clay.component.Clay} component.</p>
+ */
+ private static final Builder[] builders = {new ElementBuilder()};
+
+ /**
+ * <p>Maps matching html {@link org.apache.shale.clay.parser.Node}'s to
+ * corresponding builders.</p>
+ */
+ public boolean execute(Context context) throws Exception {
+
+ boolean isFinal = false;
+
+ BuilderRuleContext builderRuleContext = (BuilderRuleContext) context;
+ Node node = builderRuleContext.getNode();
+
+ if (node.isWellFormed() && node.getName().equals("element")) {
+ builderRuleContext.setBuilder(builders[0]);
+ isFinal = true;
+ }
+
+ return isFinal;
+ }
+
+
+}
Propchange: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/chain/ClayNamespaceBuilderRule.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/chain/ClayNamespaceBuilderRule.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/chain/shale-builder-config.xml
URL: http://svn.apache.org/viewvc/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/chain/shale-builder-config.xml?rev=408825&r1=408824&r2=408825&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/chain/shale-builder-config.xml (original)
+++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/chain/shale-builder-config.xml Mon May 22 20:48:47 2006
@@ -22,20 +22,26 @@
<catalog name="builder">
- <chain name="findBuilder">
-
+ <chain name="default-namespace">
<command className="org.apache.shale.clay.parser.builder.chain.DirectiveBuilderRule"/>
<command className="org.apache.shale.clay.parser.builder.chain.InputBuilderRule"/>
<command className="org.apache.shale.clay.parser.builder.chain.FormBuilderRule"/>
<command className="org.apache.shale.clay.parser.builder.chain.SelectBuilderRule"/>
<command className="org.apache.shale.clay.parser.builder.chain.OptionBuilderRule"/>
<command className="org.apache.shale.clay.parser.builder.chain.LabelBuilderRule"/>
- <command className="org.apache.shale.clay.parser.builder.chain.AnchorBuilderRule"/>
- <command className="org.apache.shale.clay.parser.builder.chain.TextareaBuilderRule"/>
-
- <command className="org.apache.shale.clay.parser.builder.chain.SpanBuilderRule"/>
+ <command className="org.apache.shale.clay.parser.builder.chain.AnchorBuilderRule"/>
+ <command className="org.apache.shale.clay.parser.builder.chain.TextareaBuilderRule"/>
+ <command className="org.apache.shale.clay.parser.builder.chain.SpanBuilderRule"/>
+ <command className="org.apache.shale.clay.parser.builder.chain.DefaultBuilderRule"/>
+ </chain>
+
+ <chain name="unknown-namespace">
<command className="org.apache.shale.clay.parser.builder.chain.DefaultBuilderRule"/>
-
</chain>
+
+ <chain name="http://struts.apache.org/dtds/shale-clay-config">
+ <command className="org.apache.shale.clay.parser.builder.chain.ClayNamespaceBuilderRule"/>
+ </chain>
+
</catalog>
Modified: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java
URL: http://svn.apache.org/viewvc/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java?rev=408825&r1=408824&r2=408825&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java (original)
+++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java Mon May 22 20:48:47 2006
@@ -245,7 +245,7 @@
//loads the default and the custom address config file
loadConfigFile("/org/apache/shale/clay/config/address-config.xml");
- ComponentBean bean = htmlTemplateConfigBean.getElement("/org/apache/shale/clay/config/address.html");
+ ComponentBean bean = htmlTemplateConfigBean.getElement("/org/apache/shale/clay/config/address2.html");
assertNotNull(bean);
Iterator ci = bean.getChildrenIterator();
@@ -257,6 +257,30 @@
}
+
+ // loads the XHTML document fragment into a graph of
+ // shale meta component data and validates the select
+ // sample to the known good state
+ public void testLoadXHTMLNamespaceFile() {
+
+ //loads the default and the custom address config file
+ loadConfigFile("/org/apache/shale/clay/config/address-config.xml");
+
+ ComponentBean bean = htmlTemplateConfigBean.getElement("/org/apache/shale/clay/config/address1.html");
+ assertNotNull(bean);
+
+ Iterator ci = bean.getChildrenIterator();
+ while (ci.hasNext()) {
+ ElementBean child = (ElementBean) ci.next();
+ //look for a component that we have setup to test
+ checkComponent(child, CUSTOM_HTML_COMPONENTS);
+ }
+
+ }
+
+
+
+
//test a full xml view including a html template (on-demand)
public void testLoadXMLFileOnDemand() {
Copied: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address1.html (from r405826, struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address.html)
URL: http://svn.apache.org/viewvc/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address1.html?p2=struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address1.html&p1=struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address.html&r1=405826&r2=408825&rev=408825&view=diff
==============================================================================
--- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address.html (original)
+++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address1.html Mon May 22 20:48:47 2006
@@ -1,37 +1,54 @@
<form>
- <table>
+ <table xmlns:clay="http://struts.apache.org/dtds/shale-clay-config">
<tr>
- <td><label jsfid=street1Label>Mock Address 1:</label></td>
- <td><input jsfid=street1 type=text size=45></td>
- <td><span jsfid="street1Message>Mock Error Message</span></td>
+ <td><clay:element jsfid="street1Label"/></td>
+ <td><clay:element jsfid="street1">
+ <clay:attributes>
+ <clay:set name="size" value="45"/>
+ </clay:attributes>
+ </clay:element>
+ </td>
+ <td><clay:element jsfid="street1Message"/></td>
</tr>
<tr>
- <td><label jsfid=street2Label>Mock Address 2:</label></td>
- <td><input jsfid=street2 type=text size=45></td>
- <td><span jsfid="street2Message">Mock Error Message</span></td>
+ <td><clay:element jsfid="street2Label"/></td>
+ <td><clay:element jsfid="street2">
+ <clay:attributes>
+ <clay:set name="size" value="45"/>
+ </clay:attributes>
+ </clay:element>
+ </td>
+ <td><clay:element jsfid="street2Message"/></td>
</tr>
<tr>
- <td><label jsfid=cityLabel>Mock City:</label></td>
- <td><input jsfid=city type=text size=25></td>
- <td><span jsfid="cityMessage">Mock Error Message</span></td>
+ <td><clay:element jsfid="cityLabel"/></td>
+ <td><clay:element jsfid="city">
+ <clay:attributes>
+ <clay:set name="size" value="25"/>
+ </clay:attributes>
+ </clay:element>
+ </td>
+ <td><clay:element jsfid="cityMessage"/></td>
</tr>
<tr>
- <td><label jsfid=stateLabel>Mock State:</label></td>
+ <td><clay:element jsfid="stateLabel"/></td>
<td>
- <select jsfid=state>
- <option value=M1>Mock 1</option>
- <option value=M1>Mock 1</option>
- </select>
+ <clay:element jsfid="state"/>
</td>
- <td><span jsfid=stateMessage>Mock Error Message</span></td>
+ <td><clay:element jsfid="stateMessage"/></td>
</tr>
<tr>
- <td><label jsfid=zipLabel>Mock Zip:</label></td>
- <td><input jsfid=zip type=text size=9></td>
- <td><span jsfid="zipMessage">Mock Error Message</span></td>
+ <td><clay:element jsfid="zipLabel"/></td>
+ <td><clay:element jsfid="zip">
+ <clay:attributes>
+ <clay:set name="size" value="9"/>
+ </clay:attributes>
+ </clay:element>
+ </td>
+ <td><clay:element jsfid="zipMessage"/></td>
</tr>
<tr>
- <td colspan=3><input jsfid=saveCommand type=submit value=Save></td>
+ <td colspan=3><clay:element jsfid="saveCommand"/></td>
</tr>
</table>
</form>
Added: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address2.html
URL: http://svn.apache.org/viewvc/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address2.html?rev=408825&view=auto
==============================================================================
--- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address2.html (added)
+++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address2.html Mon May 22 20:48:47 2006
@@ -0,0 +1,37 @@
+<form>
+ <table>
+ <tr>
+ <td><label jsfid=street1Label>Mock Address 1:</label></td>
+ <td><input jsfid=street1 type=text size=45></td>
+ <td><span jsfid="street1Message>Mock Error Message</span></td>
+ </tr>
+ <tr>
+ <td><label jsfid=street2Label>Mock Address 2:</label></td>
+ <td><input jsfid=street2 type=text size=45></td>
+ <td><span jsfid="street2Message">Mock Error Message</span></td>
+ </tr>
+ <tr>
+ <td><label jsfid=cityLabel>Mock City:</label></td>
+ <td><input jsfid=city type=text size=25></td>
+ <td><span jsfid="cityMessage">Mock Error Message</span></td>
+ </tr>
+ <tr>
+ <td><label jsfid=stateLabel>Mock State:</label></td>
+ <td>
+ <select jsfid=state>
+ <option value=M1>Mock 1</option>
+ <option value=M1>Mock 1</option>
+ </select>
+ </td>
+ <td><span jsfid=stateMessage>Mock Error Message</span></td>
+ </tr>
+ <tr>
+ <td><label jsfid=zipLabel>Mock Zip:</label></td>
+ <td><input jsfid=zip type=text size=9></td>
+ <td><span jsfid="zipMessage">Mock Error Message</span></td>
+ </tr>
+ <tr>
+ <td colspan=3><input jsfid=saveCommand type=submit value=Save></td>
+ </tr>
+ </table>
+</form>
\ No newline at end of file
Propchange: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address2.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address2.html
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL