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

Last change on this file since 25635 was 25635, checked in by sjm84, 12 years ago

Fixing Greenstone 3's use (or lack thereof) of generics, this was done automatically so we may want to change it over time. This change will also auto-format any files that have not already been formatted.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 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.*;
14import java.io.StringReader;
15import org.xml.sax.InputSource;
16import javax.xml.parsers.DocumentBuilder;
17import javax.xml.parsers.DocumentBuilderFactory;
18
19import java.io.*;
20import org.xml.sax.*;
21import javax.xml.parsers.SAXParserFactory;
22import javax.xml.parsers.ParserConfigurationException;
23import javax.xml.parsers.SAXParser;
24
25import java.io.PrintWriter;
26import java.io.Serializable;
27import java.io.StringWriter;
28
29import org.apache.log4j.*;
30
31public class SystemAction extends Action
32{
33
34 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.SystemAction.class.getName());
35
36 String tempVal = "";
37
38 /** process a request */
39 public Node process(Node message_node)
40 {
41
42 Element message = this.converter.nodeToElement(message_node);
43
44 // assume only one request
45 Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
46
47 String subaction = request.getAttribute(GSXML.SUBACTION_ATT);
48 UserContext userContext = new UserContext(request);
49 // get the param list
50 Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
51 HashMap<String, Serializable> params = GSXML.extractParams(cgi_param_list, false);
52
53 Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
54
55 String coll = (String) params.get(GSParams.SYSTEM_CLUSTER);
56
57 String to = "";
58 if (coll != null && !coll.equals(""))
59 {
60 to = coll;
61 }
62
63 Element mr_request_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
64 Element mr_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SYSTEM, to, userContext);
65 mr_request_message.appendChild(mr_request);
66
67 Element system = this.doc.createElement(GSXML.SYSTEM_ELEM);
68 mr_request.appendChild(system);
69
70 // will need to change the following if can do more than one system request at once
71 if (subaction.equals("c"))
72 { // configure
73 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_CONFIGURE);
74 String info = (String) params.get(GSParams.SYSTEM_SUBSET);
75 system.setAttribute(GSXML.SYSTEM_SUBSET_ATT, info);
76 }
77 else if (subaction.equals("ping")) { // can ping the server or a collection
78 String name = (String) params.get(GSParams.SYSTEM_MODULE_NAME);
79
80 if(name != null && !name.equals("")) {
81 // Pinging a collection (or module) with ?a=s&sa=ping&st=collection&sn=<colName>
82 // is a collection-level (servicecluster/module level) ping
83
84 String type = (String) params.get(GSParams.SYSTEM_MODULE_TYPE);
85 if(type == null || type.equals("")) {
86 type = "collection"; // if the st=collection was omitted, assume collection
87 }
88 // ping action set to moduleType=Collection and moduleName=colName
89 system.setAttribute(GSXML.SYSTEM_MODULE_NAME_ATT, name);
90 system.setAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT, type);
91 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_PING);
92 } // else SYSTEM_MODULE_NAME given by the "sn" GSParam is null or empty
93 // meaning server-level ping: ?a=s&sa=ping
94
95 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_PING);
96 }
97 //else if (subaction.equals("is-persistent")){
98 // system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_ISPERSISTENT);
99 //}
100 else
101 {
102 String name = (String) params.get(GSParams.SYSTEM_MODULE_NAME);
103 String type = (String) params.get(GSParams.SYSTEM_MODULE_TYPE);
104
105 system.setAttribute(GSXML.SYSTEM_MODULE_NAME_ATT, name);
106 system.setAttribute(GSXML.SYSTEM_MODULE_TYPE_ATT, type);
107
108 if (subaction.equals("d"))
109 { // delete
110 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_DEACTIVATE);
111
112 }
113 else if (subaction.equals("a"))
114 { // add
115 system.setAttribute(GSXML.TYPE_ATT, GSXML.SYSTEM_TYPE_ACTIVATE);
116 }
117 else
118 {
119 // create the default response
120 // for now just have an error
121 logger.error("bad subaction type");
122 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
123 result.appendChild(page_response);
124
125 return result;
126 }
127 }
128
129 Node response_message = this.mr.process(mr_request_message);
130
131 Element response = GSXML.duplicateWithNewName(this.doc, (Element) GSXML.getChildByTagName(response_message, GSXML.RESPONSE_ELEM), GSXML.RESPONSE_ELEM, true);
132 addSiteMetadata(response, userContext);
133 addInterfaceOptions(response);
134
135 result.appendChild(response);
136 return result;
137
138 }
139
140}
Note: See TracBrowser for help on using the repository browser.