source: SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUScanRequest.java @ 2959

Last change on this file since 2959 was 2959, checked in by oschonef, 11 years ago
  • add constructor for SRU*Request that accepts an URI object
  • Property svn:eol-style set to native
File size: 6.2 KB
Line 
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 */
17package eu.clarin.sru.client;
18
19import 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 */
32public 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) throws SRUClientException {
161        // scanClause
162        final String malformedScan =
163                getExtraRequestData(X_MALFORMED_SCAN_CLAUSE);
164        if (malformedScan == null) {
165            if ((scanClause == null) || scanClause.isEmpty()) {
166                throw new SRUClientException(
167                        "mandatory argument 'scanClause' not set or empty");
168            }
169            uriHelper.append(PARAM_SCAN_CLAUSE, scanClause);
170        } else {
171            if (!malformedScan.equalsIgnoreCase(MALFORMED_OMIT)) {
172                uriHelper.append(PARAM_VERSION, malformedScan);
173            }
174        }
175
176        // responsePosition
177        final String malformedResponsePosition =
178                getExtraRequestData(X_MALFORMED_RESPONSE_POSITION);
179        if (malformedResponsePosition == null) {
180            if (responsePosition > -1) {
181                uriHelper.append(PARAM_RESPONSE_POSITION, responsePosition);
182            }
183        } else {
184            if (!malformedResponsePosition.equalsIgnoreCase(MALFORMED_OMIT)) {
185                uriHelper.append(PARAM_RESPONSE_POSITION,
186                        malformedResponsePosition);
187            }
188        }
189
190        // maximumTerms
191        final String malformedMaximumTerms =
192                getExtraRequestData(X_MALFORMED_MAXIMUM_TERMS);
193        if (malformedMaximumTerms == null) {
194            if (maximumTerms > -1) {
195                uriHelper.append(PARAM_MAXIMUM_TERMS, maximumTerms);
196            }
197        } else {
198            if (!malformedMaximumTerms.equalsIgnoreCase(MALFORMED_OMIT)) {
199                uriHelper.append(PARAM_MAXIMUM_TERMS, malformedMaximumTerms);
200            }
201        }
202    }
203
204} // class SRUScanRequest
Note: See TracBrowser for help on using the repository browser.