You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2002/06/25 05:16:30 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/taglib/tiles AddTag.java AddTagParent.java AttributeToScopeTag.java ComponentConstants.java DefinitionTag.java DefinitionTagSupport.java GetAttributeTag.java GetTag.java ImportAttributeTag.java InitDefinitionsTag.java InsertTag.java PutListTag.java PutListTagParent.java PutTag.java PutTagParent.java UseAttributeTag.java UseAttributeTei.java
craigmcc 2002/06/24 20:16:30
Added: src/share/org/apache/struts/taglib/tiles AddTag.java
AddTagParent.java AttributeToScopeTag.java
ComponentConstants.java DefinitionTag.java
DefinitionTagSupport.java GetAttributeTag.java
GetTag.java ImportAttributeTag.java
InitDefinitionsTag.java InsertTag.java
PutListTag.java PutListTagParent.java PutTag.java
PutTagParent.java UseAttributeTag.java
UseAttributeTei.java
Log:
Migrate Tiles to main codebase (Part 3).
Revision Changes Path
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/AddTag.java
Index: AddTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/AddTag.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.taglib.tiles.util.TagUtils;
import java.lang.reflect.InvocationTargetException;
import java.lang.IllegalAccessException;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.ServletException;
/**
* Add an element to surrounding list tag.
* Same syntax as put.
*/
public class AddTag extends PutTag {
/**
* default constructor
*/
public AddTag() {
super();
}
/**
* Find parent tag wich must implements AttributeContainer.
* @throws JspException If we can't find an appropriate enclosing tag.
*/
protected void callParent() throws JspException
{
// Get enclosing parent,
AddTagParent enclosingParent = findEnclosingPutListTagParent();
enclosingParent.processNestedTag( this );
}
/**
* Find parent tag wich must implements AttributeContainer.
* @throws JspException If we can't find an appropriate enclosing tag.
*/
protected AddTagParent findEnclosingPutListTagParent() throws JspException {
try
{
AddTagParent parent = (AddTagParent)findAncestorWithClass(this,AddTagParent.class);
if( parent == null )
{
throw new JspException( "Error - tag add : enclosing tag doesn't accept 'add' tag." );
}
return parent;
}
catch( ClassCastException ex )
{
throw new JspException( "Error - tag add : enclosing tag doesn't accept 'add' tag." );
}
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/AddTagParent.java
Index: AddTagParent.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/AddTagParent.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import javax.servlet.jsp.JspException;
/**
* Tag Class implementing this interface can contains nested PutTag.
* This interface define a method calls by nested tag.
*/
public interface AddTagParent {
/**
* Process the nested tag.
* @param nestedTag Nested to process.
*/
void processNestedTag(AddTag nestedTag) throws JspException;
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/AttributeToScopeTag.java
Index: AttributeToScopeTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/AttributeToScopeTag.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.taglib.tiles.util.TagUtils;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
/**
* Custom tag that put component's attributes in a scope (request, page, ...).
* @deprecated Is it still in use ?
*/
public final class AttributeToScopeTag extends TagSupport {
// ----------------------------------------------------- Instance Variables
/**
* The scope name.
*/
private String scopeName = null;
/**
* The scope value.
*/
private int scope = PageContext.PAGE_SCOPE;
/**
* The property name to be exposed.
*/
private String property = null;
// ------------------------------------------------------------- Properties
/**
* Return the property name.
*/
public String getProperty() {
return (this.property);
}
/**
* Set the property name.
*
* @param property The property name
*/
public void setProperty(String property) {
this.property = property;
}
/**
* Set the offset.
*
* @param offset The new offset
*/
public void setScope(String scope) {
this.scopeName = scope;
}
// --------------------------------------------------------- Public Methods
/**
* Expose the requested property from component context.
*
* @exception JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException
{
if( id==null )
id=property;
ComponentContext compContext = (ComponentContext)pageContext.getAttribute( ComponentConstants.COMPONENT_CONTEXT, pageContext.REQUEST_SCOPE);
if( compContext == null )
throw new JspException ( "Error - tag.useProperty : component context is not defined. Check tag syntax" );
Object value = compContext.getAttribute(property);
if( value == null )
throw new JspException ( "Error - tag.useProperty : property '"+ property + "' not found in context. Check tag syntax" );
if( scopeName != null )
{
scope = TagUtils.getScope( scopeName, PageContext.PAGE_SCOPE );
pageContext.setAttribute(id, value, scope);
}
else
pageContext.setAttribute(id, value);
// Continue processing this page
return SKIP_BODY;
}
/**
* Clean up after processing this enumeration.
*
* @exception JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException
{
return (EVAL_PAGE);
}
/**
* Release all allocated resources.
*/
public void release() {
super.release();
property = null;
scopeName = null;
scope = PageContext.PAGE_SCOPE;
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/ComponentConstants.java
Index: ComponentConstants.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/ComponentConstants.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import org.apache.struts.taglib.tiles.*;
import javax.servlet.jsp.PageContext;
import org.apache.struts.action.Action;
/**
* Constant used by Tiles/Components.
*/
public interface ComponentConstants {
/** Name used to store Tile/Component context */
public static final String COMPONENT_CONTEXT = "CompContext";
public static final int COMPONENT_SCOPE = 8;
public static final String LOCALE_KEY = Action.LOCALE_KEY;
public static final String EXCEPTION_KEY = Action.EXCEPTION_KEY;
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/DefinitionTag.java
Index: DefinitionTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/DefinitionTag.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import org.apache.struts.taglib.tiles.util.TagUtils;
import org.apache.struts.tiles.ComponentDefinition;
import org.apache.struts.tiles.AttributeDefinition;
import org.apache.struts.tiles.UntyppedAttribute;
import org.apache.struts.tiles.DefinitionsUtil;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.JspException;
/**
* This is the tag handler for <tiles:definition>, which defines
* a tiles (or template / component). Definition is put in requested context, and can be
* used in <tiles:insert>.
*
* @author Cedric Dumoulin
* @version $Revision: 1.1 $ $Date: 2002/06/25 03:16:30 $
*/
public class DefinitionTag extends DefinitionTagSupport implements PutTagParent, PutListTagParent
{
/* JSP Tag attributes */
/**
* Definition identifier.
*/
private String id;
/**
* Scope into which definition will be saved.
*/
private String scope;
/**
* Extends attribute value.
*/
private String extendsDefinition;
/* Internal properties */
/**
* Template definition
*/
private ComponentDefinition definition;
/**
* Reset member values for reuse. This method calls super.release(),
* which invokes TagSupport.release(), which typically does nothing.
*/
public void release()
{
super.release();
id = null;
page = null;
scope = null;
role = null;
extendsDefinition = null;
}
/**
* Reset member values for reuse. This method calls super.release(),
* which invokes TagSupport.release(), which typically does nothing.
*/
protected void releaseInternal()
{
definition = null;
}
/**
* This method is a convenience for others tags for
* putting content into the tile definition.
* Content is already typed by caller.
*/
public void putAttribute(String name, Object content)
{
definition.putAttribute(name, content);
}
/**
* Process nested ≶put> tag.
* Method calls by nested ≶put> tags.
* Nested list is added to current list.
* If role is defined, nested attribute is wrapped into an untypped definition
* containing attribute value and role.
*/
public void processNestedTag(PutTag nestedTag) throws JspException
{
// Get real value and check role
// If role is set, add it in attribute definition if any.
// If no attribute definition, create untyped one, and set role.
Object attributeValue = nestedTag.getRealValue();
AttributeDefinition def;
if( nestedTag.getRole() != null )
{
try
{
def = ((AttributeDefinition)attributeValue);
}
catch( ClassCastException ex )
{
def = new UntyppedAttribute( attributeValue );
}
def.setRole(nestedTag.getRole());
attributeValue = def;
} // end if
// now add attribute to enclosing parent (i.e. : this object)
putAttribute( nestedTag.getName(), attributeValue);
}
/**
* Process nested ≶putList> tag.
* Method calls by nested ≶putList> tags.
* Nested list is added to current list.
* If role is defined, nested attribute is wrapped into an untypped definition
* containing attribute value and role.
*/
public void processNestedTag(PutListTag nestedTag) throws JspException
{
// Get real value and check role
// If role is set, add it in attribute definition if any.
// If no attribute definition, create untyped one, and set role.
Object attributeValue = nestedTag.getList();
if( nestedTag.getRole() != null )
{
AttributeDefinition def = new UntyppedAttribute( attributeValue );
def.setRole(nestedTag.getRole());
attributeValue = def;
} // end if
// Check if a name is defined
if( nestedTag.getName() == null)
throw new JspException( "Error - PutList : attribute name is not defined. It is mandatory as the list is added to a 'definition'." );
// now add attribute to enclosing parent (i.e. : this object).
putAttribute(nestedTag.getName(), attributeValue);
}
/**
* Access method for the id property.
*
* @return the current value of the id property
*/
public String getId()
{
return id;
}
/**
* Sets the value of the id property.
*
* @param aId the new value of the id property
*/
public void setId(String id)
{
this.id = id;
}
/**
* Access method for the scope property.
*
* @return the current value of the scope property
*/
public String getScope()
{
return scope;
}
/**
* Sets the value of the scope property.
*
* @param aScope the new value of the scope property
*/
public void setScope(String aScope)
{
scope = aScope;
}
/**
* Sets the value of the extends property.
*
* @param definitionName Name of parent definition.
*/
public void setExtends(String definitionName)
{
this.extendsDefinition = definitionName;
}
/**
* Access method for the extends property.
* @return the current value of the extends property
*/
public String getExtends()
{
return extendsDefinition;
}
/**
* Process the start tag by creating a new definition.
*/
public int doStartTag() throws JspException
{
// Do we extend a definition ?
if( extendsDefinition != null && !extendsDefinition.equals("") )
{
ComponentDefinition parentDef = TagUtils.getComponentDefinition( extendsDefinition, pageContext );
System.out.println( "parent definition=" + parentDef );
definition = new ComponentDefinition( parentDef );
} // end if
else
definition = new ComponentDefinition();
// Set definitions attributes
if( page != null )
definition.setTemplate(page);
if( role != null )
definition.setRole(role);
//System.out.println( "definition=" + definition );
return EVAL_BODY_INCLUDE;
}
/**
* Process the end tag by puting the definition in appropriate context.
*/
public int doEndTag() throws JspException
{
TagUtils.setAttribute( pageContext, id, definition, scope);
releaseInternal();
return EVAL_PAGE;
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/DefinitionTagSupport.java
Index: DefinitionTagSupport.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/DefinitionTagSupport.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.PageContext;
import java.io.Serializable;
/**
* Common base class for tags dealing with Tile Definition.
* This class define properties used in Definition Tags.
* It also extends TagSupport.
*/
public class DefinitionTagSupport extends TagSupport implements Serializable
{
/** Associated Controller type */
protected String controllerType;
/** Associated Controller name (classname or url) */
protected String controllerName;
/**
* Role associated to definition.
*/
protected String role;
/**
* Uri of page assoicated to this definition.
*/
protected String page;
/**
* Release class properties.
*/
public void release()
{
super.release();
controllerType = null;
controllerName = null;
role = null;
page = null;
}
/**
* Get controller type.
* Type can be 'classname', 'url'
*/
public String getControllerType()
{
return controllerType;
}
/**
* Get controller name.
* Name denote a fully qualified classname, or an url.
* Exact type can be specified with setControllerType.
*/
public String getControllerName()
{
return controllerName;
}
/**
* Set associated controller type.
* Type denote a fully qualified classname.
* @param controllerType Typeof associated controller
*/
public void setControllerType(String controllerType)
{
this.controllerType = controllerType;
}
/**
* Set associated controller name.
* Name denote a fully qualified classname, or an url.
* Exact type can be specified with setControllerType.
* @param controller Controller classname or url
*/
public void setController(String controller)
{
setControllerName(controller); ;
}
/**
* Set associated controller name.
* Name denote a fully qualified classname, or an url.
* Exact type can be specified with setControllerType.
* @param controller Controller classname or url
*/
public void setControllerName(String controller)
{
this.controllerName = controller;
}
/**
* Set associated controller name as an url, and controller
* type as "url".
* Name must be an url (not checked).
* Convenience method.
* @param controller Controller url
*/
public void setControllerUrl(String controller)
{
setControllerName( controller);
setControllerType( "url" );
}
/**
* Set associated controller name as a classtype, and controller
* type as "classname".
* Name denote a fully qualified classname
* Convenience method.
* @param controller Controller classname.
*/
public void setControllerClass(String controller)
{
setControllerName( controller);
setControllerType( "classname" );
}
/**
* Access method for the role property.
* @return the current value of the role property
*/
public String getRole()
{
return role;
}
/**
* Sets the value of the role property.
*
* @param role the new value of the role property
*/
public void setRole(String role)
{
this.role = role;
}
/**
* Sets the value of the page property.
*
* @param page the new value of the template property
*/
public void setPage(String page)
{
this.page = page;
}
/**
* Gets the value of the page property.
*
* @param page the new value of the template property
*/
public String getPage(String page)
{
return page;
}
/**
* Access method for the template property.
*
* @return the current value of the template property
*/
public String getTemplate()
{
return page;
}
/**
* Sets the value of the template property.
* Same as setPage()
*
* @param template the new value of the template property
*/
public void setTemplate(String template)
{
this.page = template;
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/GetAttributeTag.java
Index: GetAttributeTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/GetAttributeTag.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import org.apache.struts.tiles.ComponentContext;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
/**
* Retrieve the value of the specified component/template attribute property,
* and render it to the current JspWriter as a String.
* The usual toString() conversions is applied on found value.
*/
public class GetAttributeTag extends TagSupport implements ComponentConstants {
private String attribute = null;
/** Role attribute */
private String role = null;
/**
* Do we ignore error if attribute is not found.
* Default value is false, which throw an exception.
*/
private boolean isErrorIgnored = false;
/**
* default constructor
*/
public GetAttributeTag() {
super();
}
/**
* Release all allocated resources.
*/
public void release() {
super.release();
attribute = null;
role = null;
isErrorIgnored = false;
}
/**
* Set attribute
*/
public void setAttribute(String attribute){
this.attribute = attribute;
}
/**
* Set attribute
*/
public void setName(String value)
{
this.attribute = value;
}
/**
* Set attribute
*/
public void setIgnore(boolean ignore)
{
this.isErrorIgnored = ignore;
}
/**
* Set role attribute
* @param name The role the user must be in to store content.
*/
public void setRole(String role) {
this.role = role;
}
/**
* Set attribute
*/
public int doEndTag() throws JspException {
// Check role
if(role != null && !((HttpServletRequest)pageContext.getRequest()).isUserInRole(role) )
{
return EVAL_PAGE;
} // end if
// Get context
ComponentContext compContext = (ComponentContext)pageContext.getAttribute( ComponentConstants.COMPONENT_CONTEXT, pageContext.REQUEST_SCOPE);
if( compContext == null )
throw new JspException ( "Error - tag.getAsString : component context is not defined. Check tag syntax" );
Object value = compContext.getAttribute(attribute);
if( value == null)
{ // no value : throw error or fail silently according to ignore
if(isErrorIgnored == false )
throw new JspException ( "Error - tag.getAsString : attribute '"+ attribute + "' not found in context. Check tag syntax" );
else
return EVAL_PAGE;
} // end if
try
{
pageContext.getOut().print( value );
}
catch( IOException ex )
{
ex.printStackTrace();
throw new JspException ( "Error - tag.getProperty : IOException ");
}
return EVAL_PAGE;
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/GetTag.java
Index: GetTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/GetTag.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import org.apache.struts.tiles.ComponentContext;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
/**
* This is the tag handler for <template:get>, which gets
* content from the request scope and either includes the content or prints
* it, depending upon the value of the content's direct attribute.
*
* This tag is intended to be compatible with the same tag from Templates (David Geary).
* Implementation extends InsertTag, for facility (no so well).
* The only difference is the default value of attribute 'ignore', which is true
* for this tag (default behavior of David Geary's templates).
*/
public class GetTag extends InsertTag {
/**
* Constructor.
* Set default value for 'isErrorIgnored'.
*/
public GetTag() {
isErrorIgnored = true;
}
/**
* Release all allocated resources.
*/
public void release() {
super.release();
isErrorIgnored = true;
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/ImportAttributeTag.java
Index: ImportAttributeTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/ImportAttributeTag.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.taglib.tiles.util.TagUtils;
import java.util.Iterator;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
/**
* Import attribute from component to requested scope.
* Attribute name and scope are optional. If not specified, all component
* attributes are imported in page scope.
*/
public final class ImportAttributeTag extends TagSupport {
/**
* Class name of object.
*/
private String name = null;
/**
* The scope name.
*/
private String scopeName = null;
/**
* The scope value.
*/
private int scope = PageContext.PAGE_SCOPE;
/**
* 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.
*/
protected boolean isErrorIgnored = false;
/**
* Release all allocated resources.
*/
public void release() {
super.release();
name = null;
scopeName = null;
scope = PageContext.PAGE_SCOPE;
isErrorIgnored = false;
}
/**
* Return the name.
*/
public String getName()
{
return (this.name);
}
/**
* Set the name.
*
* @param name The new name
*/
public void setName(String name)
{
this.name = name;
}
/**
* Set the scope by its string name.
*
* @param offset The new offset
*/
public void setScope(String scope)
{
this.scopeName = scope;
}
/**
* Set ignore attribute
*/
public void setIgnore(boolean ignore)
{
this.isErrorIgnored = ignore;
}
// --------------------------------------------------------- Public Methods
/**
* Expose the requested property from component context.
*
* @exception JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException
{
// retrieve component context
ComponentContext compContext = (ComponentContext)pageContext.getAttribute( ComponentConstants.COMPONENT_CONTEXT, pageContext.REQUEST_SCOPE);
if( compContext == null )
throw new JspException ( "Error - tag.useProperty : component context is not defined. Check tag syntax" );
// set scope
scope = TagUtils.getScope( scopeName, PageContext.PAGE_SCOPE );
// push attribute in requested context.
if( name != null )
{
Object value = compContext.getAttribute(name);
// Check if value exist and if we must send a runtime exception
if( value == null )
if(!isErrorIgnored)
throw new JspException ( "Error - tag.useProperty : property '"+ name + "' not found in context. Check tag syntax" );
else
return SKIP_BODY;
pageContext.setAttribute(name, value, scope);
}
else
{ // set all attributes
Iterator names = compContext.getAttributeNames();
while(names.hasNext())
{
String name = (String)names.next();
pageContext.setAttribute(name, compContext.getAttribute(name), scope);
} // end loop
} // end if
// Continue processing this page
return SKIP_BODY;
}
/**
* Clean up after processing this enumeration.
*
* @exception JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException
{
return (EVAL_PAGE);
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/InitDefinitionsTag.java
Index: InitDefinitionsTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/InitDefinitionsTag.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import org.apache.struts.tiles.DefinitionsUtil;
import org.apache.struts.tiles.ComponentDefinitionsFactory;
import org.apache.struts.tiles.DefinitionsFactoryException;
import org.apache.struts.tiles.ComponentDefinition;
import org.apache.struts.tiles.xmlDefinition.I18nFactorySet;
import java.util.Map;
import java.util.HashMap;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.PageContext;
/**
* Init definitions factory.
*/
public class InitDefinitionsTag extends TagSupport implements ComponentConstants {
private String filename = null;
private String classname = null;
/**
* default constructor
*/
public InitDefinitionsTag() {
super();
}
/**
* Release all allocated resources.
*/
public void release() {
super.release();
filename = null;
}
/**
* Set property
*/
public void setFile(String name){
this.filename = name;
}
/**
* Set property
*/
public void setClassname(String classname){
this.classname = classname;
}
/**
* Do start tag
*/
public int doStartTag() throws JspException
{
ComponentDefinitionsFactory factory = DefinitionsUtil.getDefinitionsFactory(pageContext);
if(factory != null )
return SKIP_BODY;
Map properties = new HashMap();
// Read properties
// Not so nice, but works for default factory ;-(
properties.put( I18nFactorySet.DEFINITIONS_CONFIG_PARAMETER_NAME, filename);
try
{
factory = DefinitionsUtil.createDefinitionsFactory(pageContext.getServletContext(), properties, classname);
}
catch( DefinitionsFactoryException ex )
{
ex.printStackTrace();
throw new JspException( ex.getMessage() + " See console for details" );
}
return SKIP_BODY;
}
/**
* Set property
*/
public int doEndTag() throws JspException {
return EVAL_PAGE;
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/InsertTag.java
Index: InsertTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/InsertTag.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.tiles.ComponentDefinition;
import org.apache.struts.tiles.Controller;
import org.apache.struts.tiles.DefinitionsUtil;
import org.apache.struts.tiles.NoSuchDefinitionException;
import org.apache.struts.tiles.FactoryNotFoundException;
import org.apache.struts.tiles.DefinitionsFactoryException;
import org.apache.struts.tiles.AttributeDefinition;
import org.apache.struts.tiles.DirectStringAttribute;
import org.apache.struts.tiles.PathAttribute;
import org.apache.struts.tiles.DefinitionAttribute;
import org.apache.struts.tiles.DefinitionNameAttribute;
import org.apache.struts.taglib.tiles.util.TagUtils;
import org.apache.struts.action.Action;
import java.util.Map;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.PageContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* This is the tag handler for <template:insert>, which includes
* a template. The tag's body content consists of <template:put>
* tags, which are accessed by <template:get> in the template.
*
* @author David Geary
* @author Cedric Dumoulin
* @version $Revision: 1.1 $ $Date: 2002/06/25 03:16:30 $
*/
public class InsertTag extends DefinitionTagSupport implements PutTagParent, ComponentConstants, PutListTagParent
{
/** debug flag */
public final static boolean debug = false;
/* JSP Tag attributes */
/** Flush attribute value */
protected boolean flush = true;
/** Name to insert */
private String name = null;
/** Name of attribute from which to read page name to include */
private String attribute = null;
/** Name of bean used as entity to include */
private String beanName = null;
/** Name of bean property, if any */
private String beanProperty = null;
/** Scope of bean, if any */
private 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.
*/
protected boolean isErrorIgnored = false;
/** Name of component instance to include */
private String definitionName = null;
/* Internal properties */
/**
* Does the end tag need to be processed.
* Default value is true. Boolean set in case of ignored errors.
*/
private boolean processEndTag = true;
/** Current component context */
protected ComponentContext cachedCurrentContext;
/** Finale handler of tag methods */
private TagHandler tagHandler = null;
/** Trick to allows inner classes to access pageContext */
protected PageContext pageContext = null;
/**
* Reset member values for reuse. This method calls super.release(),
* which invokes TagSupport.release(), which typically does nothing.
*/
public void release() {
super.release();
attribute = null;
beanName = null;
beanProperty = null;
beanScope = null;
definitionName = null;
flush = true;
name = null;
page = null;
role = null;
isErrorIgnored = false;
}
/**
* Reset internal member values for reuse.
*/
protected void releaseInternal()
{
cachedCurrentContext = null;
processEndTag = true;
// pageContext = null; // orion doesn't set it between two tags
tagHandler = null;
}
/**
* Set the current page context.
* Called by the page implementation prior to doStartTag().
* <p>
* Needed to allow inner classes to access pageContext.
*/
public void setPageContext(PageContext pc)
{
this.pageContext = pc;
super.setPageContext(pc);
}
/**
* Set property.
*/
public void setName(String value){
this.name = value;
}
/**
* Set property
*/
public void setComponent(String name){
this.page = name;
}
/**
* Set property
* @deprecated Use setDefinition() instead.
*/
public void setInstance(String name){
this.definitionName = name;
}
/**
* Set property
*/
public void setDefinition(String name){
this.definitionName = name;
}
/**
* Set property
*/
public void setAttribute(String value){
this.attribute = value;
}
/**
* Set property.
*/
public void setBeanName(String value){
this.beanName = value;
}
/**
* Set property.
*/
public void setBeanProperty(String value){
this.beanProperty = value;
}
/**
* Set property.
*/
public void setBeanScope(String value){
this.beanScope = value;
}
/**
* Set property
*/
public void setFlush(boolean flush){
this.flush = flush;
}
/**
* Set property
* Method added for compatibility with JSP1.1
*/
public void setFlush(String flush){
this.flush = (Boolean.valueOf(flush).booleanValue());
}
/**
* Set ignore attribute
*/
public void setIgnore(boolean ignore)
{
this.isErrorIgnored = ignore;
}
/////////////////////////////////////////////////////////////////////////
/**
* Add a body attribute.
* Erase any attribute with same name previously set.
*/
public void putAttribute(String name, Object value)
{
tagHandler.putAttribute(name, value);
}
/**
* Process nested ≶put> tag.
* Method calls by nested ≶put> tags.
* Nested list is added to current list.
* If role is defined, it is checked immediately.
*/
public void processNestedTag(PutTag nestedTag) throws JspException
{
// Check role
String role = nestedTag.getRole();
if( role != null && !((HttpServletRequest)pageContext.getRequest()).isUserInRole(role) )
{ // not allowed : skip attribute
return;
} // end if
putAttribute( nestedTag.getName(), nestedTag.getRealValue() );
}
/**
* Process nested ≶putList> tag.
* Method calls by nested ≶putList> tags.
* Nested list is added to sub-component attributes
* If role is defined, it is checked immediately.
*/
public void processNestedTag(PutListTag nestedTag) throws JspException
{
// Check role
String role = nestedTag.getRole();
if( role != null && !((HttpServletRequest)pageContext.getRequest()).isUserInRole(role) )
{ // not allowed : skip attribute
return;
} // end if
// Check if a name is defined
if( nestedTag.getName() == null)
throw new JspException( "Error - PutList : attribute name is not defined. It is mandatory as the list is added as attribute of 'insert'." );
// now add attribute to enclosing parent (i.e. : this object).
putAttribute( nestedTag.getName(), nestedTag.getList() );
}
/**
* Method calls by nested ≶putList> tags.
* A new list is added to current insert object.
*/
public void putAttribute(PutListTag nestedTag) throws JspException
{
// Check role
String role = nestedTag.getRole();
if( role != null && !((HttpServletRequest)pageContext.getRequest()).isUserInRole(role) )
{ // not allowed : skip attribute
return;
} // end if
putAttribute( nestedTag.getName(), nestedTag.getList() );
}
/**
* Get current component context.
*/
private ComponentContext getCurrentContext()
{
if( cachedCurrentContext == null )
{
cachedCurrentContext = (ComponentContext)pageContext.getAttribute( ComponentConstants.COMPONENT_CONTEXT, pageContext.REQUEST_SCOPE);
}
return cachedCurrentContext;
}
/**
* Get instanciated Controller.
* Return controller denoted by controllerType, or null if controllerType
* is null.
* @throws JspException If controller can't be created.
*/
private Controller getController() throws JspException
{
if( controllerType == null )
{
return null;
}
try
{
return ComponentDefinition.createController( controllerName, controllerType );
}
catch( InstantiationException ex )
{
throw new JspException( ex.getMessage() );
}
}
/**
* Process the start tag by checking tag's attributes and creating appropriate handler.
* Possible handlers :
* <ul>
* <li> URL
* <li> definition
* <li> direct String
* </ul>
* Handlers also contain sub-component context.
*
*/
public int doStartTag() throws JspException
{
// Check role immediatly to avoid useless stuff.
// In case of insertion of a "definition", definition's role still checked later.
// This lead to a double check of "role" ;-(
if(role != null && !((HttpServletRequest)pageContext.getRequest()).isUserInRole(role) )
{
processEndTag = false;
return SKIP_BODY;
} // end if
// Now, real stuff
try
{
tagHandler = createTagHandler();
}
catch( JspException ex )
{ // Do we ignore errors ?
if( isErrorIgnored )
{
processEndTag = false;
return SKIP_BODY;
}
// Errors aren't ignored, let it throw.
throw ex;
}
return tagHandler.doStartTag();
}
/**
* Process the end tag by including the template.
* Simply call the handler doEndTag
*/
public int doEndTag() throws JspException
{
if( !processEndTag )
{
releaseInternal();
return EVAL_PAGE;
}
int res = tagHandler.doEndTag();
// Reset properties used by object, in order to be able to reuse object.
releaseInternal();
return res;
}
/**
* Process tag attribute and create corresponding tag handler.
*/
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 )
{
return processName( name );
}
else if( page != null )
{
return processUrl( page );
}
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 AttributeDefinition )
{ // We have a type => return appropriate IncludeType
return processTypedAttribute((AttributeDefinition)value);
}
else if( value instanceof ComponentDefinition )
return processDefinition( (ComponentDefinition)value );
// Value must denote a valid String
return processAsDefinitionOrURL( value.toString() );
}
/**
* Process name.
* Search in following order :
* <ul>
* <li>Component context - if found, process it as value.</li>
* <li>definitions factory</li>
* <li>URL</li>
* <li></li>
* </ul>
*
* @return appropriate tag handler.
* @throws JspException - Throws by underlying nested call to processDefinitionName()
*/
public TagHandler processName(String name)
throws JspException
{
Object attrValue = getCurrentContext().getAttribute(name);
if( attrValue != null )
return processObjectValue( attrValue);
return processAsDefinitionOrURL(name);
}
/**
* Process
* @throws JspException If failed to create controller
*/
public TagHandler processUrl(String url) throws JspException
{
return new InsertHandler(url, role, getController() );
}
/**
* Process tag attribute "definition"
* First, search definition in the factory, then create handler from this definition.
* @param name Name of the definition.
* @return Appropriate TagHandler.
* @throws JspException- NoSuchDefinitionException No Definition found for name.
* @throws JspException- FactoryNotFoundException Can't find Definitions factory.
* @throws JspException- DefinedComponentFactoryException General error in factory.
* @throws JspException InstantiationException Can't create requested controller
*/
protected TagHandler processDefinitionName(String name)
throws JspException
{
try
{
ComponentDefinition definition = DefinitionsUtil.getDefinition(name, pageContext);
if( definition == null )
{ // is it possible ?
throw new NoSuchDefinitionException();
}
return processDefinition( definition );
}
catch( NoSuchDefinitionException ex )
{
throw new JspException ( "Error - Tag Insert : Can't get definition '"
+ definitionName
+ "'. Check if this name exist in definitions factory." );
}
catch( FactoryNotFoundException ex )
{ // factory not found.
throw new JspException ( ex.getMessage() );
} // end catch
catch( DefinitionsFactoryException ex )
{
if(debug)
ex.printStackTrace( );
// Save exception to be able to show it later
pageContext.setAttribute(Action.EXCEPTION_KEY, ex, PageContext.REQUEST_SCOPE);
throw new JspException ( ex.getMessage() );
} // end catch
}
/**
* End of Process tag attribute "definition"
* Overload definition with tag attributes "template" and "role".
* Then, create appropriate tag handler.
* @param definition Definition to process.
* @return Appropriate TagHandler.
* @throws JspException InstantiationException Can't create requested controller
*/
protected TagHandler processDefinition(ComponentDefinition definition)
throws JspException
{
// Declare local variable in order to not change Tag attribute values.
String role = this.role;
String page = this.page;
Controller controller = null;
try
{
controller = definition.getOrCreateController();
// Overload definition with tag's template and role.
if(role == null )
role = definition.getRole();
if( page == null )
page = definition.getTemplate();
if( controllerName != null )
controller = ComponentDefinition.createController( controllerName, controllerType );
// Can check if page is set
return new InsertHandler( definition.getAttributes(), page, role, controller );
}
catch( InstantiationException ex )
{
throw new JspException( ex.getMessage() );
}
}
/**
* Process a bean.
* Get bean value, eventually using property and scope. Found value is process by processObjectValue().
* @param name Name of the bean
* @param property Property in the bean, or null.
* @param scope 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 NoSuchDefinitionException();
throw new JspException( "Error - Tag Insert : No value defined for bean '"
+ beanName + "' with property '"
+ beanProperty + "' in scope '"
+ beanScope + "'." );
} // end if
return processObjectValue(beanValue);
}
/**
* Process tag attribute "attribute=".
* Get value from component attribute.
* Found value is process by processObjectValue().
* @param name Name of the attribute.
* @return Appropriate TagHandler.
* @throws JspException - NoSuchDefinitionException No Definition found for name.
* @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
{
ComponentDefinition definition = DefinitionsUtil.getDefinition(name, pageContext);
if( definition != null )
return processDefinition( definition );
}
catch( DefinitionsFactoryException ex )
{ // silently failed, because we can choose to not define a factory.
}
// no definition found, try as url
return processUrl( name );
}
/**
* Process typed attribute according to its type.
* @param value Typed attribute to process.
* @return appropriate TagHandler.
* @throws JspException - Throws by underlying nested call to processDefinitionName()
*/
public TagHandler processTypedAttribute(AttributeDefinition value)
throws JspException
{
if( value instanceof DirectStringAttribute )
return new DirectStringHandler( (String)value.getValue() );
else if( value instanceof DefinitionAttribute )
return processDefinition( (ComponentDefinition)value.getValue() );
else if( value instanceof DefinitionNameAttribute )
{
return processDefinitionName( (String)value.getValue() );
}
//else if( value instanceof PathAttribute )
return new InsertHandler( (String)value.getValue(), role, getController() );
}
/////////////////////////////////////////////////////////////////////////////
/**
* Inner Interface
* Sub handler for tag.
*/
protected interface TagHandler
{
/**
* Create ComponentContext for type depicted by implementation class.
*/
public int doStartTag() throws JspException;
/**
* Do include for type depicted by implementation class.
*/
public int doEndTag() throws JspException;
/**
* Add a component parameter (attribute) to subContext.
*/
public void putAttribute( String name, Object value );
} // end inner interface
/////////////////////////////////////////////////////////////////////////////
/**
* Real handler, after attribute resolution.
* Handle include sub-component.
*/
protected class InsertHandler implements TagHandler
{
protected String page;
protected ComponentContext currentContext;
protected ComponentContext subCompContext;
protected String role;
protected Controller controller;
/**
* Constructor.
* Create insert handler using Component definition.
*/
public InsertHandler( Map attributes, String page, String role, Controller controller )
{
this.page = page;
this.role = role;
this.controller = controller;
subCompContext = new ComponentContext( attributes );
}
/**
* Constructor.
* Create insert handler to insert page at specified location.
*/
public InsertHandler( String page, String role, Controller controller )
{
this.page = page;
this.role = role;
this.controller = controller;
subCompContext = new ComponentContext();
}
/**
* Create a new empty context.
*/
public int doStartTag() throws JspException
{
// Check role
if(role != null && !((HttpServletRequest)pageContext.getRequest()).isUserInRole(role) )
{
return SKIP_BODY;
} // end if
// save current context
this.currentContext = getCurrentContext();
return EVAL_BODY_INCLUDE;
}
/**
* Add attribute to sub context.
* Do nothing.
*/
public void putAttribute( String name, Object value )
{
subCompContext.putAttribute( name, value );
}
/**
* Include requested page.
*/
public int doEndTag() throws JspException
{
// Check role
if(role != null && !((HttpServletRequest)pageContext.getRequest()).isUserInRole(role) )
{
return EVAL_PAGE;
} // end if
try {
if( DefinitionsUtil.userDebugLevel > DefinitionsUtil.NO_DEBUG )
System.out.println( "insert page='" + page + "'." );
// set new context for included component.
pageContext.setAttribute( ComponentConstants.COMPONENT_CONTEXT, subCompContext, pageContext.REQUEST_SCOPE);
// Call controller if any
if( controller != null )
controller.perform(subCompContext, (HttpServletRequest)pageContext.getRequest(), (HttpServletResponse)pageContext.getResponse(), pageContext.getServletContext());
// include requested component.
if( flush )
pageContext.getOut().flush();
pageContext.include(page);
}
catch (IOException ex)
{
processException( ex, "Can't insert page '"+ page+ "' : " + ex.getMessage() );
}
catch (IllegalArgumentException ex)
{ // Can't resolve page uri
// Do we ignore bad page uri errors ?
if( ! (page == null && isErrorIgnored) )
// Don't ignore bad page uri errors
processException( ex, "Tag 'insert' can't insert page '" + page + "'. Check if it exists.\n" + ex.getMessage() );
}
catch (ServletException ex)
{
Throwable realEx = ex;
if( ex.getRootCause() != null )
{
realEx = ex.getRootCause();
}
processException( realEx, "[ServletException in:"+ page+ "] " + realEx.getMessage()+ "'" );
}
catch (Exception ex) {
processException( ex, "[Exception in:" + page + "] "+ ex.getMessage());
}
finally
{
// restore old context
// done only if currentContext not null (bug with Silverstream ?; related by Arvindra Sehmi 20010712)
if( currentContext != null )
pageContext.setAttribute( ComponentConstants.COMPONENT_CONTEXT, currentContext, pageContext.REQUEST_SCOPE);
}
return EVAL_PAGE;
}
/**
* Process an exception.
* Depending of debug attribute, print full exception trace, or only
* its message in output page.
* @param ex Exception
* @param msg An additional message to show in console, and to propagate if we can't output exception.
*/
protected void processException( Throwable ex, String msg ) throws JspException
{
try {
if( msg == null )
msg = ex.getMessage();
if(debug)
{ // show full trace
System.out.println( msg );
ex.printStackTrace();
pageContext.getOut().println(msg);
ex.printStackTrace(new PrintWriter(pageContext.getOut(), true) );
}
else
{ // show only message
pageContext.getOut().println(msg);
} // end if
}
catch(IOException ioex )
{ // problems. Propagate original exception
pageContext.setAttribute(ComponentConstants.EXCEPTION_KEY, ex, PageContext.REQUEST_SCOPE);
throw new JspException( msg );
}
}
}
/////////////////////////////////////////////////////////////////////////////
/**
* Handle insert direct string.
*/
protected class DirectStringHandler implements TagHandler
{
/** Object to print as a direct string */
private Object value;
/**
* Constructor.
*/
public DirectStringHandler(Object value )
{
this.value = value;
}
/**
* Do nothing are there is no context for a direct string
*/
public int doStartTag() throws JspException
{
return SKIP_BODY;
}
/**
* Add attribute to sub context.
* Do nothing.
*/
public void putAttribute( String name, Object value )
{
}
/**
* Print String in page output stream
*/
public int doEndTag() throws JspException
{
try
{
if(flush)
pageContext.getOut().flush();
pageContext.getOut().print( value );
}
catch (IOException ex)
{
if(debug)
System.out.println( "Can't write string '"+ value + "' : " + ex.getMessage() );
pageContext.setAttribute(ComponentConstants.EXCEPTION_KEY, ex, PageContext.REQUEST_SCOPE);
throw new JspException( "Can't write string '"+ value + "' : " + ex.getMessage() );
}
return EVAL_PAGE;
}
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/PutListTag.java
Index: PutListTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/PutListTag.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.tiles.AttributeDefinition;
import org.apache.struts.tiles.UntyppedAttribute;
import java.util.List;
import java.util.ArrayList;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
/**
* PutList tag implementation.
*/
public class PutListTag extends TagSupport implements ComponentConstants, AddTagParent, PutListTagParent {
/** Name of this attribute */
private String attributeName = null;
/** The list itself */
private List list = null;
/** Role attribute */
private String role = null;
/**
* default constructor
*/
public PutListTag() {
super();
}
/**
* Release all allocated resources.
*/
public void release() {
super.release();
attributeName = null;
role = null;
}
/**
* Release all internal resources.
*/
protected void releaseInternal()
{
list = null;
}
/**
* Set property
*/
public void setName(String name)
{
this.attributeName = name;
}
/**
* Get property
*/
public String getName()
{
return attributeName;
}
/**
* Set role attribute
* @param name The role the user must be in to store content.
*/
public void setRole(String role)
{
this.role = role;
}
/**
* Get role attribute
*/
public String getRole()
{
return role;
}
/**
* Get list defined in tag.
*/
public List getList()
{
return list;
}
/**
* Set property
*/
public void addElement(Object value){
if(list==null)
list = new ArrayList();
list.add(value);
}
/**
* Process nested ≶putList> tag.
* Method calls by nested ≶putList> tags.
* Nested list is added to current list.
* If role is defined, nested attribute is wrapped into an untypped definition
* containing attribute value and role.
*/
public void processNestedTag(PutListTag nestedTag) throws JspException
{
// Get real value and check role
// If role is set, add it in attribute definition if any.
// If no attribute definition, create untyped one, and set role.
Object attributeValue = nestedTag.getList();
if( nestedTag.getRole() != null )
{
AttributeDefinition def = new UntyppedAttribute( attributeValue );
def.setRole(nestedTag.getRole());
attributeValue = def;
} // end if
// now add attribute to enclosing parent (i.e. : this object)
addElement(attributeValue);
}
/**
* Process nested ≶add> tag.
* Method calls by nested ≶add> tags.
* Nested attribute is added to current list.
* If role is defined, nested attribute is wrapped into an untypped definition
* containing attribute value and role.
*/
public void processNestedTag(AddTag nestedTag) throws JspException
{
// Get real value and check role
// If role is set, add it in attribute definition if any.
// If no attribute definition, create untyped one, and set role.
Object attributeValue = nestedTag.getRealValue();
AttributeDefinition def;
if( nestedTag.getRole() != null )
{
try
{
def = ((AttributeDefinition)attributeValue);
}
catch( ClassCastException ex )
{
def = new UntyppedAttribute( attributeValue );
}
def.setRole(nestedTag.getRole());
attributeValue = def;
} // end if
// now add attribute to enclosing parent (i.e. : this object)
addElement(attributeValue);
}
/**
* Do start tag.
*/
public int doStartTag() throws JspException
{
return EVAL_BODY_INCLUDE;
}
/**
* Do end tag.
*/
public int doEndTag() throws JspException
{
PutListTagParent enclosingParent = findEnclosingParent();
enclosingParent.processNestedTag( this );
// Clear list to avoid reuse
releaseInternal();
return EVAL_PAGE;
}
/**
* Find enclosing parent tag accepting this tag.
* @throws JspException If we can't find an appropriate enclosing tag.
*/
protected PutListTagParent findEnclosingParent() throws JspException {
try
{
PutListTagParent parent = (PutListTagParent)findAncestorWithClass(this,PutListTagParent.class);
if( parent == null )
{
throw new JspException( "Error - tag putList : enclosing tag doesn't accept 'putList' tag." );
}
return parent;
}
catch( ClassCastException ex )
{
throw new JspException( "Error - tag putList : enclosing tag doesn't accept 'putList' tag." );
}
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/PutListTagParent.java
Index: PutListTagParent.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/PutListTagParent.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import javax.servlet.jsp.JspException;
/**
* Tag Class implementing this interface can contains nested PutTag.
* This interface define a method calls by nested tag.
*/
public interface PutListTagParent {
/**
* Add an attribute to container.
* @param nestedTag Nested PutTag defining the attribute.
*/
void processNestedTag(PutListTag nestedTag) throws JspException;
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/PutTag.java
Index: PutTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/PutTag.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.taglib.tiles.util.TagUtils;
import org.apache.struts.tiles.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.IllegalAccessException;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.PageContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
/**
* Put an attribute in enclosing attribute container tag.
* Enclosing attribute container tag can be : <insert> or <definition>.
* Exception is thrown if no appropriate tag can be found.
* Put tag can have following atributes :
* <li>
* <ul>name : Name of the attribute</ul>
* <ul>value | content : value to put as attribute</ul>
* <ul>type : value type. Only valid if value is a String and is set by
* value="something" or by a bean.
* Possible type are : string (value is used as direct string),
* page | template (value is used as a page url to insert),
* definition (value is used as a definition name to insert)</ul>
* <ul>direct : Specify if value is to be used as a direct string or as a
* page url to insert. This is another way to specify the type. It only apply
* if value is set as a string, and type is not present.</ul>
* <ul>beanName : Name of a bean used for setting value. Only valid if value is not set.
* If property is specified, value come from bean's property. Otherwise, bean
* itself is used for value.</ul>
* <ul>beanProperty : Name of the property used for retrieving value.</ul>
* <ul>beanScope : Scope containing bean. </ul>
* <ul>role : Role to check when 'insert' will be called. If enclosing tag is
* <insert>, role is checked immediately. If enclosing tag is
* <definition>, role will be checked when this definition will be
* inserted.</ul>
* </li>
* Value can also come from tag body. Tag body is taken into account only if
* value is not set by one of the tag attributes. In this case Attribute type is
* "string", unless tag body define another type.
*/
public class PutTag extends BodyTagSupport implements ComponentConstants {
/* JSP Tag attributes */
/** Name of attribute to put in component context */
protected String attributeName = null;
/** associated attribute value */
private Object value = null;
/** JSP Template compatibility */
private String direct = null;
/** Requested type for the value */
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;
/* Internal properties */
/** cached real value computed from tag attributes */
protected Object realValue = null;
/**
* default constructor
*/
public PutTag() {
super();
}
/**
* Release all allocated resources.
*/
public void release() {
super.release();
attributeName = null;
valueType = null;
direct = null;
value = null;
beanName = null;
beanProperty = null;
beanScope = null;
role = null;
}
/**
* Release internal properties.
*/
protected void releaseInternal()
{
realValue = null;
}
/**
* Set property
*/
public void setName(String value){
this.attributeName = value;
}
/**
* Set property
*/
public String getName(){
return attributeName;
}
/**
* Set property.
* Method added to satisfy Tomcat (bug ?)
*/
public void setValue(String value){
this.value = value;
}
/**
* Set property.
* Method added to satisfy Tomcat (bug ?)
*/
public String getValue(){
return (String)this.value;
}
/**
* Set property
*/
public void setValue(Object value){
this.value = value;
}
/**
* Set property value as an object
* Added because some web container react badly to value as Object.
*/
public void setObjectValue(Object value){
this.value = value;
}
/**
* Set property
* Method added to satisfy Tomcat (bug ?)
*/
public void setContent(String value){
this.value = value;
}
/**
* Get property
* Method added to satisfy Tomcat (bug ?)
*/
public String getContent(){
return (String)value;
}
/**
* Set property
*/
public void setContent(Object value){
this.value = value;
}
/**
* Set property
* Method added for compatibility with JSP1.1
*/
public void setDirect( String isDirect ){
this.direct = isDirect;
}
/**
* Set property
*/
public void setType( String value ){
this.valueType = value;
}
/**
* Get property
*/
public String getType( ){
return this.valueType;
}
/**
* Set property.
*/
public void setBeanName(String value){
this.beanName = value;
}
/**
* Set property.
*/
public void setBeanProperty(String value){
this.beanProperty = value;
}
/**
* Set property.
*/
public void setBeanScope(String value){
this.beanScope = value;
}
/**
* Set role attribute
* @param name The role the user must be in to store content.
*/
public void setRole(String role) {
this.role = role;
}
/**
* Get role attribute
* @return The role defined in the tag or null.
*/
public String getRole() {
return role;
}
/**
* Get real value according to tag attribute.
* Real value is the value compute after attribute processing :
* @return real value.
* @throws JspTagException If something goes wrong while getting value from bean.
*/
public Object getRealValue() throws JspException
{
if( realValue == null )
computeRealValue();
return realValue;
}
/**
* Compute real value according to tag attributes.
* @throws JspTagException If something goes wrong while getting value from bean.
*/
protected void computeRealValue() throws JspException
{
// Compute real value from attributes set.
realValue = value;
// Does value comes from a bean ?
if( value == null && beanName != null )
{
getRealValueFromBean();
} // end if
// Is there a type set ?
// First check direct attribute, and translate it to a valueType.
// Then, evaluate valueType, and create requested typed attribute.
// If valueType is not set, use the value "as is".
if( valueType==null && direct != null )
{
if( Boolean.valueOf(direct).booleanValue() == true )
valueType = "string";
else
valueType = "path";
} // end if
if( value != null && valueType!=null && !(value instanceof AttributeDefinition) )
{
String strValue = value.toString();
if( valueType.equalsIgnoreCase( "string" ) )
{
realValue = new DirectStringAttribute( strValue );
}
else if( valueType.equalsIgnoreCase( "page" ) )
{
realValue = new PathAttribute( strValue );
}
else if( valueType.equalsIgnoreCase( "template" ) )
{
realValue = new PathAttribute( strValue );
}
else if( valueType.equalsIgnoreCase( "instance" ) )
{
realValue = new DefinitionNameAttribute( strValue );
}
else if( valueType.equalsIgnoreCase( "definition" ) )
{
realValue = new DefinitionNameAttribute( strValue );
}
else
{ // bad type
throw new JspException( "Warning - Tag put : Bad type '" + valueType + "'." );
} // end if
} // end if
}
/**
* Extract real value from specified bean.
* @throws JspTagException If something goes wrong while getting value from bean.
*/
protected void getRealValueFromBean() throws JspException
{
try
{
Object bean = TagUtils.retrieveBean( beanName, beanScope, pageContext );
if( bean != null && beanProperty != null )
realValue = TagUtils.getProperty( bean, beanProperty );
else
realValue = bean; // value can be null
}
catch( NoSuchMethodException ex )
{
throw new JspException( "Error - component.PutAttributeTag : Error while retrieving value from bean '"
+ beanName + "' with property '"
+ beanProperty + "' in scope '"
+ beanScope + "'. (exception : "
+ ex.getMessage() );
}
catch( InvocationTargetException ex )
{
throw new JspException( "Error - component.PutAttributeTag : Error while retrieving value from bean '"
+ beanName + "' with property '"
+ beanProperty + "' in scope '"
+ beanScope + "'. (exception : "
+ ex.getMessage() );
}
catch( IllegalAccessException ex )
{
throw new JspException( "Error - component.PutAttributeTag : Error while retrieving value from bean '"
+ beanName + "' with property '"
+ beanProperty + "' in scope '"
+ beanScope + "'. (exception : "
+ ex.getMessage() );
}
}
/**
* Do start tag
*/
public int doStartTag() throws JspException
{
// Does we need to evaluate body ?
if( value == null && beanName == null )
return EVAL_BODY_TAG;
// Value is set, don't evaluate body.
return SKIP_BODY;
}
/**
* Do end tag
*/
public int doEndTag() throws JspException
{
// If nothing is set, value must come from body
if( value == null && beanName == null )
{ // body
// Test body content in case of empty body.
if( bodyContent != null )
value = bodyContent.getString();
else
value = "";
}
callParent();
// clean up tag handler for reuse.
releaseInternal();
return EVAL_PAGE;
}
/**
* Find parent tag which must implements AttributeContainer.
* @throws JspException If we can't find an appropriate enclosing tag.
*/
protected void callParent() throws JspException
{
// Get enclosing parent,
PutTagParent enclosingParent = findEnclosingPutTagParent();
enclosingParent.processNestedTag( this );
}
/**
* Find parent tag which must implements AttributeContainer.
* @throws JspException If we can't find an appropriate enclosing tag.
*/
protected PutTagParent findEnclosingPutTagParent() throws JspException {
try
{
PutTagParent parent = (PutTagParent)findAncestorWithClass(this,PutTagParent.class);
if( parent == null )
{
throw new JspException( "Error - tag put : enclosing tag doesn't accept 'put' tag." );
}
return parent;
}
catch( ClassCastException ex )
{
throw new JspException( "Error - tag put : enclosing tag doesn't accept 'put' tag." );
}
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/PutTagParent.java
Index: PutTagParent.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/PutTagParent.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import javax.servlet.jsp.JspException;
/**
* Tag Class implementing this interface can contains nested PutTag.
* This interface define a method calls by nested tag.
*/
public interface PutTagParent {
/**
* Process the nested tag.
* @param nestedTag Nested to process.
*/
void processNestedTag(PutTag nestedTag ) throws JspException;
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/UseAttributeTag.java
Index: UseAttributeTag.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/UseAttributeTag.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.taglib.tiles.util.TagUtils;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
/**
* Custom tag that expose a component attribute to page.
*
*/
public final class UseAttributeTag extends TagSupport {
// ----------------------------------------------------- Instance Variables
/**
* Class name of object.
*/
private String classname = null;
/**
* The scope name.
*/
private String scopeName = null;
/**
* The scope value.
*/
private int scope = PageContext.PAGE_SCOPE;
/**
* The attribute name to be exposed.
*/
private String attributeName = 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.
*/
protected boolean isErrorIgnored = false;
// ------------------------------------------------------------- Properties
/**
* Release all allocated resources.
*/
public void release() {
super.release();
attributeName = null;
classname = null;
scope = PageContext.PAGE_SCOPE;
scopeName = null;
isErrorIgnored = false;
// Parent doesn't clear id, so we do it
// bug reported by Heath Chiavettone on 18 Mar 2002
id = null;
}
/**
* Return the length.
*/
public String getClassname() {
return (this.classname);
}
/**
* Set the length.
*
* @param length The new length
*/
public void setClassname(String name) {
this.classname = name;
}
/**
* Set attributeName
*/
public void setName(String value){
this.attributeName = value;
}
/**
* Set the offset.
*
* @param offset The new offset
*/
public void setScope(String scope) {
this.scopeName = scope;
}
/**
* Set ignore attribute
*/
public void setIgnore(boolean ignore)
{
this.isErrorIgnored = ignore;
}
// --------------------------------------------------------- Public Methods
/**
* Expose the requested attribute from component context.
*
* @exception JspException if a JSP exception has occurred
*/
public int doStartTag() throws JspException
{
if( id==null )
id=attributeName;
ComponentContext compContext = (ComponentContext)pageContext.getAttribute( ComponentConstants.COMPONENT_CONTEXT, pageContext.REQUEST_SCOPE);
if( compContext == null )
throw new JspException ( "Error - tag.useAttribute : component context is not defined. Check tag syntax" );
Object value = compContext.getAttribute(attributeName);
// Check if value exist and if we must send a runtime exception
if( value == null )
if(!isErrorIgnored)
throw new JspException ( "Error - tag.useAttribute : attribute '"+ attributeName + "' not found in context. Check tag syntax" );
else
return SKIP_BODY;
if( scopeName != null )
{
scope = TagUtils.getScope( scopeName, PageContext.PAGE_SCOPE );
if(scope!=ComponentConstants.COMPONENT_SCOPE)
pageContext.setAttribute(id, value, scope);
}
else
pageContext.setAttribute(id, value);
// Continue processing this page
return SKIP_BODY;
}
/**
* Clean up after processing this enumeration.
*
* @exception JspException if a JSP exception has occurred
*/
public int doEndTag() throws JspException
{
return (EVAL_PAGE);
}
}
1.1 jakarta-struts/src/share/org/apache/struts/taglib/tiles/UseAttributeTei.java
Index: UseAttributeTei.java
===================================================================
/*
* $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/tiles/UseAttributeTei.java,v 1.1 2002/06/25 03:16:30 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2002/06/25 03:16:30 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.taglib.tiles;
import javax.servlet.jsp.tagext.TagData;
import javax.servlet.jsp.tagext.TagExtraInfo;
import javax.servlet.jsp.tagext.VariableInfo;
/**
* Implementation of <code>TagExtraInfo</code> for the <b>UseAtribute</b>
* tag, identifying the scripting object(s) to be made visible.
*
*/
public final class UseAttributeTei extends TagExtraInfo {
/**
* Return information about the scripting variables to be created.
*/
public VariableInfo[] getVariableInfo(TagData data) {
String classname = data.getAttributeString("classname");
if( classname == null )
classname = "java.lang.Object";
String id = data.getAttributeString("id");
if( id == null )
id = data.getAttributeString("name");;
return new VariableInfo[] {
new VariableInfo(id,
classname,
true,
VariableInfo.AT_END)
};
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>