View Javadoc

1   /*
2    * Copyright 2003,2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.struts.chain.commands.servlet;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  import org.apache.struts.Globals;
21  import org.apache.struts.action.ActionForm;
22  import org.apache.struts.action.ActionMapping;
23  import org.apache.struts.chain.commands.AbstractPopulateActionForm;
24  import org.apache.struts.chain.contexts.ActionContext;
25  import org.apache.struts.chain.contexts.ServletActionContext;
26  import org.apache.struts.config.ActionConfig;
27  import org.apache.struts.util.RequestUtils;
28  
29  /***
30   * <p>Populate the form bean (if any) for this request.  Sets the multipart
31   * class from the action config in the request attributes.</p>
32   *
33   * @version $Rev: 421119 $ $Date: 2005-11-12 13:01:44 -0500 (Sat, 12 Nov 2005)
34   *          $
35   */
36  public class PopulateActionForm extends AbstractPopulateActionForm {
37      private static final Log log = LogFactory.getLog(PopulateActionForm.class);
38  
39      // ------------------------------------------------------- Protected Methods
40      protected void populate(ActionContext context, ActionConfig actionConfig,
41          ActionForm actionForm)
42          throws Exception {
43          ServletActionContext saContext = (ServletActionContext) context;
44  
45          RequestUtils.populate(actionForm, actionConfig.getPrefix(),
46              actionConfig.getSuffix(), saContext.getRequest());
47      }
48  
49      protected void reset(ActionContext context, ActionConfig actionConfig,
50          ActionForm actionForm) {
51          ServletActionContext saContext = (ServletActionContext) context;
52  
53          actionForm.reset((ActionMapping) actionConfig, saContext.getRequest());
54  
55          // Set the multipart class
56          if (actionConfig.getMultipartClass() != null) {
57              saContext.getRequestScope().put(Globals.MULTIPART_KEY,
58                  actionConfig.getMultipartClass());
59          }
60      }
61  }