cedric 02/02/18 06:50:05
Modified: contrib/tiles/src/share/org/apache/struts/taglib/tiles
ImportAttributeTag.java InsertTag.java PutTag.java
contrib/tiles/src/share/org/apache/struts/tiles
DefinitionsUtil.java
contrib/tiles/src/share/org/apache/struts/tiles/definition
ReloadableDefinitionsFactory.java
contrib/tiles/src/share/org/apache/struts/tiles/xmlDefinition
I18nFactorySet.java
contrib/tiles/src/tutorial/org/apache/struts/example/tiles/invoice
InvoiceForm.java
contrib/tiles/src/tutorial/org/apache/struts/example/tiles/portal
UserMenuAction.java UserMenuSettingsAction.java
UserPortalAction.java UserPortalSettingsAction.java
contrib/tiles/src/tutorial/org/apache/struts/example/tiles/rssChannel
Channels.java
contrib/tiles/src/tutorial/org/apache/struts/example/tiles/test
TestActionTileAction.java
Added: contrib/tiles/src/share/org/apache/struts/tiles
TilesRequestProcessor.java TilesServlet.java
Log:
Updated sources after change in Struts1.1 ActionServlet
Added a TilesRequestProcessor, compliant to new Struts mechanism
Added a TilesServlet, to run Tiles without Struts
Revision Changes Path
1.4 +3 -3
jakarta-struts/contrib/tiles/src/share/org/apache/struts/taglib/tiles/ImportAttributeTag.java
Index: ImportAttributeTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/taglib/tiles/ImportAttributeTag.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ImportAttributeTag.java 27 Dec 2001 17:35:37 -0000 1.3
+++ ImportAttributeTag.java 18 Feb 2002 14:50:03 -0000 1.4
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/taglib/tiles/ImportAttributeTag.java,v
1.3 2001/12/27 17:35:37 cedric Exp $
- * $Revision: 1.3 $
- * $Date: 2001/12/27 17:35:37 $
+ * $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/taglib/tiles/ImportAttributeTag.java,v
1.4 2002/02/18 14:50:03 cedric Exp $
+ * $Revision: 1.4 $
+ * $Date: 2002/02/18 14:50:03 $
* $Author: cedric $
*
*/
1.6 +4 -4
jakarta-struts/contrib/tiles/src/share/org/apache/struts/taglib/tiles/InsertTag.java
Index: InsertTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/taglib/tiles/InsertTag.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- InsertTag.java 27 Dec 2001 17:35:37 -0000 1.5
+++ InsertTag.java 18 Feb 2002 14:50:03 -0000 1.6
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/taglib/tiles/InsertTag.java,v
1.5 2001/12/27 17:35:37 cedric Exp $
- * $Revision: 1.5 $
- * $Date: 2001/12/27 17:35:37 $
+ * $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/taglib/tiles/InsertTag.java,v
1.6 2002/02/18 14:50:03 cedric Exp $
+ * $Revision: 1.6 $
+ * $Date: 2002/02/18 14:50:03 $
* $Author: cedric $
*
*/
@@ -43,7 +43,7 @@
*
* @author David Geary
* @author Cedric Dumoulin
- * @version $Revision: 1.5 $ $Date: 2001/12/27 17:35:37 $
+ * @version $Revision: 1.6 $ $Date: 2002/02/18 14:50:03 $
*/
public class InsertTag extends DefinitionTagSupport implements PutTagParent,
ComponentConstants, PutListTagParent
{
1.3 +10 -6
jakarta-struts/contrib/tiles/src/share/org/apache/struts/taglib/tiles/PutTag.java
Index: PutTag.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/taglib/tiles/PutTag.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PutTag.java 27 Dec 2001 17:35:37 -0000 1.2
+++ PutTag.java 18 Feb 2002 14:50:03 -0000 1.3
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/taglib/tiles/PutTag.java,v
1.2 2001/12/27 17:35:37 cedric Exp $
- * $Revision: 1.2 $
- * $Date: 2001/12/27 17:35:37 $
+ * $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/taglib/tiles/PutTag.java,v
1.3 2002/02/18 14:50:03 cedric Exp $
+ * $Revision: 1.3 $
+ * $Date: 2002/02/18 14:50:03 $
* $Author: cedric $
*
*/
@@ -260,7 +260,7 @@
{
// Compute real value from attributes set.
realValue = value;
-
+
// Does value comes from a bean ?
if( value == null && beanName != null )
{
@@ -297,7 +297,7 @@
else if( valueType.equalsIgnoreCase( "instance" ) )
{
realValue = new DefinitionNameAttribute( strValue );
- }
+ }
else if( valueType.equalsIgnoreCase( "definition" ) )
{
realValue = new DefinitionNameAttribute( strValue );
@@ -371,7 +371,11 @@
// If nothing is set, value must come from body
if( value == null && beanName == null )
{ // body
- value = bodyContent.getString();
+ // Test body content in case of empty body.
+ if( bodyContent != null )
+ value = bodyContent.getString();
+ else
+ value = "";
}
callParent();
1.4 +23 -18
jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/DefinitionsUtil.java
Index: DefinitionsUtil.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/DefinitionsUtil.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DefinitionsUtil.java 27 Dec 2001 17:35:38 -0000 1.3
+++ DefinitionsUtil.java 18 Feb 2002 14:50:04 -0000 1.4
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/DefinitionsUtil.java,v
1.3 2001/12/27 17:35:38 cedric Exp $
- * $Revision: 1.3 $
- * $Date: 2001/12/27 17:35:38 $
+ * $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/DefinitionsUtil.java,v
1.4 2002/02/18 14:50:04 cedric Exp $
+ * $Revision: 1.4 $
+ * $Date: 2002/02/18 14:50:04 $
* $Author: cedric $
*
*/
@@ -145,10 +145,25 @@
public static ComponentDefinitionsFactory createDefinitionsFactory(ServletContext
servletContext, ServletConfig servletConfig)
throws DefinitionsFactoryException
{
- initUserDebugLevel(servletConfig);
- ComponentDefinitionsFactory factory = new
ReloadableDefinitionsFactory(servletContext, servletConfig); ;
- DefinitionsUtil.setDefinitionsFactory(factory, servletContext );
- return factory;
+ // Check if already exist in context
+ ComponentDefinitionsFactory factory = getDefinitionsFactory( servletContext);
+ if( factory != null )
+ return factory;
+ // Doesn' exist, create it and save it in context
+ // Ensure that only one is created by synchronizing section. This imply a
+ // second checking.
+ // Todo : check that servletContext is unique for this servlet !
+ synchronized (servletContext) {
+ // Check if someone has created it while we had wait for synchonized section
+ factory = getDefinitionsFactory( servletContext);
+ if( factory != null )
+ return factory;
+ // Now really create it
+ initUserDebugLevel(servletConfig);
+ factory = new ReloadableDefinitionsFactory(servletContext, servletConfig); ;
+ setDefinitionsFactory(factory, servletContext );
+ return factory;
+ } // synchronized
}
/**
@@ -162,17 +177,6 @@
}
/**
- * Set definition factory in appropriate servlet context.
- * Convenient method.
- * @param factory Factory to store.
- * @param pageContext Page context containing servlet context.
- */
- static protected void setDefinitionsFactory(ComponentDefinitionsFactory factory,
PageContext pageContext)
- {
- setDefinitionsFactory( factory, pageContext.getServletContext() );
- }
-
- /**
* Get a definition by its name.
* First, retrieve definition factory, and then get requested definition.
* Throw appropriate exception if definition or definition factory is not found.
@@ -229,6 +233,7 @@
/**
* Get instances factory from appropriate servlet context.
* @return Definitions factory or null if not found.
+ * @deprecated since 020207, use
getDefinitionsFactory(pageContext.getServletContext()) instead
*/
static public ComponentDefinitionsFactory getDefinitionsFactory(PageContext
pageContext)
{
1.1
jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/TilesRequestProcessor.java
Index: TilesRequestProcessor.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/TilesRequestProcessor.java,v
1.1 2002/02/18 14:50:04 cedric Exp $
* $Revision: 1.1 $
* $Date: 2002/02/18 14:50:04 $
* $Author: cedric $
*
*/
package org.apache.struts.tiles;
import org.apache.struts.taglib.tiles.ComponentConstants;
import java.util.Locale;
import org.apache.struts.action.RequestProcessor;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.Action;
import org.apache.struts.config.ApplicationConfig;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.InputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import org.apache.struts.taglib.html.Constants;
import org.apache.struts.upload.MultipartRequestWrapper;
/**
* <p><strong>RequestProcessor</strong> contains the processing logic that
* the Struts controller servlet performs as it receives each servlet request
* from the container. </p>
* <p>This processor subclass the Struts one in order to intercept calls to forward
* or include. When such call is done, Tiles processor check if the specified uri
* is a definition name. If true, the definition is retrieved and included. If
* false, the original uri is included or a forward is performed.
* </p>
* @author Cedric Dumoulin
* @since Tiles 1.1.1
*/
public class TilesRequestProcessor extends RequestProcessor
{
/** Definitions factory */
private ComponentDefinitionsFactory definitionsFactory;
/**
* Initialize this request processor instance.
*
* @param servlet The ActionServlet we are associated with
* @param appConfig The ApplicationConfig we are associated with.
* @throw ServletException If an error occur during initialization
*/
public void init(ActionServlet servlet, ApplicationConfig appConfig)
throws ServletException
{
super.init(servlet, appConfig);
initComponentDefinitionsMapping();
}
/**
* Read component instance mapping configuration file.
* This is where we read files properties.
*/
public void initComponentDefinitionsMapping() throws ServletException //
IOException,
{
try
{
// init component instances
definitionsFactory =
DefinitionsUtil.createDefinitionsFactory(getServletContext(),
servlet.getServletConfig());
}
catch( DefinitionsFactoryException ex )
{
log( "Fail to load Tiles definition factory from processor", ex);
throw new ServletException( ex.getMessage(), ex );
}
log( "Tiles definition factory loaded for processor " );
}
/**
* Do a forward using request dispatcher.
* Forward to requested uri.
* Uri can be a valid uri, or a definition name. If definition name, the
* definition is retrieved and included. Otherwise, a forward is done to
* original uri.
* @param uri Uri or Definition name to forward
* @param request Current page request
* @param response Current page response
*/
protected void doForward(String uri, HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
// Do we do a forward (original behavior) or an include ?
boolean doInclude = false;
// Controller associated to a definition, if any
Controller controller = null;
ComponentContext tileContext = null;
try
{
// Get current tile context if any.
// If context exist, we will do an include
tileContext = ComponentContext.getContext( request );
doInclude = (tileContext!=null );
ComponentDefinition definition;
// Process tiles definition names only if a definition factory exist,
// and definition is found.
if( definitionsFactory != null )
{ // Get definition of tiles/component corresponding to uri.
definition = definitionsFactory.getDefinition(uri, request,
getServletContext());
if( definition != null )
{ // We have a definition.
// We use it to complete missing attribute in context.
// We also get uri, controller.
uri = definition.getPath();
controller = definition.getOrCreateController();
if( tileContext == null )
{
tileContext = new ComponentContext( definition.getAttributes() );
ComponentContext.setContext( tileContext, request);
}
else
tileContext.addMissing( definition.getAttributes() );
} // end if
} // end if
// Process definition set in Action, if any.
definition = DefinitionsUtil.getActionDefinition(request);
if( definition != null )
{ // We have a definition.
// We use it to complete missing attribute in context.
// We also overload uri and controller if set in definition.
if(definition.getPath()!=null)
uri = definition.getPath();
if(definition.getOrCreateController()!=null)
controller = definition.getOrCreateController();
if( tileContext == null )
{
tileContext = new ComponentContext( definition.getAttributes() );
ComponentContext.setContext( tileContext, request);
}
else
tileContext.addMissing( definition.getAttributes() );
} // end if
}
catch( java.lang.InstantiationException ex )
{
throw new ServletException( "Can't create associated controller", ex );
}
catch( DefinitionsFactoryException ex )
{
throw new ServletException( ex );
}
// Execute controller associated to definition, if any.
if(controller !=null)
{
controller.perform( tileContext, request, response, getServletContext());
} // end if
// Do dispatching : search dispatcher, then dispatch
RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
if (rd == null)
{ // error
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
getInternal().getMessage
("requestDispatcher", uri));
return;
} // end if
// If request comes from a previous Tile, do an include.
// This allows to insert an action in a Tile.
if( doInclude )
rd.include(request, response);
else
rd.forward(request, response); // original behavior
}
/**
* Do an include of specified uri.
* Uri can be a valid uri, or a definition name. If definition name, the
* definition is retrieved and included. Otherwise,
* original uri is included.
* @param uri Uri or Definition name to include
* @param request Current page request
* @param response Current page response
*/
protected void doInclude(String uri, HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doForward( uri, request, response );
}
}
1.1
jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/TilesServlet.java
Index: TilesServlet.java
===================================================================
package org.apache.struts.tiles;
import org.apache.struts.tiles.DefinitionsUtil;
import org.apache.struts.tiles.DefinitionsFactoryException;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
/**
* A simple servlet initializing and loading Tiles factory.
* This servlet can be declared in web.xml, as well as all initialization
* parameters available with the specified factory.
* This servlet is intended to be used in application using Tiles without Struts.
* @author Cedric Dumoulin
*/
public class TilesServlet extends HttpServlet
{
/**
* Initialize this servlet
*
* @exception ServletException if we cannot configure ourselves correctly
*/
public void init() throws ServletException
{
log( "Start Tiles initialization");
System.out.println( "Start Tiles initialization" );
super.init();
// init component instances
try
{
System.out.println( "Start try" );
DefinitionsUtil.createDefinitionsFactory( getServletContext(),
getServletConfig() );
log( "Tiles Factory loaded");
}
catch( DefinitionsFactoryException ex )
{
log( "Tiles Factory load fail !", ex);
throw new ServletException(ex );
}
}
}
1.2 +5 -3
jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/definition/ReloadableDefinitionsFactory.java
Index: ReloadableDefinitionsFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/definition/ReloadableDefinitionsFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ReloadableDefinitionsFactory.java 27 Dec 2001 17:41:35 -0000 1.1
+++ ReloadableDefinitionsFactory.java 18 Feb 2002 14:50:04 -0000 1.2
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/definition/ReloadableDefinitionsFactory.java,v
1.1 2001/12/27 17:41:35 cedric Exp $
- * $Revision: 1.1 $
- * $Date: 2001/12/27 17:41:35 $
+ * $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/definition/ReloadableDefinitionsFactory.java,v
1.2 2002/02/18 14:50:04 cedric Exp $
+ * $Revision: 1.2 $
+ * $Date: 2002/02/18 14:50:04 $
* $Author: cedric $
*
*/
@@ -137,6 +137,8 @@
throws DefinitionsFactoryException
{
String classname = (String)properties.get(DEFINITIONS_FACTORY_CLASSNAME);
+ if(classname!=null)
+ return createFactoryFromClassname( servletContext, properties, classname);
return new I18nFactorySet( servletContext, properties );
}
1.4 +1 -1
jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/xmlDefinition/I18nFactorySet.java
Index: I18nFactorySet.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/share/org/apache/struts/tiles/xmlDefinition/I18nFactorySet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- I18nFactorySet.java 27 Dec 2001 17:35:38 -0000 1.3
+++ I18nFactorySet.java 18 Feb 2002 14:50:04 -0000 1.4
@@ -197,7 +197,7 @@
this.filenames = new ArrayList(tokenizer.countTokens());
while( tokenizer.hasMoreTokens() )
{
- this.filenames.add(tokenizer.nextToken());
+ this.filenames.add(tokenizer.nextToken().trim());
}
loaded = new HashMap();
1.2 +136 -4
jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/invoice/InvoiceForm.java
Index: InvoiceForm.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/invoice/InvoiceForm.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InvoiceForm.java 1 Aug 2001 14:36:43 -0000 1.1
+++ InvoiceForm.java 18 Feb 2002 14:50:04 -0000 1.2
@@ -7,16 +7,148 @@
import java.util.Vector;
import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionForm;
/**
*/
-public final class InvoiceForm extends Invoice {
+public final class InvoiceForm extends ActionForm {
-
-
- // --------------------------------------------------------- Public Methods
+ /**
+ * Shipping address
+ */
+ private Address shippingAddress;
+
+ /**
+ * Bill address
+ */
+ private Address billAddress;
+
+ /**
+ * Invoice total amount
+ */
+ private double amount;
+
+ /**
+ * Customer firstname
+ */
+ private String firstname;
+
+ /**
+ * Customer last name
+ */
+ private String lastname;
+
+ public InvoiceForm()
+ {
+ shippingAddress = new Address();
+ billAddress = new Address();
+ }
+
+ /**
+ * Access method for the shippingAddress property.
+ *
+ * @return the current value of the shippingAddress property
+ */
+ public Address getShippingAddress()
+ {
+ return shippingAddress;}
+
+ /**
+ * @return void
+ * Sets the value of the shippingAddress property.
+ *
+ * @param aShippingAddress the new value of the shippingAddress property
+ */
+ public void setShippingAddress(Address aShippingAddress)
+ {
+ shippingAddress = aShippingAddress;
+ }
+
+ /**
+ * Access method for the billAddress property.
+ *
+ * @return the current value of the billAddress property
+ */
+ public Address getBillAddress()
+ {
+ return billAddress;
+ }
+
+ /**
+ * @return void
+ * Sets the value of the billAddress property.
+ *
+ * @param aBillAddress the new value of the billAddress property
+ */
+ public void setBillAddress(Address aBillAddress)
+ {
+ billAddress = aBillAddress;
+ }
+
+ /**
+ * Access method for the amount property.
+ *
+ * @return the current value of the amount property
+ */
+ public double getAmount()
+ {
+ return amount;
+ }
+
+ /**
+ * @return void
+ * Sets the value of the amount property.
+ *
+ * @param aAmount the new value of the amount property
+ */
+ public void setAmount(double aAmount)
+ {
+ amount = aAmount;
+ }
+
+ /**
+ * Access method for the firstname property.
+ *
+ * @return the current value of the firstname property
+ */
+ public String getFirstname()
+ {
+ return firstname;
+ }
+
+ /**
+ * @return void
+ * Sets the value of the firstname property.
+ *
+ * @param aFirstname the new value of the firstname property
+ */
+ public void setFirstname(String aFirstname)
+ {
+ firstname = aFirstname;
+ }
+
+ /**
+ * Access method for the lastname property.
+ *
+ * @return the current value of the lastname property
+ */
+ public String getLastname()
+ {
+ return lastname;
+ }
+
+ /**
+ * @return void
+ * Sets the value of the lastname property.
+ *
+ * @param aLastname the new value of the lastname property
+ */
+ public void setLastname(String aLastname)
+ {
+ lastname = aLastname;
+ }
}
1.2 +42 -32
jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/portal/UserMenuAction.java
Index: UserMenuAction.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/portal/UserMenuAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UserMenuAction.java 27 Dec 2001 17:37:46 -0000 1.1
+++ UserMenuAction.java 18 Feb 2002 14:50:04 -0000 1.2
@@ -35,7 +35,7 @@
* If menu settings are not defined for user, defined them based on tiles
* attributes used as default.
*
- * This implementation extends Struts Action, and also define Tiles Controller.
+ * This implementation extends Struts Action, and also define Tiles Controller
interface.
* This allows to use it as well as a controller type or a controller url. If used
* as controller type, Struts Action functionality are not availables.
*
@@ -55,7 +55,7 @@
* </ul>
*
* @author Cedric Dumoulin
- * @version $Revision: 1.1 $ $Date: 2001/12/27 17:37:46 $
+ * @version $Revision: 1.2 $ $Date: 2002/02/18 14:50:04 $
*/
public final class UserMenuAction extends TilesAction implements Controller {
@@ -63,18 +63,19 @@
/** debug flag */
public static boolean debug = false;
- /** Tile attribute name. Value of this tile's attribute is the name used to
store settings in user context */
- public static String STORE_UNDER_ATTRIBUTE = "storeUnderName";
+ /** Tile attribute containing name used to store user settings in session
context */
+ public static String USER_SETTINGS_NAME_ATTRIBUTE = "userSettingsName";
/** Default name used to store settings in session context */
- public static String DEFAULT_STORE_UNDER_NAME = "menu.DEFAULT_STORE_UNDER_NAME";
+ public static String DEFAULT_USER_SETTINGS_NAME =
"tiles.examples.portal.USER_MENU_SETTINGS";
- /** Name under which item choices are stored in application context */
- public static final String CHOICES_ITEMS_NAME = "menu.AvailableItems";
+ /** Default name used to store menu catalog in application scope */
+ public static String DEFAULT_MENU_CATALOG_NAME =
"tiles.examples.portal.MenuCatalog";
+ /** Tile attribute containing name used to store menu catalog in application
scope */
+ public static String MENU_CATALOG_NAME_ATTRIBUTE = "catalogName";
+ /** Tile attribute containing name of the settings definition used to
initialize catalog */
+ public static final String CATALOG_SETTING_ATTRIBUTE = "catalogSettings";
- /** Tile attribute name. List of menu or items used as choices */
- public static final String CHOICES_ITEMS_ATTRIBUTE = "defaultChoice";
-
- /** Tile attribute name. User items are stored under this name in tile's
context */
+ /** Tile attribute containing items to render */
public static String USER_ITEMS_ATTRIBUTE = "items";
/**
@@ -119,11 +120,9 @@
{
if(debug)
System.out.println("Enter action UserMenuAction");
- // Get current session.
- HttpSession session = request.getSession();
// Load user settings from user context
- MenuSettings settings = loadUserSettings( context, session );
+ MenuSettings settings = getUserSettings( request, context);
// Set parameters for rendering page
context.putAttribute( USER_ITEMS_ATTRIBUTE, settings.getItems() );
@@ -141,13 +140,16 @@
* in Tile's context.
* If settings are not found, initialized them.
*/
- public static MenuSettings loadUserSettings( ComponentContext context,
HttpSession session )
+ public static MenuSettings getUserSettings( HttpServletRequest request,
ComponentContext context )
throws ServletException
{
+ // Get current session.
+ HttpSession session = request.getSession();
+
// Retrieve attribute name used to store settings.
- String userSettingsName = (String)context.getAttribute( STORE_UNDER_ATTRIBUTE );
+ String userSettingsName = (String)context.getAttribute(
USER_SETTINGS_NAME_ATTRIBUTE );
if( userSettingsName == null )
- userSettingsName = DEFAULT_STORE_UNDER_NAME;
+ userSettingsName = DEFAULT_USER_SETTINGS_NAME;
// Get user list from user context
MenuSettings settings = (MenuSettings)session.getAttribute( userSettingsName );
@@ -172,30 +174,38 @@
}
/**
- * Load list of menu entries available as choices to user.
- * Look in servlet context, or create it from list of object provided
+ * Get catalog of available menu entries.
+ * This implementation create catalog list from the provided menu bar entries.
+ *
* as Tiles attribute.
* Create it from default values if needed.
*/
- static public List loadMenuChoices( ComponentContext context,
HttpServletRequest request, ServletContext servletContext)
+ static public List getCatalog( ComponentContext context, HttpServletRequest
request, ServletContext servletContext)
throws ServletException
{
- // Get list of choices from context
- List choices = (List)servletContext.getAttribute( CHOICES_ITEMS_NAME );
+ // Retrieve name used to store catalog in application context.
+ // If not found, use default name
+ String catalogName = (String)context.getAttribute(
MENU_CATALOG_NAME_ATTRIBUTE );
+ if(catalogName == null)
+ catalogName = DEFAULT_MENU_CATALOG_NAME;
+
+ // Get catalog from context
+ List catalog = (List)servletContext.getAttribute( catalogName );
// If not found, initialize it from provided default menu
- if( choices == null )
+ if( catalog == null )
{
- Object dflt = context.getAttribute( CHOICES_ITEMS_ATTRIBUTE );
- if( dflt == null )
- throw new ServletException( "Can't find default menu item choices under
name '" + CHOICES_ITEMS_ATTRIBUTE + "'" );
- choices = new ArrayList();
- extractItems(choices, dflt, request, servletContext);
- if( choices.size() == 0 )
- throw new ServletException( "Can't initialize menu items choices" );
+ Object menuBar = context.getAttribute( CATALOG_SETTING_ATTRIBUTE );
+ if( menuBar == null )
+ throw new ServletException( "Attribute '" + CATALOG_SETTING_ATTRIBUTE +
"' must be set. It define entries used in catalog" );
+ catalog = new ArrayList();
+ extractItems(catalog, menuBar, request, servletContext);
+ if( catalog.size() == 0 )
+ throw new ServletException( "Can't initialize menu items catalog" );
+
// save it for future use
- servletContext.setAttribute( CHOICES_ITEMS_NAME, choices );
+ servletContext.setAttribute( catalogName, catalog );
} // end if
- return choices;
+ return catalog;
}
/**
* Extract menu items from passed object. Items are stored in parameter
'result'.
1.2 +12 -13
jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/portal/UserMenuSettingsAction.java
Index: UserMenuSettingsAction.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/portal/UserMenuSettingsAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UserMenuSettingsAction.java 27 Dec 2001 17:37:46 -0000 1.1
+++ UserMenuSettingsAction.java 18 Feb 2002 14:50:04 -0000 1.2
@@ -79,12 +79,11 @@
if(debug)
System.out.println("Enter action UserMenuSettingsAction");
- HttpSession session = request.getSession();
MenuSettingsForm actionForm = (MenuSettingsForm)form;
// Load user menu settings and available list of choices
- MenuSettings settings = UserMenuAction.loadUserSettings( context, session );
- List choices = UserMenuAction.loadMenuChoices( context, request,
getServlet().getServletContext() );
+ MenuSettings settings = UserMenuAction.getUserSettings( request, context );
+ List catalog = UserMenuAction.getCatalog( context, request,
getServlet().getServletContext() );
// Check if form is submitted
// If true, read, check and store new values submitted by user.
@@ -94,7 +93,7 @@
System.out.println("form submitted");
settings.reset();
- settings.addItems( checkSelected(actionForm.getSelected(), choices) );
+ settings.addItems( getItems(actionForm.getSelected(), catalog) );
if(debug)
System.out.println( "settings : " +settings.toString() );
actionForm.reset();
@@ -103,21 +102,21 @@
// Prepare data for view tile
context.putAttribute( "userItems", settings.getItems() );
- context.putAttribute( "choiceItems", choices );
+ context.putAttribute( "catalog", catalog );
if(debug)
System.out.println("Exit action UserMenuSettingsAction");
- return null; //(mapping.findForward("editPortal"));
+ return null;
}
/**
* Check selected items, and return apppropriate list of items.
- * For each item in selected list, check if it exist in available choice.
+ * For each item in selected list, check if it exist in catalog.
* Also check for double.
* @param selectedKey Key of selected items (generally, link url)
- * @param choices List of avalaible items choice to compare against.
+ * @param catalog List of avalaible items to compare against.
*/
- static protected List checkSelected( String[] selectedKey, List choices )
+ static protected List getItems( String[] selectedKey, List catalog )
{
List selectedList = java.util.Arrays.asList( selectedKey );
List result = new ArrayList(selectedList.size());
@@ -126,7 +125,7 @@
Iterator iter = selectedList.iterator();
while( iter.hasNext() )
{
- MenuItem item = getItemByKey( iter.next(), choices);
+ MenuItem item = getItem( iter.next(), catalog);
if( item != null )
result.add(item );
} // end loop
@@ -135,12 +134,12 @@
/**
* Get item by its key in list of choices
* @param key Key of selected items (generally, link url)
- * @param choices List of avalaible items choice to compare against.
+ * @param catalog List of avalaible items to compare against.
* @return corresponding item or null if not found.
*/
- static protected MenuItem getItemByKey( Object key, List choices )
+ static protected MenuItem getItem( Object key, List catalog )
{
- Iterator iter = choices.iterator();
+ Iterator iter = catalog.iterator();
while( iter.hasNext() )
{
MenuItem item = (MenuItem)iter.next();
1.2 +34 -35
jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/portal/UserPortalAction.java
Index: UserPortalAction.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/portal/UserPortalAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UserPortalAction.java 27 Dec 2001 17:37:46 -0000 1.1
+++ UserPortalAction.java 18 Feb 2002 14:50:04 -0000 1.2
@@ -32,23 +32,23 @@
* attributes used as default.
*
* @author Cedric Dumoulin
- * @version $Revision: 1.1 $ $Date: 2001/12/27 17:37:46 $
+ * @version $Revision: 1.2 $ $Date: 2002/02/18 14:50:04 $
*/
public final class UserPortalAction extends TilesAction {
- /** Name used to store settings in session context */
- public static String DEFAULT_CONTEXT_ID = "portal.USER_PORTAL_SETTINGS";
- /** Tile parameter name */
- public static String PARAM_NUMCOLS = "numCols";
- /** Tile parameter name */
- public static String PARAM_LIST = "list";
- /** Tile parameter name */
- public static String PARAM_LIST_LABELS = "listLabels";
- /** Tile parameter name */
- public static String PARAM_ID = "userContextId";
- /** Tile parameter name */
- public static String PORTAL_CHOICES_ID = "tiles.portal.PortalChoices";
+ /** Default name used to store settings in session context */
+ public static String DEFAULT_USER_SETTINGS_NAME =
"tiles.examples.portal.USER_PORTAL_SETTINGS";
+ /** Tile attribute containing number of columns in portal */
+ public static String NUMCOLS_ATTRIBUTE = "numCols";
+ /** Tile attribute containing list prefix name */
+ public static String LIST_ATTRIBUTE = "list";
+ /** Tile attribute containing list of labels prefix name */
+ public static String LIST_LABELS_ATTRIBUTE = "labels";
+ /** Tile attribute containing name used to store user settings in session
context */
+ public static String USER_SETTINGS_NAME_ATTRIBUTE = "userSettingsName";
+ /** Name used to store portal catalog in application scope */
+ public static String PORTAL_CATALOG_NAME =
"tiles.examples.portal.PortalCatalog";
// --------------------------------------------------------- Public Methods
@@ -77,11 +77,9 @@
throws IOException, ServletException
{
//System.out.println("Enter action UserPortalAction");
- // Get current session.
- HttpSession session = request.getSession();
// Get user portal list from user context
- PortalSettings settings = getSettings( context, session );
+ PortalSettings settings = getSettings( request, context);
// Set parameters for tiles
context.putAttribute( "numCols", Integer.toString(settings.getNumCols()) );
for( int i=0; i<settings.getNumCols(); i++ )
@@ -89,19 +87,21 @@
//System.out.println( "settings=" + settings );
//System.out.println("Exit action UserPortalAction");
- return null; //(mapping.findForward("success"));
+ return null;
}
/**
* Retrieve user setting from session.
* If settings are not found, initialized them.
*/
- public static PortalSettings getSettings( ComponentContext context, HttpSession
session )
+ public static PortalSettings getSettings( HttpServletRequest request,
ComponentContext context )
{
+ // Get current session.
+ HttpSession session = request.getSession();
// Retrieve user context id used to store settings
- String userSettingsId = (String)context.getAttribute( PARAM_ID );
+ String userSettingsId = (String)context.getAttribute(
USER_SETTINGS_NAME_ATTRIBUTE );
if( userSettingsId == null )
- userSettingsId = DEFAULT_CONTEXT_ID;
+ userSettingsId = DEFAULT_USER_SETTINGS_NAME;
// Get user portal list from user context
PortalSettings settings = (PortalSettings)session.getAttribute( userSettingsId
);
@@ -109,12 +109,11 @@
if( settings == null )
{ // List doesn't exist, create it and initialize it from Tiles parameters
settings = new PortalSettings();
- settings.setNumCols( (String)context.getAttribute( PARAM_NUMCOLS ) );
+ settings.setNumCols( (String)context.getAttribute( NUMCOLS_ATTRIBUTE ) );
for( int i=0; i<settings.getNumCols(); i++ )
{
- List col = (List)context.getAttribute( ((String)PARAM_LIST+i) );
- //List labels = (List)context.getAttribute( ((String)PARAM_LIST_LABELS+i) );
- settings.setListAt( i, col );
+ List tiles = (List)context.getAttribute( ((String)LIST_ATTRIBUTE+i) );
+ settings.setListAt( i, tiles );
} // end loop
// Save user settings in session
@@ -128,23 +127,23 @@
* Retrieve portal choices object.
* Create it from default values if needed.
*/
- static public PortalChoices getPortalChoices( ComponentContext context,
ServletContext servletContext)
+ static public PortalCatalog getPortalCatalog( ComponentContext context,
ServletContext servletContext)
{
- PortalChoices choices = (PortalChoices)servletContext.getAttribute(
PORTAL_CHOICES_ID );
- if( choices == null )
- { // Initialize choices
- choices = new PortalChoices();
- int numCols = Integer.parseInt( (String)context.getAttribute( PARAM_NUMCOLS
) );
+ PortalCatalog catalog = (PortalCatalog)servletContext.getAttribute(
PORTAL_CATALOG_NAME );
+ if( catalog == null )
+ { // Initialize catalog
+ catalog = new PortalCatalog();
+ int numCols = Integer.parseInt( (String)context.getAttribute(
NUMCOLS_ATTRIBUTE ) );
for( int i=0; i<numCols; i++ )
{
- List col = (List)context.getAttribute( ((String)PARAM_LIST+i) );
- List labels = (List)context.getAttribute( ((String)PARAM_LIST_LABELS+i) );
- choices.addChoices( col, labels );
+ List tiles = (List)context.getAttribute( ((String)LIST_ATTRIBUTE+i) );
+ List labels = (List)context.getAttribute(
((String)LIST_LABELS_ATTRIBUTE+i) );
+ catalog.addTiles( tiles, labels );
} // end loop
- servletContext.setAttribute( PORTAL_CHOICES_ID, choices );
+ servletContext.setAttribute( PORTAL_CATALOG_NAME, catalog );
} // end if
- return choices;
+ return catalog;
}
}
1.2 +7 -8
jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/portal/UserPortalSettingsAction.java
Index: UserPortalSettingsAction.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/portal/UserPortalSettingsAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UserPortalSettingsAction.java 27 Dec 2001 17:37:46 -0000 1.1
+++ UserPortalSettingsAction.java 18 Feb 2002 14:50:04 -0000 1.2
@@ -38,7 +38,7 @@
* </ul>
*
* @author Cedric Dumoulin
- * @version $Revision: 1.1 $ $Date: 2001/12/27 17:37:46 $
+ * @version $Revision: 1.2 $ $Date: 2002/02/18 14:50:04 $
*/
public final class UserPortalSettingsAction extends TilesAction {
@@ -71,12 +71,11 @@
throws IOException, ServletException
{
//System.out.println("Enter action UserPortalSettingsAction");
- HttpSession session = request.getSession();
PortalSettingsForm prefsForm = (PortalSettingsForm)form;
// Get user portal settings from user context
- PortalSettings settings = UserPortalAction.getSettings( context, session );
- PortalChoices choices = UserPortalAction.getPortalChoices( context,
getServlet().getServletContext() );
+ PortalSettings settings = UserPortalAction.getSettings( request, context);
+ PortalCatalog catalog = UserPortalAction.getPortalCatalog( context,
getServlet().getServletContext() );
if( prefsForm.isSubmitted() )
{ // read arrays
@@ -85,7 +84,7 @@
// Set settings cols according to user choice
for( int i=0;i<prefsForm.getNumCol(); i++)
{
- settings.setListAt( i, choices.checkKeys( prefsForm.getNewCol(i)) );
+ settings.setListAt( i, catalog.getTiles( prefsForm.getNewCol(i)) );
} // end loop
//System.out.println( "settings : " +settings.toString() );
@@ -97,11 +96,11 @@
for( int i=0;i<settings.getNumCols(); i++ )
{
prefsForm.addCol(settings.getListAt(i) );
- prefsForm.addColLabels(choices.getChoiceLabelsForKeys( settings.getListAt(i))
);
+ prefsForm.addColLabels(catalog.getTileLabels( settings.getListAt(i)) );
} // end loop
- prefsForm.setChoices(choices.getChoices() );
- prefsForm.setChoiceLabels(choices.getChoiceLabels() );
+ prefsForm.setChoices(catalog.getTiles() );
+ prefsForm.setChoiceLabels(catalog.getTilesLabels() );
//System.out.println("Exit action UserPortalSettingsAction");
return null; //(mapping.findForward("editPortal"));
1.4 +5 -4
jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/rssChannel/Channels.java
Index: Channels.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/rssChannel/Channels.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Channels.java 27 Dec 2001 17:35:38 -0000 1.3
+++ Channels.java 18 Feb 2002 14:50:04 -0000 1.4
@@ -31,7 +31,8 @@
* @expects path={uri} on command line or as parameter property to ActionMapping.
* @expects an input page or error forwarding if exception digesting RSS
* @author Ted Husted
- * @version $Revision: 1.3 $ $Date: 2001/12/27 17:35:38 $
+ * @author Cedric Dumoulin
+ * @version $Revision: 1.4 $ $Date: 2002/02/18 14:50:04 $
*/
public final class Channels extends Action {
@@ -153,9 +154,9 @@
/*
- * $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/rssChannel/Channels.java,v
1.3 2001/12/27 17:35:38 cedric Exp $
- * $Revision: 1.3 $
- * $Date: 2001/12/27 17:35:38 $
+ * $Header:
/home/cvs/jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/rssChannel/Channels.java,v
1.4 2002/02/18 14:50:04 cedric Exp $
+ * $Revision: 1.4 $
+ * $Date: 2002/02/18 14:50:04 $
*
* ====================================================================
*
1.2 +3 -1
jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/test/TestActionTileAction.java
Index: TestActionTileAction.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/contrib/tiles/src/tutorial/org/apache/struts/example/tiles/test/TestActionTileAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestActionTileAction.java 10 Sep 2001 13:05:03 -0000 1.1
+++ TestActionTileAction.java 18 Feb 2002 14:50:05 -0000 1.2
@@ -29,7 +29,8 @@
* <code>SubscriptionForm</code> from the currently specified subscription.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2001/09/10 13:05:03 $
+ * @author Cedric Dumoulin
+ * @version $Revision: 1.2 $ $Date: 2002/02/18 14:50:05 $
*/
public final class TestActionTileAction extends Action {
@@ -79,6 +80,7 @@
{
// Read definition from factory, but we can create it here.
ComponentDefinition definition = DefinitionsUtil.getDefinition( param,
request, getServlet().getServletContext() );
+ //definition.putAttribute( "attributeName", "aValue" );
DefinitionsUtil.setActionDefinition( request, definition);
}
catch( FactoryNotFoundException ex )
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>