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

Last change on this file since 32446 was 32446, checked in by kjdon, 6 years ago

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.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 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;
22
23import org.apache.log4j.Logger;
24
25/** keeps track of the servlet parameters, and their defaults */
26public class GSParams
27{
28
29 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.GSParams.class.getName());
30 // cgi parameter names
31 public static final String ACTION = "a"; // the major type of action- eg query or browse or process
32 public static final String SUBACTION = "sa"; // subtype of action if we want different processing than the default
33 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
34 public static final String RESPONSE_ONLY = "ro"; // if == 1 do the request and pass back the response xml - no page formatting
35 public static final String OUTPUT = "o"; // if processing is to be done, what type of output - html/xml/other??
36 public static final String SERVICE = "s"; // the name of the service
37
38 public static final String UN = "un"; // username for authenticated-ping
39 public static final String PW = "pw"; // pwd for authenticated-ping
40
41 public static final String CLUSTER = "c"; // these two are the same
42 public static final String COLLECTION = "c";
43 public static final String COLLECTION_TYPE = "ct"; // collection type - mg, mgpp, lucene etc
44
45 public static final String LANGUAGE = "l";
46 public static final String DOCUMENT = "d";
47 public static final String DOCUMENT_TYPE = "dt";
48 public static final String HREF = "href"; // url. might be an external url, or a relative one that needs translating
49 public static final String RELATIVE_LINK = "rl"; // whether the href url is relative to the collection or not.
50 public static final String EXTERNAL_LINK_TYPE = "el"; // for an external link, go direct to the page or frame it in the collection
51 public static final String PROCESS_ID = "pid"; // if a request wasn't completed, this identifies the request - used when asking for a status update
52
53 public static final String HTTP_HEADER_FIELDS = "hhf";
54
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";
64
65 public static final String INLINE_TEMPLATE = "ilt";
66 public static final String FILE_LOCATION = "fl";
67
68 //Administration
69 public static final String PASSWORD = "password";
70 public static final String USERNAME = "username";
71 public static final String LOGOUT = "logout";
72
73 // some standard arg values
74 public static final String SYSTEM_ACTION = "s";
75
76 // rss feeds
77 public static final String RSS_ACTION = "rss";
78
79 public static final String EXTERNAL_LINK_TYPE_DIRECT = "direct";
80 public static final String EXTERNAL_LINK_TYPE_FRAMED = "frame";
81
82 public static final String DEBUG = "debug";
83
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;
92
93 public GSParams()
94 {
95 this.param_map = new HashMap<String, Param>(30);
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"
99 addParameter(LANGUAGE, true);
100 addParameter(DOCUMENT, true);
101 addParameter(PROCESS_ID, true);
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
106 addParameter(PASSWORD, false, true);
107
108 }
109
110 public boolean addParameter(String name, boolean save)
111 {
112 return addParameter(name, "", save);
113 }
114
115 public boolean addParameter(String name, boolean save, boolean sensitive) {
116 if (this.param_map.containsKey(name))
117 {
118 // already there so could not add
119 return false;
120 }
121 this.param_map.put(name, new Param("", save, sensitive));
122 return true;
123 }
124 public boolean addParameter(String name, String default_value, boolean save)
125 {
126 if (this.param_map.containsKey(name))
127 {
128 // already there so could not add
129 return false;
130 }
131
132 this.param_map.put(name, new Param(default_value, save));
133 return true;
134 }
135
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
146 public boolean setParamDefault(String name, String default_value)
147 {
148 Param p = this.param_map.get(name);
149 if (p == null)
150 return false;
151 p.default_value = default_value;
152 return true;
153 }
154
155 public boolean shouldSave(String name)
156 {
157 // p. is used to store previous settings
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 }
171 return p.save;
172 }
173
174
175 public boolean isSensitive(String 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 }
182 if (p==null) {
183 return false;
184 }
185 return p.sensitive;
186 }
187
188 private class Param
189 {
190
191 public String default_value = null;
192 public boolean save = true;
193 public boolean sensitive = false;
194
195 public Param(String default_value, boolean save)
196 {
197 this.default_value = default_value;
198 this.save = save;
199 }
200
201 public Param(String default_value, boolean save, boolean sensitive) {
202 this.default_value = default_value;
203 this.save = save;
204 this.sensitive = sensitive;
205 }
206
207 }
208}
Note: See TracBrowser for help on using the repository browser.