Author: greddin Date: Thu Jul 6 11:10:00 2006 New Revision: 419638 URL: http://svn.apache.org/viewvc?rev=419638&view=rev Log: Ticket SB-21. Removed redundant and obsolete Tag Attributes.
Changed the semantics of the InsertTag to support only name, template, and type attributes among a few others. If type is specified it will be processed explicitly in that way. If type is not specified the tag will try to determine what type to use. Other tags removed redundant attributes and removed beanName, beanProperty, and beanScope attribute support. This assumes a Servlet 2.4 environment will now be required. Removed: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/AttributeToScopeTag.java Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/DefinitionTag.java struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/DefinitionTagSupport.java struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertTag.java struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTag.java struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tiles-core.tld Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/DefinitionTag.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/DefinitionTag.java?rev=419638&r1=419637&r2=419638&view=diff ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/DefinitionTag.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/DefinitionTag.java Thu Jul 6 11:10:00 2006 @@ -39,7 +39,7 @@ /** * Definition identifier. */ - private String id = null; + private String name = null; /** * Scope into which definition will be saved. @@ -63,8 +63,8 @@ */ public void release() { super.release(); - id = null; - page = null; + name = null; + template = null; scope = null; role = null; extendsDefinition = null; @@ -152,16 +152,17 @@ * Get the ID. * @return ID */ - public String getId() { - return id; + public String getName() { + return name; } /** * Set the ID. - * @param id New ID. + * + * @param name New ID. */ - public void setId(String id) { - this.id = id; + public void setName(String id) { + this.name = id; } /** @@ -213,8 +214,8 @@ } // Set definitions attributes - if (page != null) { - definition.setTemplate(page); + if (template != null) { + definition.setTemplate(template); } if (role != null) { @@ -229,7 +230,7 @@ * @throws JspException On errors processing tag. */ public int doEndTag() throws JspException { - TagUtils.setAttribute(pageContext, id, definition, scope); + TagUtils.setAttribute(pageContext, name, definition, scope); releaseInternal(); return EVAL_PAGE; Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/DefinitionTagSupport.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/DefinitionTagSupport.java?rev=419638&r1=419637&r2=419638&view=diff ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/DefinitionTagSupport.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/DefinitionTagSupport.java Thu Jul 6 11:10:00 2006 @@ -38,10 +38,11 @@ * Role associated to definition. */ protected String role; + /** - * Uri of page assoicated to this definition. + * JSP page that implements the definition. */ - protected String page; + protected String template; /** * Release class properties. @@ -51,7 +52,6 @@ controllerType = null; controllerName = null; role = null; - page = null; } /** @@ -151,41 +151,22 @@ this.role = role; } - /** - * Set the page. - * - * @param page Page. - */ - public void setPage(String page) { - this.page = page; - } - - /** - * Get the page. - * - * @return Page. - */ - public String getPage() { - return page; - } /** * Get the template. - * Same as getPage(). * * @return Template. */ public String getTemplate() { - return page; + return template; } /** * Set the template. - * Same as setPage(). * * @param template Template. */ public void setTemplate(String template) { - this.page = template; + this.template = template; } } Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertTag.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertTag.java?rev=419638&r1=419637&r2=419638&view=diff ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertTag.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/InsertTag.java Thu Jul 6 11:10:00 2006 @@ -78,26 +78,6 @@ protected String name = null; /** - * Name of attribute from which to read page name to include. - */ - protected String attribute = null; - - /** - * Name of bean used as entity to include. - */ - protected String beanName = null; - - /** - * Name of bean property, if any. - */ - protected String beanProperty = null; - - /** - * Scope of bean, if any. - */ - protected String beanScope = null; - - /** * Are errors ignored. This is the property for attribute 'ignore'. * Default value is false, which throw an exception. * Only 'attribute not found' errors are ignored. @@ -109,6 +89,12 @@ */ protected String definitionName = null; + /** + * Optional attribute to explicitly specify whether the thing being + * inserted is a(n) definition, attribute, or template. + */ + private String type = null; + /* Internal properties */ /** * Does the end tag need to be processed. @@ -138,17 +124,14 @@ public void release() { super.release(); - attribute = null; - beanName = null; - beanProperty = null; - beanScope = null; definitionName = null; flush = true; name = null; - page = null; + template = null; role = null; isErrorIgnored = false; + type = null; releaseInternal(); } @@ -196,20 +179,6 @@ } /** - * Set component. - */ - public void setComponent(String name) { - this.page = name; - } - - /** - * Set definition. - */ - public void setDefinition(String name) { - this.definitionName = name; - } - - /** * Get definition name. */ public String getDefinitionName() { @@ -217,55 +186,6 @@ } /** - * Set attribute. - */ - public void setAttribute(String value) { - this.attribute = value; - } - - /** - * Set bean name. - */ - public void setBeanName(String value) { - this.beanName = value; - } - - /** - * Get bean name. - */ - public String getBeanName() { - return beanName; - } - - /** - * Set bean property. - */ - public void setBeanProperty(String value) { - this.beanProperty = value; - } - - /** - * Get bean property. - */ - public String getBeanProperty() { - return beanProperty; - } - - /** - * Set bean scope. - */ - public void setBeanScope(String value) { - this.beanScope = value; - } - - /** - * Get bean scope. - */ - public String getBeanScope() { - return beanScope; - } - - /** * Set flush. */ public void setFlush(boolean flush) { @@ -465,46 +385,41 @@ /** * Process tag attribute and create corresponding tag handler. + * + * Supported types include <code>string</code>, <code>definition</code>, + * <code>atribute</code>, and <code>template</code> If type is string, + * the attribute value passed in will be printed directly to the PrintWriter. If + * type is definition the value will be processed as a Tiles definition. + * If type is attribute, the value will be processed as an attribute of + * the current definition. If type is template, the value will be a + * JSP include. + * */ public TagHandler createTagHandler() throws JspException { - // Check each tag attribute. - // page Url attribute must be the last checked because it can appears concurrently - // with others attributes. - if (definitionName != null) { - return processDefinitionName(definitionName); - } else if (attribute != null) { - return processAttribute(attribute); - } else if (beanName != null) { - return processBean(beanName, beanProperty, beanScope); - } else if (name != null) { + + if (type != null && type.length() > 0) { + // Type is specified. Process accordingly. + if (type.equalsIgnoreCase("string")) { + return new DirectStringHandler(name); + } else if (type.equalsIgnoreCase("definition")) { + return processDefinitionName(name); + } else if (type.equalsIgnoreCase("attribute")) { + return processAttribute(name); + } else if (type.equalsIgnoreCase("template")) { + return processUrl(name); + } else { + throw new JspException("Error - Incorrect type value \"" + type + "\"passed in."); + } + } else { + // Type is not specified. Try to determine. + if (name != null) { return processName(name); - } else if (page != null) { - return processUrl(page); + } else if (template != null) { + return processUrl(template); } else { - throw new JspException("Error - Tag Insert : At least one of the following attribute must be defined : template|page|attribute|definition|name|beanName. Check tag syntax"); - } - } - - /** - * Process an object retrieved as a bean or attribute. - * Object can be a typed attribute, a String, or anything else. - * If typed attribute, use associated type. - * Otherwise, apply toString() on object, and use returned string as a name. - * @throws JspException - Throws by underlying nested call to - * processDefinitionName() - */ - public TagHandler processObjectValue(Object value) throws JspException { - // First, check if value is one of the Typed Attribute - if (value instanceof ComponentAttribute) { - // We have a type => return appropriate IncludeType - return processTypedAttribute((ComponentAttribute) value); - - } else if (value instanceof ComponentDefinition) { - return processDefinition((ComponentDefinition) value); + throw new JspException("Error - Tag Insert : At least one of the following attribute must be defined : template|name. Check tag syntax"); } - - // Value must denote a valid String - return processAsDefinitionOrURL(value.toString()); + } } /** @@ -524,11 +439,11 @@ public TagHandler processName(String name) throws JspException { Object attrValue = getCurrentContext().getAttribute(name); - if (attrValue != null) { - return processObjectValue(attrValue); - } - - return processAsDefinitionOrURL(name); + if (attrValue != null && attrValue instanceof ComponentAttribute) { + return processTypedAttribute((ComponentAttribute) attrValue); + } else { + return processDefinitionName(name); + } } /** @@ -569,7 +484,7 @@ throw new JspException( "Error - Tag Insert : Can't get definition '" + definitionName - + "'. Check if this name exist in definitions factory.", ex); + + "'. Check if this name exists in definitions factory.", ex); } catch (FactoryNotFoundException ex) { throw new JspException(ex.getMessage()); @@ -600,7 +515,7 @@ throws JspException { // Declare local variable in order to not change Tag attribute values. String role = this.role; - String page = this.page; + String page = this.template; Controller controller = null; try { @@ -635,44 +550,6 @@ } /** - * Process a bean. - * Get bean value, eventually using property and scope. Found value is process by processObjectValue(). - * @param beanName Name of the bean - * @param beanProperty Property in the bean, or null. - * @param beanScope bean scope, or null. - * @return Appropriate TagHandler. - * @throws JspException - NoSuchDefinitionException No value associated to bean. - * @throws JspException an error occur while reading bean, or no definition found. - * @throws JspException - Throws by underlying nested call to processDefinitionName() - */ - protected TagHandler processBean( - String beanName, - String beanProperty, - String beanScope) - throws JspException { - - Object beanValue = - TagUtils.getRealValueFromBean( - beanName, - beanProperty, - beanScope, - pageContext); - - if (beanValue == null) { - throw new JspException( - "Error - Tag Insert : No value defined for bean '" - + beanName - + "' with property '" - + beanProperty - + "' in scope '" - + beanScope - + "'."); - } - - return processObjectValue(beanValue); - } - - /** * Process tag attribute "attribute". * Get value from component attribute. * Found value is process by processObjectValue(). @@ -682,48 +559,23 @@ * @throws JspException - Throws by underlying nested call to processDefinitionName() */ public TagHandler processAttribute(String name) throws JspException { - Object attrValue = getCurrentContext().getAttribute(name); - - if (attrValue == null) { - throw new JspException( - "Error - Tag Insert : No value found for attribute '" - + name - + "'."); - } - - return processObjectValue(attrValue); - } - - /** - * Try to process name as a definition, or as an URL if not found. - * @param name Name to process. - * @return appropriate TagHandler - * @throws JspException InstantiationException Can't create requested controller - */ - public TagHandler processAsDefinitionOrURL(String name) - throws JspException { - - try { - TilesContext tilesContext = TilesContextFactory.getInstance( - pageContext.getServletContext(), - pageContext.getRequest(), pageContext.getResponse()); - ComponentDefinition definition = - TilesUtil.getDefinition(name, tilesContext); - - if (definition != null) { - return processDefinition(definition); - } + Object attrValue = getCurrentContext().getAttribute(name); - } catch (DefinitionsFactoryException ex) { - // silently failed, because we can choose to not define a factory. + if (attrValue == null) { + throw new JspException( + "Error - Tag Insert : No value found for attribute '" + + name + + "'."); + } else if (attrValue instanceof ComponentAttribute) { + return processTypedAttribute((ComponentAttribute) attrValue); + } else { + throw new JspException("Invalid attribute type: " + attrValue.getClass().getName()); } - - // no definition found, try as url - return processUrl(name); } /** - * Process typed attribute according to its type. + * Process typed attribute explicitly according to its type. + * * @param value Typed attribute to process. * @return appropriate TagHandler. * @throws JspException - Throws by underlying nested call to processDefinitionName() @@ -746,10 +598,10 @@ return new DirectStringHandler((String) value.getValue()); } else if (type.equalsIgnoreCase("definition")) { return processDefinition((ComponentDefinition) value.getValue()); - } - - return new InsertHandler((String) value.getValue(), + } else { + return new InsertHandler((String) value.getValue(), role, getController()); + } } /** @@ -1051,4 +903,12 @@ return EVAL_PAGE; } } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } } Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTag.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTag.java?rev=419638&r1=419637&r2=419638&view=diff ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTag.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/PutTag.java Thu Jul 6 11:10:00 2006 @@ -81,21 +81,6 @@ private String valueType = null; /** - * Bean name attribute. - */ - private String beanName = null; - - /** - * Bean property attribute. - */ - private String beanProperty = null; - - /** - * Bean scope attribute. - */ - private String beanScope = null; - - /** * Role attribute. */ private String role = null; @@ -130,9 +115,6 @@ valueType = null; direct = null; value = null; - beanName = null; - beanProperty = null; - beanScope = null; role = null; body = null; } @@ -191,22 +173,6 @@ /** * Set content. - * Method added to satisfy Tomcat (bug ?). - */ - public void setContent(String value) { - this.value = value; - } - - /** - * Get content. - * Method added to satisfy Tomcat (bug ?). - */ - public String getContent() { - return (String) value; - } - - /** - * Set content. */ public void setContent(Object value) { this.value = value; @@ -235,48 +201,6 @@ } /** - * Set bean name. - */ - public void setBeanName(String value) { - this.beanName = value; - } - - /** - * Get bean name. - */ - public String getBeanName() { - return beanName; - } - - /** - * Set bean property. - */ - public void setBeanProperty(String value) { - this.beanProperty = value; - } - - /** - * Get bean property. - */ - public String getBeanProperty() { - return beanProperty; - } - - /** - * Set bean scope. - */ - public void setBeanScope(String value) { - this.beanScope = value; - } - - /** - * Get bean scope. - */ - public String getBeanScope() { - return beanScope; - } - - /** * Set role attribute. * @param role The role the user must be in to store content. */ @@ -315,7 +239,7 @@ realValue = value; // If realValue is not set, value must come from body - if (value == null && beanName == null) { + if (value == null) { // Test body content in case of empty body. if (body != null) { realValue = body; @@ -324,12 +248,6 @@ } } - // Does value comes from a bean ? - if (realValue == null && beanName != null) { - getRealValueFromBean(); - return; - } - // Is there a type set ? // First check direct attribute, and translate it to a valueType. // Then, evaluate valueType, and create requested typed attribute. @@ -348,6 +266,7 @@ * Extract real value from specified bean. * @throws JspException If something goes wrong while getting value from bean. */ + /* - GDR - Commenting out in case someone wants to add feature back. protected void getRealValueFromBean() throws JspException { try { Object bean = TagUtils.retrieveBean(beanName, beanScope, pageContext); @@ -391,7 +310,7 @@ + ex.getMessage(), ex); } } - + */ /** * Do start tag. */ @@ -401,12 +320,12 @@ body = null; // Do we need to evaluate body ? - if (value == null && beanName == null) { + if (value == null) { return EVAL_BODY_TAG; + } else { + // Value is set, don't evaluate body. + return SKIP_BODY; } - - // Value is set, don't evaluate body. - return SKIP_BODY; } /** Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tiles-core.tld URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tiles-core.tld?rev=419638&r1=419637&r2=419638&view=diff ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tiles-core.tld (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/resources/META-INF/tiles-core.tld Thu Jul 6 11:10:00 2006 @@ -17,46 +17,11 @@ <rtexprvalue>true</rtexprvalue> </attribute> <attribute> - <name>component</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> - <name>page</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> - <name>definition</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> - <name>attribute</name> - <required>false</required> - <rtexprvalue>false</rtexprvalue> - </attribute> - <attribute> <name>name</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> - <name>beanName</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> - <name>beanProperty</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> - <name>beanScope</name> - <required>false</required> - <rtexprvalue>false</rtexprvalue> - </attribute> - <attribute> <name>flush</name> <required>false</required> <rtexprvalue>false</rtexprvalue> @@ -74,12 +39,7 @@ <rtexprvalue>true</rtexprvalue> </attribute> <attribute> - <name>controllerUrl</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> - <name>controllerClass</name> + <name>type</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> @@ -89,7 +49,7 @@ <tag-class>org.apache.tiles.taglib.DefinitionTag</tag-class> <body-content>JSP</body-content> <attribute> - <name>id</name> + <name>name</name> <required>true</required> <rtexprvalue>false</rtexprvalue> </attribute> @@ -104,11 +64,6 @@ <rtexprvalue>true</rtexprvalue> </attribute> <attribute> - <name>page</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> <name>role</name> <required>false</required> <rtexprvalue>true</rtexprvalue> @@ -134,11 +89,6 @@ <rtexprvalue>true</rtexprvalue> </attribute> <attribute> - <name>content</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> <name>direct</name> <required>false</required> <rtexprvalue>false</rtexprvalue> @@ -149,21 +99,6 @@ <rtexprvalue>false</rtexprvalue> </attribute> <attribute> - <name>beanName</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> - <name>beanProperty</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> - <name>beanScope</name> - <required>false</required> - <rtexprvalue>false</rtexprvalue> - </attribute> - <attribute> <name>role</name> <required>false</required> <rtexprvalue>true</rtexprvalue> @@ -189,32 +124,12 @@ <rtexprvalue>false</rtexprvalue> </attribute> <attribute> - <name>content</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> <name>direct</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <name>type</name> - <required>false</required> - <rtexprvalue>false</rtexprvalue> - </attribute> - <attribute> - <name>beanName</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> - <name>beanProperty</name> - <required>false</required> - <rtexprvalue>true</rtexprvalue> - </attribute> - <attribute> - <name>beanScope</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute>