Search in sources :

Example 6 with Characters

use of javax.xml.stream.events.Characters in project uPortal by Jasig.

the class IndentingXMLEventWriter method beforeMarkup.

/**
 * Prepare to write markup, by writing a new line and indentation.
 */
protected void beforeMarkup() {
    final Set<StackState> state = scopeState.getFirst();
    if (!state.contains(StackState.WROTE_DATA) && (depth > 0 || !state.isEmpty())) {
        final String indent = getIndent(this.depth, this.indentSize);
        final Characters indentEvent = xmlEventFactory.createCharacters(indent);
        try {
            wrappedWriter.add(indentEvent);
        } catch (XMLStreamException e) {
        // Ignore exceptions caused by indentation
        }
        // indentation was written
        afterMarkup();
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) Characters(javax.xml.stream.events.Characters)

Example 7 with Characters

use of javax.xml.stream.events.Characters in project omegat by omegat-org.

the class TMXReader2 method parseSegOmegaT.

/**
 * OmegaT TMX - just read full text.
 */
protected void parseSegOmegaT() throws Exception {
    segContent.setLength(0);
    while (true) {
        XMLEvent e = xml.nextEvent();
        switch(e.getEventType()) {
            case XMLEvent.END_ELEMENT:
                EndElement eEnd = (EndElement) e;
                if ("seg".equals(eEnd.getName().getLocalPart())) {
                    return;
                }
                break;
            case XMLEvent.CHARACTERS:
                Characters c = (Characters) e;
                segContent.append(c.getData());
                break;
        }
    }
}
Also used : EndElement(javax.xml.stream.events.EndElement) Characters(javax.xml.stream.events.Characters) XMLEvent(javax.xml.stream.events.XMLEvent)

Example 8 with Characters

use of javax.xml.stream.events.Characters in project omegat by omegat-org.

the class TMXReader2 method parseProp.

protected void parseProp(StartElement element) throws Exception {
    String propType = getAttributeValue(element, "type");
    propContent.setLength(0);
    while (true) {
        XMLEvent e = xml.nextEvent();
        switch(e.getEventType()) {
            case XMLEvent.END_ELEMENT:
                EndElement eEnd = (EndElement) e;
                if ("prop".equals(eEnd.getName().getLocalPart())) {
                    currentTu.props.add(new TMXProp(propType, propContent.toString()));
                    return;
                }
                break;
            case XMLEvent.CHARACTERS:
                Characters c = (Characters) e;
                propContent.append(c.getData());
                break;
        }
    }
}
Also used : EndElement(javax.xml.stream.events.EndElement) Characters(javax.xml.stream.events.Characters) XMLEvent(javax.xml.stream.events.XMLEvent)

Example 9 with Characters

use of javax.xml.stream.events.Characters in project omegat by omegat-org.

the class TMXReader2 method parseSegExtLevel1.

/**
 * External TMX - level 1. Skip text inside inline tags.
 */
protected void parseSegExtLevel1() throws Exception {
    segContent.setLength(0);
    int inlineLevel = 0;
    while (true) {
        XMLEvent e = xml.nextEvent();
        switch(e.getEventType()) {
            case XMLEvent.START_ELEMENT:
                inlineLevel++;
                break;
            case XMLEvent.END_ELEMENT:
                inlineLevel--;
                EndElement eEnd = (EndElement) e;
                if ("seg".equals(eEnd.getName().getLocalPart())) {
                    return;
                }
                break;
            case XMLEvent.CHARACTERS:
                if (inlineLevel == 0) {
                    Characters c = (Characters) e;
                    segContent.append(c.getData());
                }
                break;
        }
    }
}
Also used : EndElement(javax.xml.stream.events.EndElement) Characters(javax.xml.stream.events.Characters) XMLEvent(javax.xml.stream.events.XMLEvent)

Example 10 with Characters

use of javax.xml.stream.events.Characters in project omegat by omegat-org.

the class TMXReader2 method parseNote.

protected void parseNote(StartElement element) throws Exception {
    noteContent.setLength(0);
    while (true) {
        XMLEvent e = xml.nextEvent();
        switch(e.getEventType()) {
            case XMLEvent.END_ELEMENT:
                EndElement eEnd = (EndElement) e;
                if ("note".equals(eEnd.getName().getLocalPart())) {
                    currentTu.note = noteContent.toString();
                    return;
                }
                break;
            case XMLEvent.CHARACTERS:
                Characters c = (Characters) e;
                noteContent.append(c.getData());
                break;
        }
    }
}
Also used : EndElement(javax.xml.stream.events.EndElement) Characters(javax.xml.stream.events.Characters) XMLEvent(javax.xml.stream.events.XMLEvent)

Aggregations

Characters (javax.xml.stream.events.Characters)33 XMLEvent (javax.xml.stream.events.XMLEvent)21 XMLStreamException (javax.xml.stream.XMLStreamException)20 EndElement (javax.xml.stream.events.EndElement)11 StartElement (javax.xml.stream.events.StartElement)11 XMLEventReader (javax.xml.stream.XMLEventReader)6 QName (javax.xml.namespace.QName)5 XMLInputFactory (javax.xml.stream.XMLInputFactory)5 Test (org.junit.Test)5 Attribute (javax.xml.stream.events.Attribute)4 EntityDeclaration (javax.xml.stream.events.EntityDeclaration)4 EntityReference (javax.xml.stream.events.EntityReference)4 HashMap (java.util.HashMap)3 Namespace (javax.xml.stream.events.Namespace)3 StartDocument (javax.xml.stream.events.StartDocument)3 InputStream (java.io.InputStream)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 Base64 (java.util.Base64)2 ProcessingInstruction (javax.xml.stream.events.ProcessingInstruction)2