Changeset 33672

Show
Ignore:
Timestamp:
14.11.2019 14:14:28 (3 weeks ago)
Author:
kjdon
Message:

modified slightly so that the error messages come from the dictionary (ServiceRack?.properties) instead of hard wired in the code

Files:
1 modified

Legend:

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

    r33112 r33672  
    6363 * perl scripts 
    6464 *  
    65  * @author Katherine Don 
    6665 */ 
    6766public class GS2Construct extends ServiceRack 
     
    7170 
    7271    // default error message 
    73     private static final String NO_PERMISSIONS_ERROR = "This user does not have the required permissions to perform this action."; 
    74  
     72    private static final String NO_PERMISSIONS_ERROR = "auth.error.no_permissions"; 
     73  private static final String NO_METADATA_PERMISSIONS_ERROR = "auth.error.no_metadata_permissions"; 
     74   
    7575    // services offered 
    7676    private static final String NEW_SERVICE = "NewCollection"; 
     
    166166    protected Element processNewCollection(Element request) 
    167167    { 
     168       
    168169        if (!userHasCollectionEditPermissions(request)) { 
    169         return errorResponse("processNewCollection", NO_PERMISSIONS_ERROR); 
     170          String lang = request.getAttribute(GSXML.LANG_ATT); 
     171          return errorResponse("processNewCollection", NO_PERMISSIONS_ERROR, lang); 
    170172        } 
    171173        return runCommand(request, GS2PerlConstructor.NEW); 
     
    176178    { 
    177179        if (!userHasCollectionEditPermissions(request)) { 
    178         return errorResponse("processAddDocument", NO_PERMISSIONS_ERROR); 
     180          String lang = request.getAttribute(GSXML.LANG_ATT); 
     181        return errorResponse("processAddDocument", NO_PERMISSIONS_ERROR, lang); 
    179182        } 
    180183 
     
    198201        // check permissions 
    199202        if (!userHasCollectionEditPermissions(request)) { 
    200         return errorResponse("processBuildAndActivateCollection", NO_PERMISSIONS_ERROR); 
     203          String lang = request.getAttribute(GSXML.LANG_ATT); 
     204          return errorResponse("processBuildAndActivateCollection", NO_PERMISSIONS_ERROR, lang); 
    201205        } 
    202206 
     
    237241    { 
    238242        if (!userHasCollectionEditPermissions(request)) { 
    239         return errorResponse("processImportCollection", NO_PERMISSIONS_ERROR); 
     243          String lang = request.getAttribute(GSXML.LANG_ATT); 
     244          return errorResponse("processImportCollection", NO_PERMISSIONS_ERROR, lang); 
    240245        } 
    241246 
     
    304309    { 
    305310        if (!userHasCollectionEditPermissions(request)) { 
    306         return errorResponse("processBuildCollection", NO_PERMISSIONS_ERROR); 
     311          String lang = request.getAttribute(GSXML.LANG_ATT); 
     312          return errorResponse("processBuildCollection", NO_PERMISSIONS_ERROR, lang); 
    307313        } 
    308314 
     
    341347 
    342348        UserContext context = new UserContext(request); 
     349        String lang = request.getAttribute(GSXML.LANG_ATT); 
    343350        if (context.getUsername().equals("")) { 
    344351             
    345             return errorResponse("processModifyMetadata", "Cannot modify any metadata when not logged in."); 
     352            return errorResponse("processModifyMetadata", NO_METADATA_PERMISSIONS_ERROR, lang); 
    346353        } else { // User is logged in at least, see whether they can do any restricted set-meta ops 
    347354            // that are open to regular users (those without permissions to edit this collection). 
     
    366373            if(!isAddingUserComments) { // logged in user is attempting to set meta outside restricted set, 
    367374                 // In this case, they're attempting to set meta not related to user comments 
    368             return errorResponse("processModifyMetadata", NO_PERMISSIONS_ERROR); 
     375              return errorResponse("processModifyMetadata", NO_PERMISSIONS_ERROR, lang); 
    369376            } 
    370377        } 
     
    433440    { 
    434441 
     442      String lang = request.getAttribute(GSXML.LANG_ATT); 
    435443        if (!userHasCollectionEditPermissions(request)) { 
    436         return errorResponse("processActivateCollection", NO_PERMISSIONS_ERROR); 
     444          return errorResponse("processActivateCollection", NO_PERMISSIONS_ERROR, lang); 
    437445        } 
    438446 
     
    442450        HashMap<String, Serializable> params = GSXML.extractParams(param_list, false); 
    443451        String coll_name = (String) params.get(COL_PARAM); 
    444         String lang = request.getAttribute(GSXML.LANG_ATT); 
     452         
    445453 
    446454        UserContext userContext = new UserContext(request); 
     
    508516    protected Element processDeleteCollection(Element request) 
    509517    { 
     518       
    510519        if (!userHasCollectionEditPermissions(request)) { 
    511         return errorResponse("processDeleteCollection", NO_PERMISSIONS_ERROR); 
     520          String lang = request.getAttribute(GSXML.LANG_ATT); 
     521        return errorResponse("processDeleteCollection", NO_PERMISSIONS_ERROR, lang); 
    512522        } 
    513523 
     
    570580    { 
    571581        if (!userHasCollectionEditPermissions(request)) { 
    572         return errorResponse("processReloadCollection", NO_PERMISSIONS_ERROR); 
     582          String lang = request.getAttribute(GSXML.LANG_ATT); 
     583          return errorResponse("processReloadCollection", NO_PERMISSIONS_ERROR, lang); 
    573584        } 
    574585 
     
    11621173    } 
    11631174 
    1164     protected Element errorResponse(String serviceName, String errorMsg) { 
     1175    protected Element errorResponse(String serviceName, String errorKey, String lang) { 
     1176      String error_message = getTextString(errorKey, lang, "ServiceRack"); 
    11651177    Document result_doc = XMLConverter.newDOM(); 
    11661178    Element result = GSXML.createBasicResponse(result_doc, serviceName); 
    1167     GSXML.addError(result, errorMsg); 
     1179    GSXML.addError(result, error_message); 
    11681180    return result; 
    11691181    }