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