Package javax.xml.stream.events

Examples of javax.xml.stream.events.StartElement


    }

    private CorbaPrimitiveHandler getAttributeValue(XMLEvent evt, QName attrName, QName idlType) {
        CorbaPrimitiveHandler result = null;
        if (evt.isStartElement()) {
            StartElement el = (StartElement) evt;
            QName name = attrName;
            if (!CorbaUtils.isAttributeFormQualified(serviceInfo, attrName.getNamespaceURI())) {
                name = new QName("", attrName.getLocalPart());
            }
            Attribute attr = el.getAttributeByName(name);
            if (attr != null) {
                TypeCode tc = CorbaUtils.getTypeCode(orb, idlType, typeMaps);
                result = new CorbaPrimitiveHandler(new QName("value"), idlType, tc, null);
                result.setValueFromData(attr.getValue());
            }
View Full Code Here


    }
   
   
    private static void writeStartElementEvent(XMLEvent event, XMLStreamWriter writer)
        throws XMLStreamException {
        StartElement start = event.asStartElement();
        QName name = start.getName();
        String nsURI = name.getNamespaceURI();
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
       
        if (prefix != null) {
            writer.writeStartElement(prefix, localName, nsURI);
        } else if (nsURI != null) {
            writer.writeStartElement(localName, nsURI);
        } else {
            writer.writeStartElement(localName);
        }
        Iterator<XMLEvent> it = CastUtils.cast(start.getNamespaces());
        while (it != null && it.hasNext()) {
            writeEvent(it.next(), writer);
        }
       
        it = CastUtils.cast(start.getAttributes());
        while (it != null && it.hasNext()) {
            writeAttributeEvent(it.next(), writer);           
        }
    }
View Full Code Here

    }
   
   
    private static void writeStartElementEvent(XMLEvent event, XMLStreamWriter writer)
        throws XMLStreamException {
        StartElement start = event.asStartElement();
        QName name = start.getName();
        String nsURI = name.getNamespaceURI();
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
       
        if (prefix != null) {
            writer.writeStartElement(prefix, localName, nsURI);
        } else if (nsURI != null) {
            writer.writeStartElement(localName, nsURI);
        } else {
            writer.writeStartElement(localName);
        }
        Iterator it = start.getNamespaces();
        while (it != null && it.hasNext()) {
            writeEvent((XMLEvent)it.next(), writer);
        }
       
        it = start.getAttributes();
        while (it != null && it.hasNext()) {
            writeAttributeEvent((Attribute)it.next(), writer);           
        }
    }
