本文整理匯總了Java中org.apache.commons.digester.Digester.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java Digester.parse方法的具體用法?Java Digester.parse怎麽用?Java Digester.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.digester.Digester
的用法示例。
在下文中一共展示了Digester.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadVenusService
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
private void loadVenusService(List<ServiceConfig> serviceConfigList, Map<String, InterceptorMapping> interceptors, Map<String, InterceptorStackConfig> interceptorStacks) {
for (Resource config : configFiles) {
RuleSet ruleSet = new FromXmlRuleSet(this.getClass().getResource("venusServerRule.xml"), new DigesterRuleParser());
Digester digester = new Digester();
digester.addRuleSet(ruleSet);
try {
InputStream is = config.getInputStream();
Venus venus = (Venus) digester.parse(is);
serviceConfigList.addAll(venus.getServiceConfigs());
interceptors.putAll(venus.getInterceptors());
interceptorStacks.putAll(venus.getInterceptorStatcks());
} catch (Exception e) {
throw new ConfigurationException("can not parser xml:" + config.getFilename(), e);
}
}
}
示例2: parseConfig
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
private void parseConfig(String publicId, String entityURL,
String strutsConfig) {
// Prepare a Digester for parsing a struts-config.xml file
Digester digester = new Digester();
digester.push(config);
digester.setNamespaceAware(true);
digester.setValidating(true);
digester.addRuleSet(new ConfigRuleSet());
digester.register(publicId,
this.getClass().getResource(entityURL).toString());
// Parse the test struts-config.xml file
try {
InputStream input =
this.getClass().getResourceAsStream(strutsConfig);
assertNotNull("Got an input stream for " + strutsConfig, input);
digester.parse(input);
input.close();
} catch (Throwable t) {
t.printStackTrace(System.out);
fail("Parsing threw exception: " + t);
}
}
示例3: getWebworkPackages
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
/**
* Parse file to webwork configuration
*
* @param webworkConfigurationFile Webwork configuration file
* @return Webwork configuration package list
* @throws IOException IOException
* @throws SAXException SAXException
*/
@SuppressWarnings("unchecked")
public List<WebworkPackage> getWebworkPackages(File webworkConfigurationFile) throws IOException, SAXException {
final Digester digester = new Digester();
digester.addObjectCreate("xwork", ArrayList.class);
digester.addObjectCreate("xwork/package", WebworkPackage.class);
digester.addSetProperties("xwork/package", "name", "name");
digester.addSetProperties("xwork/package", "namespace", "namespace");
digester.addObjectCreate("xwork/package/action", WebworkAction.class);
digester.addSetProperties("xwork/package/action", "name", "name");
digester.addSetProperties("xwork/package/action", "class", "className");
digester.addSetNext("xwork/package/action", "addAction");
digester.addSetNext("xwork/package", "add");
return (List<WebworkPackage>)digester.parse(webworkConfigurationFile);
}
示例4: processSources
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
/**
* <p>Read xml configuration for source directories into SourceDirectory instances.</p>
* <p/>
* <p>package scope so that it could be individually tested</p>
*
* @param xml String xml to parse
* @throws IOException when an input/output error occurs
* @throws SAXException when given xml can not be parsed
*/
void processSources(final String xml)
throws IOException, SAXException {
final Digester digester = getDigester();
digester.addObjectCreate(XmlConfiguration.sources, ArrayList.class);
digester.addObjectCreate(XmlConfiguration.source, SourceDirectory.class);
digester.addCallMethod(XmlConfiguration.source, "setPath", 0);
digester.addSetProperties(XmlConfiguration.source, "not-found", "notFound");
digester.addSetNext(XmlConfiguration.source, "add");
final StringReader reader = new StringReader(xml);
Object o = digester.parse(reader);
if ((o != null) && o instanceof List) {
final List<SourceDirectory> parsedSources = (ArrayList<SourceDirectory>) o;
for (final SourceDirectory sourceDirectory : parsedSources) {
getSources().add(sourceDirectory);
}
}
}
示例5: processRules
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
/**
* <p>Process XML configuration to read rules elements into <code>Rules</code></p>
* <p/>
* <p>package scope so that it could be individually tested</p>
*
* @param xml String xml to parse
* @throws IOException when an input/output error occurs
* @throws SAXException when given xml can not be parsed
*/
void processRules(final String xml)
throws IOException, SAXException {
final Digester digester = getDigester();
digester.addObjectCreate(XmlConfiguration.rules, ArrayList.class);
digester.addObjectCreate(XmlConfiguration.rule, Rule.class);
digester.addSetProperties(XmlConfiguration.rule, "id", "idString");
digester.addCallMethod(XmlConfiguration.ruleComment, "setComment", 0);
digester.addCallMethod(XmlConfiguration.rulePackage, "addPackage", 0);
digester.addCallMethod(XmlConfiguration.ruleViolation, "addViolation", 0);
digester.addSetNext(XmlConfiguration.rule, "add");
final StringReader reader = new StringReader(xml);
Object o = digester.parse(reader);
if (o != null) {
final List<Rule> parsedRules = (ArrayList<Rule>) o;
getRules().addAll(parsedRules);
}
}
示例6: parse
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
public void parse() {
String path = System.getProperty("user.dir") + File.separator + "etc";
File file = new File(path, "MyDocument-1.xml");
Digester digester = new Digester();
try {
Rule rule = new MyRule();
digester.addRule("book", rule);
//digester.addRule("a/b", rule);
digester.parse(file);
}
catch(Exception e) {
e.printStackTrace();
}
}
示例7: main
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
public static void main(String[] args) {
String path = System.getProperty("user.dir") + File.separator + "etc";
File file = new File(path, "employee2.xml");
Digester digester = new Digester();
digester.addRuleSet(new EmployeeRuleSet());
try {
Employee employee = (Employee) digester.parse(file);
ArrayList offices = employee.getOffices();
Iterator iterator = offices.iterator();
System.out.println("-------------------------------------------------");
while (iterator.hasNext()) {
Office office = (Office) iterator.next();
Address address = office.getAddress();
System.out.println(office.getDescription());
System.out.println("Address : " +
address.getStreetNumber() + " " + address.getStreetName());
System.out.println("--------------------------------");
}
}
catch(Exception e) {
e.printStackTrace();
}
}
示例8: parseURL
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
private void parseURL(URL u) {
Digester d = new Digester();
d.setValidating(false);
d.push(this);
d.addObjectCreate("factory/template", HashMap.class);
d.addRule("factory/template", new AttributeCopyRule());
d.addSetNext("factory/template", "addFactoryTemplate");
try {
d.parse(u.openStream());
}
catch (Exception e) {
throw new ManifestFactoryParseException("Unable to parse " +
builder.getManifestFilename(), e);
}
}
示例9: main
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
public static void main(String[] args) {
String path = System.getProperty("user.dir") + File.separator + "etc";
File file = new File(path, "employee1.xml");
Digester digester = new Digester();
// add rules
digester.addObjectCreate("employee", "ex15.pyrmont.digestertest.Employee");
digester.addSetProperties("employee");
digester.addCallMethod("employee", "printName");
try {
Employee employee = (Employee) digester.parse(file);
System.out.println("First name : " + employee.getFirstName());
System.out.println("Last name : " + employee.getLastName());
}
catch(Exception e) {
e.printStackTrace();
}
}
示例10: load
import org.apache.commons.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("catalina.base"), pathname);
if (!file.exists() || !file.canRead()) {
log("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("Error processing configuration file " +
file.getAbsolutePath(), e);
return;
}
}
示例11: parseXML
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
public static GoPluginDescriptor parseXML(InputStream pluginXML, String pluginJarFileLocation, File pluginBundleLocation, boolean isBundledPlugin) throws IOException, SAXException {
Digester digester = initDigester();
GoPluginDescriptorParser parserForThisXML = new GoPluginDescriptorParser(pluginJarFileLocation, pluginBundleLocation, isBundledPlugin);
digester.push(parserForThisXML);
digester.addCallMethod("go-plugin", "createPlugin", 2);
digester.addCallParam("go-plugin", 0, "id");
digester.addCallParam("go-plugin", 1, "version");
digester.addCallMethod("go-plugin/about", "createAbout", 4);
digester.addCallParam("go-plugin/about/name", 0);
digester.addCallParam("go-plugin/about/version", 1);
digester.addCallParam("go-plugin/about/target-go-version", 2);
digester.addCallParam("go-plugin/about/description", 3);
digester.addCallMethod("go-plugin/about/vendor", "createVendor", 2);
digester.addCallParam("go-plugin/about/vendor/name", 0);
digester.addCallParam("go-plugin/about/vendor/url", 1);
digester.addCallMethod("go-plugin/about/target-os/value", "addTargetOS", 1);
digester.addCallParam("go-plugin/about/target-os/value", 0);
digester.parse(pluginXML);
return parserForThisXML.descriptor;
}
示例12: get
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
/**
* Reading the checksum file (xml) from an InputSream and put it in a Map.
*
* @param in
* @return A Map with the file name as key and the checksum as value.
*/
public static Map<String, String> get(final InputStream in) {
Digester digester = new Digester();
digester.setValidating(false);
digester.addObjectCreate("checksums", HashMap.class);
digester.addCallMethod("checksums/file", "put", 2);
digester.addCallParam("checksums/file/name", 0);
digester.addCallParam("checksums/file/checksum", 1);
try {
@SuppressWarnings("unchecked")
Map<String, String> checksums = (Map<String, String>) digester.parse(in);
return checksums;
} catch (Exception e) {
throw new FatalException("Error while parsing checksums: " + e.getMessage(), e);
}
}
示例13: doPipe
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session)
throws PipeRunException {
//Multi threading: instantiate digester for each request as the digester is NOT thread-safe.
//TODO: make a pool of digesters
Digester digester = DigesterLoader.createDigester(rulesURL);
try {
ByteArrayInputStream xmlInputStream =
new ByteArrayInputStream(input.toString().getBytes());
return new PipeRunResult(getForward(), digester.parse(xmlInputStream));
} catch (Exception e) {
throw new PipeRunException(this, getLogPrefix(session)+"exception in digesting", e);
}
}
示例14: getDefaultBook
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
public static OpeningBook getDefaultBook() {
if(defaultBook != null) {
return defaultBook;
}
Digester digester = new Digester();
digester.addObjectCreate("calculon/opening-book", OpeningBook.class);
digester.addObjectCreate("calculon/opening-book/moves", OpeningBook.MoveList.class);
digester.addCallMethod("calculon/opening-book/moves/move", "addMove", 2, new Class[] { String.class, Integer.class});
digester.addCallParam("calculon/opening-book/moves/move", 0, "pgn");
digester.addCallParam("calculon/opening-book/moves/move", 1, "count");
digester.addCallMethod("calculon/opening-book/moves/position", "setPosition", 1);
digester.addCallParam("calculon/opening-book/moves/position", 0);
digester.addSetNext("calculon/opening-book/moves", "addMoveList");
try {
log.fine("Creating opening book");
defaultBook = (OpeningBook) digester.parse(OpeningBook.class.getResourceAsStream("/calculon.xml"));
return defaultBook;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例15: xmlConfiguration2Object
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
public void xmlConfiguration2Object() throws SAXException
{
Digester digester = new Digester();
digester.push(this);
digester.addCallMethod("datasources/datasource", "addDataConfigurationSource", 4 );
digester.addCallParam("datasources/datasource/rutaFotos", 0);
digester.addCallParam("datasources/datasource/rutaCarpetaFotos", 1);
digester.addCallParam("datasources/datasource/rutaFotoNoExiste", 2);
digester.addCallParam("datasources/datasource/passPhrase", 3);
try{
//java.io.InputStream xmlFile = getClass().getResourceAsStream("xml/datasource.xml");
java.io.InputStream xmlFile
= new java.io.FileInputStream(gafetes.util.VariablesAmbiente.getArchivoConfiguracion());
digester.parse(xmlFile);
}catch( java.io.IOException ioex ){
System.out.println();
}
}