Changeset 32446 for main

Show
Ignore:
Timestamp:
13.09.2018 13:55:17 (9 months ago)
Author:
kjdon
Message:

overhaul of params class. default is now to not save - add params to teh object if they are needed to be saved. separate map for service params so we don't need to store s1.xxx as well as xxx. there are only a few global params listed in the class now. actions will add their own ones, and services also will add their own ones.

Files:
1 modified

Legend:

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

    r32361 r32446  
    2121import java.util.HashMap; 
    2222 
     23import org.apache.log4j.Logger; 
     24 
    2325/** keeps track of the servlet parameters, and their defaults */ 
    2426public class GSParams 
    2527{ 
    2628 
     29  static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.GSParams.class.getName()); 
    2730    // cgi parameter names 
    2831    public static final String ACTION = "a"; // the major type of action- eg query or browse or process 
     
    4346    public static final String DOCUMENT = "d"; 
    4447    public static final String DOCUMENT_TYPE = "dt"; 
    45     public static final String START_PAGE = "startPage"; 
    46     public static final String S_START_PAGE = "s1.startPage"; 
    4748    public static final String HREF = "href"; // url. might be an external url, or a relative one that needs translating 
    4849    public static final String RELATIVE_LINK = "rl"; // whether the href url is relative to the collection or not. 
     
    5152 
    5253    public static final String HTTP_HEADER_FIELDS = "hhf"; 
    53     public static final String QUICK_SEARCH = "qs"; 
    5454 
    5555    // internal configure args 
     
    6464 
    6565    public static final String INLINE_TEMPLATE = "ilt"; 
    66     public static final String DISPLAY_METADATA = "dmd"; 
    6766    public static final String FILE_LOCATION = "fl"; 
    68     public static final String DOC_EDIT = "docEdit"; 
    69     public static final String AJAX_LOAD_BYPASS = "alb"; 
    70  
    71   // document display args 
    72   public static final String EXPAND_DOCUMENT = "ed"; 
    73   public static final String EXPAND_CONTENTS = "ec"; 
    74   public static final String NO_TEXT = "noText"; 
    7567   
    7668    //Administration 
    77     public static final String PASSWORD = "password"; 
    78     public static final String S_PASSWORD = "s1.password"; 
    79     public static final String S_NEW_PASSWORD = "s1.newPassword"; 
    80     public static final String S_OLD_PASSWORD = "s1.oldPassword"; 
    81   public static final String S_NEW_EMAIL="s1.newEmail"; 
    82     public static final String S_NEW_USERNAME = "s1.newUsername"; 
    83     public static final String S_PREV_USERNAME = "s1.prevUsername"; 
    84  
    85   // Authentication 
    86   public static final String S_RECAPTCHA_RESPONSE = "s1.g-recaptcha-response"; 
    87   public static final String S_USERNAME = "s1.username"; 
    88   public static final String S_EMAIL = "s1.email"; 
    89     //Facets 
    90     public static final String S_FACETS = "s1.facets"; 
    91     public static final String S_FACETS_QUERIES = "s1.facetQueries"; 
     69        public static final String PASSWORD = "password"; 
     70        public static final String USERNAME = "username"; 
     71        public static final String LOGOUT = "logout"; 
    9272 
    9373    // some standard arg values 
     
    10282    public static final String DEBUG = "debug"; 
    10383 
    104     protected HashMap<String, Param> param_map = null; 
     84  public static final String SERVICE_PREFIX = "s1"; 
     85  public static final String PREVIOUS_PREFIX = "p"; 
     86  public static final String MD_PREFIX = "md___"; 
     87 
     88  public static final String SERVICE_PARAM_REGEX = "^s\\d\\..*"; 
     89   
     90  protected HashMap<String, Param> param_map = null; 
     91  protected HashMap<String, Param> service_param_map = null; 
    10592 
    10693    public GSParams() 
    10794    { 
    10895        this.param_map = new HashMap<String, Param>(30); 
    109  
    110         // add in all the standard params 
    111         addParameter(ACTION, false); 
    112         addParameter(SUBACTION, false); 
    113         addParameter(REQUEST_TYPE, false); 
    114         addParameter(RESPONSE_ONLY, false); 
    115         addParameter(CLUSTER, false); // we don't want to save cluster/collection  
     96        this.service_param_map =  new HashMap<String, Param>(30); 
     97 
     98        // we now only need to add in the ones that need saving, as we will default to "not save" 
    11699        addParameter(LANGUAGE, true); 
    117100        addParameter(DOCUMENT, true); 
    118         addParameter(DOCUMENT_TYPE, false); 
    119         addParameter(QUICK_SEARCH, false); 
    120         addParameter(START_PAGE, false); 
    121         addParameter(S_START_PAGE, false); 
    122         // should the following two just be in doc action?? 
    123         addParameter(HREF, false); 
    124         addParameter(RELATIVE_LINK, false); 
    125         addParameter(OUTPUT, false); 
    126         addParameter(SERVICE, false); 
    127101        addParameter(PROCESS_ID, true); 
    128         addParameter(SYSTEM_SUBSET, false); 
    129         addParameter(SYSTEM_CLUSTER, false); 
    130         addParameter(SYSTEM_MODULE_NAME, false); 
    131         addParameter(SYSTEM_MODULE_TYPE, false); 
    132         addParameter(INLINE_TEMPLATE, false); 
    133         addParameter(DISPLAY_METADATA, false); 
    134         addParameter(AJAX_LOAD_BYPASS, false); 
    135         addParameter(EXPAND_DOCUMENT, false); 
    136         addParameter(EXPAND_CONTENTS, false); 
    137         addParameter(NO_TEXT, false); 
    138         addParameter(DOC_EDIT, false); 
     102        addParameter(COLLECTION_TYPE, true); 
     103        addParameter(DEBUG, true); 
     104 
     105        // password is sensitive. don't save, but also don't return it in the page response 
    139106        addParameter(PASSWORD, false, true); 
    140         addParameter(S_PASSWORD, false, true); 
    141         addParameter(S_NEW_PASSWORD, false, true); 
    142         addParameter(S_OLD_PASSWORD, false, true); 
    143         addParameter(S_RECAPTCHA_RESPONSE, false, true); 
    144         addParameter(S_USERNAME, false); 
    145         addParameter(S_EMAIL, false); 
    146         addParameter(S_NEW_USERNAME, false); 
    147         addParameter(S_PREV_USERNAME, false); 
    148         addParameter(S_NEW_EMAIL, false); 
    149         addParameter(S_FACETS, false); 
    150         addParameter(S_FACETS_QUERIES, false); 
    151  
    152         addParameter(COLLECTION_TYPE, true); 
    153         addParameter(EXTERNAL_LINK_TYPE, false); 
    154         // filtering args must be specified each time 
    155         addParameter(EXCERPT_ID, false); 
    156         addParameter(EXCERPT_TAG, false); 
    157107         
    158         addParameter(DEBUG, true); 
    159108    } 
    160109 
     
    185134    } 
    186135 
     136  public boolean addServiceParameter(String name, String default_value, boolean save, boolean sensitive) { 
     137    if (this.service_param_map.containsKey(name)) { 
     138      // already there, could not add 
     139      return false; 
     140    } 
     141    this.service_param_map.put(name, new Param(default_value, save, sensitive)); 
     142    return true; 
     143  } 
     144     
     145    
    187146    public boolean setParamDefault(String name, String default_value) 
    188147    { 
     
    197156    { 
    198157        // p. is used to store previous settings 
    199         if (name.startsWith("p.") || name.startsWith("md___")) 
    200             return false; 
    201         Param p = this.param_map.get(name); 
    202         if (p == null) 
    203             return true; // if things are not in here, always save. 
     158        if (name.startsWith(PREVIOUS_PREFIX+".") || name.startsWith(MD_PREFIX)) 
     159            return false; 
     160        Param p; 
     161        if (name.matches(SERVICE_PARAM_REGEX)) { 
     162          // its a service param 
     163          p = this.service_param_map.get(name.substring(3)); 
     164        } else { 
     165          // an ordinary param 
     166          p = this.param_map.get(name); 
     167        } 
     168        if (p==null) { 
     169          return false; // never save unknown params 
     170        } 
    204171        return p.save; 
    205172    } 
     173         
    206174 
    207175  public boolean isSensitive(String name) { 
    208     Param p = this.param_map.get(name); 
     176    Param p; 
     177    if (name.matches(SERVICE_PARAM_REGEX)) { 
     178      p = this.service_param_map.get(name.substring(3)); 
     179    } else { 
     180      p = this.param_map.get(name); 
     181    } 
    209182    if (p==null) { 
    210183      return false;