本文整理汇总了Java中org.apache.tomcat.util.digester.Digester.parse方法的典型用法代码示例。如果您正苦于以下问题:Java Digester.parse方法的具体用法?Java Digester.parse怎么用?Java Digester.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tomcat.util.digester.Digester
的用法示例。
在下文中一共展示了Digester.parse方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTestValidateVersion
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
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());
}
示例2: testWebapp_2_2
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
@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());
}
示例3: testWebapp_2_3
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
@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());
}
示例4: testWebapp_2_4
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
@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());
}
示例5: testWebapp_2_5
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
@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());
}
示例6: testWebapp_3_0
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
@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());
}
示例7: execute
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
/**
* Execute the specified command. This logic only performs the common
* attribute validation required by all subclasses; it does not perform
* any functional logic directly.
*
* @exception BuildException if a validation error occurs
*/
public void execute() throws BuildException {
if (path == null) {
throw new BuildException("Must specify 'path'");
}
File file = new File(path, Constants.ApplicationWebXml);
if ((!file.exists()) || (!file.canRead())) {
throw new BuildException("Cannot find web.xml");
}
// Commons-logging likes having the context classloader set
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader
(ValidatorTask.class.getClassLoader());
Digester digester = DigesterFactory.newDigester(true, true, null);
try {
file = file.getCanonicalFile();
InputStream stream =
new BufferedInputStream(new FileInputStream(file));
InputSource is = new InputSource(file.toURL().toExternalForm());
is.setByteStream(stream);
digester.parse(is);
handleOutput("web.xml validated");
} catch (Throwable t) {
if (isFailOnError()) {
throw new BuildException("Validation failure", t);
} else {
handleErrorOutput("Validation failure: " + t);
}
} finally {
Thread.currentThread().setContextClassLoader(oldCL);
closeRedirector();
}
}
示例8: parse
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
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);
}
}
示例9: startInternal
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
/**
* 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 {
// Validate the existence of our database file
File file = new File(pathname);
if (!file.isAbsolute())
file = new File(System.getProperty(Globals.CATALINA_BASE_PROP), pathname);
if (!file.exists() || !file.canRead())
throw new LifecycleException
(sm.getString("memoryRealm.loadExist",
file.getAbsolutePath()));
// Load the contents of the database file
if (log.isDebugEnabled())
log.debug(sm.getString("memoryRealm.loadPath",
file.getAbsolutePath()));
Digester digester = getDigester();
try {
synchronized (digester) {
digester.push(this);
digester.parse(file);
}
} catch (Exception e) {
throw new LifecycleException
(sm.getString("memoryRealm.readXml"), e);
} finally {
digester.reset();
}
super.startInternal();
}
示例10: load
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
/**
* Load the contents of our configuration file.
*/
protected void load() {
// Validate the existence of our configuration file
File file = new File(pathname);
if (!file.isAbsolute())
file = new File(System.getProperty(Globals.CATALINA_BASE_PROP), pathname);
if (!file.exists() || !file.canRead()) {
log.warn("Cannot load configuration file " + file.getAbsolutePath());
return;
}
// Load the contents of our configuration file
Digester digester = new Digester();
digester.setValidating(false);
digester.addRuleSet(new MemoryRuleSet());
try {
digester.push(this);
digester.parse(file);
} catch (Exception e) {
log.warn("Error processing configuration file " +
file.getAbsolutePath(), e);
return;
} finally {
digester.reset();
}
}
示例11: execute
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
/**
* Execute the specified command. This logic only performs the common
* attribute validation required by all subclasses; it does not perform
* any functional logic directly.
*
* @exception BuildException if a validation error occurs
*/
@Override
public void execute() throws BuildException {
if (path == null) {
throw new BuildException("Must specify 'path'");
}
File file = new File(path, Constants.ApplicationWebXml);
if ((!file.exists()) || (!file.canRead())) {
throw new BuildException("Cannot find web.xml");
}
// Commons-logging likes having the context classloader set
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader
(ValidatorTask.class.getClassLoader());
Digester digester = DigesterFactory.newDigester(true, true, null);
try {
file = file.getCanonicalFile();
InputStream stream =
new BufferedInputStream(new FileInputStream(file));
InputSource is =
new InputSource(file.toURI().toURL().toExternalForm());
is.setByteStream(stream);
digester.parse(is);
handleOutput("web.xml validated");
} catch (Exception e) {
if (isFailOnError()) {
throw new BuildException("Validation failure", e);
} else {
handleErrorOutput("Validation failure: " + e);
}
} finally {
Thread.currentThread().setContextClassLoader(oldCL);
closeRedirector();
}
}
示例12: execute
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
/**
* Execute the specified command. This logic only performs the common
* attribute validation required by all subclasses; it does not perform
* any functional logic directly.
*
* @exception BuildException if a validation error occurs
*/
@Override
public void execute() throws BuildException {
if (path == null) {
throw new BuildException("Must specify 'path'");
}
File file = new File(path, Constants.ApplicationWebXml);
if ((!file.exists()) || (!file.canRead())) {
throw new BuildException("Cannot find web.xml");
}
// Commons-logging likes having the context classloader set
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader
(ValidatorTask.class.getClassLoader());
// Called through trusted manager interface. If running under a
// SecurityManager assume that untrusted applications may be deployed.
Digester digester = DigesterFactory.newDigester(
true, true, null, Globals.IS_SECURITY_ENABLED);
try {
file = file.getCanonicalFile();
InputStream stream =
new BufferedInputStream(new FileInputStream(file));
InputSource is =
new InputSource(file.toURI().toURL().toExternalForm());
is.setByteStream(stream);
digester.parse(is);
handleOutput("web.xml validated");
} catch (Exception e) {
if (isFailOnError()) {
throw new BuildException("Validation failure", e);
} else {
handleErrorOutput("Validation failure: " + e);
}
} finally {
Thread.currentThread().setContextClassLoader(oldCL);
closeRedirector();
}
}
示例13: open
import org.apache.tomcat.util.digester.Digester; //导入方法依赖的package包/类
/**
* Initialize access to this user database.
*
* @exception Exception if any exception is thrown during opening
*/
@Override
public void open() throws Exception {
synchronized (groups) {
synchronized (users) {
// Erase any previous groups and users
users.clear();
groups.clear();
roles.clear();
// Construct a reader for the XML input file (if it exists)
File file = new File(pathname);
if (!file.isAbsolute()) {
file = new File(System.getProperty(Globals.CATALINA_BASE_PROP),
pathname);
}
if (!file.exists()) {
log.error(sm.getString("memoryUserDatabase.fileNotFound",
file.getAbsolutePath()));
return;
}
// 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);
} catch (Exception e) {
log.warn(sm.getString("memoryUserDatabase.xmlFeatureEncoding"), e);
}
digester.addFactoryCreate
("tomcat-users/group",
new MemoryGroupCreationFactory(this), true);
digester.addFactoryCreate
("tomcat-users/role",
new MemoryRoleCreationFactory(this), true);
digester.addFactoryCreate
("tomcat-users/user",
new MemoryUserCreationFactory(this), true);
// Parse the XML input file to load this database
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
digester.parse(fis);
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException ioe) {
// Ignore
}
}
}
}
}
}