Package javax.xml.stream

Examples of javax.xml.stream.XMLEventReader


        assertEquals("Invalid local name", LOCAL_NAME, streamReader.getLocalName());
    }

    private void testEventReader(Object result) throws XMLStreamException {
        assertTrue("resolver does not return XMLEventReader", result instanceof XMLEventReader);
        XMLEventReader eventReader = (XMLEventReader) result;
        assertTrue("eventReader has no next element", eventReader.hasNext());
        XMLEvent event = eventReader.nextTag();
        assertEquals(XMLStreamConstants.START_ELEMENT, event.getEventType());
        StartElement startElement = (StartElement) event;
        assertEquals("Invalid namespace", NAMESPACE_URI, startElement.getName().getNamespaceURI());
        assertEquals("Invalid local name", LOCAL_NAME, startElement.getName().getLocalPart());
    }
View Full Code Here


        }
        XMLStreamReader streamReader = null;
        if (StaxUtils.isStaxSource(source)) {
            streamReader = StaxUtils.getXMLStreamReader(source);
            if (streamReader == null) {
                XMLEventReader eventReader = StaxUtils.getXMLEventReader(source);
                if (eventReader != null) {
                    try {
                        streamReader = StaxUtils.createEventStreamReader(eventReader);
                    }
                    catch (XMLStreamException ex) {
View Full Code Here

    private XMLEventFactory eventFactory;

    @Override
    public final void invoke(MessageContext messageContext) throws Exception {
        XMLEventReader eventReader = getEventReader(messageContext.getRequest().getPayloadSource());
        XMLEventWriter streamWriter = new ResponseCreatingEventWriter(messageContext);
        invokeInternal(eventReader, streamWriter, getEventFactory());
        streamWriter.flush();
    }
View Full Code Here

    private XMLEventReader getEventReader(Source source) throws XMLStreamException, TransformerException {
        if (source == null) {
            return null;
        }
        XMLEventReader eventReader = null;
        if (StaxUtils.isStaxSource(source)) {
            eventReader = StaxUtils.getXMLEventReader(source);
            if (eventReader == null) {
                XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(source);
                if (streamReader != null) {
View Full Code Here

  }

  public <T> T getJaxbRoot(InputStream stream, Class<T> clazz, Schema schema)
      throws XmlParsingException {

    XMLEventReader staxEventReader;
    try {
      staxEventReader = createXmlEventReader( stream );
    }
    catch ( XMLStreamException e ) {
      throw new XmlParsingException( "Unable to create stax reader", e );
View Full Code Here

    xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
  }

  // TODO : woodstox xmlInputFactory synchronization?
  protected synchronized XMLEventReader getXMLEventReader(InputStream source) throws ApplicationException {
    XMLEventReader eventReader;
    try {
      eventReader = xmlInputFactory.createXMLEventReader(source);
    } catch (XMLStreamException e) {
      throw new ApplicationException("Could not read input data!", e);
    }
View Full Code Here

   {

      try {

         XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
         XMLEventReader reader = xmlInputFactory.createXMLEventReader(stream);

         // parse the complete document
         while (reader.hasNext()) {

            XMLEvent event = reader.nextEvent();

            // this events means we can abort
            if (event.isEndDocument()) {
               break;
            }
View Full Code Here

    private static final String TEST_XML_WITH_XML_HEADER = "<?xml version=\"1.0\"?>" + TEST_XML;

    public void testEncodingXmlEventReader() throws Exception {
        TEST_XML_WITH_XML_HEADER_ISO_8859_1_AS_BYTE_ARRAY_STREAM.reset();
        XMLEventReader reader = null;
        XMLEventWriter writer = null;
        ByteArrayOutputStream output = null;
        try {
            // enter text encoded with Latin1
            reader = context.getTypeConverter().mandatoryConvertTo(XMLEventReader.class,
                    TEST_XML_WITH_XML_HEADER_ISO_8859_1_AS_BYTE_ARRAY_STREAM);

            output = new ByteArrayOutputStream();
            // ensure UTF-8 encoding
            Exchange exchange = new DefaultExchange(context);
            exchange.setProperty(Exchange.CHARSET_NAME, UTF_8.toString());
            writer = context.getTypeConverter().mandatoryConvertTo(XMLEventWriter.class, exchange, output);
            while (reader.hasNext()) {
                writer.add(reader.nextEvent());
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (writer != null) {
                writer.close();
            }
        }
View Full Code Here

    private static final String TEST_XML_WITH_XML_HEADER = "<?xml version=\"1.0\"?>" + TEST_XML;

    public void testEncodingXmlEventReader() throws Exception {
        TEST_XML_WITH_XML_HEADER_ISO_8859_1_AS_BYTE_ARRAY_STREAM.reset();
        XMLEventReader reader = null;
        XMLEventWriter writer = null;
        ByteArrayOutputStream output = null;
        try {
            // enter text encoded with Latin1
            reader = context.getTypeConverter().mandatoryConvertTo(XMLEventReader.class,
                    TEST_XML_WITH_XML_HEADER_ISO_8859_1_AS_BYTE_ARRAY_STREAM);

            output = new ByteArrayOutputStream();
            // ensure UTF-8 encoding
            Exchange exchange = new DefaultExchange(context);
            exchange.setProperty(Exchange.CHARSET_NAME, UTF_8.toString());
            writer = context.getTypeConverter().mandatoryConvertTo(XMLEventWriter.class, exchange, output);
            while (reader.hasNext()) {
                writer.add(reader.nextEvent());
            }
        } finally {
            if (reader != null) {
                reader.close();
            }
            if (writer != null) {
                writer.close();
            }
        }
View Full Code Here

   */
  private MappingReader() {
  }

  public XmlDocument readMappingDocument(InputSource source, Origin origin) {
    XMLEventReader staxReader = buildStaxEventReader( source, origin );
    try {
      return read( staxReader, origin );
    }
    finally {
      try {
        staxReader.close();
      }
      catch ( Exception ignore ) {
      }
    }
  }
View Full Code Here

TOP

Related Classes of javax.xml.stream.XMLEventReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.