[16869] | 1 | /*
|
---|
| 2 | * GSParams.java
|
---|
| 3 | * Copyright (C) 2008 New Zealand Digital Library, http://www.nzdl.org
|
---|
| 4 | *
|
---|
| 5 | * This program is free software; you can redistribute it and/or modify
|
---|
| 6 | * it under the terms of the GNU General Public License as published by
|
---|
| 7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 8 | * (at your option) any later version.
|
---|
| 9 | *
|
---|
| 10 | * This program is distributed in the hope that it will be useful,
|
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | * GNU General Public License for more details.
|
---|
| 14 | *
|
---|
| 15 | * You should have received a copy of the GNU General Public License
|
---|
| 16 | * along with this program; if not, write to the Free Software
|
---|
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 18 | */
|
---|
[4991] | 19 | package org.greenstone.gsdl3.util;
|
---|
| 20 |
|
---|
| 21 | import java.util.HashMap;
|
---|
[33077] | 22 | import java.util.ArrayList;
|
---|
[4991] | 23 |
|
---|
[32446] | 24 | import org.apache.log4j.Logger;
|
---|
| 25 |
|
---|
[26445] | 26 | /** keeps track of the servlet parameters, and their defaults */
|
---|
[24861] | 27 | public class GSParams
|
---|
| 28 | {
|
---|
[24885] | 29 |
|
---|
[32446] | 30 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.GSParams.class.getName());
|
---|
[33611] | 31 |
|
---|
| 32 | // Only used internally in the session
|
---|
| 33 | public static final String USER_SESSION_CACHE = "user_session_cache";
|
---|
| 34 |
|
---|
[25356] | 35 | // cgi parameter names
|
---|
[24861] | 36 | public static final String ACTION = "a"; // the major type of action- eg query or browse or process
|
---|
| 37 | public static final String SUBACTION = "sa"; // subtype of action if we want different processing than the default
|
---|
| 38 | public static final String REQUEST_TYPE = "rt"; // whether the request is just to display the service form, or to actually do a request to the service
|
---|
| 39 | public static final String RESPONSE_ONLY = "ro"; // if == 1 do the request and pass back the response xml - no page formatting
|
---|
| 40 | public static final String OUTPUT = "o"; // if processing is to be done, what type of output - html/xml/other??
|
---|
| 41 | public static final String SERVICE = "s"; // the name of the service
|
---|
[32717] | 42 |
|
---|
| 43 | public static final String CACHE_KEY = "ck"; // if we want to use another cache key apart from the collection name
|
---|
[28958] | 44 | public static final String UN = "un"; // username for authenticated-ping
|
---|
| 45 | public static final String PW = "pw"; // pwd for authenticated-ping
|
---|
[25300] | 46 |
|
---|
[24861] | 47 | public static final String CLUSTER = "c"; // these two are the same
|
---|
| 48 | public static final String COLLECTION = "c";
|
---|
[25300] | 49 | public static final String COLLECTION_TYPE = "ct"; // collection type - mg, mgpp, lucene etc
|
---|
[32647] | 50 | public static final String GROUP = "group";
|
---|
[24861] | 51 | public static final String LANGUAGE = "l";
|
---|
| 52 | public static final String DOCUMENT = "d";
|
---|
| 53 | public static final String DOCUMENT_TYPE = "dt";
|
---|
[25356] | 54 | public static final String HREF = "href"; // url. might be an external url, or a relative one that needs translating
|
---|
| 55 | public static final String RELATIVE_LINK = "rl"; // whether the href url is relative to the collection or not.
|
---|
| 56 | public static final String EXTERNAL_LINK_TYPE = "el"; // for an external link, go direct to the page or frame it in the collection
|
---|
[24861] | 57 | public static final String PROCESS_ID = "pid"; // if a request wasn't completed, this identifies the request - used when asking for a status update
|
---|
[4991] | 58 |
|
---|
[26084] | 59 | public static final String HTTP_HEADER_FIELDS = "hhf";
|
---|
[25300] | 60 |
|
---|
[33283] | 61 | public static final String FAVOURITEBASKET = "favouritebasket";
|
---|
[36067] | 62 | public static final String DOCUMENTBASKET = "documentbasket";
|
---|
[24861] | 63 | // internal configure args
|
---|
| 64 | public static final String SYSTEM_SUBSET = "ss";
|
---|
| 65 | public static final String SYSTEM_CLUSTER = "sc";
|
---|
| 66 | public static final String SYSTEM_MODULE_NAME = "sn";
|
---|
| 67 | public static final String SYSTEM_MODULE_TYPE = "st";
|
---|
| 68 |
|
---|
| 69 | // used for filtering out a piece of the final page
|
---|
| 70 | public static final String EXCERPT_ID = "excerptid";
|
---|
| 71 | public static final String EXCERPT_TAG = "excerpttag";
|
---|
[24885] | 72 |
|
---|
| 73 | public static final String INLINE_TEMPLATE = "ilt";
|
---|
[24964] | 74 | public static final String FILE_LOCATION = "fl";
|
---|
[32361] | 75 |
|
---|
[25262] | 76 | //Administration
|
---|
[32446] | 77 | public static final String PASSWORD = "password";
|
---|
| 78 | public static final String USERNAME = "username";
|
---|
| 79 | public static final String LOGOUT = "logout";
|
---|
[33178] | 80 | public static final String VERIFIED = "hmvf";
|
---|
[32361] | 81 |
|
---|
[25356] | 82 | // some standard arg values
|
---|
| 83 | public static final String SYSTEM_ACTION = "s";
|
---|
[25300] | 84 |
|
---|
[27087] | 85 | // rss feeds
|
---|
| 86 | public static final String RSS_ACTION = "rss";
|
---|
| 87 |
|
---|
[25356] | 88 | public static final String EXTERNAL_LINK_TYPE_DIRECT = "direct";
|
---|
| 89 | public static final String EXTERNAL_LINK_TYPE_FRAMED = "frame";
|
---|
[26499] | 90 |
|
---|
| 91 | public static final String DEBUG = "debug";
|
---|
[25356] | 92 |
|
---|
[35484] | 93 | public static final String SERVICE_PREFIX = "s1";
|
---|
| 94 | public static final String PREVIOUS_PREFIX = "p";
|
---|
| 95 | public static final String MD_PREFIX = "md___";
|
---|
| 96 | public static final String SAVEPARAM_PREFIX = "jsession";
|
---|
[4991] | 97 |
|
---|
[32446] | 98 | public static final String SERVICE_PARAM_REGEX = "^s\\d\\..*";
|
---|
| 99 |
|
---|
| 100 | protected HashMap<String, Param> param_map = null;
|
---|
| 101 | protected HashMap<String, Param> service_param_map = null;
|
---|
| 102 |
|
---|
[33077] | 103 | protected ArrayList<String> params_with_default_list = null;
|
---|
| 104 |
|
---|
[24861] | 105 | public GSParams()
|
---|
| 106 | {
|
---|
[25635] | 107 | this.param_map = new HashMap<String, Param>(30);
|
---|
[32446] | 108 | this.service_param_map = new HashMap<String, Param>(30);
|
---|
[33077] | 109 | this.params_with_default_list = new ArrayList<String>(10);
|
---|
[23269] | 110 |
|
---|
[32446] | 111 | // we now only need to add in the ones that need saving, as we will default to "not save"
|
---|
[33611] | 112 | // these ones are global params - apply across all collections
|
---|
[34218] | 113 | //addParameter(name, save, sensitive, global)
|
---|
[33611] | 114 | addParameter(LANGUAGE, true, false, true);
|
---|
| 115 | addParameter(FAVOURITEBASKET, true, false, true);
|
---|
[36067] | 116 | addParameter(DOCUMENTBASKET, true, false, true);
|
---|
[33611] | 117 | addParameter(DEBUG, true, false, true);
|
---|
| 118 |
|
---|
| 119 | // these will only be saved per collection/service
|
---|
[24861] | 120 | addParameter(DOCUMENT, true);
|
---|
| 121 | addParameter(PROCESS_ID, true);
|
---|
[32446] | 122 | addParameter(COLLECTION_TYPE, true);
|
---|
[33611] | 123 |
|
---|
[32446] | 124 | // password is sensitive. don't save, but also don't return it in the page response
|
---|
[32361] | 125 | addParameter(PASSWORD, false, true);
|
---|
[26499] | 126 |
|
---|
[4991] | 127 | }
|
---|
| 128 |
|
---|
[24861] | 129 | public boolean addParameter(String name, boolean save)
|
---|
| 130 | {
|
---|
[32361] | 131 | return addParameter(name, "", save);
|
---|
[24861] | 132 | }
|
---|
[4991] | 133 |
|
---|
[35484] | 134 | public boolean addParameter(String name, boolean save, boolean sensitive)
|
---|
| 135 | {
|
---|
[32361] | 136 | if (this.param_map.containsKey(name))
|
---|
| 137 | {
|
---|
| 138 | // already there so could not add
|
---|
| 139 | return false;
|
---|
| 140 | }
|
---|
| 141 | this.param_map.put(name, new Param("", save, sensitive));
|
---|
| 142 | return true;
|
---|
[35484] | 143 | }
|
---|
| 144 |
|
---|
[24861] | 145 | public boolean addParameter(String name, String default_value, boolean save)
|
---|
| 146 | {
|
---|
| 147 | if (this.param_map.containsKey(name))
|
---|
| 148 | {
|
---|
| 149 | // already there so could not add
|
---|
| 150 | return false;
|
---|
| 151 | }
|
---|
[4991] | 152 |
|
---|
[24861] | 153 | this.param_map.put(name, new Param(default_value, save));
|
---|
[33077] | 154 | if (default_value != null && !default_value.equals("")) {
|
---|
| 155 | this.params_with_default_list.add(name);
|
---|
| 156 | }
|
---|
[24861] | 157 | return true;
|
---|
[4991] | 158 | }
|
---|
[33611] | 159 | public boolean addParameter(String name, boolean save, boolean sensitive, boolean global)
|
---|
| 160 | {
|
---|
| 161 | if (this.param_map.containsKey(name))
|
---|
| 162 | {
|
---|
| 163 | // already there so could not add
|
---|
| 164 | return false;
|
---|
| 165 | }
|
---|
| 166 | this.param_map.put(name, new Param("", save, sensitive, global));
|
---|
| 167 | return true;
|
---|
| 168 |
|
---|
| 169 | }
|
---|
[24861] | 170 |
|
---|
[32446] | 171 | public boolean addServiceParameter(String name, String default_value, boolean save, boolean sensitive) {
|
---|
| 172 | if (this.service_param_map.containsKey(name)) {
|
---|
| 173 | // already there, could not add
|
---|
| 174 | return false;
|
---|
| 175 | }
|
---|
| 176 | this.service_param_map.put(name, new Param(default_value, save, sensitive));
|
---|
| 177 | return true;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
| 180 |
|
---|
[24861] | 181 | public boolean setParamDefault(String name, String default_value)
|
---|
| 182 | {
|
---|
[25635] | 183 | Param p = this.param_map.get(name);
|
---|
[33077] | 184 | if (p == null) {
|
---|
| 185 | addParameter(name, default_value, true);
|
---|
| 186 | }else {
|
---|
| 187 | p.default_value = default_value;
|
---|
| 188 | }
|
---|
| 189 | if (!this.params_with_default_list.contains(name)) {
|
---|
| 190 | this.params_with_default_list.add(name);
|
---|
| 191 | }
|
---|
[24861] | 192 | return true;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
[33077] | 195 | public String getParamDefault(String name) {
|
---|
| 196 | Param p = this.param_map.get(name);
|
---|
| 197 | if (p==null) {
|
---|
| 198 | return null;
|
---|
| 199 | }
|
---|
| 200 | return p.default_value;
|
---|
| 201 |
|
---|
| 202 | }
|
---|
[24861] | 203 | public boolean shouldSave(String name)
|
---|
| 204 | {
|
---|
[25356] | 205 | // p. is used to store previous settings
|
---|
[35484] | 206 | if (name.startsWith(PREVIOUS_PREFIX+".") || name.startsWith(MD_PREFIX)) {
|
---|
[24861] | 207 | return false;
|
---|
[35484] | 208 | }
|
---|
| 209 | else if (name.startsWith(SAVEPARAM_PREFIX+".")) {
|
---|
| 210 | return true;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
[32446] | 213 | Param p;
|
---|
| 214 | if (name.matches(SERVICE_PARAM_REGEX)) {
|
---|
| 215 | // its a service param
|
---|
| 216 | p = this.service_param_map.get(name.substring(3));
|
---|
| 217 | } else {
|
---|
| 218 | // an ordinary param
|
---|
| 219 | p = this.param_map.get(name);
|
---|
| 220 | }
|
---|
| 221 | if (p==null) {
|
---|
| 222 | return false; // never save unknown params
|
---|
| 223 | }
|
---|
[35484] | 224 |
|
---|
[24861] | 225 | return p.save;
|
---|
| 226 | }
|
---|
[32446] | 227 |
|
---|
[24861] | 228 |
|
---|
[32361] | 229 | public boolean isSensitive(String name) {
|
---|
[32446] | 230 | Param p;
|
---|
| 231 | if (name.matches(SERVICE_PARAM_REGEX)) {
|
---|
| 232 | p = this.service_param_map.get(name.substring(3));
|
---|
| 233 | } else {
|
---|
| 234 | p = this.param_map.get(name);
|
---|
| 235 | }
|
---|
[32361] | 236 | if (p==null) {
|
---|
| 237 | return false;
|
---|
| 238 | }
|
---|
| 239 | return p.sensitive;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[33611] | 242 | public boolean isGlobal(String name) {
|
---|
| 243 | Param p = this.param_map.get(name);
|
---|
| 244 | if (p==null) {
|
---|
| 245 | return false;
|
---|
[33077] | 246 | }
|
---|
[33611] | 247 | return p.is_global;
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | public ArrayList<String> getParamsWithDefaults() {
|
---|
| 251 | return (ArrayList<String> )this.params_with_default_list.clone();
|
---|
| 252 | }
|
---|
| 253 |
|
---|
[32361] | 254 | private class Param
|
---|
[33611] | 255 | {
|
---|
[24861] | 256 |
|
---|
[33611] | 257 | public String default_value = null;
|
---|
| 258 | public boolean save = true;
|
---|
| 259 | public boolean sensitive = false;
|
---|
| 260 | public boolean is_global = false;
|
---|
| 261 |
|
---|
| 262 | public Param(String default_value, boolean save)
|
---|
| 263 | {
|
---|
| 264 | this.default_value = default_value;
|
---|
| 265 | this.save = save;
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | public Param(String default_value, boolean save, boolean sensitive) {
|
---|
| 269 | this.default_value = default_value;
|
---|
| 270 | this.save = save;
|
---|
| 271 | this.sensitive = sensitive;
|
---|
| 272 | }
|
---|
[24861] | 273 |
|
---|
[33611] | 274 | public Param(String default_value, boolean save, boolean sensitive, boolean global) {
|
---|
| 275 | this.default_value = default_value;
|
---|
| 276 | this.save = save;
|
---|
| 277 | this.sensitive = sensitive;
|
---|
| 278 | this.is_global = global;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 | }
|
---|
[4991] | 282 | }
|
---|