Examples of XmlPullParser


Examples of org.gjt.xpp.XmlPullParser

  protected Document parseDocument() throws DocumentException, IOException,
      XmlPullParserException {
    Document document = getDocumentFactory().createDocument();
    Element parent = null;
    XmlPullParser parser = getXPPParser();
    parser.setNamespaceAware(true);

    ProxyXmlStartTag startTag = new ProxyXmlStartTag();
    XmlEndTag endTag = xppFactory.newEndTag();

    while (true) {
      int type = parser.next();

      switch (type) {
        case XmlPullParser.END_DOCUMENT:
          return document;

        case XmlPullParser.START_TAG: {
          parser.readStartTag(startTag);

          Element newElement = startTag.getElement();

          if (parent != null) {
            parent.add(newElement);
          } else {
            document.add(newElement);
          }

          parent = newElement;

          break;
        }

        case XmlPullParser.END_TAG: {
          parser.readEndTag(endTag);

          if (parent != null) {
            parent = parent.getParent();
          }

          break;
        }

        case XmlPullParser.CONTENT: {
          String text = parser.readContent();

          if (parent != null) {
            parent.addText(text);
          } else {
            String msg = "Cannot have text content outside of the "
View Full Code Here

Examples of org.waveprotocol.wave.model.document.parser.XmlPullParser

   * @param text
   * @return a DocInitialization
   * @throws XmlParseException
   */
  public static DocInitialization docInitializationFromXml(String text) throws XmlParseException {
    XmlPullParser p = XmlParserFactory.unbuffered(text);
    DocOpBuilder builder = new DocOpBuilder();
    while (p.hasNext()) {
      switch (p.next()) {
        case START_ELEMENT:
          builder.elementStart(p.getTagName(), AttributesImpl.fromStringMap(p.getAttributes()));
          continue;
        case END_ELEMENT:
          builder.elementEnd();
          continue;
        case TEXT:
          builder.characters(p.getText());
          continue;
        case PROCESSING_INSTRUCTION:
          String name = p.getProcessingInstructionName();
          AnnotationBoundaryMapBuilder anBuilder = new AnnotationBoundaryMapBuilder();
          if (PI_TARGET.equals(name)) {
            List<Pair<String, String>> parseAnnotations =
                AnnotationParser.parseAnnotations(p.getProcessingInstructionValue());
            for (Pair<String, String> ann : parseAnnotations) {
              final String key = ann.first;
              final String oldValue = null;
              final String newValue = ann.second;
              if (newValue == null) {
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

                writer.write(stream.toString());
                writer.flush();
                stream = null;

                // Get the answer from the server
                XmlPullParser xpp = reader.getXPPParser();
                for (int eventType = xpp.getEventType(); eventType != XmlPullParser.START_TAG;) {
                    eventType = xpp.next();
                }

                // Set the streamID returned from the server
                connectionID = xpp.getAttributeValue("", "id");
                if (xpp.getAttributeValue("", "from") != null) {
                    this.domain = xpp.getAttributeValue("", "from");
                }
                xmlSerializer = new XMLWriter(writer);

                // Handshake with the server
                stream = new StringBuilder();
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

    //-------------------------------------------------------------------------
    public Document parseDocument() throws DocumentException, IOException, XmlPullParserException {
        DocumentFactory df = getDocumentFactory();
        Document document = df.createDocument();
        Element parent = null;
        XmlPullParser pp = getXPPParser();
        int count = 0;
        while (true) {
            int type = -1;
            type = pp.nextToken();
            switch (type) {
                case XmlPullParser.PROCESSING_INSTRUCTION: {
                    String text = pp.getText();
                    int loc = text.indexOf(" ");
                    if (loc >= 0) {
                        document.addProcessingInstruction(text.substring(0, loc), text.substring(loc + 1));
                    }
                    else
                        document.addProcessingInstruction(text, "");
                    break;
                }
                case XmlPullParser.COMMENT: {
                    if (parent != null)
                        parent.addComment(pp.getText());
                    else
                        document.addComment(pp.getText());
                    break;
                }
                case XmlPullParser.CDSECT: {
                    String text = pp.getText();
                    if (parent != null) {
                        parent.addCDATA(text);
                    }
                    else {
                        if (text.trim().length() > 0) {
                            throw new DocumentException("Cannot have text content outside of the root document");
                        }
                    }
                    break;

                }
                case XmlPullParser.ENTITY_REF: {
                    String text = pp.getText();
                    if (parent != null) {
                        parent.addText(text);
                    }
                    else {
                        if (text.trim().length() > 0) {
                            throw new DocumentException("Cannot have an entityref outside of the root document");
                        }
                    }
                    break;
                }
                case XmlPullParser.END_DOCUMENT: {
                    return document;
                }
                case XmlPullParser.START_TAG: {
                    QName qname = (pp.getPrefix() == null) ? df.createQName(pp.getName(), pp.getNamespace()) : df.createQName(pp.getName(), pp.getPrefix(), pp.getNamespace());
                    Element newElement = null;
                    // Do not include the namespace if this is the start tag of a new packet
                    // This avoids including "jabber:client", "jabber:server" or
                    // "jabber:component:accept"
                    if ("jabber:client".equals(qname.getNamespaceURI()) ||
                            "jabber:server".equals(qname.getNamespaceURI()) ||
                            "jabber:component:accept".equals(qname.getNamespaceURI()) ||
                            "http://jabber.org/protocol/httpbind".equals(qname.getNamespaceURI())) {
                        newElement = df.createElement(pp.getName());
                    }
                    else {
                        newElement = df.createElement(qname);
                    }
                    int nsStart = pp.getNamespaceCount(pp.getDepth() - 1);
                    int nsEnd = pp.getNamespaceCount(pp.getDepth());
                    for (int i = nsStart; i < nsEnd; i++)
                        if (pp.getNamespacePrefix(i) != null)
                            newElement.addNamespace(pp.getNamespacePrefix(i), pp.getNamespaceUri(i));
                    for (int i = 0; i < pp.getAttributeCount(); i++) {
                        QName qa = (pp.getAttributePrefix(i) == null) ? df.createQName(pp.getAttributeName(i)) : df.createQName(pp.getAttributeName(i), pp.getAttributePrefix(i), pp.getAttributeNamespace(i));
                        newElement.addAttribute(qa, pp.getAttributeValue(i));
                    }
                    if (parent != null) {
                        parent.add(newElement);
                    }
                    else {
                        document.add(newElement);
                    }
                    parent = newElement;
                    count++;
                    break;
                }
                case XmlPullParser.END_TAG: {
                    if (parent != null) {
                        parent = parent.getParent();
                    }
                    count--;
                    if (count < 1) {
                        return document;
                    }
                    break;
                }
                case XmlPullParser.TEXT: {
                    String text = pp.getText();
                    if (parent != null) {
                        parent.addText(text);
                    }
                    else {
                        if (text.trim().length() > 0) {
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

     * @return parser instance
     * @throws XmlPullParserException on error creating parser
     */
    private XmlPullParser createParser(boolean nsf)
        throws XmlPullParserException {
        XmlPullParser parser = m_factory.newPullParser();
        if (nsf) {
            parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
        }
        return parser;
    }
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

  protected Document parseDocument() throws DocumentException, IOException,
      XmlPullParserException {
    DocumentFactory df = getDocumentFactory();
    Document document = df.createDocument();
    Element parent = null;
    XmlPullParser pp = getXPPParser();
    pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

    while (true) {
      int type = pp.nextToken();

      switch (type) {
        case XmlPullParser.PROCESSING_INSTRUCTION: {
          String text = pp.getText();
          int loc = text.indexOf(" ");

          if (loc >= 0) {
            String target = text.substring(0, loc);
            String txt = text.substring(loc + 1);
            document.addProcessingInstruction(target, txt);
          } else {
            document.addProcessingInstruction(text, "");
          }

          break;
        }

        case XmlPullParser.COMMENT: {
          if (parent != null) {
            parent.addComment(pp.getText());
          } else {
            document.addComment(pp.getText());
          }

          break;
        }

        case XmlPullParser.CDSECT: {
          if (parent != null) {
            parent.addCDATA(pp.getText());
          } else {
            String msg = "Cannot have text content outside of the "
                + "root document";
            throw new DocumentException(msg);
          }

          break;
        }

        case XmlPullParser.ENTITY_REF:
          break;

        case XmlPullParser.END_DOCUMENT:
          return document;

        case XmlPullParser.START_TAG: {
          QName qname = (pp.getPrefix() == null) ? df.createQName(pp
              .getName(), pp.getNamespace()) : df.createQName(pp
              .getName(), pp.getPrefix(), pp.getNamespace());
          Element newElement = df.createElement(qname);
          int nsStart = pp.getNamespaceCount(pp.getDepth() - 1);
          int nsEnd = pp.getNamespaceCount(pp.getDepth());

          for (int i = nsStart; i < nsEnd; i++) {
            if (pp.getNamespacePrefix(i) != null) {
              newElement.addNamespace(pp.getNamespacePrefix(i),
                  pp.getNamespaceUri(i));
            }
          }

          for (int i = 0; i < pp.getAttributeCount(); i++) {
            QName qa = (pp.getAttributePrefix(i) == null) ? df
                .createQName(pp.getAttributeName(i)) : df
                .createQName(pp.getAttributeName(i), pp
                    .getAttributePrefix(i), pp
                    .getAttributeNamespace(i));
            newElement.addAttribute(qa, pp.getAttributeValue(i));
          }

          if (parent != null) {
            parent.add(newElement);
          } else {
            document.add(newElement);
          }

          parent = newElement;

          break;
        }

        case XmlPullParser.END_TAG: {
          if (parent != null) {
            parent = parent.getParent();
          }

          break;
        }

        case XmlPullParser.TEXT: {
          String text = pp.getText();

          if (parent != null) {
            parent.addText(text);
          } else {
            String msg = "Cannot have text content outside of the "
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

      }

      // parse response stuff
      //
      // setup pull parser
      XmlPullParser pullParser = XmlPullParserFactory.newInstance().newPullParser();
      entity = response.getEntity();
      Reader reader = new InputStreamReader(new BufferedInputStream(entity.getContent()));
// for testing purposes only
// reader = new StringReader("<?xml version='1.0'?><methodResponse><params><param><value>\n\n\n</value></param></params></methodResponse>");
      pullParser.setInput(reader);
     
      // lets start pulling...
      pullParser.nextTag();
      pullParser.require(XmlPullParser.START_TAG, null, Tag.METHOD_RESPONSE);
     
      pullParser.nextTag(); // either Tag.PARAMS (<params>) or Tag.FAULT (<fault>) 
      String tag = pullParser.getName();
      if (tag.equals(Tag.PARAMS)) {
        // normal response
        pullParser.nextTag(); // Tag.PARAM (<param>)
        pullParser.require(XmlPullParser.START_TAG, null, Tag.PARAM);
        pullParser.nextTag(); // Tag.VALUE (<value>)
        // no parser.require() here since its called in XMLRPCSerializer.deserialize() below
       
        // deserialize result
        Object obj = iXMLRPCSerializer.deserialize(pullParser);
        entity.consumeContent();
        return obj;
      } else
      if (tag.equals(Tag.FAULT)) {
        // fault response
        pullParser.nextTag(); // Tag.VALUE (<value>)
        // no parser.require() here since its called in XMLRPCSerializer.deserialize() below

        // deserialize fault result
        Map<String, Object> map = (Map<String, Object>) iXMLRPCSerializer.deserialize(pullParser);
        String faultString = (String) map.get(Tag.FAULT_STRING);
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

  public MethodCall readMethodCall(Socket socket) throws IOException, XmlPullParserException
  {
    MethodCall methodCall = new MethodCall();
    InputStream inputStream = socket.getInputStream();

    XmlPullParser pullParser = xmlPullParserFromSocket(inputStream);
   
    pullParser.nextTag();
    pullParser.require(XmlPullParser.START_TAG, null, Tag.METHOD_CALL);
    pullParser.nextTag();
    pullParser.require(XmlPullParser.START_TAG, null, Tag.METHOD_NAME);

    methodCall.setMethodName(pullParser.nextText());

    pullParser.nextTag();
    pullParser.require(XmlPullParser.START_TAG, null, Tag.PARAMS);
    pullParser.nextTag(); // <param>
   
    do {
      //Log.d(Tag.LOG, "type=" + pullParser.getEventType() + ", tag=" + pullParser.getName());
      pullParser.require(XmlPullParser.START_TAG, null, Tag.PARAM);
      pullParser.nextTag(); // <value>

      Object param = iXMLRPCSerializer.deserialize(pullParser);
      methodCall.params.add(param); // add to return value

      pullParser.nextTag();
      pullParser.require(XmlPullParser.END_TAG, null, Tag.PARAM);
      pullParser.nextTag(); // <param> or </params>
     
    } while (!pullParser.getName().equals(Tag.PARAMS)); // </params>

    return methodCall;
  }
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

    while (br.ready())
      xmlRpcText = xmlRpcText + br.readLine();
    // Log.d(Tag.LOG, "xml received:" + xmlRpcText);
   
    InputStream inputStream = new ByteArrayInputStream(xmlRpcText.getBytes("UTF-8"));
    XmlPullParser pullParser = XmlPullParserFactory.newInstance().newPullParser();
    Reader streamReader = new InputStreamReader(inputStream);
    pullParser.setInput(streamReader);
    return pullParser;
  }
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

        }

        XmlPullParserFactory factory = XmlPullParserFactory.newInstance(System.getProperty(XmlPullParserFactory.PROPERTY_NAME), null);
        factory.setNamespaceAware(true);

        XmlPullParser xpp = factory.newPullParser();
        xpp.setInput(new StringReader(data));

        int eventType = xpp.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG && xpp.getName().equals("BinarySecurityToken")) {
                if (xpp.getAttributeValue(null, "Id").equals("Compact1")) {
                    xpp.next();
                    securityToken = xpp.getText().replace("&", "&amp;");
                }
            }
            xpp.next();
            eventType = xpp.getEventType();
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.