Mercurial > hg > mpdl-group
comparison software/mpdl-services/mpiwg-mpdl-cms-web/src/de/mpg/mpiwg/berlin/mpdl/servlets/cms/DocumentOperation.java @ 23:e845310098ba
diverse Korrekturen
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 27 Nov 2012 12:35:19 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
22:6a45a982c333 | 23:e845310098ba |
---|---|
1 package de.mpg.mpiwg.berlin.mpdl.servlets.cms; | |
2 | |
3 import java.io.IOException; | |
4 import java.io.PrintWriter; | |
5 | |
6 import javax.servlet.ServletConfig; | |
7 import javax.servlet.ServletException; | |
8 import javax.servlet.http.HttpServlet; | |
9 import javax.servlet.http.HttpServletRequest; | |
10 import javax.servlet.http.HttpServletResponse; | |
11 | |
12 import de.mpg.mpiwg.berlin.mpdl.cms.scheduler.CmsChainScheduler; | |
13 import de.mpg.mpiwg.berlin.mpdl.cms.scheduler.CmsDocOperation; | |
14 import de.mpg.mpiwg.berlin.mpdl.servlets.util.ServletUtil; | |
15 | |
16 public class DocumentOperation extends HttpServlet { | |
17 private static final long serialVersionUID = 1L; | |
18 | |
19 public DocumentOperation() { | |
20 super(); | |
21 } | |
22 | |
23 public void init(ServletConfig config) throws ServletException { | |
24 super.init(config); | |
25 } | |
26 | |
27 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
28 request.setCharacterEncoding("utf-8"); | |
29 response.setCharacterEncoding("utf-8"); | |
30 String srcUrlStr = request.getParameter("srcUrl"); | |
31 String docId = request.getParameter("docId"); // id in file system: e.g. /tei/en/Test_1789.xml | |
32 String mainLanguage = request.getParameter("mainLanguage"); // main language of that document | |
33 String elementNames = request.getParameter("elementNames"); | |
34 String operation = request.getParameter("operation"); | |
35 String outputFormat = request.getParameter("outputFormat"); | |
36 if (outputFormat == null) | |
37 outputFormat = "xml"; | |
38 if (outputFormat.equals("xml")) { | |
39 response.setContentType("text/xml"); | |
40 } else { | |
41 response.setContentType("text/html"); | |
42 } | |
43 CmsDocOperation docOperation = new CmsDocOperation(operation, srcUrlStr, null, docId); | |
44 if (mainLanguage != null) | |
45 docOperation.setMainLanguage(mainLanguage); | |
46 String[] elementNamesArray = null; | |
47 if (elementNames != null) | |
48 elementNamesArray = elementNames.split(" "); | |
49 docOperation.setElementNames(elementNamesArray); | |
50 try { | |
51 if (docId == null || docId.isEmpty()) { | |
52 write(response, "Parameter: \"docId\" is not set. Please set parameter \"docId\"."); | |
53 return; | |
54 } | |
55 if (operation.equals("create") || operation.equals("delete")) { | |
56 CmsChainScheduler scheduler = CmsChainScheduler.getInstance(); | |
57 docOperation = scheduler.doOperation(docOperation); | |
58 String jobId = "" + docOperation.getOrderId(); | |
59 String baseUrl = ServletUtil.getInstance().getBaseUrl(request); | |
60 String docJobUrlStr = baseUrl + "/doc/GetDocumentJobs?id=" + jobId; | |
61 if (outputFormat.equals("xml")) { | |
62 write(response, "<result>"); | |
63 write(response, "<docJob>"); | |
64 write(response, "<id>" + jobId + "</id>"); | |
65 write(response, "<url>" + docJobUrlStr + "</url>"); | |
66 write(response, "</docJob>"); | |
67 write(response, "</result>"); | |
68 } else if (outputFormat.equals("html")) { | |
69 write(response, "<html>"); | |
70 write(response, "<h2>" + "Document operation result" + "</h2>"); | |
71 write(response, "See your document operation " + jobId + " <a href=\"" + docJobUrlStr + "\">" + "here" + "</a>"); | |
72 write(response, "</html>"); | |
73 } else if (outputFormat.equals("string")) { | |
74 write(response, docJobUrlStr); | |
75 } | |
76 } else { | |
77 String errorStr = "Error: Operation: " + operation + " is not supported"; | |
78 if (outputFormat.equals("xml")) { | |
79 write(response, "<error>" + errorStr + "</error>"); | |
80 } else { | |
81 write(response, "<html>"); | |
82 write(response, "<h2>" + "Error" + "</h2>"); | |
83 write(response, errorStr); | |
84 } | |
85 } | |
86 PrintWriter out = response.getWriter(); | |
87 out.close(); | |
88 } catch (Exception e) { | |
89 throw new ServletException(e); | |
90 } | |
91 } | |
92 | |
93 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
94 // TODO | |
95 } | |
96 | |
97 private void write(HttpServletResponse response, String str) throws IOException { | |
98 PrintWriter out = response.getWriter(); | |
99 out.write(str); | |
100 } | |
101 | |
102 } |