Changeset 2840


Ignore:
Timestamp:
04/26/13 12:33:26 (11 years ago)
Author:
oschonef
Message:
  • if operating in non-strict mode, allow empty <details> and <message> elements within <diagnostic>
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

    r2466 r2840  
    576576
    577577            // explainResponse/diagnostics
    578             final List<SRUDiagnostic> diagnostics = parseDiagnostics(reader);
     578            final List<SRUDiagnostic> diagnostics =
     579                    parseDiagnostics(reader, strictMode);
    579580            if (diagnostics != null) {
    580581                handler.onDiagnostics(diagnostics);
     
    725726
    726727                // scanResponse/diagnostics
    727                 final List<SRUDiagnostic> diagnostics = parseDiagnostics(reader);
     728                final List<SRUDiagnostic> diagnostics =
     729                        parseDiagnostics(reader, strictMode);
    728730                if (diagnostics != null) {
    729731                    handler.onDiagnostics(diagnostics);
     
    872874
    873875                        if (SRU_DIAGNOSTIC_RECORD_SCHEMA.equals(schema)) {
    874                             surrogate = parseDiagnostic(recordReader, true);
     876                            surrogate = parseDiagnostic(recordReader,
     877                                    true, strictMode);
    875878                        } else {
    876879                            SRURecordDataParser parser = findParser(schema);
     
    10241027
    10251028                // searchRetrieveResponse/diagnostics
    1026                 final List<SRUDiagnostic> diagnostics = parseDiagnostics(reader);
     1029                final List<SRUDiagnostic> diagnostics =
     1030                        parseDiagnostics(reader, strictMode);
    10271031                if (diagnostics != null) {
    10281032                    handler.onDiagnostics(diagnostics);
     
    10671071
    10681072    private static List<SRUDiagnostic> parseDiagnostics(
    1069             SRUXMLStreamReader reader) throws XMLStreamException,
    1070             SRUClientException {
     1073            SRUXMLStreamReader reader, boolean strictMode)
     1074            throws XMLStreamException, SRUClientException {
    10711075        if (reader.readStart(SRU_NS, "diagnostics", false)) {
    10721076            List<SRUDiagnostic> diagnostics = null;
     
    10741078            SRUDiagnostic diagnostic = null;
    10751079            while ((diagnostic = parseDiagnostic(reader,
    1076                     (diagnostics == null))) != null) {
     1080                    (diagnostics == null), strictMode)) != null) {
    10771081                if (diagnostics == null) {
    10781082                    diagnostics = new ArrayList<SRUDiagnostic>();
     
    10891093
    10901094    private static SRUDiagnostic parseDiagnostic(SRUXMLStreamReader reader,
    1091             boolean required) throws XMLStreamException, SRUClientException {
     1095            boolean required, boolean stictMode) throws XMLStreamException,
     1096            SRUClientException {
    10921097        if (reader.readStart(SRU_DIAGNOSIC_NS, "diagnostic", required)) {
    10931098
     
    10961101
    10971102            // diagnostic/details
    1098             String details =
    1099                     reader.readContent(SRU_DIAGNOSIC_NS, "details", false);
     1103            String details = reader.readContent(SRU_DIAGNOSIC_NS, "details",
     1104                    false, stictMode);
     1105            if ((details != null) && details.isEmpty()) {
     1106                details = null;
     1107                logger.warn("omitting empty element <details> " +
     1108                        "within element <diagnostic>");
     1109            }
    11001110
    11011111            // diagnostic/message
    1102             String message =
    1103                     reader.readContent(SRU_DIAGNOSIC_NS, "message", false);
     1112            String message = reader.readContent(SRU_DIAGNOSIC_NS, "message",
     1113                    false, stictMode);
     1114            if ((message != null) && message.isEmpty()) {
     1115                message = null;
     1116                logger.warn("omitting empty element <message> " +
     1117                        "within element <diagnostic>");
     1118            }
    11041119
    11051120            reader.readEnd(SRU_DIAGNOSIC_NS, "diagnostic");
  • SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUXMLStreamReader.java

    r2466 r2840  
    515515    String readContent(String namespaceURI, String localName, boolean required)
    516516            throws XMLStreamException {
     517        return readContent(namespaceURI, localName, required, true);
     518    }
     519
     520       
     521    String readContent(String namespaceURI, String localName, boolean required,
     522            boolean contentRequired) throws XMLStreamException {
    517523        String result = null;
    518524        if (readStart(namespaceURI, localName, required)) {
    519525            try {
    520                 result = readString(true);
     526                result = readString(contentRequired);
     527                if (!contentRequired && (result == null)) {
     528                    result = "";
     529                }
    521530            } catch (XMLStreamException e) {
    522531                StringBuilder sb = new StringBuilder();
Note: See TracChangeset for help on using the changeset viewer.