1 package net.sf.cantina.system;
2
3 import net.sf.cantina.DataSource;
4 import net.sf.cantina.Document;
5 import net.sf.cantina.webgui.StrutsAction;
6 import net.sf.cantina.exceptions.ObjectNotFoundException;
7 import net.sf.cantina.util.Localizer;
8 import org.apache.struts.action.*;
9 import org.apache.struts.validator.DynaValidatorActionForm;
10
11 import javax.servlet.http.HttpServletRequest;
12 import javax.servlet.http.HttpServletResponse;
13
14 /***
15 * @author Stephane JAIS
16 */
17 public class LoadDocumentAction
18 extends StrutsAction
19 {
20
21 public ActionForward execute(ActionMapping mapping,
22 ActionForm form,
23 HttpServletRequest request,
24 HttpServletResponse response)
25 throws Exception
26 {
27
28 DynaValidatorActionForm dynaform = (DynaValidatorActionForm)form;
29 String documentId = (String)dynaform.get("documentId");
30 ActionErrors errors = new ActionErrors();
31 try
32 {
33 Document document = DataSource.getInstance().loadDocument(documentId);
34 if (dynaform.get("locale") != null &&
35 !"".equals(dynaform.get("locale")) &&
36 document.getContentType().startsWith("text"))
37 dynaform.set("content",
38 new String(document.getContent(Localizer.parseLocaleString((String)dynaform.get("locale"))),"UTF-8"));
39 saveInRequest(request,document);
40 } catch (ObjectNotFoundException e)
41 {
42 errors.add("documentId",new ActionError("document.not.found",documentId));
43 saveErrors(request,errors);
44 return mapping.findForward(MAPPING_INPUT);
45 }
46 return mapping.findForward(MAPPING_SUCCESS);
47 }
48 }