- Timestamp:
- 06/05/13 14:30:15 (11 years ago)
- Location:
- SRUClient/trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUExplainRecordData.java
r2989 r2995 403 403 } // class IndexInfo 404 404 405 public static class Schema { 406 private final String identifier; 407 private final String name; 408 private final String location; 409 private final boolean sort; 410 private final boolean retrieve; 411 private final List<LocalizedString> title; 412 413 414 Schema(String identifier, String name, String location, boolean sort, 415 boolean retrieve, List<LocalizedString> title) { 416 this.identifier = identifier; 417 this.name = name; 418 this.location = location; 419 this.sort = sort; 420 this.retrieve = retrieve; 421 if ((title != null) && !title.isEmpty()) { 422 this.title = Collections.unmodifiableList(title); 423 } else { 424 this.title = null; 425 } 426 } 427 428 429 public String getIdentifier() { 430 return identifier; 431 } 432 433 434 public String getName() { 435 return name; 436 } 437 438 439 public String getLocation() { 440 return location; 441 } 442 443 444 public boolean getSort() { 445 return sort; 446 } 447 448 449 public boolean getRetrieve() { 450 return retrieve; 451 } 452 453 454 public List<LocalizedString> getTitle() { 455 return title; 456 } 457 } // class SchemaInfo 458 405 459 public static class ConfigInfo { 406 460 private final Map<String, String> defaults; … … 447 501 private final DatabaseInfo databaseInfo; 448 502 private final IndexInfo indexInfo; 503 private final List<Schema> schemaInfo; 449 504 private final ConfigInfo configInfo; 450 505 451 506 452 507 SRUExplainRecordData(ServerInfo serverInfo, DatabaseInfo databaseInfo, 453 IndexInfo indexInfo, ConfigInfo configInfo) { 508 IndexInfo indexInfo, List<Schema> schemaInfo, 509 ConfigInfo configInfo) { 454 510 this.serverInfo = serverInfo; 455 511 this.databaseInfo = databaseInfo; 456 512 this.indexInfo = indexInfo; 513 if ((schemaInfo != null) && !schemaInfo.isEmpty()) { 514 this.schemaInfo = Collections.unmodifiableList(schemaInfo); 515 } else { 516 this.schemaInfo = null; 517 } 457 518 this.configInfo = configInfo; 458 519 } … … 481 542 482 543 544 public List<Schema> getSchemaInfo() { 545 return schemaInfo; 546 } 547 548 483 549 public IndexInfo getIndexInfo() { 484 550 return indexInfo; -
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUExplainRecordDataParser.java
r2994 r2995 35 35 import eu.clarin.sru.client.SRUExplainRecordData.IndexInfo; 36 36 import eu.clarin.sru.client.SRUExplainRecordData.LocalizedString; 37 import eu.clarin.sru.client.SRUExplainRecordData.Schema; 37 38 import eu.clarin.sru.client.SRUExplainRecordData.ServerInfo; 38 39 … … 134 135 135 136 // explain/recordInfo or explain/schemaInfo 137 List<Schema> schemaInfo = null; 136 138 if (XmlStreamReaderUtils.peekStart(reader, ns, "recordInfo") || 137 139 XmlStreamReaderUtils.peekStart(reader, ns, "schemaInfo")) { 138 140 if (XmlStreamReaderUtils.readStart(reader, 139 141 ns, "recordInfo", false)) { 140 logger.debug(" recordInfo");142 logger.debug("skipping 'recordInfo'"); 141 143 XmlStreamReaderUtils.readEnd(reader, ns, "recordInfo", true); 142 144 } else if (XmlStreamReaderUtils.readStart(reader, 143 145 ns, "schemaInfo", false)) { 144 logger.debug("schemaInfo");145 XmlStreamReaderUtils.readEnd(reader, ns, "schemaInfo" , true);146 schemaInfo = parseSchemaInfo(reader, strict, ns); 147 XmlStreamReaderUtils.readEnd(reader, ns, "schemaInfo"); 146 148 } else { 147 149 throw new XMLStreamException("unexpected start element '" + … … 159 161 XmlStreamReaderUtils.readEnd(reader, ns, "explain", true); 160 162 return new SRUExplainRecordData(serverInfo, databaseInfo, indexInfo, 161 configInfo);163 schemaInfo, configInfo); 162 164 } 163 165 … … 448 450 final String id = 449 451 XmlStreamReaderUtils.readAttributeValue(reader, null, "id"); 450 final boolean can_search = 451 parseBooleanAttribute(reader, strict,null, "search");452 final boolean can_scan = 453 parseBooleanAttribute(reader, strict,null, "search");454 final boolean can_sort = 455 parseBooleanAttribute(reader, strict,null, "search");452 final boolean can_search = parseBooleanAttribute(reader, 453 strict, null, "search", false); 454 final boolean can_scan = parseBooleanAttribute(reader, 455 strict, null, "scan", false); 456 final boolean can_sort = parseBooleanAttribute(reader, 457 strict, null, "sort", false); 456 458 XmlStreamReaderUtils.consumeStart(reader); 457 459 … … 476 478 first_map, true)) { 477 479 final boolean primary = parseBooleanAttribute(reader, 478 strict, null, "primary" );480 strict, null, "primary", false); 479 481 XmlStreamReaderUtils.consumeStart(reader); 480 482 … … 599 601 } 600 602 final boolean primary = 601 parseBooleanAttribute(reader, strict, null, "primary" );603 parseBooleanAttribute(reader, strict, null, "primary", false); 602 604 XmlStreamReaderUtils.consumeStart(reader); 603 605 String value = XmlStreamReaderUtils.readString(reader, false); … … 608 610 609 611 private static boolean parseBooleanAttribute(XMLStreamReader reader, 610 boolean strict, String ns, String localName )612 boolean strict, String ns, String localName, boolean defaultValue) 611 613 throws XMLStreamException { 612 boolean result = false;614 boolean result = defaultValue; 613 615 final String s = XmlStreamReaderUtils.readAttributeValue(reader, 614 616 ns, localName, false); … … 643 645 644 646 647 private static List<Schema> parseSchemaInfo(XMLStreamReader reader, 648 boolean strict, String ns) throws XMLStreamException { 649 /* 650 * schemaInfo (schema+) 651 * schema (title*) 652 */ 653 List<Schema> schemaInfo = null; 654 boolean first_schema = true; 655 while (XmlStreamReaderUtils.readStart(reader, ns, "schema", 656 first_schema, true)) { 657 final String identifier = 658 XmlStreamReaderUtils.readAttributeValue(reader, 659 null, "identifier", true); 660 final String name = XmlStreamReaderUtils.readAttributeValue(reader, 661 null, "name", true); 662 final String location = 663 XmlStreamReaderUtils.readAttributeValue(reader, 664 null, "location"); 665 final boolean sort = parseBooleanAttribute(reader, strict, 666 null, "sort", false); 667 final boolean retrieve = parseBooleanAttribute(reader, strict, 668 null, "retrieve", true); 669 XmlStreamReaderUtils.consumeStart(reader); 670 671 List<LocalizedString> titles = null; 672 for (;;) { 673 LocalizedString title = 674 parseStringI18N(reader, strict, ns, "title", false); 675 if (title == null) { 676 break; 677 } 678 if (titles == null) { 679 titles = new ArrayList<LocalizedString>(); 680 } 681 titles.add(title); 682 } // for 683 XmlStreamReaderUtils.readEnd(reader, ns, "schema"); 684 685 if (schemaInfo == null) { 686 schemaInfo = new ArrayList<Schema>(); 687 } 688 schemaInfo.add(new Schema(identifier, name, location, sort, 689 retrieve, titles)); 690 first_schema = false; 691 } 692 return schemaInfo; 693 } 694 695 645 696 private static Map<String, String> parseConfigInfoItem( 646 697 XMLStreamReader reader, boolean strict, String ns, -
SRUClient/trunk/src/test/java/eu/clarin/sru/client/TestUtils.java
r2989 r2995 25 25 26 26 import eu.clarin.sru.client.SRUExplainRecordData.ConfigInfo; 27 import eu.clarin.sru.client.SRUExplainRecordData.Schema; 27 28 import eu.clarin.sru.client.fcs.ClarinFCSRecordData; 28 29 import eu.clarin.sru.client.fcs.DataView; … … 155 156 data.getServerInfo().getPort(), 156 157 data.getServerInfo().getDatabase()); 158 List<Schema> schemaInfo = data.getSchemaInfo(); 159 if (schemaInfo != null) { 160 for (Schema schema : schemaInfo) { 161 logger.debug("schema: identifier={}, name={}, " + 162 "location={}, sort={}, retrieve={}", 163 schema.getIdentifier(), 164 schema.getName(), 165 schema.getLocation(), 166 schema.getSort(), 167 schema.getRetrieve()); 168 } 169 } 157 170 ConfigInfo configInfo = data.getConfigInfo(); 158 171 if (configInfo != null) {
Note: See TracChangeset
for help on using the changeset viewer.