View Full Code Here

      while (eventReader.hasNext())
      {
        XMLEvent event = eventReader.nextEvent();
        if (event.isStartElement())
        {
          StartElement startElement = event.asStartElement();
          // if the element is starting with <data:Series
          if (startElement.getName().getLocalPart() == "Series")
          {
            counter += 1;
            Iterator<Attribute> attributes = startElement.getAttributes();
            while (attributes.hasNext())
            {
              Attribute attribute = attributes.next();
              // if it has a FREQ attribute
              if (attribute.getName().toString().equals("FREQ"))
View Full Code Here

        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

      final XMLEvent event = (XMLEvent) e.getMessage();

      switch (status) {
      case CONNECT:
        if (event.isStartElement()) {
          final StartElement element = event.asStartElement();

          if (STREAM_NAME.equals(element.getName()) && XMPPNamespaces.ACCEPT.equals(element.getNamespaceURI(null))) {
            if (!serverName.equals(element.getAttributeByName(new QName("from")).getValue())) {
              throw new Exception("server name mismatch");
            }
            streamID = element.getAttributeByName(new QName("id")).getValue();

            status = Status.AUTHENTICATE;
            Channels.write(ctx.getChannel(), ChannelBuffers.copiedBuffer("<handshake>" + Hashing.sha1().hashString(streamID + secret, CharsetUtil.UTF_8).toString() + "</handshake>", CharsetUtil.UTF_8));
          }
        } else {
          throw new Exception("Expected stream:stream element");
        }
        break;
      case AUTHENTICATE:
      case READY:
        if (event.isEndElement()) {
          final EndElement element = event.asEndElement();

          if (STREAM_NAME.equals(element.getName())) {
            Channels.disconnect(ctx.getChannel());
            return;
          }
        }
        break;
      case DISCONNECTED:
        throw new Exception("received DISCONNECTED");
      }
    }
    else if (e.getMessage() instanceof XMLElement) {
      final XMLElement element = (XMLElement) e.getMessage();
     
      switch (status) {
      case AUTHENTICATE:
        if (!"handshake".equals(element.getTagName()))
          throw new Exception("expected handshake");
        status = Status.READY;
        System.out.println("logged in");
       
        ctx.getPipeline().get(XMPPStreamHandler.class).loggedIn();
View Full Code Here

    }
   
   
    private static void writeStartElementEvent(XMLEvent event, XMLStreamWriter writer)
        throws XMLStreamException {
        StartElement start = event.asStartElement();
        QName name = start.getName();
        String nsURI = name.getNamespaceURI();
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
       
        if (prefix != null) {
            writer.writeStartElement(prefix, localName, nsURI);
        } else if (nsURI != null) {
            writer.writeStartElement(localName, nsURI);
        } else {
            writer.writeStartElement(localName);
        }
        Iterator it = start.getNamespaces();
        while (it != null && it.hasNext()) {
            writeEvent((XMLEvent)it.next(), writer);
        }
       
        it = start.getAttributes();
        while (it != null && it.hasNext()) {
            writeAttributeEvent((Attribute)it.next(), writer);           
        }
    }
View Full Code Here

    }
   
   
    private static void writeStartElementEvent(XMLEvent event, XMLStreamWriter writer)
        throws XMLStreamException {
        StartElement start = event.asStartElement();
        QName name = start.getName();
        String nsURI = name.getNamespaceURI();
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
       
        if (prefix != null) {
            writer.writeStartElement(prefix, localName, nsURI);
        } else if (nsURI != null) {
            writer.writeStartElement(localName, nsURI);
        } else {
            writer.writeStartElement(localName);
        }
        Iterator it = start.getNamespaces();
        while (it != null && it.hasNext()) {
            writeEvent((XMLEvent)it.next(), writer);
        }
       
        it = start.getAttributes();
        while (it != null && it.hasNext()) {
            writeAttributeEvent((Attribute)it.next(), writer);           
        }
    }
View Full Code Here

      //If there are pruned elements in the queue filtering events is still needed
      if (!prunedElements.isEmpty()) {
        //If another start element add it to the queue
        if (event.isStartElement()) {
          final StartElement startElement = event.asStartElement();
          prunedElements.push(startElement.getName());
        }
        //If end element pop the newest name of the queue and double check that the start/end elements match up
        else if (event.isEndElement()) {
          final QName startElementName = prunedElements.pop();

          final EndElement endElement = event.asEndElement();
          final QName endElementName = endElement.getName();

          if (!startElementName.equals(endElementName)) {
            throw new IllegalArgumentException("Malformed XMLEvent stream. Expected end element for " + startElementName + " but found end element for " + endElementName);
          }
        }

        event = null;
      }
      else {
        final XMLEvent filteredEvent = this.filterEvent(event, peek);

        //If the event is being removed and it is a start element all elements until the matching
        //end element need to be removed as well
        if (filteredEvent == null && event.isStartElement()) {
          final StartElement startElement = event.asStartElement();
          final QName name = startElement.getName();
          prunedElements.push(name);
        }

        event = filteredEvent;
      }
View Full Code Here

      {
         XMLEvent event = reader.nextEvent();
         switch (event.getEventType())
         {
            case XMLStreamConstants.START_ELEMENT :
               StartElement startElement = event.asStartElement();

               Map<String, String> attr = new HashMap<String, String>();

               Iterator attributes = startElement.getAttributes();
               while (attributes.hasNext())
               {
                  Attribute attribute = (Attribute)attributes.next();
                  attr.put(attribute.getName().getLocalPart(), attribute.getValue());
               }

               String localName = startElement.getName().getLocalPart();
               if (localName.equals(REFERENCE_ELEMENT))
               {
                  String bindName = attr.get(BIND_NAME_ATTR);
                  String className = attr.get(CLASS_NAME_ATTR);
                  String factoryName = attr.get(FACTORY_ATTR);
View Full Code Here

TOP

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

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.