1 | /** |
---|
2 | * This software is copyright (c) 2011-2013 by |
---|
3 | * - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) |
---|
4 | * This is free software. You can redistribute it |
---|
5 | * and/or modify it under the terms described in |
---|
6 | * the GNU General Public License v3 of which you |
---|
7 | * should have received a copy. Otherwise you can download |
---|
8 | * it from |
---|
9 | * |
---|
10 | * http://www.gnu.org/licenses/gpl-3.0.txt |
---|
11 | * |
---|
12 | * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de) |
---|
13 | * |
---|
14 | * @license http://www.gnu.org/licenses/gpl-3.0.txt |
---|
15 | * GNU General Public License v3 |
---|
16 | */ |
---|
17 | package eu.clarin.sru.server; |
---|
18 | |
---|
19 | import java.util.List; |
---|
20 | |
---|
21 | import javax.servlet.http.HttpServletRequest; |
---|
22 | |
---|
23 | import org.z3950.zing.cql.CQLNode; |
---|
24 | |
---|
25 | |
---|
26 | /** |
---|
27 | * Provides information about a SRU request. |
---|
28 | */ |
---|
29 | public interface SRURequest { |
---|
30 | |
---|
31 | /** |
---|
32 | * Get the <em>operation</em> parameter of this request. Available for |
---|
33 | * <em>explain</em>, <em>searchRetrieve</em> and <em>scan</em> requests. |
---|
34 | * |
---|
35 | * @return the operation |
---|
36 | * @see SRUOperation |
---|
37 | */ |
---|
38 | public SRUOperation getOperation(); |
---|
39 | |
---|
40 | |
---|
41 | /** |
---|
42 | * Get the <em>version</em> parameter of this request. Available for |
---|
43 | * <em>explain</em>, <em>searchRetrieve</em> and <em>scan</em> requests. |
---|
44 | * |
---|
45 | * @return the version |
---|
46 | * @see SRUVersion |
---|
47 | */ |
---|
48 | public SRUVersion getVersion(); |
---|
49 | |
---|
50 | |
---|
51 | /** |
---|
52 | * Check if this request is of a specific version. |
---|
53 | * |
---|
54 | * @param version |
---|
55 | * the version to check |
---|
56 | * @return <code>true</code> if this request is in the requested version, |
---|
57 | * <code>false</code> otherwise |
---|
58 | * @throws NullPointerException |
---|
59 | * if version is <code>null</code> |
---|
60 | */ |
---|
61 | public boolean isVersion(SRUVersion version); |
---|
62 | |
---|
63 | |
---|
64 | /** |
---|
65 | * Check if version of this request is at least <em>min</em> and at most |
---|
66 | * <em>max</em>. |
---|
67 | * |
---|
68 | * @param min |
---|
69 | * the minimum version |
---|
70 | * @param max |
---|
71 | * the maximum version |
---|
72 | * @return <code>true</code> if this request is in the provides version, |
---|
73 | * <code>false</code> otherwise |
---|
74 | * @throws NullPointerException |
---|
75 | * if minimum or maximum <code>null</code> |
---|
76 | * @throws IllegalArgumentException |
---|
77 | * if minimum is larger the maximum |
---|
78 | */ |
---|
79 | public boolean isVersion(SRUVersion min, SRUVersion max); |
---|
80 | |
---|
81 | |
---|
82 | /** |
---|
83 | * Get the <em>recordXmlEscpaing</em> (SRU 2.0) or <em>recordPacking</em> |
---|
84 | * (SRU 1.1 and SRU 1.2) parameter of this request. Only available for |
---|
85 | * <em>explain</em> and <em>searchRetrieve</em> requests. |
---|
86 | * |
---|
87 | * @return the record XML escaping method |
---|
88 | * @see SRURecordXmlEscaping |
---|
89 | */ |
---|
90 | public SRURecordXmlEscaping getRecordXmlEscaping(); |
---|
91 | |
---|
92 | |
---|
93 | /** |
---|
94 | * Get the <em>recordPacking</em> (SRU 2.0) parameter of this request. Only |
---|
95 | * available for <em>searchRetrieve</em> requests. |
---|
96 | * |
---|
97 | * @return the record packing method |
---|
98 | * @see SRURecordPacking |
---|
99 | */ |
---|
100 | public SRURecordPacking getRecordPacking(); |
---|
101 | |
---|
102 | |
---|
103 | /** |
---|
104 | * Get the <em>query</em> parameter of this request. Only available for |
---|
105 | * <em>searchRetrieve</em> requests. |
---|
106 | * |
---|
107 | * @return an {@link SRUQuery} instance tailored for the used queryType or |
---|
108 | * <code>null</code> if not a <em>searchRetrieve</em> request |
---|
109 | */ |
---|
110 | public SRUQuery<?> getQuery(); |
---|
111 | |
---|
112 | |
---|
113 | /** |
---|
114 | * Get the <em>query</em> parameter of this request. Only available for |
---|
115 | * <em>searchRetrieve</em> requests. This convenience method tried to cast |
---|
116 | * the query object to the supplied type. |
---|
117 | * |
---|
118 | * @param type |
---|
119 | * Class representing the Java data type to convert the query to. |
---|
120 | * @return an {@link SRUQuery} instance tailored for the used queryType or |
---|
121 | * <code>null</code> if not a <em>searchRetrieve</em> request |
---|
122 | * @throws ClassCastException |
---|
123 | * if conversion is not supported, type is <code>null</code> or |
---|
124 | * another error occurs |
---|
125 | */ |
---|
126 | public <T extends SRUQuery<?>> T getQuery(Class<T> type); |
---|
127 | |
---|
128 | |
---|
129 | /** |
---|
130 | * Get the <em>queryType</em> parameter of this request. Only available for |
---|
131 | * <em>searchRetrieve</em> requests. |
---|
132 | * |
---|
133 | * @return the queryType of the parsed query or <code>null</code> if not a |
---|
134 | * <em>searchRetrieve</em> request |
---|
135 | */ |
---|
136 | public String getQueryType(); |
---|
137 | |
---|
138 | |
---|
139 | /** |
---|
140 | * Check if the request was made with the given queryType. Only available |
---|
141 | * for <em>searchRetrieve</em> requests. |
---|
142 | * |
---|
143 | * @param queryType |
---|
144 | * the queryType to compare with |
---|
145 | * @return <code>true</code> if the queryType matches, <code>false</code> |
---|
146 | * otherwise |
---|
147 | */ |
---|
148 | public boolean isQueryType(String queryType); |
---|
149 | |
---|
150 | |
---|
151 | /** |
---|
152 | * Get the <em>startRecord</em> parameter of this request. Only available |
---|
153 | * for <em>searchRetrieve</em> requests. If the client did not provide a |
---|
154 | * value for the request, it is set to <code>1</code>. |
---|
155 | * |
---|
156 | * @return the number of the start record |
---|
157 | */ |
---|
158 | public int getStartRecord(); |
---|
159 | |
---|
160 | |
---|
161 | /** |
---|
162 | * Get the <em>maximumRecords</em> parameter of this request. Only available |
---|
163 | * for <em>searchRetrieve</em> requests. If no value was supplied with the |
---|
164 | * request, the server will automatically set a default value. |
---|
165 | * |
---|
166 | * @return the maximum number of records |
---|
167 | */ |
---|
168 | public int getMaximumRecords(); |
---|
169 | |
---|
170 | |
---|
171 | /** |
---|
172 | * Get the record schema identifier derived from the <em>recordSchema</em> |
---|
173 | * parameter of this request. Only available for <em>searchRetrieve</em> |
---|
174 | * requests. If the request was send with the short record schema name, |
---|
175 | * it will automatically expanded to the record schema identifier. |
---|
176 | * |
---|
177 | * @return the record schema identifier or <code>null</code> if no |
---|
178 | * <em>recordSchema</em> parameter was supplied for this request |
---|
179 | */ |
---|
180 | public String getRecordSchemaIdentifier(); |
---|
181 | |
---|
182 | |
---|
183 | /** |
---|
184 | * Get the <em>recordXPath</em> parameter of this request. Only available |
---|
185 | * for <em>searchRetrieve</em> requests and version 1.1 requests. |
---|
186 | * |
---|
187 | * @return the record XPath or <code>null</code> of no value was supplied |
---|
188 | * for this request |
---|
189 | */ |
---|
190 | public String getRecordXPath(); |
---|
191 | |
---|
192 | |
---|
193 | /** |
---|
194 | * Get the <em>resultSetTTL</em> parameter of this request. Only available |
---|
195 | * for <em>searchRetrieve</em> requests. |
---|
196 | * |
---|
197 | * @return the result set TTL or <code>-1</code> if no value was supplied |
---|
198 | * for this request |
---|
199 | */ |
---|
200 | public int getResultSetTTL(); |
---|
201 | |
---|
202 | |
---|
203 | /** |
---|
204 | * Get the <em>sortKeys</em> parameter of this request. Only available for |
---|
205 | * <em>searchRetrieve</em> requests and version 1.1 requests. |
---|
206 | * |
---|
207 | * @return the record XPath or <code>null</code> of no value was supplied |
---|
208 | * for this request |
---|
209 | */ |
---|
210 | public String getSortKeys(); |
---|
211 | |
---|
212 | |
---|
213 | /** |
---|
214 | * Get the <em>scanClause</em> parameter of this request. Only available for |
---|
215 | * <em>scan</em> requests. |
---|
216 | * |
---|
217 | * @return the parsed scan clause or <code>null</code> if not a |
---|
218 | * <em>scan</em> request |
---|
219 | */ |
---|
220 | public CQLNode getScanClause(); |
---|
221 | |
---|
222 | |
---|
223 | /** |
---|
224 | * Get the <em>responsePosition</em> parameter of this request. Only |
---|
225 | * available for <em>scan</em> requests. If the client did not provide |
---|
226 | * a value for the request, it is set to <code>1</code>. |
---|
227 | * |
---|
228 | * @return the response position |
---|
229 | */ |
---|
230 | public int getResponsePosition(); |
---|
231 | |
---|
232 | |
---|
233 | /** |
---|
234 | * Get the <em>maximumTerms</em> parameter of this request. Available for |
---|
235 | * any type of request. |
---|
236 | * |
---|
237 | * @return the maximum number of terms or <code>-1</code> if no value was |
---|
238 | * supplied for this request |
---|
239 | */ |
---|
240 | public int getMaximumTerms(); |
---|
241 | |
---|
242 | |
---|
243 | /** |
---|
244 | * Get the <em>stylesheet</em> parameter of this request. Available for |
---|
245 | * <em>explain</em>, <em>searchRetrieve</em> and <em>scan</em> requests. |
---|
246 | * |
---|
247 | * @return the stylesheet or <code>null</code> if no value was supplied for |
---|
248 | * this request |
---|
249 | */ |
---|
250 | public String getStylesheet(); |
---|
251 | |
---|
252 | |
---|
253 | /** |
---|
254 | * Get the <em>renderBy</em> parameter of this request. |
---|
255 | * |
---|
256 | * @return the renderBy parameter or <code>null</code> if no value was |
---|
257 | * supplied for this request |
---|
258 | */ |
---|
259 | public SRURenderBy getRenderBy(); |
---|
260 | |
---|
261 | |
---|
262 | /** |
---|
263 | * (SRU 2.0) The request parameter <em>responseType</em>, paired with the |
---|
264 | * Internet media type specified for the response (via either the httpAccept |
---|
265 | * parameter or http accept header) determines the schema for the response. |
---|
266 | * |
---|
267 | * @return the value of the responeType request parameter or |
---|
268 | * <code>null</code> if no value was supplied for this request |
---|
269 | */ |
---|
270 | public String getResponeType(); |
---|
271 | |
---|
272 | |
---|
273 | /** |
---|
274 | * (SRU 2.0) The request parameter <em>httpAccept</em> may be supplied to |
---|
275 | * indicate the preferred format of the response. The value is an Internet |
---|
276 | * media type. |
---|
277 | * |
---|
278 | * @return the value of the httpAccept request parameter or |
---|
279 | * <code>null</code> if no value was supplied for |
---|
280 | */ |
---|
281 | public String getHttpAccept(); |
---|
282 | |
---|
283 | |
---|
284 | /** |
---|
285 | * Get the protocol schema which was used of this request. Available for |
---|
286 | * <em>explain</em>, <em>searchRetrieve</em> and <em>scan</em> requests. |
---|
287 | * |
---|
288 | * @return the protocol scheme |
---|
289 | */ |
---|
290 | public String getProtocolScheme(); |
---|
291 | |
---|
292 | |
---|
293 | /** |
---|
294 | * Get the names of extra parameters of this request. Available for |
---|
295 | * <em>explain</em>, <em>searchRetrieve</em> and <em>scan</em> requests. |
---|
296 | * |
---|
297 | * @return a possibly empty list of parameter names |
---|
298 | */ |
---|
299 | public List<String> getExtraRequestDataNames(); |
---|
300 | |
---|
301 | |
---|
302 | /** |
---|
303 | * Get the value of an extra parameter of this request. Available for |
---|
304 | * <em>explain</em>, <em>searchRetrieve</em> and <em>scan</em> requests. |
---|
305 | * |
---|
306 | * @param name |
---|
307 | * name of the extra parameter. Must be prefixed with |
---|
308 | * <code>x-</code> |
---|
309 | * @return the value of the parameter of <code>null</code> of extra |
---|
310 | * parameter with that name exists |
---|
311 | * @throws NullPointerException |
---|
312 | * if <code>name</code> is null |
---|
313 | * @throws IllegalArgumentException |
---|
314 | * if <code>name</code> does not start with <code>x-</code> |
---|
315 | */ |
---|
316 | public String getExtraRequestData(String name); |
---|
317 | |
---|
318 | |
---|
319 | /** |
---|
320 | * Get the raw client request information from the Servlet container. |
---|
321 | * |
---|
322 | * @return the Servlet request |
---|
323 | */ |
---|
324 | public HttpServletRequest getServletRequest(); |
---|
325 | |
---|
326 | } // interface SRURequest |
---|