1 | /** |
---|
2 | * This software is copyright (c) 2011 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.client; |
---|
18 | |
---|
19 | /** |
---|
20 | * An object for performing a <em>explain</em> operation. |
---|
21 | * <p> |
---|
22 | * The following argument arguments are mandatory: |
---|
23 | * </p> |
---|
24 | * <ul> |
---|
25 | * <li><em>query</em></li> |
---|
26 | * </ul> |
---|
27 | * |
---|
28 | * @see SRUSearchRetrieveHandler |
---|
29 | * @see <a href="http://www.loc.gov/standards/sru/specs/search-retrieve.html"> |
---|
30 | * SRU SearchRetrieve Operation</a> |
---|
31 | */ |
---|
32 | public final class SRUSearchRetrieveRequest extends SRUAbstractRequest { |
---|
33 | private String query; |
---|
34 | private int startRecord = -1; |
---|
35 | private int maximumRecords = -1; |
---|
36 | private SRURecordPacking recordPacking; |
---|
37 | private String recordSchema; |
---|
38 | private int resultSetTTL = -1; |
---|
39 | |
---|
40 | |
---|
41 | /** |
---|
42 | * Constructor. |
---|
43 | * |
---|
44 | * @param baseURI |
---|
45 | * the baseURI of the endpoint |
---|
46 | */ |
---|
47 | public SRUSearchRetrieveRequest(String baseURI) { |
---|
48 | super(baseURI); |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | /** |
---|
53 | * Get the value of the <em>query</em> argument for this request. |
---|
54 | * |
---|
55 | * @return the value for the <em>query</em> argument or <code>null</code> of |
---|
56 | * none was set |
---|
57 | */ |
---|
58 | public String getQuery() { |
---|
59 | return query; |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | /** |
---|
64 | * Set the value of the <em>query</em> argument for this request. |
---|
65 | * |
---|
66 | * @param query |
---|
67 | * the value for the <em>query</em> argument |
---|
68 | * @throws NullPointerException |
---|
69 | * if any required argument is <code>null</code> |
---|
70 | * @throws IllegalArgumentException |
---|
71 | * if any argument is invalid |
---|
72 | */ |
---|
73 | public void setQuery(String query) { |
---|
74 | if (query == null) { |
---|
75 | throw new NullPointerException("query == null"); |
---|
76 | } |
---|
77 | if (query.isEmpty()) { |
---|
78 | throw new IllegalArgumentException("query is an empty string"); |
---|
79 | } |
---|
80 | this.query = query; |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | /** |
---|
85 | * Get the value of the <em>startRecord</em> argument for this request. |
---|
86 | * |
---|
87 | * @return the value for the <em>startRecord</em> argument or |
---|
88 | * <code>-1</code> of none was set |
---|
89 | */ |
---|
90 | public int getStartRecord() { |
---|
91 | return startRecord; |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | /** |
---|
96 | * Set the value of the <em>startRecord</em> argument for this request. |
---|
97 | * |
---|
98 | * @param startRecord |
---|
99 | * the value for the <em>startRecord</em> argument |
---|
100 | * @throws IllegalArgumentException |
---|
101 | * if any argument is invalid |
---|
102 | */ |
---|
103 | public void setStartRecord(int startRecord) { |
---|
104 | if (startRecord < 1) { |
---|
105 | throw new IllegalArgumentException("startRecord < 1"); |
---|
106 | } |
---|
107 | this.startRecord = startRecord; |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | /** |
---|
112 | * Get the value of the <em>maximumRecords</em> argument for this request. |
---|
113 | * |
---|
114 | * @return the value for the <em>maximumRecords</em> argument or |
---|
115 | * <code>-1</code> of none was set |
---|
116 | */ |
---|
117 | public int getMaximumRecords() { |
---|
118 | return maximumRecords; |
---|
119 | } |
---|
120 | |
---|
121 | |
---|
122 | /** |
---|
123 | * Set the value of the <em>maximumRecords</em> argument for this request. |
---|
124 | * |
---|
125 | * @param maximumRecords |
---|
126 | * the value for the <em>maximumRecords</em> argument |
---|
127 | * @throws IllegalArgumentException |
---|
128 | * if any argument is invalid |
---|
129 | */ |
---|
130 | public void setMaximumRecords(int maximumRecords) { |
---|
131 | if (maximumRecords < 0) { |
---|
132 | throw new IllegalArgumentException("maximumRecords < 0"); |
---|
133 | } |
---|
134 | this.maximumRecords = maximumRecords; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | /** |
---|
139 | * Get the value of the <em>recordSchema</em> argument for this request. |
---|
140 | * |
---|
141 | * @return the value for the <em>recordSchema</em> argument or |
---|
142 | * <code>null</code> of none was set |
---|
143 | */ |
---|
144 | public String getRecordSchema() { |
---|
145 | return recordSchema; |
---|
146 | } |
---|
147 | |
---|
148 | |
---|
149 | /** |
---|
150 | * Set the value of the <em>recordSchema</em> argument for this request. |
---|
151 | * |
---|
152 | * @param recordSchema |
---|
153 | * the value for the <em>recordSchema</em> argument |
---|
154 | * @throws NullPointerException |
---|
155 | * if any required argument is <code>null</code> |
---|
156 | * @throws IllegalArgumentException |
---|
157 | * if any argument is invalid |
---|
158 | */ |
---|
159 | public void setRecordSchema(String recordSchema) { |
---|
160 | this.recordSchema = recordSchema; |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | /** |
---|
165 | * Get the value of the <em>recordSchema</em> argument for this request. |
---|
166 | * |
---|
167 | * @return the value for the <em>recordSchema</em> argument or |
---|
168 | * <code>null</code> of none was set |
---|
169 | */ |
---|
170 | public SRURecordPacking getRecordPacking() { |
---|
171 | return recordPacking; |
---|
172 | } |
---|
173 | |
---|
174 | |
---|
175 | /** |
---|
176 | * Set the value of the <em>recordPacking</em> argument for this request. |
---|
177 | * |
---|
178 | * @param recordPacking |
---|
179 | * the value for the <em>recordPacking</em> argument |
---|
180 | * @throws NullPointerException |
---|
181 | * if any required argument is <code>null</code> |
---|
182 | */ |
---|
183 | public void setRecordPacking(SRURecordPacking recordPacking) { |
---|
184 | if (recordPacking == null) { |
---|
185 | throw new NullPointerException("recordPacking == null"); |
---|
186 | } |
---|
187 | this.recordPacking = recordPacking; |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | /** |
---|
192 | * Get the value of the <em>resultSetTTL</em> argument for this request. |
---|
193 | * |
---|
194 | * @return the value for the <em>resultSetTTL</em> argument or |
---|
195 | * <code>-1</code> of none was set |
---|
196 | */ |
---|
197 | public int getResultSetTTL() { |
---|
198 | return resultSetTTL; |
---|
199 | } |
---|
200 | |
---|
201 | |
---|
202 | /** |
---|
203 | * Set the value of the <em>resultSetTTL</em> argument for this request. |
---|
204 | * |
---|
205 | * @param resultSetTTL |
---|
206 | * the value for the <em>resultSetTTL</em> argument |
---|
207 | * @throws IllegalArgumentException |
---|
208 | * if any argument is invalid |
---|
209 | */ |
---|
210 | public void setResultSetTTL(int resultSetTTL) { |
---|
211 | this.resultSetTTL = resultSetTTL; |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
215 | @Override |
---|
216 | SRUOperation getOperation() { |
---|
217 | return SRUOperation.SEARCH_RETRIEVE; |
---|
218 | } |
---|
219 | |
---|
220 | |
---|
221 | @Override |
---|
222 | void addParametersToURI(URIBuilder uriBuilder) throws SRUClientException { |
---|
223 | // query |
---|
224 | if ((query == null) || query.isEmpty()) { |
---|
225 | throw new SRUClientException( |
---|
226 | "mandatory argument 'query' not set or empty"); |
---|
227 | } |
---|
228 | uriBuilder.append(PARAM_QUERY, query); |
---|
229 | |
---|
230 | // startRecord |
---|
231 | if (startRecord > 0) { |
---|
232 | uriBuilder.append(PARAM_START_RECORD, startRecord); |
---|
233 | } |
---|
234 | |
---|
235 | // maximumRecords |
---|
236 | if (maximumRecords > -1) { |
---|
237 | uriBuilder.append(PARAM_MAXIMUM_RECORDS, maximumRecords); |
---|
238 | } |
---|
239 | |
---|
240 | // recordPacking |
---|
241 | if (recordPacking != null) { |
---|
242 | switch (recordPacking) { |
---|
243 | case XML: |
---|
244 | uriBuilder.append(PARAM_RECORD_PACKING, RECORD_PACKING_XML); |
---|
245 | break; |
---|
246 | case STRING: |
---|
247 | uriBuilder.append(PARAM_RECORD_PACKING, RECORD_PACKING_STRING); |
---|
248 | break; |
---|
249 | default: |
---|
250 | throw new SRUClientException("unsupported record packing: " + |
---|
251 | recordPacking); |
---|
252 | } // switch |
---|
253 | } |
---|
254 | |
---|
255 | // recordSchema |
---|
256 | if (recordSchema != null) { |
---|
257 | uriBuilder.append(PARAM_RECORD_SCHEMA, recordSchema); |
---|
258 | } |
---|
259 | |
---|
260 | // resultSetTTL |
---|
261 | if (resultSetTTL > -1) { |
---|
262 | uriBuilder.append(PARAM_RESULT_SET_TTL, resultSetTTL); |
---|
263 | } |
---|
264 | } |
---|
265 | |
---|
266 | } // class SRUSearchRetrieveRequest |
---|