- Timestamp:
- 01/12/16 21:03:47 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSearchRetrieveRequest.java
r5750 r6903 43 43 "x-malformed-maximumRecords"; 44 44 /** for end-point conformance testing only. never use in production. */ 45 public static final String X_MALFORMED_RECORD_ PACKING =45 public static final String X_MALFORMED_RECORD_XML_ESCAPING = 46 46 "x-malformed-recordPacking"; 47 private String queryType; 47 48 private String query; 48 49 private int startRecord = -1; 49 50 private int maximumRecords = -1; 51 private SRURecordXmlEscaping recordXmlEscaping; 50 52 private SRURecordPacking recordPacking; 51 53 private String recordSchema; … … 72 74 public SRUSearchRetrieveRequest(String baseURI) { 73 75 super(baseURI); 76 } 77 78 79 /** 80 * (SRU 2.0) Get the value of the <em>queryType</em> argument for this 81 * request. 82 * 83 * @return the value for the <em>queryType</em> argument or 84 * <code>null</code> of none was set 85 */ 86 public String getQueryType() { 87 return queryType; 88 } 89 90 91 /** 92 * (SRU 2.0) Set the value of the <em>queryType</em> argument for this 93 * request. 94 * 95 * @param queryType 96 * the value for the <em>queryType</em> argument 97 * @throws NullPointerException 98 * if any required argument is <code>null</code> 99 * @throws IllegalArgumentException 100 * if any argument is invalid 101 */ 102 public void setQueryType(String queryType) { 103 if (queryType == null) { 104 throw new NullPointerException("queryType == null"); 105 } 106 if (queryType.isEmpty()) { 107 throw new IllegalArgumentException("queryType is an empty string"); 108 } 109 for (int i = 0; i < queryType.length(); i++) { 110 final char ch = queryType.charAt(i); 111 if (!((ch >= 'a' && ch <= 'z') || 112 (ch >= 'A' && ch <= 'Z') || 113 (ch >= '0' && ch <= '9') || 114 ((i > 0) && ((ch == '-') || ch == '_')))) { 115 throw new IllegalArgumentException( 116 "queryType contains illegal characters"); 117 } 118 } 119 this.queryType = queryType; 74 120 } 75 121 … … 188 234 189 235 /** 190 * Get the value of the <em>recordSchema</em> argument for this request. 191 * 192 * @return the value for the <em>recordSchema</em> argument or 193 * <code>null</code> of none was set 236 * Get the <em>recordXmlEscpaing</em> (SRU 2.0) or <em>recordPacking</em> 237 * (SRU 1.1 and SRU 1.2) parameter of this request. 238 * 239 * @return the requested record XML escaping 240 * @see SRURecordXmlEscaping 241 */ 242 public SRURecordXmlEscaping getRecordXmlEscaping() { 243 return recordXmlEscaping; 244 } 245 246 247 /** 248 * Set the <em>recordXmlEscpaing</em> (SRU 2.0) or <em>recordPacking</em> 249 * (SRU 1.1 and SRU 1.2) parameter of this request. 250 * 251 * @param recordXmlEscaping 252 * the requested record XML escaping 253 * @see SRURecordXmlEscaping 254 */ 255 public void setRecordXmlEscaping(SRURecordXmlEscaping recordXmlEscaping) { 256 if (recordXmlEscaping == null) { 257 throw new NullPointerException("recordXmlEscaping == null"); 258 } 259 this.recordXmlEscaping = recordXmlEscaping; 260 } 261 262 263 /** 264 * Get the <em>recordPacking</em> (SRU 2.0) parameter of this request. 265 * 266 * @return the requested record packing 267 * @see SRURecordPacking 194 268 */ 195 269 public SRURecordPacking getRecordPacking() { … … 199 273 200 274 /** 201 * Set the value of the <em>recordPacking</em> argument for this request. 202 * 203 * @param recordPacking 204 * the value for the <em>recordPacking</em> argument 205 * @throws NullPointerException 206 * if any required argument is <code>null</code> 275 * Set the <em>recordPacking</em> (SRU 2.0) parameter of this request. 276 * 277 * @param getRecordXmlEscaping 278 * the requested record XML escaping 279 * @see SRURecordXmlEscaping 207 280 */ 208 281 public void setRecordPacking(SRURecordPacking recordPacking) { … … 245 318 246 319 @Override 247 void addParametersToURI(URIHelper uriHelper) throws SRUClientException { 320 void addParametersToURI(URIHelper uriHelper, SRUVersion version) 321 throws SRUClientException { 248 322 /* 249 323 * append query argument (mandatory) … … 268 342 269 343 /* 344 * append queryType parameter (SRU 2.0, optional) 345 */ 346 if ((version == SRUVersion.VERSION_2_0) && (queryType != null)) { 347 if (!SRUClientConstants.QUERY_TYPE_CQL.equals(queryType)) { 348 uriHelper.append(PARAM_QUERY_TYPE, queryType); 349 } 350 } 351 352 /* 270 353 * append startRecord argument (optional) 271 354 * … … 309 392 310 393 /* 311 * append record Packing argument (optional)394 * append record XML escaping argument (optional) 312 395 * 313 396 * NB: Setting "x-malformed-recordPacking" as an extra request … … 316 399 * (i.e. provoke an error) and SHOULD NEVER be used in production! 317 400 */ 318 final String malformedRecord Packing =319 getExtraRequestData(X_MALFORMED_RECORD_ PACKING);320 if (malformedRecord Packing == null) {321 if (record Packing != null) {322 switch (record Packing) {401 final String malformedRecordXmlEscaping = 402 getExtraRequestData(X_MALFORMED_RECORD_XML_ESCAPING); 403 if (malformedRecordXmlEscaping == null) { 404 if (recordXmlEscaping != null) { 405 switch (recordXmlEscaping) { 323 406 case XML: 324 uriHelper.append(PARAM_RECORD_PACKING, RECORD_PACKING_XML); 407 if (version == SRUVersion.VERSION_2_0) { 408 uriHelper.append(PARAM_RECORD_XML_ESCAPING, 409 RECORD_XML_ESCAPING_XML); 410 } else { 411 uriHelper.append(PARAM_RECORD_PACKING, 412 RECORD_XML_ESCAPING_XML); 413 } 325 414 break; 326 415 case STRING: 327 uriHelper.append(PARAM_RECORD_PACKING, 328 RECORD_PACKING_STRING); 416 if (version == SRUVersion.VERSION_2_0) { 417 uriHelper.append(PARAM_RECORD_XML_ESCAPING, 418 RECORD_XML_ESCPAING_STRING); 419 } else { 420 uriHelper.append(PARAM_RECORD_PACKING, 421 RECORD_XML_ESCPAING_STRING); 422 } 329 423 break; 330 424 default: 331 425 throw new SRUClientException( 332 "unsupported record packing: " + recordPacking);426 "unsupported record XML escpaing: " + recordXmlEscaping); 333 427 } // switch 334 428 } 335 429 } else { 336 if (!malformedRecordPacking.equalsIgnoreCase(MALFORMED_OMIT)) { 337 uriHelper.append(PARAM_RECORD_PACKING, malformedRecordPacking); 338 } 430 if (!malformedRecordXmlEscaping.equalsIgnoreCase(MALFORMED_OMIT)) { 431 if (version == SRUVersion.VERSION_2_0) { 432 uriHelper.append(PARAM_RECORD_XML_ESCAPING, 433 malformedRecordXmlEscaping); 434 } else { 435 uriHelper.append(PARAM_RECORD_PACKING, 436 malformedRecordXmlEscaping); 437 } 438 } 439 } 440 441 /* 442 * (SRU 2.0) append recordPacking argument (optional) 443 */ 444 if ((version == SRUVersion.VERSION_2_0) && (recordPacking != null)) { 445 String s = null; 446 switch (recordPacking) { 447 case PACKED: 448 s = "packed"; 449 break; 450 case UNPACKED: 451 s = "unpacked"; 452 break; 453 } 454 uriHelper.append(PARAM_RECORD_PACKING, s); 339 455 } 340 456
Note: See TracChangeset
for help on using the changeset viewer.