dgraham 2003/07/11 16:57:15
Modified: src/share/org/apache/struts/tiles/actions
DefinitionDispatcherAction.java
Log:
Formatted code.
Revision Changes Path
1.7 +80 -61
jakarta-struts/src/share/org/apache/struts/tiles/actions/DefinitionDispatcherAction.java
Index: DefinitionDispatcherAction.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/tiles/actions/DefinitionDispatcherAction.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DefinitionDispatcherAction.java 4 Feb 2003 02:23:08 -0000 1.6
+++ DefinitionDispatcherAction.java 11 Jul 2003 23:57:15 -0000 1.7
@@ -59,13 +59,14 @@
*
*/
-
package org.apache.struts.tiles.actions;
import java.io.IOException;
import java.io.PrintWriter;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
@@ -78,7 +79,6 @@
import org.apache.struts.tiles.FactoryNotFoundException;
import org.apache.struts.tiles.NoSuchDefinitionException;
-
/**
* <p>An <strong>Action</strong> that dispatches to a Tiles Definition
* that is named by the request parameter whose name is specified
@@ -111,10 +111,12 @@
* @author Cedric Dumoulin
* @version $Revision$ $Date$
*/
-
public class DefinitionDispatcherAction extends Action {
- /** Commons Logging instance. */
- protected static Log log = LogFactory.getLog(DefinitionDispatcherAction.class);
+
+ /**
+ * Commons Logging instance.
+ */
+ protected static Log log = LogFactory.getLog(DefinitionDispatcherAction.class);
/**
* Process the specified HTTP request, and create the corresponding HTTP
@@ -130,71 +132,88 @@
* an exception
* @since Struts 1.1
*/
- public ActionForward execute(ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response)
- throws Exception
- {
+ public ActionForward execute(
+ ActionMapping mapping,
+ ActionForm form,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws Exception {
+
// Identify the request parameter containing the method name
// If none defined, use "def"
String parameter = mapping.getParameter();
if (parameter == null) {
- parameter = "def";
+ parameter = "def";
}
// Identify the method name to be dispatched to
String name = request.getParameter(parameter);
- if (name == null)
- {
- String msg = "Definition dispatcher action : can't get parameter '"
- + parameter + "'.";
- printError( response, msg );
- return (null);
- }
+ if (name == null) {
+ String msg =
+ "Definition dispatcher action : can't get parameter '"
+ + parameter
+ + "'.";
+
+ printError(response, msg);
+ return null;
+ }
// Try to dispatch to requested definition
- try
- {
- // Read definition from factory, but we can create it here.
- ComponentDefinition definition = DefinitionsUtil.getDefinition( name,
request, getServlet().getServletContext() );
- if(log.isDebugEnabled())
- log.debug("get Definition " + definition );
- DefinitionsUtil.setActionDefinition( request, definition);
- }
- catch( FactoryNotFoundException ex )
- {
- printError( response, "Error - DefinitionDispatcherAction : Can't get
definition factory.");
- return (mapping.findForward("error"));
- }
- catch( NoSuchDefinitionException ex )
- {
- printError( response, "Error - DefinitionDispatcherAction : Can't get
definition '" + name +"'.");
- return (mapping.findForward("error"));
- }
- catch( DefinitionsFactoryException ex )
- {
- printError( response, "Error - DefinitionDispatcherAction : General Factory
error '" + ex.getMessage() +"'.");
- return (mapping.findForward("error"));
- }
- catch( Exception ex )
- {
- printError( response, "Error - DefinitionDispatcherAction : General error
'" + ex.getMessage() +"'.");
- return (mapping.findForward("error"));
+ try {
+ // Read definition from factory, but we can create it here.
+ ComponentDefinition definition =
+ DefinitionsUtil.getDefinition(
+ name,
+ request,
+ getServlet().getServletContext());
+
+ if (log.isDebugEnabled()) {
+ log.debug("get Definition " + definition);
+ }
+
+ DefinitionsUtil.setActionDefinition(request, definition);
+
+ } catch (FactoryNotFoundException ex) {
+ printError(
+ response,
+ "Error - DefinitionDispatcherAction : Can't get definition
factory.");
+ return mapping.findForward("error");
+
+ } catch (NoSuchDefinitionException ex) {
+ printError(
+ response,
+ "Error - DefinitionDispatcherAction : Can't get definition '"
+ + name
+ + "'.");
+ return mapping.findForward("error");
+
+ } catch (DefinitionsFactoryException ex) {
+ printError(
+ response,
+ "Error - DefinitionDispatcherAction : General Factory error '"
+ + ex.getMessage()
+ + "'.");
+ return mapping.findForward("error");
+
+ } catch (Exception ex) {
+ printError(
+ response,
+ "Error - DefinitionDispatcherAction : General error '"
+ + ex.getMessage()
+ + "'.");
+ return mapping.findForward("error");
}
- return (mapping.findForward("success"));
+ return mapping.findForward("success");
- }
+ }
- protected void printError( HttpServletResponse response, String msg )
- throws IOException
- {
- response.setContentType("text/plain");
- PrintWriter writer = response.getWriter();
- writer.println(msg);
- writer.flush();
- writer.close();
+ protected void printError(HttpServletResponse response, String msg)
+ throws IOException {
+ response.setContentType("text/plain");
+ PrintWriter writer = response.getWriter();
+ writer.println(msg);
+ writer.flush();
+ writer.close();
}
}
-
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]