Package org.codehaus.stax2

Examples of org.codehaus.stax2.XMLStreamReader2


    }

    protected int test(File file)
        throws Exception
    {
        XMLInputFactory2 f = getFactory();

        //f.setProperty(WstxInputProperties.P_BASE_URL, "file:///tmp/");

        System.out.print("Coalesce: "+f.getProperty(XMLInputFactory.IS_COALESCING));
        System.out.println("NS-aware: "+f.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE));
        System.out.print("Entity-expanding: "+f.getProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES));
        System.out.println("Validating: "+f.getProperty(XMLInputFactory.IS_VALIDATING));
        System.out.println("Xml-id support: "+f.getProperty(XMLInputFactory2.XSP_SUPPORT_XMLID));

        int total = 0;
        XMLStreamReader2 sr;

        // Let's deal with gzipped files too?
        if (file.getName().endsWith(".gz")) {
            System.out.println("[gzipped input file!]");
            sr = (XMLStreamReader2) f.createXMLStreamReader
                (new InputStreamReader(new GZIPInputStream
                                       (new FileInputStream(file)), "UTF-8"));
        } else {
            sr = f.createXMLStreamReader(file);
            //sr = (XMLStreamReader2) f.createXMLStreamReader(new InputStreamReader(new FileInputStream(file), "IBM500"));
            //sr = (XMLStreamReader2) f.createXMLStreamReader(new StreamSource(file));
        }

        //sr.setProperty(WstxInputProperties.P_BASE_URL, "file:///tmp");
View Full Code Here


public class RunValidation
    extends RunStreamReader
{
    protected XMLInputFactory2 getFactory()
    {
        XMLInputFactory2 f = super.getFactory();

        f.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.TRUE);
        f.setProperty(XMLInputFactory.IS_VALIDATING, Boolean.TRUE);

        // Usually we don't care about full stress testing...
        if (f.isPropertySupported(WstxInputProperties.P_INPUT_BUFFER_LENGTH)) {
            f.setProperty(WstxInputProperties.P_INPUT_BUFFER_LENGTH,
                          new Integer(2000));
        }

        // Do we want to handle validation problems gracefully?
        //f.setProperty(XMLInputFactory.REPORTER, new TestReporter());
View Full Code Here

    }

    protected int test3(byte[] bdata, char[] cdata, File file)
        throws Exception
    {
        XMLInputFactory2 f = (XMLInputFactory2) mInputFactory;
        XMLStreamReader2 sr;

        if (bdata != null) {
            //sr = (XMLStreamReader2) f.createXMLStreamReader(new ByteArrayInputStream(bdata));
            sr = (XMLStreamReader2) f.createXMLStreamReader(new org.codehaus.stax2.io.Stax2ByteArraySource(bdata, 0, bdata.length));
        } else {
            sr = (XMLStreamReader2) f.createXMLStreamReader(new CharArrayReader(cdata));
        }
        //sr = (XMLStreamReader2) f.createXMLStreamReader(file);

        int result = 0;
View Full Code Here

    public void testFullValidationOk()
        throws XMLStreamException
    {
        String XML = "<root attr='123'><leaf /></root>";
        XMLValidationSchema schema = parseDTDSchema(SIMPLE_DTD);
        XMLStreamReader2 sr = getReader(XML);
        sr.validateAgainst(schema);
        while (sr.next() != END_DOCUMENT) { }
        sr.close();
    }
View Full Code Here

    public void testPartialValidationOk()
        throws XMLStreamException
    {
        String XML = "<root attr='123'><leaf /></root>";
        XMLValidationSchema schema = parseDTDSchema(SIMPLE_DTD);
        XMLStreamReader2 sr = getReader(XML);
        assertTokenType(START_ELEMENT, sr.next());
        sr.validateAgainst(schema);
        while (sr.next() != END_DOCUMENT) { }
        sr.close();
    }
View Full Code Here

+"    </xs:sequence>"
+"  </xs:extension>"
+"</xs:complexContent>"
+"</xs:complexType>"
+"</xs:schema>");
        XMLStreamReader2 sr = getReader("<ns11:Root xmlns:ns11='http://MySchema'>"
            +"<ns11:Child xsi:type='ns11:ChildInst' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>"
            +"</ns11:Child>"
            +"</ns11:Root>");
        sr.validateAgainst(schema);
       
        try {
            assertTokenType(START_ELEMENT, sr.next());
            assertEquals("Root", sr.getLocalName());
            assertTokenType(START_ELEMENT, sr.next());
            assertEquals("Child", sr.getLocalName());
            assertTokenType(END_ELEMENT, sr.next());
            assertTokenType(END_ELEMENT, sr.next());
            assertTokenType(END_DOCUMENT, sr.next());
        } catch (XMLValidationException vex) {
            fail("Did not expect validation exception, got: " + vex);
        }
        assertTokenType(END_DOCUMENT, sr.getEventType());       
    }
