Package org.xmlpull.v1.builder

Examples of org.xmlpull.v1.builder.XmlInfosetBuilder


                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


    //-------------------------------------------------------------------------
    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

     * @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

  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

      }

      // 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

  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

    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

        }

        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

    private List<Contact> contactsResponseHandle(String data) throws Exception  {
        List<Contact> contacts = new ArrayList<Contact>();

        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser xpp = factory.newPullParser();
        xpp.setInput(new StringReader(data));

        int eventType = xpp.getEventType();

        String username = null;
        String email = null;
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG && "Contact".equals(xpp.getName())) {
                while (true) {
                    if (eventType == XmlPullParser.END_TAG && "Contact".equals(xpp.getName())) {
                        break;
                    }

                    if (eventType == XmlPullParser.START_TAG && "ContactEmail".equals(xpp.getName())) {
                        while (true) {
                            if (eventType == XmlPullParser.END_TAG && "ContactEmail".equals(xpp.getName())) {
                                break;
                            }

                            if (eventType == XmlPullParser.START_TAG && "email".equals(xpp.getName())) {
                                xpp.next();
                                email = xpp.getText();
                            }
                            xpp.next();
                            eventType = xpp.getEventType();
                        }
                    }

                    if (eventType == XmlPullParser.START_TAG && "passportName".equals(xpp.getName())) {
                        xpp.next();
                        email = xpp.getText();
                    }

                    if (eventType == XmlPullParser.START_TAG && "displayName".equals(xpp.getName())) {
                        xpp.next();
                        username = xpp.getText();

                        Contact contact = new Contact(username, email);
                        contacts.add(contact);
                    }

                    xpp.next();
                    eventType = xpp.getEventType();
                }
            }
            xpp.next();
            eventType = xpp.getEventType();
        }

        return contacts;
    }
View Full Code Here

    {
    }

    public RepositoryImpl parseRepository(InputStream is) throws Exception
    {
        XmlPullParser reader = new KXmlParser();

        // The spec-based Repository XML uses namespaces, so switch this on...
        reader.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

        reader.setInput(is, null);
        int event = reader.nextTag();
        if (event != XmlPullParser.START_TAG || !REPOSITORY.equals(reader.getName()))
        {
            throw new Exception("Expected element 'repository' at the root of the document");
        }

        if ("http://www.osgi.org/xmlns/repository/v1.0.0".equals(reader.getNamespace()))
            // TODO there are a bunch of other methods here that create a parser, should they be updated too?
            // at the very least they should be made namespace-aware too, so that parsing is the same no matter
            // how its initiated.
            return SpecXMLPullParser.parse(reader);
        else
View Full Code Here

TOP

Related Classes of org.xmlpull.v1.builder.XmlInfosetBuilder

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.