Package javax.xml.stream

Examples of javax.xml.stream.XMLInputFactory


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

    protected void runTest() throws Throwable {
        XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
        XMLStreamReader reader = factory.createXMLStreamReader(
                new StringReader("<?xml version=\"1.0\"?>\r\n<root/>"));
        assertEquals(XMLStreamReader.SPACE, reader.next());
        assertEquals("\n", reader.getText());
    }
View Full Code Here


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

    protected void runTest() throws Throwable {
        XMLInputFactory factory = staxImpl.getDialect().enableCDataReporting(staxImpl.newNormalizedXMLInputFactory());
        XMLStreamReader reader = factory.createXMLStreamReader(new StringReader("<a><![CDATA[test]]></a>"));
        reader.nextTag();
        assertEquals(XMLStreamReader.CDATA, reader.next());
        assertEquals("test", reader.getText());
    }
View Full Code Here

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

    protected void runTest() throws Throwable {
        XMLInputFactory factory = staxImpl.newNormalizedXMLInputFactory();
        XMLStreamReader reader = factory.createXMLStreamReader(new StringReader(
                "<root><child xmlns=\"\"/></root>"));
        int eventType;
        while ((eventType = reader.next()) != XMLStreamReader.END_DOCUMENT) {
            if (eventType == XMLStreamReader.START_ELEMENT) {
                assertNull(reader.getNamespaceURI());
View Full Code Here

    }
   
    public static XMLStreamReader createXMLStreamReader(StAXParserConfiguration configuration,
            final InputStream in, final String encoding) throws XMLStreamException {
       
        final XMLInputFactory inputFactory = getXMLInputFactory(configuration);
        try {
            XMLStreamReader reader =
                (XMLStreamReader)
                AccessController.doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws XMLStreamException {
                        return inputFactory.createXMLStreamReader(in, encoding);
                    }
                }
                );
            if (log.isDebugEnabled()) {
                log.debug("XMLStreamReader is " + reader.getClass().getName());
View Full Code Here

    }
   
    public static XMLStreamReader createXMLStreamReader(StAXParserConfiguration configuration,
            final InputStream in) throws XMLStreamException {
       
        final XMLInputFactory inputFactory = getXMLInputFactory(configuration);
        try {
            XMLStreamReader reader =
                (XMLStreamReader)
                AccessController.doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws XMLStreamException {
                        return inputFactory.createXMLStreamReader(in);
                    }
                }
                );
           
            if (log.isDebugEnabled()) {
View Full Code Here

    }

    public static XMLStreamReader createXMLStreamReader(StAXParserConfiguration configuration,
            final String systemId, final InputStream in) throws XMLStreamException {
       
        final XMLInputFactory inputFactory = getXMLInputFactory(configuration);
        try {
            XMLStreamReader reader =
                (XMLStreamReader)
                AccessController.doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws XMLStreamException {
                        return inputFactory.createXMLStreamReader(systemId, in);
                    }
                }
                );
           
            if (log.isDebugEnabled()) {
View Full Code Here

    }
   
    public static XMLStreamReader createXMLStreamReader(StAXParserConfiguration configuration,
            final Reader in) throws XMLStreamException {
       
        final XMLInputFactory inputFactory = getXMLInputFactory(configuration);
        try {
            XMLStreamReader reader =
                (XMLStreamReader)
                AccessController.doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws XMLStreamException {
                        return inputFactory.createXMLStreamReader(in);
                    }
                }
                );
            if (log.isDebugEnabled()) {
                log.debug("XMLStreamReader is " + reader.getClass().getName());
View Full Code Here

                } else {
                    savedClassLoader = Thread.currentThread().getContextClassLoader();
                    Thread.currentThread().setContextClassLoader(classLoader);
                }
                try {
                    XMLInputFactory factory = XMLInputFactory.newInstance();
                    // Woodstox by default creates coalescing parsers. Even if this violates
                    // the StAX specs, for compatibility with Woodstox, we always enable the
                    // coalescing mode. Note that we need to do that before loading
                    // XMLInputFactory.properties so that this setting can be overridden.
                    factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
                    Map props = loadFactoryProperties("XMLInputFactory.properties");
                    if (props != null) {
                        for (Iterator it = props.entrySet().iterator(); it.hasNext(); ) {
                            Map.Entry entry = (Map.Entry)it.next();
                            factory.setProperty((String)entry.getKey(), entry.getValue());
                        }
                    }
                    StAXDialect dialect = StAXDialectDetector.getDialect(factory.getClass());
                    if (configuration != null) {
                        factory = configuration.configure(factory, dialect);
                    }
                    return new ImmutableXMLInputFactory(dialect.normalize(
                            dialect.makeThreadSafe(factory)));
View Full Code Here

     * @return XMLInputFactory for the current classloader
     */
    private static XMLInputFactory getXMLInputFactory_perClassLoader(StAXParserConfiguration configuration) {
       
        ClassLoader cl = getContextClassLoader();
        XMLInputFactory factory;
        if (cl == null) {
            factory = getXMLInputFactory_singleton(configuration);
        } else {
            // Check the cache
            if (configuration == null) {
                configuration = StAXParserConfiguration.DEFAULT;
            }
            Map map = (Map)inputFactoryPerCLMap.get(configuration);
            if (map == null) {
                map = Collections.synchronizedMap(new WeakHashMap());
                inputFactoryPerCLMap.put(configuration, map);
                factory = null;
            } else {
                factory = (XMLInputFactory)map.get(cl);
            }
           
            // If not found in the cache map, crate a new factory
            if (factory == null) {

                if (log.isDebugEnabled()) {
                    log.debug("About to create XMLInputFactory implementation with " +
                                "classloader=" + cl);
                    log.debug("The classloader for javax.xml.stream.XMLInputFactory is: "
                              + XMLInputFactory.class.getClassLoader());
                }
                try {
                    factory = newXMLInputFactory(null, configuration);
                } catch (ClassCastException cce) {
                    if (log.isDebugEnabled()) {
                        log.debug("Failed creation of XMLInputFactory implementation with " +
                                        "classloader=" + cl);
                        log.debug("Exception is=" + cce);
                        log.debug("Attempting with classloader: " +
                                  XMLInputFactory.class.getClassLoader());
                    }
                    factory = newXMLInputFactory(XMLInputFactory.class.getClassLoader(),
                            configuration);
                }
                   
                if (factory != null) {
                    // Cache the new factory
                    map.put(cl, factory);
                   
                    if (log.isDebugEnabled()) {
                        log.debug("Created XMLInputFactory = " + factory.getClass() +
                                  " with classloader=" + cl);
                        log.debug("Configuration = " + configuration);
                        log.debug("Size of XMLInputFactory map for this configuration = " + map.size());
                        log.debug("Configurations for which factories have been cached = " +
                                inputFactoryPerCLMap.keySet());
View Full Code Here

     */
    private static XMLInputFactory getXMLInputFactory_singleton(StAXParserConfiguration configuration) {
        if (configuration == null) {
            configuration = StAXParserConfiguration.DEFAULT;
        }
        XMLInputFactory f = (XMLInputFactory)inputFactoryMap.get(configuration);
        if (f == null) {
            f = newXMLInputFactory(StAXUtils.class.getClassLoader(), configuration);
            inputFactoryMap.put(configuration, f);
            if (log.isDebugEnabled()) {
                if (f != null) {
                    log.debug("Created singleton XMLInputFactory " + f.getClass() + " with configuration " + configuration);
                }
            }
        }
       
        return f;
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.