Search in sources :

Example 1 with XmlParser

use of org.eclipse.jetty.xml.XmlParser in project jetty.project by eclipse.

the class Descriptor method parse.

public void parse() throws Exception {
    if (_root == null) {
        try {
            XmlParser parser = ensureParser();
            _root = parser.parse(_xml.getInputStream());
            _dtd = parser.getDTD();
        } finally {
            _xml.close();
        }
    }
}
Also used : XmlParser(org.eclipse.jetty.xml.XmlParser)

Example 2 with XmlParser

use of org.eclipse.jetty.xml.XmlParser in project jetty.project by eclipse.

the class WebDescriptor method newParser.

public static XmlParser newParser(boolean validating) throws ClassNotFoundException {
    XmlParser xmlParser = new XmlParser(validating) {

        boolean mapped = false;

        @Override
        protected InputSource resolveEntity(String pid, String sid) {
            if (!mapped) {
                mapResources();
                mapped = true;
            }
            InputSource is = super.resolveEntity(pid, sid);
            return is;
        }

        void mapResources() {
            //set up cache of DTDs and schemas locally
            URL dtd22 = Loader.getResource("javax/servlet/resources/web-app_2_2.dtd");
            URL dtd23 = Loader.getResource("javax/servlet/resources/web-app_2_3.dtd");
            URL j2ee14xsd = Loader.getResource("javax/servlet/resources/j2ee_1_4.xsd");
            URL javaee5 = Loader.getResource("javax/servlet/resources/javaee_5.xsd");
            URL javaee6 = Loader.getResource("javax/servlet/resources/javaee_6.xsd");
            URL javaee7 = Loader.getResource("javax/servlet/resources/javaee_7.xsd");
            URL webapp24xsd = Loader.getResource("javax/servlet/resources/web-app_2_4.xsd");
            URL webapp25xsd = Loader.getResource("javax/servlet/resources/web-app_2_5.xsd");
            URL webapp30xsd = Loader.getResource("javax/servlet/resources/web-app_3_0.xsd");
            URL webapp31xsd = Loader.getResource("javax/servlet/resources/web-app_3_1.xsd");
            URL webcommon30xsd = Loader.getResource("javax/servlet/resources/web-common_3_0.xsd");
            URL webcommon31xsd = Loader.getResource("javax/servlet/resources/web-common_3_1.xsd");
            URL webfragment30xsd = Loader.getResource("javax/servlet/resources/web-fragment_3_0.xsd");
            URL webfragment31xsd = Loader.getResource("javax/servlet/resources/web-fragment_3_1.xsd");
            URL schemadtd = Loader.getResource("javax/servlet/resources/XMLSchema.dtd");
            URL xmlxsd = Loader.getResource("javax/servlet/resources/xml.xsd");
            URL webservice11xsd = Loader.getResource("javax/servlet/resources/j2ee_web_services_client_1_1.xsd");
            URL webservice12xsd = Loader.getResource("javax/servlet/resources/javaee_web_services_client_1_2.xsd");
            URL webservice13xsd = Loader.getResource("javax/servlet/resources/javaee_web_services_client_1_3.xsd");
            URL webservice14xsd = Loader.getResource("javax/servlet/resources/javaee_web_services_client_1_4.xsd");
            URL datatypesdtd = Loader.getResource("javax/servlet/resources/datatypes.dtd");
            URL jsp20xsd = null;
            URL jsp21xsd = null;
            URL jsp22xsd = null;
            URL jsp23xsd = null;
            try {
                //try both javax/servlet/resources and javax/servlet/jsp/resources to load 
                jsp20xsd = Loader.getResource("javax/servlet/resources/jsp_2_0.xsd");
                jsp21xsd = Loader.getResource("javax/servlet/resources/jsp_2_1.xsd");
                jsp22xsd = Loader.getResource("javax/servlet/resources/jsp_2_2.xsd");
                jsp23xsd = Loader.getResource("javax/servlet/resources/jsp_2_3.xsd");
            } catch (Exception e) {
                LOG.ignore(e);
            } finally {
                if (jsp20xsd == null)
                    jsp20xsd = Loader.getResource("javax/servlet/jsp/resources/jsp_2_0.xsd");
                if (jsp21xsd == null)
                    jsp21xsd = Loader.getResource("javax/servlet/jsp/resources/jsp_2_1.xsd");
                if (jsp22xsd == null)
                    jsp22xsd = Loader.getResource("javax/servlet/jsp/resources/jsp_2_2.xsd");
                if (jsp23xsd == null)
                    jsp23xsd = Loader.getResource("javax/servlet/jsp/resources/jsp_2_3.xsd");
            }
            redirectEntity("web-app_2_2.dtd", dtd22);
            redirectEntity("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN", dtd22);
            redirectEntity("web.dtd", dtd23);
            redirectEntity("web-app_2_3.dtd", dtd23);
            redirectEntity("-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN", dtd23);
            redirectEntity("XMLSchema.dtd", schemadtd);
            redirectEntity("http://www.w3.org/2001/XMLSchema.dtd", schemadtd);
            redirectEntity("-//W3C//DTD XMLSCHEMA 200102//EN", schemadtd);
            redirectEntity("jsp_2_0.xsd", jsp20xsd);
            redirectEntity("http://java.sun.com/xml/ns/j2ee/jsp_2_0.xsd", jsp20xsd);
            redirectEntity("http://java.sun.com/xml/ns/javaee/jsp_2_1.xsd", jsp21xsd);
            redirectEntity("jsp_2_2.xsd", jsp22xsd);
            redirectEntity("http://java.sun.com/xml/ns/javaee/jsp_2_2.xsd", jsp22xsd);
            redirectEntity("jsp_2_3.xsd", jsp23xsd);
            redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/jsp_2_3.xsd", jsp23xsd);
            redirectEntity("j2ee_1_4.xsd", j2ee14xsd);
            redirectEntity("http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd", j2ee14xsd);
            redirectEntity("http://java.sun.com/xml/ns/javaee/javaee_5.xsd", javaee5);
            redirectEntity("http://java.sun.com/xml/ns/javaee/javaee_6.xsd", javaee6);
            redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/javaee_7.xsd", javaee7);
            redirectEntity("web-app_2_4.xsd", webapp24xsd);
            redirectEntity("http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd", webapp24xsd);
            redirectEntity("web-app_2_5.xsd", webapp25xsd);
            redirectEntity("http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd", webapp25xsd);
            redirectEntity("web-app_3_0.xsd", webapp30xsd);
            redirectEntity("http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd", webapp30xsd);
            redirectEntity("web-common_3_0.xsd", webcommon30xsd);
            redirectEntity("http://java.sun.com/xml/ns/javaee/web-common_3_0.xsd", webcommon30xsd);
            redirectEntity("web-fragment_3_0.xsd", webfragment30xsd);
            redirectEntity("http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd", webfragment30xsd);
            redirectEntity("web-app_3_1.xsd", webapp31xsd);
            redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd", webapp31xsd);
            redirectEntity("web-common_3_1.xsd", webcommon30xsd);
            redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/web-common_3_1.xsd", webcommon31xsd);
            redirectEntity("web-fragment_3_1.xsd", webfragment30xsd);
            redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/web-fragment_3_1.xsd", webfragment31xsd);
            redirectEntity("xml.xsd", xmlxsd);
            redirectEntity("http://www.w3.org/2001/xml.xsd", xmlxsd);
            redirectEntity("datatypes.dtd", datatypesdtd);
            redirectEntity("http://www.w3.org/2001/datatypes.dtd", datatypesdtd);
            redirectEntity("j2ee_web_services_client_1_1.xsd", webservice11xsd);
            redirectEntity("http://www.ibm.com/webservices/xsd/j2ee_web_services_client_1_1.xsd", webservice11xsd);
            redirectEntity("javaee_web_services_client_1_2.xsd", webservice12xsd);
            redirectEntity("http://www.ibm.com/webservices/xsd/javaee_web_services_client_1_2.xsd", webservice12xsd);
            redirectEntity("javaee_web_services_client_1_3.xsd", webservice13xsd);
            redirectEntity("http://java.sun.com/xml/ns/javaee/javaee_web_services_client_1_3.xsd", webservice13xsd);
            redirectEntity("javaee_web_services_client_1_4.xsd", webservice14xsd);
            redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/javaee_web_services_client_1_4.xsd", webservice14xsd);
        }
    };
    return xmlParser;
}
Also used : XmlParser(org.eclipse.jetty.xml.XmlParser) InputSource(org.xml.sax.InputSource) URL(java.net.URL)

Aggregations

XmlParser (org.eclipse.jetty.xml.XmlParser)2 URL (java.net.URL)1 InputSource (org.xml.sax.InputSource)1