Java Code Examples for javax.xml.stream.events.Characters#getData()

The following examples show how to use javax.xml.stream.events.Characters#getData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmlPolicyModelUnmarshaller.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private StringBuilder processCharacters(final ModelNode.Type currentNodeType, final Characters characters,
        final StringBuilder currentValueBuffer)
        throws PolicyException {
    if (characters.isWhiteSpace()) {
        return currentValueBuffer;
    } else {
        final StringBuilder buffer = (currentValueBuffer == null) ? new StringBuilder() : currentValueBuffer;
        final String data = characters.getData();
        if (currentNodeType == ModelNode.Type.ASSERTION || currentNodeType == ModelNode.Type.ASSERTION_PARAMETER_NODE) {
            return buffer.append(data);
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0009_UNEXPECTED_CDATA_ON_SOURCE_MODEL_NODE(currentNodeType, data)));
        }

    }
}
 
Example 2
Source File: XmlParser.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
private void collectEventInfo(Characters characters) {
    if (currentObjects.size() == 0) {
        return;
    }

    if (characters.isIgnorableWhiteSpace() || characters.isWhiteSpace()) {
        return;
    }

    String text = characters.getData();

    if (currentObjects.peek().containsKey(parents.peek().getName().getLocalPart() + "_value")) {
        String oldText = (String) currentObjects.peek().get(parents.peek().getName().getLocalPart() + "_value");
        text = oldText + text;
    }

    currentObjects.peek().put(parents.peek().getName().getLocalPart() + "_value", text);
}
 
Example 3
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private StringBuilder processCharacters(final ModelNode.Type currentNodeType, final Characters characters,
        final StringBuilder currentValueBuffer)
        throws PolicyException {
    if (characters.isWhiteSpace()) {
        return currentValueBuffer;
    } else {
        final StringBuilder buffer = (currentValueBuffer == null) ? new StringBuilder() : currentValueBuffer;
        final String data = characters.getData();
        if (currentNodeType == ModelNode.Type.ASSERTION || currentNodeType == ModelNode.Type.ASSERTION_PARAMETER_NODE) {
            return buffer.append(data);
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0009_UNEXPECTED_CDATA_ON_SOURCE_MODEL_NODE(currentNodeType, data)));
        }

    }
}
 
Example 4
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private void processCharacters(final Characters chars, final StartElement currentElement, final Map<URI, Policy> map)
        throws PolicyException {
    if (chars.isWhiteSpace()) {
        return;
    }
    else {
        final String data = chars.getData();
        if ((currentElement != null) && URI.equals(currentElement.getName())) {
            processUri(chars, map);
            return;
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0092_CHARACTER_DATA_UNEXPECTED(currentElement, data, chars.getLocation())));
        }

    }
}
 
Example 5
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private StringBuilder processCharacters(final ModelNode.Type currentNodeType, final Characters characters,
        final StringBuilder currentValueBuffer)
        throws PolicyException {
    if (characters.isWhiteSpace()) {
        return currentValueBuffer;
    } else {
        final StringBuilder buffer = (currentValueBuffer == null) ? new StringBuilder() : currentValueBuffer;
        final String data = characters.getData();
        if (currentNodeType == ModelNode.Type.ASSERTION || currentNodeType == ModelNode.Type.ASSERTION_PARAMETER_NODE) {
            return buffer.append(data);
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0009_UNEXPECTED_CDATA_ON_SOURCE_MODEL_NODE(currentNodeType, data)));
        }

    }
}
 
Example 6
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private void processCharacters(final Characters chars, final StartElement currentElement, final Map<URI, Policy> map)
        throws PolicyException {
    if (chars.isWhiteSpace()) {
        return;
    }
    else {
        final String data = chars.getData();
        if ((currentElement != null) && URI.equals(currentElement.getName())) {
            processUri(chars, map);
            return;
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0092_CHARACTER_DATA_UNEXPECTED(currentElement, data, chars.getLocation())));
        }

    }
}
 
Example 7
Source File: XmlPolicyModelUnmarshaller.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private StringBuilder processCharacters(final ModelNode.Type currentNodeType, final Characters characters,
        final StringBuilder currentValueBuffer)
        throws PolicyException {
    if (characters.isWhiteSpace()) {
        return currentValueBuffer;
    } else {
        final StringBuilder buffer = (currentValueBuffer == null) ? new StringBuilder() : currentValueBuffer;
        final String data = characters.getData();
        if (currentNodeType == ModelNode.Type.ASSERTION || currentNodeType == ModelNode.Type.ASSERTION_PARAMETER_NODE) {
            return buffer.append(data);
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0009_UNEXPECTED_CDATA_ON_SOURCE_MODEL_NODE(currentNodeType, data)));
        }

    }
}
 
