javax.xml.stream.events.Characters Java Examples

The following examples show how to use javax.xml.stream.events.Characters. 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: AnimalRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #2
Source File: EntityRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");

	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);

	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);

	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);

}
 
Example #3
Source File: EmployeeRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #4
Source File: AnimalRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {

		XMLEventFactory eventFactory = XMLEventFactory.newInstance();
		XMLEvent end = eventFactory.createDTD("\n");
		XMLEvent tab = eventFactory.createDTD("\t");

		// Create start node
		StartElement sElement = eventFactory.createStartElement("", "", name);
		eventWriter.add(tab);
		eventWriter.add(sElement);

		// Create content

		Characters characters = eventFactory.createCharacters(value);
		eventWriter.add(characters);

		// Create end node

		EndElement eElement = eventFactory.createEndElement("", "", name);
		eventWriter.add(eElement);
		eventWriter.add(end);
	}
 
Example #5
Source File: StaxEventXMLReader.java    From java-technology-stack with MIT License 6 votes vote down vote up
private void handleCharacters(Characters characters) throws SAXException {
	char[] data = characters.getData().toCharArray();
	if (getContentHandler() != null && characters.isIgnorableWhiteSpace()) {
		getContentHandler().ignorableWhitespace(data, 0, data.length);
		return;
	}
	if (characters.isCData() && getLexicalHandler() != null) {
		getLexicalHandler().startCDATA();
	}
	if (getContentHandler() != null) {
		getContentHandler().characters(data, 0, data.length);
	}
	if (characters.isCData() && getLexicalHandler() != null) {
		getLexicalHandler().endCDATA();
	}
}
 
Example #6
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 #7
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 #8
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 #9
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 #10
Source File: EntityRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {

		XMLEventFactory eventFactory = XMLEventFactory.newInstance();
		XMLEvent end = eventFactory.createDTD("\n");
		XMLEvent tab = eventFactory.createDTD("\t");

		StartElement sElement = eventFactory.createStartElement("", "", name);
		eventWriter.add(tab);
		eventWriter.add(sElement);

		Characters characters = eventFactory.createCharacters(value);
		eventWriter.add(characters);

		EndElement eElement = eventFactory.createEndElement("", "", name);
		eventWriter.add(eElement);
		eventWriter.add(end);
	}
 
Example #11
Source File: StaxEventXMLReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void handleCharacters(Characters characters) throws SAXException {
	char[] data = characters.getData().toCharArray();
	if (getContentHandler() != null && characters.isIgnorableWhiteSpace()) {
		getContentHandler().ignorableWhitespace(data, 0, data.length);
		return;
	}
	if (characters.isCData() && getLexicalHandler() != null) {
		getLexicalHandler().startCDATA();
	}
	if (getContentHandler() != null) {
		getContentHandler().characters(data, 0, data.length);
	}
	if (characters.isCData() && getLexicalHandler() != null) {
		getLexicalHandler().endCDATA();
	}
}
 
Example #12
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 #13
Source File: AnimalRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {

		XMLEventFactory eventFactory = XMLEventFactory.newInstance();
		XMLEvent end = eventFactory.createDTD("\n");
		XMLEvent tab = eventFactory.createDTD("\t");

		StartElement sElement = eventFactory.createStartElement("", "", name);
		eventWriter.add(tab);
		eventWriter.add(sElement);

		Characters characters = eventFactory.createCharacters(value);
		eventWriter.add(characters);

		EndElement eElement = eventFactory.createEndElement("", "", name);
		eventWriter.add(eElement);
		eventWriter.add(end);
	}
 
Example #14
Source File: StaxEventXMLReader.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void handleCharacters(Characters characters) throws SAXException {
	char[] data = characters.getData().toCharArray();
	if (getContentHandler() != null && characters.isIgnorableWhiteSpace()) {
		getContentHandler().ignorableWhitespace(data, 0, data.length);
		return;
	}
	if (characters.isCData() && getLexicalHandler() != null) {
		getLexicalHandler().startCDATA();
	}
	if (getContentHandler() != null) {
		getContentHandler().characters(data, 0, data.length);
	}
	if (characters.isCData() && getLexicalHandler() != null) {
		getLexicalHandler().endCDATA();
	}
}
 
