[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;
|
---|
| 22 |
|
---|
[26445] | 23 | /** keeps track of the servlet parameters, and their defaults */
|
---|
[24861] | 24 | public class GSParams
|
---|
| 25 | {
|
---|
[24885] | 26 |
|
---|
[25356] | 27 | // cgi parameter names
|
---|
[24861] | 28 | public static final String ACTION = "a"; // the major type of action- eg query or browse or process
|
---|
| 29 | public static final String SUBACTION = "sa"; // subtype of action if we want different processing than the default
|
---|
| 30 | 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
|
---|
| 31 | public static final String RESPONSE_ONLY = "ro"; // if == 1 do the request and pass back the response xml - no page formatting
|
---|
| 32 | public static final String OUTPUT = "o"; // if processing is to be done, what type of output - html/xml/other??
|
---|
| 33 | public static final String SERVICE = "s"; // the name of the service
|
---|
[28958] | 34 |
|
---|
| 35 | public static final String UN = "un"; // username for authenticated-ping
|
---|
| 36 | public static final String PW = "pw"; // pwd for authenticated-ping
|
---|
[25300] | 37 |
|
---|
[24861] | 38 | public static final String CLUSTER = "c"; // these two are the same
|
---|
| 39 | public static final String COLLECTION = "c";
|
---|
[25300] | 40 | public static final String COLLECTION_TYPE = "ct"; // collection type - mg, mgpp, lucene etc
|
---|
| 41 |
|
---|
[24861] | 42 | public static final String LANGUAGE = "l";
|
---|
| 43 | public static final String DOCUMENT = "d";
|
---|
| 44 | public static final String DOCUMENT_TYPE = "dt";
|
---|
[25483] | 45 | public static final String START_PAGE = "startPage";
|
---|
[25735] | 46 | public static final String S_START_PAGE = "s1.startPage";
|
---|
[25356] | 47 | public static final String HREF = "href"; // url. might be an external url, or a relative one that needs translating
|
---|
| 48 | public static final String RELATIVE_LINK = "rl"; // whether the href url is relative to the collection or not.
|
---|
| 49 | public static final String EXTERNAL_LINK_TYPE = "el"; // for an external link, go direct to the page or frame it in the collection
|
---|
[24861] | 50 | 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] | 51 |
|
---|
[26084] | 52 | public static final String HTTP_HEADER_FIELDS = "hhf";
|
---|
| 53 | public static final String QUICK_SEARCH = "qs";
|
---|
[25300] | 54 |
|
---|
[24861] | 55 | // internal configure args
|
---|
| 56 | public static final String SYSTEM_SUBSET = "ss";
|
---|
| 57 | public static final String SYSTEM_CLUSTER = "sc";
|
---|
| 58 | public static final String SYSTEM_MODULE_NAME = "sn";
|
---|
| 59 | public static final String SYSTEM_MODULE_TYPE = "st";
|
---|
| 60 |
|
---|
| 61 | // used for filtering out a piece of the final page
|
---|
| 62 | public static final String EXCERPT_ID = "excerptid";
|
---|
| 63 | public static final String EXCERPT_TAG = "excerpttag";
|
---|
[24885] | 64 |
|
---|
| 65 | public static final String INLINE_TEMPLATE = "ilt";
|
---|
| 66 | public static final String DISPLAY_METADATA = "dmd";
|
---|
[24964] | 67 | public static final String FILE_LOCATION = "fl";
|
---|
[25461] | 68 | public static final String DOC_EDIT = "docEdit";
|
---|
[25653] | 69 | public static final String AJAX_LOAD_BYPASS = "alb";
|
---|
[25356] | 70 |
|
---|
[31870] | 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";
|
---|
[32361] | 75 |
|
---|
[25262] | 76 | //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";
|
---|
[32361] | 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";
|
---|
[25857] | 89 | //Facets
|
---|
| 90 | public static final String S_FACETS = "s1.facets";
|
---|
| 91 | public static final String S_FACETS_QUERIES = "s1.facetQueries";
|
---|
[24885] | 92 |
|
---|
[25356] | 93 | // some standard arg values
|
---|
| 94 | public static final String SYSTEM_ACTION = "s";
|
---|
[25300] | 95 |
|
---|
[27087] | 96 | // rss feeds
|
---|
| 97 | public static final String RSS_ACTION = "rss";
|
---|
| 98 |
|
---|
[25356] | 99 | public static final String EXTERNAL_LINK_TYPE_DIRECT = "direct";
|
---|
| 100 | public static final String EXTERNAL_LINK_TYPE_FRAMED = "frame";
|
---|
[26499] | 101 |
|
---|
| 102 | public static final String DEBUG = "debug";
|
---|
[25356] | 103 |
|
---|
[25635] | 104 | protected HashMap<String, Param> param_map = null;
|
---|
[4991] | 105 |
|
---|
[24861] | 106 | public GSParams()
|
---|
| 107 | {
|
---|
[25635] | 108 | this.param_map = new HashMap<String, Param>(30);
|
---|
[23269] | 109 |
|
---|
[24861] | 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);
|
---|
[25300] | 115 | addParameter(CLUSTER, false); // we don't want to save cluster/collection
|
---|
[24861] | 116 | addParameter(LANGUAGE, true);
|
---|
| 117 | addParameter(DOCUMENT, true);
|
---|
[25937] | 118 | addParameter(DOCUMENT_TYPE, false);
|
---|
[26084] | 119 | addParameter(QUICK_SEARCH, false);
|
---|
[25735] | 120 | addParameter(START_PAGE, false);
|
---|
| 121 | addParameter(S_START_PAGE, false);
|
---|
[25300] | 122 | // should the following two just be in doc action??
|
---|
| 123 | addParameter(HREF, false);
|
---|
| 124 | addParameter(RELATIVE_LINK, false);
|
---|
[24861] | 125 | addParameter(OUTPUT, false);
|
---|
| 126 | addParameter(SERVICE, false);
|
---|
| 127 | 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);
|
---|
[24885] | 132 | addParameter(INLINE_TEMPLATE, false);
|
---|
| 133 | addParameter(DISPLAY_METADATA, false);
|
---|
[25653] | 134 | addParameter(AJAX_LOAD_BYPASS, false);
|
---|
[31870] | 135 | addParameter(EXPAND_DOCUMENT, false);
|
---|
| 136 | addParameter(EXPAND_CONTENTS, false);
|
---|
| 137 | addParameter(NO_TEXT, false);
|
---|
[25461] | 138 | addParameter(DOC_EDIT, false);
|
---|
[32361] | 139 | 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);
|
---|
[25857] | 149 | addParameter(S_FACETS, false);
|
---|
| 150 | addParameter(S_FACETS_QUERIES, false);
|
---|
[24861] | 151 |
|
---|
[25356] | 152 | addParameter(COLLECTION_TYPE, true);
|
---|
[25300] | 153 | addParameter(EXTERNAL_LINK_TYPE, false);
|
---|
[24861] | 154 | // filtering args must be specified each time
|
---|
| 155 | addParameter(EXCERPT_ID, false);
|
---|
| 156 | addParameter(EXCERPT_TAG, false);
|
---|
[26499] | 157 |
|
---|
[27022] | 158 | addParameter(DEBUG, true);
|
---|
[4991] | 159 | }
|
---|
| 160 |
|
---|
[24861] | 161 | public boolean addParameter(String name, boolean save)
|
---|
| 162 | {
|
---|
[32361] | 163 | return addParameter(name, "", save);
|
---|
[24861] | 164 | }
|
---|
[4991] | 165 |
|
---|
[32361] | 166 | public boolean addParameter(String name, boolean save, boolean sensitive) {
|
---|
| 167 | if (this.param_map.containsKey(name))
|
---|
| 168 | {
|
---|
| 169 | // already there so could not add
|
---|
| 170 | return false;
|
---|
| 171 | }
|
---|
| 172 | this.param_map.put(name, new Param("", save, sensitive));
|
---|
| 173 | return true;
|
---|
| 174 | }
|
---|
[24861] | 175 | public boolean addParameter(String name, String default_value, boolean save)
|
---|
| 176 | {
|
---|
| 177 | if (this.param_map.containsKey(name))
|
---|
| 178 | {
|
---|
| 179 | // already there so could not add
|
---|
| 180 | return false;
|
---|
| 181 | }
|
---|
[4991] | 182 |
|
---|
[24861] | 183 | this.param_map.put(name, new Param(default_value, save));
|
---|
| 184 | return true;
|
---|
[4991] | 185 | }
|
---|
[24861] | 186 |
|
---|
| 187 | public boolean setParamDefault(String name, String default_value)
|
---|
| 188 | {
|
---|
[25635] | 189 | Param p = this.param_map.get(name);
|
---|
[24861] | 190 | if (p == null)
|
---|
| 191 | return false;
|
---|
| 192 | p.default_value = default_value;
|
---|
| 193 | return true;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | public boolean shouldSave(String name)
|
---|
| 197 | {
|
---|
[25356] | 198 | // p. is used to store previous settings
|
---|
[27719] | 199 | if (name.startsWith("p.") || name.startsWith("md___"))
|
---|
[24861] | 200 | return false;
|
---|
[25635] | 201 | Param p = this.param_map.get(name);
|
---|
[24861] | 202 | if (p == null)
|
---|
| 203 | return true; // if things are not in here, always save.
|
---|
| 204 | return p.save;
|
---|
| 205 | }
|
---|
| 206 |
|
---|
[32361] | 207 | public boolean isSensitive(String name) {
|
---|
| 208 | Param p = this.param_map.get(name);
|
---|
| 209 | if (p==null) {
|
---|
| 210 | return false;
|
---|
| 211 | }
|
---|
| 212 | return p.sensitive;
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | private class Param
|
---|
[24861] | 216 | {
|
---|
| 217 |
|
---|
| 218 | public String default_value = null;
|
---|
| 219 | public boolean save = true;
|
---|
[32361] | 220 | public boolean sensitive = false;
|
---|
[24861] | 221 |
|
---|
[32361] | 222 | public Param(String default_value, boolean save)
|
---|
[24861] | 223 | {
|
---|
| 224 | this.default_value = default_value;
|
---|
| 225 | this.save = save;
|
---|
| 226 | }
|
---|
[32361] | 227 |
|
---|
| 228 | public Param(String default_value, boolean save, boolean sensitive) {
|
---|
| 229 | this.default_value = default_value;
|
---|
| 230 | this.save = save;
|
---|
| 231 | this.sensitive = sensitive;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
[24861] | 234 | }
|
---|
[4991] | 235 | }
|
---|