Changeset 5670


Ignore:
Timestamp:
09/23/14 06:53:21 (10 years ago)
Author:
Oliver Schonefeld
Message:
  • work-in-progress
Location:
FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/DataView.java

    r5546 r5670  
    5959
    6060
     61    /**
     62     * Get the identifier of this data view.
     63     *
     64     * @return the identifier of the data view
     65     */
    6166    public String getIdentifier() {
    6267        return identifier;
     
    6469
    6570
     71    /**
     72     * Get the MIME type of this data view.
     73     *
     74     * @return the MIME type of this data view
     75     */
    6676    public String getMimeType() {
    6777        return mimeType;
     
    6979
    7080
     81    /**
     82     * Get the delivery policy for this data view.
     83     *
     84     * @return the delivery policy of this data view
     85     * @see DeliveryPolicy
     86     */
    7187    public DeliveryPolicy getDeliveryPolicy() {
    7288        return deliveryPolicy;
     
    84100        return sb.toString();
    85101    }
     102
    86103} // class DataView
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/SimpleEndpointSearchEngineBase.java

    r5547 r5670  
    3737public abstract class SimpleEndpointSearchEngineBase extends
    3838        SRUSearchEngineBase {
     39    private static final String FCS_DISABLE_LEGECY_MODE =
     40            "eu.clarin.sru.server.fcs.disableLegacyMode";
    3941    private static final String X_FCS_ENDPOINT_DESCRIPTION = "x-fcs-endpoint-description";
    4042    private static final String X_CMD_RESOURCE_INFO = "x-cmd-resource-info";
     
    5153            LoggerFactory.getLogger(SimpleEndpointSearchEngineBase.class);
    5254    protected EndpointDescription endpointDescription;
     55    private boolean disableLegecyMode;
    5356
    5457
     
    7881                    "returned no valid implementation of an EndpointDescription");
    7982        }
     83
     84        if (params.containsKey(FCS_DISABLE_LEGECY_MODE)) {
     85            logger.info("disabling FCS legacy mode");
     86            this.disableLegecyMode = false;
     87        } else {
     88            this.disableLegecyMode = true;
     89        }
    8090    }
    8191
     
    138148            SRURequest request, SRUDiagnosticList diagnostics)
    139149            throws SRUException {
    140         /*
    141          * Check if we got a scan on fcs.resource. If yes, handle it
    142          * accordingly, otherwise delegate to user-provided implementation.
    143          */
    144         final List<ResourceInfo> result =
    145                 translateFcsScanResource(request.getScanClause());
    146         if (result != null) {
     150
     151        if (isLegacyMode()) {
    147152            /*
    148              * Make sure, we honor the maximumTerms limit, of the client
    149              * requests it ...
     153             * Check if we got a scan on fcs.resource. If yes, handle it
     154             * accordingly, otherwise delegate to user-provided implementation.
    150155             */
    151             final int maxTerms
    152                 = ((result.size() > 0) && (request.getMaximumTerms() > 0))
    153                 ? Math.min(result.size(), request.getMaximumTerms())
    154                 : result.size();
    155 
    156             /*
    157              * Shall we provide extended resource information ... ?
    158              */
    159             final boolean provideResourceInfo = parseBoolean(
    160                     request.getExtraRequestData(X_CMD_RESOURCE_INFO));
    161 
    162             return new SRUScanResultSet(diagnostics) {
    163                 private int idx = -1;
    164 
    165                 @Override
    166                 public boolean nextTerm() {
    167                     return (result != null) && (++idx < maxTerms);
    168                 }
    169 
    170 
    171                 @Override
    172                 public String getValue() {
    173                     return result.get(idx).getPid();
    174                 }
    175 
    176 
    177                 @Override
    178                 public int getNumberOfRecords() {
    179                     return -1;
    180                 }
    181 
    182 
    183                 @Override
    184                 public String getDisplayTerm() {
    185                     return result.get(idx).getTitle("en");
    186                 }
    187 
    188 
    189                 @Override
    190                 public WhereInList getWhereInList() {
    191                     return null;
    192                 }
    193 
    194 
    195                 @Override
    196                 public boolean hasExtraTermData() {
    197                     return provideResourceInfo;
    198                 }
    199 
    200 
    201                 @Override
    202                 public void writeExtraTermData(XMLStreamWriter writer)
    203                         throws XMLStreamException {
    204                     if (provideResourceInfo) {
    205                         writeLegacyResourceInfo(writer, result.get(idx));
    206                     }
    207                 }
    208             };
     156            final List<ResourceInfo> result = translateFcsScanResource(request
     157                    .getScanClause());
     158            if (result != null) {
     159                /*
     160                 * Make sure, we honor the maximumTerms limit, of the client
     161                 * requests it ...
     162                 */
     163                final int maxTerms = ((result.size() > 0) && (request
     164                        .getMaximumTerms() > 0)) ? Math.min(result.size(),
     165                        request.getMaximumTerms()) : result.size();
     166
     167                /*
     168                 * Shall we provide extended resource information ... ?
     169                 */
     170                final boolean provideResourceInfo = parseBoolean(request
     171                        .getExtraRequestData(X_CMD_RESOURCE_INFO));
     172
     173                return new SRUScanResultSet(diagnostics) {
     174                    private int idx = -1;
     175
     176
     177                    @Override
     178                    public boolean nextTerm() {
     179                        return (result != null) && (++idx < maxTerms);
     180                    }
     181
     182
     183                    @Override
     184                    public String getValue() {
     185                        return result.get(idx).getPid();
     186                    }
     187
     188
     189                    @Override
     190                    public int getNumberOfRecords() {
     191                        return -1;
     192                    }
     193
     194
     195                    @Override
     196                    public String getDisplayTerm() {
     197                        return result.get(idx).getTitle("en");
     198                    }
     199
     200
     201                    @Override
     202                    public WhereInList getWhereInList() {
     203                        return null;
     204                    }
     205
     206
     207                    @Override
     208                    public boolean hasExtraTermData() {
     209                        return provideResourceInfo;
     210                    }
     211
     212
     213                    @Override
     214                    public void writeExtraTermData(XMLStreamWriter writer)
     215                            throws XMLStreamException {
     216                        if (provideResourceInfo) {
     217                            writeLegacyResourceInfo(writer, result.get(idx));
     218                        }
     219                    }
     220                };
     221            } else {
     222                return doScan(config, request, diagnostics);
     223            }
    209224        } else {
    210225            return doScan(config, request, diagnostics);
     
    543558    }
    544559
     560
     561    /**
     562     * Check, if running in legacy mode. Only intended for comparability with
     563     * legacy clients until the new CLARIN-FCS specification is deployed on a
     564     * larger scale.
     565     *
     566     * @return <code>true</code> if running in legacy mode, <code>false</code>
     567     *         otherwise
     568     */
     569    protected boolean isLegacyMode() {
     570        return !disableLegecyMode;
     571    }
     572
    545573} // class SimpleEndpointSearchEngineBase
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/XMLStreamWriterHelper.java

    r5546 r5670  
    1616 */
    1717public final class XMLStreamWriterHelper {
    18     private static final String FCS_NS          = "http://clarin.eu/fcs/1.0";
    19     private static final String FCS_PREFIX      = "fcs";
     18    private static final String FCS_NS          =
     19            "http://clarin.eu/fcs/resource";
     20    private static final String FCS_PREFIX      =
     21            "fcs";
    2022    private static final String FCS_KWIC_NS     =
    2123            "http://clarin.eu/fcs/1.0/kwic";
    22     private static final String FCS_KWIC_PREFIX = "kwic";
     24    private static final String FCS_KWIC_PREFIX =
     25            "kwic";
    2326    private static final String FCS_KWIC_MIMETYPE =
    2427            "application/x-clarin-fcs-kwic+xml";
    2528    private static final String FCS_HITS_NS =
    2629            "http://clarin.eu/fcs/dataview/hits";
    27     private static final String FCS_HITS_PREFIX = "hits";
     30    private static final String FCS_HITS_PREFIX =
     31            "hits";
    2832    private static final String FCS_HITS_MIMETYPE =
    2933            "application/x-clarin-fcs-hits+xml";
     
    354358
    355359    /**
    356      * Convince method for writing a record with a KWIC data view. The following
     360     * Convince method for writing a record with a HITS data view. The following
    357361     * code (arguments omitted) would accomplish the same result:
    358362     *
     
    528532    }
    529533
     534
     535    /**
     536     * Convince method for writing a record with a HITS and a KWIC data view.
     537     * This method is intended for applications that want ensure computability
     538     * to legacy CLARIN-FCS clients The following code (arguments omitted) would
     539     * accomplish the same result:
     540     *
     541     * <pre>
     542     * ...
     543     * writeStartResource(...);
     544     * writeHitsDataView(...);
     545     * writeKWICDataView(...);
     546     * writeEndResource(...);
     547     * ...
     548     * </pre>
     549     *
     550     * @param writer
     551     *            the {@link XMLStreamWriter} to be used
     552     * @param pid
     553     *            the persistent identifier of this resource or
     554     *            <code>null</code>, if not applicable
     555     * @param ref
     556     *            the reference of this resource or <code>null</code>, if not
     557     *            applicable
     558     * @param left
     559     *            the left context of the hit or <code>null</code> if not
     560     *            applicable
     561     * @param hit
     562     *            the actual hit, that will be highlighted
     563     * @param right
     564     *            the right context of the hit or <code>null</code> if not
     565     *            applicable
     566     * @throws XMLStreamException
     567     *             if an error occurred
     568     * @deprecated Only use, if you want compatability to legacy FCS
     569     *             applications.
     570     */
     571    @Deprecated
     572    public static void writeResourceWithHitsDataViewLegacy(XMLStreamWriter writer,
     573            String pid, String ref, String left, String hit, String right)
     574            throws XMLStreamException {
     575        if (writer == null) {
     576            throw new NullPointerException("writer == null");
     577        }
     578
     579        writeStartResource(writer, pid, ref);
     580        writeHitsDataView(writer, left, hit, right);
     581        writeKWICDataView(writer, left, hit, right);
     582        writeEndResource(writer);
     583    }
     584
    530585} // class XMLStreamWriterHelper
  • FCSSimpleEndpoint/trunk/src/main/java/eu/clarin/sru/server/fcs/utils/AbstractEndpointDescriptionBase.java

    r5546 r5670  
    3636            throw new IllegalArgumentException("capabilities are empty");
    3737        }
     38        for (URI capability : capabilities) {
     39            if (capability == null) {
     40                throw new IllegalArgumentException(
     41                        "capabilities must not contain a 'null' item");
     42            }
     43        }
    3844        this.capabilities = Collections.unmodifiableList(capabilities);
    3945
     
    4349        if (supportedDataViews.isEmpty()) {
    4450            throw new IllegalArgumentException("supportedDataViews are empty");
     51        }
     52        for (DataView supportedDataView : supportedDataViews) {
     53            if (supportedDataView == null) {
     54                throw new IllegalArgumentException(
     55                        "supportedDataViews must not contain a 'null' item");
     56            }
    4557        }
    4658        this.supportedDataViews =
Note: See TracChangeset for help on using the changeset viewer.