Author: apetrelli Date: Thu Aug 31 04:52:58 2006 New Revision: 438875 URL: http://svn.apache.org/viewvc?rev=438875&view=rev Log: SB-37 Now definitions (defined in tiles-defs.xml and created in JSP pages) are got in a centralized way. Precedence is gived to definitions created with <tiles:definition> tag.
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/InsertTag.java struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/util/TagUtils.java 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=438875&r1=438874&r2=438875&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 Aug 31 04:52:58 2006 @@ -83,7 +83,11 @@ * Content is already typed by caller. */ public void putAttribute(String name, Object content) { - definition.putAttribute(name, new ComponentAttribute(content)); + if (content instanceof ComponentAttribute) { + definition.putAttribute(name, (ComponentAttribute) content); + } else { + definition.putAttribute(name, new ComponentAttribute(content)); + } } /** @@ -100,24 +104,19 @@ Object attributeValue = nestedTag.getRealValue(); ComponentAttribute def = null; - if (nestedTag.getRole() != null) { - try { - def = ((ComponentAttribute) attributeValue); - } catch (ClassCastException ex) { - def = new ComponentAttribute(attributeValue); - } - - if (def != null) { + if (attributeValue != null + && attributeValue instanceof ComponentAttribute) { + def = ((ComponentAttribute) attributeValue); + if (nestedTag.getRole() != null) { def.setRole(nestedTag.getRole()); - } else { - // now what? Is this an exception? } - - attributeValue = def; + } else { + def = new ComponentAttribute(attributeValue, nestedTag.getRole(), + nestedTag.getType()); } // now add attribute to enclosing parent (i.e. : this object) - putAttribute(nestedTag.getName(), new ComponentAttribute(attributeValue)); + putAttribute(nestedTag.getName(), def); } /** 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=438875&r1=438874&r2=438875&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 Aug 31 04:52:58 2006 @@ -478,8 +478,9 @@ TilesContext tilesContext = TilesContextFactory.getInstance( pageContext.getServletContext(), pageContext.getRequest(), pageContext.getResponse()); - ComponentDefinition definition = TilesUtil.getDefinition( - name, tilesContext); + ComponentDefinition definition = null; + definition = TagUtils.getComponentDefinition(name, pageContext, + tilesContext); if (definition == null) { // is it possible ? throw new NoSuchDefinitionException(); @@ -492,9 +493,6 @@ "Error - Tag Insert : Can't get definition '" + definitionName + "'. Check if this name exists in definitions factory.", ex); - - } catch (FactoryNotFoundException ex) { - throw new JspException(ex.getMessage()); } catch (DefinitionsFactoryException ex) { if (log.isDebugEnabled()) { Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/util/TagUtils.java URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/util/TagUtils.java?rev=438875&r1=438874&r2=438875&view=diff ============================================================================== --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/util/TagUtils.java (original) +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/taglib/util/TagUtils.java Thu Aug 31 04:52:58 2006 @@ -342,13 +342,37 @@ */ public static ComponentDefinition getComponentDefinition(String name, PageContext pageContext) throws JspException { + return getComponentDefinition(name, pageContext, null); + } + + + /** + * Get component definition by its name. + * @param name Definition name. + * @param pageContext The PageContext for the current page. + * @param tilesContext The TilesContext for the current request. If it is + * null, it will be created. + * @throws JspException - + */ + public static ComponentDefinition getComponentDefinition(String name, + PageContext pageContext, TilesContext tilesContext) + throws JspException { try { - TilesContext tilesContext = TilesContextFactory.getInstance( - pageContext.getServletContext(), - pageContext.getRequest(), pageContext.getResponse()); - return TilesUtil.getDefinition( - name, tilesContext); + ComponentDefinition definition; + Object definitionCandidate = findAttribute(name, pageContext); + if (definitionCandidate != null + && definitionCandidate instanceof ComponentDefinition) { + definition = (ComponentDefinition) definitionCandidate; + } else { + if (tilesContext == null) { + tilesContext = TilesContextFactory.getInstance( + pageContext.getServletContext(), + pageContext.getRequest(), pageContext.getResponse()); + } + definition = TilesUtil.getDefinition(name, tilesContext); + } + return definition; } catch (NoSuchDefinitionException ex) { throw new JspException(