Search in sources :

Example 51 with SAXException

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

the class UnmarshallerImpl method unmarshal.

public final Object unmarshal(Node node) throws JAXBException {
    try {
        DOMScanner scanner = new DOMScanner();
        UnmarshallerHandler handler = new InterningUnmarshallerHandler(createUnmarshallerHandler(new DOMLocator(scanner)));
        if (node instanceof Element)
            scanner.parse((Element) node, handler);
        else if (node instanceof Document)
            scanner.parse(((Document) node).getDocumentElement(), handler);
        else
            // no other type of input is supported
            throw new IllegalArgumentException();
        return handler.getResult();
    } catch (SAXException e) {
        throw createUnmarshalException(e);
    }
}
Also used : DOMScanner(com.sun.xml.bind.unmarshaller.DOMScanner) Element(org.w3c.dom.Element) UnmarshallerHandler(javax.xml.bind.UnmarshallerHandler) DOMLocator(com.sun.xml.bind.validator.DOMLocator) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Example 52 with SAXException

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

the class MarshallerImpl method write.

private void write(XMLSerializable obj, ContentHandler writer) throws JAXBException {
    try {
        if (getSchemaLocation() != null || getNoNSSchemaLocation() != null) {
            // if we need to add xsi:schemaLocation or its brother,
            // throw in the component to do that.
            writer = new SchemaLocationFilter(getSchemaLocation(), getNoNSSchemaLocation(), writer);
        }
        SAXMarshaller serializer = new SAXMarshaller(writer, prefixMapper, this);
        // set a DocumentLocator that doesn't provide any information
        writer.setDocumentLocator(new LocatorImpl());
        writer.startDocument();
        serializer.childAsBody(obj, null);
        writer.endDocument();
        // extra check
        serializer.reconcileID();
    } catch (SAXException e) {
        throw new MarshalException(e);
    }
}
Also used : SchemaLocationFilter(com.sun.xml.bind.marshaller.SchemaLocationFilter) MarshalException(javax.xml.bind.MarshalException) LocatorImpl(org.xml.sax.helpers.LocatorImpl) SAXException(org.xml.sax.SAXException)

Example 53 with SAXException

use of org.xml.sax.SAXException 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 54 with SAXException

use of org.xml.sax.SAXException 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 55 with SAXException

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

the class Util method handlePrintConversionException.

/**
     * Reports a print conversion error while marshalling.
     */
public static void handlePrintConversionException(Object caller, Exception e, XMLSerializer serializer) throws SAXException {
    if (e instanceof SAXException)
        //        will be thrown) 
        throw (SAXException) e;
    String message = e.getMessage();
    if (message == null) {
        message = e.toString();
    }
    ValidationEvent ve = new PrintConversionEventImpl(ValidationEvent.ERROR, message, new ValidationEventLocatorImpl(caller), e);
    serializer.reportError(ve);
}
Also used : ValidationEvent(javax.xml.bind.ValidationEvent) ValidationEventLocatorImpl(javax.xml.bind.helpers.ValidationEventLocatorImpl) PrintConversionEventImpl(javax.xml.bind.helpers.PrintConversionEventImpl) SAXException(org.xml.sax.SAXException)

Aggregations

SAXException (org.xml.sax.SAXException)2465 IOException (java.io.IOException)1622 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1049 Document (org.w3c.dom.Document)682 DocumentBuilder (javax.xml.parsers.DocumentBuilder)537 InputSource (org.xml.sax.InputSource)518 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)415 InputStream (java.io.InputStream)317 Element (org.w3c.dom.Element)311 NodeList (org.w3c.dom.NodeList)292 File (java.io.File)274 Node (org.w3c.dom.Node)247 ByteArrayInputStream (java.io.ByteArrayInputStream)235 StringReader (java.io.StringReader)224 SAXParser (javax.xml.parsers.SAXParser)209 SAXParseException (org.xml.sax.SAXParseException)196 TransformerException (javax.xml.transform.TransformerException)180 ArrayList (java.util.ArrayList)169 SAXParserFactory (javax.xml.parsers.SAXParserFactory)159 XMLReader (org.xml.sax.XMLReader)151