View Javadoc

1   package net.sf.cantina.system;
2   
3   import net.sf.cantina.DataSource;
4   import net.sf.cantina.webgui.StrutsAction;
5   import net.sf.cantina.exceptions.DuplicateKeyException;
6   import org.apache.struts.action.*;
7   import org.apache.struts.validator.DynaValidatorActionForm;
8   
9   import javax.servlet.http.HttpServletRequest;
10  import javax.servlet.http.HttpServletResponse;
11  
12  /***
13   * @author Stephane JAIS
14   */
15  public class CreateDocumentAction
16    extends StrutsAction
17  {
18    public ActionForward execute(ActionMapping mapping,
19                                 ActionForm form,
20                                 HttpServletRequest request,
21                                 HttpServletResponse response)
22      throws Exception
23    {
24  
25      ActionMessages messages = new ActionMessages();
26      ActionErrors errors = new ActionErrors();
27      DynaValidatorActionForm dynaform = (DynaValidatorActionForm) form;
28      String documentId = (String) dynaform.get("documentId");
29      String contentType = (String) dynaform.get("contentType");
30      String realmName = (String) dynaform.get("realmName");
31      Transaction t = new CreateDocumentTransaction(
32        documentId,
33        realmName,
34        contentType,
35        new HttpUser(request)
36      );
37      try
38      {
39        t.execute();
40      } catch (DuplicateKeyException e)
41      {
42        errors.add("documentId", new ActionError("duplicate.document.id",documentId));
43        saveErrors(request,errors);
44        return mapping.findForward(MAPPING_INPUT);
45      }
46      messages.add("documentId",new ActionMessage("document.created",documentId));
47      saveMessages(request,messages);
48      saveInRequest(request,DataSource.getInstance().loadDocument(documentId));
49      return mapping.findForward(MAPPING_SUCCESS);
50    }
51  }
52