Package javax.xml.stream

Examples of javax.xml.stream.XMLEventReader


    @Before
    public void createChainUp() throws Exception {
        inputFactory = XMLInputFactory.newFactory();
        List<XMLEvent> events = getEvents("<event1-1><event1-2>text1</event1-2></event1-1>");
        expectedEvents.addAll(events);
        XMLEventReader reader1 = new ListBasedXMLEventReader(events);
        XMLEventReader reader2 = new ListBasedXMLEventReader();
        events = getEvents("<event2-1></event2-1>");
        expectedEvents.addAll(events);
        XMLEventReader reader3 = new ListBasedXMLEventReader(events);
        XMLEventReader reader4 = new ListBasedXMLEventReader();
        chain = new CompositeXMLEventReader(reader1, reader2, reader3, reader4);
    }
View Full Code Here


        XMLEventReader reader4 = new ListBasedXMLEventReader();
        chain = new CompositeXMLEventReader(reader1, reader2, reader3, reader4);
    }

    private List<XMLEvent> getEvents(String xml) throws XMLStreamException {
        XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(xml));
        List<XMLEvent> events = new LinkedList<XMLEvent>();
        while (eventReader.hasNext()) {
            XMLEvent event = eventReader.nextEvent();
            if (!(event.isStartDocument() || event.isEndDocument())) {
                events.add(event);
            }

        }
View Full Code Here

    }

    @Test
    public void testEventReaderPayload() throws Exception {
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        XMLEventReader eventReader = inputFactory.createXMLEventReader(payload.getInputStream());
        Source staxSource = StaxUtils.createCustomStaxSource(eventReader);
        transformer.transform(staxSource, webServiceMessage.getPayloadResult());
        StringWriter stringWriter = new StringWriter();
        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
        XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(stringWriter);
View Full Code Here

            if (streamReader != null) {
                callback.staxSource(streamReader);
                return;
            }
            else {
                XMLEventReader eventReader = StaxUtils.getXMLEventReader(source);
                if (eventReader != null) {
                    callback.staxSource(eventReader);
                    return;
                }
            }
View Full Code Here

    }

    static StroapMessage build(InputStream inputStream, StroapMessageFactory messageFactory)
            throws XMLStreamException, IOException {
        MultiValueMap<String, String> mimeHeaders = parseMimeHeaders(inputStream);
        XMLEventReader eventReader = messageFactory.getInputFactory().createXMLEventReader(inputStream);
        StroapEnvelope envelope = StroapEnvelope.build(eventReader, messageFactory);
        return new StroapMessage(mimeHeaders, envelope, messageFactory);
    }
View Full Code Here

    public void setDocument(Document document) {
        try {
            try {
                DOMSource domSource = new DOMSource(document);
                XMLEventReader eventReader = messageFactory.getInputFactory().createXMLEventReader(domSource);
                this.envelope = StroapEnvelope.build(eventReader, messageFactory);
                return;
            }
            catch (XMLStreamException ignored) {
                // ignored
            }
            catch (UnsupportedOperationException ignored) {
                // ignored
            }
            // XMLInputFactory does not support DOMSources, so let's do it the hard way
            DOMImplementation implementation = document.getImplementation();
            Assert.isInstanceOf(DOMImplementationLS.class, implementation);

            DOMImplementationLS loadSaveImplementation = (DOMImplementationLS) implementation;
            LSOutput output = loadSaveImplementation.createLSOutput();
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            output.setByteStream(bos);

            LSSerializer serializer = loadSaveImplementation.createLSSerializer();
            serializer.write(document, output);

            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            XMLEventReader eventReader = messageFactory.getInputFactory().createXMLEventReader(bis);
            this.envelope = StroapEnvelope.build(eventReader, messageFactory);
        }
        catch (XMLStreamException ex) {
            throw new StroapMessageException("Could not read Document", ex);
        }
View Full Code Here

    }

    @Test
    public void testDoWithStaxSourceEventReader() throws Exception {
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader("<element/>"));

        TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
        mock.staxSource(eventReader);

        replay(mock);
View Full Code Here

            return null;
        }
    }

    public Source getPayloadSource() {
        XMLEventReader eventReader = payload.getEventReader();
        return StaxUtils.createCustomStaxSource(eventReader);
    }
View Full Code Here

      Stack<RefEntity> stack = new Stack<RefEntity>();

      Map<String, Reference> importedRefs = new HashMap<String, Reference>();

      XMLInputFactory factory = XMLInputFactory.newInstance();
      XMLEventReader reader = factory.createXMLEventReader(new FileInputStream(bindingsStorePath), "UTF-8");

      while (reader.hasNext())
      {
         XMLEvent event = reader.nextEvent();
         switch (event.getEventType())
         {
            case XMLStreamConstants.START_ELEMENT :
               StartElement startElement = event.asStartElement();
View Full Code Here

   */
  public void translate(InputStream in, OutputStream out) throws XMLStreamException {
    final XMLInputFactory inFactory = XMLInputFactory.newInstance();
    final XMLOutputFactory outFactory = XMLOutputFactory.newInstance();

    final XMLEventReader reader = inFactory.createXMLEventReader(in);
    final XMLEventWriter writer = outFactory.createXMLEventWriter(out);

    try {
      EventLoop: while (reader.hasNext()) {
        XMLEvent event = reader.nextEvent();

        if (event.isStartElement()) {
          StartElement start = event.asStartElement();
          if (isRemovable(start)) {
            while (reader.hasNext()) {
              XMLEvent next = reader.nextEvent();
              if (next.isEndElement() && next.asEndElement().getName().equals(start.getName()))
                continue EventLoop;
            }
            // If this is reached, we finished the document before the tag ended
            throw new RuntimeException(String.format("End of file was reached before %s closing tag was found.",
                    start.getName()));
          }
          else if (toAdd.containsKey(start.getName().getLocalPart())
                  && !toAdd.get(start.getName().getLocalPart()).isEmpty()) {
            writer.add(event);
            final XMLEventFactory eventFactory = XMLEventFactory.newInstance();
            for (final Tag tag : toAdd.get(start.getName().getLocalPart())) {
              List<Attribute> attrs = new ArrayList<Attribute>();
              for (final AttributeEntry entry : tag) {
                attrs.add(eventFactory.createAttribute(entry.getKey(), entry.getValue()));
              }
              StartElement newStart = eventFactory.createStartElement(QName.valueOf(tag.getName()), attrs.iterator(),
                      null);
              EndElement newEnd = eventFactory.createEndElement(newStart.getName(), null);

              writer.add(newStart);
              writer.add(newEnd);
            }
          }
          else {
            writer.add(event);
          }
        }
        else {
          writer.add(event);
        }
      }
    } finally {
      writer.close();
      reader.close();
    }

  }
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.