FileDocCategorySizeDatePackage
JAXPParser.javaAPI DocGlassfish v2 API9493Tue May 22 16:54:50 BST 2007oracle.toplink.essentials.platform.xml.jaxp

JAXPParser

public class JAXPParser extends Object implements XMLParser

Fields Summary
private static final String
SCHEMA_LANGUAGE
private static final String
XML_SCHEMA
private static final String
JAXP_SCHEMA_SOURCE
private DocumentBuilderFactory
documentBuilderFactory
private EntityResolver
entityResolver
private ErrorHandler
errorHandler
Constructors Summary
public JAXPParser()


      
        super();
        documentBuilderFactory = DocumentBuilderFactory.newInstance();
        setNamespaceAware(true);
        setWhitespacePreserving(false);
    
Methods Summary
private javax.xml.parsers.DocumentBuildergetDocumentBuilder()

        try {
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            documentBuilder.setEntityResolver(entityResolver);
            documentBuilder.setErrorHandler(errorHandler);
            return documentBuilder;
        } catch (ParserConfigurationException e) {
            throw XMLPlatformException.xmlPlatformParseException(e);
        }
    
public org.xml.sax.EntityResolvergetEntityResolver()

        return entityResolver;
    
public org.xml.sax.ErrorHandlergetErrorHandler()

        return errorHandler;
    
public intgetValidationMode()

        if (!documentBuilderFactory.isValidating()) {
            return XMLParser.NONVALIDATING;
        }

        try {
            if (null == documentBuilderFactory.getAttribute(SCHEMA_LANGUAGE)) {
                return XMLParser.DTD_VALIDATION;
            }
        } catch (IllegalArgumentException e) {
            return XMLParser.DTD_VALIDATION;
        }

        return XMLParser.SCHEMA_VALIDATION;
    
public org.w3c.dom.Documentparse(org.xml.sax.InputSource inputSource)

        try {
            return getDocumentBuilder().parse(inputSource);
        } catch (SAXException e) {
            throw XMLPlatformException.xmlPlatformParseException(e);
        } catch (IOException e) {
            throw XMLPlatformException.xmlPlatformParseException(e);
        }
    
public org.w3c.dom.Documentparse(java.io.File file)

        try {
            return getDocumentBuilder().parse(file);
        } catch (SAXParseException e) {
            throw XMLPlatformException.xmlPlatformSAXParseException(e);
        } catch (SAXException e) {
            throw XMLPlatformException.xmlPlatformParseException(e);
        } catch (IOException e) {
            throw XMLPlatformException.xmlPlatformFileNotFoundException(file, e);
        }
    
public org.w3c.dom.Documentparse(java.io.InputStream inputStream)

        try {
            return getDocumentBuilder().parse(inputStream);
        } catch (SAXParseException e) {
            throw XMLPlatformException.xmlPlatformSAXParseException(e);
        } catch (SAXException e) {
            throw XMLPlatformException.xmlPlatformParseException(e);
        } catch (IOException e) {
            throw XMLPlatformException.xmlPlatformParseException(e);
        }
    
public org.w3c.dom.Documentparse(java.io.Reader reader)

        InputSource inputSource = new InputSource(reader);
        return parse(inputSource);
    
public org.w3c.dom.Documentparse(javax.xml.transform.Source source)

        try {
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            DOMResult domResult = new DOMResult();
            transformer.transform(source, domResult);
            return (Document)domResult.getNode();
        } catch (TransformerException e) {
            throw XMLPlatformException.xmlPlatformParseException(e);
        }
    
public org.w3c.dom.Documentparse(java.net.URL url)

        try {
            InputStream inputStream = url.openStream();
            return parse(inputStream);
        } catch (IOException e) {
            throw XMLPlatformException.xmlPlatformParseException(e);
        }
    
public voidsetEntityResolver(org.xml.sax.EntityResolver entityResolver)

        this.entityResolver = entityResolver;
    
public voidsetErrorHandler(org.xml.sax.ErrorHandler errorHandler)

        this.errorHandler = errorHandler;
    
public voidsetNamespaceAware(boolean isNamespaceAware)

        documentBuilderFactory.setNamespaceAware(isNamespaceAware);
    
public voidsetValidationMode(int validationMode)

        switch (validationMode) {
        case XMLParser.NONVALIDATING: {
            documentBuilderFactory.setValidating(false);
            // documentBuilderFactory.setAttribute(SCHEMA_LANGUAGE, null);			
            return;
        }
        case XMLParser.DTD_VALIDATION: {
            documentBuilderFactory.setValidating(true);
            // documentBuilderFactory.setAttribute(SCHEMA_LANGUAGE, null);
            return;
        }
        case XMLParser.SCHEMA_VALIDATION: {
            try {
                documentBuilderFactory.setAttribute(SCHEMA_LANGUAGE, XML_SCHEMA);
                documentBuilderFactory.setValidating(true);
            } catch (IllegalArgumentException e) {
                // This parser does not support XML Schema validation so leave it as
                // a non-validating parser.
            }
            return;
        }
        }
    
public voidsetWhitespacePreserving(boolean isWhitespacePreserving)

        documentBuilderFactory.setIgnoringElementContentWhitespace(!isWhitespacePreserving);
    
public voidsetXMLSchema(java.net.URL url)

        if (null == url) {
            return;
        }
        try {
            documentBuilderFactory.setAttribute(SCHEMA_LANGUAGE, XML_SCHEMA);
            documentBuilderFactory.setAttribute(JAXP_SCHEMA_SOURCE, url.toString());
        } catch (IllegalArgumentException e) {
            // The attribute isn't supported so do nothing
        } catch (Exception e) {
            XMLPlatformException.xmlPlatformErrorResolvingXMLSchema(url, e);
        }
    
public voidsetXMLSchemas(java.lang.Object[] schemas)

        if ((null == schemas) || (schemas.length == 0)) {
            return;
        }
        try {
            documentBuilderFactory.setAttribute(SCHEMA_LANGUAGE, XML_SCHEMA);
            documentBuilderFactory.setAttribute(JAXP_SCHEMA_SOURCE, schemas);
        } catch (IllegalArgumentException e) {
            // The attribute isn't supported so do nothing
        } catch (Exception e) {
            XMLPlatformException.xmlPlatformErrorResolvingXMLSchemas(schemas, e);
        }