- Timestamp:
- 11/09/15 18:01:20 (9 years ago)
- Location:
- SRUServer/trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUServer/trunk/pom.xml
r6110 r6779 17 17 <maven.compiler.target>1.6</maven.compiler.target> 18 18 <!-- dependency versions --> 19 <slf4j.version>1. 6.4</slf4j.version>19 <slf4j.version>1.7.12</slf4j.version> 20 20 </properties> 21 21 -
SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRURequestImpl.java
r5924 r6779 25 25 import javax.servlet.http.HttpServletRequest; 26 26 27 import org.slf4j.Logger; 28 import org.slf4j.LoggerFactory; 27 29 import org.z3950.zing.cql.CQLNode; 28 30 import org.z3950.zing.cql.CQLParseException; … … 31 33 32 34 final class SRURequestImpl implements SRURequest, SRUDiagnosticList { 35 private static final Logger logger = 36 LoggerFactory.getLogger(SRURequest.class); 33 37 private static final String PARAM_OPERATION = "operation"; 34 38 private static final String PARAM_VERSION = "version"; … … 195 199 196 200 201 /** 202 * Validate incoming request parameters. 203 * 204 * @return <code>true</code> if successful, <code>false</code> if something 205 * went wrong 206 */ 197 207 boolean checkParameters() { 198 // parse mandatory operation parameter 199 final String op = getParameter(PARAM_OPERATION, false, false); 200 if (op != null) { 201 if (!op.isEmpty()) { 202 if (op.equals(OP_EXPLAIN)) { 203 this.operation = SRUOperation.EXPLAIN; 204 } else if (op.equals(OP_SCAN)) { 205 this.operation = SRUOperation.SCAN; 206 } else if (op.equals(OP_SEARCH_RETRIEVE)) { 207 this.operation = SRUOperation.SEARCH_RETRIEVE; 208 /* 209 * FIXME: those parameters must be inject from "outside" (probably 210 * by the appropriate Servlet instance) 211 */ 212 final SRUVersion minVersion = config.getMinVersion(); 213 final SRUVersion maxVersion = config.getMaxVersion(); 214 215 /* 216 * Heuristic to detect SRU version and operation ... 217 */ 218 SRUOperation operation = null; 219 SRUVersion version = null; 220 if (maxVersion.compareTo(SRUVersion.VERSION_2_0) >= 0) { 221 if (getParameter(PARAM_VERSION, false, false) == null) { 222 logger.debug("handling request as SRU 2.0, because no '{}' " + 223 "parameter was found in the request", PARAM_VERSION); 224 if (getParameter(PARAM_QUERY, false, false) != null) { 225 logger.debug("found parameter '{}' therefore " + 226 "assuming '{}' operation", 227 PARAM_QUERY, SRUOperation.SEARCH_RETRIEVE); 228 operation = SRUOperation.SEARCH_RETRIEVE; 229 } else if (getParameter(PARAM_SCAN_CLAUSE, false, false) != null) { 230 logger.debug("found parameter '{}' therefore " + 231 "assuming '{}' operation", 232 PARAM_SCAN_CLAUSE, SRUOperation.SCAN); 233 operation = SRUOperation.SCAN; 208 234 } else { 209 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_OPERATION, null, 210 "Operation \"" + op + "\" is not supported."); 235 logger.debug("no special parameter found therefore " + 236 "assuming '{}' operation", 237 SRUOperation.EXPLAIN); 238 operation = SRUOperation.EXPLAIN; 239 } 240 241 /* record version ... */ 242 version = SRUVersion.VERSION_2_0; 243 244 /* do pedantic check for 'operation' parameter */ 245 final String op = getParameter(PARAM_OPERATION, false, false); 246 if (op != null) { 247 /* 248 * XXX: if operation is searchRetrive an operation parameter, 249 * is also searchRetrieve, the server may ignore it 250 */ 251 if (!(operation == SRUOperation.SEARCH_RETRIEVE) && 252 op.equals(OP_SEARCH_RETRIEVE)) { 253 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_PARAMETER, 254 PARAM_OPERATION, "Parameter '" + 255 PARAM_OPERATION + 256 "' is not valid for SRU version 2.0"); 257 } 211 258 } 212 259 } else { 213 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_OPERATION, null, 214 "An empty parameter \"" + PARAM_OPERATION + 215 "\" is not supported."); 216 } 217 218 // parse and check version 219 parseAndCheckVersionParameter(); 220 } else { 221 /* 222 * absent parameter should be interpreted as "explain" 223 */ 224 this.operation = SRUOperation.EXPLAIN; 225 226 // parse and check version 227 parseAndCheckVersionParameter(); 228 } 260 logger.debug("handling request as legacy SRU, because found " + 261 "parameter '{}' in request", PARAM_VERSION); 262 263 // parse mandatory operation parameter 264 final String op = getParameter(PARAM_OPERATION, false, false); 265 if (op != null) { 266 if (!op.isEmpty()) { 267 if (op.equals(OP_EXPLAIN)) { 268 this.operation = SRUOperation.EXPLAIN; 269 } else if (op.equals(OP_SCAN)) { 270 this.operation = SRUOperation.SCAN; 271 } else if (op.equals(OP_SEARCH_RETRIEVE)) { 272 this.operation = SRUOperation.SEARCH_RETRIEVE; 273 } else { 274 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_OPERATION, 275 null, "Operation \"" + op + "\" is not supported."); 276 } 277 } else { 278 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_OPERATION, 279 null, "An empty parameter \"" + 280 PARAM_OPERATION + 281 "\" is not supported."); 282 } 283 284 // parse and check version 285 version = parseAndCheckVersionParameter(operation); 286 } else { 287 /* 288 * absent parameter should be interpreted as "explain" 289 */ 290 operation = SRUOperation.EXPLAIN; 291 292 // parse and check version 293 version = parseAndCheckVersionParameter(operation); 294 } 295 } 296 } 297 298 if ((version == null) || (operation == null)) { 299 logger.error("internal error!!!!1elf"); 300 } 301 302 if (minVersion.compareTo(version) < 0) { 303 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_VERSION, 304 version.getVersionString(), "Version '{}' is not supported by this endpoint"); 305 } 306 return checkParameters2(); 307 } 308 309 310 boolean checkParameters2() { 229 311 230 312 if (diagnostics == null) { … … 664 746 665 747 666 private void parseAndCheckVersionParameter() {748 private SRUVersion parseAndCheckVersionParameter(SRUOperation operation) { 667 749 final String v = getParameter(PARAM_VERSION, true, true); 668 750 if (v != null) { 751 SRUVersion version = null; 669 752 if (v.equals(VERSION_1_1)) { 670 this.version = SRUVersion.VERSION_1_1;753 version = SRUVersion.VERSION_1_1; 671 754 } else if (v.equals(VERSION_1_2)) { 672 this.version = SRUVersion.VERSION_1_2;755 version = SRUVersion.VERSION_1_2; 673 756 } else { 674 757 addDiagnostic(SRUConstants.SRU_UNSUPPORTED_VERSION, … … 676 759 "\" is not supported"); 677 760 } 761 return version; 678 762 } else { 679 763 /* … … 681 765 * parameter was not supplied. 682 766 */ 683 if ( this.operation != SRUOperation.EXPLAIN) {767 if (operation != SRUOperation.EXPLAIN) { 684 768 addDiagnostic( 685 769 SRUConstants.SRU_MANDATORY_PARAMETER_NOT_SUPPLIED, … … 691 775 * this is an explain operation, assume default version 692 776 */ 693 this.version =config.getDefaultVersion();777 return config.getDefaultVersion(); 694 778 } 695 779 } … … 730 814 break; 731 815 case VERSION_1_2: 816 /* FALL-THROUGH */ 817 case VERSION_2_0: 732 818 compat = CQLParser.V1POINT2; 733 819 } -
SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUServer.java
r5924 r6779 51 51 */ 52 52 public final class SRUServer { 53 private static final String SRU_NS =54 "http://www.loc.gov/zing/srw/";55 private static final String SRU_PREFIX = "sru";56 private static final String SRU_DIAGNOSIC_NS =57 "http://www.loc.gov/zing/srw/diagnostic/";58 private static final String SRU_DIAGNOSTIC_PREFIX = "diag";59 53 private static final String SRU_DIAGNOSTIC_RECORD_SCHEMA = 60 54 "info:srw/schema/1/diagnostics-v1.1"; 61 private static final String SRU_EXPLAIN_NS =62 "http://explain.z3950.org/dtd/2.0/";63 private static final String SRU_EXPLAIN_PREFIX = "zr";64 private static final String SRU_XCQL_NS =65 "http://www.loc.gov/zing/cql/xcql/";66 55 static final String RESPONSE_ENCODING = "utf-8"; 67 56 private static final String RESPONSE_CONTENT_TYPE = "application/xml"; … … 136 125 SRURecordPacking.XML, false, 137 126 req.getIndentResponse()); 138 writeFatalError(out, req, req.getDiagnostics()); 127 final SRUNamespaces ns = getNamespaces(req.getVersion()); 128 writeFatalError(out, ns, req, req.getDiagnostics()); 139 129 } 140 130 } catch (XMLStreamException e) { … … 176 166 SRURecordPacking.XML, false, 177 167 req.getIndentResponse()); 178 writeFatalError(out, req, diagnostics); 168 final SRUNamespaces ns = getNamespaces(req.getVersion()); 169 writeFatalError(out, ns, req, diagnostics); 179 170 } catch (Exception ex) { 180 171 logger.error("An exception occurred while in error state", … … 205 196 206 197 try { 198 final SRUNamespaces ns = getNamespaces(request.getVersion()); 199 207 200 // send results 208 201 SRUXMLStreamWriter out = … … 212 205 request.getIndentResponse()); 213 206 214 beginResponse(out, request);207 beginResponse(out, ns, request); 215 208 216 209 // write the explain record 217 writeExplainRecord(out, request);210 writeExplainRecord(out, ns, request); 218 211 219 212 if (config.getEchoRequests()) { 220 writeEchoedExplainRequest(out, request);213 writeEchoedExplainRequest(out, ns, request); 221 214 } 222 215 223 216 // diagnostics 224 writeDiagnosticList(out, request.getDiagnostics());217 writeDiagnosticList(out, ns, request.getDiagnostics()); 225 218 226 219 // extraResponseData 227 220 if (result != null) { 228 221 if (result.hasExtraResponseData()) { 229 out.writeStartElement( SRU_NS, "extraResponseData");222 out.writeStartElement(ns.getResponseNS(), "extraResponseData"); 230 223 result.writeExtraResponseData(out); 231 224 out.writeEndElement(); // "extraResponseData" element … … 256 249 257 250 try { 251 final SRUNamespaces ns = getNamespaces(request.getVersion()); 252 253 /* 254 * FIXME: re-check, if while scan response needs to be put 255 * in scan namespace for SRU 2.0! 256 */ 258 257 // send results 259 258 SRUXMLStreamWriter out = … … 263 262 request.getIndentResponse()); 264 263 265 beginResponse(out, request);264 beginResponse(out, ns, request); 266 265 267 266 try { … … 274 273 while (result.nextTerm()) { 275 274 if (!wroteTerms) { 276 out.writeStartElement(SRU_NS, "terms"); 275 final boolean needNsDecl = 276 !ns.getResponseNS().equals(ns.getScanNS()); 277 if (needNsDecl) { 278 out.setPrefix(ns.getScanPrefix(), ns.getScanNS()); 279 } 280 out.writeStartElement(ns.getScanNS(), "terms"); 281 if (needNsDecl) { 282 out.writeNamespace(ns.getScanPrefix(), 283 ns.getScanNS()); 284 } 277 285 wroteTerms = true; 278 286 } 279 out.writeStartElement( SRU_NS, "term");280 281 out.writeStartElement( SRU_NS, "value");287 out.writeStartElement(ns.getScanNS(), "term"); 288 289 out.writeStartElement(ns.getScanNS(), "value"); 282 290 out.writeCharacters(result.getValue()); 283 291 out.writeEndElement(); // "value" element 284 292 285 293 if (result.getNumberOfRecords() > -1) { 286 out.writeStartElement( SRU_NS, "numberOfRecords");294 out.writeStartElement(ns.getScanNS(), "numberOfRecords"); 287 295 out.writeCharacters( 288 296 Integer.toString(result.getNumberOfRecords())); … … 291 299 292 300 if (result.getDisplayTerm() != null) { 293 out.writeStartElement( SRU_NS, "displayTerm");301 out.writeStartElement(ns.getScanNS(), "displayTerm"); 294 302 out.writeCharacters(result.getDisplayTerm()); 295 303 out.writeEndElement(); // "displayTerm" element … … 297 305 298 306 if (result.getWhereInList() != null) { 299 out.writeStartElement( SRU_NS, "whereInList");307 out.writeStartElement(ns.getScanNS(), "whereInList"); 300 308 switch (result.getWhereInList()) { 301 309 case FIRST: … … 316 324 317 325 if (result.hasExtraTermData()) { 318 out.writeStartElement( SRU_NS, "extraTermData");326 out.writeStartElement(ns.getScanNS(), "extraTermData"); 319 327 result.writeExtraTermData(out); 320 328 out.writeEndElement(); // "extraTermData" element … … 334 342 // echoedScanRequest 335 343 if (config.getEchoRequests()) { 336 writeEchoedScanRequest(out, request, request.getScanClause());344 writeEchoedScanRequest(out, ns, request, request.getScanClause()); 337 345 } 338 346 339 347 // diagnostics 340 writeDiagnosticList(out, request.getDiagnostics());348 writeDiagnosticList(out, ns, request.getDiagnostics()); 341 349 342 350 // extraResponseData 343 351 if (result.hasExtraResponseData()) { 344 out.writeStartElement( SRU_NS, "extraResponseData");352 out.writeStartElement(ns.getResponseNS(), "extraResponseData"); 345 353 result.writeExtraResponseData(out); 346 354 out.writeEndElement(); // "extraResponseData" element … … 381 389 382 390 try { 391 final SRUNamespaces ns = getNamespaces(request.getVersion()); 392 383 393 // send results 384 394 SRUXMLStreamWriter out = … … 388 398 request.getIndentResponse()); 389 399 390 beginResponse(out, request);400 beginResponse(out, ns, request); 391 401 392 402 // numberOfRecords 393 out.writeStartElement( SRU_NS, "numberOfRecords");403 out.writeStartElement(ns.getResponseNS(), "numberOfRecords"); 394 404 out.writeCharacters( 395 405 Integer.toString(result.getTotalRecordCount())); … … 398 408 // resultSetId 399 409 if (result.getResultSetId() != null) { 400 out.writeStartElement( SRU_NS, "resultSetId");410 out.writeStartElement(ns.getResponseNS(), "resultSetId"); 401 411 out.writeCharacters(result.getResultSetId()); 402 412 out.writeEndElement(); // "resultSetId" element … … 405 415 // resultSetIdleTime 406 416 if (result.getResultSetIdleTime() > 0) { 407 out.writeStartElement( SRU_NS, "resultSetIdleTime");417 out.writeStartElement(ns.getResponseNS(), "resultSetIdleTime"); 408 418 out.writeCharacters(Integer.toString(result 409 419 .getResultSetIdleTime())); … … 419 429 : -1; 420 430 try { 421 out.writeStartElement( SRU_NS, "records");431 out.writeStartElement(ns.getResponseNS(), "records"); 422 432 while (result.nextRecord()) { 423 433 /* … … 435 445 } 436 446 437 out.writeStartElement( SRU_NS, "record");447 out.writeStartElement(ns.getResponseNS(), "record"); 438 448 439 449 /* … … 445 455 result.getSurrogateDiagnostic(); 446 456 447 out.writeStartElement( SRU_NS, "recordSchema");457 out.writeStartElement(ns.getResponseNS(), "recordSchema"); 448 458 if (diagnostic == null) { 449 459 out.writeCharacters( … … 455 465 456 466 // recordPacking 457 writeRecordPacking(out, request.getRecordPacking());467 writeRecordPacking(out, ns, request.getRecordPacking()); 458 468 459 469 /* 460 470 * Output either record data or surrogate diagnostic ... 461 471 */ 462 out.writeStartElement( SRU_NS, "recordData");472 out.writeStartElement(ns.getResponseNS(), "recordData"); 463 473 out.startRecord(); 464 474 if (diagnostic == null) { … … 466 476 } else { 467 477 // write a surrogate diagnostic 468 writeDiagnostic(out, diagnostic, true);478 writeDiagnostic(out, ns, diagnostic, true); 469 479 } 470 480 out.endRecord(); … … 478 488 result.getRecordIdentifier(); 479 489 if (identifier != null) { 480 out.writeStartElement( SRU_NS,490 out.writeStartElement(ns.getResponseNS(), 481 491 "recordIdentifier"); 482 492 out.writeCharacters(identifier); … … 485 495 } 486 496 487 out.writeStartElement(SRU_NS, "recordPosition"); 497 out.writeStartElement(ns.getResponseNS(), 498 "recordPosition"); 488 499 out.writeCharacters(Integer.toString(position)); 489 500 out.writeEndElement(); // "recordPosition" element 490 501 491 502 if (result.hasExtraRecordData()) { 492 out.writeStartElement(SRU_NS, "extraRecordData"); 503 out.writeStartElement(ns.getResponseNS(), 504 "extraRecordData"); 493 505 result.writeExtraRecordData(out); 494 506 out.writeEndElement(); // "extraRecordData" … … 510 522 // nextRecordPosition 511 523 if (position <= result.getTotalRecordCount()) { 512 out.writeStartElement( SRU_NS, "nextRecordPosition");524 out.writeStartElement(ns.getResponseNS(), "nextRecordPosition"); 513 525 out.writeCharacters(Integer.toString(position)); 514 526 out.writeEndElement(); … … 517 529 // echoedSearchRetrieveRequest 518 530 if (config.getEchoRequests()) { 519 writeEchoedSearchRetrieveRequest(out, request,531 writeEchoedSearchRetrieveRequest(out, ns, request, 520 532 request.getQuery()); 521 533 } 522 534 523 535 // diagnostics 524 writeDiagnosticList(out, request.getDiagnostics());536 writeDiagnosticList(out, ns, request.getDiagnostics()); 525 537 526 538 // extraResponseData 527 539 if (result.hasExtraResponseData()) { 528 out.writeStartElement( SRU_NS, "extraResponseData");540 out.writeStartElement(ns.getResponseNS(), "extraResponseData"); 529 541 result.writeExtraResponseData(out); 530 542 out.writeEndElement(); // "extraResponseData" element … … 538 550 539 551 540 private void beginResponse(SRUXMLStreamWriter out, SRUOperation operation, 541 SRUVersion version, String stylesheet) throws XMLStreamException { 552 private void beginResponse(SRUXMLStreamWriter out, SRUNamespaces ns, 553 SRUOperation operation, SRUVersion version, String stylesheet) 554 throws XMLStreamException { 542 555 out.writeStartDocument("utf-8", "1.0"); 543 556 … … 552 565 } 553 566 554 out.setPrefix( SRU_PREFIX, SRU_NS);567 out.setPrefix(ns.getResponsePrefix(), ns.getResponseNS()); 555 568 switch (operation) { 556 569 case EXPLAIN: 557 out.writeStartElement( SRU_NS, "explainResponse");570 out.writeStartElement(ns.getResponseNS(), "explainResponse"); 558 571 break; 559 572 case SCAN: 560 out.writeStartElement( SRU_NS, "scanResponse");573 out.writeStartElement(ns.getResponseNS(), "scanResponse"); 561 574 break; 562 575 case SEARCH_RETRIEVE: 563 out.writeStartElement( SRU_NS, "searchRetrieveResponse");576 out.writeStartElement(ns.getResponseNS(), "searchRetrieveResponse"); 564 577 break; 565 578 } 566 out.writeNamespace( SRU_PREFIX, SRU_NS);579 out.writeNamespace(ns.getResponsePrefix(), ns.getResponseNS()); 567 580 568 581 // version 569 writeVersion(out, version);570 } 571 572 573 private void beginResponse(SRUXMLStreamWriter out, SRU Request request)574 throws XMLStreamException {575 beginResponse(out, request.getOperation(), request.getVersion(),582 writeVersion(out, ns, version); 583 } 584 585 586 private void beginResponse(SRUXMLStreamWriter out, SRUNamespaces ns, 587 SRURequest request) throws XMLStreamException { 588 beginResponse(out, ns, request.getOperation(), request.getVersion(), 576 589 request.getStylesheet()); 577 590 } … … 592 605 593 606 594 private void writeFatalError(SRUXMLStreamWriter out, 607 private void writeFatalError(SRUXMLStreamWriter out, SRUNamespaces ns, 595 608 SRURequestImpl request, List<SRUDiagnostic> diagnotics) 596 609 throws XMLStreamException { … … 609 622 * write a response which conforms to the schema 610 623 */ 611 beginResponse(out, operation, version, null);624 beginResponse(out, ns, operation, version, null); 612 625 switch (operation) { 613 626 case EXPLAIN: 614 627 // 'explain' requires a complete explain record ... 615 writeExplainRecord(out, request);628 writeExplainRecord(out, ns, request); 616 629 break; 617 630 case SCAN: … … 620 633 case SEARCH_RETRIEVE: 621 634 // 'searchRetrieve' needs numberOfRecords .. 622 out.writeStartElement( SRU_NS, "numberOfRecords");635 out.writeStartElement(ns.getResponseNS(), "numberOfRecords"); 623 636 out.writeCharacters("0"); 624 637 out.writeEndElement(); // "numberOfRecords" element 625 638 break; 626 639 } 627 writeDiagnosticList(out, diagnotics);640 writeDiagnosticList(out, ns, diagnotics); 628 641 endResponse(out); 629 642 } 630 643 631 644 632 private void writeDiagnosticList(SRUXMLStreamWriter out, 645 private void writeDiagnosticList(SRUXMLStreamWriter out, SRUNamespaces ns, 633 646 List<SRUDiagnostic> diagnostics) throws XMLStreamException { 634 647 if ((diagnostics != null) && !diagnostics.isEmpty()) { 635 out.setPrefix( SRU_DIAGNOSTIC_PREFIX, SRU_DIAGNOSIC_NS);636 out.writeStartElement( SRU_NS, "diagnostics");637 out.writeNamespace( SRU_DIAGNOSTIC_PREFIX, SRU_DIAGNOSIC_NS);648 out.setPrefix(ns.getDiagnosticPrefix(), ns.getDiagnosticNS()); 649 out.writeStartElement(ns.getDiagnosticNS(), "diagnostics"); 650 out.writeNamespace(ns.getDiagnosticPrefix(), ns.getDiagnosticNS()); 638 651 for (SRUDiagnostic diagnostic : diagnostics) { 639 writeDiagnostic(out, diagnostic, false);652 writeDiagnostic(out, ns, diagnostic, false); 640 653 } 641 654 out.writeEndElement(); // "diagnostics" element … … 644 657 645 658 646 private void writeExplainRecord(SRUXMLStreamWriter out, 659 private void writeExplainRecord(SRUXMLStreamWriter out, SRUNamespaces ns, 647 660 SRURequestImpl request) throws XMLStreamException { 648 out.writeStartElement( SRU_NS, "record");649 650 out.writeStartElement( SRU_NS, "recordSchema");651 out.writeCharacters( SRU_EXPLAIN_NS);661 out.writeStartElement(ns.getResponseNS(), "record"); 662 663 out.writeStartElement(ns.getResponseNS(), "recordSchema"); 664 out.writeCharacters(ns.getExplainNS()); 652 665 out.writeEndElement(); // "recordSchema" element 653 666 654 667 // recordPacking 655 writeRecordPacking(out, request.getRecordPacking());656 657 out.writeStartElement( SRU_NS, "recordData");668 writeRecordPacking(out, ns, request.getRecordPacking()); 669 670 out.writeStartElement(ns.getResponseNS(), "recordData"); 658 671 659 672 out.startRecord(); 660 673 661 674 // explain ... 662 out.setPrefix( SRU_EXPLAIN_PREFIX, SRU_EXPLAIN_NS);663 out.writeStartElement( SRU_EXPLAIN_NS, "explain");664 out.writeNamespace( SRU_EXPLAIN_PREFIX, SRU_EXPLAIN_NS);675 out.setPrefix(ns.getExplainPrefix(), ns.getExplainNS()); 676 out.writeStartElement(ns.getExplainNS(), "explain"); 677 out.writeNamespace(ns.getExplainPrefix(), ns.getExplainNS()); 665 678 666 679 // explain/serverInfo 667 out.writeStartElement( SRU_EXPLAIN_NS, "serverInfo");680 out.writeStartElement(ns.getExplainNS(), "serverInfo"); 668 681 out.writeAttribute("protocol", "SRU"); 669 682 switch (config.getDefaultVersion()) { … … 673 686 case VERSION_1_2: 674 687 out.writeAttribute("version", "1.2"); 688 break; 689 case VERSION_2_0: 690 out.writeAttribute("version", "2.0"); 691 break; 675 692 } // switch 676 693 out.writeAttribute("transport", config.getTransports()); 677 out.writeStartElement( SRU_EXPLAIN_NS, "host");694 out.writeStartElement(ns.getExplainNS(), "host"); 678 695 out.writeCharacters(config.getHost()); 679 696 out.writeEndElement(); // "host" element 680 out.writeStartElement( SRU_EXPLAIN_NS, "port");697 out.writeStartElement(ns.getExplainNS(), "port"); 681 698 out.writeCharacters(Integer.toString(config.getPort())); 682 699 out.writeEndElement(); // "port" element 683 out.writeStartElement( SRU_EXPLAIN_NS, "database");700 out.writeStartElement(ns.getExplainNS(), "database"); 684 701 out.writeCharacters(config.getDatabase()); 685 702 out.writeEndElement(); // "database" element … … 689 706 final DatabaseInfo dbinfo = config.getDatabaseInfo(); 690 707 if (dbinfo != null) { 691 out.writeStartElement(SRU_EXPLAIN_NS, "databaseInfo"); 692 writeLocalizedStrings(out, "title", dbinfo.getTitle()); 693 writeLocalizedStrings(out, "description", dbinfo.getDescription()); 694 writeLocalizedStrings(out, "author", dbinfo.getAuthor()); 695 writeLocalizedStrings(out, "extent", dbinfo.getExtend()); 696 writeLocalizedStrings(out, "history", dbinfo.getHistory()); 697 writeLocalizedStrings(out, "langUsage", dbinfo.getLangUsage()); 698 writeLocalizedStrings(out, "restrictions", dbinfo.getRestrictions()); 699 writeLocalizedStrings(out, "subjects", dbinfo.getSubjects()); 700 writeLocalizedStrings(out, "links", dbinfo.getLinks()); 701 writeLocalizedStrings(out, "implementation", 708 out.writeStartElement(ns.getExplainNS(), "databaseInfo"); 709 writeLocalizedStrings(out, ns, "title", 710 dbinfo.getTitle()); 711 writeLocalizedStrings(out, ns, "description", 712 dbinfo.getDescription()); 713 writeLocalizedStrings(out, ns, "author", 714 dbinfo.getAuthor()); 715 writeLocalizedStrings(out, ns, "extent", 716 dbinfo.getExtend()); 717 writeLocalizedStrings(out, ns, "history", 718 dbinfo.getHistory()); 719 writeLocalizedStrings(out, ns, "langUsage", 720 dbinfo.getLangUsage()); 721 writeLocalizedStrings(out, ns, "restrictions", 722 dbinfo.getRestrictions()); 723 writeLocalizedStrings(out, ns, "subjects", 724 dbinfo.getSubjects()); 725 writeLocalizedStrings(out, ns, "links", 726 dbinfo.getLinks()); 727 writeLocalizedStrings(out, ns, "implementation", 702 728 dbinfo.getImplementation()); 703 729 out.writeEndElement(); // "databaseInfo" element … … 707 733 final IndexInfo indexInfo = config.getIndexInfo(); 708 734 if (indexInfo != null) { 709 out.writeStartElement( SRU_EXPLAIN_NS, "indexInfo");735 out.writeStartElement(ns.getExplainNS(), "indexInfo"); 710 736 711 737 List<IndexInfo.Set> sets = indexInfo.getSets(); 712 738 if (sets != null) { 713 739 for (IndexInfo.Set set : sets) { 714 out.writeStartElement( SRU_EXPLAIN_NS, "set");740 out.writeStartElement(ns.getExplainNS(), "set"); 715 741 out.writeAttribute("identifier", set.getIdentifier()); 716 742 out.writeAttribute("name", set.getName()); 717 writeLocalizedStrings(out, "title", set.getTitle());743 writeLocalizedStrings(out, ns, "title", set.getTitle()); 718 744 out.writeEndElement(); // "set" element 719 745 } … … 723 749 if (indexes != null) { 724 750 for (IndexInfo.Index index : indexes) { 725 out.writeStartElement( SRU_EXPLAIN_NS, "index");751 out.writeStartElement(ns.getExplainNS(), "index"); 726 752 out.writeAttribute("search", 727 753 index.canSearch() ? "true" : "false"); … … 730 756 out.writeAttribute("sort", 731 757 index.canSort() ? "true" : "false"); 732 writeLocalizedStrings(out, "title", index.getTitle());758 writeLocalizedStrings(out, ns, "title", index.getTitle()); 733 759 List<IndexInfo.Index.Map> maps = index.getMaps(); 734 760 if (maps != null) { 735 761 for (IndexInfo.Index.Map map : maps) { 736 out.writeStartElement( SRU_EXPLAIN_NS, "map");762 out.writeStartElement(ns.getExplainNS(), "map"); 737 763 if (map.isPrimary()) { 738 764 out.writeAttribute("primary", "true"); 739 765 } 740 out.writeStartElement( SRU_EXPLAIN_NS, "name");766 out.writeStartElement(ns.getExplainNS(), "name"); 741 767 out.writeAttribute("set", map.getSet()); 742 768 out.writeCharacters(map.getName()); … … 755 781 config.getSchemaInfo(); 756 782 if (schemaInfo != null) { 757 out.writeStartElement( SRU_EXPLAIN_NS, "schemaInfo");783 out.writeStartElement(ns.getExplainNS(), "schemaInfo"); 758 784 for (SRUServerConfig.SchemaInfo schema : schemaInfo) { 759 out.writeStartElement( SRU_EXPLAIN_NS, "schema");785 out.writeStartElement(ns.getExplainNS(), "schema"); 760 786 out.writeAttribute("identifier", schema.getIdentifier()); 761 787 out.writeAttribute("name", schema.getName()); … … 772 798 out.writeAttribute("retrieve", "false"); 773 799 } 774 writeLocalizedStrings(out, "title", schema.getTitle());800 writeLocalizedStrings(out, ns, "title", schema.getTitle()); 775 801 out.writeEndElement(); // "schema" element 776 802 } … … 779 805 780 806 // explain/configInfo 781 out.writeStartElement( SRU_EXPLAIN_NS, "configInfo");807 out.writeStartElement(ns.getExplainNS(), "configInfo"); 782 808 // numberOfRecords (default) 783 out.writeStartElement( SRU_EXPLAIN_NS, "default");809 out.writeStartElement(ns.getExplainNS(), "default"); 784 810 out.writeAttribute("type", "numberOfRecords"); 785 811 out.writeCharacters(Integer.toString(config.getNumberOfRecords())); … … 787 813 788 814 // maximumRecords (setting) 789 out.writeStartElement( SRU_EXPLAIN_NS, "setting");815 out.writeStartElement(ns.getExplainNS(), "setting"); 790 816 out.writeAttribute("type", "maximumRecords"); 791 817 out.writeCharacters(Integer.toString(config.getMaximumRecords())); … … 803 829 804 830 805 private void writeDiagnostic(SRUXMLStreamWriter out, 831 private void writeDiagnostic(SRUXMLStreamWriter out, SRUNamespaces ns, 806 832 SRUDiagnostic diagnostic, boolean writeNsDecl) 807 833 throws XMLStreamException { 808 834 if (writeNsDecl) { 809 out.setPrefix( SRU_DIAGNOSTIC_PREFIX, SRU_DIAGNOSIC_NS);810 } 811 out.writeStartElement( SRU_DIAGNOSIC_NS, "diagnostic");835 out.setPrefix(ns.getDiagnosticPrefix(), ns.getDiagnosticNS()); 836 } 837 out.writeStartElement(ns.getDiagnosticNS(), "diagnostic"); 812 838 if (writeNsDecl) { 813 out.writeNamespace( SRU_DIAGNOSTIC_PREFIX, SRU_DIAGNOSIC_NS);814 } 815 out.writeStartElement( SRU_DIAGNOSIC_NS, "uri");839 out.writeNamespace(ns.getDiagnosticPrefix(), ns.getDiagnosticNS()); 840 } 841 out.writeStartElement(ns.getDiagnosticNS(), "uri"); 816 842 out.writeCharacters(diagnostic.getURI()); 817 843 out.writeEndElement(); // "uri" element 818 844 if (diagnostic.getDetails() != null) { 819 out.writeStartElement( SRU_DIAGNOSIC_NS, "details");845 out.writeStartElement(ns.getDiagnosticNS(), "details"); 820 846 out.writeCharacters(diagnostic.getDetails()); 821 847 out.writeEndElement(); // "details" element 822 848 } 823 849 if (diagnostic.getMessage() != null) { 824 out.writeStartElement( SRU_DIAGNOSIC_NS, "message");850 out.writeStartElement(ns.getDiagnosticNS(), "message"); 825 851 out.writeCharacters(diagnostic.getMessage()); 826 852 out.writeEndElement(); // "message" element … … 831 857 832 858 private void writeEchoedExplainRequest(SRUXMLStreamWriter out, 833 SRU RequestImpl request) throws XMLStreamException,834 SRUException {859 SRUNamespaces ns, SRURequestImpl request) 860 throws XMLStreamException, SRUException { 835 861 // echoedSearchRetrieveRequest 836 out.writeStartElement( SRU_NS, "echoedExplainRequest");862 out.writeStartElement(ns.getResponseNS(), "echoedExplainRequest"); 837 863 838 864 // echoedExplainRequest/version 839 865 if (request.getRawVersion() != null) { 840 writeVersion(out, request.getRawVersion());866 writeVersion(out, ns, request.getRawVersion()); 841 867 } 842 868 843 869 // echoedExplainRequest/recordPacking 844 870 if (request.getRawRecordPacking() != null) { 845 writeRecordPacking(out, request.getRawRecordPacking());871 writeRecordPacking(out, ns, request.getRawRecordPacking()); 846 872 } 847 873 848 874 // echoedExplainRequest/stylesheet 849 875 if (request.getStylesheet() != null) { 850 out.writeStartElement( SRU_NS, "stylesheet");876 out.writeStartElement(ns.getResponseNS(), "stylesheet"); 851 877 out.writeCharacters(request.getStylesheet()); 852 878 out.writeEndElement(); // "stylesheet" element … … 855 881 // echoedExplainRequest/baseUrl (SRU 1.2 only) 856 882 if (request.isVersion(SRUVersion.VERSION_1_2)) { 857 writeBaseUrl(out, request);883 writeBaseUrl(out, ns, request); 858 884 } 859 885 … … 863 889 864 890 private void writeEchoedScanRequest(SRUXMLStreamWriter out, 865 SRU RequestImpl request, CQLNode cql) throws XMLStreamException,866 SRUException {891 SRUNamespaces ns, SRURequestImpl request, CQLNode cql) 892 throws XMLStreamException, SRUException { 867 893 // echoedScanRequest 868 out.writeStartElement( SRU_NS, "echoedScanRequest");894 out.writeStartElement(ns.getResponseNS(), "echoedScanRequest"); 869 895 870 896 // echoedScanRequest/version 871 897 if (request.getRawVersion() != null) { 872 writeVersion(out, request.getRawVersion());898 writeVersion(out, ns, request.getRawVersion()); 873 899 } 874 900 875 901 // echoedScanRequest/scanClause 876 out.writeStartElement( SRU_NS, "scanClause");902 out.writeStartElement(ns.getResponseNS(), "scanClause"); 877 903 out.writeCharacters(request.getRawScanClause()); 878 904 out.writeEndElement(); // "query" 879 905 880 906 // echoedScanRequest/xScanClause 881 out.setDefaultNamespace( SRU_XCQL_NS);882 out.writeStartElement( SRU_NS, "xScanClause");883 out.writeDefaultNamespace( SRU_XCQL_NS);907 out.setDefaultNamespace(ns.getXcqlNS()); 908 out.writeStartElement(ns.getResponseNS(), "xScanClause"); 909 out.writeDefaultNamespace(ns.getXcqlNS()); 884 910 out.writeXCQL(cql, false); 885 911 out.writeEndElement(); // "xScanClause" element … … 887 913 // echoedScanRequest/responsePosition 888 914 if (request.getResponsePosition() != -1) { 889 out.writeStartElement( SRU_NS, "responsePosition");915 out.writeStartElement(ns.getResponseNS(), "responsePosition"); 890 916 out.writeCharacters( 891 917 Integer.toString(request.getResponsePosition())); … … 895 921 // echoedScanRequest/maximumTerms 896 922 if (request.getMaximumTerms() != -1) { 897 out.writeStartElement( SRU_NS, "maximumTerms");923 out.writeStartElement(ns.getResponseNS(), "maximumTerms"); 898 924 out.writeCharacters(Integer.toString(request.getMaximumTerms())); 899 925 out.writeEndElement(); // "maximumTerms" element … … 902 928 // echoedScanRequest/stylesheet 903 929 if (request.getStylesheet() != null) { 904 out.writeStartElement( SRU_NS, "stylesheet");930 out.writeStartElement(ns.getResponseNS(), "stylesheet"); 905 931 out.writeCharacters(request.getStylesheet()); 906 932 out.writeEndElement(); // "stylesheet" element … … 909 935 // echoedScanRequest/baseUrl (SRU 1.2 only) 910 936 if (request.isVersion(SRUVersion.VERSION_1_2)) { 911 writeBaseUrl(out, request);937 writeBaseUrl(out, ns, request); 912 938 } 913 939 … … 917 943 918 944 private void writeEchoedSearchRetrieveRequest(SRUXMLStreamWriter out, 919 SRU RequestImpl request, CQLNode cql) throws XMLStreamException,920 SRUException {945 SRUNamespaces ns, SRURequestImpl request, CQLNode cql) 946 throws XMLStreamException, SRUException { 921 947 // echoedSearchRetrieveRequest 922 out.writeStartElement(SRU_NS, "echoedSearchRetrieveRequest"); 948 out.writeStartElement(ns.getResponseNS(), 949 "echoedSearchRetrieveRequest"); 923 950 924 951 // echoedSearchRetrieveRequest/version 925 952 if (request.getRawVersion() != null) { 926 writeVersion(out, request.getRawVersion());953 writeVersion(out, ns, request.getRawVersion()); 927 954 } 928 955 929 956 // echoedSearchRetrieveRequest/query 930 out.writeStartElement( SRU_NS, "query");957 out.writeStartElement(ns.getResponseNS(), "query"); 931 958 out.writeCharacters(request.getRawQuery()); 932 959 out.writeEndElement(); // "query" 933 960 934 961 // echoedSearchRetrieveRequest/xQuery 935 out.setDefaultNamespace( SRU_XCQL_NS);936 out.writeStartElement( SRU_NS, "xQuery");937 out.writeDefaultNamespace( SRU_XCQL_NS);962 out.setDefaultNamespace(ns.getXcqlNS()); 963 out.writeStartElement(ns.getResponseNS(), "xQuery"); 964 out.writeDefaultNamespace(ns.getXcqlNS()); 938 965 out.writeXCQL(cql, true); 939 966 out.writeEndElement(); // "xQuery" element … … 941 968 // echoedSearchRetrieveRequest/startRecord 942 969 if (request.getStartRecord() > 0) { 943 out.writeStartElement( SRU_NS, "startRecord");970 out.writeStartElement(ns.getResponseNS(), "startRecord"); 944 971 out.writeCharacters(Integer.toString(request.getStartRecord())); 945 972 out.writeEndElement(); // "startRecord" element … … 948 975 // echoedSearchRetrieveRequest/maximumRecords 949 976 if (request.getRawMaximumRecords() > 0) { 950 out.writeStartElement( SRU_NS, "maximumRecords");977 out.writeStartElement(ns.getResponseNS(), "maximumRecords"); 951 978 out.writeCharacters( 952 979 Integer.toString(request.getRawMaximumRecords())); … … 956 983 // echoedSearchRetrieveRequest/recordPacking 957 984 if (request.getRawRecordPacking() != null) { 958 writeRecordPacking(out, request.getRawRecordPacking());985 writeRecordPacking(out, ns, request.getRawRecordPacking()); 959 986 } 960 987 961 988 // echoedSearchRetrieveRequest/recordSchema 962 989 if (request.getRawRecordSchemaIdentifier() != null) { 963 out.writeStartElement( SRU_NS, "recordSchema");990 out.writeStartElement(ns.getResponseNS(), "recordSchema"); 964 991 out.writeCharacters(request.getRawRecordSchemaIdentifier()); 965 992 out.writeEndElement(); // "recordSchema" element … … 969 996 if (request.isVersion(SRUVersion.VERSION_1_1) && 970 997 (request.getRecordXPath() != null)) { 971 out.writeStartElement( SRU_NS, "recordXPath");998 out.writeStartElement(ns.getResponseNS(), "recordXPath"); 972 999 out.writeCharacters(request.getRecordXPath()); 973 1000 out.writeEndElement(); // "recordXPath" element … … 976 1003 // echoedSearchRetrieveRequest/resultSetTTL 977 1004 if (request.getResultSetTTL() > 0) { 978 out.writeStartElement( SRU_NS, "resultSetTTL");1005 out.writeStartElement(ns.getResponseNS(), "resultSetTTL"); 979 1006 out.writeCharacters(Long.toString(request.getResultSetTTL())); 980 1007 out.writeEndElement(); // "resultSetTTL" element … … 984 1011 if (request.isVersion(SRUVersion.VERSION_1_1) && 985 1012 (request.getSortKeys() != null)) { 986 out.writeStartElement( SRU_NS, "sortKeys");1013 out.writeStartElement(ns.getResponseNS(), "sortKeys"); 987 1014 out.writeCharacters(request.getSortKeys()); 988 1015 out.writeEndElement(); // "sortKeys" element … … 993 1020 // echoedSearchRetrieveRequest/stylesheet 994 1021 if (request.getStylesheet() != null) { 995 out.writeStartElement( SRU_NS, "stylesheet");1022 out.writeStartElement(ns.getResponseNS(), "stylesheet"); 996 1023 out.writeCharacters(request.getStylesheet()); 997 1024 out.writeEndElement(); // "stylesheet" element … … 1000 1027 // echoedSearchRetrieveRequest/baseUrl (SRU 1.2 only) 1001 1028 if (request.isVersion(SRUVersion.VERSION_1_2)) { 1002 writeBaseUrl(out, request);1029 writeBaseUrl(out, ns, request); 1003 1030 } 1004 1031 … … 1007 1034 1008 1035 1009 private void writeVersion(SRUXMLStreamWriter out, SRU Version version)1010 throws XMLStreamException {1011 out.writeStartElement( SRU_NS, "version");1036 private void writeVersion(SRUXMLStreamWriter out, SRUNamespaces ns, 1037 SRUVersion version) throws XMLStreamException { 1038 out.writeStartElement(ns.getResponseNS(), "version"); 1012 1039 switch (version) { 1013 1040 case VERSION_1_1: … … 1017 1044 out.writeCharacters("1.2"); 1018 1045 break; 1046 case VERSION_2_0: 1047 out.writeCharacters("2.0"); 1048 break; 1019 1049 } // switch 1020 1050 out.writeEndElement(); // "version" element … … 1022 1052 1023 1053 1024 private void writeRecordPacking(SRUXMLStreamWriter out, 1054 private void writeRecordPacking(SRUXMLStreamWriter out, SRUNamespaces ns, 1025 1055 SRURecordPacking recordPacking) throws XMLStreamException { 1026 out.writeStartElement( SRU_NS, "recordPacking");1056 out.writeStartElement(ns.getResponseNS(), "recordPacking"); 1027 1057 switch (recordPacking) { 1028 1058 case XML: … … 1037 1067 1038 1068 1039 private void writeBaseUrl(SRUXMLStreamWriter out, 1069 private void writeBaseUrl(SRUXMLStreamWriter out, SRUNamespaces ns, 1040 1070 SRURequest request) throws XMLStreamException { 1041 out.writeStartElement( SRU_NS, "baseUrl");1071 out.writeStartElement(ns.getResponseNS(), "baseUrl"); 1042 1072 out.writeCharacters(request.getProtocolScheme()); 1043 1073 out.writeCharacters(config.getBaseUrl()); … … 1046 1076 1047 1077 1048 private void writeLocalizedStrings(XMLStreamWriter writer, String name, 1049 List<LocalizedString> list) throws XMLStreamException { 1078 private void writeLocalizedStrings(XMLStreamWriter writer, 1079 SRUNamespaces ns, String name, List<LocalizedString> list) 1080 throws XMLStreamException { 1050 1081 if ((list != null) && !list.isEmpty()) { 1051 1082 for (LocalizedString item : list) { 1052 writer.writeStartElement( SRU_EXPLAIN_NS, name);1083 writer.writeStartElement(ns.getExplainNS(), name); 1053 1084 if (item.getLang() != null) { 1054 1085 writer.writeAttribute("lang", item.getLang()); … … 1101 1132 } 1102 1133 1103 } // class SRUService 1134 1135 private SRUNamespaces getNamespaces(SRUVersion version) { 1136 if (version == null) { 1137 throw new NullPointerException("version == null"); 1138 } 1139 switch (version) { 1140 case VERSION_1_1: 1141 /* FALL-THROUGH */ 1142 case VERSION_1_2: 1143 return NAMESPACES_LEGACY; 1144 case VERSION_2_0: 1145 return NAMESPACES_2_0; 1146 default: 1147 // FIXME: better exception? 1148 throw new IllegalAccessError("invalid version: " + version); 1149 } 1150 } 1151 1152 1153 1154 1155 private static final SRUNamespaces NAMESPACES_LEGACY = new SRUNamespaces() { 1156 private static final String SRU_NS = 1157 "http://www.loc.gov/zing/srw/"; 1158 private static final String SRU_PREFIX = 1159 "sru"; 1160 private static final String SRU_DIAGNOSIC_NS = 1161 "http://www.loc.gov/zing/srw/diagnostic/"; 1162 private static final String SRU_DIAGNOSTIC_PREFIX = 1163 "diag"; 1164 private static final String SRU_EXPLAIN_NS = 1165 "http://explain.z3950.org/dtd/2.0/"; 1166 private static final String SRU_EXPLAIN_PREFIX = 1167 "zr"; 1168 private static final String SRU_XCQL_NS = 1169 "http://www.loc.gov/zing/cql/xcql/"; 1170 1171 1172 @Override 1173 public String getResponseNS() { 1174 return SRU_NS; 1175 } 1176 1177 1178 @Override 1179 public String getResponsePrefix() { 1180 return SRU_PREFIX; 1181 } 1182 1183 1184 @Override 1185 public String getScanNS() { 1186 return SRU_NS; 1187 } 1188 1189 1190 @Override 1191 public String getScanPrefix() { 1192 return SRU_PREFIX; 1193 } 1194 1195 1196 @Override 1197 public String getDiagnosticNS() { 1198 return SRU_DIAGNOSIC_NS; 1199 } 1200 1201 1202 @Override 1203 public String getDiagnosticPrefix() { 1204 return SRU_DIAGNOSTIC_PREFIX; 1205 } 1206 1207 1208 @Override 1209 public String getExplainNS() { 1210 return SRU_EXPLAIN_NS; 1211 } 1212 1213 1214 @Override 1215 public String getExplainPrefix() { 1216 return SRU_EXPLAIN_PREFIX; 1217 } 1218 1219 1220 @Override 1221 public String getXcqlNS() { 1222 return SRU_XCQL_NS; 1223 } 1224 }; 1225 1226 1227 private static final SRUNamespaces NAMESPACES_2_0 = new SRUNamespaces() { 1228 private static final String SRU_RESPONSE_NS = 1229 "http://docs.oasis-open.org/ns/search-ws/sruResponse"; 1230 private static final String SRU_RESPONSE_PREFIX = 1231 "sruResponse"; 1232 private static final String SRU_SCAN_NS = 1233 "http://docs.oasis-open.org/ns/search-ws/scan"; 1234 private static final String SRU_SCAN_PREFIX = 1235 "scan"; 1236 private static final String SRU_DIAGNOSIC_NS = 1237 "http://docs.oasis-open.org/ns/search-ws/diagnostic"; 1238 private static final String SRU_DIAGNOSTIC_PREFIX = 1239 "diag"; 1240 private static final String SRU_EXPLAIN_NS = 1241 "http://explain.z3950.org/dtd/2.0/"; 1242 private static final String SRU_EXPLAIN_PREFIX = 1243 "zr"; 1244 private static final String SRU_XCQL_NS = 1245 "http://docs.oasis-open.org/ns/search-ws/xcql"; 1246 1247 1248 @Override 1249 public String getResponseNS() { 1250 return SRU_RESPONSE_NS; 1251 } 1252 1253 1254 @Override 1255 public String getResponsePrefix() { 1256 return SRU_RESPONSE_PREFIX; 1257 } 1258 1259 1260 @Override 1261 public String getScanNS() { 1262 return SRU_SCAN_NS; 1263 } 1264 1265 1266 @Override 1267 public String getScanPrefix() { 1268 return SRU_SCAN_PREFIX; 1269 } 1270 1271 1272 @Override 1273 public String getDiagnosticNS() { 1274 return SRU_DIAGNOSIC_NS; 1275 } 1276 1277 1278 @Override 1279 public String getDiagnosticPrefix() { 1280 return SRU_DIAGNOSTIC_PREFIX; 1281 } 1282 1283 1284 @Override 1285 public String getExplainNS() { 1286 return SRU_EXPLAIN_NS; 1287 } 1288 1289 1290 @Override 1291 public String getExplainPrefix() { 1292 return SRU_EXPLAIN_PREFIX; 1293 } 1294 1295 1296 @Override 1297 public String getXcqlNS() { 1298 return SRU_XCQL_NS; 1299 } 1300 }; 1301 1302 } // class SRUServer -
SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUServerConfig.java
r6105 r6779 86 86 public final class SRUServerConfig { 87 87 /** 88 * Parameter constant for setting the minimum supported SRU version for this 89 * SRU server. Must be smaller or equal to {@link #SRU_SUPPORTED_VERSION_MAX}. 90 * <p> 91 * Valid values: "<code>1.1</code>", "<code>1.2</code>" or " 92 * <code>2.0</code>" (without quotation marks) 93 * <p> 94 */ 95 public static final String SRU_SUPPORTED_VERSION_MIN = 96 "eu.clarin.sru.server.sruSupportedVersionMin"; 97 /** 98 * Parameter constant for setting the maximum supported SRU version for this 99 * SRU server. Must be larger or equal to {@link #SRU_SUPPORTED_VERSION_MIN}. 100 * <p> 101 * Valid values: "<code>1.1</code>", "<code>1.2</code>" or " 102 * <code>2.0</code>" (without quotation marks) 103 * <p> 104 */ 105 public static final String SRU_SUPPORTED_VERSION_MAX = 106 "eu.clarin.sru.server.sruSupportedVersionMax"; 107 /** 108 * Parameter constant for setting the default SRU version for this SRU 109 * server, e.g. for an <em>Explain</em> request without explicit version. 110 * Must not me less than {@link #SRU_SUPPORTED_VERSION_MIN} or larger than 111 * {@link #SRU_SUPPORTED_VERSION_MAX}. Defaults to 112 * {@link #SRU_SUPPORTED_VERSION_MAX}. 113 * <p> 114 * Valid values: "<code>1.1</code>", "<code>1.2</code>" or " 115 * <code>2.0</code>" (without quotation marks) 116 * <p> 117 */ 118 public static final String SRU_SUPPORTED_VERSION_DEFAULT = 119 "eu.clarin.sru.server.sruSupportedVersionDefault"; 120 /** 88 121 * Parameter constant for configuring the transports for this SRU server. 89 122 * <p> … … 293 326 private static final String LEGACY_SRU_ALLOW_OVERRIDE_INDENT_RESPONSE = 294 327 "sru.allowOverrideIndentResponse"; 328 private static final SRUVersion DEFAULT_SRU_VERSION_MIN = 329 SRUVersion.VERSION_1_1; 330 private static final SRUVersion DEFAULT_SRU_VERSION_MAX = 331 SRUVersion.VERSION_1_2; 295 332 private static final int DEFAULT_NUMBER_OF_RECORDS = 100; 296 333 private static final int DEFAULT_MAXIMUM_RECORDS = 250; … … 627 664 private static final Logger logger = 628 665 LoggerFactory.getLogger(SRUServerConfig.class); 666 private final SRUVersion minVersion; 667 private final SRUVersion maxVersion; 668 private final SRUVersion defaultVersion; 629 669 private final String transport; 630 670 private final String host; … … 647 687 648 688 649 private SRUServerConfig(String transport, String host, int port, 689 private SRUServerConfig(SRUVersion minVersion, SRUVersion maxVersion, 690 SRUVersion defaultVersion, String transport, String host, int port, 650 691 String database, int numberOfRecords, int maximumRecords, 651 692 int numberOfTerms, int maximumTerms, boolean echoRequests, … … 655 696 boolean allowOverrideIndentResponse, DatabaseInfo databaseinfo, 656 697 IndexInfo indexInfo, List<SchemaInfo> schemaInfo) { 698 this.minVersion = minVersion; 699 this.maxVersion = maxVersion; 700 this.defaultVersion = defaultVersion; 657 701 this.transport = transport; 658 702 this.host = host; … … 688 732 689 733 734 public SRUVersion getMinVersion() { 735 return minVersion; 736 } 737 738 739 public SRUVersion getMaxVersion() { 740 return maxVersion; 741 } 742 743 690 744 public SRUVersion getDefaultVersion() { 691 return SRUVersion.VERSION_1_2;745 return defaultVersion; 692 746 } 693 747 … … 937 991 938 992 /* 939 * fetch parameters more parameters 993 * fetch parameters more parameters (usually passed from Servlet 994 * context) 940 995 */ 996 997 SRUVersion minVersion = parseVersionNumber(params, 998 SRU_SUPPORTED_VERSION_MIN, false, DEFAULT_SRU_VERSION_MIN); 999 1000 SRUVersion maxVersion = parseVersionNumber(params, 1001 SRU_SUPPORTED_VERSION_MAX, false, DEFAULT_SRU_VERSION_MAX); 1002 if (maxVersion.compareTo(minVersion) < 0) { 1003 throw new SRUConfigException( 1004 "parameter value \"" + SRU_SUPPORTED_VERSION_MAX + 1005 "\" (" + maxVersion.getVersionString() + 1006 ") must be equal or larger than value of parameter \"" + 1007 SRU_SUPPORTED_VERSION_MIN + "\" (" + 1008 minVersion.getVersionString() + ")"); 1009 } 1010 1011 SRUVersion defaultVersion = parseVersionNumber(params, 1012 SRU_SUPPORTED_VERSION_DEFAULT, false, maxVersion); 1013 if ((defaultVersion.compareTo(minVersion) < 0) || 1014 (defaultVersion.compareTo(maxVersion) > 0)) { 1015 throw new SRUConfigException( 1016 "parameter value \"" + SRU_SUPPORTED_VERSION_DEFAULT + 1017 "\" (" + defaultVersion.getVersionString() + 1018 ") must be between value of parameter \"" + 1019 SRU_SUPPORTED_VERSION_MIN + "\" (" + 1020 minVersion.getVersionString() + ") and \"" + 1021 SRU_SUPPORTED_VERSION_MAX + "\" (" + 1022 maxVersion.getVersionString() + ")"); 1023 } 1024 941 1025 String transport = params.get(SRU_TRANSPORT); 942 1026 if ((transport == null) || transport.isEmpty()) { … … 1011 1095 DEFAULT_RESPONSE_BUFFER_SIZE, 0, -1); 1012 1096 1013 return new SRUServerConfig(transport, host, port, database, 1014 numberOfRecords, maximumRecords, numberOfTerms, 1015 maximumTerms, echoRequests, indentResponse, 1016 responseBufferSize, allowOverrideMaximumRecords, 1017 allowOverrideMaximumTerms, allowOverrideIndentResponse, 1018 databaseInfo, indexInfo, schemaInfo); 1097 return new SRUServerConfig(minVersion, maxVersion, defaultVersion, 1098 transport, host, port, database, numberOfRecords, 1099 maximumRecords, numberOfTerms, maximumTerms, echoRequests, 1100 indentResponse, responseBufferSize, 1101 allowOverrideMaximumRecords, allowOverrideMaximumTerms, 1102 allowOverrideIndentResponse, databaseInfo, indexInfo, 1103 schemaInfo); 1019 1104 } catch (IOException e) { 1020 1105 throw new SRUConfigException("error reading configuration file", e); … … 1025 1110 } catch (SAXException e) { 1026 1111 throw new SRUConfigException("error parsing configuration file", e); 1112 } 1113 } 1114 1115 1116 private static SRUVersion parseVersionNumber(Map<String, String> params, 1117 String name, boolean mandatory, SRUVersion defaultValue) 1118 throws SRUConfigException { 1119 String value = params.get(name); 1120 if ((value == null) || value.isEmpty()) { 1121 if (mandatory) { 1122 throw new SRUConfigException( 1123 "parameter \"" + name + "\" is mandatory"); 1124 } else { 1125 return defaultValue; 1126 } 1127 } else { 1128 if ("1.1".equals(value)) { 1129 return SRUVersion.VERSION_1_1; 1130 } else if ("1.2".equals(value)) { 1131 return SRUVersion.VERSION_1_2; 1132 } else if ("2.0".equals(value)) { 1133 return SRUVersion.VERSION_2_0; 1134 } else { 1135 throw new SRUConfigException("invalid value for parameter \"" + 1136 name + "\": " + value); 1137 } 1027 1138 } 1028 1139 } -
SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUVersion.java
r2623 r6779 51 51 return "1.2"; 52 52 } 53 }, 54 55 /** 56 * SRU/CQL version 2.0 57 */ 58 VERSION_2_0 { 59 @Override 60 int getVersionNumber() { 61 return ((2 << 16) | 0); 62 } 63 64 65 @Override 66 String getVersionString() { 67 return "2.0"; 68 } 53 69 }; 54 70
Note: See TracChangeset
for help on using the changeset viewer.