Changeset 6816


Ignore:
Timestamp:
11/17/15 12:28:02 (9 years ago)
Author:
Oliver Schonefeld
Message:
  • first step towards SRU 2.0 argument parsing and response serialization
Location:
SRUServer/trunk/src/main/java/eu/clarin/sru/server
Files:
2 added
9 edited
1 copied

Legend:

Unmodified
Added
Removed
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUConstants.java

    r5924 r6816  
    155155    public static final String SRU_RECORD_TOO_LARGE_TO_SEND =
    156156            SRU_DIAGNOSTIC_URI_PREFIX + 70;
    157     public static final String SRU_UNSUPPORTED_RECORD_PACKING =
     157    public static final String SRU_UNSUPPORTED_XML_ESCAPING_VALUE =
    158158            SRU_DIAGNOSTIC_URI_PREFIX + 71;
    159159    public static final String SRU_XPATH_RETRIEVAL_UNSUPPORTED =
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUDiagnostic.java

    r5924 r6816  
    257257        } else if (uri.equals(SRUConstants.SRU_RECORD_TOO_LARGE_TO_SEND)) {
    258258            return "Record too large to send";
    259         } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_RECORD_PACKING)) {
     259        } else if (uri.equals(SRUConstants.SRU_UNSUPPORTED_XML_ESCAPING_VALUE)) {
    260260            return "Unsupported record packing";
    261261        } else if (uri.equals(SRUConstants.SRU_XPATH_RETRIEVAL_UNSUPPORTED)) {
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRURecordPacking.java

    r2623 r6816  
    1818
    1919/**
    20  * SRU Record packing
     20 * SRU 2.0 record packing.
    2121 */
    2222public enum SRURecordPacking {
    2323    /**
    24      * XML record packing
     24     * The client requests that the server should supply records strictly
     25     * according to the requested schema.
    2526     */
    26     XML,
     27    PACKED,
    2728
    2829    /**
    29      * String record packing
     30     * The server is free to allow the location of application data to vary
     31     * within the record.
    3032     */
    31     STRING
     33    UNPACKED
    3234} // enum SRURecordPacking
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRURecordXmlEscaping.java

    r6107 r6816  
    1818
    1919/**
    20  * SRU Record packing
     20 * SRU Record XML escaping.
    2121 */
    22 public enum SRURecordPacking {
     22public enum SRURecordXmlEscaping {
    2323    /**
    2424     * XML record packing
     
    3030     */
    3131    STRING
    32 } // enum SRURecordPacking
     32} // enum SRURecordXmlEscaping
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRURequest.java

    r2866 r6816  
    8181
    8282    /**
    83      * Get the <em>recordPacking</em> parameter of this request. Only available
    84      * for <em>explain</em> and <em>searchRetrieve</em> requests.
     83     * Get the <em>recordXmlEscpaing</em> (SRU 2.0) or <em>recordPacking</em>
     84     * (SRU 1.1 and SRU 1.2) parameter of this request. Only available for
     85     * <em>explain</em> and <em>searchRetrieve</em> requests.
     86     *
     87     * @return the record XML escaping method
     88     * @see SRURecordXmlEscaping
     89     */
     90    public SRURecordXmlEscaping getRecordXmlEscaping();
     91
     92
     93    /**
     94     * Get the <em>recordPacking</em> (SRU 2.0) parameter of this request. Only
     95     * available for <em>searchRetrieve</em> requests.
    8596     *
    8697     * @return the record packing method
     
    8899     */
    89100    public SRURecordPacking getRecordPacking();
    90 
    91101
    92102    /**
     
    118128     */
    119129    public int getMaximumRecords();
    120 
    121 
    122     /**
    123      * Get the <em>recordSchema</em> parameter of this request. Only available
    124      * for <em>searchRetrieve</em> requests.
    125      *
    126      * @return the record schema name or <code>null</code> if no value was
    127      *         supplied for this request
    128      * @deprecated use {@link #getRecordSchemaIdentifier()}
    129      */
    130     @Deprecated
    131     public String getRecordSchemaName();
    132130
    133131
     
    212210     */
    213211    public String getStylesheet();
     212
     213
     214    /**
     215     * Get the <em>renderBy</em> parameter of this request.
     216     *
     217     * @return the renderBy parameter or <code>null</code> if no value was
     218     *         supplied for this request
     219     */
     220    public SRURenderBy getRenderBy();
     221
     222
     223    /**
     224     * (SRU 2.0) The request parameter <em>responseType</em>, paired with the
     225     * Internet media type specified for the response (via either the httpAccept
     226     * parameter or http accept header) determines the schema for the response.
     227     *
     228     * @return the value of the responeType request parameter or
     229     *         <code>null</code> if no value was supplied for this request
     230     */
     231    public String getResponeType();
     232
     233
     234    /**
     235     * (SRU 2.0) The request parameter <em>httpAccept</em> may be supplied to
     236     * indicate the preferred format of the response. The value is an Internet
     237     * media type.
     238     *
     239     * @return the value of the httpAccept request parameter or
     240     *         <code>null</code> if no value was supplied for
     241     */
     242    public String getHttpAccept();
    214243
    215244
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRURequestImpl.java

    r6787 r6816  
    3535    private static final Logger logger =
    3636            LoggerFactory.getLogger(SRURequest.class);
    37     private static final String PARAM_OPERATION         = "operation";
    38     private static final String PARAM_VERSION           = "version";
    39     private static final String PARAM_RECORD_PACKING    = "recordPacking";
    40     private static final String PARAM_STYLESHEET        = "stylesheet";
    41     private static final String PARAM_QUERY             = "query";
    42     private static final String PARAM_START_RECORD      = "startRecord";
    43     private static final String PARAM_MAXIMUM_RECORDS   = "maximumRecords";
    44     private static final String PARAM_RECORD_SCHEMA     = "recordSchema";
    45     private static final String PARAM_RECORD_X_PATH     = "recordXPath";
    46     private static final String PARAM_RESULT_SET_TTL    = "resultSetTTL";
    47     private static final String PARAM_SORT_KEYS         = "sortKeys";
    48     private static final String PARAM_SCAN_CLAUSE       = "scanClause";
    49     private static final String PARAM_RESPONSE_POSITION = "responsePosition";
    50     private static final String PARAM_MAXIMUM_TERMS     = "maximumTerms";
    51     private static final String OP_EXPLAIN              = "explain";
    52     private static final String OP_SCAN                 = "scan";
    53     private static final String OP_SEARCH_RETRIEVE      = "searchRetrieve";
    54     private static final String VERSION_1_1             = "1.1";
    55     private static final String VERSION_1_2             = "1.2";
    56     private static final String RECORD_PACKING_XML      = "xml";
    57     private static final String RECORD_PACKING_STRING   = "string";
    58     private static final String PARAM_EXTENSION_PREFIX  = "x-";
    59     private static final String X_UNLIMITED_RESULTSET   = "x-unlimited-resultset";
    60     private static final String X_UNLIMITED_TERMLIST    = "x-unlimited-termlist";
    61     private static final String X_INDENT_RESPONSE       = "x-indent-response";
    62     private static final int DEFAULT_START_RECORD       = 1;
    63     private static final int DEFAULT_RESPONSE_POSITION  = 1;
     37    /* general / explain related parameter names */
     38    private static final String PARAM_OPERATION            = "operation";
     39    private static final String PARAM_VERSION              = "version";
     40    private static final String PARAM_STYLESHEET           = "stylesheet";
     41    private static final String PARAM_RENDER_BY            = "renderedBy";
     42    private static final String PARAM_HTTP_ACCEPT          = "httpAccept";
     43    private static final String PARAM_RESPONSE_TYPE        = "responseType";
     44    /* searchRetrieve related parameter names */
     45    private static final String PARAM_QUERY                = "query";
     46    private static final String PARAM_QUERY_TYPE           = "queryType";
     47    private static final String PARAM_START_RECORD         = "startRecord";
     48    private static final String PARAM_MAXIMUM_RECORDS      = "maximumRecords";
     49    private static final String PARAM_RECORD_XML_ESCAPING  = "recordXMLEscaping";
     50    private static final String PARAM_RECORD_PACKING       = "recordPacking";
     51    private static final String PARAM_RECORD_SCHEMA        = "recordSchema";
     52    private static final String PARAM_RECORD_X_PATH        = "recordXPath";
     53    private static final String PARAM_RESULT_SET_TTL       = "resultSetTTL";
     54    private static final String PARAM_SORT_KEYS            = "sortKeys";
     55    /* scan related parameter names */
     56    private static final String PARAM_SCAN_CLAUSE          = "scanClause";
     57    private static final String PARAM_RESPONSE_POSITION    = "responsePosition";
     58    private static final String PARAM_MAXIMUM_TERMS        = "maximumTerms";
     59    /* operations */
     60    private static final String OP_EXPLAIN                 = "explain";
     61    private static final String OP_SCAN                    = "scan";
     62    private static final String OP_SEARCH_RETRIEVE         = "searchRetrieve";
     63    private static final String VERSION_1_1                = "1.1";
     64    private static final String VERSION_1_2                = "1.2";
     65    /* various parameter values */
     66    private static final String RECORD_XML_ESCAPING_XML    = "xml";
     67    private static final String RECORD_XML_ESCPAING_STRING = "string";
     68    private static final String RECORD_PACKING_PACKED      = "packed";
     69    private static final String RECORD_PACKING_UNPACKED    = "unpacked";
     70    private static final String RENDER_BY_CLIENT           = "client";
     71    private static final String RENDER_BY_SERVER           = "server";
     72    private static final String PARAM_EXTENSION_PREFIX     = "x-";
     73    private static final String X_UNLIMITED_RESULTSET      = "x-unlimited-resultset";
     74    private static final String X_UNLIMITED_TERMLIST       = "x-unlimited-termlist";
     75    private static final String X_INDENT_RESPONSE          = "x-indent-response";
     76    private static final int DEFAULT_START_RECORD          = 1;
     77    private static final int DEFAULT_RESPONSE_POSITION     = 1;
    6478    private final SRUServerConfig config;
    6579    private final HttpServletRequest request;
     
    6781    private SRUOperation operation;
    6882    private SRUVersion version;
     83    private SRURecordXmlEscaping recordXmlEscaping;
    6984    private SRURecordPacking recordPacking;
    7085    private CQLNode query;
     86    private String queryType;
    7187    private int startRecord = DEFAULT_START_RECORD;
    7288    private int maximumRecords = -1;
    7389    private String recordSchemaIdentifier;
    7490    private String stylesheet;
     91    private SRURenderBy renderBy;
     92    private String responseType;
     93    private String httpAccept;
    7594    private String recordXPath;
    7695    private int resultSetTTL = -1;
     
    81100
    82101    private static enum Parameter {
    83         RECORD_PACKING,
     102        STYLESHEET,
     103        RENDER_BY,
     104        HTTP_ACCEPT,
     105        RESPONSE_TYPE,
    84106        QUERY,
     107        QUERY_TYPE,
    85108        START_RECORD,
    86109        MAXIMUM_RECORDS,
     110        RECORD_XML_ESCAPING,
     111        RECORD_PACKING,
    87112        RECORD_SCHEMA,
    88113        RECORD_XPATH,
     
    92117        RESPONSE_POSITION,
    93118        MAXIMUM_TERMS,
    94         STYLESHEET
    95119    }
    96120
     
    113137        }
    114138
    115         public String getName() {
     139        public String getName(SRUVersion version) {
    116140            switch (parameter) {
    117             case RECORD_PACKING:
    118                 return PARAM_RECORD_PACKING;
     141            case STYLESHEET:
     142                return PARAM_STYLESHEET;
     143            case RENDER_BY:
     144                return PARAM_RENDER_BY;
     145            case HTTP_ACCEPT:
     146                return PARAM_HTTP_ACCEPT;
     147            case RESPONSE_TYPE:
     148                return PARAM_RESPONSE_TYPE;
    119149            case QUERY:
    120150                return PARAM_QUERY;
     151            case QUERY_TYPE:
     152                return PARAM_QUERY_TYPE;
    121153            case START_RECORD:
    122154                return PARAM_START_RECORD;
    123155            case MAXIMUM_RECORDS:
    124156                return PARAM_MAXIMUM_RECORDS;
     157            case RECORD_XML_ESCAPING:
     158                /*
     159                 * 'recordPacking' was renamed to 'recordXMLEscaping' in SRU
     160                 * 2.0. For library API treat 'recordPacking' parameter as
     161                 * 'recordPacking' for SRU 1.1 and SRU 1.2.
     162                 */
     163                if (version == SRUVersion.VERSION_2_0) {
     164                    return PARAM_RECORD_XML_ESCAPING;
     165                } else {
     166                    return PARAM_RECORD_PACKING;
     167                }
     168            case RECORD_PACKING:
     169                /*
     170                 * FIXME: make this better
     171                 */
     172                if (version == SRUVersion.VERSION_2_0) {
     173                    return PARAM_RECORD_PACKING;
     174                } else {
     175                    throw new InternalError("should not happen");
     176                }
    125177            case RECORD_SCHEMA:
    126178                return PARAM_RECORD_SCHEMA;
     
    137189            case MAXIMUM_TERMS:
    138190                return PARAM_MAXIMUM_TERMS;
    139             case STYLESHEET:
    140                 return PARAM_STYLESHEET;
    141191            default:
    142192                throw new InternalError();
     
    154204    } // class ParameterInfo
    155205
    156     private static final ParameterInfo[] PARAMS_EXPLAIN = {
     206    private static final ParameterInfo[] PARAMETER_SET_EXPLAIN = {
     207            new ParameterInfo(Parameter.STYLESHEET, false,
     208                    SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2),
     209            new ParameterInfo(Parameter.RECORD_XML_ESCAPING, false,
     210                    SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2)
     211    };
     212    private static final ParameterInfo[] PARAMETER_SET_SCAN = {
     213            new ParameterInfo(Parameter.STYLESHEET, false,
     214                    SRUVersion.VERSION_1_1, SRUVersion.VERSION_2_0),
     215            new ParameterInfo(Parameter.HTTP_ACCEPT, false,
     216                    SRUVersion.VERSION_2_0, SRUVersion.VERSION_2_0),
     217            new ParameterInfo(Parameter.SCAN_CLAUSE, true,
     218                    SRUVersion.VERSION_1_1, SRUVersion.VERSION_2_0),
     219            new ParameterInfo(Parameter.RESPONSE_POSITION, false,
     220                    SRUVersion.VERSION_1_1, SRUVersion.VERSION_2_0),
     221            new ParameterInfo(Parameter.MAXIMUM_TERMS, false,
     222                    SRUVersion.VERSION_1_1, SRUVersion.VERSION_2_0)
     223    };
     224    private static final ParameterInfo[] PARAMETER_SET_SEARCH_RETRIEVE = {
     225        new ParameterInfo(Parameter.STYLESHEET, false,
     226                    SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2),
     227        new ParameterInfo(Parameter.HTTP_ACCEPT, false,
     228                SRUVersion.VERSION_2_0, SRUVersion.VERSION_2_0),
     229        new ParameterInfo(Parameter.RENDER_BY, false,
     230                SRUVersion.VERSION_2_0, SRUVersion.VERSION_2_0),
     231        new ParameterInfo(Parameter.RESPONSE_TYPE, false,
     232                SRUVersion.VERSION_2_0, SRUVersion.VERSION_2_0),
     233        new ParameterInfo(Parameter.QUERY, true,
     234                SRUVersion.VERSION_1_1, SRUVersion.VERSION_2_0),
     235        new ParameterInfo(Parameter.QUERY_TYPE, true,
     236                SRUVersion.VERSION_2_0, SRUVersion.VERSION_2_0),
     237        new ParameterInfo(Parameter.START_RECORD, false,
     238                SRUVersion.VERSION_1_1, SRUVersion.VERSION_2_0),
     239        new ParameterInfo(Parameter.MAXIMUM_RECORDS, false,
     240                SRUVersion.VERSION_1_1, SRUVersion.VERSION_2_0),
     241        new ParameterInfo(Parameter.RECORD_XML_ESCAPING, false,
     242                SRUVersion.VERSION_1_1, SRUVersion.VERSION_2_0),
    157243        new ParameterInfo(Parameter.RECORD_PACKING, false,
    158                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2),
    159         new ParameterInfo(Parameter.STYLESHEET, false,
    160                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2)
    161     };
    162     private static final ParameterInfo[] PARAMS_SCAN = {
    163         new ParameterInfo(Parameter.SCAN_CLAUSE, true,
    164                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2),
    165         new ParameterInfo(Parameter.RESPONSE_POSITION, false,
    166                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2),
    167         new ParameterInfo(Parameter.MAXIMUM_TERMS, false,
    168                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2),
    169         new ParameterInfo(Parameter.STYLESHEET, false,
    170                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2)
    171 
    172     };
    173     private static final ParameterInfo[] PARAMS_SEARCH_RETRIEVE = {
    174         new ParameterInfo(Parameter.QUERY, true,
    175                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2),
    176         new ParameterInfo(Parameter.START_RECORD, false,
    177                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2),
    178         new ParameterInfo(Parameter.MAXIMUM_RECORDS, false,
    179                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2),
    180         new ParameterInfo(Parameter.RECORD_PACKING, false,
    181                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2),
     244                SRUVersion.VERSION_2_0, SRUVersion.VERSION_2_0),
    182245        new ParameterInfo(Parameter.RECORD_SCHEMA, false,
    183                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2),
     246                SRUVersion.VERSION_1_1, SRUVersion.VERSION_2_0),
     247        new ParameterInfo(Parameter.RESULT_SET_TTL, false,
     248                SRUVersion.VERSION_1_1, SRUVersion.VERSION_2_0),
    184249        new ParameterInfo(Parameter.RECORD_XPATH, false,
    185                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_1),
    186         new ParameterInfo(Parameter.RESULT_SET_TTL, false,
    187250                SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2),
    188251        new ParameterInfo(Parameter.SORT_KEYS, false,
    189                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_1),
    190         new ParameterInfo(Parameter.STYLESHEET, false,
    191                 SRUVersion.VERSION_1_1, SRUVersion.VERSION_1_2)
     252                SRUVersion.VERSION_1_1, SRUVersion.VERSION_2_0),
    192253    };
    193254
     
    340401        if (diagnostics == null) {
    341402            // check mandatory/optional parameters for operation
    342             ParameterInfo[] parameters;
     403            ParameterInfo[] parameter_set;
    343404            switch (operation) {
    344405            case EXPLAIN:
    345                 parameters = PARAMS_EXPLAIN;
     406                parameter_set = PARAMETER_SET_EXPLAIN;
    346407                break;
    347408            case SCAN:
    348                 parameters = PARAMS_SCAN;
     409                parameter_set = PARAMETER_SET_SCAN;
    349410                break;
    350411            case SEARCH_RETRIEVE:
    351                 parameters = PARAMS_SEARCH_RETRIEVE;
     412                parameter_set = PARAMETER_SET_SEARCH_RETRIEVE;
    352413                break;
    353414            default:
     
    366427
    367428            // check parameters ...
    368             for (ParameterInfo parameter : parameters) {
    369                 String value = getParameter(parameter.getName(), true, true);
     429            for (ParameterInfo parameter : parameter_set) {
     430                final String name = parameter.getName(version);
     431                final String value = getParameter(name, true, true);
    370432                if (value != null) {
    371433                    // remove supported parameter from list
    372                     parameterNames.remove(parameter.getName());
     434                    parameterNames.remove(name);
    373435
    374436                    /*
     
    378440                    if (!parameter.isForVersion(version)) {
    379441                        addDiagnostic(SRUConstants.SRU_UNSUPPORTED_PARAMETER,
    380                                 parameter.getName(),
     442                                name,
    381443                                "Version " + version.getVersionString() +
    382444                                        " does not support parameter \"" +
    383                                         parameter.getName() + "\".");
     445                                        name + "\".");
    384446                        continue;
    385447                    }
     
    387449                    // validate and parse parameters ...
    388450                    switch (parameter.getParameter()) {
    389                     case RECORD_PACKING:
    390                         if (value.endsWith(RECORD_PACKING_XML)) {
    391                             recordPacking = SRURecordPacking.XML;
    392                         } else if (value.equals(RECORD_PACKING_STRING)) {
    393                             recordPacking = SRURecordPacking.STRING;
     451                    case RECORD_XML_ESCAPING:
     452                        if (value.equals(RECORD_XML_ESCAPING_XML)) {
     453                            recordXmlEscaping = SRURecordXmlEscaping.XML;
     454                        } else if (value.equals(RECORD_XML_ESCPAING_STRING)) {
     455                            recordXmlEscaping = SRURecordXmlEscaping.STRING;
    394456                        } else {
    395457                            addDiagnostic(
    396                                     SRUConstants.SRU_UNSUPPORTED_RECORD_PACKING,
     458                                    SRUConstants.SRU_UNSUPPORTED_XML_ESCAPING_VALUE,
     459                                    null, "Record XML escaping \"" + value +
     460                                            "\" is not supported.");
     461                        }
     462                        break;
     463                    case RECORD_PACKING:
     464                        if (value.equals(RECORD_PACKING_PACKED)) {
     465                            recordPacking = SRURecordPacking.PACKED;
     466                        } else if (value.equals(RECORD_PACKING_UNPACKED)) {
     467                            recordPacking = SRURecordPacking.UNPACKED;
     468                        } else {
     469                            addDiagnostic(
     470                                    SRUConstants.SRU_UNSUPPORTED_PARAMETER_VALUE,
    397471                                    null, "Record packing \"" + value +
    398472                                            "\" is not supported.");
     
    400474                        break;
    401475                    case QUERY:
    402                         query = parseCQLParameter(parameter.getName(), value);
     476                        query = parseCQLParameter(name, value);
     477                        break;
     478                    case QUERY_TYPE:
     479                        queryType = parseQueryTypeParameter(name, value);
    403480                        break;
    404481                    case START_RECORD:
    405                         startRecord = parseNumberedParameter(
    406                                 parameter.getName(), value, 1);
     482                        startRecord = parseNumberedParameter(name, value, 1);
    407483                        break;
    408484                    case MAXIMUM_RECORDS:
    409                         maximumRecords = parseNumberedParameter(
    410                                 parameter.getName(), value, 0);
     485                        maximumRecords = parseNumberedParameter(name, value, 0);
    411486                        break;
    412487                    case RECORD_SCHEMA:
     
    436511                        break;
    437512                    case RESULT_SET_TTL:
    438                         resultSetTTL = parseNumberedParameter(
    439                                 parameter.getName(), value, 0);
     513                        resultSetTTL = parseNumberedParameter(name, value, 0);
    440514                        break;
    441515                    case SORT_KEYS:
     
    443517                        break;
    444518                    case SCAN_CLAUSE:
    445                         scanClause = parseCQLParameter(
    446                                 parameter.getName(), value);
     519                        scanClause = parseCQLParameter(name, value);
    447520                        break;
    448521                    case RESPONSE_POSITION:
    449522                        responsePosition = parseNumberedParameter(
    450                                 parameter.getName(), value, 0);
     523                                name, value, 0);
    451524                        break;
    452525                    case MAXIMUM_TERMS:
    453                         maximumTerms = parseNumberedParameter(
    454                                 parameter.getName(), value, 0);
     526                        maximumTerms = parseNumberedParameter(name, value, 0);
    455527                        break;
    456528                    case STYLESHEET:
    457529                        stylesheet = value;
     530                        break;
     531                    case RENDER_BY:
     532                        if (value.equals(RENDER_BY_CLIENT)) {
     533                            renderBy = SRURenderBy.CLIENT;
     534                        } else if (value.equals(RENDER_BY_SERVER)) {
     535                            renderBy = SRURenderBy.SERVER;
     536                        } else {
     537                            addDiagnostic(
     538                                    SRUConstants.SRU_UNSUPPORTED_PARAMETER_VALUE,
     539                                    null,
     540                                    "Value \"" + value + "\" for parameter '" +
     541                                            name + "' is not supported.");
     542                        }
     543                        break;
     544                    case RESPONSE_TYPE:
     545                        /*
     546                         * FIXME: check parameter validity?!
     547                         */
     548                        responseType = value;
     549                        break;
     550                    case HTTP_ACCEPT:
     551                        /*
     552                         * FIXME: check parameter validity?!
     553                         */
     554                        httpAccept = value;
    458555                        break;
    459556                    } // switch
     
    462559                        addDiagnostic(
    463560                                SRUConstants.SRU_MANDATORY_PARAMETER_NOT_SUPPLIED,
    464                                 parameter.getName(), "Mandatory parameter \"" +
    465                                         parameter.getName() +
     561                                name, "Mandatory parameter \"" + name +
    466562                                        "\" was not supplied.");
    467563                    }
     
    503599
    504600
    505     SRURecordPacking getRawRecordPacking() {
    506         return recordPacking;
     601    SRURecordXmlEscaping getRawRecordPacking() {
     602        return recordXmlEscaping;
    507603    }
    508604
     
    585681
    586682    @Override
     683    public SRURecordXmlEscaping getRecordXmlEscaping() {
     684        return (recordXmlEscaping != null)
     685                ? recordXmlEscaping
     686                : config.getDefaultRecordXmlEscaping();
     687    }
     688
     689
     690    @Override
    587691    public SRURecordPacking getRecordPacking() {
    588692        return (recordPacking != null)
     
    623727
    624728    @Override
    625     @Deprecated
    626     public String getRecordSchemaName() {
    627         return getRawRecordSchemaIdentifier();
    628     }
    629 
    630 
    631     @Override
    632729    public String getRecordSchemaIdentifier() {
    633730        return recordSchemaIdentifier;
     
    686783    public String getStylesheet() {
    687784        return stylesheet;
     785    }
     786
     787
     788    @Override
     789    public SRURenderBy getRenderBy() {
     790        return renderBy;
     791    }
     792
     793
     794    @Override
     795    public String getResponeType() {
     796        return responseType;
     797    }
     798
     799
     800    @Override
     801    public String getHttpAccept() {
     802        if (httpAccept != null) {
     803            return httpAccept;
     804        } else {
     805            return request.getHeader("ACCEPT");
     806        }
    688807    }
    689808
     
    808927            return config.getDefaultVersion();
    809928        }
     929    }
     930
     931
     932    private String parseQueryTypeParameter(String param, String value) {
     933        if (value != null) {
     934            for (int i = 0; i < value.length(); i++) {
     935                final char ch = value.charAt(i);
     936                if (!((ch >= 'a' && ch <= 'z') ||
     937                        (ch >= 'A' && ch <= 'Z') ||
     938                        (ch >= '0' && ch <= '9') ||
     939                        ((i > 0) && ((ch == '-') || ch == '_')))) {
     940                    addDiagnostic(SRUConstants.SRU_UNSUPPORTED_PARAMETER_VALUE,
     941                            param, "Value contains illegal characters.");
     942                }
     943            }
     944        }
     945        return value;
    810946    }
    811947
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUSearchResultSet.java

    r2699 r6816  
    9090
    9191    /**
    92      * The idle time for this result. The default implementation returns
    93      * <code>-1</code>.
    94      *
    95      * @return the result set idle time or <code>-1</code> if not applicable for
     92     * The result set time to live. In SRU 2.0 it will be serialized as
     93     * <code>&lt;resultSetTTL&gt;</code> element; in SRU 1.2 as
     94     * <code>&lt;resultSetIdleTime&gt;</code> element.The default implementation
     95     * returns <code>-1</code>.
     96     *
     97     * @return the result set time to live or <code>-1</code> if not applicable for
    9698     *         this result
    9799     */
    98     public int getResultSetIdleTime() {
     100    public int getResultSetTTL() {
    99101        return -1;
     102    }
     103
     104
     105    /**
     106     * (SRU 2.0) Indicate the accuracy of the result count reported by total
     107     * number of records that matched the query. Default implementation returns
     108     * <code>null</code>.
     109     *
     110     * @see SRUResultCountPrecision
     111     * @return the result count precision or <code>null</code> if not applicable
     112     *         for this result
     113     */
     114    public SRUResultCountPrecision getResultCountPrecision() {
     115        return null;
    100116    }
    101117
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUServer.java

    r6787 r6816  
    123123                    SRUXMLStreamWriter out =
    124124                        createXMLStreamWriter(response.getOutputStream(),
    125                                 SRURecordPacking.XML, false,
     125                                SRURecordXmlEscaping.XML, false,
    126126                                req.getIndentResponse());
    127127                    final SRUNamespaces ns = getNamespaces(req.getVersion());
     
    164164                    SRUXMLStreamWriter out =
    165165                            createXMLStreamWriter(response.getOutputStream(),
    166                                     SRURecordPacking.XML, false,
     166                                    SRURecordXmlEscaping.XML, false,
    167167                                    req.getIndentResponse());
    168168                    final SRUNamespaces ns = getNamespaces(req.getVersion());
     
    201201            SRUXMLStreamWriter out =
    202202                    createXMLStreamWriter(response.getOutputStream(),
    203                                           request.getRecordPacking(),
     203                                          request.getRecordXmlEscaping(),
    204204                                          true,
    205205                                          request.getIndentResponse());
     
    258258            SRUXMLStreamWriter out =
    259259                    createXMLStreamWriter(response.getOutputStream(),
    260                                           request.getRecordPacking(),
     260                                          request.getRecordXmlEscaping(),
    261261                                          true,
    262262                                          request.getIndentResponse());
     
    394394            SRUXMLStreamWriter out =
    395395                    createXMLStreamWriter(response.getOutputStream(),
    396                                           request.getRecordPacking(),
     396                                          request.getRecordXmlEscaping(),
    397397                                          true,
    398398                                          request.getIndentResponse());
     
    413413            }
    414414
    415             // resultSetIdleTime
    416             if (result.getResultSetIdleTime() > 0) {
     415            // resultSetIdleTime (SRU 1.1 and SRU 1.2)
     416            if (!request.isVersion(SRUVersion.VERSION_2_0) &&
     417                    (result.getResultSetTTL() > 0)) {
    417418                out.writeStartElement(ns.getResponseNS(), "resultSetIdleTime");
    418419                out.writeCharacters(Integer.toString(result
    419                         .getResultSetIdleTime()));
     420                        .getResultSetTTL()));
    420421                out.writeEndElement(); // "resultSetIdleTime" element
    421422            }
     
    465466
    466467                        // recordPacking
    467                         writeRecordPacking(out, ns, request.getRecordPacking());
     468                        writeRecordPacking(out, ns, request.getRecordXmlEscaping());
    468469
    469470                        /*
     
    482483
    483484                        /*
    484                          * recordIdentifier is version 1.2 only
     485                         * recordIdentifier is version 1.2+ only
    485486                         */
    486                         if (request.isVersion(SRUVersion.VERSION_1_2)) {
     487                        if (request.isVersion(SRUVersion.VERSION_1_2,
     488                                SRUVersion.VERSION_2_0)) {
    487489                            final String identifier =
    488490                                    result.getRecordIdentifier();
     
    543545            }
    544546
     547            // SRU 2.0 stuff ...
     548            if (request.isVersion(SRUVersion.VERSION_2_0)) {
     549                // resultSetTTL
     550                if (result.getResultSetTTL() > 0) {
     551                    out.writeStartElement(ns.getResponseNS(), "resultSetTTL");
     552                    out.writeCharacters(Integer.toString(result
     553                            .getResultSetTTL()));
     554                    out.writeEndElement(); // "resultSetTTL" element
     555                }
     556
     557                // resultCountPrecision (SRU 2.0)
     558                final SRUResultCountPrecision precision =
     559                        result.getResultCountPrecision();
     560                if (precision != null) {
     561                    out.writeStartElement(ns.getResponseNS(), "resultCountPrecision");
     562                    switch (precision) {
     563                    case EXACT:
     564                        out.writeCharacters("info:srw/vocabulary/resultCountPrecision/1/exact");
     565                        break;
     566                    case UNKNOWN:
     567                        out.writeCharacters("info:srw/vocabulary/resultCountPrecision/1/unknown");
     568                        break;
     569                    case ESTIMATE:
     570                        out.writeCharacters("info:srw/vocabulary/resultCountPrecision/1/estimate");
     571                        break;
     572                    case MAXIMUM:
     573                        out.writeCharacters("info:srw/vocabulary/resultCountPrecision/1/maximum");
     574                        break;
     575                    case MINIMUM:
     576                        out.writeCharacters("info:srw/vocabulary/resultCountPrecision/1/minimum");
     577                        break;
     578                    case CURRENT:
     579                        out.writeCharacters("info:srw/vocabulary/resultCountPrecision/1/current");
     580                        break;
     581                    } // switch
     582                    out.writeEndElement(); // "resultCountPrecision" element
     583                }
     584
     585                // facetedResults
     586                // NOT YET SUPPORTED
     587
     588                // searchResultAnalysis
     589                // NOT YET SUPPORTED
     590            }
    545591            endResponse(out);
    546592        } finally {
     
    666712
    667713        // recordPacking
    668         writeRecordPacking(out, ns, request.getRecordPacking());
     714        writeRecordPacking(out, ns, request.getRecordXmlEscaping());
    669715
    670716        out.writeStartElement(ns.getResponseNS(), "recordData");
     
    10251071        }
    10261072
     1073        // echoedSearchRetrieveRequest/renderedBy
     1074        // FIXME: NOT YET IMPLEMENTED
     1075
     1076        // echoedSearchRetrieveRequest/extraRequestParameter
     1077        // FIXME: NOT YET IMPLEMENTED
     1078
     1079        // echoedSearchRetrieveRequest/httpAccept
     1080        // FIXME: NOT YET IMPLEMENTED
     1081
     1082        // echoedSearchRetrieveRequest/responseType
     1083        // FIXME: NOT YET IMPLEMENTED
     1084
    10271085        // echoedSearchRetrieveRequest/baseUrl (SRU 1.2 only)
    10281086        if (request.isVersion(SRUVersion.VERSION_1_2)) {
     
    10531111
    10541112    private void writeRecordPacking(SRUXMLStreamWriter out, SRUNamespaces ns,
    1055             SRURecordPacking recordPacking) throws XMLStreamException {
     1113            SRURecordXmlEscaping recordPacking) throws XMLStreamException {
    10561114        out.writeStartElement(ns.getResponseNS(), "recordPacking");
    10571115        switch (recordPacking) {
     
    10961154
    10971155    private SRUXMLStreamWriter createXMLStreamWriter(OutputStream out,
    1098             SRURecordPacking recordPacking, boolean skipFlush, int indent)
     1156            SRURecordXmlEscaping recordPacking, boolean skipFlush, int indent)
    10991157            throws SRUException {
    11001158        try {
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUServerConfig.java

    r6787 r6816  
    717717
    718718
     719    public SRURecordXmlEscaping getDefaultRecordXmlEscaping() {
     720        return SRURecordXmlEscaping.XML;
     721    }
     722
     723
    719724    public SRURecordPacking getDefaultRecordPacking() {
    720         return SRURecordPacking.XML;
     725        return SRURecordPacking.PACKED;
    721726    }
    722727
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUXMLStreamWriter.java

    r2729 r6816  
    4545    }
    4646    private static final SAXParserFactory factory;
    47     private final SRURecordPacking packing;
     47    private final SRURecordXmlEscaping recordEscaping;
    4848    private final Writer writer;
    4949    private final XMLStreamWriter xmlwriter;
     
    5555
    5656
    57     SRUXMLStreamWriter(OutputStream stream, XMLOutputFactory factory,
    58             SRURecordPacking recordPacking, int indent) throws IOException,
    59             XMLStreamException {
    60         this.packing = recordPacking;
     57    SRUXMLStreamWriter(OutputStream stream,
     58            XMLOutputFactory factory,
     59            SRURecordXmlEscaping recordXmlEscaping,
     60            int indent) throws IOException, XMLStreamException {
     61        this.recordEscaping = recordXmlEscaping;
    6162        this.writer = new OutputStreamWriter(stream,
    6263                SRUServer.RESPONSE_ENCODING) {
    6364            @Override
    6465            public void write(int c) throws IOException {
    65                 if (writingRecord && (packing == SRURecordPacking.STRING)) {
     66                if (writingRecord && (recordEscaping == SRURecordXmlEscaping.STRING)) {
    6667                    /*
    6768                     * NOTE: need to write single characters here, because
     
    9899            @Override
    99100            public void write(char[] c, int off, int len) throws IOException {
    100                 if (writingRecord && (packing == SRURecordPacking.STRING)) {
     101                if (writingRecord && (recordEscaping == SRURecordXmlEscaping.STRING)) {
    101102                    for (int i = off; i < len; i++) {
    102103                        this.write(c[i]);
     
    109110            @Override
    110111            public void write(String s, int off, int len) throws IOException {
    111                 if (writingRecord && (packing == SRURecordPacking.STRING)) {
     112                if (writingRecord && (recordEscaping == SRURecordXmlEscaping.STRING)) {
    112113                    for (int i = off; i < len; i++) {
    113114                        this.write(s.charAt(i));
     
    480481
    481482    private void onStartElement() throws XMLStreamException {
    482         if (!(writingRecord && (packing == SRURecordPacking.STRING))) {
     483        if (!(writingRecord && (recordEscaping == SRURecordXmlEscaping.STRING))) {
    483484            stateStack.push(IndentingState.SEEN_ELEMENT);
    484485            state = IndentingState.SEEN_NOTHING;
     
    493494
    494495    private void onEndElement() throws XMLStreamException {
    495         if (!(writingRecord && (packing == SRURecordPacking.STRING))) {
     496        if (!(writingRecord && (recordEscaping == SRURecordXmlEscaping.STRING))) {
    496497            depth--;
    497498            if (state == IndentingState.SEEN_ELEMENT) {
     
    505506
    506507    private void onEmptyElement() throws XMLStreamException {
    507         if (!(writingRecord && (packing == SRURecordPacking.STRING))) {
     508        if (!(writingRecord && (recordEscaping == SRURecordXmlEscaping.STRING))) {
    508509            state = IndentingState.SEEN_ELEMENT;
    509510            if (depth > 0) {
Note: See TracChangeset for help on using the changeset viewer.