Changeset 28972

Show
Ignore:
Timestamp:
14.04.2014 14:38:36 (5 years ago)
Author:
kjdon
Message:

removing this.converter and this.doc - just create a new document when we need one, and all XMLConverter methods are now static so don't need this.converter

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
2 modified

Legend:

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

    r27617 r28972  
    3838 * A program to take cgi args from the command line and return html 
    3939 *  
    40  * @author Katherine Don 
    41  * @version $Revision$ 
    4240 */ 
    4341 
    4442final public class LibraryCommandline 
    4543{ 
    46  
    47     protected XMLConverter converter = null; 
    48     protected Document doc = null; 
    49  
    5044    protected HashMap<String, String> saved_args = null; 
    5145    protected GSParams params = null; 
     
    5448    public LibraryCommandline() 
    5549    { 
    56         this.converter = new XMLConverter(); 
    57         this.doc = converter.newDOM(); 
    5850        this.saved_args = new HashMap<String, String>(); 
    5951        this.params = new GSParams(); 
     
    143135        Element xml_message = generateRequest(query); 
    144136        System.out.println("*********************"); 
    145         System.out.println(converter.getPrettyString(xml_message)); 
     137        System.out.println(XMLConverter.getPrettyString(xml_message)); 
    146138        Node xml_result = recept.process(xml_message); 
    147         return this.converter.getPrettyString(xml_result); 
     139        return XMLConverter.getPrettyString(xml_result); 
    148140    } 
    149141 
     
    151143    { 
    152144 
    153         Element xml_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    154         Element xml_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", new UserContext()); 
     145      Document msg_doc = XMLConverter.newDOM(); 
     146        Element xml_message = msg_doc.createElement(GSXML.MESSAGE_ELEM); 
     147        Element xml_request = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_PAGE, "", new UserContext()); 
    155148        xml_message.appendChild(xml_request); 
    156         Element xml_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     149        Element xml_param_list = msg_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
    157150        xml_request.appendChild(xml_param_list); 
    158151 
     
    200193            { 
    201194                // make a param now 
    202                 Element param = doc.createElement(GSXML.PARAM_ELEM); 
     195                Element param = msg_doc.createElement(GSXML.PARAM_ELEM); 
    203196                param.setAttribute(GSXML.NAME_ATT, name); 
    204197                param.setAttribute(GSXML.VALUE_ATT, GSXML.xmlSafe(value)); 
     
    220213            if (name.equals(GSParams.LANGUAGE)) 
    221214                continue; 
    222             Element param = this.doc.createElement(GSXML.PARAM_ELEM); 
     215            Element param = msg_doc.createElement(GSXML.PARAM_ELEM); 
    223216            param.setAttribute(GSXML.NAME_ATT, name); 
    224217            param.setAttribute(GSXML.VALUE_ATT, GSXML.xmlSafe(saved_args.get(name))); 
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java

    r28966 r28972  
    8686    protected final String DEFAULT_LANG = "en"; 
    8787 
    88     /** container Document to create XML Nodes */ 
    89     protected Document doc = null; 
    90  
    91     /** a converter class to parse XML and create Docs */ 
    92     protected XMLConverter converter = null; 
    93  
    9488    /** 
    9589     * the cgi stuff - the Receptionist can add new args to this 
     
    186180            config_params.put(GSConstants.SITE_NAME, site_name); 
    187181        } 
    188         this.converter = new XMLConverter(); 
    189         this.doc = XMLConverter.newDOM(); 
     182        //this.converter = new XMLConverter(); 
     183        //this.doc = XMLConverter.newDOM(); 
    190184 
    191185        // the receptionist -the servlet will talk to this 
     
    243237            Communicator communicator = null; 
    244238            // we need to create the XML to configure the communicator 
    245             Element site_elem = this.doc.createElement(GSXML.SITE_ELEM); 
     239            Document doc = XMLConverter.newDOM(); 
     240            Element site_elem = doc.createElement(GSXML.SITE_ELEM); 
    246241            site_elem.setAttribute(GSXML.TYPE_ATT, remote_site_type); 
    247242            site_elem.setAttribute(GSXML.NAME_ATT, remote_site_name); 
     
    292287        //Allow the message router and the document to be accessed from anywhere in this servlet context 
    293288        this.getServletContext().setAttribute("GSRouter", this.recept.getMessageRouter()); 
    294         this.getServletContext().setAttribute("GSDocument", this.doc); 
     289        //this.getServletContext().setAttribute("GSDocument", this.doc); 
    295290    } 
    296291 
     
    464459 
    465460            //Get the groups for the user 
    466             Element acquireGroupMessage = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    467             Element acquireGroupRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, "GetUserInformation", userContext); 
     461            Document msg_doc = XMLConverter.newDOM(); 
     462            Element acquireGroupMessage = msg_doc.createElement(GSXML.MESSAGE_ELEM); 
     463            Element acquireGroupRequest = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_PROCESS, "GetUserInformation", userContext); 
    468464            acquireGroupMessage.appendChild(acquireGroupRequest); 
    469465 
    470             Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     466            Element paramList = msg_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
    471467            acquireGroupRequest.appendChild(paramList); 
    472             paramList.appendChild(GSXML.createParameter(this.doc, GSXML.USERNAME_ATT, request.getUserPrincipal().getName())); 
     468            paramList.appendChild(GSXML.createParameter(msg_doc, GSXML.USERNAME_ATT, request.getUserPrincipal().getName())); 
    473469 
    474470            Element aquireGroupsResponseMessage = (Element) this.recept.process(acquireGroupMessage); 
     
    520516 
    521517        // the request to the receptionist 
    522         Element xml_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    523         Element xml_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", userContext); 
     518        Document msg_doc = XMLConverter.newDOM(); 
     519        Element xml_message = msg_doc.createElement(GSXML.MESSAGE_ELEM); 
     520        Element xml_request = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_PAGE, "", userContext); 
    524521        xml_request.setAttribute(GSXML.OUTPUT_ATT, output); 
    525522 
     
    655652            //  create the param list for the greenstone request - includes 
    656653            // the params from the current request and any others from the saved session 
    657             Element xml_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     654            Element xml_param_list = msg_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
    658655            xml_request.appendChild(xml_param_list); 
    659656 
     
    680677                    else 
    681678                    { 
    682                         Element param = this.doc.createElement(GSXML.PARAM_ELEM); 
     679                        Element param = msg_doc.createElement(GSXML.PARAM_ELEM); 
    683680                        param.setAttribute(GSXML.NAME_ATT, name); 
    684681                        param.setAttribute(GSXML.VALUE_ATT, GSXML.xmlSafe(value)); 
     
    709706 
    710707                    // lang and uid are stored but we dont want it in the param list cos its already in the request 
    711                     Element param = this.doc.createElement(GSXML.PARAM_ELEM); 
     708                    Element param = msg_doc.createElement(GSXML.PARAM_ELEM); 
    712709                    param.setAttribute(GSXML.NAME_ATT, name); 
    713710                    String value = GSXML.xmlSafe((String) session.getAttribute(name)); 
     
    784781        encodeURLs(xml_result, response); 
    785782 
    786         String xml_string = this.converter.getPrettyString(xml_result); 
     783        String xml_string = XMLConverter.getPrettyString(xml_result); 
    787784 
    788785        if (output.equals("json")) 
     
    851848                { 
    852849                    //The user entered in either the wrong username or the wrong password 
    853                     Element loginPageMessage = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    854                     Element loginPageRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", userContext); 
     850                  Document loginPageDoc = XMLConverter.newDOM(); 
     851                    Element loginPageMessage = loginPageDoc.createElement(GSXML.MESSAGE_ELEM); 
     852                    Element loginPageRequest = GSXML.createBasicRequest(loginPageDoc, GSXML.REQUEST_TYPE_PAGE, "", userContext); 
    855853                    loginPageRequest.setAttribute(GSXML.ACTION_ATT, "p"); 
    856854                    loginPageRequest.setAttribute(GSXML.SUBACTION_ATT, "login"); 
     
    859857                    loginPageMessage.appendChild(loginPageRequest); 
    860858 
    861                     Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     859                    Element paramList = loginPageDoc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
    862860                    loginPageRequest.appendChild(paramList); 
    863861 
    864                     Element messageParam = this.doc.createElement(GSXML.PARAM_ELEM); 
     862                    Element messageParam = loginPageDoc.createElement(GSXML.PARAM_ELEM); 
    865863                    messageParam.setAttribute(GSXML.NAME_ATT, "loginMessage"); 
    866864                    messageParam.setAttribute(GSXML.VALUE_ATT, "Either your username or password was incorrect, please try again."); 
    867865                    paramList.appendChild(messageParam); 
    868866 
    869                     Element urlParam = this.doc.createElement(GSXML.PARAM_ELEM); 
     867                    Element urlParam = loginPageDoc.createElement(GSXML.PARAM_ELEM); 
    870868                    urlParam.setAttribute(GSXML.NAME_ATT, "redirectURL"); 
    871869                    String queryString = ""; 
     
    878876 
    879877                    Node loginPageResponse = this.recept.process(loginPageMessage); 
    880                     out.println(this.converter.getPrettyString(loginPageResponse)); 
     878                    out.println(XMLConverter.getPrettyString(loginPageResponse)); 
    881879 
    882880                    return false; 
     
    888886        if (request.getAuthType() != null) 
    889887        { 
    890             Element userInformation = this.doc.createElement(GSXML.USER_INFORMATION_ELEM); 
     888          Element userInformation = xml_request.getOwnerDocument().createElement(GSXML.USER_INFORMATION_ELEM); 
    891889            userInformation.setAttribute(GSXML.USERNAME_ATT, request.getUserPrincipal().getName()); 
    892890 
    893             Element userInfoMessage = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    894             Element userInfoRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SECURITY, "GetUserInformation", userContext); 
     891            Document msg_doc = XMLConverter.newDOM(); 
     892            Element userInfoMessage = msg_doc.createElement(GSXML.MESSAGE_ELEM); 
     893            Element userInfoRequest = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_SECURITY, "GetUserInformation", userContext); 
    895894            userInfoMessage.appendChild(userInfoRequest); 
    896895 
    897             Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     896            Element paramList = msg_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
    898897            userInfoRequest.appendChild(paramList); 
    899898 
    900             Element param = this.doc.createElement(GSXML.PARAM_ELEM); 
     899            Element param = msg_doc.createElement(GSXML.PARAM_ELEM); 
    901900            param.setAttribute(GSXML.NAME_ATT, GSXML.USERNAME_ATT); 
    902901            param.setAttribute(GSXML.VALUE_ATT, request.getUserPrincipal().getName()); 
     
    925924        { 
    926925            //Get the security info for this collection 
    927             Element securityMessage = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    928             Element securityRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_SECURITY, collection, userContext); 
     926          Document msg_doc = XMLConverter.newDOM(); 
     927            Element securityMessage = msg_doc.createElement(GSXML.MESSAGE_ELEM); 
     928            Element securityRequest = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_SECURITY, collection, userContext); 
    929929            securityMessage.appendChild(securityRequest); 
    930930            if (document != null && !document.equals("")) 
     
    957957                if (!found) 
    958958                { 
    959                     Element loginPageMessage = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    960                     Element loginPageRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PAGE, "", userContext); 
     959                  Document loginPageDoc = XMLConverter.newDOM(); 
     960                    Element loginPageMessage = loginPageDoc.createElement(GSXML.MESSAGE_ELEM); 
     961                    Element loginPageRequest = GSXML.createBasicRequest(loginPageDoc, GSXML.REQUEST_TYPE_PAGE, "", userContext); 
    961962                    loginPageRequest.setAttribute(GSXML.ACTION_ATT, "p"); 
    962963                    loginPageRequest.setAttribute(GSXML.SUBACTION_ATT, "login"); 
     
    965966                    loginPageMessage.appendChild(loginPageRequest); 
    966967 
    967                     Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     968                    Element paramList = loginPageDoc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
    968969                    loginPageRequest.appendChild(paramList); 
    969970 
    970                     Element messageParam = this.doc.createElement(GSXML.PARAM_ELEM); 
     971                    Element messageParam = loginPageDoc.createElement(GSXML.PARAM_ELEM); 
    971972                    messageParam.setAttribute(GSXML.NAME_ATT, "loginMessage"); 
    972973                    if (request.getAuthType() == null) 
     
    980981                    paramList.appendChild(messageParam); 
    981982 
    982                     Element urlParam = this.doc.createElement(GSXML.PARAM_ELEM); 
     983                    Element urlParam = loginPageDoc.createElement(GSXML.PARAM_ELEM); 
    983984                    urlParam.setAttribute(GSXML.NAME_ATT, "redirectURL"); 
    984985                    if (request.getQueryString() != null && request.getQueryString().length() > 0) 
     
    993994 
    994995                    Node loginPageResponse = this.recept.process(loginPageMessage); 
    995                     out.println(this.converter.getPrettyString(loginPageResponse)); 
     996                    out.println(XMLConverter.getPrettyString(loginPageResponse)); 
    996997 
    997998                    return false;