source: greenstone3/trunk/src/java/org/greenstone/gsdl3/action/SystemAction.java@ 16688

Last change on this file since 16688 was 16688, checked in by davidb, 16 years ago

Changed 'Element process(Element)' in ModuleInterface to 'Node process(Node)'. After some deliberation is was decided this is a more useful (generic) layer of the DOM to pass information around in. Helps with the DocType problem when producing XSL Transformed pages, for example. When this was an Element, it would loose track of its DocType. Supporting method provided in XMLConverter 'Element nodeToElement(Node)' which checks a nodes docType and casts to Element if appropriate, or if a Document, typecasts to that and then extracts the top-level Element. With this fundamental change in ModuleInterface, around 20 files needed to be updated (Actions, Services, etc) that build on top of 'process()' to reflect this change, and use nodeToElement where necessary.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1package org.greenstone.gsdl3.action;
2
3import org.greenstone.gsdl3.core.ModuleInterface;
4import org.greenstone.gsdl3.util.*;
5
6// XML classes
7import org.w3c.dom.Node;
8import org.w3c.dom.Element;
9import org.w3c.dom.Document;
10
11// other java stuff
12import java.io.File;
13import java.util.HashMap;
14
15import org.apache.log4j.*;
16
17public class SystemAction extends Action {
18
19 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.SystemAction.class.getName());
20
21 /** process a request */
22 public Node process (Node message_node) {
23
24 Element message = this.converter.nodeToElement(message_node);
25
26 // assume only one request
27 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
28
29 String subaction = request.getAttribute(GSXML.SUBACTION_ATT);
30 String lang = request.getAttribute(GSXML.LANG_ATT);
31 String uid = request.getAttribute(GSXML.USER_ID_ATT);
32 // get the param list
33 Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
34 HashMap params = GSXML.extractParams(cgi_param_list, false);
35
36 Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
37
38 String coll = (String)params.get(GSParams.SYSTEM_CLUSTER);
39
40 String to = "";
41 if (coll!=null && !coll.equals("")) {
42 to = coll;
43 }
44
45 Element mr_request_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
46 Element mr_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SYSTEM, to, lang, uid);
47 mr_request_message.appendChild(mr_request);
48
49 Element system = this.doc.createElement(GSXML.SYSTEM_ELEM);
50 mr_request.appendChild(system);
51
52 // will need to change the following if can do more than one system request at once
53 if (subaction.equals("c")) { // configure
54 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_CONFIGURE);
55 String info = (String)params.get(GSParams.SYSTEM_SUBSET);
56 system.setAttribute(GSXML.SYSTEM_SUBSET_ATT, info);
57
58 } else {
59 String name = (String)params.get(GSParams.SYSTEM_MODULE_NAME);
60 String type = (String)params.get(GSParams.SYSTEM_MODULE_TYPE);
61
62 system.setAttribute(GSXML.SYSTEM_MODULE_NAME_ATT, name);
63 system.setAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT, type);
64
65 if (subaction.equals("d")) { // delete
66 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_DEACTIVATE);
67
68 } else if (subaction.equals("a")) { // add
69 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_ACTIVATE);
70 } else {
71 // create the default response
72 // for now just have an error
73 logger.error("bad subaction type");
74 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
75 result.appendChild(page_response);
76
77 return result;
78 }
79 }
80
81 Node response_message = this.mr.process(mr_request_message);
82
83 result.appendChild(GSXML.duplicateWithNewName(this.doc, (Element)GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM), GSXML.RESPONSE_ELEM, true));
84 return result;
85
86 }
87
88}
Note: See TracBrowser for help on using the repository browser.