Search in sources :

Example 1 with WstxEOFException

use of com.ctc.wstx.exc.WstxEOFException in project RecordManager2 by moravianlibrary.

the class ZakonyProLidiFulltextXmlStreamReader method next.

public String next() {
    boolean fulltext = false;
    String result = "";
    int countDiv = 0;
    while (eventReader.hasNext()) {
        try {
            XMLEvent xmlEvent = eventReader.nextEvent();
            if (xmlEvent.isStartElement()) {
                switch(xmlEvent.asStartElement().getName().getLocalPart()) {
                    case ELEMENT_DIV:
                        if (isAttribute(xmlEvent.asStartElement(), ATTR_NAME_CLASS, ATTR_VALUE_FRAGS_NOVEL)) {
                            fulltext = true;
                        }
                        if (fulltext)
                            ++countDiv;
                        break;
                    case ELEMENT_H3:
                    case ELEMENT_P:
                        if (fulltext) {
                            String xmlFragment = readElementBody(eventReader);
                            result += xmlFragment + "\n";
                        }
                        break;
                    default:
                        break;
                }
            } else if (xmlEvent.isEndElement()) {
                switch(xmlEvent.asEndElement().getName().getLocalPart()) {
                    case ELEMENT_DIV:
                        if (fulltext)
                            --countDiv;
                        if (countDiv == 0)
                            fulltext = false;
                        break;
                    default:
                        break;
                }
            }
        } catch (WstxEOFException e) {
            break;
        } catch (WstxParsingException e) {
        } catch (XMLStreamException e) {
            e.printStackTrace();
        }
    }
    return result;
}
Also used : WstxParsingException(com.ctc.wstx.exc.WstxParsingException) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEvent(javax.xml.stream.events.XMLEvent) WstxEOFException(com.ctc.wstx.exc.WstxEOFException)

Example 2 with WstxEOFException

use of com.ctc.wstx.exc.WstxEOFException in project RecordManager2 by moravianlibrary.

the class ManuscriptoriumFulltextXmlStreamReader method next.

public String next() {
    String result = "";
    List<String> titles = new ArrayList<>();
    while (eventReader.hasNext()) {
        try {
            XMLEvent xmlEvent = eventReader.nextEvent();
            if (xmlEvent.isStartElement()) {
                switch(xmlEvent.asStartElement().getName().getLocalPart()) {
                    case ELEMENT_UNCIPIT:
                    case ELEMENT_EXPLICIT:
                    case ELEMENT_COLOFON:
                    case ELEMENT_QUOTE:
                    case ELEMENT_TITLE:
                    case ELEMENT_RUBRIC:
                        String xmlFragment = readElementBody(eventReader);
                        if (!titles.contains(xmlFragment)) {
                            result += xmlFragment + "\n";
                            titles.add(xmlFragment);
                        }
                        break;
                    default:
                        break;
                }
            }
        } catch (WstxEOFException e) {
            break;
        } catch (WstxParsingException e) {
        } catch (XMLStreamException e) {
            e.printStackTrace();
        }
    }
    return result;
}
Also used : WstxParsingException(com.ctc.wstx.exc.WstxParsingException) XMLStreamException(javax.xml.stream.XMLStreamException) ArrayList(java.util.ArrayList) XMLEvent(javax.xml.stream.events.XMLEvent) WstxEOFException(com.ctc.wstx.exc.WstxEOFException)

Example 3 with WstxEOFException

use of com.ctc.wstx.exc.WstxEOFException in project tomee by apache.

the class AbstractJAXBProvider method handleExceptionEnd.

protected static void handleExceptionEnd(Throwable t, String message, boolean read) throws NoContentException {
    if (t instanceof WstxEOFException && t.getMessage().startsWith("Unexpected EOF in prolog")) {
        String noContent = new org.apache.cxf.common.i18n.Message("EMPTY_BODY", BUNDLE).toString();
        LOG.warning(noContent);
        throw new NoContentException(noContent);
    }
    Response.Status status = read ? Response.Status.BAD_REQUEST : Response.Status.INTERNAL_SERVER_ERROR;
    Response r = JAXRSUtils.toResponseBuilder(status).type(MediaType.TEXT_PLAIN).entity(message).build();
    throw read ? ExceptionUtils.toBadRequestException(t, r) : ExceptionUtils.toInternalServerErrorException(t, r);
}
Also used : Response(javax.ws.rs.core.Response) WstxEOFException(com.ctc.wstx.exc.WstxEOFException) NoContentException(javax.ws.rs.core.NoContentException)

Aggregations

WstxEOFException (com.ctc.wstx.exc.WstxEOFException)3 WstxParsingException (com.ctc.wstx.exc.WstxParsingException)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 XMLEvent (javax.xml.stream.events.XMLEvent)2 ArrayList (java.util.ArrayList)1 NoContentException (javax.ws.rs.core.NoContentException)1 Response (javax.ws.rs.core.Response)1