Java Code Examples for org.apache.tomcat.util.digester.Digester#parse()
The following examples show how to use
org.apache.tomcat.util.digester.Digester#parse() .
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: 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 2
Source File: TestSchemaValidation.java From tomcatsrc 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 3
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()); }
Example 4
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 5
Source File: TestSchemaValidation.java From tomcatsrc 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 6
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 7
Source File: TestSchemaValidation.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
@Test public void testWebapp_2_3() 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.3/WEB-INF/web.xml")); Assert.assertEquals("2.3", desc.getVersion()); Assert.assertEquals(XmlIdentifiers.WEB_23_PUBLIC, desc.getPublicId()); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); }
Example 8
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 9
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 10
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 11
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 12
Source File: TestSchemaValidation.java From Tomcat8-Source-Read with MIT License | 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 13
Source File: TestSchemaValidation.java From tomcatsrc with Apache License 2.0 | 5 votes |
@Test public void testWebapp_2_3() 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.3/WEB-INF/web.xml")); Assert.assertEquals("2.3", desc.getVersion()); Assert.assertEquals(XmlIdentifiers.WEB_23_PUBLIC, desc.getPublicId()); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); }
Example 14
Source File: TestSchemaValidation.java From Tomcat8-Source-Read with MIT License | 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 15
Source File: TestSchemaValidation.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testWebapp_2_3() 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.3/WEB-INF/web.xml")); Assert.assertEquals("2.3", desc.getVersion()); Assert.assertEquals(XmlIdentifiers.WEB_23_PUBLIC, desc.getPublicId()); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); }
Example 16
Source File: TestSchemaValidation.java From Tomcat8-Source-Read with MIT License | 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 17
Source File: TestSchemaValidation.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Test public void testWebapp() 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/WEB-INF/web.xml")); Assert.assertEquals("3.1", desc.getVersion()); Assert.assertEquals(0, handler.getErrors().size()); Assert.assertEquals(0, handler.getWarnings().size()); }
Example 18
Source File: TestWebRuleSet.java From Tomcat8-Source-Read with MIT License | 5 votes |
private synchronized void parse(WebXml webXml, String target, boolean fragment, boolean expected) { 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); boolean result = true; try (InputStream is = new FileInputStream(f);) { d.parse(is); } catch (Exception e) { if (expected) { // Didn't expect an exception e.printStackTrace(); } result = false; } if (expected) { Assert.assertTrue(result); } else { Assert.assertFalse(result); } }
Example 19
Source File: TestWebXml.java From Tomcat8-Source-Read with MIT License | 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<>(); 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 20
Source File: MemoryRealm.java From Tomcat8-Source-Read with MIT License | 5 votes |
/** * Prepare for the beginning of active use of the public methods of this * component and implement the requirements of * {@link org.apache.catalina.util.LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected void startInternal() throws LifecycleException { String pathName = getPathname(); try (InputStream is = ConfigFileLoader.getInputStream(pathName)) { // Load the contents of the database file if (log.isDebugEnabled()) { log.debug(sm.getString("memoryRealm.loadPath", pathName)); } Digester digester = getDigester(); try { synchronized (digester) { digester.push(this); digester.parse(is); } } catch (Exception e) { throw new LifecycleException(sm.getString("memoryRealm.readXml"), e); } finally { digester.reset(); } } catch (IOException ioe) { throw new LifecycleException(sm.getString("memoryRealm.loadExist", pathName), ioe); } super.startInternal(); }