Author: gvanmatre Date: Fri Oct 21 13:30:22 2005 New Revision: 327264 URL: http://svn.apache.org/viewcvs?rev=327264&view=rev Log: Added a check for duplicate component ids within the same naming container. This lifting is done by the JSP tags in the RI.
Added: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/duplicate1.html struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/duplicate2.html Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayTemplateParser.java struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBean.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/Bundle.properties URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties?rev=327264&r1=327263&r2=327264&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/Bundle.properties Fri Oct 21 13:30:22 2005 @@ -114,14 +114,16 @@ realizing.inheritance=Realizing heritage $:-< realizing.inheritance.exception=Runtime exception caught realizing inheritance resolve.inheritance.end=Inheritance resolved @:-) -missing.componentType.exception=Missing componentType {0} -circular.inheritance.exception=Circular inheritance detected {0} -circular.composition.exception=Circular composition detected {0} +missing.componentType.exception=Missing componentType {0}. +duplicate.componentid.exception=A duplicate component id ({0}) was found within the same naming container ({1}). +circular.inheritance.exception=Circular inheritance detected {0}. +circular.composition.exception=Circular composition detected {0}. circular.child.parent.same.exception=Circular association detected; an element ({0}) cannot be associated with ({1}). A component cannot be an inherited and composition parent to the same child. circular.child.extends.same.parent.exception=Circular composition detected; contained element ({0}) cannot inherit from owning parent component ({1}). jsfid.notfound=The component identified by jsfid {0} could not be found. config.notloaded=ConfigBean is not loaded to handle a component identified by jsfid {0}. file.notfound=Unable to find file {0}. If this is a full HTML or XML view, check your navigation rules. +check.tree=Checking for duplicate component ids within a naming container ({0}) #:-< #org.apache.shale.clay.config.beans.TemplateConfigBean loading.template=Loading clay HTML template {0} Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayTemplateParser.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayTemplateParser.java?rev=327264&r1=327263&r2=327264&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayTemplateParser.java (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/ClayTemplateParser.java Fri Oct 21 13:30:22 2005 @@ -126,6 +126,10 @@ buffer = null; ri = null; + //verify there is not a duplicate component id within a naming + //container. + config.checkTree(root); + return root; } Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java?rev=327264&r1=327263&r2=327264&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ComponentConfigBean.java Fri Oct 21 13:30:22 2005 @@ -355,6 +355,11 @@ throw e1; } + //check to make sure that there is not a duplicate component id + //within the same naming container. + checkTree(b); + + b = null; e = null; } @@ -1164,5 +1169,85 @@ return wasDirty; } + + /** + * <p>A static string array of faces component types that are naming + * containers.</p> + */ + protected static final String[] NAMING_CONTAINER_TYPES = { + "javax.faces.HtmlForm", + "javax.faces.HtmlDataTable", + "org.apache.shale.clay.component.Clay", + "org.apache.shale.Subview", + "javax.faces.NamingContainer"}; + + /** + * <p>Checks the <code>componentType</code> against the <code>NAMING_CONTAINER_TYPES</code> + * list to determine if it is a naming container. Component id's must be unique within a + * naming container. Returns a <code>true</code> value if the <code>componentType</code> + * is a naming container; otherwise, returns <code>false</code>.</p> + */ + protected boolean isNamingContainer(String componentType) { + boolean flag = false; + for (int i = 0; i < NAMING_CONTAINER_TYPES.length; i++) { + if (NAMING_CONTAINER_TYPES[i].equals(componentType)) { + flag = true; + break; + } + } + + return flag; + } + + + /** + * <p>Recursively walks the tree of component metadata verifying + * there is not a duplicate component id within a naming container. + * A root [EMAIL PROTECTED] ComponentBean} is passed as a single parameter. + * The overloaded <code>checkTree(List, ComponentBean)</code> is + * invoked to process components under a naming container.</p> + */ + public void checkTree(ComponentBean b) { + if (log.isDebugEnabled()) + log.debug(messages.getMessage("check.tree", new Object[] {b.getComponentType()})); + + List componentIds = new ArrayList(); + checkTree(componentIds, b); + componentIds.clear(); + componentIds = null; + } + + + /** + * <p>Verifies there is not a duplicate component id within a naming container. + * A list of accumulating <code>componentIds</code> and a + * root [EMAIL PROTECTED] ComponentBean} is passed as parameters. A runtime + * exception is thrown if a duplicate id is encountered.</p> + */ + protected void checkTree(List componentIds, ComponentBean b) { + + //check fo duplicate component id's + String id = b.getId(); + if (id != null) { + if (componentIds.contains(id)) { + throw new NullPointerException(messages.getMessage("duplicate.componentid.exception", + new Object[] {id, b})); + } else { + componentIds.add(id); + } + } + + Iterator ci = b.getChildrenIterator(); + while (ci.hasNext()) { + ComponentBean c = (ComponentBean) ci.next(); + if (isNamingContainer(c.getComponentType())) { + checkTree(c); + } else { + checkTree(componentIds, c); + } + } + + } + } Modified: struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBean.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBean.java?rev=327264&r1=327263&r2=327264&view=diff ============================================================================== --- struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBean.java (original) +++ struts/shale/trunk/clay-plugin/src/java/org/apache/shale/clay/config/beans/ConfigBean.java Fri Oct 21 13:30:22 2005 @@ -107,5 +107,12 @@ * files were reloaded.</p> */ public boolean refresh(boolean forceReload); + + /** + * <p>Verifies there is not a duplicate component id within a naming container. + * A root [EMAIL PROTECTED] ComponentBean} is passed as a single parameter.</p> + */ + public void checkTree(ComponentBean b); + } Modified: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/ConfigTestCase.java?rev=327264&r1=327263&r2=327264&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 Fri Oct 21 13:30:22 2005 @@ -606,4 +606,28 @@ } + // test duplicate id check + public void testDuplicateComponentIds() { + + // loads the default and the custom address config file + loadConfigFile("org/apache/shale/clay/config/address-config.xml"); + + try { + ComponentBean bean = htmlTemplateConfigBean.getElement("org/apache/shale/clay/config/duplicate1.html"); + assertTrue("Duplicate component check", false); + } catch (RuntimeException e) { + assertTrue( + "Duplicate component check", + e.getMessage().startsWith("A duplicate component id (street1) was found within the same naming container")); + } + + + ComponentBean bean = htmlTemplateConfigBean.getElement("org/apache/shale/clay/config/duplicate2.html"); + assertNotNull("Duplicate component check", bean); + + + } + + + } Added: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/duplicate1.html URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/duplicate1.html?rev=327264&view=auto ============================================================================== --- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/duplicate1.html (added) +++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/duplicate1.html Fri Oct 21 13:30:22 2005 @@ -0,0 +1,3 @@ +<input id=street1 value="#{managed-bean-name.street1}" type=text size=45> +<input id=street1 value="#{managed-bean-name.street1}" type=text size=45> + Added: struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/duplicate2.html URL: http://svn.apache.org/viewcvs/struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/duplicate2.html?rev=327264&view=auto ============================================================================== --- struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/duplicate2.html (added) +++ struts/shale/trunk/clay-plugin/src/test/org/apache/shale/clay/config/duplicate2.html Fri Oct 21 13:30:22 2005 @@ -0,0 +1,10 @@ +<input id=street1 value="#{managed-bean-name.street1}" type=text size=45> +<form> + <input id=street1 value="#{managed-bean-name.street1}" type=text size=45> + <span jsfid="clay" allowBody="true"> + <input id=street1 value="#{managed-bean-name.street1}" type=text size=45> + </span> + <span jsfid="subview" allowBody="true"> + <input id=street1 value="#{managed-bean-name.street1}" type=text size=45> + </span> +</form> \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]