View Full Code Here

    }

    public void testPropertiesStreamReader() throws XMLStreamException
    {
        XMLInputFactory f = getInputFactory();
        XMLStreamReader2 r = (XMLStreamReader2) f.createXMLStreamReader(new StringReader("<root></root>"));
       
        // First, verify property is indeed unsupported
        assertFalse(r.isPropertySupported(NO_SUCH_PROPERTY));

        /* Ok: as of Woodstox 4.0, behavior is such that no exception is thrown,
         * because javadocs do not indicate that it should be done (save for case
         * where property name is null). Whether this is right interpretation or not
         * is open to discussion; but for now we will verify that behavior does not
         * change from 4.0 without explicit decision.
         */
        /*
        try {
            Object ob = r.getProperty(NO_SUCH_PROPERTY);
            fail("Expected exception, instead got result: "+ob);
        } catch (IllegalArgumentException e) {
            verifyException(e, NO_SUCH_PROPERTY);
        }
        */
        Object ob = r.getProperty(NO_SUCH_PROPERTY);
        assertNull(ob);

        // And although setter is specified by Stax2, it too fails on unrecognized:
        try {
            r.setProperty(NO_SUCH_PROPERTY, "foobar");
            fail("Expected exception");
        } catch (IllegalArgumentException e) {
            verifyException(e, NO_SUCH_PROPERTY);
        }
    }
View Full Code Here

    String runMe = System.getProperty("testWsdlValidation");
    if (runMe == null || "".equals(runMe)) {
      return;
    }
    XMLInputFactory2 factory = getInputFactory();
    XMLStreamReader2 reader = (XMLStreamReader2) factory.createXMLStreamReader(getClass().getResourceAsStream("test-message.xml"), "utf-8");
    QName msgQName = new QName("http://server.hw.demo/", "sayHi");
    while (true) {
      int what = reader.nextTag();
      if (what == XMLStreamConstants.START_ELEMENT) {
        if (reader.getName().equals(msgQName)) {
          reader.validateAgainst(schema);
        }
      } else if (what == XMLStreamConstants.END_ELEMENT) {
        if (reader.getName().equals(msgQName)) {
          reader.stopValidatingAgainst(schema);
        }
      } else if (what == XMLStreamConstants.END_DOCUMENT) {
        break;
      }
    }
View Full Code Here

    private void doTestXmlId(boolean xmlidEnabled,
                             boolean nsAware, boolean coal)
        throws XMLStreamException
    {
        XMLStreamReader2 sr = getReader(XML_WITH_XMLID, xmlidEnabled, nsAware, coal);
        final String xmlidType = xmlidEnabled ? "ID" : "CDATA";

        // root:
        assertTokenType(START_ELEMENT, sr.next());
        assertEquals(1, sr.getAttributeCount());
        assertEquals("id", sr.getAttributeLocalName(0));
        assertEquals("CDATA", sr.getAttributeType(0));
        assertEquals(-1, sr.getAttributeInfo().getIdAttributeIndex());

        // leaf#1:
        assertTokenType(START_ELEMENT, sr.next());
        assertEquals(1, sr.getAttributeCount());
        assertEquals("abc", sr.getAttributeValue(0));
        if (xmlidEnabled) {
            assertEquals(0, sr.getAttributeInfo().getIdAttributeIndex());
        } else {
            assertEquals(-1, sr.getAttributeInfo().getIdAttributeIndex());
        }
        assertEquals(xmlidType, sr.getAttributeType(0));
        assertTokenType(END_ELEMENT, sr.next());

        // leaf#2:
        assertTokenType(START_ELEMENT, sr.next());
        assertEquals(1, sr.getAttributeCount());
        assertEquals("foobar", sr.getAttributeValue(0));
        assertEquals("id", sr.getAttributeLocalName(0));
        assertEquals(-1, sr.getAttributeInfo().getIdAttributeIndex());
        assertEquals("CDATA", sr.getAttributeType(0));
        assertTokenType(END_ELEMENT, sr.next());

        // leaf#3:
        assertTokenType(START_ELEMENT, sr.next());
        assertEquals(1, sr.getAttributeCount());
        assertEquals(xmlidType, sr.getAttributeType(0));
        if (xmlidEnabled) {
            assertEquals(0, sr.getAttributeInfo().getIdAttributeIndex());
        } else {
            assertEquals(-1, sr.getAttributeInfo().getIdAttributeIndex());
        }

        // also, should be normalized:
        if (xmlidEnabled) {
            assertEquals("_otherId", sr.getAttributeValue(0));
        } else {
            assertEquals("  _otherId ", sr.getAttributeValue(0));
        }
        assertTokenType(END_ELEMENT, sr.next());

        sr.close();
    }
View Full Code Here

    }

    private void doTestInvalid(boolean nsAware, boolean coal)
        throws XMLStreamException
    {
        XMLStreamReader2 sr = getValidatingReader(XML_WITH_XMLID_INVALID, nsAware, coal);
        try {
            assertTokenType(DTD, sr.next());
            assertTokenType(START_ELEMENT, sr.next());
            fail("Expected a validation exception for invalid Xml:id attribute declaration");
        } catch (XMLValidationException vex) {
            //System.err.println("VLD exc -> "+vex);
        }
    }
View Full Code Here

TOP

Related Classes of org.codehaus.stax2.XMLStreamReader2

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.