Search in sources :

Example 1 with XMLValidationHandler

use of com.sun.enterprise.tools.verifier.util.XMLValidationHandler in project Payara by payara.

the class TagLibFactory method init.

/**
 * this method is called once to create the Documentbuilder required for
 * creating documen objects from tlds
 */
private void init() {
    if (!uninitialised) {
        synchronized (this) {
            if (!uninitialised) {
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                // NOI18N
                String W3C_XML_SCHEMA = "http://www.w3c.org/2001/XMLSchema";
                // NOI18N
                String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
                factory.setNamespaceAware(true);
                factory.setValidating(true);
                factory.setAttribute(// NOI18N
                "http://apache.org/xml/features/validation/schema", Boolean.TRUE);
                factory.setAttribute(// NOI18N
                "http://xml.org/sax/features/validation", Boolean.TRUE);
                factory.setAttribute(// NOI18N
                "http://apache.org/xml/features/allow-java-encodings", Boolean.TRUE);
                factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
                try {
                    builder = factory.newDocumentBuilder();
                } catch (ParserConfigurationException e) {
                    logger.log(Level.SEVERE, e.getMessage());
                }
                EntityResolver dh = new XMLValidationHandler(true);
                ErrorHandler eh = new XMLValidationHandler(true);
                builder.setErrorHandler(eh);
                builder.setEntityResolver(dh);
                uninitialised = true;
            }
        }
    }
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XMLValidationHandler(com.sun.enterprise.tools.verifier.util.XMLValidationHandler) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) EntityResolver(org.xml.sax.EntityResolver)

Example 2 with XMLValidationHandler

use of com.sun.enterprise.tools.verifier.util.XMLValidationHandler in project Payara by payara.

the class BaseVerifier method createDOMObject.

protected void createDOMObject(InputSource source, String dd) throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
    factory.setNamespaceAware(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    EntityResolver dh = new XMLValidationHandler(false);
    builder.setEntityResolver(dh);
    Document document = builder.parse(source);
    if ((dd.indexOf("sun-")) < 0) {
        // NOI18N
        if ((dd.indexOf("webservices")) < 0) {
            // NOI18N
            context.setDocument(document);
        } else {
            context.setWebServiceDocument(document);
        }
    } else
        context.setRuntimeDocument(document);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XMLValidationHandler(com.sun.enterprise.tools.verifier.util.XMLValidationHandler) DocumentBuilder(javax.xml.parsers.DocumentBuilder) EntityResolver(org.xml.sax.EntityResolver) Document(org.w3c.dom.Document)

Example 3 with XMLValidationHandler

use of com.sun.enterprise.tools.verifier.util.XMLValidationHandler in project Payara by payara.

the class NameToken method isNMTOKEN.

/**
 * Determine is value is legal NMToken type
 *
 * @param value xml element to be checked
 * @return <code>boolean</code> true if xml element is legal NMToken,
 *         false otherwise
 */
public static boolean isNMTOKEN(String value) {
    /*
        com.sun.enterprise.util.LocalStringManagerImpl smh =
            StringManagerHelper.getLocalStringsManager();
*/
    String XMLdoc = XMLtop + value + XMLbottom;
    logger.log(Level.FINE, // NOI18N
    "com.sun.enterprise.tools.verifier.NameToken.print", new Object[] { XMLdoc });
    try {
        InputSource source = new InputSource(new ByteArrayInputStream(XMLdoc.getBytes()));
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setValidating(true);
        // ValidatingParser p = new ValidatingParser();
        XMLReader p = spf.newSAXParser().getXMLReader();
        // XMLErrorHandler eh = new XMLErrorHandler(null);
        p.setErrorHandler(new XMLValidationHandler());
        p.parse(source);
        return true;
    } catch (Exception e) {
        return false;
    }
}
Also used : InputSource(org.xml.sax.InputSource) XMLValidationHandler(com.sun.enterprise.tools.verifier.util.XMLValidationHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

XMLValidationHandler (com.sun.enterprise.tools.verifier.util.XMLValidationHandler)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 EntityResolver (org.xml.sax.EntityResolver)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 Document (org.w3c.dom.Document)1 ErrorHandler (org.xml.sax.ErrorHandler)1 InputSource (org.xml.sax.InputSource)1 XMLReader (org.xml.sax.XMLReader)1