Ignore:
Timestamp:
01/12/16 21:03:47 (8 years ago)
Author:
Oliver Schonefeld
Message:
  • some steps towards SRU 2.0
File:
1 edited

Legend:

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

    r5750 r6903  
    4343            "x-malformed-maximumRecords";
    4444    /** for end-point conformance testing only. never use in production. */
    45     public static final String X_MALFORMED_RECORD_PACKING =
     45    public static final String X_MALFORMED_RECORD_XML_ESCAPING =
    4646            "x-malformed-recordPacking";
     47    private String queryType;
    4748    private String query;
    4849    private int startRecord = -1;
    4950    private int maximumRecords = -1;
     51    private SRURecordXmlEscaping recordXmlEscaping;
    5052    private SRURecordPacking recordPacking;
    5153    private String recordSchema;
     
    7274    public SRUSearchRetrieveRequest(String baseURI) {
    7375        super(baseURI);
     76    }
     77
     78
     79    /**
     80     * (SRU 2.0) Get the value of the <em>queryType</em> argument for this
     81     * request.
     82     *
     83     * @return the value for the <em>queryType</em> argument or
     84     *         <code>null</code> of none was set
     85     */
     86    public String getQueryType() {
     87        return queryType;
     88    }
     89
     90
     91    /**
     92     * (SRU 2.0) Set the value of the <em>queryType</em> argument for this
     93     * request.
     94     *
     95     * @param queryType
     96     *            the value for the <em>queryType</em> argument
     97     * @throws NullPointerException
     98     *             if any required argument is <code>null</code>
     99     * @throws IllegalArgumentException
     100     *             if any argument is invalid
     101     */
     102    public void setQueryType(String queryType) {
     103        if (queryType == null) {
     104            throw new NullPointerException("queryType == null");
     105        }
     106        if (queryType.isEmpty()) {
     107            throw new IllegalArgumentException("queryType is an empty string");
     108        }
     109        for (int i = 0; i < queryType.length(); i++) {
     110            final char ch = queryType.charAt(i);
     111            if (!((ch >= 'a' && ch <= 'z') ||
     112                    (ch >= 'A' && ch <= 'Z') ||
     113                    (ch >= '0' && ch <= '9') ||
     114                    ((i > 0) && ((ch == '-') || ch == '_')))) {
     115                throw new IllegalArgumentException(
     116                        "queryType contains illegal characters");
     117            }
     118        }
     119        this.queryType = queryType;
    74120    }
    75121
     
    188234
    189235    /**
    190      * Get the value of the <em>recordSchema</em> argument for this request.
    191      *
    192      * @return the value for the <em>recordSchema</em> argument or
    193      *         <code>null</code> of none was set
     236     * Get the <em>recordXmlEscpaing</em> (SRU 2.0) or <em>recordPacking</em>
     237     * (SRU 1.1 and SRU 1.2) parameter of this request.
     238     *
     239     * @return the requested record XML escaping
     240     * @see SRURecordXmlEscaping
     241     */
     242    public SRURecordXmlEscaping getRecordXmlEscaping() {
     243        return recordXmlEscaping;
     244    }
     245
     246
     247    /**
     248     * Set the <em>recordXmlEscpaing</em> (SRU 2.0) or <em>recordPacking</em>
     249     * (SRU 1.1 and SRU 1.2) parameter of this request.
     250     *
     251     * @param recordXmlEscaping
     252     *            the requested record XML escaping
     253     * @see SRURecordXmlEscaping
     254     */
     255    public void setRecordXmlEscaping(SRURecordXmlEscaping recordXmlEscaping) {
     256        if (recordXmlEscaping == null) {
     257            throw new NullPointerException("recordXmlEscaping == null");
     258        }
     259        this.recordXmlEscaping = recordXmlEscaping;
     260    }
     261
     262
     263    /**
     264     * Get the <em>recordPacking</em> (SRU 2.0) parameter of this request.
     265     *
     266     * @return the requested record packing
     267     * @see SRURecordPacking
    194268     */
    195269    public SRURecordPacking getRecordPacking() {
     
    199273
    200274    /**
    201      * Set the value of the <em>recordPacking</em> argument for this request.
    202      *
    203      * @param recordPacking
    204      *            the value for the <em>recordPacking</em> argument
    205      * @throws NullPointerException
    206      *             if any required argument is <code>null</code>
     275     * Set the <em>recordPacking</em> (SRU 2.0) parameter of this request.
     276     *
     277     * @param getRecordXmlEscaping
     278     *            the requested record XML escaping
     279     * @see SRURecordXmlEscaping
    207280     */
    208281    public void setRecordPacking(SRURecordPacking recordPacking) {
     
    245318
    246319    @Override
    247     void addParametersToURI(URIHelper uriHelper) throws SRUClientException {
     320    void addParametersToURI(URIHelper uriHelper, SRUVersion version)
     321            throws SRUClientException {
    248322        /*
    249323         * append query argument (mandatory)
     
    268342
    269343        /*
     344         * append queryType parameter (SRU 2.0, optional)
     345         */
     346        if ((version == SRUVersion.VERSION_2_0) && (queryType != null)) {
     347            if (!SRUClientConstants.QUERY_TYPE_CQL.equals(queryType)) {
     348                uriHelper.append(PARAM_QUERY_TYPE, queryType);
     349            }
     350        }
     351
     352        /*
    270353         * append startRecord argument (optional)
    271354         *
     
    309392
    310393        /*
    311          * append recordPacking argument (optional)
     394         * append record XML escaping argument (optional)
    312395         *
    313396         * NB: Setting "x-malformed-recordPacking" as an extra request
     
    316399         * (i.e. provoke an error) and SHOULD NEVER be used in production!
    317400         */
    318         final String malformedRecordPacking =
    319                 getExtraRequestData(X_MALFORMED_RECORD_PACKING);
    320         if (malformedRecordPacking == null) {
    321             if (recordPacking != null) {
    322                 switch (recordPacking) {
     401        final String malformedRecordXmlEscaping =
     402                getExtraRequestData(X_MALFORMED_RECORD_XML_ESCAPING);
     403        if (malformedRecordXmlEscaping == null) {
     404            if (recordXmlEscaping != null) {
     405                switch (recordXmlEscaping) {
    323406                case XML:
    324                     uriHelper.append(PARAM_RECORD_PACKING, RECORD_PACKING_XML);
     407                    if (version == SRUVersion.VERSION_2_0) {
     408                        uriHelper.append(PARAM_RECORD_XML_ESCAPING,
     409                                RECORD_XML_ESCAPING_XML);
     410                    } else {
     411                        uriHelper.append(PARAM_RECORD_PACKING,
     412                                RECORD_XML_ESCAPING_XML);
     413                    }
    325414                    break;
    326415                case STRING:
    327                     uriHelper.append(PARAM_RECORD_PACKING,
    328                             RECORD_PACKING_STRING);
     416                    if (version == SRUVersion.VERSION_2_0) {
     417                        uriHelper.append(PARAM_RECORD_XML_ESCAPING,
     418                                RECORD_XML_ESCPAING_STRING);
     419                    } else {
     420                        uriHelper.append(PARAM_RECORD_PACKING,
     421                                RECORD_XML_ESCPAING_STRING);
     422                    }
    329423                    break;
    330424                default:
    331425                    throw new SRUClientException(
    332                             "unsupported record packing: " + recordPacking);
     426                            "unsupported record XML escpaing: " + recordXmlEscaping);
    333427                } // switch
    334428            }
    335429        } else {
    336             if (!malformedRecordPacking.equalsIgnoreCase(MALFORMED_OMIT)) {
    337                 uriHelper.append(PARAM_RECORD_PACKING, malformedRecordPacking);
    338             }
     430            if (!malformedRecordXmlEscaping.equalsIgnoreCase(MALFORMED_OMIT)) {
     431                if (version == SRUVersion.VERSION_2_0) {
     432                    uriHelper.append(PARAM_RECORD_XML_ESCAPING,
     433                            malformedRecordXmlEscaping);
     434                } else {
     435                    uriHelper.append(PARAM_RECORD_PACKING,
     436                            malformedRecordXmlEscaping);
     437                }
     438            }
     439        }
     440
     441        /*
     442         * (SRU 2.0) append recordPacking argument (optional)
     443         */
     444        if ((version == SRUVersion.VERSION_2_0) && (recordPacking != null)) {
     445            String s = null;
     446            switch (recordPacking) {
     447            case PACKED:
     448                s = "packed";
     449                break;
     450            case UNPACKED:
     451                s = "unpacked";
     452                break;
     453            }
     454            uriHelper.append(PARAM_RECORD_PACKING, s);
    339455        }
    340456
Note: See TracChangeset for help on using the changeset viewer.