Search in sources :

Example 1 with WstxParsingException

use of com.ctc.wstx.exc.WstxParsingException 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 WstxParsingException

use of com.ctc.wstx.exc.WstxParsingException 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)

Aggregations

WstxEOFException (com.ctc.wstx.exc.WstxEOFException)2 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