Search in sources :

Example 11 with SAXParseException

use of org.xml.sax.SAXParseException in project OpenAM by OpenRock.

the class LogMessageProviderBase method getXMLDoc.

private Document getXMLDoc() throws IOException {
    Document xmlDoc = null;
    try {
        DocumentBuilder builder = XMLUtils.getSafeDocumentBuilder(true);
        builder.setErrorHandler(new ValidationErrorHandler());
        InputStream is = getClass().getClassLoader().getResourceAsStream(xmlDefinitionFilename);
        if (is != null) {
            xmlDoc = builder.parse(is);
        } else {
            throw new IOException(xmlDefinitionFilename + " cannot be found.");
        }
    } catch (SAXParseException e) {
        Debug.error("LogMessageProviderBase.getXMLDoc", e);
    } catch (SAXException e) {
        Debug.error("LogMessageProviderBase.getXMLDoc", e);
    } catch (ParserConfigurationException e) {
        Debug.error("LogMessageProviderBase.getXMLDoc", e);
    }
    return xmlDoc;
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) InputStream(java.io.InputStream) SAXParseException(org.xml.sax.SAXParseException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 12 with SAXParseException

use of org.xml.sax.SAXParseException in project OpenAM by OpenRock.

the class ValidationErrorHandler method getXMLDocument.

public static Document getXMLDocument(InputStream in) throws Exception {
    try {
        DocumentBuilder builder = getSafeDocumentBuilder(validating);
        Document doc = builder.parse(in);
        return doc;
    } catch (SAXParseException pe) {
        String msg = "\n" + pe.getMessage() + "\n";
        Object[] params = { new Integer(pe.getLineNumber()) };
        throw new Exception(msg + "XMLUtils.parser_error" + params);
    } catch (SAXException sax) {
        Object[] params = { sax.getMessage() };
        throw new Exception("XMLUtils.exception_message" + params);
    } catch (ParserConfigurationException pc) {
        Object[] params = { pc.getMessage() };
        throw new Exception("XMLUtils.invalid_xml_document" + params);
    } catch (IOException ioe) {
        Object[] params = { ioe.getMessage() };
        throw new Exception("XMLUtils.invalid_input_stream" + params);
    }
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SAXException(org.xml.sax.SAXException)

Example 13 with SAXParseException

use of org.xml.sax.SAXParseException in project OpenAM by OpenRock.

the class ErrorHandlerAdaptor method propagateEvent.

private void propagateEvent(int severity, SAXParseException saxException) throws SAXException {
    // get location info:
    //     sax locators simply use the location info embedded in the 
    //     sax exception, dom locators keep a reference to their DOMScanner
    //     and call back to figure out where the error occurred.
    ValidationEventLocator vel = locator.getLocation(saxException);
    ValidationEventImpl ve = new ValidationEventImpl(severity, saxException.getMessage(), vel);
    Exception e = saxException.getException();
    if (e != null) {
        ve.setLinkedException(e);
    } else {
        ve.setLinkedException(saxException);
    }
    // call the client's event handler.
    host.handleEvent(ve, severity != ValidationEvent.FATAL_ERROR);
}
Also used : ValidationEventImpl(javax.xml.bind.helpers.ValidationEventImpl) ValidationEventLocator(javax.xml.bind.ValidationEventLocator) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Example 14 with SAXParseException

use of org.xml.sax.SAXParseException in project OpenAM by OpenRock.

the class ErrorHandlerAdaptor method propagateEvent.

private void propagateEvent(int severity, SAXParseException saxException) throws SAXException {
    // get location info:
    //     sax locators simply use the location info embedded in the 
    //     sax exception, dom locators keep a reference to their DOMScanner
    //     and call back to figure out where the error occurred.
    ValidationEventLocator vel = locator.getLocation(saxException);
    ValidationEventImpl ve = new ValidationEventImpl(severity, saxException.getMessage(), vel);
    Exception e = saxException.getException();
    if (e != null) {
        ve.setLinkedException(e);
    } else {
        ve.setLinkedException(saxException);
    }
    // call the client's event handler.
    host.handleEvent(ve, severity != ValidationEvent.FATAL_ERROR);
}
Also used : ValidationEventImpl(javax.xml.bind.helpers.ValidationEventImpl) ValidationEventLocator(javax.xml.bind.ValidationEventLocator) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Example 15 with SAXParseException

use of org.xml.sax.SAXParseException in project tdi-studio-se by Talend.

the class AutoConvertTypesUtils method load.

public static List<AutoConversionType> load(File file) {
    beanList = new ArrayList<>();
    try {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder analyseur = documentBuilderFactory.newDocumentBuilder();
        analyseur.setErrorHandler(new ErrorHandler() {

            @Override
            public void error(final SAXParseException exception) throws SAXException {
                throw exception;
            }

            @Override
            public void fatalError(final SAXParseException exception) throws SAXException {
                throw exception;
            }

            @Override
            public void warning(final SAXParseException exception) throws SAXException {
                throw exception;
            }
        });
        Document document = analyseur.parse(file);
        //$NON-NLS-1$
        NodeList typeNodes = document.getElementsByTagName("conversionType");
        for (int i = 0; i < typeNodes.getLength(); i++) {
            Node typeNode = typeNodes.item(i);
            NamedNodeMap typeAttributes = typeNode.getAttributes();
            AutoConversionType typeObj = new AutoConversionType();
            //$NON-NLS-1$
            typeObj.setSourceDataType(typeAttributes.getNamedItem("source").getNodeValue());
            //$NON-NLS-1$
            typeObj.setTargetDataType(typeAttributes.getNamedItem("target").getNodeValue());
            //$NON-NLS-1$
            typeObj.setConversionFunction(typeAttributes.getNamedItem("function").getNodeValue());
            beanList.add(typeObj);
        }
    } catch (Exception e) {
        return beanList;
    }
    return beanList;
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) PersistenceException(org.talend.commons.exception.PersistenceException) SAXParseException(org.xml.sax.SAXParseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) AutoConversionType(org.talend.core.model.metadata.types.AutoConversionType) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXParseException(org.xml.sax.SAXParseException)

Aggregations

SAXParseException (org.xml.sax.SAXParseException)365 SAXException (org.xml.sax.SAXException)170 IOException (java.io.IOException)131 DocumentBuilder (javax.xml.parsers.DocumentBuilder)73 InputSource (org.xml.sax.InputSource)69 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)68 Document (org.w3c.dom.Document)64 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)56 ErrorHandler (org.xml.sax.ErrorHandler)52 InputStream (java.io.InputStream)36 File (java.io.File)34 ArrayList (java.util.ArrayList)33 FileInputStream (java.io.FileInputStream)31 FileNotFoundException (java.io.FileNotFoundException)31 Element (org.w3c.dom.Element)30 StringReader (java.io.StringReader)21 NodeList (org.w3c.dom.NodeList)21 URL (java.net.URL)20 Test (org.junit.jupiter.api.Test)19 Node (org.w3c.dom.Node)19