You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by dg...@apache.org on 2003/08/16 20:21:31 UTC
cvs commit: jakarta-struts/src/tiles-documentation/org/apache/struts/webapp/tiles/portal UserPortalSettingsAction.java UserPortalAction.java
dgraham 2003/08/16 11:21:31
Modified: src/tiles-documentation/org/apache/struts/webapp/tiles/portal
UserPortalSettingsAction.java UserPortalAction.java
Log:
Formatting, bad imports.
Revision Changes Path
1.4 +35 -48 jakarta-struts/src/tiles-documentation/org/apache/struts/webapp/tiles/portal/UserPortalSettingsAction.java
Index: UserPortalSettingsAction.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/tiles-documentation/org/apache/struts/webapp/tiles/portal/UserPortalSettingsAction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- UserPortalSettingsAction.java 21 Jul 2003 15:18:46 -0000 1.3
+++ UserPortalSettingsAction.java 16 Aug 2003 18:21:31 -0000 1.4
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -61,9 +61,6 @@
package org.apache.struts.webapp.tiles.portal;
-import java.io.IOException;
-
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -73,7 +70,6 @@
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.tiles.actions.TilesAction;
-
/**
* Implementation of <strong>Action</strong> that populates an instance of
* <code>SubscriptionForm</code> from the currently specified subscription.
@@ -90,13 +86,8 @@
* @author Cedric Dumoulin
* @version $Revision$ $Date$
*/
-
public final class UserPortalSettingsAction extends TilesAction {
-
- // --------------------------------------------------------- Public Methods
-
-
/**
* Process the specified HTTP request, and create the corresponding HTTP
* response (or forward to another web component that will create it).
@@ -120,42 +111,38 @@
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
- throws Exception
- {
- //System.out.println("Enter action UserPortalSettingsAction");
- PortalSettingsForm prefsForm = (PortalSettingsForm)form;
-
- // Get user portal settings from user context
- PortalSettings settings = UserPortalAction.getSettings( request, context);
- PortalCatalog catalog = UserPortalAction.getPortalCatalog( context, getServlet().getServletContext() );
-
- if( prefsForm.isSubmitted() )
- { // read arrays
- //System.out.println("form submitted");
-
- // Set settings cols according to user choice
- for( int i=0;i<prefsForm.getNumCol(); i++)
- {
- settings.setListAt( i, catalog.getTiles( prefsForm.getNewCol(i)) );
- } // end loop
-
- //System.out.println( "settings : " +settings.toString() );
- prefsForm.reset();
- //return null; // (mapping.findForward("viewPortal"));
- }
-
- // Set lists values to be shown
- for( int i=0;i<settings.getNumCols(); i++ )
- {
- prefsForm.addCol(settings.getListAt(i) );
- prefsForm.addColLabels(catalog.getTileLabels( settings.getListAt(i)) );
- } // end loop
+ throws Exception {
+
+ PortalSettingsForm prefsForm = (PortalSettingsForm) form;
+
+ // Get user portal settings from user context
+ PortalSettings settings = UserPortalAction.getSettings(request, context);
+ PortalCatalog catalog =
+ UserPortalAction.getPortalCatalog(
+ context,
+ getServlet().getServletContext());
+
+ if (prefsForm.isSubmitted()) { // read arrays
+
+ // Set settings cols according to user choice
+ for (int i = 0; i < prefsForm.getNumCol(); i++) {
+ settings.setListAt(i, catalog.getTiles(prefsForm.getNewCol(i)));
+ }
+
+ prefsForm.reset();
+
+ }
+
+ // Set lists values to be shown
+ for (int i = 0; i < settings.getNumCols(); i++) {
+ prefsForm.addCol(settings.getListAt(i));
+ prefsForm.addColLabels(catalog.getTileLabels(settings.getListAt(i)));
+ }
- prefsForm.setChoices(catalog.getTiles() );
- prefsForm.setChoiceLabels(catalog.getTilesLabels() );
+ prefsForm.setChoices(catalog.getTiles());
+ prefsForm.setChoiceLabels(catalog.getTilesLabels());
- //System.out.println("Exit action UserPortalSettingsAction");
- return null; //(mapping.findForward("editPortal"));
+ return null;
}
}
1.4 +112 -84 jakarta-struts/src/tiles-documentation/org/apache/struts/webapp/tiles/portal/UserPortalAction.java
Index: UserPortalAction.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/tiles-documentation/org/apache/struts/webapp/tiles/portal/UserPortalAction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- UserPortalAction.java 21 Jul 2003 15:18:46 -0000 1.3
+++ UserPortalAction.java 16 Aug 2003 18:21:31 -0000 1.4
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -61,11 +61,9 @@
package org.apache.struts.webapp.tiles.portal;
-import java.io.IOException;
import java.util.List;
import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@@ -76,7 +74,6 @@
import org.apache.struts.tiles.ComponentContext;
import org.apache.struts.tiles.actions.TilesAction;
-
/**
* This controller load user portal settings and put them in tile context.
* If portal settings are not defined for user, defined them based on tiles
@@ -85,24 +82,39 @@
* @author Cedric Dumoulin
* @version $Revision$ $Date$
*/
-
public final class UserPortalAction extends TilesAction {
- /** 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 */
+ /**
+ * 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 */
+
+ /**
+ * Tile attribute containing list prefix name.
+ */
public static String LIST_ATTRIBUTE = "list";
- /** Tile attribute containing list of labels prefix name */
+
+ /**
+ * 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
+ /**
+ * 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";
/**
* Process the specified HTTP request, and create the corresponding HTTP
@@ -127,77 +139,93 @@
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
- throws Exception
- {
- //System.out.println("Enter action UserPortalAction");
-
- // Get user portal list from user context
- PortalSettings settings = getSettings( request, context);
- // Set parameters for tiles
- context.putAttribute( "numCols", Integer.toString(settings.getNumCols()) );
- for( int i=0; i<settings.getNumCols(); i++ )
- context.putAttribute( "list"+i, settings.getListAt(i) );
-
- //System.out.println( "settings=" + settings );
- //System.out.println("Exit action UserPortalAction");
- return null;
+ throws Exception {
+
+ // Get user portal list from user context
+ PortalSettings settings = getSettings(request, context);
+
+ // Set parameters for tiles
+ context.putAttribute("numCols", Integer.toString(settings.getNumCols()));
+
+ for (int i = 0; i < settings.getNumCols(); i++) {
+ context.putAttribute("list" + i, settings.getListAt(i));
+ }
+
+ return null;
}
/**
* Retrieve user setting from session.
* If settings are not found, initialized them.
*/
- 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( USER_SETTINGS_NAME_ATTRIBUTE );
- if( userSettingsId == null )
- userSettingsId = DEFAULT_USER_SETTINGS_NAME;
-
- // Get user portal list from user context
- PortalSettings settings = (PortalSettings)session.getAttribute( userSettingsId );
-
- if( settings == null )
- { // List doesn't exist, create it and initialize it from Tiles parameters
- settings = new PortalSettings();
- settings.setNumCols( (String)context.getAttribute( NUMCOLS_ATTRIBUTE ) );
- for( int i=0; i<settings.getNumCols(); i++ )
- {
- List tiles = (List)context.getAttribute( ((String)LIST_ATTRIBUTE+i) );
- settings.setListAt( i, tiles );
- } // end loop
-
- // Save user settings in session
- session.setAttribute( userSettingsId, settings);
- } // end if
-
- return settings;
- }
-
- /**
- * Retrieve portal choices object.
- * Create it from default values if needed.
- */
- static public PortalCatalog getPortalCatalog( ComponentContext context, ServletContext servletContext)
- {
- 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 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_CATALOG_NAME, catalog );
- } // end if
+ public static PortalSettings getSettings(
+ HttpServletRequest request,
+ ComponentContext context) {
- return catalog;
- }
+ // Get current session.
+ HttpSession session = request.getSession();
-}
+ // Retrieve user context id used to store settings
+ String userSettingsId =
+ (String) context.getAttribute(USER_SETTINGS_NAME_ATTRIBUTE);
+
+ if (userSettingsId == null) {
+ userSettingsId = DEFAULT_USER_SETTINGS_NAME;
+ }
+
+ // Get user portal list from user context
+ PortalSettings settings =
+ (PortalSettings) session.getAttribute(userSettingsId);
+
+ if (settings == null) {
+ // List doesn't exist, create it and initialize it from Tiles parameters
+ settings = new PortalSettings();
+ settings.setNumCols((String) context.getAttribute(NUMCOLS_ATTRIBUTE));
+
+ for (int i = 0; i < settings.getNumCols(); i++) {
+ List tiles =
+ (List) context.getAttribute(((String) LIST_ATTRIBUTE + i));
+
+ settings.setListAt(i, tiles);
+ }
+
+ // Save user settings in session
+ session.setAttribute(userSettingsId, settings);
+ }
+
+ return settings;
+ }
+ /**
+ * Retrieve portal choices object.
+ * Create it from default values if needed.
+ */
+ static public PortalCatalog getPortalCatalog(
+ ComponentContext context,
+ ServletContext servletContext) {
+
+ 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 tiles =
+ (List) context.getAttribute(((String) LIST_ATTRIBUTE + i));
+
+ List labels =
+ (List) context.getAttribute(
+ ((String) LIST_LABELS_ATTRIBUTE + i));
+
+ catalog.addTiles(tiles, labels);
+ }
+ servletContext.setAttribute(PORTAL_CATALOG_NAME, catalog);
+ }
+
+ return catalog;
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org