Package javax.xml.stream

Examples of javax.xml.stream.XMLOutputFactory


        return createXMLStreamWriter(null, out);
    }
   
    public static XMLStreamWriter createXMLStreamWriter(StAXWriterConfiguration configuration,
            final OutputStream out) throws XMLStreamException {
        final XMLOutputFactory outputFactory = getXMLOutputFactory(configuration);
        try {
            XMLStreamWriter writer =
                (XMLStreamWriter)
                AccessController.doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws XMLStreamException {
                        return outputFactory.createXMLStreamWriter(out, OMConstants.DEFAULT_CHAR_SET_ENCODING);
                    }
                }
                );
               
            if (log.isDebugEnabled()) {
View Full Code Here


        return createXMLStreamWriter(null, out, encoding);
    }
   
    public static XMLStreamWriter createXMLStreamWriter(StAXWriterConfiguration configuration,
            final OutputStream out, final String encoding) throws XMLStreamException {
        final XMLOutputFactory outputFactory = getXMLOutputFactory(configuration);
        try {
            XMLStreamWriter writer =
                (XMLStreamWriter)
                AccessController.doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws XMLStreamException {
                        return outputFactory.createXMLStreamWriter(out, encoding);
                    }
                }
                );
           
            if (log.isDebugEnabled()) {
View Full Code Here

        return createXMLStreamWriter(null, out);
    }
   
    public static XMLStreamWriter createXMLStreamWriter(StAXWriterConfiguration configuration,
            final Writer out) throws XMLStreamException {
        final XMLOutputFactory outputFactory = getXMLOutputFactory(configuration);
        try {
            XMLStreamWriter writer =
                (XMLStreamWriter)
                AccessController.doPrivileged(new PrivilegedExceptionAction() {
                    public Object run() throws XMLStreamException {
                        return outputFactory.createXMLStreamWriter(out);
                    }
                }
                );
            if (log.isDebugEnabled()) {
                log.debug("XMLStreamWriter is " + writer.getClass().getName());
View Full Code Here

                } else {
                    savedClassLoader = Thread.currentThread().getContextClassLoader();
                    Thread.currentThread().setContextClassLoader(classLoader);
                }
                try {
                    XMLOutputFactory factory = XMLOutputFactory.newInstance();
                    factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
                                        Boolean.FALSE);
                    Map props = loadFactoryProperties("XMLOutputFactory.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 ImmutableXMLOutputFactory(dialect.normalize(
                            dialect.makeThreadSafe(factory)));
View Full Code Here

    /**
     * @return XMLOutputFactory for the current classloader
     */
    private static XMLOutputFactory getXMLOutputFactory_perClassLoader(StAXWriterConfiguration configuration) {
        ClassLoader cl = getContextClassLoader();
        XMLOutputFactory factory;
        if (cl == null) {
            factory = getXMLOutputFactory_singleton(configuration);
        } else {
            if (configuration == null) {
                configuration = StAXWriterConfiguration.DEFAULT;
            }
            Map map = (Map)outputFactoryPerCLMap.get(configuration);
            if (map == null) {
                map = Collections.synchronizedMap(new WeakHashMap());
                outputFactoryPerCLMap.put(configuration, map);
                factory = null;
            } else {
                factory = (XMLOutputFactory)map.get(cl);
            }
           
            if (factory == null) {
                if (log.isDebugEnabled()) {
                    log.debug("About to create XMLOutputFactory implementation with " +
                                "classloader=" + cl);
                    log.debug("The classloader for javax.xml.stream.XMLOutputFactory is: " +
                              XMLOutputFactory.class.getClassLoader());
                }
                try {
                    factory = newXMLOutputFactory(null, configuration);
                } catch (ClassCastException cce) {
                    if (log.isDebugEnabled()) {
                        log.debug("Failed creation of XMLOutputFactory implementation with " +
                                        "classloader=" + cl);
                        log.debug("Exception is=" + cce);
                        log.debug("Attempting with classloader: " +
                                  XMLOutputFactory.class.getClassLoader());
                    }
                    factory = newXMLOutputFactory(XMLOutputFactory.class.getClassLoader(),
                            configuration);
                }
                if (factory != null) {
                    map.put(cl, factory);
                    if (log.isDebugEnabled()) {
                        log.debug("Created XMLOutputFactory = " + factory.getClass()
                                  + " for classloader=" + cl);
                        log.debug("Configuration = " + configuration);
                        log.debug("Size of XMLOutFactory map for this configuration = " + map.size());
                        log.debug("Configurations for which factories have been cached = " +
                                outputFactoryPerCLMap.keySet());
View Full Code Here

     */
    private static XMLOutputFactory getXMLOutputFactory_singleton(StAXWriterConfiguration configuration) {
        if (configuration == null) {
            configuration = StAXWriterConfiguration.DEFAULT;
        }
        XMLOutputFactory f = (XMLOutputFactory)outputFactoryMap.get(configuration);
        if (f == null) {
            f = newXMLOutputFactory(StAXUtils.class.getClassLoader(), configuration);
            outputFactoryMap.put(configuration, f);
            if (log.isDebugEnabled()) {
                if (f != null) {
                    log.debug("Created singleton XMLOutputFactory " + f.getClass() + " with configuration " + configuration);
                }
            }
        }
        return f;
    }
View Full Code Here

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

    protected void runTest() throws Throwable {
        final XMLOutputFactory factory = staxImpl.getDialect().makeThreadSafe(staxImpl.newNormalizedXMLOutputFactory());
        ConcurrentTestUtils.testThreadSafety(new Action() {
            public void execute() throws Exception {
                String text = String.valueOf((int)(Math.random() * 10000));
                StringWriter out = new StringWriter();
                XMLStreamWriter writer = factory.createXMLStreamWriter(out);
                writer.writeStartElement("root");
                writer.writeCharacters(text);
                writer.writeEndElement();
                writer.writeEndDocument();
                writer.flush();
View Full Code Here

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

    protected void runTest() throws Throwable {
        XMLOutputFactory factory = staxImpl.newNormalizedXMLOutputFactory();
        // This should cause an exception
        try {
            factory.createXMLEventWriter(System.out, null);
        } catch (Throwable ex) {
            // Expected
            return;
        }
        // Attention here: since the fail method works by throwing an exception and we
View Full Code Here

        return dialect.normalize(factory);
    }

    public XMLOutputFactory newXMLOutputFactory() {
        String className = props == null ? null : props.getProperty(XMLOutputFactory.class.getName());
        XMLOutputFactory factory;
        if (className == null) {
            ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(classLoader);
            try {
                factory = XMLOutputFactory.newInstance();
            } finally {
                Thread.currentThread().setContextClassLoader(savedClassLoader);
            }
        } else {
            try {
                factory = (XMLOutputFactory)classLoader.loadClass(className).newInstance();
            } catch (Exception ex) {
                throw new FactoryConfigurationError(ex);
            }
        }
        if (classLoader != ClassLoader.getSystemClassLoader()
                && 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 XMLOutputFactory newNormalizedXMLOutputFactory() {
        XMLOutputFactory factory = newXMLOutputFactory();
        if (dialect == null) {
            dialect = StAXDialectDetector.getDialect(factory.getClass());
        }
        return dialect.normalize(factory);
    }
View Full Code Here

TOP

Related Classes of javax.xml.stream.XMLOutputFactory

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.