Changeset 5477


Ignore:
Timestamp:
07/11/14 15:29:52 (10 years ago)
Author:
margaretha@ids-mannheim.de
Message:

Added endpoint description,
updated SimpleResourceInfoInventory? according to the new format.

Location:
FCSSimpleEndpoint/trunk
Files:
3 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • FCSSimpleEndpoint/trunk/pom.xml

    r2803 r5477  
    44    <groupId>eu.clarin.sru.fcs</groupId>
    55    <artifactId>fcs-simple-endpoint</artifactId>
    6     <version>1.3.0-SNAPSHOT</version>
     6    <version>2.0-SNAPSHOT</version>
    77    <packaging>jar</packaging>
    88    <name>A simple CLARIN FCS endpoint</name>
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/ResourceInfo.java

    r2751 r5477  
    1414public class ResourceInfo {
    1515    private final String pid;
     16    @Deprecated
    1617    private final int resourceCount;
    1718    private final Map<String, String> title;
     
    1920    private final String landingPageURI;
    2021    private final List<String> languages;
     22    private final List<String> availableDataViews;
    2123    private List<ResourceInfo> subResources;
    22 
     24   
    2325
    2426    /**
     
    5052            Map<String, String> title, Map<String, String> description,
    5153            String landingPageURI, List<String> languages,
     54            List<String> availableDataViews,
    5255            List<ResourceInfo> subResources) {
    5356        if (pid == null) {
     
    7679        }
    7780        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;
    7888        if ((subResources != null) && !subResources.isEmpty()) {
    7989            this.subResources = Collections.unmodifiableList(subResources);
    8090        } else {
    8191            this.subResources = null;
    82         }
     92        }       
    8393    }
    8494
     
    101111     * @return a number of items or <code>-1</code> if not applicable
    102112     */
     113    @Deprecated
    103114    public int getResourceCount() {
    104115        return resourceCount;
     
    196207    }
    197208
     209
     210        public List<String> getAvailableDataViews() {
     211                return availableDataViews;
     212        }
     213
     214
    198215} // class ResourceInfo
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/SimpleEndpointSearchEngineBase.java

    r2801 r5477  
    11package eu.clarin.sru.server.fcs;
    22
     3import java.util.ArrayList;
    34import java.util.Collections;
    45import java.util.List;
     
    67
    78import javax.servlet.ServletContext;
    8 import javax.xml.XMLConstants;
    99import javax.xml.stream.XMLStreamException;
    1010import javax.xml.stream.XMLStreamWriter;
     
    3636public abstract class SimpleEndpointSearchEngineBase extends
    3737        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   
    4142    private static final String FCS_SCAN_INDEX_FCS_RESOURCE = "fcs.resource";
    4243    private static final String FCS_SCAN_INDEX_CQL_SERVERCHOICE = "cql.serverChoice";
     
    4748            LoggerFactory.getLogger(SimpleEndpointSearchEngineBase.class);
    4849    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        /**
    5263     * This method should not be overridden. Perform your custom initialization
    5364     * in the {@link #doInit(ServletContext, SRUServerConfig, Map)} method
     
    6172        logger.debug("initializing");
    6273        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       
    6489        logger.debug("initializing search engine implementation");
    6590        doInit(context, config, params);
    66 
     91               
    6792        logger.debug("initizalizing resource info inventory");
    6893        this.resourceInfoInventory = createResourceInfoInventory(context, config, params);
     
    97122            throws SRUException {
    98123        final boolean provideResourceInfo =
    99                 parseBoolean(request.getExtraRequestData(X_CMD_RESOURCE_INFO));
     124                parseBoolean(request.getExtraRequestData(X_FCS_ENDPOINT_DESCRIPTION));
    100125        if (provideResourceInfo) {
    101126            final List<ResourceInfo> resourceInfoList =
     
    112137                public void writeExtraResponseData(XMLStreamWriter writer)
    113138                        throws XMLStreamException {
    114                     writeFullResourceInfo(writer, null, resourceInfoList);
     139                        EndpointDescriptionWriter.writeEndpointDescription(writer,
     140                                        capabilities, supportedDataViews, resourceInfoList);
     141                    //ResourceInfoWriter.writeFullResourceInfo(writer, null, resourceInfoList);
    115142                }
    116143            };
     
    130157     */
    131158    @Override
     159    @Deprecated
    132160    public final SRUScanResultSet scan(SRUServerConfig config,
    133161            SRURequest request, SRUDiagnosticList diagnostics)
     
    153181             */
    154182            final boolean provideResourceInfo = parseBoolean(
    155                     request.getExtraRequestData(X_CMD_RESOURCE_INFO));
     183                    request.getExtraRequestData(X_FCS_ENDPOINT_DESCRIPTION));
    156184
    157185            return new SRUScanResultSet(diagnostics) {
     
    198226                        throws XMLStreamException {
    199227                    if (provideResourceInfo) {
    200                         writeResourceInfo(writer, null, result.get(idx));
     228                        ResourceInfoWriter.writeResourceInfo(writer, null, result.get(idx));
    201229                    }
    202230                }
     
    266294     *      SRUDiagnosticList)
    267295     */
     296    @Deprecated
    268297    protected SRUScanResultSet doScan(SRUServerConfig config,
    269298            SRURequest request, SRUDiagnosticList diagnostics)
     
    301330    }
    302331
    303 
     332    @Deprecated
    304333    private List<ResourceInfo> translateFcsScanResource(CQLNode scanClause)
    305334            throws SRUException {
     
    373402
    374403
    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   
    490405
    491406} // class SimpleEndpointSearchEngineBase
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/SimpleFcsResourceWriter.java

    r5474 r5477  
    44import javax.xml.stream.XMLStreamWriter;
    55
    6 public class FCSResultWriter {
     6public class SimpleFcsResourceWriter {
    77        private static final String FCS_NS = "http://clarin.eu/fcs/resource";
    88    private static final String FCS_PREFIX = "fcs";
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/utils/SimpleResourceInfoInventoryParser.java

    r2751 r5477  
    44import java.net.URL;
    55import java.util.ArrayList;
     6import java.util.Arrays;
    67import java.util.HashMap;
    78import java.util.HashSet;
     
    2728import org.w3c.dom.Document;
    2829import org.w3c.dom.Element;
     30import org.w3c.dom.Node;
    2931import org.w3c.dom.NodeList;
    3032import org.xml.sax.SAXException;
     
    4446 */
    4547public 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";
    4749    private static final String LANG_EN = "en";
    4850    private static final Logger logger =
     
    103105            });
    104106            XPathExpression expression =
    105                     xpath.compile("/ri:ResourceCollection/ri:ResourceInfo");
     107                    xpath.compile("/ri:Resources/ri:Resource");
    106108            NodeList list =
    107109                    (NodeList) expression.evaluate(doc, XPathConstants.NODESET);
     
    137139            String link = null;
    138140            List<String> langs = null;
     141            String[] availableDataViews = null;
    139142            List<ResourceInfo> sub = null;
    140143
     
    262265                }
    263266            }
    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           
    265279            XPathExpression x5 =
    266                     xpath.compile("ri:ResourceCollection/ri:ResourceInfo");
     280                    xpath.compile("ri:Resources/ri:Resource");
    267281            NodeList l5 = (NodeList) x5.evaluate(node, XPathConstants.NODESET);
    268282            if ((l5 != null) && (l5.getLength() > 0)) {
     
    274288            }
    275289            ris.add(new ResourceInfo(pid, resourceCount, titles, descrs, link,
    276                     langs, sub));
     290                    langs, Arrays.asList(availableDataViews),sub));
    277291        }
    278292        return ris;
Note: See TracChangeset for help on using the changeset viewer.