Package javax.xml.stream

Examples of javax.xml.stream.XMLInputFactory


    public TestCreateXMLStreamReaderThreadSafety(StAXImplementation staxImpl) {
        super(staxImpl);
    }

    protected void runTest() throws Throwable {
        final XMLInputFactory factory = staxImpl.getDialect().makeThreadSafe(staxImpl.newNormalizedXMLInputFactory());
        ConcurrentTestUtils.testThreadSafety(new Action() {
            public void execute() throws Exception {
                String text = String.valueOf((int)(Math.random() * 10000));
                String xml = "<root>" + text + "</root>";
                XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(xml));
                assertEquals(XMLStreamReader.START_DOCUMENT, reader.getEventType());
                assertEquals(XMLStreamReader.START_ELEMENT, reader.next());
                assertEquals(XMLStreamReader.CHARACTERS, reader.next());
                assertEquals(text, reader.getText());
                assertEquals(XMLStreamReader.END_ELEMENT, reader.next());
View Full Code Here


    public TestDisallowDoctypeDeclWithInternalSubset(StAXImplementation staxImpl) {
        super(staxImpl);
    }

    protected void runTest() throws Throwable {
        XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
        factory = staxImpl.getDialect().disallowDoctypeDecl(factory);
        boolean gotException = false;
        boolean reachedDocumentElement = false;
        try {
            XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(
                    "<?xml version='1.0'?><!DOCTYPE root []><root/>"));
            try {
                while (reader.hasNext()) {
                    if (reader.next() == XMLStreamConstants.START_ELEMENT) {
                        reachedDocumentElement = true;
View Full Code Here

    public TestIsStandalone(StAXImplementation staxImpl) {
        super(staxImpl);
    }

    protected void runTest() throws Throwable {
        XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
        XMLStreamReader reader = factory.createXMLStreamReader(
                new StringReader("<?xml version='1.0' standalone='no'?><root/>"));
        assertEquals(false, reader.isStandalone());
        reader.next();
        try {
            reader.isStandalone();
View Full Code Here

        return name;
    }

    public XMLInputFactory newXMLInputFactory() {
        String className = props == null ? null : props.getProperty(XMLInputFactory.class.getName());
        XMLInputFactory factory;
        if (className == null) {
            ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(classLoader);
            try {
                factory = XMLInputFactory.newInstance();
            } finally {
                Thread.currentThread().setContextClassLoader(savedClassLoader);
            }
        } else {
            try {
                factory = (XMLInputFactory)classLoader.loadClass(className).newInstance();
            } catch (Exception ex) {
                throw new FactoryConfigurationError(ex);
            }
        }
        // Check that the parser has actually been loaded from the expected class loader.
        // If the parser has been loaded from the JRE, then comparing the class loaders
        // is not reliable (because it may be null). Hence the check on ParentLastURLClassLoader.
        if (classLoader instanceof ParentLastURLClassLoader
                && factory.getClass().getClassLoader() != classLoader) {
            throw new FactoryConfigurationError("Wrong factory: got " + factory.getClass().getName()
                    + " loaded from " + factory.getClass().getClassLoader());
        }
        return factory;
    }
View Full Code Here

        }
        return factory;
    }
   
    public XMLInputFactory newNormalizedXMLInputFactory() {
        XMLInputFactory factory = newXMLInputFactory();
        if (dialect == null) {
            dialect = StAXDialectDetector.getDialect(factory.getClass());
        }
        return dialect.normalize(factory);
    }
View Full Code Here

    public TestGetEncodingWithCharacterStream(StAXImplementation staxImpl) {
        super(staxImpl);
    }

    protected void runTest() throws Throwable {
        XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
        XMLStreamReader reader = factory.createXMLStreamReader(new StringReader("<root/>"));
        assertNull(reader.getEncoding());
    }
View Full Code Here

    public TestDisallowDoctypeDeclWithDenialOfService(StAXImplementation staxImpl) {
        super(staxImpl);
    }

    protected void runTest() throws Throwable {
        XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
        factory = staxImpl.getDialect().disallowDoctypeDecl(factory);
        InputStream in = TestDisallowDoctypeDeclWithDenialOfService.class.getResourceAsStream("doctype_dos.xml");
        try {
            boolean gotException = false;
            boolean reachedDocumentElement = false;
            try {
                XMLStreamReader reader = factory.createXMLStreamReader(in);
                try {
                    while (reader.hasNext()) {
                        if (reader.next() == XMLStreamConstants.START_ELEMENT) {
                            reachedDocumentElement = true;
                        }
View Full Code Here

                        ConformanceTestFile.class.getResourceAsStream("filelist")));
                List result = new ArrayList(10);
                // We make use of Woodstox' DTDInfo interface here, but we want to be able to use system properties
                // to specify the StAX implementation to be used by the tests. Therefore we need to create
                // an instance of the Woodstox InputFactory implementation directly.
                XMLInputFactory inputFactory = new WstxInputFactory();
                inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
                String name;
                while ((name = in.readLine()) != null) {
                    String resourceName = "org/apache/axiom/testutils/conformance/" + name;
                    boolean hasDTD = false;
                    boolean hasExternalSubset = false;
                    boolean hasInternalSubset = false;
                    boolean hasEntityReferences = false;
                    try {
                        XMLStreamReader reader = inputFactory.createXMLStreamReader(new StreamSource(
                                ConformanceTestFile.class.getResource(name).toString()));
                        while (reader.hasNext()) {
                            switch (reader.next()) {
                                case XMLStreamReader.DTD:
                                    hasDTD = true;
View Full Code Here

        {
            // Set header values intial to the empty string
            String title = "";
            String link = "";
            // First create a new XMLInputFactory
            XMLInputFactory inputFactory = XMLInputFactory.newInstance();
            // Setup a new eventReader
            InputStream in = read();
            XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
            // Read the XML document
            while (eventReader.hasNext())
            {
                XMLEvent event = eventReader.nextEvent();
                if (event.isStartElement())
View Full Code Here

  public String get_FREQ_fromSDMX(String sdmxFilePath)
  {
    String freq = "";
    int counter = 0;
    try {
      XMLInputFactory inputFactory = XMLInputFactory.newInstance();
      InputStream in = new FileInputStream(sdmxFilePath);
      XMLEventReader eventReader = inputFactory.createXMLEventReader(in);
     
      while (eventReader.hasNext())
      {
        XMLEvent event = eventReader.nextEvent();
        if (event.isStartElement())
View Full Code Here

TOP

Related Classes of javax.xml.stream.XMLInputFactory

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.