本文整理匯總了Java中org.apache.commons.digester.Digester.addRuleSet方法的典型用法代碼示例。如果您正苦於以下問題:Java Digester.addRuleSet方法的具體用法?Java Digester.addRuleSet怎麽用?Java Digester.addRuleSet使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.digester.Digester
的用法示例。
在下文中一共展示了Digester.addRuleSet方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createTldDigester
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
/**
* Create (if necessary) and return a Digester configured to process a tag
* library descriptor, looking for additional listener classes to be
* registered.
*/
private static Digester createTldDigester() {
URL url = null;
Digester tldDigester = new Digester();
tldDigester.setValidating(true);
url = ContextConfig.class.getResource(Constants.TldDtdResourcePath_11);
tldDigester.register(Constants.TldDtdPublicId_11,
url.toString());
url = ContextConfig.class.getResource(Constants.TldDtdResourcePath_12);
tldDigester.register(Constants.TldDtdPublicId_12,
url.toString());
tldDigester.addRuleSet(new TldRuleSet());
return (tldDigester);
}
示例2: createWebDigester
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
/**
* Create (if necessary) and return a Digester configured to process the
* web application deployment descriptor (web.xml).
*/
private static Digester createWebDigester() {
URL url = null;
Digester webDigester = new Digester();
webDigester.setValidating(true);
url = ContextConfig.class.getResource(Constants.WebDtdResourcePath_22);
webDigester.register(Constants.WebDtdPublicId_22,
url.toString());
url = ContextConfig.class.getResource(Constants.WebDtdResourcePath_23);
webDigester.register(Constants.WebDtdPublicId_23,
url.toString());
webDigester.addRuleSet(new WebRuleSet());
return (webDigester);
}
示例3: 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);
}
}
}
示例4: 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);
}
}
示例5: DdlUtilsDataHandling
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
/**
* Creates a new data handling object.
*/
public DdlUtilsDataHandling()
{
_digester = new Digester();
_digester.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId)
{
// we don't care about the DTD for data files
return new InputSource(new StringReader(""));
}
});
_digester.setNamespaceAware(true);
_digester.setValidating(false);
_digester.setUseContextClassLoader(true);
_digester.setRules(new ExtendedBaseRules());
_digester.addRuleSet(new DataRuleSet());
}
示例6: 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;
}
}
示例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: read
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
/**
* Read from the <code>input</code> and return it's configuration settings
* as a {@link Map}.
*
* @param input
* @return return {@link Map} with all the configurations read from the
* config file, or throws an exception if there's a problem reading
* the input, e.g.: invalid XML.
* @throws SAXException
* @throws IOException
* @throws ConfigReadException
*/
public Map read(InputStream input) throws IOException,
SAXException,
ConfigReadException {
Digester digester = new Digester();
digester.addRuleSet(new RuleSet());
Object result = digester.parse(input);
if (result == null && !(result instanceof Profiles)) {
throw new ConfigReadException("No profiles found in config file");
}
Profiles profiles = (Profiles) result;
List list = profiles.getProfiles();
if (list.size() == 0) {
throw new ConfigReadException("No profile in config file of kind: " + Profiles.PROFILE_KIND);
}
return (Map) list.get(0);
}
示例9: read
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
/**
* Read from the <code>input</code> and return it's configuration settings
* as a {@link Map}.
*
* @param input
* @return return {@link Map} with all the configurations read from the
* config file, or throws an exception if there's a problem reading
* the input, e.g.: invalid XML.
* @throws SAXException
* @throws IOException
* @throws ConfigReadException
*/
public Map<String, String> read(InputStream input) throws IOException,
SAXException, ConfigReadException {
Digester digester = new Digester();
digester.addRuleSet(new RuleSet());
Object result = digester.parse(input);
if (result == null && !(result instanceof Profiles)) {
throw new ConfigReadException("No profiles found in config file");
}
Profiles profiles = (Profiles) result;
List<Map<String, String>> list = profiles.getProfiles();
if (list.size() == 0) {
throw new ConfigReadException("No profile in config file of kind: "
+ Profiles.PROFILE_KIND);
}
return (Map<String, String>) list.get(0);
}
示例10: applyRuleSets
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
/**
* Instantiate any <code>RuleSet</code> classes defined in the
* <code>rulesets</code> property and use them to add rules to our
* <code>Digester</code>.
* @param digester the Digester instance to add RuleSet objects to.
* @throws ServletException
*/
protected void applyRuleSets(Digester digester) throws ServletException {
if (this.rulesets == null || this.rulesets.trim().length() == 0) {
return;
}
rulesets = rulesets.trim();
String ruleSet = null;
while (rulesets.length() > 0) {
int comma = rulesets.indexOf(",");
if (comma < 0) {
ruleSet = rulesets.trim();
rulesets = "";
} else {
ruleSet = rulesets.substring(0, comma).trim();
rulesets = rulesets.substring(comma + 1).trim();
}
if (log.isDebugEnabled()) {
// TODO Internationalize msg
log.debug("Configuring custom Digester Ruleset of type " + ruleSet);
}
try {
RuleSet instance =
(RuleSet) RequestUtils.applicationInstance(ruleSet);
digester.addRuleSet(instance);
} catch (Exception e) {
// TODO Internationalize msg
log.error("Exception configuring custom Digester RuleSet", e);
throw new ServletException(e);
}
}
}
示例11: loadConfiguration
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
private void loadConfiguration(List<ObjectPool> realPools) throws Exception {
VenusClient all = new VenusClient();
for (String configFile : configFiles) {
configFile = (String) ConfigUtil.filter(configFile);
RuleSet ruleSet = new FromXmlRuleSet(ServiceFactory.class.getResource("venusClientRule.xml"), new DigesterRuleParser());
Digester digester = new Digester();
digester.setValidating(false);
digester.addRuleSet(ruleSet);
try {
InputStream is = ResourceUtils.getURL(configFile.trim()).openStream();
VenusClient venus = (VenusClient) digester.parse(is);
for (ServiceConfig config : venus.getServiceConfigs()) {
if (config.getType() == null) {
throw new ConfigurationException("Service type can not be null:" + configFile);
}
}
all.getRemoteMap().putAll(venus.getRemoteMap());
all.getServiceConfigs().addAll(venus.getServiceConfigs());
} catch (Exception e) {
throw new ConfigurationException("can not parser xml:" + configFile, e);
}
}
// 初始化 remote,並且創建Pool
for (Map.Entry<String, Remote> entry : all.getRemoteMap().entrySet()) {
pool = createObjectPool(entry.getValue(), realPools);
}
}
示例12: load
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
public void load(Resource resource){
URL eis = this.getClass().getResource("VenusSystemExceptionRule.xml");
if (eis == null) {
throw new VenusConfigException("classpath resource 'VenusSystemExceptionRule.xml' not found");
}
RuleSet ruleSet = new FromXmlRuleSet(eis, new DigesterRuleParser());
Digester digester = new Digester();
digester.addRuleSet(ruleSet);
try{
List<ExceptionConfig> list = (List<ExceptionConfig>) digester.parse(resource.getInputStream());
for (ExceptionConfig config : list) {
if (config.getErrorCode() == 0) {
Exception exception = (Exception) reflectionProvider.newInstance(config.getType());
if (exception instanceof CodedException) {
config.setErrorCode(((CodedException) exception).getErrorCode());
} else {
throw new VenusConfigException("exception type=" + config.getType()
+ " must implement CodedException or errorCode must not be null");
}
}
codeMap.put(config.getErrorCode(), config);
classMap.put(config.getType(), config);
}
}catch(Exception e){
try {
logger.error("parser "+resource.getURL()+" error", e);
} catch (IOException e1) {
logger.error("parser "+resource.getFilename()+" error", e);
}
}finally{
digester.clear();
}
}
示例13: configureDigester
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
protected void configureDigester(JasperReportsContext jasperReportsContext, Digester digester) throws SAXException, ParserConfigurationException
{
digester.setNamespaceAware(true);
digester.setRuleNamespaceURI(JRXmlConstants.JASPERTEMPLATE_NAMESPACE);
boolean validating = JRPropertiesUtil.getInstance(jasperReportsContext).getBooleanProperty(JRReportSaxParserFactory.COMPILER_XML_VALIDATION);
digester.setErrorHandler(this);
digester.setValidating(validating);
digester.setFeature("http://xml.org/sax/features/validation", validating);
digester.addRuleSet(rules);
}
示例14: parseRecord
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
private static List<RawOccurrenceRecord> parseRecord(InputSource inputSource, OccurrenceSchemaType schemaType)
throws IOException, SAXException {
RawOccurrenceRecordBuilder builder = new RawOccurrenceRecordBuilder();
Digester digester = new Digester();
digester.setNamespaceAware(true);
digester.setValidating(false);
digester.push(builder);
digester.addRuleSet(RULE_SETS.get(schemaType));
digester.parse(inputSource);
builder.resolvePriorities();
return builder.generateRawOccurrenceRecords();
}
示例15: init
import org.apache.commons.digester.Digester; //導入方法依賴的package包/類
public void init() {
doScanExtension();
//兼容 3.0.8以前版本
if(configFiles == null){
return;
}
for (String configFile : configFiles) {
configFile = (String) ConfigUtil.filter(configFile);
configFile = configFile.trim();
URL eis = this.getClass().getResource("VenusSystemExceptionRule.xml");
if (eis == null) {
throw new VenusConfigException("classpath resource 'VenusSystemExceptionRule.xml' not found");
}
RuleSet ruleSet = new FromXmlRuleSet(eis, new DigesterRuleParser());
Digester digester = new Digester();
digester.addRuleSet(ruleSet);
try {
InputStream is = null;
if (configFile.startsWith("classpath:")) {
configFile = configFile.substring("classpath:".length());
is = this.getClass().getClassLoader().getResourceAsStream(configFile);
} else {
is = new FileInputStream(new File(configFile));
}
List<ExceptionConfig> list = (List<ExceptionConfig>) digester.parse(is);
for (ExceptionConfig config : list) {
if (config.getErrorCode() == 0) {
Exception exception = (Exception) reflectionProvider.newInstance(config.getType());
if (exception instanceof CodedException) {
config.setErrorCode(((CodedException) exception).getErrorCode());
} else {
throw new VenusConfigException("exception type=" + config.getType()
+ " must implement CodedException or errorCode must not be null");
}
}
codeMap.put(config.getErrorCode(), config);
classMap.put(config.getType(), config);
}
} catch (Exception e) {
logger.error("parser VenusSystemExceptionRule.xml error", e);
}finally{
digester.clear();
}
}
}