Package javax.xml.stream.events

Examples of javax.xml.stream.events.XMLEvent


    {
        if (omitDoc)
        {
            while(reader.hasNext())
            {
                final XMLEvent event = reader.nextEvent() ;
                final int type = event.getEventType() ;
                if ((type != XMLStreamConstants.START_DOCUMENT) &&
                    (type != XMLStreamConstants.END_DOCUMENT))
                {
                    writer.add(event) ;
                }
View Full Code Here


            throw new Exception(message.toString());
        }
    }

    public static boolean compare(XMLEventReader a, XMLEventReader b, StringBuilder message) {
        XMLEvent eventA;
        XMLEvent eventB;
        int eventType;
        try {
        while ((eventA = nextInterestingEvent(a)) != null & (eventB = nextInterestingEvent(b)) != null) {
                if ((eventType = eventA.getEventType()) != eventB.getEventType()) {
                    message.append("events of different types: ").append(eventA).append(", ").append(eventB);
                    return false;
                }

                if (eventType == XMLStreamConstants.START_ELEMENT) {
                    StartElement startA = eventA.asStartElement();
                    StartElement startB = eventB.asStartElement();
                    if (!startA.getName().getLocalPart().equals(startB.getName().getLocalPart())) {
                        message.append("Different elements ").append(startA.getName()).append(", ").append(startB.getName()).append(" at location ").append(eventA.getLocation());
                        return false;
                    }
                } else if (eventType == XMLStreamConstants.END_ELEMENT) {
                    EndElement endA = eventA.asEndElement();
                    EndElement endB = eventB.asEndElement();
                    if (!endA.getName().getLocalPart().equals(endB.getName().getLocalPart())) {
                        message.append("Different elements ").append(endA.getName()).append(", ").append(endB.getName()).append(" at location ").append(eventA.getLocation());
                        return false;
                    }
                } else if (eventType == XMLStreamConstants.CHARACTERS) {
                    Characters endA = eventA.asCharacters();
                    Characters endB = eventB.asCharacters();
                    if (!endA.getData().equals(endB.getData())) {
                        message.append("Different content ").append(endA.getData()).append(", ").append(endB.getData()).append(" at location ").append(eventA.getLocation());
                        return false;
                    }
                }

        }
            if (eventA != null) {
                message.append("A is longer: ").append(eventA.getLocation());
                return false;
            }
            if (eventB != null) {
                message.append("B is longer: ").append(eventB.getLocation());
                return false;
            }
        } catch (XMLStreamException e) {
            message.append("Exception processing ").append(e.getMessage());
            return false;
View Full Code Here

        return true;
    }

    private static XMLEvent nextInterestingEvent(XMLEventReader r) throws XMLStreamException {
        do {
            XMLEvent e = r.nextEvent();
            int t = e.getEventType();
            if (t == XMLStreamConstants.START_ELEMENT || t == XMLStreamConstants.END_ELEMENT || t == XMLStreamConstants.ATTRIBUTE) {
                return e;
            }
        } while (r.hasNext());
        return null;
View Full Code Here

                }
            });

            xmlReader = xif.createXMLEventReader(inputStream);

            XMLEvent docStart = xmlReader.nextEvent();

            XMLEvent rootElement = xmlReader.nextTag();

            if (rootElement instanceof StartElement) {
                StartElement startElement = (StartElement)rootElement;
                Attribute toAttribute = startElement.getAttributeByName(ATTRIBUTE_TO);
                if (toAttribute != null) {
                    to = toAttribute.getValue();
                }
            }
            while (true) {
                if (isStopped()) {
                    break;
                }

                XMLEvent event = xmlReader.peek();
                if (event.isStartElement()) {
                    // unmarshal a new object
                    Object object = unmarshaller.unmarshal(xmlReader);
                    if (object != null) {
                        LOG.debug("Unmarshalled new incoming event - " + object.getClass().getName());
                        converter.onXmppCommand(object);
                    }
                } else {
                    if (event.getEventType() == XMLEvent.END_ELEMENT) {
                        break;
                    } else if (event.getEventType() == XMLEvent.END_ELEMENT || event.getEventType() == XMLEvent.END_DOCUMENT) {
                        break;
                    } else {
                        xmlReader.nextEvent();
                    }
View Full Code Here

                        return false;
                    }                   
                }
            });
           
            XMLEvent e;
            while ((e = rdr.nextEvent()) != null) {
                if (e.getEventType() == XMLEvent.END_DOCUMENT) {
                    break;
                }
               
                StartElement el = e.asStartElement();
               
                if (el.getName().getLocalPart().equals("depends")) {
                    Attribute pluginAttr = el.getAttributeByName(new QName("plugin"));
                    if (pluginAttr == null) {
                        throw new IllegalArgumentException("Couldn't find the 'plugin' attribute on a 'depends' element in the plugin descriptor of plugin '" + archive + "'.");
View Full Code Here

        InputStream is = archive.get(PLUGIN_DESCRIPTOR_PATH).getAsset().openStream();
        XMLEventReader rdr = null;
        try {
            rdr = XMLInputFactory.newInstance().createXMLEventReader(is);

            XMLEvent event = null;
            while (rdr.hasNext()) {
                event = rdr.nextEvent();
                if (event.getEventType() == XMLEvent.START_ELEMENT) {
                    break;
                }
            }

            StartElement startElement = event.asStartElement();
            String tagName = startElement.getName().getLocalPart();
            if (!"plugin".equals(tagName)) {
                throw new IllegalArgumentException("Illegal start tag found in the plugin descriptor. Expected 'plugin' but found '" + tagName + "' in the plugin '" + archive + "'.");
            }
           
View Full Code Here

        InputStream is = archive.get(PLUGIN_DESCRIPTOR_PATH).getAsset().openStream();
        XMLEventReader rdr = null;
        try {
            rdr = XMLInputFactory.newInstance().createXMLEventReader(is);

            XMLEvent event = null;
            while (rdr.hasNext()) {
                event = rdr.nextEvent();
                if (event.getEventType() == XMLEvent.START_ELEMENT) {
                    break;
                }
            }

            StartElement startElement = event.asStartElement();
            String tagName = startElement.getName().getLocalPart();
            if (!"plugin".equals(tagName)) {
                throw new IllegalArgumentException("Illegal start tag found in the plugin descriptor. Expected 'plugin' but found '" + tagName + "' in the plugin '" + archive + "'.");
            }
View Full Code Here

        eventReader = inputFactory.createXMLEventReader(fis);
        eventWriter = outputFactory.createXMLEventWriter(fos);

        while(eventReader.hasNext()) {
            XMLEvent xmlEvent = eventReader.nextEvent();
            switch(xmlEvent.getEventType()) {
                case XMLEvent.DTD:
                    // We have DTD declaration, remove it by skipping it
                    break;
                default:
                    eventWriter.add(xmlEvent);
View Full Code Here

        factory = XMLInputFactory.newInstance();
      }
      in = new FileInputStream(artifact);
      parser = factory.createXMLEventReader(in);
      while (parser.hasNext()) {
        XMLEvent event = parser.nextEvent();
        if (event.isStartElement()) {
          return event.asStartElement();
        }
      }
      return null;
    } finally {
      if (parser != null) {
View Full Code Here

        ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());       
        XMLEventReader evtReader = null;
        try {           
            evtReader = inputFactory.createXMLEventReader(inStream);
            // read the first tag which should be a start document
            XMLEvent evt = evtReader.nextEvent();
            assertTrue(evt.isStartDocument());
        } catch (XMLStreamException ex) {
        }
        assertNotNull(evtReader);
       
        CorbaObjectHandler result = simpleBindingImpl.readPrimitiveFromStax(evtReader,
View Full Code Here

TOP

Related Classes of javax.xml.stream.events.XMLEvent

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.