Changeset 7171 for SRUClient


Ignore:
Timestamp:
03/22/18 20:46:25 (6 years ago)
Author:
Oliver Schonefeld
Message:
  • fix parsing of SRU 2.0 responses that include a record identifier
Location:
SRUClient/trunk/src/main/java/eu/clarin/sru/client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSimpleClient.java

    r7094 r7171  
    511511                // XXX: what to do with it?
    512512                SRURecordPacking recordPacking = null;
    513                 if (version == SRUVersion.VERSION_2_0) {
     513                if (version.isVersion(SRUVersion.VERSION_2_0)) {
    514514                    recordPacking = parseRecordPacking(reader,
    515515                            ns.sruNS(), strictMode);
    516516                }
    517517
     518                // recordXmlEscaping (used to be recordPacking in SRU 1.0/1.2)
    518519                if (recordXmlEscaping == null) {
    519520                    recordXmlEscaping = parseRecordXmlEscaping(reader, ns,
     
    571572                reader.readEnd(ns.sruNS(), "recordData", true);
    572573
    573                 if (version == SRUVersion.VERSION_1_2) {
     574                if (version.isVersion(SRUVersion.VERSION_1_2,
     575                        SRUVersion.VERSION_2_0)) {
    574576                    reader.readContent(ns.sruNS(), "recordIdentifier", false);
    575577                }
     
    967969                            // XXX: what to do with it?
    968970                            SRURecordPacking recordPacking = null;
    969                             if (version == SRUVersion.VERSION_2_0) {
     971                            if (version.isVersion(SRUVersion.VERSION_2_0)) {
    970972                                recordPacking = parseRecordPacking(reader,
    971973                                        ns.sruNS(), strictMode);
     
    10851087
    10861088                            String identifier = null;
    1087                             if (version == SRUVersion.VERSION_1_2) {
     1089                            if (version.isVersion(SRUVersion.VERSION_1_2,
     1090                                    SRUVersion.VERSION_2_0)) {
    10881091                                identifier = reader.readContent(ns.sruNS(),
    10891092                                        "recordIdentifier", false);
     
    12211224                }
    12221225
    1223                 if (version == SRUVersion.VERSION_2_0) {
     1226                if (version.isVersion(SRUVersion.VERSION_2_0)) {
    12241227                    // SRU (2.0) arbitrary stuff
    12251228                    // SRU (2.0) resultSetTTL (replaces resultSetIdleTime)
     
    13731376            throws XMLStreamException, SRUClientException {
    13741377
    1375         final String name = (version == SRUVersion.VERSION_2_0)
     1378        final String name = version.isVersion(SRUVersion.VERSION_2_0)
    13761379                          ? "recordXMLEscaping" : "recordPacking";
    13771380        final String s = reader.readContent(ns.sruNS(), name, true);
  • SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUVersion.java

    r6938 r7171  
    2424     * SRU/CQL version 1.1
    2525     */
    26     VERSION_1_1,
     26    VERSION_1_1 {
     27        @Override
     28        public int getVersionNumber() {
     29            return ((1 << 16) | 1);
     30        }
     31    },
    2732
    2833    /**
    2934     * SRU/CQL version 1.2
    3035     */
    31     VERSION_1_2,
     36    VERSION_1_2 {
     37        @Override
     38        public int getVersionNumber() {
     39            return ((1 << 16) | 2);
     40        }
     41    },
    3242
    3343    /**
    3444     * SRU/CQL version 2.0
    3545     */
    36     VERSION_2_0;
     46    VERSION_2_0 {
     47        @Override
     48        public int getVersionNumber() {
     49            return ((2 << 16) | 0);
     50        }
     51    };
     52
     53   
     54    /**
     55     * Get a numerical representation of the version.
     56     *
     57     * @return numerical representation of the version
     58     */
     59    public abstract int getVersionNumber();
     60   
     61
     62    public boolean isVersion(SRUVersion version) {
     63        if (version == null) {
     64            throw new NullPointerException("version == null");
     65        }
     66        return (this == version);
     67    }
     68
     69
     70    public boolean isVersion(SRUVersion min, SRUVersion max) {
     71        if (min == null) {
     72            throw new NullPointerException("min == null");
     73        }
     74        if (max == null) {
     75            throw new NullPointerException("max == null");
     76        }
     77        return ((this.getVersionNumber() >= min.getVersionNumber()) &
     78                (this.getVersionNumber() <= max.getVersionNumber()));
     79    }
    3780
    3881} // enum SRUVersion
Note: See TracChangeset for help on using the changeset viewer.