Changeset 5477 for FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/SimpleEndpointSearchEngineBase.java
- Timestamp:
- 07/11/14 15:29:52 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.