Ignore:
Timestamp:
2014-04-10T14:39:33+12:00 (10 years ago)
Author:
kjdon
Message:

Lots of changes. Mainly to do with removing this.doc from everywhere. Document is not thread safe. Now we tend to create a new Document everytime we are starting a new page/message etc. in service this.desc_doc is available as teh document to create service info stuff. But it should only be used for this and not for other messages. newDOM is now static for XMLConverter. method param changes for some GSXML methods.

File:
1 edited

Legend:

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

    r28958 r28966  
    1919import org.greenstone.gsdl3.util.UserQueryResult;
    2020import org.greenstone.gsdl3.util.UserTermInfo;
     21import org.greenstone.gsdl3.util.XMLConverter;
    2122import org.greenstone.util.GlobalProperties;
     23
     24import org.w3c.dom.Document;
    2225import org.w3c.dom.Element;
    2326import org.w3c.dom.NodeList;
     
    168171
    169172        // set up Authentication service info - for now just has name and type
    170         Element authentication_service = this.doc.createElement(GSXML.SERVICE_ELEM);
     173        Element authentication_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
    171174        authentication_service.setAttribute(GSXML.TYPE_ATT, "authen");
    172175        authentication_service.setAttribute(GSXML.NAME_ATT, AUTHENTICATION_SERVICE);
    173176        this.short_service_info.appendChild(authentication_service);
    174177
    175         Element getUserInformation_service = this.doc.createElement(GSXML.SERVICE_ELEM);
     178        Element getUserInformation_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
    176179        getUserInformation_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS);
    177180        getUserInformation_service.setAttribute(GSXML.NAME_ATT, GET_USER_INFORMATION_SERVICE);
    178181        this.short_service_info.appendChild(getUserInformation_service);
    179182
    180         Element changeEditMode_service = this.doc.createElement(GSXML.SERVICE_ELEM);
     183        Element changeEditMode_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
    181184        changeEditMode_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS);
    182185        changeEditMode_service.setAttribute(GSXML.NAME_ATT, CHANGE_USER_EDIT_MODE_SERVICE);
    183186        this.short_service_info.appendChild(changeEditMode_service);
    184187       
    185         Element remoteAuthentication_service = this.doc.createElement(GSXML.SERVICE_ELEM);
     188        Element remoteAuthentication_service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
    186189        remoteAuthentication_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_PROCESS);
    187190        remoteAuthentication_service.setAttribute(GSXML.NAME_ATT, REMOTE_AUTHENTICATION_SERVICE);
     
    214217    }
    215218
    216     protected Element getServiceDescription(String service_id, String lang, String subset)
    217     {
    218 
    219         Element authen_service = this.doc.createElement(GSXML.SERVICE_ELEM);
     219  protected Element getServiceDescription(Document doc, String service_id, String lang, String subset)
     220    {
     221
     222        Element authen_service = doc.createElement(GSXML.SERVICE_ELEM);
    220223
    221224        if (service_id.equals(AUTHENTICATION_SERVICE))
     
    246249        if (service_id.equals(AUTHENTICATION_SERVICE) && (subset == null || subset.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER)))
    247250        {
    248             authen_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_NAME, getServiceName(service_id, lang)));
    249             authen_service.appendChild(GSXML.createDisplayTextElement(this.doc, GSXML.DISPLAY_TEXT_DESCRIPTION, getServiceDescription(service_id, lang)));
     251            authen_service.appendChild(GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_NAME, getServiceName(service_id, lang)));
     252            authen_service.appendChild(GSXML.createDisplayTextElement(doc, GSXML.DISPLAY_TEXT_DESCRIPTION, getServiceDescription(service_id, lang)));
    250253        }
    251254        return authen_service;
     
    270273    {
    271274        // Create a new (empty) result message
    272         Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
     275      Document result_doc = XMLConverter.newDOM();
     276        Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
    273277
    274278        result.setAttribute(GSXML.FROM_ATT, CHANGE_USER_EDIT_MODE_SERVICE);
     
    278282        if (paramList == null)
    279283        {
    280             GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_REQUEST_HAS_NO_PARAM_LIST));
     284            GSXML.addError(result, _errorMessageMap.get(ERROR_REQUEST_HAS_NO_PARAM_LIST));
    281285            return result;
    282286        }
     
    362366            }
    363367        }
    364        
    365         Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
     368        Document result_doc = XMLConverter.newDOM();
     369        Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
    366370        result.setAttribute(GSXML.FROM_ATT, REMOTE_AUTHENTICATION_SERVICE);
    367371        result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);       
    368         Element s = GSXML.createTextElement(this.doc, GSXML.STATUS_ELEM, message);
     372        Element s = GSXML.createTextElement(result_doc, GSXML.STATUS_ELEM, message);
    369373        result.appendChild(s);
    370374        return result;
     
    374378    {
    375379        // Create a new (empty) result message
    376         Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
     380      Document result_doc = XMLConverter.newDOM();
     381        Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
    377382
    378383        result.setAttribute(GSXML.FROM_ATT, GET_USER_INFORMATION_SERVICE);
     
    382387        if (paramList == null)
    383388        {
    384             GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_REQUEST_HAS_NO_PARAM_LIST));
     389            GSXML.addError(result, _errorMessageMap.get(ERROR_REQUEST_HAS_NO_PARAM_LIST));
    385390            return result;
    386391        }
     
    392397        if (username == null)
    393398        {
    394             GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_USERNAME_NOT_SPECIFIED));
     399            GSXML.addError(result, _errorMessageMap.get(ERROR_USERNAME_NOT_SPECIFIED));
    395400            return result;
    396401        }
     
    405410        if (terms.size() == 0)
    406411        {
    407             GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_REQUESTED_USER_NOT_FOUND));
     412            GSXML.addError(result, _errorMessageMap.get(ERROR_REQUESTED_USER_NOT_FOUND));
    408413            return result;
    409414        }
    410415
    411416        UserTermInfo userInfo = terms.get(0);
    412         Element userInfoList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     417        Element userInfoList = result_doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
    413418        result.appendChild(userInfoList);
    414419
    415         Element usernameField = GSXML.createParameter(this.doc, "username", userInfo.username);
    416         Element passwordField = GSXML.createParameter(this.doc, "password", userInfo.password);
    417         Element groupsField = GSXML.createParameter(this.doc, "groups", userInfo.groups);
    418         Element accountStatusField = GSXML.createParameter(this.doc, "accountstatus", userInfo.accountstatus);
    419         Element commentField = GSXML.createParameter(this.doc, "comment", userInfo.comment);
     420        Element usernameField = GSXML.createParameter(result_doc, "username", userInfo.username);
     421        Element passwordField = GSXML.createParameter(result_doc, "password", userInfo.password);
     422        Element groupsField = GSXML.createParameter(result_doc, "groups", userInfo.groups);
     423        Element accountStatusField = GSXML.createParameter(result_doc, "accountstatus", userInfo.accountstatus);
     424        Element commentField = GSXML.createParameter(result_doc, "comment", userInfo.comment);
    420425
    421426        if (editEnabled != null)
    422427        {
    423             Element editEnabledElem = GSXML.createParameter(this.doc, "editEnabled", editEnabled);
     428            Element editEnabledElem = GSXML.createParameter(result_doc, "editEnabled", editEnabled);
    424429            userInfoList.appendChild(editEnabledElem);
    425430        }
     
    441446
    442447        // Create a new (empty) result message
    443         Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
     448        Document result_doc = XMLConverter.newDOM();
     449        Element result = result_doc.createElement(GSXML.RESPONSE_ELEM);
    444450        result.setAttribute(GSXML.FROM_ATT, AUTHENTICATION_SERVICE);
    445451        result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
    446452
    447453        // Create an Authentication node put into the result
    448         Element authenNode = this.doc.createElement(GSXML.AUTHEN_NODE_ELEM);
     454        Element authenNode = result_doc.createElement(GSXML.AUTHEN_NODE_ELEM);
    449455        result.appendChild(authenNode);
    450         result.appendChild(getCollectList(this.site_home + File.separatorChar + "collect"));
     456        result.appendChild(getCollectList(result_doc, this.site_home + File.separatorChar + "collect"));
    451457
    452458        // Create a service node added into the Authentication node
    453         Element serviceNode = this.doc.createElement(GSXML.SERVICE_ELEM);
     459        Element serviceNode = result_doc.createElement(GSXML.SERVICE_ELEM);
    454460        authenNode.appendChild(serviceNode);
    455461
     
    459465        {
    460466            serviceNode.setAttribute("operation", LOGIN);
    461             GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_REQUEST_HAS_NO_PARAM_LIST));
     467            GSXML.addError(result, _errorMessageMap.get(ERROR_REQUEST_HAS_NO_PARAM_LIST));
    462468            return result; // Return the empty result
    463469        }
     
    473479        {
    474480            serviceNode.setAttribute("operation", LOGIN);
    475             GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_NOT_LOGGED_IN));
     481            GSXML.addError(result, _errorMessageMap.get(ERROR_NOT_LOGGED_IN));
    476482            return result;
    477483        }
     
    486492        {
    487493            serviceNode.setAttribute("operation", LOGIN);
    488             GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_NOT_LOGGED_IN));
     494            GSXML.addError(result, _errorMessageMap.get(ERROR_NOT_LOGGED_IN));
    489495            return result;
    490496        }
     
    493499        {
    494500            serviceNode.setAttribute("operation", LOGIN);
    495             GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_ADMIN_NOT_LOGGED_IN));
     501            GSXML.addError(result, _errorMessageMap.get(ERROR_ADMIN_NOT_LOGGED_IN));
    496502            return result;
    497503        }
     
    502508            if (error != NO_ERROR)
    503509            {
    504                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     510                GSXML.addError(result, _errorMessageMap.get(error));
    505511            }
    506512        }
     
    518524            if ((error = checkUsername(newUsername)) != NO_ERROR)
    519525            {
    520                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     526                GSXML.addError(result, _errorMessageMap.get(error));
    521527                return result;
    522528            }
     
    525531            if ((error = checkPassword(newPassword)) != NO_ERROR)
    526532            {
    527                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     533                GSXML.addError(result, _errorMessageMap.get(error));
    528534                return result;
    529535            }
     
    535541            {
    536542                serviceNode.setAttribute("operation", ADD_USER);
    537                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     543                GSXML.addError(result, _errorMessageMap.get(error));
    538544            }
    539545            else
     
    553559            if ((error = checkUsername(newUsername)) != NO_ERROR)
    554560            {
    555                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     561                GSXML.addError(result, _errorMessageMap.get(error));
    556562                return result;
    557563            }
     
    560566            if ((error = checkPassword(newPassword)) != NO_ERROR)
    561567            {
    562                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     568                GSXML.addError(result, _errorMessageMap.get(error));
    563569                return result;
    564570            }
     
    584590                    {
    585591                        serviceNode.setAttribute("operation", REGISTER);
    586                         GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_CAPTCHA_MISSING));
     592                        GSXML.addError(result, _errorMessageMap.get(ERROR_CAPTCHA_MISSING));
    587593                        return result;
    588594                    }
     
    593599                    {
    594600                        serviceNode.setAttribute("operation", REGISTER);
    595                         GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_CAPTCHA_DOES_NOT_MATCH));
     601                        GSXML.addError(result, _errorMessageMap.get(ERROR_CAPTCHA_DOES_NOT_MATCH));
    596602                        return result;
    597603                    }
     
    606612            {
    607613                serviceNode.setAttribute("operation", REGISTER);
    608                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     614                GSXML.addError(result, _errorMessageMap.get(error));
    609615            }
    610616        }
     
    623629            if ((error = checkUsername(newUsername)) != NO_ERROR)
    624630            {
    625                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     631                GSXML.addError(result, _errorMessageMap.get(error));
    626632                return result;
    627633            }
     
    636642                if ((error = checkPassword(newPassword)) != NO_ERROR)
    637643                {
    638                     GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     644                    GSXML.addError(result, _errorMessageMap.get(error));
    639645                    return result;
    640646                }
     
    654660                {
    655661                    serviceNode.setAttribute("operation", EDIT_USER);
    656                     GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     662                    GSXML.addError(result, _errorMessageMap.get(error));
    657663                }
    658664                return result;
     
    663669            {
    664670                serviceNode.setAttribute("operation", EDIT_USER);
    665                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     671                GSXML.addError(result, _errorMessageMap.get(error));
    666672            }
    667673            else
     
    684690                addUserInformationToNode(previousUsername, serviceNode);
    685691                serviceNode.setAttribute("operation", ACCOUNT_SETTINGS);
    686                 GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_USER_ALREADY_EXISTS));
     692                GSXML.addError(result, _errorMessageMap.get(ERROR_USER_ALREADY_EXISTS));
    687693                return result;
    688694            }
     
    698704                    addUserInformationToNode(previousUsername, serviceNode);
    699705                    serviceNode.setAttribute("operation", ACCOUNT_SETTINGS);
    700                     GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_INCORRECT_PASSWORD), "Incorrect Password");
     706                    GSXML.addError(result, _errorMessageMap.get(ERROR_INCORRECT_PASSWORD), "Incorrect Password");
    701707                    return result;
    702708                }
     
    706712                if ((error = checkPassword(newPassword)) != NO_ERROR)
    707713                {
    708                     GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     714                    GSXML.addError(result, _errorMessageMap.get(error));
    709715                    return result;
    710716                }
     
    721727            if ((error = checkUsername(newUsername)) != NO_ERROR)
    722728            {
    723                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     729                GSXML.addError(result, _errorMessageMap.get(error));
    724730                return result;
    725731            }
     
    741747                    addUserInformationToNode(previousUsername, serviceNode);
    742748                    serviceNode.setAttribute("operation", ACCOUNT_SETTINGS);
    743                     GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     749                    GSXML.addError(result, _errorMessageMap.get(error));
    744750                }
    745751                return result;
     
    749755            if (error != NO_ERROR)
    750756            {
    751                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     757                GSXML.addError(result, _errorMessageMap.get(error));
    752758            }
    753759
     
    767773            if (user_name == null || oldPassword == null || newPassword == null)
    768774            {
    769                 GSXML.addError(this.doc, result, _errorMessageMap.get("missing compulsory parameters: username, oldPassword, or newPassword"));
     775                GSXML.addError(result, _errorMessageMap.get("missing compulsory parameters: username, oldPassword, or newPassword"));
    770776                return result;
    771777            }
     
    775781            {
    776782                addUserInformationToNode(user_name, serviceNode);
    777                 GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_INCORRECT_PASSWORD), "Incorrect Password");
     783                GSXML.addError(result, _errorMessageMap.get(ERROR_INCORRECT_PASSWORD), "Incorrect Password");
    778784                return result;
    779785            }
     
    783789            if ((error = checkPassword(newPassword)) != NO_ERROR)
    784790            {
    785                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     791                GSXML.addError(result, _errorMessageMap.get(error));
    786792                return result;
    787793            }
     
    794800            if (info != "succeed")
    795801            {//see DerbyWrapper.modifyUserInfo
    796                 GSXML.addError(this.doc, result, _errorMessageMap.get(info));
     802                GSXML.addError(result, _errorMessageMap.get(info));
    797803                return result;
    798804            }
     
    804810            if (error != NO_ERROR)
    805811            {
    806                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     812                GSXML.addError(result, _errorMessageMap.get(error));
    807813            }
    808814        }
     
    814820            {
    815821                serviceNode.setAttribute("operation", "");
    816                 GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_USERNAME_NOT_SPECIFIED));
     822                GSXML.addError(result, _errorMessageMap.get(ERROR_USERNAME_NOT_SPECIFIED));
    817823                return result;
    818824            }
     
    821827            {
    822828                serviceNode.setAttribute("operation", LOGIN);
    823                 GSXML.addError(this.doc, result, _errorMessageMap.get(ERROR_NOT_AUTHORISED));
     829                GSXML.addError(result, _errorMessageMap.get(ERROR_NOT_AUTHORISED));
    824830                return result;
    825831            }
     
    827833            if (error != NO_ERROR)
    828834            {
    829                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     835                GSXML.addError(result, _errorMessageMap.get(error));
    830836            }
    831837        }
     
    861867            if (_recaptchaPublicKey != null && _recaptchaPrivateKey != null)
    862868            {
    863                 Element recaptchaElem = this.doc.createElement("recaptcha");
     869                Element recaptchaElem = result_doc.createElement("recaptcha");
    864870                recaptchaElem.setAttribute("publicKey", _recaptchaPublicKey);
    865871                recaptchaElem.setAttribute("privateKey", _recaptchaPrivateKey);
     
    873879            if (error != NO_ERROR)
    874880            {
    875                 GSXML.addError(this.doc, result, _errorMessageMap.get(error));
     881                GSXML.addError(result, _errorMessageMap.get(error));
    876882            }
    877883            addUserInformationToNode(null, serviceNode);
     
    985991        if (userQueryResult != null)
    986992        {
    987             Element user_node = getUserNode(userQueryResult);
     993          Element user_node = getUserNodeList(serviceNode.getOwnerDocument(), userQueryResult);
    988994            serviceNode.appendChild(user_node);
    989995            return NO_ERROR;
     
    11141120    }
    11151121
    1116     private Element getUserNode(UserQueryResult userQueryResult)
    1117     {
    1118         Element user_list_node = this.doc.createElement(GSXML.USER_NODE_ELEM + "List");
     1122  private Element getUserNodeList(Document doc, UserQueryResult userQueryResult)
     1123    {
     1124        Element user_list_node = doc.createElement(GSXML.USER_NODE_ELEM + GSXML.LIST_MODIFIER);
    11191125
    11201126        Vector userInfo = userQueryResult.users;
     
    11221128        for (int i = 0; i < userQueryResult.getSize(); i++)
    11231129        {
    1124             Element user_node = this.doc.createElement(GSXML.USER_NODE_ELEM);
     1130            Element user_node = doc.createElement(GSXML.USER_NODE_ELEM);
    11251131            String username = ((UserTermInfo) userInfo.get(i)).username;
    11261132            String groups = ((UserTermInfo) userInfo.get(i)).groups;
     
    11391145    }
    11401146
    1141     private Element getCollectList(String collect)
    1142     {
    1143         Element collect_list_node = this.doc.createElement(GSXML.COLLECTION_ELEM + "List");
     1147  private Element getCollectList(Document doc, String collect)
     1148    {
     1149        Element collect_list_node = doc.createElement(GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER);
    11441150        File[] collect_dir = (new File(collect)).listFiles();
    11451151        if (collect_dir != null && collect_dir.length > 0)
     
    11491155                if (collect_dir[i].isDirectory() && (!collect_dir[i].getName().startsWith(".svn")))
    11501156                {
    1151                     Element collect_node = this.doc.createElement(GSXML.COLLECTION_ELEM);
    1152                     collect_node.setAttribute("name", collect_dir[i].getName());
     1157                    Element collect_node = doc.createElement(GSXML.COLLECTION_ELEM);
     1158                    collect_node.setAttribute(GSXML.NAME_ATT, collect_dir[i].getName());
    11531159                    collect_list_node.appendChild(collect_node);
    11541160                }
Note: See TracChangeset for help on using the changeset viewer.