Modified: shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/taglib/ClayTag.java URL: http://svn.apache.org/viewvc/shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/taglib/ClayTag.java?rev=419799&r1=419798&r2=419799&view=diff ============================================================================== --- shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/taglib/ClayTag.java (original) +++ shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/taglib/ClayTag.java Thu Jul 6 21:34:01 2006 @@ -21,22 +21,15 @@ import javax.faces.el.ValueBinding; import javax.faces.webapp.UIComponentBodyTag; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.shale.clay.component.Clay; public class ClayTag extends UIComponentBodyTag { - - /** - * <p>Common logging utility instance.</p> - */ - public static Log log = LogFactory.getLog(ClayTag.class); - + /** * <p>Represents the meta-component to build the subtree on.</p> */ private String jsfid = null; - + /** * <p>The name of the managed bean instance in the faces configuration file that * should be bound to this view composition. The literal "@managed-bean-name" @@ -45,7 +38,7 @@ * </p> */ private String managedBeanName = null; - + /** * <p>A method event that conforms to the standard <code>validator</code> * attribute. This event will get fired before the sub component tree is @@ -53,16 +46,18 @@ * </p> */ private String shapeValidator = null; - + /** * <p>Returns the expression literal defining the validator event method * binding. * </p> + * + * @return method binding expression */ public String getShapeValidator() { return shapeValidator; } - + /** * <p>Sets the expression literal defining the validator event method binding. * </p> @@ -72,15 +67,17 @@ public void setShapeValidator(String shapeValidator) { this.shapeValidator = shapeValidator; } - - + + /** * <p>Gets the display Element identifier to be rendered.</p> + * + * @return jsfid */ public String getJsfid() { return jsfid; } - + /** * <p>Sets the identifier defining component metadata. * </p> @@ -90,21 +87,23 @@ public void setJsfid(String jsfid) { this.jsfid = jsfid; } - + /** * <p>Gets the name of the managed bean that is dynamically resolved * using a token replacement before binding the value expression. * If not explicitly set, it will default to the literal <code>UNKNOWN</code> * </p> + * + * @return managed bean name symbol */ public String getManagedBeanName() { if (managedBeanName == null || managedBeanName.length() == 0) { return "UNKNOWN"; } - + return managedBeanName; } - + /** * <p> Name of the managed bean that is dynamically resolved. The literal * string "managed-bean-name" is replaced with the value of this @@ -116,19 +115,20 @@ public void setManagedBeanName(String managedBeanName) { this.managedBeanName = managedBeanName; } - - + + /** * <p> Returns the logical component name registered in the faces config * for the [EMAIL PROTECTED] org.apache.shale.clay.component.Clay} component. * </p> * + * @return component type * @see javax.faces.webapp.UIComponentTag#getComponentType() */ public String getComponentType() { return "org.apache.shale.clay.component.Clay"; } - + /** * <p>Returns the render registered for the component. The * [EMAIL PROTECTED] org.apache.shale.clay.component.Clay} component doesn't @@ -136,12 +136,13 @@ * it's children. * </p> * + * @return <code>null</code> * @see javax.faces.webapp.UIComponentTag#getRendererType() */ public String getRendererType() { return null; } - + /** * <p>This method is invoked by the super and its purpose it * to push tag attributes to corresponding component property @@ -152,45 +153,35 @@ */ protected void setProperties(UIComponent component) { super.setProperties(component); - + Clay c = (Clay) component; FacesContext facesContext = getFacesContext(); - + if (getJsfid() != null) { - /* FIXME - "id" attributes in JSF components are not value binding enabled, - * so do not support it here either - if(isValueReference(getJsfid())) { - ValueBinding valueBinding = facesContext.getApplication().createValueBinding(getJsfid()); - Object value = valueBinding.getValue(facesContext); - c.setJsfid((value != null) ? value.toString() : null); - - } else { - c.setJsfid(getJsfid()); - } - */ c.setJsfid(getJsfid()); - + } - - + + if (getManagedBeanName() != null) { c.setManagedBeanName(getManagedBeanName()); - - if(isValueReference(getManagedBeanName())) { + + if (isValueReference(getManagedBeanName())) { ValueBinding valueBinding = facesContext.getApplication().createValueBinding(getManagedBeanName()); Object value = valueBinding.getValue(facesContext); c.setManagedBeanName((value != null) ? value.toString() : null); - + } else { c.setManagedBeanName(getManagedBeanName()); } - + } - - - if (getShapeValidator() != null) + + + if (getShapeValidator() != null) { c.setShapeValidator(getShapeValidator()); - + } + } }
Modified: shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/taglib/ClayTagValidator.java URL: http://svn.apache.org/viewvc/shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/taglib/ClayTagValidator.java?rev=419799&r1=419798&r2=419799&view=diff ============================================================================== --- shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/taglib/ClayTagValidator.java (original) +++ shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/taglib/ClayTagValidator.java Thu Jul 6 21:34:01 2006 @@ -12,7 +12,7 @@ * 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$ */ @@ -32,31 +32,31 @@ import org.apache.shale.util.Messages; /** - * <p>Validates the JSP page for the clay namespace, + * <p>Validates the JSP page for the clay namespace, * "http://struts.apache.org/shale/clay-plugin". This tag - * validator checks to make sure that there are not any nested - * tags under the [EMAIL PROTECTED] ClayTag} with the exception of the - * [EMAIL PROTECTED] SymbolTag}.</p> + * validator checks to make sure that there are not any nested + * tags under the [EMAIL PROTECTED] ClayTag} with the exception of the + * [EMAIL PROTECTED] SymbolTag}.</p> */ public class ClayTagValidator extends TagLibraryValidator { private static final String CLAY_URI_NAMESPACE = "http://struts.apache.org/shale/clay-plugin"; - + /** * <p>Message resources for this class.</p> */ private static Messages messages = new Messages("org.apache.shale.clay.Bundle", ClayTagValidator.class.getClassLoader()); - + /** * <p>Loads the <code>page</code> content into a <code>StringBuffer</code>.</p> */ protected StringBuffer loadTemplate(PageData page) throws IOException { - - + + StringBuffer buff = new StringBuffer(); InputStream inputStream = page.getInputStream(); - + int c = 0; done: while (true) { c = inputStream.read(); @@ -64,15 +64,15 @@ buff.append((char) c); else break done; - + } return buff; - + } /** - * <p>Creates a <code>ValidationMessage</code> for a [EMAIL PROTECTED] ClayTag} containing + * <p>Creates a <code>ValidationMessage</code> for a [EMAIL PROTECTED] ClayTag} containing * a child of anything other than the [EMAIL PROTECTED] SymbolTag}.</p> */ private ValidationMessage getMessage(String prefix, Node clayNode, Node childNode) { @@ -83,8 +83,8 @@ String message = messages.getMessage("invalid.nested.tag", args); return new ValidationMessage(jspid, message); } - - + + /** * <p>Checks the child nodes of the <code>clayNode</code> verifying that * only the symbol node is present.</p> @@ -93,64 +93,64 @@ List children = clayNode.getChildren(); next: for (int i = 0; i < children.size(); i++) { Node child = (Node) children.get(i); - if ((!child.isComment() && !child.isCdata()) && child.isWellFormed()) { + if ((!child.isComment() && !child.isCdata()) && child.isWellFormed()) { if (child.getQname() != null && child.getName() != null) { - - if (child.getQname().equals("jsp") && child.getName().equals("text")) { + + if (child.getQname().equals("jsp") && child.getName().equals("text")) { continue next; } else if (!child.getName().equals("symbol") || !prefix.equals(child.getQname())) { - messages.add(getMessage(prefix, clayNode, child)); + messages.add(getMessage(prefix, clayNode, child)); } } - + } } } - + /** - * <p>Recursively walks the parsed document looking for clay component nodes. The children + * <p>Recursively walks the parsed document looking for clay component nodes. The children * are checked to make sure the symbol tag is the only valid child tag.</p> */ private void validateClayTags(String prefix, Node node, List messages) { - if ((!node.isComment() && !node.isCdata()) && node.isWellFormed() - && node.getName() != null && node.getName().equals("clay") + if ((!node.isComment() && !node.isCdata()) && node.isWellFormed() + && node.getName() != null && node.getName().equals("clay") && node.getQname() != null && node.getQname().equals(prefix)) { - + checkForInvalidNestedTags(prefix, node, messages); return; } - + List children = node.getChildren(); for (int i = 0; i < children.size(); i++) { Node child = (Node) children.get(i); validateClayTags(prefix, child, messages); } - + } - + /** - * <p>Validates the page for a directive with a uri of + * <p>Validates the page for a directive with a uri of * "<strong>http://struts.apache.org/shale/clay-plugin</strong>". - */ + */ public ValidationMessage[] validate(String prefix, String uri, PageData page) { List messages = new ArrayList(); - + if (uri != null && CLAY_URI_NAMESPACE.equals(uri)) { try { StringBuffer buff = loadTemplate(page); Parser p = new Parser(); List roots = p.parse(buff); - + for (int i = 0; i < roots.size(); i++) { - Node node = (Node) roots.get(i); - validateClayTags(prefix, node, messages); + Node node = (Node) roots.get(i); + validateClayTags(prefix, node, messages); } - + } catch (IOException e) { messages.add(new ValidationMessage(null, e.getMessage())); } } - + if (messages.isEmpty()) return null; else { @@ -158,7 +158,7 @@ messages.toArray(validationMessages); return validationMessages; } - + } } Modified: shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/taglib/SymbolTag.java URL: http://svn.apache.org/viewvc/shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/taglib/SymbolTag.java?rev=419799&r1=419798&r2=419799&view=diff ============================================================================== --- shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/taglib/SymbolTag.java (original) +++ shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/taglib/SymbolTag.java Thu Jul 6 21:34:01 2006 @@ -45,7 +45,7 @@ */ private static Messages messages = new Messages( "org.apache.shale.clay.Bundle", SymbolTag.class.getClassLoader()); - + /** * <p>The <code>name</code> of the symbol.</p> */ @@ -96,9 +96,9 @@ * <p>Finds the parent component and adds the symbol to the * Clay component's symbol table. The parent has to be a [EMAIL PROTECTED] Clay} component. * </p> - * + * * @return next transition - * @exception JspException + * @exception JspException */ public int doStartTag() throws JspException { UIComponentTag parentTag = UIComponentTag.getParentUIComponentTag(pageContext); Modified: shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/ClayAmalgam.java URL: http://svn.apache.org/viewvc/shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/ClayAmalgam.java?rev=419799&r1=419798&r2=419799&view=diff ============================================================================== --- shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/ClayAmalgam.java (original) +++ shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/ClayAmalgam.java Thu Jul 6 21:34:01 2006 @@ -41,28 +41,28 @@ import org.apache.shale.util.Tags; /** - * <p>This class is a mix of runtime utilities for the - * [EMAIL PROTECTED] org.apache.shale.clay.component.Clay} component. - * It is loaded as a managed bean in application scope by - * the clay component's registration.</p> + * <p>This class is a mix of runtime utilities for the + * [EMAIL PROTECTED] org.apache.shale.clay.component.Clay} component. + * It is loaded as a managed bean in application scope by + * the clay component's registration.</p> */ public class ClayAmalgam { - + /** * <p>Message resources for this class.</p> */ private static Messages messages = new Messages("org.apache.shale.clay.Bundle", ClayConfigureListener.class.getClassLoader()); - + /** - * <p>Shale tag helper class that contains utility methods for setting + * <p>Shale tag helper class that contains utility methods for setting * component binding and method properties.</p> */ private Tags tagUtils = new Tags(); - - + + /** - * <p>Replaces tokens in the <code>document</code> with + * <p>Replaces tokens in the <code>document</code> with * matching tokens in the <code>context</code>.</p> */ protected void replace(StringBuffer document, Map context) { @@ -103,7 +103,7 @@ encodeMap.put("<", "<"); encodeMap.put(">", ">"); encodeMap.put("}", "}"); - encodeMap.put("{", "{"); + encodeMap.put("{", "{"); } /** @@ -127,7 +127,7 @@ decodeMap.put("<", "<"); decodeMap.put(">", ">"); decodeMap.put("}", "}"); - decodeMap.put("{", "{"); + decodeMap.put("{", "{"); } /** @@ -138,109 +138,109 @@ replace(buff, decodeMap); return buff.toString(); } - - + + /** - * <p>This is a method binding "validator" signature that can be bound to the + * <p>This is a method binding "validator" signature that can be bound to the * <code>shapeValidator</code> attribute of the [EMAIL PROTECTED] org.apache.shale.clay.component.Clay} * component. It expects that the <code>value</code> attribute will contain an html string that * represents an HTML node. The value will be encode or decode depending on the value of the - * <code>escapeXml</code> optional attribute. The default is "false". </p> + * <code>escapeXml</code> optional attribute. The default is "false". </p> */ public void clayOut(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object displayElementRoot) { - + if (!(displayElementRoot instanceof ComponentBean) || !(component instanceof Clay)) { - throw new RuntimeException(messages.getMessage("invalid.binding", new Object[] {"clayOut"})); + throw new RuntimeException(messages.getMessage("invalid.binding", new Object[] {"clayOut"})); } - + ComponentBean text = (ComponentBean) displayElementRoot; Clay clay = (Clay) component; String value = (String) clay.getAttributes().get("value"); value = tagUtils.evalString(value); if (value == null) { - throw new IllegalArgumentException(messages.getMessage("missing.attribute", new Object[] {"value", "clayOut"})); + throw new IllegalArgumentException(messages.getMessage("missing.attribute", new Object[] {"value", "clayOut"})); } - + boolean escapeXml = false; String tmp = (String) clay.getAttributes().get("escapeXml"); if (tmp != null) { escapeXml = tagUtils.evalBoolean(tmp).booleanValue(); } - + if (!escapeXml) value = decode(value); - else + else value = encode(value); - + text.setJsfid("outputText"); text.setComponentType("javax.faces.HtmlOutputText"); - + // add a value attribute AttributeBean attr = new AttributeBean(); attr.setName("value"); attr.setValue(value); text.addAttribute(attr); - + // add a escape attribute attr = new AttributeBean(); attr.setName("escape"); attr.setValue(Boolean.FALSE.toString()); text.addAttribute(attr); - + // add a isTransient attribute attr = new AttributeBean(); attr.setName("isTransient"); attr.setValue(Boolean.TRUE.toString()); text.addAttribute(attr); - + } /** - * <p>This is a method binding "validator" signature that can be bound to the + * <p>This is a method binding "validator" signature that can be bound to the * <code>shapeValidator</code> attribute of the [EMAIL PROTECTED] org.apache.shale.clay.component.Clay} * component. It expects that the <code>url</code> attribute will contain the file to import - * relative to the web context root. The content of the file will be encode or decode depending + * relative to the web context root. The content of the file will be encode or decode depending * on the value of the <code>escapeXml</code> optional attribute. The default doesn't apply - * any encoding. </p> + * any encoding. </p> */ public void clayImport(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object displayElementRoot) { - + if (!(displayElementRoot instanceof ComponentBean) || !(component instanceof Clay)) { - throw new RuntimeException(messages.getMessage("invalid.binding", new Object[] {"clayImport"})); + throw new RuntimeException(messages.getMessage("invalid.binding", new Object[] {"clayImport"})); } - + ComponentBean text = (ComponentBean) displayElementRoot; Clay clay = (Clay) component; String url = (String) clay.getAttributes().get("url"); if (url == null) { - throw new IllegalArgumentException(messages.getMessage("missing.attribute", new Object[] {"url", "clayImport"})); + throw new IllegalArgumentException(messages.getMessage("missing.attribute", new Object[] {"url", "clayImport"})); } url = tagUtils.evalString(url); - + boolean escapeXml = true; String escAttribute = (String) clay.getAttributes().get("escapeXml"); if (escAttribute != null) { escapeXml = tagUtils.evalBoolean(escAttribute).booleanValue(); } - + StringBuffer value = new StringBuffer(); StringBuffer buff = new StringBuffer(url); - - //look for a classpath prefix. + + //look for a classpath prefix. int i = -1; - if ((i = buff.indexOf(Globals.CLASSPATH_PREFIX)) > -1) + if ((i = buff.indexOf(Globals.CLASSPATH_PREFIX)) > -1) buff.delete(0, i + Globals.CLASSPATH_PREFIX.length()); - + InputStream in = null; - + try { // if classpath prefix found, use the classloader if (i > -1) { @@ -274,49 +274,49 @@ try { in.close(); } catch (IOException e) {} - } + } } - + if (escAttribute != null) { if (!escapeXml) replace(value, decodeMap); - else + else replace(value, encodeMap); } - + text.setJsfid("outputText"); text.setComponentType("javax.faces.HtmlOutputText"); - + // add a value attribute AttributeBean attr = new AttributeBean(); attr.setName("value"); attr.setValue(value.toString()); text.addAttribute(attr); - + // add a escape attribute attr = new AttributeBean(); attr.setName("escape"); attr.setValue(Boolean.FALSE.toString()); text.addAttribute(attr); - + // add a isTransient attribute attr = new AttributeBean(); attr.setName("isTransient"); attr.setValue(Boolean.TRUE.toString()); text.addAttribute(attr); - } - + } + /** - * <p>This is a method binding "validator" signature that can be bound to the + * <p>This is a method binding "validator" signature that can be bound to the * <code>shapeValidator</code> attribute of the [EMAIL PROTECTED] org.apache.shale.clay.component.Clay} - * component. It expects four attributes value, bodyJsfid, var and scope. + * component. It expects four attributes value, bodyJsfid, var and scope. * The <code>value</code> attribute is like a dataTable. It should be a value binding expression - * that is a Map, List or Object[]. The <code>bodyJsfid</code> attribute is root of the + * that is a Map, List or Object[]. The <code>bodyJsfid</code> attribute is root of the * subtree that will be repeated in the for loop. The <code>var</code> attribute is the - * tag used to cache a Map of the bound objects. It will always be loaed in "session" - * scope. Limitation exists because the "shapeValidator" event is only called when the - * component is created. This means that you must take care in removing the <code>var</code> object + * tag used to cache a Map of the bound objects. It will always be loaed in "session" + * scope. Limitation exists because the "shapeValidator" event is only called when the + * component is created. This means that you must take care in removing the <code>var</code> object * from session scope.</p> */ public void clayForEach(javax.faces.context.FacesContext context, @@ -328,49 +328,49 @@ throw new RuntimeException(messages.getMessage("invalid.binding", new Object[] { "clayForEach" })); } - + Clay clay = (Clay) component; String value = (String) clay.getAttributes().get("value"); if (value == null) { - throw new IllegalArgumentException(messages.getMessage("missing.attribute", new Object[] {"value", "clayForEach"})); + throw new IllegalArgumentException(messages.getMessage("missing.attribute", new Object[] {"value", "clayForEach"})); } String bodyJsfid = (String) clay.getAttributes().get("bodyJsfid"); bodyJsfid = tagUtils.evalString(bodyJsfid); if (bodyJsfid == null) { - throw new IllegalArgumentException(messages.getMessage("missing.attribute", new Object[] {"bodyJsfid", "clayForEach"})); + throw new IllegalArgumentException(messages.getMessage("missing.attribute", new Object[] {"bodyJsfid", "clayForEach"})); } String var = (String) clay.getAttributes().get("var"); var = tagUtils.evalString(var); if (var == null) { - throw new IllegalArgumentException(messages.getMessage("missing.attribute", new Object[] {"var", "clayForEach"})); + throw new IllegalArgumentException(messages.getMessage("missing.attribute", new Object[] {"var", "clayForEach"})); } - + // lookup the ConfigBean that handles the bodyJsfid ConfigBean config = ConfigBeanFactory.findConfig(bodyJsfid); if (config == null) throw new NullPointerException(messages.getMessage("clay.config.notloaded")); - + //make sure it's parsed and cached ComponentBean b = config.getElement(bodyJsfid); if (b == null) throw new NullPointerException(messages.getMessage( "clay.jsfid.notfound", new Object[] { bodyJsfid })); - + ValueBinding vb = context.getApplication().createValueBinding(value); final Object valueList = vb.getValue(context); - + Map beans = new TreeMap(); int i = 0; Iterator vi = null; if (valueList == null) - vi = Collections.EMPTY_LIST.iterator(); - else if (valueList instanceof List) + vi = Collections.EMPTY_LIST.iterator(); + else if (valueList instanceof List) vi = ((List) valueList).iterator(); - else if (valueList instanceof Map) + else if (valueList instanceof Map) vi = ((Map) valueList).entrySet().iterator(); - else { + else { Object[] anArray = new Object[0]; if (anArray.getClass().isAssignableFrom(valueList.getClass())) { vi = new Iterator() { @@ -395,7 +395,7 @@ messages.getMessage("invalid.collectiontype", new Object[] {value})); } } - + if (vi != null) { while (vi.hasNext()) { //create a key for the beans map @@ -408,30 +408,30 @@ namingContainer.setRenderId(i); namingContainer.setJsfid("namingContainer"); namingContainer.setComponentType("javax.faces.NamingContainer"); - + //create a new nested bean ElementBean target = new ElementBean(); - target.setJsfid(bodyJsfid); + target.setJsfid(bodyJsfid); target.setExtends(bodyJsfid); target.setRenderId(i); config.assignParent(target); config.realizingInheritance(target); //prepend the var to the generated key - id.insert(0, var + "."); + id.insert(0, var + "."); SymbolBean symbol = new SymbolBean(); symbol.setName(Globals.MANAGED_BEAN_MNEMONIC); symbol.setValue(id.toString()); target.addSymbol(symbol); - - + + namingContainer.addChild(target); ((ComponentBean) displayElementRoot).addChild(namingContainer); } - + } - + context.getExternalContext().getSessionMap().put(var, beans); - + } } Modified: shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/PluggableLookupCommand.java URL: http://svn.apache.org/viewvc/shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/PluggableLookupCommand.java?rev=419799&r1=419798&r2=419799&view=diff ============================================================================== --- shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/PluggableLookupCommand.java (original) +++ shale/trunk/shale-clay/src/main/java/org/apache/shale/clay/utils/PluggableLookupCommand.java Thu Jul 6 21:34:01 2006 @@ -26,7 +26,7 @@ * If the catalog doesn't exist, it returns <code>true</code> if the * <code>optional</code> property in the super class is <code>true</code>. * If the catalog is not found and the command is not optional, it returns a - * <code>false</code> value. Otherwise, if the catalog exists, the super + * <code>false</code> value. Otherwise, if the catalog exists, the super * implementation is invoked.</p> * */ @@ -39,24 +39,24 @@ private boolean catalogExists() { String catalogName = getCatalogName(); if (catalogName == null) { - return false; - } + return false; + } CatalogFactory catalogFactory = CatalogFactory.getInstance(); - + return (catalogFactory.getCatalog(catalogName) != null); } - + /** - * <p>Adds an additional check to determine if the catalog name is loaded. - * If loaded, the super implementation is invoked. Otherwise, the chain + * <p>Adds an additional check to determine if the catalog name is loaded. + * If loaded, the super implementation is invoked. Otherwise, the chain * continues if the command is optional.</p> */ public boolean execute(Context context) throws Exception { if (!catalogExists()) { return !isOptional(); - } - + } + return super.execute(context); }
