comparison gnv/src/main/java/de/intevation/gnv/action/LoadAction.java @ 670:b89b31293772

Implemented first things to store/load projects. gnv/trunk@793 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 17 Mar 2010 13:31:38 +0000
parents
children 93b4dedc4e37
comparison
equal deleted inserted replaced
669:ef1ff5fdab5b 670:b89b31293772
1 package de.intevation.gnv.action;
2
3 import de.intevation.gnv.propertiesreader.PropertiesReaderFactory;
4 import de.intevation.gnv.propertiesreader.PropertiesReader;
5 import de.intevation.gnv.util.XMLUtils;
6
7 import java.io.InputStream;
8
9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11
12 import org.apache.commons.fileupload.FileItemIterator;
13 import org.apache.commons.fileupload.FileItemStream;
14 import org.apache.commons.fileupload.servlet.ServletFileUpload;
15
16 import org.apache.log4j.Logger;
17
18 import org.apache.struts.action.ActionForm;
19 import org.apache.struts.action.ActionForward;
20 import org.apache.struts.action.ActionMapping;
21
22 import org.w3c.dom.Document;
23
24 /**
25 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de)
26 */
27 public class LoadAction extends ArtifactDatabaseActionBase {
28
29 public static final String RESOURCE_UPLOAD_FAILURE = "upload.failure";
30
31 private static Logger logger = Logger.getLogger(LoadAction.class);
32
33 public LoadAction() {
34 super();
35 }
36
37 public ActionForward execute(
38 ActionMapping mapping,
39 ActionForm form,
40 HttpServletRequest request,
41 HttpServletResponse response)
42 throws Exception
43 {
44 logger.info("Import artifact.");
45
46 ServletFileUpload upload = new ServletFileUpload();
47 Document artifactDocument = null;
48
49 FileItemIterator iter = upload.getItemIterator(request);
50 while (iter.hasNext()) {
51 FileItemStream item = (FileItemStream) iter.next();
52 String name = item.getFieldName();
53
54 if (name.equals("document")) {
55 InputStream stream = item.openStream();
56 artifactDocument = XMLUtils.readDocument(stream);
57 }
58 }
59
60 // no document found or not valid
61 if (artifactDocument == null) {
62 logger.error("Upload failure: No document found or invalid.");
63
64 request.setAttribute(
65 CommunicationKeys.REQUEST_EXCEPTION_PROJECT,
66 RESOURCE_UPLOAD_FAILURE);
67
68 return super.getExceptionForward(mapping);
69 }
70
71 // TODO Do something with our nice xml document
72 // Use DescribeUI Action to set required attributes which are parsed in
73 // jsp files.
74 return super.execute(mapping, form, request, response);
75 }
76 }
77 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org