Example 8
Source File: ExternalAttachmentsUnmarshaller.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void processCharacters(final Characters chars, final StartElement currentElement, final Map<URI, Policy> map)
        throws PolicyException {
    if (chars.isWhiteSpace()) {
        return;
    }
    else {
        final String data = chars.getData();
        if ((currentElement != null) && URI.equals(currentElement.getName())) {
            processUri(chars, map);
            return;
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0092_CHARACTER_DATA_UNEXPECTED(currentElement, data, chars.getLocation())));
        }

    }
}
 
Example 9
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private StringBuilder processCharacters(final ModelNode.Type currentNodeType, final Characters characters,
        final StringBuilder currentValueBuffer)
        throws PolicyException {
    if (characters.isWhiteSpace()) {
        return currentValueBuffer;
    } else {
        final StringBuilder buffer = (currentValueBuffer == null) ? new StringBuilder() : currentValueBuffer;
        final String data = characters.getData();
        if (currentNodeType == ModelNode.Type.ASSERTION || currentNodeType == ModelNode.Type.ASSERTION_PARAMETER_NODE) {
            return buffer.append(data);
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0009_UNEXPECTED_CDATA_ON_SOURCE_MODEL_NODE(currentNodeType, data)));
        }

    }
}
 
Example 10
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void processCharacters(final Characters chars, final StartElement currentElement, final Map<URI, Policy> map)
        throws PolicyException {
    if (chars.isWhiteSpace()) {
        return;
    }
    else {
        final String data = chars.getData();
        if ((currentElement != null) && URI.equals(currentElement.getName())) {
            processUri(chars, map);
            return;
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0092_CHARACTER_DATA_UNEXPECTED(currentElement, data, chars.getLocation())));
        }

    }
}
 
Example 11
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private StringBuilder processCharacters(final ModelNode.Type currentNodeType, final Characters characters,
        final StringBuilder currentValueBuffer)
        throws PolicyException {
    if (characters.isWhiteSpace()) {
        return currentValueBuffer;
    } else {
        final StringBuilder buffer = (currentValueBuffer == null) ? new StringBuilder() : currentValueBuffer;
        final String data = characters.getData();
        if (currentNodeType == ModelNode.Type.ASSERTION || currentNodeType == ModelNode.Type.ASSERTION_PARAMETER_NODE) {
            return buffer.append(data);
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0009_UNEXPECTED_CDATA_ON_SOURCE_MODEL_NODE(currentNodeType, data)));
        }

    }
}
 
Example 12
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void processCharacters(final Characters chars, final StartElement currentElement, final Map<URI, Policy> map)
        throws PolicyException {
    if (chars.isWhiteSpace()) {
        return;
    }
    else {
        final String data = chars.getData();
        if ((currentElement != null) && URI.equals(currentElement.getName())) {
            processUri(chars, map);
            return;
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0092_CHARACTER_DATA_UNEXPECTED(currentElement, data, chars.getLocation())));
        }

    }
}
 
Example 13
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private StringBuilder processCharacters(final ModelNode.Type currentNodeType, final Characters characters,
        final StringBuilder currentValueBuffer)
        throws PolicyException {
    if (characters.isWhiteSpace()) {
        return currentValueBuffer;
    } else {
        final StringBuilder buffer = (currentValueBuffer == null) ? new StringBuilder() : currentValueBuffer;
        final String data = characters.getData();
        if (currentNodeType == ModelNode.Type.ASSERTION || currentNodeType == ModelNode.Type.ASSERTION_PARAMETER_NODE) {
            return buffer.append(data);
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0009_UNEXPECTED_CDATA_ON_SOURCE_MODEL_NODE(currentNodeType, data)));
        }

    }
}
 
Example 14
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void processCharacters(final Characters chars, final StartElement currentElement, final Map<URI, Policy> map)
        throws PolicyException {
    if (chars.isWhiteSpace()) {
        return;
    }
    else {
        final String data = chars.getData();
        if ((currentElement != null) && URI.equals(currentElement.getName())) {
            processUri(chars, map);
            return;
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0092_CHARACTER_DATA_UNEXPECTED(currentElement, data, chars.getLocation())));
        }

    }
}
 
