source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSParams.java@ 33283

Last change on this file since 33283 was 33283, checked in by kjdon, 5 years ago

added new favouritebasket param, and set it to be saved (like berrybasket param)

  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
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 */
19package org.greenstone.gsdl3.util;
20
21import java.util.HashMap;
22import java.util.ArrayList;
23
24import org.apache.log4j.Logger;
25
26/** keeps track of the servlet parameters, and their defaults */
27public class GSParams
28{
29
30 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.GSParams.class.getName());
31 // cgi parameter names
32 public static final String ACTION = "a"; // the major type of action- eg query or browse or process
33 public static final String SUBACTION = "sa"; // subtype of action if we want different processing than the default
34 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
35 public static final String RESPONSE_ONLY = "ro"; // if == 1 do the request and pass back the response xml - no page formatting
36 public static final String OUTPUT = "o"; // if processing is to be done, what type of output - html/xml/other??
37 public static final String SERVICE = "s"; // the name of the service
38
39 public static final String CACHE_KEY = "ck"; // if we want to use another cache key apart from the collection name
40 public static final String UN = "un"; // username for authenticated-ping
41 public static final String PW = "pw"; // pwd for authenticated-ping
42
43 public static final String CLUSTER = "c"; // these two are the same
44 public static final String COLLECTION = "c";
45 public static final String COLLECTION_TYPE = "ct"; // collection type - mg, mgpp, lucene etc
46 public static final String GROUP = "group";
47 public static final String LANGUAGE = "l";
48 public static final String DOCUMENT = "d";
49 public static final String DOCUMENT_TYPE = "dt";
50 public static final String HREF = "href"; // url. might be an external url, or a relative one that needs translating
51 public static final String RELATIVE_LINK = "rl"; // whether the href url is relative to the collection or not.
52 public static final String EXTERNAL_LINK_TYPE = "el"; // for an external link, go direct to the page or frame it in the collection
53 public static final String PROCESS_ID = "pid"; // if a request wasn't completed, this identifies the request - used when asking for a status update
54
55 public static final String HTTP_HEADER_FIELDS = "hhf";
56
57 public static final String BERRYBASKET = "berrybasket";
58 public static final String FAVOURITEBASKET = "favouritebasket";
59 // internal configure args
60 public static final String SYSTEM_SUBSET = "ss";
61 public static final String SYSTEM_CLUSTER = "sc";
62 public static final String SYSTEM_MODULE_NAME = "sn";
63 public static final String SYSTEM_MODULE_TYPE = "st";
64
65 // used for filtering out a piece of the final page
66 public static final String EXCERPT_ID = "excerptid";
67 public static final String EXCERPT_TAG = "excerpttag";
68
69 public static final String INLINE_TEMPLATE = "ilt";
70 public static final String FILE_LOCATION = "fl";
71
72 //Administration
73 public static final String PASSWORD = "password";
74 public static final String USERNAME = "username";
75 public static final String LOGOUT = "logout";
76 public static final String VERIFIED = "hmvf";
77
78 // some standard arg values
79 public static final String SYSTEM_ACTION = "s";
80
81 // rss feeds
82 public static final String RSS_ACTION = "rss";
83
84 public static final String EXTERNAL_LINK_TYPE_DIRECT = "direct";
85 public static final String EXTERNAL_LINK_TYPE_FRAMED = "frame";
86
87 public static final String DEBUG = "debug";
88
89 public static final String SERVICE_PREFIX = "s1";
90 public static final String PREVIOUS_PREFIX = "p";
91 public static final String MD_PREFIX = "md___";
92
93 public static final String SERVICE_PARAM_REGEX = "^s\\d\\..*";
94
95 protected HashMap<String, Param> param_map = null;
96 protected HashMap<String, Param> service_param_map = null;
97
98 protected ArrayList<String> params_with_default_list = null;
99
100 public GSParams()
101 {
102 this.param_map = new HashMap<String, Param>(30);
103 this.service_param_map = new HashMap<String, Param>(30);
104 this.params_with_default_list = new ArrayList<String>(10);
105
106 // we now only need to add in the ones that need saving, as we will default to "not save"
107 addParameter(LANGUAGE, true);
108 addParameter(DOCUMENT, true);
109 addParameter(PROCESS_ID, true);
110 addParameter(COLLECTION_TYPE, true);
111 addParameter(DEBUG, true);
112 addParameter(BERRYBASKET, true);
113 addParameter(FAVOURITEBASKET, true);
114 // password is sensitive. don't save, but also don't return it in the page response
115 addParameter(PASSWORD, false, true);
116
117 }
118
119 public boolean addParameter(String name, boolean save)
120 {
121 return addParameter(name, "", save);
122 }
123
124 public boolean addParameter(String name, boolean save, boolean sensitive) {
125 if (this.param_map.containsKey(name))
126 {
127 // already there so could not add
128 return false;
129 }
130 this.param_map.put(name, new Param("", save, sensitive));
131 return true;
132 }
133 public boolean addParameter(String name, String default_value, boolean save)
134 {
135 if (this.param_map.containsKey(name))
136 {
137 // already there so could not add
138 return false;
139 }
140
141 this.param_map.put(name, new Param(default_value, save));
142 if (default_value != null && !default_value.equals("")) {
143 this.params_with_default_list.add(name);
144 }
145 return true;
146 }
147
148 public boolean addServiceParameter(String name, String default_value, boolean save, boolean sensitive) {
149 if (this.service_param_map.containsKey(name)) {
150 // already there, could not add
151 return false;
152 }
153 this.service_param_map.put(name, new Param(default_value, save, sensitive));
154 return true;
155 }
156
157
158 public boolean setParamDefault(String name, String default_value)
159 {
160 Param p = this.param_map.get(name);
161 if (p == null) {
162 addParameter(name, default_value, true);
163 }else {
164 p.default_value = default_value;
165 }
166 if (!this.params_with_default_list.contains(name)) {
167 this.params_with_default_list.add(name);
168 }
169 return true;
170 }
171
172 public String getParamDefault(String name) {
173 Param p = this.param_map.get(name);
174 if (p==null) {
175 return null;
176 }
177 return p.default_value;
178
179 }
180 public boolean shouldSave(String name)
181 {
182 // p. is used to store previous settings
183 if (name.startsWith(PREVIOUS_PREFIX+".") || name.startsWith(MD_PREFIX))
184 return false;
185 Param p;
186 if (name.matches(SERVICE_PARAM_REGEX)) {
187 // its a service param
188 p = this.service_param_map.get(name.substring(3));
189 } else {
190 // an ordinary param
191 p = this.param_map.get(name);
192 }
193 if (p==null) {
194 return false; // never save unknown params
195 }
196 return p.save;
197 }
198
199
200 public boolean isSensitive(String name) {
201 Param p;
202 if (name.matches(SERVICE_PARAM_REGEX)) {
203 p = this.service_param_map.get(name.substring(3));
204 } else {
205 p = this.param_map.get(name);
206 }
207 if (p==null) {
208 return false;
209 }
210 return p.sensitive;
211 }
212
213 public ArrayList<String> getParamsWithDefaults() {
214 return (ArrayList<String> )this.params_with_default_list.clone();
215 }
216
217 private class Param
218 {
219
220 public String default_value = null;
221 public boolean save = true;
222 public boolean sensitive = false;
223
224 public Param(String default_value, boolean save)
225 {
226 this.default_value = default_value;
227 this.save = save;
228 }
229
230 public Param(String default_value, boolean save, boolean sensitive) {
231 this.default_value = default_value;
232 this.save = save;
233 this.sensitive = sensitive;
234 }
235
236 }
237}
Note: See TracBrowser for help on using the repository browser.