- Timestamp:
- 05/29/13 13:06:02 (11 years ago)
- Location:
- SRUClient/trunk/src/main/java/eu/clarin/sru/client
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUExplainRecordData.java
r2936 r2956 18 18 19 19 import java.util.Collections; 20 import java.util.List; 20 21 import java.util.Set; 21 22 22 23 /** 23 24 * A record data implementation for SRU explain record data conforming to the 24 * Zeerex schema. 25 * ZeeRex schema. 26 * 27 * @see <a href="http://zeerex.z3950.org/dtd/">ZeeRex DTD</a> 25 28 */ 26 29 public class SRUExplainRecordData implements SRURecordData { 27 public static final String RECORD_SCHEMA = "http://explain.z3950.org/dtd/2.0/"; 30 public static final String RECORD_SCHEMA = 31 "http://explain.z3950.org/dtd/2.0/"; 28 32 29 33 public static class ServerInfo { … … 34 38 private final Set<String> transport; 35 39 36 publicServerInfo(String host, int port, String database,40 ServerInfo(String host, int port, String database, 37 41 String protocol, SRUVersion version, Set<String> transport) { 38 42 if (host == null) { … … 89 93 } 90 94 } // class ServerInfo 95 96 public static final class LocalizedString { 97 private final boolean primary; 98 private final String lang; 99 private final String value; 100 101 102 LocalizedString(String value, String lang, boolean primary) { 103 this.value = value; 104 this.lang = lang; 105 this.primary = primary; 106 } 107 108 109 public boolean isPrimary() { 110 return primary; 111 } 112 113 114 public String getLang() { 115 return lang; 116 } 117 118 119 public String getValue() { 120 return value; 121 } 122 } // class LocalizedString 123 124 public static final class DatabaseInfo { 125 private final List<LocalizedString> title; 126 private final List<LocalizedString> description; 127 private final List<LocalizedString> author; 128 private final List<LocalizedString> contact; 129 private final List<LocalizedString> extent; 130 private final List<LocalizedString> history; 131 private final List<LocalizedString> langUsage; 132 private final List<LocalizedString> restrictions; 133 private final List<LocalizedString> subjects; 134 private final List<LocalizedString> links; 135 private final List<LocalizedString> implementation; 136 137 138 DatabaseInfo(List<LocalizedString> title, 139 List<LocalizedString> description, 140 List<LocalizedString> author, List<LocalizedString> contact, 141 List<LocalizedString> extent, List<LocalizedString> history, 142 List<LocalizedString> langUsage, 143 List<LocalizedString> restrictions, 144 List<LocalizedString> subjects, List<LocalizedString> links, 145 List<LocalizedString> implementation) { 146 if ((title != null) && !title.isEmpty()) { 147 this.title = Collections.unmodifiableList(title); 148 } else { 149 this.title = null; 150 } 151 if ((description != null) && !description.isEmpty()) { 152 this.description = Collections.unmodifiableList(description); 153 } else { 154 this.description = null; 155 } 156 if ((author != null) && !author.isEmpty()) { 157 this.author = Collections.unmodifiableList(author); 158 } else { 159 this.author = null; 160 } 161 if ((contact != null) && !contact.isEmpty()) { 162 this.contact = Collections.unmodifiableList(contact); 163 } else { 164 this.contact = null; 165 } 166 if ((extent != null) && !extent.isEmpty()) { 167 this.extent = Collections.unmodifiableList(extent); 168 } else { 169 this.extent = null; 170 } 171 if ((history != null) && !history.isEmpty()) { 172 this.history = Collections.unmodifiableList(history); 173 } else { 174 this.history = null; 175 } 176 if ((langUsage != null) && !langUsage.isEmpty()) { 177 this.langUsage = Collections.unmodifiableList(langUsage); 178 } else { 179 this.langUsage = null; 180 } 181 if ((restrictions != null) && !restrictions.isEmpty()) { 182 this.restrictions = Collections.unmodifiableList(restrictions); 183 } else { 184 this.restrictions = null; 185 } 186 if ((subjects != null) && !subjects.isEmpty()) { 187 this.subjects = Collections.unmodifiableList(subjects); 188 } else { 189 this.subjects = null; 190 } 191 if ((links != null) && !links.isEmpty()) { 192 this.links = Collections.unmodifiableList(links); 193 } else { 194 this.links = null; 195 } 196 if ((implementation != null) && !implementation.isEmpty()) { 197 this.implementation = Collections 198 .unmodifiableList(implementation); 199 } else { 200 this.implementation = null; 201 } 202 } 203 204 205 public List<LocalizedString> getTitle() { 206 return title; 207 } 208 209 210 public List<LocalizedString> getDescription() { 211 return description; 212 } 213 214 215 public List<LocalizedString> getAuthor() { 216 return author; 217 } 218 219 220 public List<LocalizedString> getContact() { 221 return contact; 222 } 223 224 225 public List<LocalizedString> getExtend() { 226 return extent; 227 } 228 229 230 public List<LocalizedString> getHistory() { 231 return history; 232 } 233 234 235 public List<LocalizedString> getLangUsage() { 236 return langUsage; 237 } 238 239 240 public List<LocalizedString> getRestrictions() { 241 return restrictions; 242 } 243 244 245 public List<LocalizedString> getSubjects() { 246 return subjects; 247 } 248 249 250 public List<LocalizedString> getLinks() { 251 return links; 252 } 253 254 255 public List<LocalizedString> getImplementation() { 256 return implementation; 257 } 258 } // class DatabaseInfo 259 91 260 private final ServerInfo serverInfo; 92 93 94 public SRUExplainRecordData(ServerInfo serverInfo) { 95 this.serverInfo = serverInfo; 261 private final DatabaseInfo databaseInfo; 262 263 264 SRUExplainRecordData(ServerInfo serverInfo, DatabaseInfo databaseInfo) { 265 this.serverInfo = serverInfo; 266 this.databaseInfo = databaseInfo; 96 267 } 97 268 … … 113 284 } 114 285 286 287 public DatabaseInfo getDatabaseInfo() { 288 return databaseInfo; 289 } 290 115 291 } // class SRUExplainRecordData -
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUExplainRecordDataParser.java
r2953 r2956 17 17 package eu.clarin.sru.client; 18 18 19 import java.util.ArrayList; 19 20 import java.util.HashSet; 21 import java.util.List; 20 22 import java.util.Set; 21 23 24 import javax.xml.namespace.QName; 22 25 import javax.xml.stream.XMLStreamException; 23 26 import javax.xml.stream.XMLStreamReader; … … 26 29 import org.slf4j.LoggerFactory; 27 30 31 import eu.clarin.sru.client.SRUExplainRecordData.DatabaseInfo; 32 import eu.clarin.sru.client.SRUExplainRecordData.LocalizedString; 28 33 import eu.clarin.sru.client.SRUExplainRecordData.ServerInfo; 29 34 … … 33 38 * data conforming to the ZeeRex schema. 34 39 * 35 * @see <a href="http://zeerex.z3950.org/dtd/"> TheZeeRex DTD</a>40 * @see <a href="http://zeerex.z3950.org/dtd/">ZeeRex DTD</a> 36 41 */ 37 42 class SRUExplainRecordDataParser { … … 44 49 private static final String TRANSPORT_HTTP = "http"; 45 50 private static final String TRANSPORT_HTTPS = "https"; 51 private static final String PRIMARY_TRUE = "true"; 52 private static final String PRIMARY_FALSE = "false"; 46 53 private static final Logger logger = 47 54 LoggerFactory.getLogger(SRUExplainRecordDataParser.class); 48 55 49 56 50 public SRURecordData parse(XMLStreamReader reader, 51 SRUVersion version, String recordSchema) throws XMLStreamException,57 public SRURecordData parse(XMLStreamReader reader, SRUVersion version, 58 boolean strict, String recordSchema) throws XMLStreamException, 52 59 SRUClientException { 53 60 // sanity check, if we are dealing with the expected record schema … … 62 69 63 70 // explain 64 if (XmlStreamReaderUtils.readStart(reader, ZEEREX_NS, 65 "explain", false)) { 66 return parseExplain(reader, ZEEREX_NS, version); 67 } else if (XmlStreamReaderUtils.readStart(reader, 68 ZEEREX_NS_QUIRK, "explain", false)) { 69 logger.warn("namespace '{}' is not defined by ZeeRex, enabling " + 70 "quirk mode (consider using namespace '{}' which is defined)", 71 ZEEREX_NS_QUIRK, ZEEREX_NS); 72 return parseExplain(reader, ZEEREX_NS_QUIRK, version); 71 if (XmlStreamReaderUtils.peekStart(reader, ZEEREX_NS, "explain")) { 72 if (strict) { 73 logger.warn("namespace '{}' is not defined by ZeeRex, " + 74 "enabling quirks mode (consider using namespace '{}'" + 75 " which is defined)", ZEEREX_NS_QUIRK, ZEEREX_NS); 76 } else { 77 logger.info("namespace '{}' is not defined by ZeeRex, " + 78 "enabling quirks mode (consider using namespace '{}'" + 79 " which is defined)", ZEEREX_NS_QUIRK, ZEEREX_NS); 80 } 81 return parseExplain(reader, version, strict, ZEEREX_NS); 82 } else if (XmlStreamReaderUtils.peekStart(reader, 83 ZEEREX_NS_QUIRK, "explain")) { 84 if (strict) { 85 logger.warn("namespace '{}' is not defined by ZeeRex, " + 86 "enabling quirks mode (consider using namespace '{}'" + 87 " which is defined)", ZEEREX_NS_QUIRK, ZEEREX_NS); 88 } else { 89 logger.info("namespace '{}' is not defined by ZeeRex, " + 90 "enabling quirks mode (consider using namespace '{}'" + 91 " which is defined)", ZEEREX_NS_QUIRK, ZEEREX_NS); 92 } 93 return parseExplain(reader, version, strict, ZEEREX_NS_QUIRK); 73 94 } else { 74 throw new XMLStreamException("expected element '{" + ZEEREX_NS + 75 "}explain' at this position", reader.getLocation()); 95 throw new XMLStreamException("expected element '" + 96 new QName(ZEEREX_NS, "explain") + " at this position", 97 reader.getLocation()); 76 98 } 77 99 } … … 79 101 80 102 private static SRURecordData parseExplain(XMLStreamReader reader, 81 final String namespace, final SRUVersion version)103 SRUVersion version, boolean strict, String ns) 82 104 throws XMLStreamException, SRUClientException { 105 106 // explain 107 XmlStreamReaderUtils.readStart(reader, ns, "explain", true); 83 108 84 109 /* … … 87 112 */ 88 113 89 // explain/serverInfo 90 ServerInfo serverInfo = parseServerInfo(reader, namespace); 91 92 // explain/databaseInfo 93 if (XmlStreamReaderUtils.readStart(reader, namespace, "databaseInfo", false)) { 94 /* 95 * databaseInfo (title*, description*, (author | contact | extent | 96 * history | langUsage | restrictions | subjects | links | 97 * implementation)*) 98 */ 99 logger.debug("databaseInfo"); 100 101 while (XmlStreamReaderUtils.readStart(reader, 102 namespace, "title", false, true)) { 103 final String lang = XmlStreamReaderUtils.readAttributeValue(reader, null, "lang", false); 104 final String primary = XmlStreamReaderUtils.readAttributeValue(reader, null, "primary", false); 105 XmlStreamReaderUtils.consumeStart(reader); 106 String value = XmlStreamReaderUtils.readString(reader, false); 107 XmlStreamReaderUtils.readEnd(reader, namespace, "title"); 108 logger.debug("-> title = {} (primary={}, lang={})", value, primary, lang); 109 } // while 110 111 while (XmlStreamReaderUtils.readStart(reader, 112 namespace, "description", false, true)) { 113 XmlStreamReaderUtils.consumeStart(reader); 114 String value = XmlStreamReaderUtils.readString(reader, false); 115 XmlStreamReaderUtils.readEnd(reader, namespace, "description"); 116 logger.debug("-> description = {}", value); 117 } 118 119 XmlStreamReaderUtils.readEnd(reader, namespace, "databaseInfo", true); 120 } 121 122 // explain/metaInfo 123 if (XmlStreamReaderUtils.readStart(reader, namespace, "metaInfo", false)) { 114 // explain/serverInfo (mandatory) 115 ServerInfo serverInfo = parseServerInfo(reader, ns); 116 117 // explain/databaseInfo (optional) 118 DatabaseInfo databaseInfo = null; 119 if (XmlStreamReaderUtils.readStart(reader, ns, "databaseInfo", false)) { 120 databaseInfo = parseDatabaseInfo(reader, ns, strict); 121 XmlStreamReaderUtils.readEnd(reader, ns, "databaseInfo"); 122 } 123 124 // explain/metaInfo (optional) 125 if (XmlStreamReaderUtils.readStart(reader, ns, "metaInfo", false)) { 124 126 /* 125 127 * metaInfo (dateModified, (aggregatedFrom, dateAggregated)?) 126 128 */ 127 129 logger.debug("metaInfo"); 128 XmlStreamReaderUtils.readEnd(reader, namespace, "metaInfo", true); 129 } 130 131 // explain/indexInfo 132 while (XmlStreamReaderUtils.readStart(reader, namespace, "indexInfo", false)) { 133 /* 134 * indexInfo ((set | index | sortKeywords)+) 135 */ 136 logger.debug("indexInfo"); 137 boolean found = false; 138 for (;;) { 139 if (XmlStreamReaderUtils.readStart(reader, namespace, "set", false, true)) { 140 logger.debug("-> set"); 141 // FIXME: read attributes 142 XmlStreamReaderUtils.consumeStart(reader); 143 144 XmlStreamReaderUtils.readEnd(reader, namespace, "set", true); 145 found = true; 146 } else if (XmlStreamReaderUtils.readStart(reader, namespace, "index", false, true)) { 147 logger.debug("-> index"); 148 // FIXME: read attributes 149 XmlStreamReaderUtils.consumeStart(reader); 150 XmlStreamReaderUtils.readEnd(reader, namespace, "index", true); 151 found = true; 152 } else if (XmlStreamReaderUtils.readStart(reader, namespace, "sortKeyword", false)) { 153 logger.debug("-> sortKeywords"); 154 XmlStreamReaderUtils.readEnd(reader, namespace, "sortKeyword", true); 155 found = true; 156 } else { 157 break; 158 } 159 } // for 160 if (!found) { 161 // FIXME: error message 162 throw new XMLStreamException("expected at least one of <set>. <index> or <sortKeyword> element", reader.getLocation()); 163 } 164 XmlStreamReaderUtils.readEnd(reader, namespace, "indexInfo", true); 130 XmlStreamReaderUtils.readEnd(reader, ns, "metaInfo", true); 131 } 132 133 // explain/indexInfo (optional) 134 while (XmlStreamReaderUtils.readStart(reader, ns, "indexInfo", false)) { 135 parseIndexInfo(reader, strict, ns); 136 XmlStreamReaderUtils.readEnd(reader, ns, "indexInfo"); 165 137 } // while 166 138 167 139 // explain/recordInfo or explain/schemaInfo 168 if (XmlStreamReaderUtils.peekStart(reader, n amespace, "recordInfo") ||169 XmlStreamReaderUtils.peekStart(reader, n amespace, "schemaInfo")) {140 if (XmlStreamReaderUtils.peekStart(reader, ns, "recordInfo") || 141 XmlStreamReaderUtils.peekStart(reader, ns, "schemaInfo")) { 170 142 if (XmlStreamReaderUtils.readStart(reader, 171 n amespace, "recordInfo", false)) {143 ns, "recordInfo", false)) { 172 144 logger.debug("recordInfo"); 173 XmlStreamReaderUtils.readEnd(reader, n amespace, "recordInfo", true);145 XmlStreamReaderUtils.readEnd(reader, ns, "recordInfo", true); 174 146 } else if (XmlStreamReaderUtils.readStart(reader, 175 n amespace, "schemaInfo", false)) {147 ns, "schemaInfo", false)) { 176 148 logger.debug("schemaInfo"); 177 XmlStreamReaderUtils.readEnd(reader, n amespace, "schemaInfo", true);149 XmlStreamReaderUtils.readEnd(reader, ns, "schemaInfo", true); 178 150 } else { 179 151 throw new XMLStreamException("unexpected start element '" + … … 182 154 } 183 155 184 // explain/configInfo 185 if (XmlStreamReaderUtils.readStart(reader, namespace, 186 "configInfo", false)) { 187 /* 188 * configInfo ((default|setting|supports)*) 189 */ 190 logger.debug("configInfo"); 191 for (;;) { 192 if (XmlStreamReaderUtils.readStart(reader, 193 namespace, "default", false, true)) { 194 final String type = 195 XmlStreamReaderUtils.readAttributeValue(reader, 196 null, "type", true); 197 XmlStreamReaderUtils.consumeStart(reader); 198 final String value = 199 XmlStreamReaderUtils.readString(reader, true); 200 XmlStreamReaderUtils.readEnd(reader, namespace, "default"); 201 logger.debug("-> default: type={}, value={}", type, value); 202 } else if (XmlStreamReaderUtils.readStart(reader, 203 namespace, "setting", false, true)) { 204 final String type = 205 XmlStreamReaderUtils.readAttributeValue(reader, 206 null, "type", true); 207 XmlStreamReaderUtils.consumeStart(reader); 208 final String value = 209 XmlStreamReaderUtils.readString(reader, true); 210 XmlStreamReaderUtils.readEnd(reader, namespace, "setting"); 211 logger.debug("-> setting: type={}, value={}", type, value); 212 } else if (XmlStreamReaderUtils.readStart(reader, 213 namespace, "supports", false, true)) { 214 final String type = 215 XmlStreamReaderUtils.readAttributeValue(reader, 216 null, "type", true); 217 XmlStreamReaderUtils.consumeStart(reader); 218 final String value = 219 XmlStreamReaderUtils.readString(reader, true); 220 XmlStreamReaderUtils.readEnd(reader, namespace, "supports"); 221 222 logger.debug("-> supports: type={}, value={}", type, value); 223 } else { 224 break; 225 } 226 } 227 XmlStreamReaderUtils.readEnd(reader, namespace, "configInfo", true); 228 } 229 230 XmlStreamReaderUtils.readEnd(reader, namespace, "explain", true); 231 return new SRUExplainRecordData(serverInfo); 232 } 233 234 235 private static ServerInfo parseServerInfo(final XMLStreamReader reader, 236 final String namespace) throws XMLStreamException, 237 SRUClientException { 156 // explain/configInfo (optional) 157 if (XmlStreamReaderUtils.readStart(reader, ns, "configInfo", false)) { 158 parseConfigInfo(reader, strict, ns); 159 XmlStreamReaderUtils.readEnd(reader, ns, "configInfo"); 160 } 161 162 XmlStreamReaderUtils.readEnd(reader, ns, "explain", true); 163 return new SRUExplainRecordData(serverInfo, databaseInfo); 164 } 165 166 167 private static ServerInfo parseServerInfo(XMLStreamReader reader, 168 String namespace) throws XMLStreamException, SRUClientException { 238 169 XmlStreamReaderUtils.readStart(reader, namespace, 239 170 "serverInfo", true, true); … … 311 242 } 312 243 244 245 private static DatabaseInfo parseDatabaseInfo(XMLStreamReader reader, 246 String ns, boolean strict) throws XMLStreamException, 247 SRUClientException { 248 /* 249 * databaseInfo (title*, description*, (author | contact | extent | 250 * history | langUsage | restrictions | subjects | links | 251 * implementation)*) 252 */ 253 254 // make sure to remove any whitespace 255 XmlStreamReaderUtils.consumeWhitespace(reader); 256 257 List<LocalizedString> title = null; 258 List<LocalizedString> description = null; 259 List<LocalizedString> author = null; 260 List<LocalizedString> contact = null; 261 List<LocalizedString> extent = null; 262 List<LocalizedString> history = null; 263 List<LocalizedString> langUsage = null; 264 List<LocalizedString> restrictions = null; 265 List<LocalizedString> subjects = null; 266 List<LocalizedString> links = null; 267 List<LocalizedString> implementation = null; 268 269 byte mode = 0; /* 1 = title, 2 = description, 3 = others */ 270 while (reader.isStartElement()) { 271 if (XmlStreamReaderUtils.peekStart(reader, ns, "title")) { 272 if ((mode != 0) && (mode != 1)) { 273 if (strict) { 274 throw new XMLStreamException( 275 "element '" + new QName(ns, "title") + 276 "' not allowed here [required content" + 277 " model is: title*, description*, " + 278 "(author | contact | extent | history" + 279 " | langUsage | restrictions | " + 280 "subjects | links | implementation)*]", 281 reader.getLocation()); 282 } else { 283 logger.warn("element '{}' not allowed here [required " + 284 "content model is: title*, description*, " + 285 "(author | contact | extent | history | " + 286 "langUsage | restrictions | subjects | links " + 287 "| implementation)*] at position " + 288 "[row, col]: [{}, {}]", 289 new QName(ns, "title"), 290 reader.getLocation().getLineNumber(), 291 reader.getLocation().getColumnNumber()); 292 } 293 } 294 LocalizedString s = parseStringI18N(reader, strict, ns, "title"); 295 if (title == null) { 296 title = new ArrayList<LocalizedString>(); 297 } 298 title.add(s); 299 mode = 1; 300 } else if (XmlStreamReaderUtils.peekStart(reader, ns, "description")) { 301 if ((mode != 0) && (mode != 1) && (mode != 2)) { 302 if (strict) { 303 throw new XMLStreamException( 304 "element '" + new QName(ns, "description") + 305 "' not allowed here [required content" + 306 " model is: title*, description*, " + 307 "(author | contact | extent | history" + 308 " | langUsage | restrictions | " + 309 "subjects | links | implementation)*]", 310 reader.getLocation()); 311 } else { 312 logger.warn("element '{}' not allowed here [required " + 313 "content model is: title*, description*, " + 314 "(author | contact | extent | history | " + 315 "langUsage | restrictions | subjects | links " + 316 "| implementation)*] at position " + 317 "[row, col]: [{}, {}]", 318 new QName(ns, "description"), 319 reader.getLocation().getLineNumber(), 320 reader.getLocation().getColumnNumber()); 321 } 322 } 323 LocalizedString s = 324 parseStringI18N(reader, strict, ns, "description"); 325 if (description == null) { 326 description = new ArrayList<LocalizedString>(); 327 } 328 description.add(s); 329 mode = 2; 330 } else if (XmlStreamReaderUtils.peekStart(reader, ns, "author")) { 331 LocalizedString s = 332 parseStringI18N(reader, strict, ns, "author"); 333 if (author == null) { 334 author = new ArrayList<LocalizedString>(); 335 } 336 author.add(s); 337 mode = 3; 338 } else if (XmlStreamReaderUtils.peekStart(reader, ns, "contact")) { 339 LocalizedString s = 340 parseStringI18N(reader, strict, ns, "contact"); 341 if (contact == null) { 342 contact = new ArrayList<LocalizedString>(); 343 } 344 contact.add(s); 345 mode = 3; 346 } else if (XmlStreamReaderUtils.peekStart(reader, ns, "extent")) { 347 LocalizedString s = 348 parseStringI18N(reader, strict, ns, "extent"); 349 if (extent == null) { 350 extent = new ArrayList<LocalizedString>(); 351 } 352 extent.add(s); 353 mode = 3; 354 } else if (XmlStreamReaderUtils.peekStart(reader, ns, "history")) { 355 LocalizedString s = 356 parseStringI18N(reader, strict, ns, "history"); 357 if (history == null) { 358 history = new ArrayList<LocalizedString>(); 359 } 360 history.add(s); 361 mode = 3; 362 } else if (XmlStreamReaderUtils.peekStart(reader, 363 ns, "restrictions")) { 364 LocalizedString s = 365 parseStringI18N(reader, strict, ns, "restrictions"); 366 if (restrictions == null) { 367 restrictions = new ArrayList<LocalizedString>(); 368 } 369 restrictions.add(s); 370 mode = 3; 371 } else if (XmlStreamReaderUtils.peekStart(reader, ns, "subjects")) { 372 LocalizedString s = 373 parseStringI18N(reader, strict, ns, "subjects"); 374 if (subjects == null) { 375 subjects = new ArrayList<LocalizedString>(); 376 } 377 subjects.add(s); 378 mode = 3; 379 } else if (XmlStreamReaderUtils.peekStart(reader, ns, "links")) { 380 LocalizedString s = 381 parseStringI18N(reader, strict, ns, "links"); 382 if (links == null) { 383 links = new ArrayList<LocalizedString>(); 384 } 385 links.add(s); 386 mode = 3; 387 } else if (XmlStreamReaderUtils.peekStart(reader, 388 ns, "implementation")) { 389 LocalizedString s = 390 parseStringI18N(reader, strict, ns, "implementation"); 391 if (implementation == null) { 392 implementation = new ArrayList<LocalizedString>(); 393 } 394 implementation.add(s); 395 mode = 3; 396 } else if (XmlStreamReaderUtils.peekStart(reader, ns, "langUsage")) { 397 // FIXME: implement! 398 XmlStreamReaderUtils.readContent(reader, ns, "langUsage", false); 399 mode = 3; 400 } else { 401 break; 402 } 403 404 // make sure to remove any whitespace 405 XmlStreamReaderUtils.consumeWhitespace(reader); 406 } // while 407 408 return new DatabaseInfo(title, description, author, contact, 409 extent, history, langUsage, restrictions, subjects, 410 links, implementation); 411 } 412 413 414 private static Object parseIndexInfo(XMLStreamReader reader, 415 boolean strict, String ns) throws XMLStreamException, 416 SRUClientException { 417 /* 418 * indexInfo ((set | index | sortKeywords)+) 419 */ 420 logger.debug("indexInfo"); 421 boolean found = false; 422 for (;;) { 423 if (XmlStreamReaderUtils.readStart(reader, ns, "set", false, true)) { 424 logger.debug("-> set"); 425 // FIXME: read attributes 426 XmlStreamReaderUtils.consumeStart(reader); 427 428 XmlStreamReaderUtils.readEnd(reader, ns, "set", true); 429 found = true; 430 } else if (XmlStreamReaderUtils.readStart(reader, ns, "index", false, true)) { 431 logger.debug("-> index"); 432 // FIXME: read attributes 433 XmlStreamReaderUtils.consumeStart(reader); 434 XmlStreamReaderUtils.readEnd(reader, ns, "index", true); 435 found = true; 436 } else if (XmlStreamReaderUtils.readStart(reader, ns, "sortKeyword", false)) { 437 logger.debug("-> sortKeywords"); 438 XmlStreamReaderUtils.readEnd(reader, ns, "sortKeyword", true); 439 found = true; 440 } else { 441 break; 442 } 443 } // for 444 if (!found) { 445 throw new XMLStreamException("expected at least one '" + 446 new QName(ns, "set") + "', '" + 447 new QName(ns, "index") + "' or '" + 448 new QName(ns, "sortKeyword") + 449 "' element within element '" + 450 new QName(ns, "indexInfo") + "'", 451 reader.getLocation()); 452 } 453 return null; 454 } 455 456 457 private static Object parseConfigInfo(XMLStreamReader reader, 458 boolean strict, String ns) throws XMLStreamException, 459 SRUClientException { 460 /* 461 * configInfo ((default|setting|supports)*) 462 */ 463 logger.debug("configInfo"); 464 for (;;) { 465 if (XmlStreamReaderUtils.readStart(reader, 466 ns, "default", false, true)) { 467 final String type = 468 XmlStreamReaderUtils.readAttributeValue(reader, 469 null, "type", true); 470 XmlStreamReaderUtils.consumeStart(reader); 471 final String value = 472 XmlStreamReaderUtils.readString(reader, true); 473 XmlStreamReaderUtils.readEnd(reader, ns, "default"); 474 logger.debug("-> default: type={}, value={}", type, value); 475 } else if (XmlStreamReaderUtils.readStart(reader, 476 ns, "setting", false, true)) { 477 final String type = 478 XmlStreamReaderUtils.readAttributeValue(reader, 479 null, "type", true); 480 XmlStreamReaderUtils.consumeStart(reader); 481 final String value = 482 XmlStreamReaderUtils.readString(reader, true); 483 XmlStreamReaderUtils.readEnd(reader, ns, "setting"); 484 logger.debug("-> setting: type={}, value={}", type, value); 485 } else if (XmlStreamReaderUtils.readStart(reader, 486 ns, "supports", false, true)) { 487 final String type = 488 XmlStreamReaderUtils.readAttributeValue(reader, 489 null, "type", true); 490 XmlStreamReaderUtils.consumeStart(reader); 491 final String value = 492 XmlStreamReaderUtils.readString(reader, true); 493 XmlStreamReaderUtils.readEnd(reader, ns, "supports"); 494 495 logger.debug("-> supports: type={}, value={}", type, value); 496 } else { 497 break; 498 } 499 } 500 501 return null; 502 } 503 504 505 private static LocalizedString parseStringI18N(XMLStreamReader reader, 506 boolean strict, String ns, String localName) 507 throws XMLStreamException { 508 XmlStreamReaderUtils.readStart(reader, ns, localName, true, true); 509 final String lang = XmlStreamReaderUtils.readAttributeValue(reader, 510 null, "lang", false); 511 if (lang != null) { 512 if (lang.length() != 2) { 513 // FIXME: message 514 logger.warn("ZeeRex sugguests to use 2-letter codes"); 515 } 516 } 517 final String s = XmlStreamReaderUtils.readAttributeValue(reader, 518 null, "primary", false); 519 boolean primary = false; 520 if (s != null) { 521 if (PRIMARY_TRUE.equalsIgnoreCase(s)) { 522 if (!PRIMARY_TRUE.equals(s)) { 523 if (strict) { 524 throw new XMLStreamException("capitalization"); 525 } else { 526 // FIXME: message 527 logger.warn("capitalizaton"); 528 } 529 } 530 primary = true; 531 } else if (PRIMARY_FALSE.equalsIgnoreCase(s)) { 532 if (!PRIMARY_FALSE.equals(s)) { 533 if (strict) { 534 throw new XMLStreamException("capitalization"); 535 } else { 536 // FIXME: message 537 logger.warn("capitalizaton"); 538 } 539 } 540 primary = false; 541 } else { 542 // FIXME: message 543 throw new XMLStreamException("value of @primary invalid"); 544 } 545 } 546 XmlStreamReaderUtils.consumeStart(reader); 547 String value = XmlStreamReaderUtils.readString(reader, false); 548 XmlStreamReaderUtils.readEnd(reader, ns, localName); 549 logger.debug("databaseInfo/{}='{}' (primary={}, lang={})", localName, 550 value, primary, lang); 551 return new LocalizedString(value, lang, primary); 552 } 553 313 554 } // class SRUExplainRecordDataParser -
SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSimpleClient.java
r2947 r2956 563 563 * the data. 564 564 */ 565 recordData = 566 explainRecordParser.parse(proxy, version, schema);565 recordData = explainRecordParser.parse(proxy, 566 version, strictMode, schema); 567 567 } catch (XMLStreamException e) { 568 568 throw new SRUClientException( … … 612 612 } else { 613 613 /* 614 * do not really parse record and skip everything until <record>615 * end tag614 * do not really parse record and skip everything 615 * until <record> end tag 616 616 */ 617 617 reader.readEnd(SRU_NS, "record", true);
Note: See TracChangeset
for help on using the changeset viewer.