use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.
the class TestSchemaValidation method testWebapp_2_5.
@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());
}
use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.
the class TestSchemaValidation method testWebapp_2_2.
@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());
}
use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.
the class PersistentProviderRegistrations method loadProviders.
static Providers loadProviders(File configFile) {
try (InputStream is = new FileInputStream(configFile)) {
// Construct a digester to read the XML input file
Digester digester = new Digester();
try {
digester.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
digester.setValidating(true);
digester.setNamespaceAware(true);
} catch (Exception e) {
throw new SecurityException(e);
}
// Create an object to hold the parse results and put it on the top
// of the digester's stack
Providers result = new Providers();
digester.push(result);
// Configure the digester
digester.addObjectCreate("jaspic-providers/provider", Provider.class.getName());
digester.addSetProperties("jaspic-providers/provider");
digester.addSetNext("jaspic-providers/provider", "addProvider", Provider.class.getName());
digester.addObjectCreate("jaspic-providers/provider/property", Property.class.getName());
digester.addSetProperties("jaspic-providers/provider/property");
digester.addSetNext("jaspic-providers/provider/property", "addProperty", Property.class.getName());
// Parse the input
digester.parse(is);
return result;
} catch (IOException | SAXException e) {
throw new SecurityException(e);
}
}
use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.
the class StoreLoader method createDigester.
/**
* Create and configure the Digester we will be using for setup store
* registry.
* @return the XML digester that will be used to parse the configuration
*/
protected static Digester createDigester() {
long t1 = System.currentTimeMillis();
// Initialize the digester
Digester digester = new Digester();
digester.setValidating(false);
digester.setClassLoader(StoreRegistry.class.getClassLoader());
// Configure the actions we will be using
digester.addObjectCreate("Registry", "org.apache.catalina.storeconfig.StoreRegistry", "className");
digester.addSetProperties("Registry");
digester.addObjectCreate("Registry/Description", "org.apache.catalina.storeconfig.StoreDescription", "className");
digester.addSetProperties("Registry/Description");
digester.addRule("Registry/Description", new StoreFactoryRule("org.apache.catalina.storeconfig.StoreFactoryBase", "storeFactoryClass", "org.apache.catalina.storeconfig.StoreAppender", "storeAppenderClass"));
digester.addSetNext("Registry/Description", "registerDescription", "org.apache.catalina.storeconfig.StoreDescription");
digester.addCallMethod("Registry/Description/TransientAttribute", "addTransientAttribute", 0);
digester.addCallMethod("Registry/Description/TransientChild", "addTransientChild", 0);
long t2 = System.currentTimeMillis();
if (log.isDebugEnabled())
log.debug("Digester for server-registry.xml created " + (t2 - t1));
return (digester);
}
use of org.apache.tomcat.util.digester.Digester in project tomcat by apache.
the class WebXmlParser method parseWebXml.
public boolean parseWebXml(InputSource source, WebXml dest, boolean fragment) {
boolean ok = true;
if (source == null) {
return ok;
}
XmlErrorHandler handler = new XmlErrorHandler();
Digester digester;
WebRuleSet ruleSet;
if (fragment) {
digester = webFragmentDigester;
ruleSet = webFragmentRuleSet;
} else {
digester = webDigester;
ruleSet = webRuleSet;
}
digester.push(dest);
digester.setErrorHandler(handler);
if (log.isDebugEnabled()) {
log.debug(sm.getString("webXmlParser.applicationStart", source.getSystemId()));
}
try {
digester.parse(source);
if (handler.getWarnings().size() > 0 || handler.getErrors().size() > 0) {
ok = false;
handler.logFindings(log, source.getSystemId());
}
} catch (SAXParseException e) {
log.error(sm.getString("webXmlParser.applicationParse", source.getSystemId()), e);
log.error(sm.getString("webXmlParser.applicationPosition", "" + e.getLineNumber(), "" + e.getColumnNumber()));
ok = false;
} catch (Exception e) {
log.error(sm.getString("webXmlParser.applicationParse", source.getSystemId()), e);
ok = false;
} finally {
InputSourceUtil.close(source);
digester.reset();
ruleSet.recycle();
}
return ok;
}
Aggregations