Changeset 6838 for FCSSimpleEndpoint
- Timestamp:
- 11/23/15 16:49:02 (8 years ago)
- Location:
- FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/Layer.java
r6830 r6838 27 27 private final String qualifier; 28 28 private final String altValueInfo; 29 private final StringaltValueInfoURI;29 private final URI altValueInfoURI; 30 30 31 31 … … 51 51 public Layer(String id, URI resultId, String type, 52 52 ContentEncoding encoding, String qualifier, String altValueInfo, 53 StringaltValueInfoURI) {53 URI altValueInfoURI) { 54 54 if (id == null) { 55 55 throw new NullPointerException("id == null"); … … 161 161 * layer or <code>null</code> 162 162 */ 163 public StringgetAltValueInfoURI() {163 public URI getAltValueInfoURI() { 164 164 return altValueInfoURI; 165 165 } -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/SimpleEndpointSearchEngineBase.java
r6830 r6838 292 292 if (layer.getAltValueInfoURI() != null) { 293 293 writer.writeAttribute("alt-value-info-uri", 294 layer.getAltValueInfoURI() );294 layer.getAltValueInfoURI().toString()); 295 295 } 296 296 } -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleEndpointDescriptionParser.java
r6830 r6838 59 59 private static final URI CAP_ADVANCED_SEARCH = 60 60 URI.create("http://clarin.eu/fcs/capability/advanced-search"); 61 private static final String MINETYPE_HITS = "application/x-clarin-fcs-hits+xml"; 62 private static final String MINETYPE_ADV = "application/x-clarin-fcs-adv+xml"; 61 63 private static final String LANG_EN = "en"; 62 64 private static final String POLICY_SEND_DEFAULT = "send-by-default"; 63 65 private static final String POLICY_NEED_REQUEST = "need-to-request"; 66 private static final String LAYER_ENCODING_VALUE = "value"; 67 private static final String LAYER_ENCODING_EMPTY = "empty"; 64 68 private static final Logger logger = 65 69 LoggerFactory.getLogger(SimpleEndpointDescriptionParser.class); … … 153 157 try { 154 158 URI uri = new URI(s); 155 if (capabilities.contains(uri)) { 159 if (!capabilities.contains(uri)) { 160 capabilities.add(uri); 161 } else { 156 162 logger.warn("ignoring duplicate capability " + 157 163 "entry for '{}'", uri); 158 164 } 159 capabilities.add(uri);160 165 } catch (URISyntaxException e) { 161 166 throw new SRUConfigException("capability is not encoded " + … … 174 179 } 175 180 logger.debug("CAPS:'{}'", capabilities); 181 182 // used to check for id attribute uniqueness 183 final Set<String> xml_ids = new HashSet<String>(); 176 184 177 185 // supported data views … … 188 196 + "must carry a proper 'id' attribute"); 189 197 } 198 199 if (xml_ids.contains(id)) { 200 throw new SRUConfigException("The value of attribute " + 201 "'id' of element <SupportedDataView> must be unique: " + id); 202 } 203 xml_ids.add(id); 204 190 205 String p = getAttribute(item, "delivery-policy"); 191 206 if (p == null) { … … 239 254 logger.debug("DV: {}", supportedDataViews); 240 255 256 // sanity check on data views 257 boolean hasHitsView = false; 258 boolean hasAdvView = false; 259 260 for (DataView dataView : supportedDataViews) { 261 if (dataView.getMimeType().equals(MINETYPE_HITS)) { 262 hasHitsView = true; 263 } else if (dataView.getMimeType().equals(MINETYPE_ADV)) { 264 hasAdvView = true; 265 } 266 } 267 if (!hasHitsView) { 268 throw new SRUConfigException("Generic Hits Data View (" + 269 MINETYPE_HITS + ") was not declared in <SupportedDataViews>"); 270 } 271 if (capabilities.contains(CAP_ADVANCED_SEARCH) && !hasAdvView) { 272 throw new SRUConfigException("Endpoint claimes to support " + 273 "Advanced FCS but does not declare Advanced Data View (" + 274 MINETYPE_ADV + ") in <SupportedDataViews>"); 275 276 } 277 241 278 242 279 // supported layers … … 250 287 String id = getAttribute(item, "id"); 251 288 if (id == null) { 252 throw new SRUConfigException("Element < ed:SupportedLayer> "289 throw new SRUConfigException("Element <SupportedLayer> " 253 290 + "must carry a proper 'id' attribute"); 254 291 } 292 293 if (xml_ids.contains(id)) { 294 throw new SRUConfigException("The value of attribute " + 295 "'id' of element <SupportedLayer> must be unique: " + id); 296 } 297 xml_ids.add(id); 298 255 299 String s = getAttribute(item, "result-id"); 256 300 if (s == null) { 257 throw new SRUConfigException("Element < ed:SupportedLayer> "301 throw new SRUConfigException("Element <SupportedLayer> " 258 302 + "must carry a proper 'result-id' attribute"); 259 303 } … … 263 307 } catch (URISyntaxException e) { 264 308 throw new SRUConfigException("Attribute 'result-id' on " + 265 "Element < ed:SupportedLayer> is not encoded " +309 "Element <SupportedLayer> is not encoded " + 266 310 "as proper URI: " + s); 267 311 } … … 269 313 String type = cleanString(item.getTextContent()); 270 314 if ((type != null) && !type.isEmpty()) { 271 315 // sanity check on layer types 316 if (!(type.equals("text") || 317 type.equals("lemma") || 318 type.equals("pos") || 319 type.equals("orth") || 320 type.equals("norm") || 321 type.equals("phonetic") || 322 type.startsWith("x-"))) { 323 logger.warn("layer type '{}' is not defined by specification", type); 324 } 272 325 } else { 273 throw new SRUConfigException("Element < ed:SupportedLayer> "274 + "as no proper type");326 throw new SRUConfigException("Element <SupportedLayer> " + 327 "does not define a proper layer type"); 275 328 } 276 329 277 330 String qualifier = getAttribute(item, "qualifier"); 278 331 279 // FIXME: implement parsing of content encoding!280 332 Layer.ContentEncoding encoding = 281 333 Layer.ContentEncoding.VALUE; 334 s = getAttribute(item, "type"); 335 if (s != null) { 336 if (LAYER_ENCODING_VALUE.equals(s)) { 337 encoding = Layer.ContentEncoding.VALUE; 338 } else if (LAYER_ENCODING_EMPTY.equals(s)) { 339 encoding = Layer.ContentEncoding.EMPTY; 340 } else { 341 throw new SRUConfigException("invalid layer encoding: " + s); 342 } 343 } 344 282 345 283 346 String altValueInfo = getAttribute(item, "alt-value-info"); 284 StringaltValueInfoURI = null;347 URI altValueInfoURI = null; 285 348 if (altValueInfo != null) { 286 altValueInfoURI = getAttribute(item, "alt-value-info-uri"); 349 s = getAttribute(item, "alt-value-info-uri"); 350 if (s != null) { 351 try { 352 altValueInfoURI = new URI(s); 353 } catch (URISyntaxException e) { 354 throw new SRUConfigException("Attribute 'alt-value-info-uri' on " + 355 "Element <SupportedLayer> is not encoded " + 356 "as proper URI: " + s); 357 } 358 } else { 359 360 } 287 361 } 288 362 … … 309 383 exp = xpath.compile("/ed:EndpointDescription/ed:Resources/ed:Resource"); 310 384 list = (NodeList) exp.evaluate(doc, XPathConstants.NODESET); 311 final Set<String> ids = new HashSet<String>();312 List<ResourceInfo> resources = parseRessources(xpath, list, ids,313 supportedDataViews, supportedLayers );385 final Set<String> pids = new HashSet<String>(); 386 List<ResourceInfo> resources = parseRessources(xpath, list, pids, 387 supportedDataViews, supportedLayers, hasAdvView); 314 388 if ((resources == null) || resources.isEmpty()) { 315 389 throw new SRUConfigException("No resources where " + … … 326 400 327 401 private static List<ResourceInfo> parseRessources(XPath xpath, 328 NodeList nodes, Set<String> ids, List<DataView> supportedDataViews,329 List<Layer> supportedLayers )402 NodeList nodes, Set<String> pids, List<DataView> supportedDataViews, 403 List<Layer> supportedLayers, boolean hasAdv) 330 404 throws SRUConfigException, XPathExpressionException { 331 405 List<ResourceInfo> ris = null; … … 346 420 "must carry a proper 'pid' attribute"); 347 421 } 348 if ( ids.contains(pid)) {422 if (pids.contains(pid)) { 349 423 throw new SRUConfigException("Another element <Resource> " + 350 424 "with pid '" + pid + "' already exists"); 351 425 } 352 ids.add(pid);353 354 XPathExpression x1= xpath.compile("ed:Title");355 NodeList l 1 = (NodeList) x1.evaluate(node, XPathConstants.NODESET);356 if ((l 1 != null) && (l1.getLength() > 0)) {357 for (int i = 0; i < l 1.getLength(); i++) {358 final Element n = (Element) l 1.item(i);426 pids.add(pid); 427 428 XPathExpression exp = xpath.compile("ed:Title"); 429 NodeList list = (NodeList) exp.evaluate(node, XPathConstants.NODESET); 430 if ((list != null) && (list.getLength() > 0)) { 431 for (int i = 0; i < list.getLength(); i++) { 432 final Element n = (Element) list.item(i); 359 433 360 434 final String lang = getLangAttribute(n); … … 387 461 } 388 462 389 XPathExpression x2= xpath.compile("ed:Description");390 NodeList l2 = (NodeList) x2.evaluate(node, XPathConstants.NODESET);391 if ((l 2 != null) && (l2.getLength() > 0)) {392 for (int i = 0; i < l 2.getLength(); i++) {393 Element n = (Element) l 2.item(i);463 exp = xpath.compile("ed:Description"); 464 list = (NodeList) exp.evaluate(node, XPathConstants.NODESET); 465 if ((list != null) && (list.getLength() > 0)) { 466 for (int i = 0; i < list.getLength(); i++) { 467 Element n = (Element) list.item(i); 394 468 395 469 String lang = getLangAttribute(n); … … 419 493 } 420 494 421 XPathExpression x3= xpath.compile("ed:LandingPageURI");422 NodeList l3 = (NodeList) x3.evaluate(node, XPathConstants.NODESET);423 if ((l 3 != null) && (l3.getLength() > 0)) {424 for (int i = 0; i < l 3.getLength(); i++) {425 Element n = (Element) l 3.item(i);495 exp = xpath.compile("ed:LandingPageURI"); 496 list = (NodeList) exp.evaluate(node, XPathConstants.NODESET); 497 if ((list != null) && (list.getLength() > 0)) { 498 for (int i = 0; i < list.getLength(); i++) { 499 Element n = (Element) list.item(i); 426 500 link = cleanString(n.getTextContent()); 427 501 } 428 502 } 429 503 430 XPathExpression x4= xpath.compile("ed:Languages/ed:Language");431 NodeList l4 = (NodeList) x4.evaluate(node, XPathConstants.NODESET);432 if ((l 4 != null) && (l4.getLength() > 0)) {433 for (int i = 0; i < l 4.getLength(); i++) {434 Element n = (Element) l 4.item(i);504 exp = xpath.compile("ed:Languages/ed:Language"); 505 list = (NodeList) exp.evaluate(node, XPathConstants.NODESET); 506 if ((list != null) && (list.getLength() > 0)) { 507 for (int i = 0; i < list.getLength(); i++) { 508 Element n = (Element) list.item(i); 435 509 436 510 String s = n.getTextContent(); … … 458 532 } 459 533 460 XPathExpression x5= xpath.compile("ed:AvailableDataViews");461 Node n = (Node) x5.evaluate(node, XPathConstants.NODE);534 exp = xpath.compile("ed:AvailableDataViews"); 535 Node n = (Node) exp.evaluate(node, XPathConstants.NODE); 462 536 if ((n != null) && (n instanceof Element)) { 463 537 String ref = getAttribute((Element) n, "ref"); … … 495 569 } else { 496 570 throw new SRUConfigException( 497 "missing element < ed:AvailableDataViews>");571 "missing element <AvailableDataViews>"); 498 572 } 499 573 if (availableDataViews == null) { … … 502 576 } 503 577 504 XPathExpression x6 = xpath.compile("ed:Resources/ed:Resource"); 505 NodeList l6 = (NodeList) x6.evaluate(node, XPathConstants.NODESET); 506 if ((l6 != null) && (l6.getLength() > 0)) { 507 sub = parseRessources(xpath, l6, ids, 508 supportedDataViews, supportedLayers); 578 exp = xpath.compile("ed:AvailableLayers"); 579 n = (Node) exp.evaluate(node, XPathConstants.NODE); 580 if ((n != null) && (n instanceof Element)) { 581 String ref = getAttribute((Element) n, "ref"); 582 if (ref == null) { 583 throw new SRUConfigException("Element <AvailableLayers> " + 584 "must carry a 'ref' attribute"); 585 } 586 String[] refs = ref.split("\\s+"); 587 if ((refs == null) || (refs.length < 1)) { 588 throw new SRUConfigException("Attribute 'ref' on element " + 589 "<AvailableLayers> must contain a whitespace " + 590 "seperated list of data view references"); 591 } 592 593 594 for (int i = 0; i < refs.length; i++) { 595 Layer layer = null; 596 for (Layer l : supportedLayers) { 597 if (refs[i].equals(l.getId())) { 598 layer = l; 599 break; 600 } 601 } 602 if (layer != null) { 603 if (availableLayers == null) { 604 availableLayers = new ArrayList<Layer>(); 605 } 606 availableLayers.add(layer); 607 } else { 608 throw new SRUConfigException("A layer with " + 609 "identifier '" + refs[i] + "' was not defined " + 610 "in <SupportedLayers>"); 611 } 612 } 613 } else { 614 if (hasAdv) { 615 logger.debug("no <SupportedLayers> for ressource '{}'", pid); 616 } 617 } 618 619 exp = xpath.compile("ed:Resources/ed:Resource"); 620 list = (NodeList) exp.evaluate(node, XPathConstants.NODESET); 621 if ((list != null) && (list.getLength() > 0)) { 622 sub = parseRessources(xpath, list, pids, 623 supportedDataViews, supportedLayers, hasAdv); 509 624 } 510 625 … … 526 641 527 642 private static String getAttribute(Element el, String localName) { 528 String lang= el.getAttribute(localName);529 if ( lang!= null) {530 lang = lang.trim();531 if (! lang.isEmpty()) {532 return lang;643 String value = el.getAttribute(localName); 644 if (value != null) { 645 value = value.trim(); 646 if (!value.isEmpty()) { 647 return value; 533 648 } 534 649 }
Note: See TracChangeset
for help on using the changeset viewer.