Author: gvanmatre Date: Tue May 23 20:38:04 2006 New Revision: 409062 URL: http://svn.apache.org/viewvc?rev=409062&view=rev Log: Extended the clay xhtml namespace support.
Added: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address3.html (with props) Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/Builder.java struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/ElementBuilder.java 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/parser/builder/Builder.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/Builder.java?rev=409062&r1=409061&r2=409062&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/Builder.java (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/Builder.java Tue May 23 20:38:04 2006 @@ -144,7 +144,7 @@ * replacing the <code>value</code>. * </p> */ - protected AttributeBean createAttribute(AttributeBean original, String value, ElementBean target) { + protected AttributeBean createAttribute(AttributeBean original, String value, ComponentBean target) { AttributeBean attr = new AttributeBean(); attr.setName(original.getName()); attr.setValue(value); Modified: 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=409062&r1=409061&r2=409062&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/ElementBuilder.java (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/parser/builder/ElementBuilder.java Tue May 23 20:38:04 2006 @@ -22,9 +22,17 @@ import java.util.Iterator; import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.shale.clay.config.beans.ActionListenerBean; import org.apache.shale.clay.config.beans.AttributeBean; import org.apache.shale.clay.config.beans.ComponentBean; +import org.apache.shale.clay.config.beans.ConfigBean; +import org.apache.shale.clay.config.beans.ConfigBeanFactory; +import org.apache.shale.clay.config.beans.ConverterBean; import org.apache.shale.clay.config.beans.ElementBean; +import org.apache.shale.clay.config.beans.ValidatorBean; +import org.apache.shale.clay.config.beans.ValueChangeListenerBean; import org.apache.shale.clay.parser.Node; /** @@ -35,6 +43,15 @@ public class ElementBuilder extends Builder { /** + * <p>Common Logger utility class.</p> + */ + private static Log log; + static { + log = LogFactory.getLog(ElementBuilder.class); + } + + + /** * <p>Returns the <code>jsfid</code> from the target HTML * [EMAIL PROTECTED] org.apache.shale.clay.parser.Node}.</p> */ @@ -53,16 +70,127 @@ } /** + * <p>Adds a [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ConverterBean} + * to the <code>target</code> [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ElementBean} + * using the [EMAIL PROTECTED] org.apache.shale.clay.parser.Node} as the input source.</p> + */ + protected void addConverter(Node node, ElementBean target) { + ConverterBean targetConverter = new ConverterBean(); + + String jsfid = (String) node.getAttributes().get("jsfid"); + targetConverter.setJsfid(jsfid); + + // resolve inheritance and attribute overrides + realizeComponent(node, targetConverter); + //attach to the target element + target.addConverter(targetConverter); + + } + + + /** + * <p>Adds a [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ValidatorBean} + * to the <code>target</code> [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ElementBean} + * using the [EMAIL PROTECTED] org.apache.shale.clay.parser.Node} as the input source.</p> + */ + protected void addValidator(Node node, ElementBean target) { + ValidatorBean targetValidator = new ValidatorBean(); + + String jsfid = (String) node.getAttributes().get("jsfid"); + targetValidator.setJsfid(jsfid); + + // resolve inheritance and attribute overrides + realizeComponent(node, targetValidator); + //attach to the target element + target.addValidator(targetValidator); + + } + + /** + * <p>Adds an [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ActionListenerBean} + * to the <code>target</code> [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ElementBean} + * using the [EMAIL PROTECTED] org.apache.shale.clay.parser.Node} as the input source.</p> + */ + protected void addActionListener(Node node, ElementBean target) { + ActionListenerBean targetActionListener = new ActionListenerBean(); + + String jsfid = (String) node.getAttributes().get("jsfid"); + targetActionListener.setJsfid(jsfid); + + // resolve inheritance and attribute overrides + realizeComponent(node, targetActionListener); + //attach to the target element + target.addActionListener(targetActionListener); + + } + + /** + * <p>Adds a [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ActionListenerBean} + * to the <code>target</code> [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ElementBean} + * using the [EMAIL PROTECTED] org.apache.shale.clay.parser.Node} as the input source.</p> + */ + protected void addValueChangeListener(Node node, ElementBean target) { + ValueChangeListenerBean targetValueChangeListener = new ValueChangeListenerBean(); + + String jsfid = (String) node.getAttributes().get("jsfid"); + targetValueChangeListener.setJsfid(jsfid); + + // resolve inheritance and attribute overrides + realizeComponent(node, targetValueChangeListener); + //attach to the target element + target.addValueChangeListener(targetValueChangeListener); + } + + + /** + * <p>Realizes the inheritance of the <code>target</code> + * [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ComponentBean} and + * and then applies attributes that are optionally nested + * under the <code>node</code>.</p> + */ + protected void realizeComponent(Node node, ComponentBean target) { + // lookup the ConfigBean that handles the id + ConfigBean config = ConfigBeanFactory.findConfig(target.getJsfid()); + + try { + //assign the parent + config.assignParent(target); + // resolve inheritance + config.realizingInheritance(target); + } catch (RuntimeException e) { + log.error(e); + throw new RuntimeException( + messages.getMessage("parser.unresolved", + new Object[] {node.getToken(), node.getToken().getRawText()})); + } + + //look for attributes + Iterator ci = node.getChildren().iterator(); + while (ci.hasNext()) { + Node child = (Node) ci.next(); + if (child.isWellFormed() && child.getName() != null + && child.getName().equals("attributes")) { + + addAttributes(child, target); + } + } + + } + + + /** * <p>Looks for <set/> nodes within a <attributes> node and * converting them to [EMAIL PROTECTED] org.apache.shale.clay.config.beans.AttributeBean}'s - * on the <code>target</code> [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ElementBean}. + * on the <code>target</code> [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ComponentBean}. * </p> */ - protected void addAttributes(Node attributesNode, ElementBean target) { + protected void addAttributes(Node attributesNode, ComponentBean target) { Iterator ci = attributesNode.getChildren().iterator(); while (ci.hasNext()) { Node child = (Node) ci.next(); - if (child.getName() != null && child.getName().equals("set")) { + if (child.isWellFormed() && 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"); @@ -91,7 +219,9 @@ Iterator si = symbolsNode.getChildren().iterator(); while (si.hasNext()) { Node child = (Node) si.next(); - if (child.getName() != null && child.getName().equals("set")) { + if (child.isWellFormed() && child.getName() != null + && child.getName().equals("set")) { + String name = (String) child.getAttributes().get("name"); String value = (String) child.getAttributes().get("value"); @@ -101,13 +231,15 @@ } } + + /** * <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 [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ElementBean}.</p> */ protected void encodeBegin(Node node, ElementBean target, ComponentBean root) { - super.encodeBegin(node, target, root); + super.encodeBegin(node, target, root); List deleteList = new ArrayList(); Iterator ci = node.getChildren().iterator(); @@ -120,6 +252,18 @@ } else if (child.getName().equals("symbols")) { addSymbols(child, target); deleteList.add(child); + } else if (child.getName().equals("converter")) { + addConverter(child, target); + deleteList.add(child); + } else if (child.getName().equals("validator")) { + addValidator(child, target); + deleteList.add(child); + } else if (child.getName().equals("actionListener")) { + addActionListener(child, target); + deleteList.add(child); + } else if (child.getName().equals("valueChangeListener")) { + addValueChangeListener(child, target); + deleteList.add(child); } } else { // remove white space @@ -132,7 +276,36 @@ node.getChildren().remove(ci.next()); } + + /** + * <p>This method is overridden to look for a <code>renderId</code> + * attribute in the [EMAIL PROTECTED] org.apache.shale.clay.parser.Node}. + * If one exists, it is applied to the target + * [EMAIL PROTECTED] org.apache.shale.clay.config.beans.ElementBean}. The + * super class [EMAIL PROTECTED] Builder} generates a unique id by default. + * The clay namespace HTML nodes can override the renderId to + * allow overridding of nested elements.</p> + */ + public ElementBean createElement(Node node) { + ElementBean target = super.createElement(node); + String renderId = null; + if ((renderId = (String) node.getAttributes().get("renderId")) != null) { + Integer id = null; + try { + id = Integer.valueOf(renderId); + } catch (NumberFormatException e) { + log.error(e); + throw new RuntimeException( + messages.getMessage("parser.unresolved", + new Object[] {node.getToken(), node.getToken().getRawText()})); + } + if (id != null) + target.setRenderId(id.intValue()); + } + + return target; + } /** * <p> 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=409062&r1=409061&r2=409062&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 Tue May 23 20:38:04 2006 @@ -261,7 +261,7 @@ // 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() { + public void testLoadXHTMLNamespaceFile1() { //loads the default and the custom address config file loadConfigFile("/org/apache/shale/clay/config/address-config.xml"); @@ -278,6 +278,25 @@ } + // 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 testLoadXHTMLNamespaceFile3() { + + //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/address3.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); + } + + } Added: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address3.html URL: http://svn.apache.org/viewvc/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address3.html?rev=409062&view=auto ============================================================================== --- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address3.html (added) +++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address3.html Tue May 23 20:38:04 2006 @@ -0,0 +1,169 @@ +<form> + <table xmlns:clay="http://struts.apache.org/dtds/shale-clay-config"> + <tr> + <td> + <clay:element jsfid="baseLabel"> + <clay:attributes> + <clay:set name="value" value="Street 1:"/> + <clay:set name="for" value="street1"/> + </clay:attributes> + </clay:element> + </td> + <td> + <clay:element jsfid="streetInput" id="street1"> + <clay:attributes> + <clay:set name="value" value="[EMAIL PROTECTED]" /> + <clay:set name="required" value="true" /> + <clay:set name="size" value="45"/> + </clay:attributes> + </clay:element> + </td> + <td> + <clay:element jsfid="baseMessage"> + <clay:attributes> + <clay:set name="for" value="street1"/> + </clay:attributes> + </clay:element> + </td> + </tr> + <tr> + <td> + <clay:element jsfid="baseLabel"> + <clay:attributes> + <clay:set name="value" value="Street 2:"/> + <clay:set name="for" value="street2"/> + </clay:attributes> + </clay:element> + </td> + <td> + <clay:element jsfid="streetInput" id="street2"> + <clay:attributes> + <clay:set name="value" value="[EMAIL PROTECTED]"/> + <clay:set name="required" value="true"/> + <clay:set name="size" value="45"/> + </clay:attributes> + </clay:element> + </td> + <td> + <clay:element jsfid="baseMessage"> + <clay:attributes> + <clay:set name="for" value="street2"/> + </clay:attributes> + </clay:element> + </td> + </tr> + <tr> + <td> + <clay:element jsfid="baseLabel"> + <clay:attributes> + <clay:set name="value" value="City:"/> + <clay:set name="for" value="city"/> + </clay:attributes> + </clay:element> + </td> + <td> + <clay:element jsfid="inputText" id="city"> + <clay:attributes> + <clay:set name="value" value="[EMAIL PROTECTED]"/> + <clay:set name="size" value="25"/> + <clay:set name="maxlength" value="30"/> + <clay:set name="required" value="true"/> + </clay:attributes> + </clay:element> + </td> + <td> + <clay:element jsfid="baseMessage"> + <clay:attributes> + <clay:set name="for" value="city"/> + </clay:attributes> + </clay:element> + </td> + </tr> + <tr> + <td> + <clay:element jsfid="stateLabel" extends="baseLabel"> + <clay:attributes> + <clay:set name="value" value="State:"/> + <clay:set name="for" value="state"/> + </clay:attributes> + </clay:element> + </td> + <td> + <clay:element jsfid="selectOneMenu" id="state"> + <clay:attributes> + <clay:set name="value" value="[EMAIL PROTECTED]"/> + <clay:set name="required" value="true"/> + </clay:attributes> + + <clay:element renderId="0" jsfid="selectItem"> + <clay:attributes> + <clay:set name="itemLabel" value="Colorado"/> + <clay:set name="itemValue" value="CO"/> + </clay:attributes> + </clay:element> + <clay:element renderId="1" jsfid="selectItem"> + <clay:attributes> + <clay:set name="itemLabel" value="Illinois"/> + <clay:set name="itemValue" value="IL"/> + </clay:attributes> + </clay:element> + </clay:element> + </td> + <td> + <clay:element jsfid="baseMessage"> + <clay:attributes> + <clay:set name="for" value="state"/> + </clay:attributes> + </clay:element> + </td> + </tr> + <tr> + <td> + <clay:element jsfid="baseLabel"> + <clay:attributes> + <clay:set name="value" value="Zip:"/> + <clay:set name="for" value="zip"/> + </clay:attributes> + </clay:element> + </td> + <td> + <clay:element id="zip" jsfid="inputText"> + <clay:attributes> + <clay:set name="value" value="[EMAIL PROTECTED]"/> + <clay:set name="maxlength" value="9"/> + <clay:set name="size" value="9"/> + <clay:set name="valueChangeListener" value="[EMAIL PROTECTED]"/> + </clay:attributes> + + <clay:converter jsfid="integerConverter" /> + <clay:validator jsfid="longRangeValidator"> + <clay:attributes> + <clay:set name="minimum" value="80000" /> + <clay:set name="maximum" value="80125" /> + </clay:attributes> + </clay:validator> + <clay:valueChangeListener jsfid="testValueChangeListener"/> + </clay:element> + </td> + <td> + <clay:element jsfid="zipMessage" extends="baseMessage"> + <clay:attributes> + <clay:set name="for" value="zip"/> + </clay:attributes> + </clay:element> + </td> + </tr> + <tr> + <td colspan="3"> + <clay:element jsfid="commandButton"> + <clay:attributes> + <clay:set name="value" value="Save" /> + <clay:set name="action" value="[EMAIL PROTECTED]"/> + <clay:set name="actionListener" value="[EMAIL PROTECTED]"/> + </clay:attributes> + <clay:actionListener jsfid="testActionListener"/> + </clay:element> + </td> + </tr> + </table> +</form> \ No newline at end of file Propchange: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address3.html ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/address3.html ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL