1 | /** |
---|
2 | * This software is copyright (c) 2012-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.client; |
---|
18 | |
---|
19 | import java.net.URI; |
---|
20 | |
---|
21 | /** |
---|
22 | * An object for performing a <em>explain</em> operation. |
---|
23 | * <p>The following argument arguments are mandatory:</p> |
---|
24 | * <ul> |
---|
25 | * <li><em>scanClause</em></li> |
---|
26 | * </ul> |
---|
27 | * |
---|
28 | * @see SRUScanHandler |
---|
29 | * @see <a href="http://www.loc.gov/standards/sru/specs/scan.html">SRU Scan |
---|
30 | * Operation</a> |
---|
31 | */ |
---|
32 | public class SRUScanRequest extends SRUAbstractRequest { |
---|
33 | /** for end-point conformance testing only. never use in production. */ |
---|
34 | public static final String X_MALFORMED_SCAN_CLAUSE = |
---|
35 | "x-malformed-scanClause"; |
---|
36 | /** for end-point conformance testing only. never use in production. */ |
---|
37 | public static final String X_MALFORMED_RESPONSE_POSITION = |
---|
38 | "x-malformed-responsePosition"; |
---|
39 | /** for end-point conformance testing only. never use in production. */ |
---|
40 | public static final String X_MALFORMED_MAXIMUM_TERMS = |
---|
41 | "x-malformed-maximumTerms"; |
---|
42 | private String scanClause; |
---|
43 | private int responsePosition = -1; |
---|
44 | private int maximumTerms = -1; |
---|
45 | |
---|
46 | |
---|
47 | /** |
---|
48 | * Constructor. |
---|
49 | * |
---|
50 | * @param baseURI |
---|
51 | * the baseURI of the endpoint |
---|
52 | */ |
---|
53 | public SRUScanRequest(URI baseURI) { |
---|
54 | super(baseURI); |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | /** |
---|
59 | * Constructor. |
---|
60 | * |
---|
61 | * @param baseURI |
---|
62 | * the baseURI of the endpoint |
---|
63 | */ |
---|
64 | public SRUScanRequest(String baseURI) { |
---|
65 | super(baseURI); |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | /** |
---|
70 | * Get the value of the <em>scanClause</em> argument for this request. |
---|
71 | * |
---|
72 | * @return the value for the <em>scanClause</em> argument or |
---|
73 | * <code>null</code> of none was set |
---|
74 | */ |
---|
75 | public String getScanClause() { |
---|
76 | return scanClause; |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | /** |
---|
81 | * Set the value of the <em>scanClause</em> argument for this request. |
---|
82 | * |
---|
83 | * @param scanClause |
---|
84 | * the value for the <em>scanClause</em> argument |
---|
85 | * @throws NullPointerException |
---|
86 | * if any required argument is <code>null</code> |
---|
87 | * @throws IllegalArgumentException |
---|
88 | * if any argument is invalid |
---|
89 | */ |
---|
90 | public void setScanClause(String scanClause) { |
---|
91 | if (scanClause == null) { |
---|
92 | throw new NullPointerException("scanClause == null"); |
---|
93 | } |
---|
94 | if (scanClause.isEmpty()) { |
---|
95 | throw new IllegalArgumentException("scanClause is an empty string"); |
---|
96 | } |
---|
97 | this.scanClause = scanClause; |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | /** |
---|
102 | * Get the value of the <em>responsePosition</em> argument for this request. |
---|
103 | * |
---|
104 | * @return the value for the <em>responsePosition</em> argument |
---|
105 | */ |
---|
106 | public int getResponsePosition() { |
---|
107 | return responsePosition; |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | /** |
---|
112 | * Set the value of the <em>responsePosition</em> argument for this request. |
---|
113 | * |
---|
114 | * @param responsePosition |
---|
115 | * the value for the <em>responsePosition</em> argument |
---|
116 | * @throws IllegalArgumentException |
---|
117 | * if any argument is invalid |
---|
118 | */ |
---|
119 | public void setResponsePosition(int responsePosition) { |
---|
120 | if (responsePosition < 0) { |
---|
121 | throw new IllegalArgumentException("responsePosition < 0"); |
---|
122 | } |
---|
123 | this.responsePosition = responsePosition; |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | /** |
---|
128 | * Get the value of the <em>maximumTerms</em> argument for this request. |
---|
129 | * |
---|
130 | * @return the value for the <em>maximumTerms</em> argument |
---|
131 | */ |
---|
132 | public int getMaximumTerms() { |
---|
133 | return maximumTerms; |
---|
134 | } |
---|
135 | |
---|
136 | |
---|
137 | /** |
---|
138 | * Set the value of the <em>maximumTerms</em> argument for this request. |
---|
139 | * |
---|
140 | * @param maximumTerms |
---|
141 | * the value for the <em>maximumTerms</em> argument |
---|
142 | * @throws IllegalArgumentException |
---|
143 | * if any argument is invalid |
---|
144 | */ |
---|
145 | public void setMaximumTerms(int maximumTerms) { |
---|
146 | if (maximumTerms < 0) { |
---|
147 | throw new IllegalArgumentException("maximumTerms < 0"); |
---|
148 | } |
---|
149 | this.maximumTerms = maximumTerms; |
---|
150 | } |
---|
151 | |
---|
152 | |
---|
153 | @Override |
---|
154 | SRUOperation getOperation() { |
---|
155 | return SRUOperation.SCAN; |
---|
156 | } |
---|
157 | |
---|
158 | |
---|
159 | @Override |
---|
160 | void addParametersToURI(URIHelper uriHelper, SRUVersion version) |
---|
161 | throws SRUClientException { |
---|
162 | // scanClause |
---|
163 | final String malformedScan = |
---|
164 | getExtraRequestData(X_MALFORMED_SCAN_CLAUSE); |
---|
165 | if (malformedScan == null) { |
---|
166 | if ((scanClause == null) || scanClause.isEmpty()) { |
---|
167 | throw new SRUClientException( |
---|
168 | "mandatory argument 'scanClause' not set or empty"); |
---|
169 | } |
---|
170 | uriHelper.append(PARAM_SCAN_CLAUSE, scanClause); |
---|
171 | } else { |
---|
172 | if (!malformedScan.equalsIgnoreCase(MALFORMED_OMIT)) { |
---|
173 | uriHelper.append(PARAM_VERSION, malformedScan); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | // responsePosition |
---|
178 | final String malformedResponsePosition = |
---|
179 | getExtraRequestData(X_MALFORMED_RESPONSE_POSITION); |
---|
180 | if (malformedResponsePosition == null) { |
---|
181 | if (responsePosition > -1) { |
---|
182 | uriHelper.append(PARAM_RESPONSE_POSITION, responsePosition); |
---|
183 | } |
---|
184 | } else { |
---|
185 | if (!malformedResponsePosition.equalsIgnoreCase(MALFORMED_OMIT)) { |
---|
186 | uriHelper.append(PARAM_RESPONSE_POSITION, |
---|
187 | malformedResponsePosition); |
---|
188 | } |
---|
189 | } |
---|
190 | |
---|
191 | // maximumTerms |
---|
192 | final String malformedMaximumTerms = |
---|
193 | getExtraRequestData(X_MALFORMED_MAXIMUM_TERMS); |
---|
194 | if (malformedMaximumTerms == null) { |
---|
195 | if (maximumTerms > -1) { |
---|
196 | uriHelper.append(PARAM_MAXIMUM_TERMS, maximumTerms); |
---|
197 | } |
---|
198 | } else { |
---|
199 | if (!malformedMaximumTerms.equalsIgnoreCase(MALFORMED_OMIT)) { |
---|
200 | uriHelper.append(PARAM_MAXIMUM_TERMS, malformedMaximumTerms); |
---|
201 | } |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | } // class SRUScanRequest |
---|