Changeset 2942 for SRUClient


Ignore:
Timestamp:
05/28/13 09:20:03 (11 years ago)
Author:
oschonef
Message:
  • add methods for setting of strict mode per request
  • remove strict mode setting per client
Location:
SRUClient/trunk/src/main/java/eu/clarin/sru/client
Files:
4 edited

Legend:

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

    r2880 r2942  
    111111    /** The URL of the endpoint. */
    112112    protected final String endpointURI;
    113     /** The version to be sued  for this request. */
     113    /** The request should be performed in strict SRU protocol conformance mode */
     114    private boolean strictMode;
     115    /** The version to be used for this request. */
    114116    protected SRUVersion version;
    115117    /** A map of extra request data parameters. */
     
    141143    public String getEndpointURI() {
    142144        return endpointURI;
     145    }
     146
     147
     148    /**
     149     * Get the SRU protocol conformance mode for this request
     150     *
     151     * @return <code>true</code> if the request will be performed in strict
     152     *         mode, <code>false</code> if the request will be performed in a
     153     *         more tolerant mode
     154     */
     155    public boolean isStrictMode() {
     156        return strictMode;
     157    }
     158
     159
     160    /**
     161     * Set the SRU protocol conformance mode for this request
     162     *
     163     * @param strictMode
     164     *            <code>true</code> if the request should be performed in strict
     165     *            mode, <code>false</code> if the request should be performed
     166     *            client should in a more tolerant mode
     167     */
     168    public void setStrictMode(boolean strictMode) {
     169        this.strictMode = strictMode;
    143170    }
    144171
  • SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUClient.java

    r2936 r2942  
    8080     * use the default SRU version.
    8181     *
    82      * @see #SRUClient(SRUVersion, boolean)
    8382     * @see SRUSimpleClient#DEFAULT_SRU_VERSION
    8483     */
    8584    public SRUClient() {
    86         this(SRUSimpleClient.DEFAULT_SRU_VERSION, true);
     85        this(SRUSimpleClient.DEFAULT_SRU_VERSION,
     86                new HashMap<String, SRURecordDataParser>(),
     87                DocumentBuilderFactory.newInstance());
    8788    }
    8889
     
    9495     *            the default version to use for SRU requests; may be overridden
    9596     *            by individual requests
    96      * @see #SRUClient(SRUVersion, boolean)
    9797     */
    9898    public SRUClient(SRUVersion defaultVersion) {
    99         this(defaultVersion, true);
     99        this(defaultVersion,
     100                new HashMap<String, SRURecordDataParser>(),
     101                DocumentBuilderFactory.newInstance());
    100102    }
    101103
     
    103105    /**
    104106     * Constructor.
     107     *
     108     * <p>
     109     * For internal use only.
     110     * </p>
    105111     *
    106112     * @param defaultVersion
    107113     *            the default version to use for SRU requests; may be overridden
    108114     *            by individual requests
    109      * @param strictMode
    110      *            if <code>true</code> the client will strictly adhere to the
    111      *            SRU standard and raise fatal errors on violations, if
    112      *            <code>false</code> it will act more forgiving and ignore
    113      *            certain violations
    114      */
    115     public SRUClient(SRUVersion defaultVersion, boolean strictMode) {
    116         this(defaultVersion, strictMode,
    117                 new HashMap<String, SRURecordDataParser>(),
    118                 DocumentBuilderFactory.newInstance());
    119     }
    120 
    121 
    122     /**
    123      * Constructor.
    124      *
    125      * <p>
    126      * For internal use only.
    127      * </p>
    128      *
    129      * @param defaultVersion
    130      *            the default version to use for SRU requests; may be overridden
    131      *            by individual requests
    132      * @param strictMode
    133      *            if <code>true</code> the client will strictly adhere to the
    134      *            SRU standard and raise fatal errors on violations, if
    135      *            <code>false</code> it will act more forgiving and ignore
    136      *            certain violations
    137115     * @param parsers
    138116     *            a <code>Map</code> to store record schema to record data
    139117     *            parser mappings
    140      */
    141     SRUClient(SRUVersion defaultVersion, boolean strictMode,
     118     * @param documentBuilderFactory
     119     *            the Document Builder factory to be used to create Document
     120     *            Builders
     121     */
     122    SRUClient(SRUVersion defaultVersion,
    142123            Map<String, SRURecordDataParser> parsers,
    143124            DocumentBuilderFactory documentBuilderFactory) {
     
    148129            throw new NullPointerException("parsers == null");
    149130        }
    150         this.client = new SRUSimpleClient(defaultVersion, strictMode, parsers);
     131        if (documentBuilderFactory == null) {
     132            throw new NullPointerException("documentBuilderFactory == null");
     133        }
     134        this.client = new SRUSimpleClient(defaultVersion, parsers);
    151135        this.handler = new Handler();
    152136        try {
     
    166150    /**
    167151     * Register a record data parser.
    168      * 
     152     *
    169153     * @param parser
    170154     *            a parser instance
  • SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSimpleClient.java

    r2939 r2942  
    8080            LoggerFactory.getLogger(SRUSimpleClient.class);
    8181    private final SRUVersion defaultVersion;
    82     private boolean strictMode;
    8382    private final Map<String, SRURecordDataParser> parsers;
    8483    private final HttpClient httpClient;
     
    9190     * use the default SRU version.
    9291     *
    93      * @see #SRUSimpleClient(SRUVersion, boolean)
    9492     * @see #DEFAULT_SRU_VERSION
    9593     */
    9694    public SRUSimpleClient() {
    97         this(DEFAULT_SRU_VERSION, true);
     95        this(DEFAULT_SRU_VERSION, new HashMap<String, SRURecordDataParser>());
    9896    }
    9997
     
    105103     *            the default version to use for SRU requests; may be overridden
    106104     *            by individual requests
    107      * @see #SRUSimpleClient(SRUVersion, boolean)
    108105     */
    109106    public SRUSimpleClient(SRUVersion defaultVersion) {
    110         this(defaultVersion, true);
    111     }
    112 
    113 
    114     /**
    115      * Constructor.
    116      *
    117      * @param defaultVersion
    118      *            the default version to use for SRU requests; may be overridden
    119      *            by individual requests
    120      * @param strictMode
    121      *            if <code>true</code> the client will strictly adhere to the
    122      *            SRU standard and raise fatal errors on violations, if
    123      *            <code>false</code> it will act more forgiving and ignore
    124      *            certain violations
    125      */
    126     public SRUSimpleClient(SRUVersion defaultVersion, boolean strictMode) {
    127         this(defaultVersion, strictMode,
    128                 new HashMap<String, SRURecordDataParser>());
     107        this(defaultVersion, new HashMap<String, SRURecordDataParser>());
    129108    }
    130109
     
    149128     *            parser mappings
    150129     */
    151     SRUSimpleClient(SRUVersion defaultVersion, boolean strictMode,
     130    SRUSimpleClient(SRUVersion defaultVersion,
    152131            Map<String, SRURecordDataParser> parsers) {
    153132        if (defaultVersion == null) {
     
    158137        }
    159138        this.defaultVersion = defaultVersion;
    160         this.strictMode     = strictMode;
    161139        this.parsers        = parsers;
    162         this.httpClient = new DefaultHttpClient();
     140        this.httpClient     = new DefaultHttpClient();
    163141        this.httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT,
    164142                    "eu.clarin.sru.client/0.0.1");
    165     }
    166 
    167 
    168     /**
    169      * Get the SRU protocol conformance mode of the client.
    170      *
    171      * @return <code>true</code> if the client operation in strict mode,
    172      *         <code>false</code> otherwise
    173      */
    174     public boolean isStrictMode() {
    175         return strictMode;
    176     }
    177 
    178 
    179     /**
    180      * Set the SRU protocol conformance mode of the client.
    181      *
    182      * @param strictMode
    183      *            <code>true</code> if the client should operate in strict mode,
    184      *            <code>false</code> if the client should be more tolerant
    185      */
    186     public void setStrictMode(boolean strictMode) {
    187         this.strictMode = strictMode;
    188143    }
    189144
     
    548503            boolean parseRecordData) throws SRUClientException {
    549504        try {
     505            final boolean strictMode = request.isStrictMode();
     506
    550507            // explainResponse
    551508            reader.readStart(SRU_NS, "explainResponse", true);
     
    755712            } else {
    756713                logger.debug("parsing 'scanResponse' response");
     714
     715                final boolean strictMode = request.isStrictMode();
    757716
    758717                // scanResponse
     
    931890            } else {
    932891                logger.debug("parsing 'searchRetrieve' response");
     892
     893                final boolean strictMode = request.isStrictMode();
    933894
    934895                // searchRetrieveResponse
  • SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUThreadedClient.java

    r2936 r2942  
    5555     * use the default SRU version.
    5656     *
    57      * @see #SRUThreadedClient(SRUVersion, boolean)
    5857     * @see SRUSimpleClient#DEFAULT_SRU_VERSION
    5958     */
    6059    public SRUThreadedClient() {
    61         this(SRUSimpleClient.DEFAULT_SRU_VERSION, true);
    62     }
    63 
    64 
    65     /**
    66      * Constructor. This constructor will create a <em>strict</em> client.
     60        this(SRUSimpleClient.DEFAULT_SRU_VERSION);
     61    }
     62
     63
     64    /**
     65     * Constructor.
    6766     *
    6867     * @param defaultVersion
    6968     *            the default version to use for SRU requests; may be overridden
    7069     *            by individual requests
    71      * @see #SRUThreadedClient(SRUVersion, boolean)
    72      */
    73     public SRUThreadedClient(SRUVersion defaultVersion) {
    74         this(defaultVersion, true);
    75     }
    76 
    77 
    78     /**
    79      * Constructor.
    80      *
    81      * @param defaultVersion
    82      *            the default version to use for SRU requests; may be overridden
    83      *            by individual requests
    84      * @param strictMode
    85      *            if <code>true</code> the client will strictly adhere to the
    86      *            SRU standard and raise fatal errors on violations, if
    87      *            <code>false</code> it will act more forgiving and ignore
    88      *            certain violations
    89      */
    90     public SRUThreadedClient(final SRUVersion defaultVersion,
    91             final boolean strictMode) {
     70     */
     71    public SRUThreadedClient(final SRUVersion defaultVersion) {
    9272        client = new ThreadLocal<SRUClient>() {
    9373            @Override
    9474            protected SRUClient initialValue() {
    9575                logger.debug("instantiated new sru client");
    96                 return new SRUClient(defaultVersion, strictMode, parsers,
     76                return new SRUClient(defaultVersion, parsers,
    9777                        documentBuilderFactory);
    9878            }
     
    10787    /**
    10888     * Register a record data parser.
    109      * 
     89     *
    11090     * @param parser
    11191     *            a parser instance
Note: See TracChangeset for help on using the changeset viewer.