org.apache.tomcat.util.digester.Digester Java Examples
The following examples show how to use
org.apache.tomcat.util.digester.Digester.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Catalina.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Create and configure the Digester we will be using for shutdown. * @return the digester to process the stop operation */ protected Digester createStopDigester() { // Initialize the digester Digester digester = new Digester(); digester.setUseContextClassLoader(true); // Configure the rules we need for shutting down digester.addObjectCreate("Server", "org.apache.catalina.core.StandardServer", "className"); digester.addSetProperties("Server"); digester.addSetNext("Server", "setServer", "org.apache.catalina.Server"); return digester; }
Example #2
Source File: TldConfig.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Create (if necessary) and return a Digester configured to process the * tld. */ private static synchronized Digester createTldDigester(boolean validation, boolean blockExternal) { Digester digester; int cacheIndex = 0; if (validation) { cacheIndex += 1; } if (blockExternal) { cacheIndex += 2; } digester = tldDigesters[cacheIndex]; if (digester == null) { digester = DigesterFactory.newDigester(validation, true, new TldRuleSet(), blockExternal); digester.getParser(); tldDigesters[cacheIndex] = digester; } return digester; }
Example #3
Source File: DigesterFactory.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Create a <code>Digester</code> parser. * @param xmlValidation turn on/off xml validation * @param xmlNamespaceAware turn on/off namespace validation * @param rule an instance of <code>RuleSet</code> used for parsing the xml. * @param blockExternal turn on/off the blocking of external resources */ public static Digester newDigester(boolean xmlValidation, boolean xmlNamespaceAware, RuleSet rule, boolean blockExternal) { Digester digester = new Digester(); digester.setNamespaceAware(xmlNamespaceAware); digester.setValidating(xmlValidation); digester.setUseContextClassLoader(true); EntityResolver2 resolver = new LocalResolver(SERVLET_API_PUBLIC_IDS, SERVLET_API_SYSTEM_IDS, blockExternal); digester.setEntityResolver(resolver); if (rule != null) { digester.addRuleSet(rule); } return digester; }
Example #4
Source File: DigesterFactory.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Create a <code>Digester</code> parser. * @param xmlValidation turn on/off xml validation * @param xmlNamespaceAware turn on/off namespace validation * @param rule an instance of <code>RuleSet</code> used for parsing the xml. */ public static Digester newDigester(boolean xmlValidation, boolean xmlNamespaceAware, RuleSet rule) { Digester digester = new Digester(); digester.setNamespaceAware(xmlNamespaceAware); digester.setValidating(xmlValidation); digester.setUseContextClassLoader(true); SchemaResolver schemaResolver = new SchemaResolver(digester); registerLocalSchema(schemaResolver); digester.setEntityResolver(schemaResolver); if ( rule != null ) { digester.addRuleSet(rule); } return (digester); }
Example #5
Source File: ContextConfig.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Process a "init" event for this Context. */ protected void init() { // Called from StandardContext.init() Digester contextDigester = createContextDigester(); contextDigester.getParser(); if (log.isDebugEnabled()) log.debug(sm.getString("contextConfig.init")); context.setConfigured(false); ok = true; contextConfig(contextDigester); createWebXmlDigester(context.getXmlNamespaceAware(), context.getXmlValidation()); }
Example #6
Source File: ContextConfig.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Create (if necessary) and return a Digester configured to process the * context configuration descriptor for an application. */ protected Digester createContextDigester() { Digester digester = new Digester(); digester.setValidating(false); digester.setRulesValidation(true); HashMap<Class<?>, List<String>> fakeAttributes = new HashMap<Class<?>, List<String>>(); ArrayList<String> attrs = new ArrayList<String>(); attrs.add("className"); fakeAttributes.put(Object.class, attrs); digester.setFakeAttributes(fakeAttributes); RuleSet contextRuleSet = new ContextRuleSet("", false); digester.addRuleSet(contextRuleSet); RuleSet namingRuleSet = new NamingRuleSet("Context/"); digester.addRuleSet(namingRuleSet); return digester; }
Example #7
Source File: Catalina.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
/** * Create and configure the Digester we will be using for shutdown. */ protected Digester createStopDigester() { // Initialize the digester Digester digester = new Digester(); digester.setUseContextClassLoader(true); // Configure the rules we need for shutting down digester.addObjectCreate("Server", "org.apache.catalina.core.StandardServer", "className"); digester.addSetProperties("Server"); digester.addSetNext("Server", "setServer", "org.apache.catalina.Server"); return (digester); }
Example #8
Source File: Catalina.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Cluster support is optional. The JARs may have been removed. */ private void addClusterRuleSet(Digester digester, String prefix) { Class<?> clazz = null; Constructor<?> constructor = null; try { clazz = Class.forName("org.apache.catalina.ha.ClusterRuleSet"); constructor = clazz.getConstructor(String.class); RuleSet ruleSet = (RuleSet) constructor.newInstance(prefix); digester.addRuleSet(ruleSet); } catch (Exception e) { if (log.isDebugEnabled()) { log.debug(sm.getString("catalina.noCluster", e.getClass().getName() + ": " + e.getMessage()), e); } else if (log.isInfoEnabled()) { log.info(sm.getString("catalina.noCluster", e.getClass().getName() + ": " + e.getMessage())); } } }
Example #9
Source File: Catalina.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Create and configure the Digester we will be using for shutdown. */ protected Digester createStopDigester() { // Initialize the digester Digester digester = new Digester(); digester.setUseContextClassLoader(true); // Configure the rules we need for shutting down digester.addObjectCreate("Server", "org.apache.catalina.core.StandardServer", "className"); digester.addSetProperties("Server"); digester.addSetNext("Server", "setServer", "org.apache.catalina.Server"); return (digester); }
Example #10
Source File: ContextConfig.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Create (if necessary) and return a Digester configured to process the * context configuration descriptor for an application. */ protected Digester createContextDigester() { Digester digester = new Digester(); digester.setValidating(false); digester.setRulesValidation(true); HashMap<Class<?>, List<String>> fakeAttributes = new HashMap<Class<?>, List<String>>(); ArrayList<String> attrs = new ArrayList<String>(); attrs.add("className"); fakeAttributes.put(Object.class, attrs); digester.setFakeAttributes(fakeAttributes); RuleSet contextRuleSet = new ContextRuleSet("", false); digester.addRuleSet(contextRuleSet); RuleSet namingRuleSet = new NamingRuleSet("Context/"); digester.addRuleSet(namingRuleSet); return digester; }
Example #11
Source File: ContextConfig.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Process a "init" event for this Context. */ protected void init() { // Called from StandardContext.init() Digester contextDigester = createContextDigester(); contextDigester.getParser(); if (log.isDebugEnabled()) log.debug(sm.getString("contextConfig.init")); context.setConfigured(false); ok = true; contextConfig(contextDigester); createWebXmlDigester(context.getXmlNamespaceAware(), context.getXmlValidation()); }
Example #12
Source File: DigesterFactory.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Create a <code>Digester</code> parser. * @param xmlValidation turn on/off xml validation * @param xmlNamespaceAware turn on/off namespace validation * @param rule an instance of <code>RuleSet</code> used for parsing the xml. */ public static Digester newDigester(boolean xmlValidation, boolean xmlNamespaceAware, RuleSet rule) { Digester digester = new Digester(); digester.setNamespaceAware(xmlNamespaceAware); digester.setValidating(xmlValidation); digester.setUseContextClassLoader(true); SchemaResolver schemaResolver = new SchemaResolver(digester); registerLocalSchema(schemaResolver); digester.setEntityResolver(schemaResolver); if ( rule != null ) { digester.addRuleSet(rule); } return (digester); }
Example #13
Source File: TldConfig.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Create (if necessary) and return a Digester configured to process the * tld. */ private static synchronized Digester createTldDigester(boolean validation, boolean blockExternal) { Digester digester; int cacheIndex = 0; if (validation) { cacheIndex += 1; } if (blockExternal) { cacheIndex += 2; } digester = tldDigesters[cacheIndex]; if (digester == null) { digester = DigesterFactory.newDigester(validation, true, new TldRuleSet(), blockExternal); digester.getParser(); tldDigesters[cacheIndex] = digester; } return digester; }
Example #14
Source File: OpenEJBContextConfig.java From tomee with Apache License 2.0 | 6 votes |
@Override protected void contextConfig(final Digester digester) { final NamingResourcesImpl resources; if (context != null) { resources = context.getNamingResources(); } else { resources = null; } if (resources instanceof OpenEJBNamingResource) { ((OpenEJBNamingResource) resources).setTomcatResource(true); } super.contextConfig(digester); if (resources instanceof OpenEJBNamingResource) { ((OpenEJBNamingResource) resources).setTomcatResource(false); } if (context instanceof StandardContext) { final StandardContext standardContext = (StandardContext) context; final NamingContextListener namingContextListener = standardContext.getNamingContextListener(); if (null != namingContextListener) { namingContextListener.setExceptionOnFailedWrite(standardContext.getJndiExceptionOnFailedWrite()); } } }
Example #15
Source File: DigesterFactory.java From tomcatsrc with Apache License 2.0 | 6 votes |
/** * Create a <code>Digester</code> parser. * @param xmlValidation turn on/off xml validation * @param xmlNamespaceAware turn on/off namespace validation * @param rule an instance of <code>RuleSet</code> used for parsing the xml. * @param blockExternal turn on/off the blocking of external resources */ public static Digester newDigester(boolean xmlValidation, boolean xmlNamespaceAware, RuleSet rule, boolean blockExternal) { Digester digester = new Digester(); digester.setNamespaceAware(xmlNamespaceAware); digester.setValidating(xmlValidation); digester.setUseContextClassLoader(true); EntityResolver2 resolver = new LocalResolver(SERVLET_API_PUBLIC_IDS, SERVLET_API_SYSTEM_IDS, blockExternal); digester.setEntityResolver(resolver); if (rule != null) { digester.addRuleSet(rule); } return digester; }
Example #16
Source File: Catalina.java From Tomcat8-Source-Read with MIT License | 6 votes |
/** * Cluster support is optional. The JARs may have been removed. */ private void addClusterRuleSet(Digester digester, String prefix) { Class<?> clazz = null; Constructor<?> constructor = null; try { clazz = Class.forName("org.apache.catalina.ha.ClusterRuleSet"); constructor = clazz.getConstructor(String.class); RuleSet ruleSet = (RuleSet) constructor.newInstance(prefix); digester.addRuleSet(ruleSet); } catch (Exception e) { if (log.isDebugEnabled()) { log.debug(sm.getString("catalina.noCluster", e.getClass().getName() + ": " + e.getMessage()), e); } else if (log.isInfoEnabled()) { log.info(sm.getString("catalina.noCluster", e.getClass().getName() + ": " + e.getMessage())); } } }
Example #17
Source File: TestWebXml.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
private void doTestValidateVersion(String version) throws IOException, SAXException { WebXml webxml = new WebXml(); // Special cases if ("2.2".equals(version)) { webxml.setPublicId(XmlIdentifiers.WEB_22_PUBLIC); } else if ("2.3".equals(version)) { webxml.setPublicId(XmlIdentifiers.WEB_23_PUBLIC); } else { webxml.setVersion(version); } // Merged web.xml that is published as MERGED_WEB_XML context attribute // in the simplest case consists of webapp's web.xml file // plus the default conf/web.xml one. Set<WebXml> defaults = new HashSet<WebXml>(); defaults.add(getDefaultWebXmlFragment()); webxml.merge(defaults); Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(), true); XmlErrorHandler handler = new XmlErrorHandler(); digester.setErrorHandler(handler); InputSource is = new InputSource(new StringReader(webxml.toXml())); WebXml webxmlResult = new WebXml(); digester.push(webxmlResult); digester.parse(is); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); Assert.assertEquals(version, webxml.getVersion()); Assert.assertEquals(version, webxmlResult.getVersion()); }
Example #18
Source File: TestSchemaValidation.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testWebapp_3_1() throws Exception { XmlErrorHandler handler = new XmlErrorHandler(); Digester digester = DigesterFactory.newDigester( true, true, new WebRuleSet(false), true); digester.setErrorHandler(handler); digester.push(new WebXml()); WebXml desc = (WebXml) digester.parse( new File("test/webapp-3.1/WEB-INF/web.xml")); Assert.assertEquals("3.1", desc.getVersion()); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); }
Example #19
Source File: TestSchemaValidation.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testWebapp_2_2() throws Exception { XmlErrorHandler handler = new XmlErrorHandler(); Digester digester = DigesterFactory.newDigester( true, true, new WebRuleSet(false), true); digester.setErrorHandler(handler); digester.push(new WebXml()); WebXml desc = (WebXml) digester.parse( new File("test/webapp-2.2/WEB-INF/web.xml")); Assert.assertEquals("2.2", desc.getVersion()); Assert.assertEquals(XmlIdentifiers.WEB_22_PUBLIC, desc.getPublicId()); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); }
Example #20
Source File: TestSchemaValidation.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testWebapp_2_5() throws Exception { XmlErrorHandler handler = new XmlErrorHandler(); Digester digester = DigesterFactory.newDigester( true, true, new WebRuleSet(false), true); digester.setErrorHandler(handler); digester.push(new WebXml()); WebXml desc = (WebXml) digester.parse( new File("test/webapp-2.5/WEB-INF/web.xml")); Assert.assertEquals("2.5", desc.getVersion()); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); }
Example #21
Source File: TestSchemaValidation.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testWebapp_3_0() throws Exception { XmlErrorHandler handler = new XmlErrorHandler(); Digester digester = DigesterFactory.newDigester( true, true, new WebRuleSet(false), true); digester.setErrorHandler(handler); digester.push(new WebXml()); WebXml desc = (WebXml) digester.parse( new File("test/webapp-3.0/WEB-INF/web.xml")); Assert.assertEquals("3.0", desc.getVersion()); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); }
Example #22
Source File: TestWebRuleSet.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
private synchronized void parse(WebXml webXml, String target, boolean fragment, boolean expected) throws FileNotFoundException { Digester d; if (fragment) { d = fragmentDigester; fragmentRuleSet.recycle(); } else { d = webDigester; webRuleSet.recycle(); } d.push(webXml); File f = new File("test/org/apache/catalina/startup/" + target); InputStream is = new FileInputStream(f); boolean result = true; try { d.parse(is); } catch (Exception e) { if (expected) { // Didn't expect an exception e.printStackTrace(); } result = false; } if (expected) { assertTrue(result); } else { assertFalse(result); } }
Example #23
Source File: HostConfig.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Create the digester which will be used to parse context config files. */ protected static Digester createDigester(String contextClassName) { Digester digester = new Digester(); digester.setValidating(false); // Add object creation rule digester.addObjectCreate("Context", contextClassName, "className"); // Set the properties on that object (it doesn't matter if extra // properties are set) digester.addSetProperties("Context"); return (digester); }
Example #24
Source File: TestSchemaValidation.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Test public void testWebapp_2_4() throws Exception { XmlErrorHandler handler = new XmlErrorHandler(); Digester digester = DigesterFactory.newDigester( true, true, new WebRuleSet(false), true); digester.setErrorHandler(handler); digester.push(new WebXml()); WebXml desc = (WebXml) digester.parse( new File("test/webapp-2.4/WEB-INF/web.xml")); Assert.assertEquals("2.4", desc.getVersion()); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); }
Example #25
Source File: TestSchemaValidation.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testWebapp_2_4() throws Exception { XmlErrorHandler handler = new XmlErrorHandler(); Digester digester = DigesterFactory.newDigester( true, true, new WebRuleSet(false), true); digester.setErrorHandler(handler); digester.push(new WebXml()); WebXml desc = (WebXml) digester.parse( new File("test/webapp-2.4/WEB-INF/web.xml")); Assert.assertEquals("2.4", desc.getVersion()); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); }
Example #26
Source File: RealmRuleSet.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * <p>Add the set of Rule instances defined in this RuleSet to the * specified <code>Digester</code> instance, associating them with * our namespace URI (if any). This method should only be called * by a Digester instance.</p> * * @param digester Digester instance to which the new Rule instances * should be added. */ @Override public void addRuleInstances(Digester digester) { String pattern = prefix; for (int i = 0; i < MAX_NESTED_REALM_LEVELS; i++) { if (i > 0) { pattern += "/"; } pattern += "Realm"; digester.addObjectCreate(pattern, null, // MUST be specified in the element, "className"); digester.addSetProperties(pattern); if (i == 0) { digester.addSetNext(pattern, "setRealm", "org.apache.catalina.Realm"); } else { digester.addSetNext(pattern, "addRealm", "org.apache.catalina.Realm"); } } }
Example #27
Source File: HostConfig.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Create the digester which will be used to parse context config files. */ protected static Digester createDigester(String contextClassName) { Digester digester = new Digester(); digester.setValidating(false); // Add object creation rule digester.addObjectCreate("Context", contextClassName, "className"); // Set the properties on that object (it doesn't matter if extra // properties are set) digester.addSetProperties("Context"); return (digester); }
Example #28
Source File: TestSchemaValidation.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Test public void testWebapp_3_0() throws Exception { XmlErrorHandler handler = new XmlErrorHandler(); Digester digester = DigesterFactory.newDigester( true, true, new WebRuleSet(false), true); digester.setErrorHandler(handler); digester.push(new WebXml()); WebXml desc = (WebXml) digester.parse( new File("test/webapp-3.0/WEB-INF/web.xml")); Assert.assertEquals("3.0", desc.getVersion()); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); }
Example #29
Source File: TomcatServer.java From javatech with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
@Override public Server getServer() { if (server != null) { return server; } // 默认不开启JNDI. 开启时, 注意maven必须添加tomcat-dbcp依赖 System.setProperty("catalina.useNaming", "false"); ExtendedCatalina extendedCatalina = new ExtendedCatalina(); // 覆盖默认的skip和scan jar包配置 System.setProperty(Constants.SKIP_JARS_PROPERTY, ""); System.setProperty(Constants.SCAN_JARS_PROPERTY, ""); Digester digester = extendedCatalina.createStartDigester(); digester.push(extendedCatalina); try { server = ((ExtendedCatalina) digester .parse(new File(System.getProperty("catalina.base") + RELATIVE_SERVERXML_PATH))).getServer(); // 设置catalina.base和catalna.home this.initBaseDir(); return server; } catch (Exception e) { log.error("Error while parsing server.xml", e); throw new RuntimeException("server未创建,请检查server.xml(路径:" + System.getProperty("catalina.base") + RELATIVE_SERVERXML_PATH + ")配置是否正确"); } }
Example #30
Source File: TestWebXml.java From tomcatsrc with Apache License 2.0 | 5 votes |
private void doTestValidateVersion(String version) throws IOException, SAXException { WebXml webxml = new WebXml(); // Special cases if ("2.2".equals(version)) { webxml.setPublicId(XmlIdentifiers.WEB_22_PUBLIC); } else if ("2.3".equals(version)) { webxml.setPublicId(XmlIdentifiers.WEB_23_PUBLIC); } else { webxml.setVersion(version); } // Merged web.xml that is published as MERGED_WEB_XML context attribute // in the simplest case consists of webapp's web.xml file // plus the default conf/web.xml one. Set<WebXml> defaults = new HashSet<WebXml>(); defaults.add(getDefaultWebXmlFragment()); webxml.merge(defaults); Digester digester = DigesterFactory.newDigester(true, true, new WebRuleSet(), true); XmlErrorHandler handler = new XmlErrorHandler(); digester.setErrorHandler(handler); InputSource is = new InputSource(new StringReader(webxml.toXml())); WebXml webxmlResult = new WebXml(); digester.push(webxmlResult); digester.parse(is); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); Assert.assertEquals(version, webxml.getVersion()); Assert.assertEquals(version, webxmlResult.getVersion()); }