Example #15
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 #16
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 #17
Source File: StaxWriter.java    From maven-framework-project with MIT License 6 votes vote down vote up
private void createNode(XMLEventWriter eventWriter, String name,
		String value) throws XMLStreamException {

	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	
	//XMLEvent end = eventFactory.createDTD("\n");
	//XMLEvent tab = eventFactory.createDTD("\t");
	
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	//eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	//eventWriter.add(end);

}
 
Example #18
Source File: ModifiedPomXMLEventReader.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public XMLEvent nextTag()
    throws XMLStreamException
{
    while ( hasNext() )
    {
        XMLEvent e = nextEvent();
        if ( e.isCharacters() && !( (Characters) e ).isWhiteSpace() )
        {
            throw new XMLStreamException( "Unexpected text" );
        }
        if ( e.isStartElement() || e.isEndElement() )
        {
            return e;
        }
    }
    throw new XMLStreamException( "Unexpected end of Document" );
}
 
Example #19
Source File: EmployeeRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #20
Source File: EntityRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #21
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 #22
Source File: EntityRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {

		XMLEventFactory eventFactory = XMLEventFactory.newInstance();
		XMLEvent end = eventFactory.createDTD("\n");
		XMLEvent tab = eventFactory.createDTD("\t");

		// Create start node
		StartElement sElement = eventFactory.createStartElement("", "", name);
		eventWriter.add(tab);
		eventWriter.add(sElement);

		// Create content

		Characters characters = eventFactory.createCharacters(value);
		eventWriter.add(characters);

		// Create end node

		EndElement eElement = eventFactory.createEndElement("", "", name);
		eventWriter.add(eElement);
		eventWriter.add(end);
	}
 
Example #23
Source File: EmployeeRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #24
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 #25
Source File: EmployeeRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #26
Source File: EmployeeRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #27
Source File: XmlResourceValues.java    From bazel with Apache License 2.0 6 votes vote down vote up
public static XMLEvent nextTag(XMLEventReader eventReader) throws XMLStreamException {
  while (eventReader.hasNext()
      && !(eventReader.peek().isEndElement() || eventReader.peek().isStartElement())) {
    XMLEvent nextEvent = eventReader.nextEvent();
    if (nextEvent.isCharacters() && !nextEvent.asCharacters().isIgnorableWhiteSpace()) {
      Characters characters = nextEvent.asCharacters();
      // TODO(corysmith): Turn into a warning with the Path is available to add to it.
      // This case is when unexpected characters are thrown into the xml. Best case, it's a
      // incorrect comment type...
      logger.fine(
          String.format(
              "Invalid characters [%s] found at %s",
              characters.getData(), characters.getLocation().getLineNumber()));
    }
  }
  return eventReader.nextEvent();
}
 
Example #28
Source File: AnimalRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");

	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);

	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);

	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);

}
 
Example #29
Source File: EwsXmlReaderTest.java    From ews-java-api with MIT License 6 votes vote down vote up
@Test
public void testReadValueWhenCharacterDataIsNull() throws Exception {

  doReturn(false).when(presentEvent).isStartElement();
  doReturn(XmlNodeType.CHARACTERS).when(presentEvent).getEventType();
  doReturn(true).when(presentEvent).isCharacters();
  doReturn(character).when(presentEvent).asCharacters();

  //next event, then end event, then no more event
  doReturn(true).doReturn(true).doReturn(false).when(xmlReader).hasNext();
  Characters nextEvent = Mockito.mock(Characters.class);
  doReturn(true).when(nextEvent).isCharacters();
  doReturn(XmlNodeType.CHARACTERS).when(nextEvent).getEventType();
  XMLEvent endEvent = Mockito.mock(XMLEvent.class);
  doReturn(nextEvent).doReturn(endEvent).when(xmlReader).nextEvent();
  doReturn(true).when(endEvent).isEndElement();

  impl.readValue(true);  //must not throw npe even if character.getData() is null

  Assert.assertNull(character.getData());
}
 
Example #30
Source File: EntityRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}