Example 15
Source File: XmlPolicyModelUnmarshaller.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private StringBuilder processCharacters(final ModelNode.Type currentNodeType, final Characters characters,
        final StringBuilder currentValueBuffer)
        throws PolicyException {
    if (characters.isWhiteSpace()) {
        return currentValueBuffer;
    } else {
        final StringBuilder buffer = (currentValueBuffer == null) ? new StringBuilder() : currentValueBuffer;
        final String data = characters.getData();
        if (currentNodeType == ModelNode.Type.ASSERTION || currentNodeType == ModelNode.Type.ASSERTION_PARAMETER_NODE) {
            return buffer.append(data);
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0009_UNEXPECTED_CDATA_ON_SOURCE_MODEL_NODE(currentNodeType, data)));
        }

    }
}
 
Example 16
Source File: ExternalAttachmentsUnmarshaller.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void processCharacters(final Characters chars, final StartElement currentElement, final Map<URI, Policy> map)
        throws PolicyException {
    if (chars.isWhiteSpace()) {
        return;
    }
    else {
        final String data = chars.getData();
        if ((currentElement != null) && URI.equals(currentElement.getName())) {
            processUri(chars, map);
            return;
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0092_CHARACTER_DATA_UNEXPECTED(currentElement, data, chars.getLocation())));
        }

    }
}
 
Example 17
Source File: ExternalAttachmentsUnmarshaller.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void processCharacters(final Characters chars, final StartElement currentElement, final Map<URI, Policy> map)
        throws PolicyException {
    if (chars.isWhiteSpace()) {
        return;
    }
    else {
        final String data = chars.getData();
        if ((currentElement != null) && URI.equals(currentElement.getName())) {
            processUri(chars, map);
            return;
        } else {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0092_CHARACTER_DATA_UNEXPECTED(currentElement, data, chars.getLocation())));
        }

    }
}
 
Example 18
Source File: CDataChunkSizeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "xml-data")
public void testEventReader(String xml, int chunkSize, int expectedNumOfChunks, boolean withinLimit) throws Exception {
    XMLInputFactory xif = XMLInputFactory.newInstance();
    xif.setProperty("http://java.sun.com/xml/stream/properties/report-cdata-event", true);
    if (chunkSize > 0) {
        xif.setProperty(CDATA_CHUNK_SIZE, chunkSize);
    }
    XMLEventReader reader = xif.createXMLEventReader(new StringReader(xml));

    StringBuilder cdata = new StringBuilder();
    int numOfChunks = 0;
    boolean isWithinLimit = true;
    while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();
        //All text events get reported as Characters events
        if (event.getEventType() == XMLStreamConstants.CHARACTERS) {
            Characters cdataEvent = (Characters) event;
            if (cdataEvent.isCData()) {
                String text = cdataEvent.getData();
                numOfChunks++;
                if (text.length() > chunkSize) {
                    isWithinLimit = false;
                }
                debugPrint("\nCDATA: " + text.length());
                cdata.append(text);
            }
        }
    }
    debugPrint("CData in single chunk:" + cdata.toString().length());
    Assert.assertEquals(numOfChunks, expectedNumOfChunks);
    Assert.assertEquals(isWithinLimit, withinLimit);
}
 
Example 19
Source File: WindowSuffixTransformer.java    From recheck with GNU Affero General Public License v3.0 5 votes vote down vote up
protected boolean updatePath( final XMLEvent event, final XMLEventWriter eventWriter ) throws XMLStreamException {
	if ( isInPath && event.isCharacters() ) {
		final Characters characters = event.asCharacters();
		final String window = characters.getData();

		isWindowPath = "Window".equals( window );

		final String replace = window.replaceFirst( "Window", "Window_0" );
		eventWriter.add( characters( replace ) );
		return true;
	}
	return false;
}
 
Example 20
Source File: EdfiRecordParserImpl.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
private void parseCharacters(Characters characters) {
    if (!characters.isIgnorableWhiteSpace() && !characters.isWhiteSpace()) {
        String text = characters.getData();
        Object convertedValue = typeProvider.convertType(complexTypeStack.peek().getLeft().getType(), text);
        complexTypeStack.peek().getRight().put("_value", convertedValue);
    }
}