- Timestamp:
- 06/05/13 12:57:12 (11 years ago)
- Location:
- SRUClient/trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUExplainRecordData.java
r2986 r2989 19 19 import java.util.Collections; 20 20 import java.util.List; 21 import java.util.Map; 21 22 import java.util.Set; 22 23 … … 402 403 } // class IndexInfo 403 404 405 public static class ConfigInfo { 406 private final Map<String, String> defaults; 407 private final Map<String, String> settings; 408 private final Map<String, String> supports; 409 410 411 ConfigInfo(Map<String, String> defaults, Map<String, String> settings, 412 Map<String, String> supports) { 413 if ((defaults != null) && !defaults.isEmpty()) { 414 this.defaults = Collections.unmodifiableMap(defaults); 415 } else { 416 this.defaults = Collections.emptyMap(); 417 } 418 if ((settings != null) && !settings.isEmpty()) { 419 this.settings = Collections.unmodifiableMap(settings); 420 } else { 421 this.settings = Collections.emptyMap(); 422 } 423 if ((supports != null) && !supports.isEmpty()) { 424 this.supports = Collections.unmodifiableMap(supports); 425 } else { 426 this.supports = Collections.emptyMap(); 427 } 428 } 429 430 431 public Map<String, String> getDefaults() { 432 return defaults; 433 } 434 435 436 public Map<String, String> getSettings() { 437 return settings; 438 } 439 440 441 public Map<String, String> getSupports() { 442 return supports; 443 } 444 } // class ConfigInfo 445 404 446 private final ServerInfo serverInfo; 405 447 private final DatabaseInfo databaseInfo; 406 448 private final IndexInfo indexInfo; 449 private final ConfigInfo configInfo; 407 450 408 451 409 452 SRUExplainRecordData(ServerInfo serverInfo, DatabaseInfo databaseInfo, 410 IndexInfo indexInfo ) {453 IndexInfo indexInfo, ConfigInfo configInfo) { 411 454 this.serverInfo = serverInfo; 412 455 this.databaseInfo = databaseInfo; 413 456 this.indexInfo = indexInfo; 457 this.configInfo = configInfo; 414 458 } 415 459 … … 441 485 } 442 486 487 488 public ConfigInfo getConfigInfo() { 489 return configInfo; 490 } 491 443 492 } // class SRUExplainRecordData -
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUExplainRecordDataParser.java
r2987 r2989 18 18 19 19 import java.util.ArrayList; 20 import java.util.HashMap; 20 21 import java.util.HashSet; 21 22 import java.util.List; 23 import java.util.Map; 22 24 import java.util.Set; 23 25 … … 29 31 import org.slf4j.LoggerFactory; 30 32 33 import eu.clarin.sru.client.SRUExplainRecordData.ConfigInfo; 31 34 import eu.clarin.sru.client.SRUExplainRecordData.DatabaseInfo; 32 35 import eu.clarin.sru.client.SRUExplainRecordData.IndexInfo; … … 85 88 return parseExplain(reader, version, strict, ZEEREX_NS_QUIRK); 86 89 } else { 87 throw new XMLStreamException("expected element '" +90 throw new XMLStreamException("expected start tag for element '" + 88 91 new QName(ZEEREX_NS, "explain") + " at this position", 89 92 reader.getLocation()); … … 148 151 149 152 // explain/configInfo (optional) 153 ConfigInfo configInfo = null; 150 154 if (XmlStreamReaderUtils.readStart(reader, ns, "configInfo", false)) { 151 parseConfigInfo(reader, strict, ns);155 configInfo = parseConfigInfo(reader, strict, ns); 152 156 XmlStreamReaderUtils.readEnd(reader, ns, "configInfo"); 153 157 } 154 158 155 159 XmlStreamReaderUtils.readEnd(reader, ns, "explain", true); 156 return new SRUExplainRecordData(serverInfo, databaseInfo, indexInfo); 160 return new SRUExplainRecordData(serverInfo, databaseInfo, indexInfo, 161 configInfo); 157 162 } 158 163 … … 259 264 byte mode = 0; /* 1 = title, 2 = description, 3 = others */ 260 265 for (;;) { 261 /*262 * make sure to remove any whitespace and break, if we do not point263 * to a start tag264 */265 XmlStreamReaderUtils.consumeWhitespace(reader);266 if (!reader.isStartElement()) {267 break;268 }269 270 266 if (XmlStreamReaderUtils.peekStart(reader, ns, "title")) { 271 267 if ((mode != 0) && (mode != 1)) { … … 557 553 558 554 559 private static ObjectparseConfigInfo(XMLStreamReader reader,555 private static ConfigInfo parseConfigInfo(XMLStreamReader reader, 560 556 boolean strict, String ns) throws XMLStreamException, 561 557 SRUClientException { … … 563 559 * configInfo ((default|setting|supports)*) 564 560 */ 565 logger.debug("configInfo"); 561 Map<String, String> defaults = null; 562 Map<String, String> settings = null; 563 Map<String, String> supports = null; 566 564 for (;;) { 567 if (XmlStreamReaderUtils.readStart(reader, 568 ns, "default", false, true)) { 569 final String type = 570 XmlStreamReaderUtils.readAttributeValue(reader, 571 null, "type", true); 572 XmlStreamReaderUtils.consumeStart(reader); 573 final String value = 574 XmlStreamReaderUtils.readString(reader, true); 575 XmlStreamReaderUtils.readEnd(reader, ns, "default"); 576 logger.debug("-> default: type={}, value={}", type, value); 577 } else if (XmlStreamReaderUtils.readStart(reader, 578 ns, "setting", false, true)) { 579 final String type = 580 XmlStreamReaderUtils.readAttributeValue(reader, 581 null, "type", true); 582 XmlStreamReaderUtils.consumeStart(reader); 583 final String value = 584 XmlStreamReaderUtils.readString(reader, true); 585 XmlStreamReaderUtils.readEnd(reader, ns, "setting"); 586 logger.debug("-> setting: type={}, value={}", type, value); 587 } else if (XmlStreamReaderUtils.readStart(reader, 588 ns, "supports", false, true)) { 589 final String type = 590 XmlStreamReaderUtils.readAttributeValue(reader, 591 null, "type", true); 592 XmlStreamReaderUtils.consumeStart(reader); 593 final String value = 594 XmlStreamReaderUtils.readString(reader, true); 595 XmlStreamReaderUtils.readEnd(reader, ns, "supports"); 596 597 logger.debug("-> supports: type={}, value={}", type, value); 565 if (XmlStreamReaderUtils.peekStart(reader, ns, "default")) { 566 defaults = parseConfigInfoItem(reader, strict, ns, "default", defaults); 567 } else if (XmlStreamReaderUtils.peekStart(reader, ns, "setting")) { 568 settings = parseConfigInfoItem(reader, strict, ns, "setting", settings); 569 } else if (XmlStreamReaderUtils.peekStart(reader, ns, "supports")) { 570 supports = parseConfigInfoItem(reader, strict, ns, "supports", supports); 598 571 } else { 599 572 break; … … 601 574 } 602 575 603 return null; 576 return ((defaults != null) || (settings != null) || (supports != null)) 577 ? new ConfigInfo(defaults, settings, supports) 578 : null; 604 579 } 605 580 … … 664 639 } 665 640 641 642 private static Map<String, String> parseConfigInfoItem( 643 XMLStreamReader reader, boolean strict, String ns, 644 String localName, Map<String, String> map) 645 throws XMLStreamException { 646 XmlStreamReaderUtils.readStart(reader, ns, localName, true, true); 647 final String type = XmlStreamReaderUtils.readAttributeValue(reader, 648 null, "type", true); 649 XmlStreamReaderUtils.consumeStart(reader); 650 final String value = XmlStreamReaderUtils.readString(reader, true); 651 XmlStreamReaderUtils.readEnd(reader, ns, localName); 652 653 if ((type != null) && (value != null)) { 654 if (map == null) { 655 map = new HashMap<String, String>(); 656 } 657 if (map.containsKey(type)) { 658 logger.warn( 659 "{} with type '{}' is already present, skipping duplicate entry", 660 localName, type); 661 } else { 662 map.put(type, value); 663 } 664 } 665 return map; 666 } 667 666 668 } // class SRUExplainRecordDataParser -
SRUClient/trunk/src/main/java/eu/clarin/sru/client/XmlStreamReaderUtils.java
r2953 r2989 226 226 227 227 228 public static String peekElementLocalName(XMLStreamReader reader)229 throws XMLStreamException {230 consumeWhitespace(reader);231 if (!reader.isStartElement()) {232 throw new XMLStreamException("not at a start elment event",233 reader.getLocation());234 }235 return reader.getLocalName();236 }237 238 239 228 public static boolean peekStart(XMLStreamReader reader, 240 String namespaceURI, String localName) throws XMLStreamException { 241 consumeWhitespace(reader); 242 if (!reader.isStartElement()) { 243 throw new XMLStreamException("not at a start elment event", 244 reader.getLocation()); 229 String namespaceURI, String localName) 230 throws XMLStreamException { 231 if (reader.isWhiteSpace()) { 232 consumeWhitespace(reader); 233 } 234 if (!reader.isStartElement()) { 235 return false; 245 236 } 246 237 return namespaceURI.equals(reader.getNamespaceURI()) && … … 252 243 throws XMLStreamException { 253 244 if (!reader.isStartElement()) { 254 throw new XMLStreamException("not at a start el ment event",245 throw new XMLStreamException("not at a start element event", 255 246 reader.getLocation()); 256 247 } -
SRUClient/trunk/src/test/java/eu/clarin/sru/client/TestUtils.java
r2984 r2989 24 24 import org.w3c.dom.Node; 25 25 26 import eu.clarin.sru.client.SRUExplainRecordData.ConfigInfo; 26 27 import eu.clarin.sru.client.fcs.ClarinFCSRecordData; 27 28 import eu.clarin.sru.client.fcs.DataView; … … 154 155 data.getServerInfo().getPort(), 155 156 data.getServerInfo().getDatabase()); 157 ConfigInfo configInfo = data.getConfigInfo(); 158 if (configInfo != null) { 159 if (configInfo.getDefaults() != null) { 160 logger.debug("configInfo/default = {}", 161 configInfo.getDefaults()); 162 } 163 if (configInfo.getSettings() != null) { 164 logger.debug("configInfo/setting = {}", 165 configInfo.getSettings()); 166 } 167 if (configInfo.getSupports() != null) { 168 logger.debug("configInfo/supports = {}", 169 configInfo.getSupports()); 170 } 171 } 156 172 } 157 173 }
Note: See TracChangeset
for help on using the changeset viewer.