Search in sources :

Example 16 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project teiid by teiid.

the class PlanNode method toXml.

/**
 * Converts this PlanNode to XML. See the JAXB bindings for the
 * document form.
 * @return an XML document of this PlanNode
 */
public String toXml() {
    try {
        XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
        StringWriter stringWriter = new StringWriter();
        XMLStreamWriter writer = outputFactory.createXMLStreamWriter(stringWriter);
        // $NON-NLS-1$ //$NON-NLS-2$
        writer.writeStartDocument("UTF-8", "1.0");
        writePlanNode(this, writer);
        writer.writeEndDocument();
        return stringWriter.toString();
    } catch (FactoryConfigurationError e) {
        throw new TeiidRuntimeException(JDBCPlugin.Event.TEIID20002, e);
    } catch (XMLStreamException e) {
        throw new TeiidRuntimeException(JDBCPlugin.Event.TEIID20003, e);
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError)

Example 17 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project uPortal by Jasig.

the class EventProviderImpl method createEvent.

@Override
public Event createEvent(QName qname, Serializable value) throws IllegalArgumentException {
    if (this.isDeclaredAsPublishingEvent(qname)) {
        if (value != null && !this.isValueInstanceOfDefinedClass(qname, value)) {
            throw new IllegalArgumentException("Payload class (" + value.getClass().getCanonicalName() + ") does not have the right class, check your defined event types in portlet.xml.");
        }
        if (value == null) {
            return new EventImpl(qname);
        }
        try {
            final Thread currentThread = Thread.currentThread();
            final ClassLoader cl = currentThread.getContextClassLoader();
            final Writer out = new StringWriter();
            final Class clazz = value.getClass();
            try {
                currentThread.setContextClassLoader(this.portletClassLoader);
                final JAXBContext jc = JAXBContext.newInstance(clazz);
                final Marshaller marshaller = jc.createMarshaller();
                final JAXBElement<Serializable> element = new JAXBElement<Serializable>(qname, clazz, value);
                marshaller.marshal(element, out);
            } finally {
                currentThread.setContextClassLoader(cl);
            }
            return new EventImpl(qname, out.toString());
        } catch (JAXBException e) {
            // maybe there is no valid jaxb binding
            // TODO throw exception?
            logger.error("Event handling failed", e);
        } catch (FactoryConfigurationError e) {
            // TODO throw exception?
            logger.warn(e.getMessage(), e);
        }
    }
    return null;
}
Also used : Marshaller(javax.xml.bind.Marshaller) Serializable(java.io.Serializable) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) StringWriter(java.io.StringWriter) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 18 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project mule by mulesoft.

the class DefaultXMLSecureFactories method createDocumentBuilderFactory.

public DocumentBuilderFactory createDocumentBuilderFactory() {
    DocumentBuilderFactory factory;
    if (System.getProperty(DOCUMENT_BUILDER_PROPERTY) == null) {
        try {
            factory = DocumentBuilderFactory.newInstance(DOCUMENT_BUILDER_FACTORY, DefaultXMLSecureFactories.class.getClassLoader());
        } catch (FactoryConfigurationError e) {
            logCreationWarning(DocumentBuilderFactory.class.getName(), DOCUMENT_BUILDER_FACTORY, e);
            factory = DocumentBuilderFactory.newInstance();
        }
    } else {
        factory = DocumentBuilderFactory.newInstance();
    }
    try {
        factory.setFeature("http://xml.org/sax/features/external-general-entities", externalEntities);
        factory.setFeature("http://xml.org/sax/features/external-parameter-entities", externalEntities);
        factory.setExpandEntityReferences(expandEntities);
        factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", !expandEntities);
    } catch (Exception e) {
        logConfigurationWarning(DocumentBuilderFactory.class.getName(), factory.getClass().getName(), e);
    }
    return factory;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError)

Example 19 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project mule by mulesoft.

the class DefaultXMLSecureFactories method createTransformerFactory.

public TransformerFactory createTransformerFactory() {
    TransformerFactory factory;
    if (System.getProperty(TRANSFORMER_PROPERTY) == null) {
        try {
            factory = TransformerFactory.newInstance(TRANSFORMER_FACTORY, DefaultXMLSecureFactories.class.getClassLoader());
        } catch (FactoryConfigurationError e) {
            logCreationWarning(TransformerFactory.class.getName(), TRANSFORMER_FACTORY, e);
            factory = TransformerFactory.newInstance();
        }
    } else {
        factory = TransformerFactory.newInstance();
    }
    configureTransformerFactory(factory);
    return factory;
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError)

Example 20 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project galley by Commonjava.

the class PomPeek method parseCoordElements.

private void parseCoordElements() {
    InputStream in = null;
    XMLStreamReader xml = null;
    try {
        if (pom != null) {
            in = new FileInputStream(pom);
        } else if (transfer != null) {
            in = transfer.openInputStream(false);
        } else {
            in = stream;
        }
        xml = XMLInputFactory.newFactory().createXMLStreamReader(in);
        final Stack<String> path = new Stack<>();
        while (xml.hasNext()) {
            final int evt = xml.next();
            switch(evt) {
                case START_ELEMENT:
                    {
                        final String elem = xml.getLocalName();
                        if (captureValue(elem, path, xml)) {
                            // seems like xml.getElementText() traverses the END_ELEMENT event...
                            path.pop();
                        }
                        break;
                    }
                case END_ELEMENT:
                    {
                        path.pop();
                        break;
                    }
                default:
                    {
                    }
            }
            if (foundAll()) {
                return;
            }
        }
    } catch (final IOException | FactoryConfigurationError | XMLStreamException e) {
        logger.warn("Failed to peek at POM coordinate for: " + pom + " Reason: " + e.getMessage() + "\nThis POM will NOT be available as an ancestor to other models during effective-model building.", e);
    } finally {
        if (xml != null) {
            try {
                xml.close();
            } catch (final XMLStreamException e) {
                logger.warn("Failed to close XMLStreamReader: " + e.getMessage(), e);
            }
        }
        closeQuietly(in);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError) FileInputStream(java.io.FileInputStream) Stack(java.util.Stack)

Aggregations

FactoryConfigurationError (javax.xml.stream.FactoryConfigurationError)25 IOException (java.io.IOException)14 XMLStreamException (javax.xml.stream.XMLStreamException)11 StringWriter (java.io.StringWriter)6 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 ConfigurationException (org.opensaml.xml.ConfigurationException)5 SAXException (org.xml.sax.SAXException)5 StringReader (java.io.StringReader)3 Writer (java.io.Writer)3 XMLInputFactory (javax.xml.stream.XMLInputFactory)3 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)3 XMLEvent (javax.xml.stream.events.XMLEvent)3 MarshallingException (org.opensaml.xml.io.MarshallingException)3 InputStream (java.io.InputStream)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SignatureException (java.security.SignatureException)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 XMLEventReader (javax.xml.stream.XMLEventReader)2