Examples of XmlPullParser


Examples of org.xmlpull.v1.XmlPullParser

    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

Examples of org.xmlpull.v1.XmlPullParser

    {
    }

    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

Examples of org.xmlpull.v1.XmlPullParser

            return parse(reader);
    }

    public RepositoryImpl parseRepository(Reader r) throws Exception
    {
        XmlPullParser reader = new KXmlParser();
        reader.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

        reader.setInput(r);
        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");
        }
        return parse(reader);
    }
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

        return parse(reader);
    }

    public ResourceImpl parseResource(Reader r) throws Exception
    {
        XmlPullParser reader = new KXmlParser();
        reader.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

        reader.setInput(r);
        int event = reader.nextTag();
        if (event != XmlPullParser.START_TAG || !RESOURCE.equals(reader.getName()))
        {
            throw new Exception("Expected element 'resource'");
        }
        return parseResource(reader);
    }
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

        return parseResource(reader);
    }

    public CapabilityImpl parseCapability(Reader r) throws Exception
    {
        XmlPullParser reader = new KXmlParser();
        reader.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

        reader.setInput(r);
        int event = reader.nextTag();
        if (event != XmlPullParser.START_TAG || !CAPABILITY.equals(reader.getName()))
        {
            throw new Exception("Expected element 'capability'");
        }
        return parseCapability(reader);
    }
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

        return parseCapability(reader);
    }

    public PropertyImpl parseProperty(Reader r) throws Exception
    {
        XmlPullParser reader = new KXmlParser();
        reader.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

        reader.setInput(r);
        int event = reader.nextTag();
        if (event != XmlPullParser.START_TAG || !P.equals(reader.getName()))
        {
            throw new Exception("Expected element 'p'");
        }
        return parseProperty(reader);
    }
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

        return parseProperty(reader);
    }

    public RequirementImpl parseRequirement(Reader r) throws Exception
    {
        XmlPullParser reader = new KXmlParser();
        reader.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);

        reader.setInput(r);
        int event = reader.nextTag();
        if (event != XmlPullParser.START_TAG || !REQUIRE.equals(reader.getName()))
        {
            throw new Exception("Expected element 'require'");
        }
        return parseRequire(reader);
    }
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

    /**
     * {@inheritDoc}
     */
    public void executeAction( Dsmlv2Container container ) throws XmlPullParserException, IOException
    {
        XmlPullParser xpp = container.getParser();

        int eventType = xpp.getEventType();

        do
        {
            if ( eventType == XmlPullParser.START_DOCUMENT )
            {
                container.setState( Dsmlv2StatesEnum.INIT_GRAMMAR_STATE );
            }
            else if ( eventType == XmlPullParser.END_DOCUMENT )
            {
                container.setState( Dsmlv2StatesEnum.GRAMMAR_END );
            }
            else if ( eventType == XmlPullParser.START_TAG )
            {
                processTag( container, Tag.START );
            }
            else if ( eventType == XmlPullParser.END_TAG )
            {
                processTag( container, Tag.END );
            }

            eventType = xpp.next();
        }
        while ( eventType != XmlPullParser.END_DOCUMENT );
    }
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

     * @throws XmlPullParserException
     *      when an error occurs during the parsing
     */
    private void processTag( Dsmlv2Container container, int tagType ) throws XmlPullParserException
    {
        XmlPullParser xpp = container.getParser();

        String tagName = Strings.toLowerCase( xpp.getName() );

        GrammarTransition transition = getTransition( container.getState(), new Tag( tagName, tagType ) );

        if ( transition != null )
        {
View Full Code Here

Examples of org.xmlpull.v1.XmlPullParser

    private void createAndAddControl( Dsmlv2Container container,
        AbstractDsmlMessageDecorator<? extends Message> parent ) throws XmlPullParserException
    {
        CodecControl<? extends Control> control = null;

        XmlPullParser xpp = container.getParser();

        // Checking and adding the Control's attributes
        String attributeValue;
        // TYPE
        attributeValue = xpp.getAttributeValue( "", "type" );

        if ( attributeValue != null )
        {
            if ( !Oid.isOid( attributeValue ) )
            {
                throw new XmlPullParserException( I18n.err( I18n.ERR_03006 ), xpp, null );
            }

            control = container.getLdapCodecService().newControl( new OpaqueControl( attributeValue ) );
            parent.addControl( control );
        }
        else
        {
            throw new XmlPullParserException( I18n.err( I18n.ERR_03005 ), xpp, null );
        }
        // CRITICALITY
        attributeValue = xpp.getAttributeValue( "", "criticality" );

        if ( attributeValue != null )
        {
            if ( attributeValue.equals( "true" ) )
            {
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.