- Timestamp:
- 2012-02-21T16:26:17+13:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/GeneralAction.java
r24993 r25128 2 2 3 3 import org.greenstone.gsdl3.util.*; 4 import org.greenstone.util.GlobalProperties; 4 5 // XML classes 6 import org.w3c.dom.Document; 5 7 import org.w3c.dom.Node; 6 8 import org.w3c.dom.Element; 9 import org.w3c.dom.NodeList; 7 10 11 import java.io.File; 8 12 import java.util.HashMap; 13 14 import javax.xml.parsers.DocumentBuilder; 15 import javax.xml.parsers.DocumentBuilderFactory; 16 import javax.xml.transform.Result; 17 import javax.xml.transform.Transformer; 18 import javax.xml.transform.TransformerFactory; 19 import javax.xml.transform.dom.DOMSource; 20 import javax.xml.transform.stream.StreamResult; 9 21 10 22 public class GeneralAction extends Action … … 31 43 Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 32 44 HashMap params = GSXML.extractParams(cgi_param_list, false); 45 46 if (params.get("configChangeName") != null && params.get("configChangeValue") != null) 47 { 48 String optionName = (String) params.get("configChangeName"); 49 String optionValue = (String) params.get("configChangeValue"); 50 51 changeConfig(optionName, optionValue); 52 } 53 33 54 String service_name = (String) params.get(GSParams.SERVICE); 34 55 String cluster_name = (String) params.get(GSParams.CLUSTER); … … 66 87 Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 67 88 Element mr_query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext); 68 69 if (request_type.equals("s"))89 90 if (request_type.equals("s")) 70 91 { 71 92 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_STATUS); … … 91 112 // just send the reponse as is 92 113 addSiteMetadata(result_response, userContext); 114 addInterfaceOptions(result_response); 93 115 return result_response; 94 116 } … … 107 129 mr_info_message.appendChild(mr_info_request); 108 130 Element mr_info_response = (Element) this.mr.process(mr_info_message); 109 131 110 132 String path = GSXML.RESPONSE_ELEM; 111 133 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM); … … 118 140 119 141 addSiteMetadata(page_response, userContext); 120 142 addInterfaceOptions(page_response); 143 121 144 return result; 122 145 } 146 147 protected void changeConfig (String optionName, String optionValue) 148 { 149 if(this.config_params.get(optionName) != null) 150 { 151 this.config_params.put(optionName, optionValue); 152 153 File interfaceConfigFile = new File(GSFile.interfaceConfigFile(GSFile.interfaceHome(GlobalProperties.getGSDL3Home(), (String)this.config_params.get("interface_name")))); 154 155 Document interfaceXML = null; 156 try 157 { 158 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 159 DocumentBuilder db = dbf.newDocumentBuilder(); 160 interfaceXML = db.parse(interfaceConfigFile); 161 Element topElement = interfaceXML.getDocumentElement(); 162 Element optionListElem = (Element) GSXML.getChildByTagName(topElement, "optionList"); 123 163 164 NodeList optionList = optionListElem.getElementsByTagName("option"); 165 166 for(int i = 0; i < optionList.getLength(); i++) 167 { 168 Element currentOption = (Element)optionList.item(i); 169 if(currentOption.getAttribute(GSXML.NAME_ATT) != null && currentOption.getAttribute(GSXML.NAME_ATT).equals(optionName)) 170 { 171 currentOption.setAttribute(GSXML.VALUE_ATT, optionValue); 172 } 173 } 174 175 DOMSource source = new DOMSource(interfaceXML); 176 Result xmlresult = new StreamResult(interfaceConfigFile); 177 178 Transformer transformer = TransformerFactory.newInstance().newTransformer(); 179 transformer.transform(source, xmlresult); 180 } 181 catch(Exception ex) 182 { 183 ex.printStackTrace(); 184 } 185 } 186 else 187 { 188 logger.error("Could not set param \"" + optionName + "\" to \"" + optionValue + "\" because that option does not exist."); 189 } 190 } 124 191 }
Note:
See TracChangeset
for help on using the changeset viewer.