Changeset 5477 for FCSSimpleEndpoint
- Timestamp:
- 07/11/14 15:29:52 (10 years ago)
- Location:
- FCSSimpleEndpoint/trunk
- Files:
-
- 3 added
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
FCSSimpleEndpoint/trunk/pom.xml
r2803 r5477 4 4 <groupId>eu.clarin.sru.fcs</groupId> 5 5 <artifactId>fcs-simple-endpoint</artifactId> 6 <version> 1.3.0-SNAPSHOT</version>6 <version>2.0-SNAPSHOT</version> 7 7 <packaging>jar</packaging> 8 8 <name>A simple CLARIN FCS endpoint</name> -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/ResourceInfo.java
r2751 r5477 14 14 public class ResourceInfo { 15 15 private final String pid; 16 @Deprecated 16 17 private final int resourceCount; 17 18 private final Map<String, String> title; … … 19 20 private final String landingPageURI; 20 21 private final List<String> languages; 22 private final List<String> availableDataViews; 21 23 private List<ResourceInfo> subResources; 22 24 23 25 24 26 /** … … 50 52 Map<String, String> title, Map<String, String> description, 51 53 String landingPageURI, List<String> languages, 54 List<String> availableDataViews, 52 55 List<ResourceInfo> subResources) { 53 56 if (pid == null) { … … 76 79 } 77 80 this.languages = languages; 81 if (availableDataViews == null){ 82 throw new IllegalArgumentException("available data views == null"); 83 } 84 if (availableDataViews.isEmpty()){ 85 throw new IllegalArgumentException("available data views are empty"); 86 } 87 this.availableDataViews = availableDataViews; 78 88 if ((subResources != null) && !subResources.isEmpty()) { 79 89 this.subResources = Collections.unmodifiableList(subResources); 80 90 } else { 81 91 this.subResources = null; 82 } 92 } 83 93 } 84 94 … … 101 111 * @return a number of items or <code>-1</code> if not applicable 102 112 */ 113 @Deprecated 103 114 public int getResourceCount() { 104 115 return resourceCount; … … 196 207 } 197 208 209 210 public List<String> getAvailableDataViews() { 211 return availableDataViews; 212 } 213 214 198 215 } // class ResourceInfo -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/SimpleEndpointSearchEngineBase.java
r2801 r5477 1 1 package eu.clarin.sru.server.fcs; 2 2 3 import java.util.ArrayList; 3 4 import java.util.Collections; 4 5 import java.util.List; … … 6 7 7 8 import javax.servlet.ServletContext; 8 import javax.xml.XMLConstants;9 9 import javax.xml.stream.XMLStreamException; 10 10 import javax.xml.stream.XMLStreamWriter; … … 36 36 public abstract class SimpleEndpointSearchEngineBase extends 37 37 SRUSearchEngineBase { 38 private static final String FCS_RESOURCE_INFO_NS = 39 "http://clarin.eu/fcs/1.0/resource-info"; 40 private static final String X_CMD_RESOURCE_INFO = "x-cmd-resource-info"; 38 39 // private static final String X_CMD_RESOURCE_INFO = "x-cmd-resource-info"; 40 private static final String X_FCS_ENDPOINT_DESCRIPTION = "x-fcs-endpoint-description"; 41 41 42 private static final String FCS_SCAN_INDEX_FCS_RESOURCE = "fcs.resource"; 42 43 private static final String FCS_SCAN_INDEX_CQL_SERVERCHOICE = "cql.serverChoice"; … … 47 48 LoggerFactory.getLogger(SimpleEndpointSearchEngineBase.class); 48 49 protected ResourceInfoInventory resourceInfoInventory; 49 50 51 /** 50 51 public List<String> capabilities; 52 public List<DataView> supportedDataViews; 53 54 public void addEndpointCapability(String c){ 55 capabilities.add(c); 56 } 57 58 public void addDataView(DataView d){ 59 supportedDataViews.add(d); 60 } 61 62 /** 52 63 * This method should not be overridden. Perform your custom initialization 53 64 * in the {@link #doInit(ServletContext, SRUServerConfig, Map)} method … … 61 72 logger.debug("initializing"); 62 73 super.init(context, config, params); 63 74 75 logger.debug("Setting basic capability"); 76 capabilities = new ArrayList<String>(); 77 capabilities.add("http://clarin.eu/fcs/capability/basic-search"); 78 79 logger.debug("Setting Generic Hits dataview"); 80 supportedDataViews = new ArrayList<DataView>(); 81 supportedDataViews.add( 82 new DataView("The representation of the hit", 83 "application/x-clarin-fcs-hits+xml", 84 DataView.PayloadDisposition.INLINE, 85 DataView.PayloadDelivery.SEND_BY_DEFAULT, 86 "hits") 87 ); 88 64 89 logger.debug("initializing search engine implementation"); 65 90 doInit(context, config, params); 66 91 67 92 logger.debug("initizalizing resource info inventory"); 68 93 this.resourceInfoInventory = createResourceInfoInventory(context, config, params); … … 97 122 throws SRUException { 98 123 final boolean provideResourceInfo = 99 parseBoolean(request.getExtraRequestData(X_ CMD_RESOURCE_INFO));124 parseBoolean(request.getExtraRequestData(X_FCS_ENDPOINT_DESCRIPTION)); 100 125 if (provideResourceInfo) { 101 126 final List<ResourceInfo> resourceInfoList = … … 112 137 public void writeExtraResponseData(XMLStreamWriter writer) 113 138 throws XMLStreamException { 114 writeFullResourceInfo(writer, null, resourceInfoList); 139 EndpointDescriptionWriter.writeEndpointDescription(writer, 140 capabilities, supportedDataViews, resourceInfoList); 141 //ResourceInfoWriter.writeFullResourceInfo(writer, null, resourceInfoList); 115 142 } 116 143 }; … … 130 157 */ 131 158 @Override 159 @Deprecated 132 160 public final SRUScanResultSet scan(SRUServerConfig config, 133 161 SRURequest request, SRUDiagnosticList diagnostics) … … 153 181 */ 154 182 final boolean provideResourceInfo = parseBoolean( 155 request.getExtraRequestData(X_ CMD_RESOURCE_INFO));183 request.getExtraRequestData(X_FCS_ENDPOINT_DESCRIPTION)); 156 184 157 185 return new SRUScanResultSet(diagnostics) { … … 198 226 throws XMLStreamException { 199 227 if (provideResourceInfo) { 200 writeResourceInfo(writer, null, result.get(idx));228 ResourceInfoWriter.writeResourceInfo(writer, null, result.get(idx)); 201 229 } 202 230 } … … 266 294 * SRUDiagnosticList) 267 295 */ 296 @Deprecated 268 297 protected SRUScanResultSet doScan(SRUServerConfig config, 269 298 SRURequest request, SRUDiagnosticList diagnostics) … … 301 330 } 302 331 303 332 @Deprecated 304 333 private List<ResourceInfo> translateFcsScanResource(CQLNode scanClause) 305 334 throws SRUException { … … 373 402 374 403 375 private static void writeFullResourceInfo(XMLStreamWriter writer, 376 String prefix, List<ResourceInfo> resourceInfoList) 377 throws XMLStreamException { 378 if (resourceInfoList == null) { 379 throw new NullPointerException("resourceInfoList == null"); 380 } 381 if (!resourceInfoList.isEmpty()) { 382 final boolean defaultNS = ((prefix == null) || prefix.isEmpty()); 383 if (defaultNS) { 384 writer.setDefaultNamespace(FCS_RESOURCE_INFO_NS); 385 } else { 386 writer.setPrefix(prefix, FCS_RESOURCE_INFO_NS); 387 } 388 writer.writeStartElement(FCS_RESOURCE_INFO_NS, "ResourceCollection"); 389 if (defaultNS) { 390 writer.writeDefaultNamespace(FCS_RESOURCE_INFO_NS); 391 } else { 392 writer.writeNamespace(prefix, FCS_RESOURCE_INFO_NS); 393 } 394 for (ResourceInfo resourceInfo : resourceInfoList) { 395 doWriteResourceInfo(writer, prefix, resourceInfo, false, true); 396 } 397 writer.writeEndElement(); // "ResourceCollection" element 398 } 399 } 400 401 402 private static void writeResourceInfo(XMLStreamWriter writer, String prefix, 403 ResourceInfo resourceInfo) throws XMLStreamException { 404 if (resourceInfo == null) { 405 throw new NullPointerException("resourceInfo == null"); 406 } 407 doWriteResourceInfo(writer, prefix, resourceInfo, true, false); 408 } 409 410 411 private static void doWriteResourceInfo(XMLStreamWriter writer, 412 String prefix, ResourceInfo resourceInfo, boolean writeNS, 413 boolean recursive) throws XMLStreamException { 414 final boolean defaultNS = ((prefix == null) || prefix.isEmpty()); 415 if (writeNS) { 416 if (defaultNS) { 417 writer.setDefaultNamespace(FCS_RESOURCE_INFO_NS); 418 } else { 419 writer.setPrefix(prefix, FCS_RESOURCE_INFO_NS); 420 } 421 } 422 writer.writeStartElement(FCS_RESOURCE_INFO_NS, "ResourceInfo"); 423 if (writeNS) { 424 if (defaultNS) { 425 writer.writeDefaultNamespace(FCS_RESOURCE_INFO_NS); 426 } else { 427 writer.writeNamespace(prefix, FCS_RESOURCE_INFO_NS); 428 } 429 } 430 if (recursive) { 431 /* 432 * HACK: only output @pid for recursive (= explain) requests. 433 * This should be revisited, if we decide to go for the explain 434 * style enumeration of resources. 435 */ 436 writer.writeAttribute("pid", resourceInfo.getPid()); 437 } 438 if (resourceInfo.hasSubResources()) { 439 writer.writeAttribute("hasSubResources", "true"); 440 } 441 442 final Map<String, String> title = resourceInfo.getTitle(); 443 for (Map.Entry<String, String> i : title.entrySet()) { 444 writer.setPrefix(XMLConstants.XML_NS_PREFIX, 445 XMLConstants.XML_NS_URI); 446 writer.writeStartElement(FCS_RESOURCE_INFO_NS, "Title"); 447 writer.writeAttribute(XMLConstants.XML_NS_URI, "lang", i.getKey()); 448 writer.writeCharacters(i.getValue()); 449 writer.writeEndElement(); // "title" element 450 } 451 452 final Map<String, String> description = resourceInfo.getDescription(); 453 if (description != null) { 454 for (Map.Entry<String, String> i : description.entrySet()) { 455 writer.writeStartElement(FCS_RESOURCE_INFO_NS, "Description"); 456 writer.writeAttribute(XMLConstants.XML_NS_URI, "lang", 457 i.getKey()); 458 writer.writeCharacters(i.getValue()); 459 writer.writeEndElement(); // "Description" element 460 } 461 } 462 463 final String landingPageURI = resourceInfo.getLandingPageURI(); 464 if (landingPageURI != null) { 465 writer.writeStartElement(FCS_RESOURCE_INFO_NS, "LandingPageURI"); 466 writer.writeCharacters(landingPageURI); 467 writer.writeEndElement(); // "LandingPageURI" element 468 } 469 470 final List<String> languages = resourceInfo.getLanguages(); 471 writer.writeStartElement(FCS_RESOURCE_INFO_NS, "Languages"); 472 for (String i : languages) { 473 writer.writeStartElement(FCS_RESOURCE_INFO_NS, "Language"); 474 writer.writeCharacters(i); 475 writer.writeEndElement(); // "Language" element 476 477 } 478 writer.writeEndElement(); // "Languages" element 479 480 if (recursive && resourceInfo.hasSubResources()) { 481 writer.writeStartElement(FCS_RESOURCE_INFO_NS, 482 "ResourceInfoCollection"); 483 for (ResourceInfo r : resourceInfo.getSubResources()) { 484 doWriteResourceInfo(writer, prefix, r, writeNS, recursive); 485 } 486 writer.writeEndElement(); // "ResourceCollection" element 487 } 488 writer.writeEndElement(); // "ResourceInfo" element 489 } 404 490 405 491 406 } // class SimpleEndpointSearchEngineBase -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/SimpleFcsResourceWriter.java
r5474 r5477 4 4 import javax.xml.stream.XMLStreamWriter; 5 5 6 public class FCSResultWriter {6 public class SimpleFcsResourceWriter { 7 7 private static final String FCS_NS = "http://clarin.eu/fcs/resource"; 8 8 private static final String FCS_PREFIX = "fcs"; -
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleResourceInfoInventoryParser.java
r2751 r5477 4 4 import java.net.URL; 5 5 import java.util.ArrayList; 6 import java.util.Arrays; 6 7 import java.util.HashMap; 7 8 import java.util.HashSet; … … 27 28 import org.w3c.dom.Document; 28 29 import org.w3c.dom.Element; 30 import org.w3c.dom.Node; 29 31 import org.w3c.dom.NodeList; 30 32 import org.xml.sax.SAXException; … … 44 46 */ 45 47 public class SimpleResourceInfoInventoryParser { 46 private static final String NS = "http://clarin.eu/fcs/ 1.0/resource-info";48 private static final String NS = "http://clarin.eu/fcs/endpoint-description"; 47 49 private static final String LANG_EN = "en"; 48 50 private static final Logger logger = … … 103 105 }); 104 106 XPathExpression expression = 105 xpath.compile("/ri:Resource Collection/ri:ResourceInfo");107 xpath.compile("/ri:Resources/ri:Resource"); 106 108 NodeList list = 107 109 (NodeList) expression.evaluate(doc, XPathConstants.NODESET); … … 137 139 String link = null; 138 140 List<String> langs = null; 141 String[] availableDataViews = null; 139 142 List<ResourceInfo> sub = null; 140 143 … … 262 265 } 263 266 } 264 267 268 XPathExpression x6 = xpath.compile("ri:AvailableDataViews/@ref"); 269 String ref = (String) x6.evaluate(node, XPathConstants.STRING); 270 271 if (ref == null || ref.isEmpty()){ 272 throw new SRUConfigException("Element <AvailableDataViews> " + 273 "must have a non-empty attribute ref."); 274 } 275 276 availableDataViews = ref.split("\\s+"); 277 278 265 279 XPathExpression x5 = 266 xpath.compile("ri:Resource Collection/ri:ResourceInfo");280 xpath.compile("ri:Resources/ri:Resource"); 267 281 NodeList l5 = (NodeList) x5.evaluate(node, XPathConstants.NODESET); 268 282 if ((l5 != null) && (l5.getLength() > 0)) { … … 274 288 } 275 289 ris.add(new ResourceInfo(pid, resourceCount, titles, descrs, link, 276 langs, sub));290 langs, Arrays.asList(availableDataViews),sub)); 277 291 } 278 292 return ris;
Note: See TracChangeset
for help on using the changeset viewer.