Ignore:
Timestamp:
2012-02-21T16:26:17+13:00 (12 years ago)
Author:
sjm84
Message:

Second round of changes adding in the login ability, also interface options are now returned whenever site metadata is returned

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/GeneralAction.java

    r24993 r25128  
    22
    33import org.greenstone.gsdl3.util.*;
     4import org.greenstone.util.GlobalProperties;
    45// XML classes
     6import org.w3c.dom.Document;
    57import org.w3c.dom.Node;
    68import org.w3c.dom.Element;
     9import org.w3c.dom.NodeList;
    710
     11import java.io.File;
    812import java.util.HashMap;
     13
     14import javax.xml.parsers.DocumentBuilder;
     15import javax.xml.parsers.DocumentBuilderFactory;
     16import javax.xml.transform.Result;
     17import javax.xml.transform.Transformer;
     18import javax.xml.transform.TransformerFactory;
     19import javax.xml.transform.dom.DOMSource;
     20import javax.xml.transform.stream.StreamResult;
    921
    1022public class GeneralAction extends Action
     
    3143        Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    3244        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
    3354        String service_name = (String) params.get(GSParams.SERVICE);
    3455        String cluster_name = (String) params.get(GSParams.CLUSTER);
     
    6687            Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    6788            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"))
    7091            {
    7192                mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_STATUS);
     
    91112                // just send the reponse as is
    92113                addSiteMetadata(result_response, userContext);
     114                addInterfaceOptions(result_response);
    93115                return result_response;
    94116            }
     
    107129        mr_info_message.appendChild(mr_info_request);
    108130        Element mr_info_response = (Element) this.mr.process(mr_info_message);
    109        
     131
    110132        String path = GSXML.RESPONSE_ELEM;
    111133        path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
     
    118140
    119141        addSiteMetadata(page_response, userContext);
    120        
     142        addInterfaceOptions(page_response);
     143
    121144        return result;
    122145    }
     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");
    123163
     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    }
    124191}
Note: See TracChangeset for help on using the changeset viewer.