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

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

setting berrybasket param to be saved in session

  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 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 CACHE_KEY = "ck"; // if we want to use another cache key apart from the collection name
39 public static final String UN = "un"; // username for authenticated-ping
40 public static final String PW = "pw"; // pwd for authenticated-ping
41
42 public static final String CLUSTER = "c"; // these two are the same
43 public static final String COLLECTION = "c";
44 public static final String COLLECTION_TYPE = "ct"; // collection type - mg, mgpp, lucene etc
45 public static final String GROUP = "group";
46 public static final String LANGUAGE = "l";
47 public static final String DOCUMENT = "d";
48 public static final String DOCUMENT_TYPE = "dt";
49 public static final String HREF = "href"; // url. might be an external url, or a relative one that needs translating
50 public static final String RELATIVE_LINK = "rl"; // whether the href url is relative to the collection or not.
51 public static final String EXTERNAL_LINK_TYPE = "el"; // for an external link, go direct to the page or frame it in the collection
52 public static final String PROCESS_ID = "pid"; // if a request wasn't completed, this identifies the request - used when asking for a status update
53
54 public static final String HTTP_HEADER_FIELDS = "hhf";
55
56 public static final String BERRYBASKET = "berrybasket";
57 // internal configure args
58 public static final String SYSTEM_SUBSET = "ss";
59 public static final String SYSTEM_CLUSTER = "sc";
60 public static final String SYSTEM_MODULE_NAME = "sn";
61 public static final String SYSTEM_MODULE_TYPE = "st";
62
63 // used for filtering out a piece of the final page
64 public static final String EXCERPT_ID = "excerptid";
65 public static final String EXCERPT_TAG = "excerpttag";
66
67 public static final String INLINE_TEMPLATE = "ilt";
68 public static final String FILE_LOCATION = "fl";
69
70 //Administration
71 public static final String PASSWORD = "password";
72 public static final String USERNAME = "username";
73 public static final String LOGOUT = "logout";
74
75 // some standard arg values
76 public static final String SYSTEM_ACTION = "s";
77
78 // rss feeds
79 public static final String RSS_ACTION = "rss";
80
81 public static final String EXTERNAL_LINK_TYPE_DIRECT = "direct";
82 public static final String EXTERNAL_LINK_TYPE_FRAMED = "frame";
83
84 public static final String DEBUG = "debug";
85
86 public static final String SERVICE_PREFIX = "s1";
87 public static final String PREVIOUS_PREFIX = "p";
88 public static final String MD_PREFIX = "md___";
89
90 public static final String SERVICE_PARAM_REGEX = "^s\\d\\..*";
91
92 protected HashMap<String, Param> param_map = null;
93 protected HashMap<String, Param> service_param_map = null;
94
95 public GSParams()
96 {
97 this.param_map = new HashMap<String, Param>(30);
98 this.service_param_map = new HashMap<String, Param>(30);
99
100 // we now only need to add in the ones that need saving, as we will default to "not save"
101 addParameter(LANGUAGE, true);
102 addParameter(DOCUMENT, true);
103 addParameter(PROCESS_ID, true);
104 addParameter(COLLECTION_TYPE, true);
105 addParameter(DEBUG, true);
106 addParameter(BERRYBASKET, true);
107 // password is sensitive. don't save, but also don't return it in the page response
108 addParameter(PASSWORD, false, true);
109
110 }
111
112 public boolean addParameter(String name, boolean save)
113 {
114 return addParameter(name, "", save);
115 }
116
117 public boolean addParameter(String name, boolean save, boolean sensitive) {
118 if (this.param_map.containsKey(name))
119 {
120 // already there so could not add
121 return false;
122 }
123 this.param_map.put(name, new Param("", save, sensitive));
124 return true;
125 }
126 public boolean addParameter(String name, String default_value, boolean save)
127 {
128 if (this.param_map.containsKey(name))
129 {
130 // already there so could not add
131 return false;
132 }
133
134 this.param_map.put(name, new Param(default_value, save));
135 return true;
136 }
137
138 public boolean addServiceParameter(String name, String default_value, boolean save, boolean sensitive) {
139 if (this.service_param_map.containsKey(name)) {
140 // already there, could not add
141 return false;
142 }
143 this.service_param_map.put(name, new Param(default_value, save, sensitive));
144 return true;
145 }
146
147
148 public boolean setParamDefault(String name, String default_value)
149 {
150 Param p = this.param_map.get(name);
151 if (p == null)
152 return false;
153 p.default_value = default_value;
154 return true;
155 }
156
157 public boolean shouldSave(String name)
158 {
159 // p. is used to store previous settings
160 if (name.startsWith(PREVIOUS_PREFIX+".") || name.startsWith(MD_PREFIX))
161 return false;
162 Param p;
163 if (name.matches(SERVICE_PARAM_REGEX)) {
164 // its a service param
165 p = this.service_param_map.get(name.substring(3));
166 } else {
167 // an ordinary param
168 p = this.param_map.get(name);
169 }
170 if (p==null) {
171 return false; // never save unknown params
172 }
173 return p.save;
174 }
175
176
177 public boolean isSensitive(String name) {
178 Param p;
179 if (name.matches(SERVICE_PARAM_REGEX)) {
180 p = this.service_param_map.get(name.substring(3));
181 } else {
182 p = this.param_map.get(name);
183 }
184 if (p==null) {
185 return false;
186 }
187 return p.sensitive;
188 }
189
190 private class Param
191 {
192
193 public String default_value = null;
194 public boolean save = true;
195 public boolean sensitive = false;
196
197 public Param(String default_value, boolean save)
198 {
199 this.default_value = default_value;
200 this.save = save;
201 }
202
203 public Param(String default_value, boolean save, boolean sensitive) {
204 this.default_value = default_value;
205 this.save = save;
206 this.sensitive = sensitive;
207 }
208
209 }
210}
Note: See TracBrowser for help on using the repository browser.