1 | package org.greenstone.gsdl3.action;
|
---|
2 |
|
---|
3 | import org.greenstone.gsdl3.core.ModuleInterface;
|
---|
4 | import org.greenstone.gsdl3.util.*;
|
---|
5 |
|
---|
6 | // XML classes
|
---|
7 | import org.w3c.dom.Node;
|
---|
8 | import org.w3c.dom.Element;
|
---|
9 | import org.w3c.dom.Document;
|
---|
10 |
|
---|
11 | // other java stuff
|
---|
12 | import java.io.File;
|
---|
13 | import java.util.HashMap;
|
---|
14 |
|
---|
15 | public class SystemAction extends Action {
|
---|
16 |
|
---|
17 | /** process a request */
|
---|
18 | public Element process (Element message) {
|
---|
19 |
|
---|
20 | // assume only one request
|
---|
21 | Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
|
---|
22 |
|
---|
23 | String subaction = request.getAttribute(GSXML.SUBACTION_ATT);
|
---|
24 | String lang = request.getAttribute(GSXML.LANG_ATT);
|
---|
25 | // get the param list
|
---|
26 | Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
|
---|
27 | HashMap params = GSXML.extractParams(cgi_param_list, false);
|
---|
28 |
|
---|
29 | Element page = doc_.createElement(GSXML.PAGE_ELEM);
|
---|
30 | page.setAttribute(GSXML.LANG_ATT, lang);
|
---|
31 |
|
---|
32 | // add the lang stuff from message
|
---|
33 | page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true));
|
---|
34 | // add the system stuff from message
|
---|
35 | page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
|
---|
36 |
|
---|
37 | String coll = (String)params.get(GSCGI.COLLECTION_ARG);
|
---|
38 |
|
---|
39 | String to = "";
|
---|
40 | if (coll!=null && !coll.equals("")) {
|
---|
41 | to = coll;
|
---|
42 | }
|
---|
43 |
|
---|
44 | Element mr_request_message = doc_.createElement(GSXML.MESSAGE_ELEM);
|
---|
45 | Element mr_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_SYSTEM, to, lang);
|
---|
46 | mr_request_message.appendChild(mr_request);
|
---|
47 |
|
---|
48 | Element system = doc_.createElement(GSXML.SYSTEM_ELEM);
|
---|
49 | mr_request.appendChild(system);
|
---|
50 |
|
---|
51 | // will need to change the following if can do more than one system request at once
|
---|
52 | if (subaction.equals("c")) { // configure
|
---|
53 | system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_CONFIGURE);
|
---|
54 | String info = (String)params.get(GSCGI.STATUS_SUBSET_ARG);
|
---|
55 | system.setAttribute(GSXML.SYSTEM_SUBSET_ATT, info);
|
---|
56 |
|
---|
57 | } else {
|
---|
58 | String name = (String)params.get(GSCGI.STATUS_MODULE_NAME_ARG);
|
---|
59 | String type = (String)params.get(GSCGI.STATUS_MODULE_TYPE_ARG);
|
---|
60 |
|
---|
61 | system.setAttribute(GSXML.SYSTEM_MODULE_NAME_ATT, name);
|
---|
62 | system.setAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT, type);
|
---|
63 |
|
---|
64 | if (subaction.equals("d")) { // delete
|
---|
65 | system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_DEACTIVATE);
|
---|
66 |
|
---|
67 | } else if (subaction.equals("a")) { // add
|
---|
68 | system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_ACTIVATE);
|
---|
69 | } else {
|
---|
70 | // create the default response
|
---|
71 | // for now just have an error
|
---|
72 | System.err.println("SystemAction error: bad subaction type");
|
---|
73 | return null;
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | Element response_message = mr_.process(mr_request_message);
|
---|
78 |
|
---|
79 | page.appendChild(GSXML.duplicateWithNewName(doc_, (Element)GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM), GSXML.PAGE_RESPONSE_ELEM, true));
|
---|
80 |
|
---|
81 | // check that the stylesheet is present - cant output the page without one.
|
---|
82 | String stylesheet = GSFile.stylesheetFile(config_, "system.xsl");
|
---|
83 | if (stylesheet==null) {
|
---|
84 | System.err.println("SystemAction Error: system stylesheet not found!");
|
---|
85 | return page;
|
---|
86 | }
|
---|
87 | Document style_doc = converter_.getDOM(new File(stylesheet));
|
---|
88 | GSXSLT.absoluteIncludePaths(style_doc, config_);
|
---|
89 | return (Element)transformer_.transform(style_doc, page);
|
---|
90 |
|
---|
91 |
|
---|
92 | }
|
---|
93 |
|
---|
94 | }
|
---|