List of usage examples for org.apache.commons.digester Digester parse
public Object parse(URL url) throws IOException, SAXException
From source file:com.panet.imeta.core.config.DigesterConfigManager.java
/** * Loads the configuration parameters by delegating to commons digester. *//*from w ww .ja v a 2 s .c o m*/ public Collection<T> load() throws KettleConfigException { ClassLoader loader = Thread.currentThread().getContextClassLoader(); Digester digester = DigesterLoader.createDigester(loader.getResource(rulesURL)); final Set<T> configObjs = new LinkedHashSet<T>(); digester.addRule(setNext, new SetNextRule("") { @SuppressWarnings("unchecked") public void end(String nameSpace, String name) throws Exception { configObjs.add((T) digester.peek()); } }); try { digester.parse(loader.getResource(configURL)); } catch (Exception e) { throw new KettleConfigException(e); } return configObjs; }
From source file:com.liteoc.dao.core.DAODigester.java
public void run() throws IOException, SAXException { Digester digester = new Digester(); digester.push(this); // set up a simple format for grabbing queries through XML /*/*from w w w . j a v a 2 s . c om*/ * <queries> <query> <name>userDaoInsert</name> <sql>INSERT INTO USER * (USER_ID, USER_NAME, USER_PASS) VALUES (USER_ID_SEQ.NEXTVAL,?,?);</sql> * </query> </queries> * */ digester.addCallMethod("queries/query", "setQuery", 2); digester.addCallParam("queries/query/name", 0); digester.addCallParam("queries/query/sql", 1); digester.parse(fis); }
From source file:com.founder.e5.config.ConfigReader.java
/** * /* w w w .j a v a 2s . c o m*/ * @param in */ public synchronized void getConfigure(InputStream in) { // if (centralDB != null) return; Digester digester = new Digester(); digester.setNamespaceAware(true); digester.setValidating(false); digester.setUseContextClassLoader(true); digester.push(this); digester.addRuleSet(new RuleSetConfig()); try { digester.parse(in); } catch (IOException e) { throw new RuntimeException("Configuration file io exception!!! ", e); } catch (SAXException e) { throw new RuntimeException("Configuration file parse exception!!! ", e); } }
From source file:com.discursive.jccook.xml.bean.XMLNamespaceDigest.java
public void testDigest() throws IOException, SAXException { Pages pages = new Pages(); Digester digester = new Digester(); digester.setNamespaceAware(true);//from w ww .j a va 2s .co m digester.setRuleNamespaceURI("http://discursive.com/page"); URL pageRules = getClass().getResource("./page-rules.xml"); digester.addRuleSet(new FromXmlRuleSet(pageRules)); digester.setRuleNamespaceURI("http://discursive.com/person"); URL personRules = getClass().getResource("./person-rules.xml"); digester.addRuleSet(new FromXmlRuleSet(personRules)); digester.push(pages); InputStream input = getClass().getResourceAsStream("./content.xml"); digester.parse(input); Page page = (Page) pages.getPages().get(0); System.out.println(page); }
From source file:com.meidusa.venus.frontend.http.VenusPoolFactory.java
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);//ww w . j a va2 s . co m 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); } } // ? remotePool for (Map.Entry<String, Remote> entry : all.getRemoteMap().entrySet()) { pool = createObjectPool(entry.getValue(), realPools); } }
From source file:com.germinus.easyconf.ConfigurationLoader.java
/** * Read an XML file and return an Object representation of its contents *///from w w w .jav a 2s . c o m Object loadXMLFile(URL confFileUrl, ComponentProperties properties) throws IOException, SAXException { log.debug("Loading XML file: " + confFileUrl); String componentName = properties.getComponentName(); String rulesFileName = componentName + Conventions.DIGESTERRULES_EXTENSION; URL digesterRulesUrl = ClasspathUtil.locateResource(rulesFileName); if (digesterRulesUrl == null) { throw new DigesterRulesNotFoundException(componentName, rulesFileName); } Digester digester = DigesterLoader.createDigester(digesterRulesUrl); digester.setUseContextClassLoader(true); digester.setValidating(false); MultiVariableExpander expander = new MultiVariableExpander(); expander.addSource("$", properties.toMap()); Substitutor substitutor = new VariableSubstitutor(expander); digester.setSubstitutor(substitutor); try { Object confObj = digester.parse(confFileUrl.openStream()); log.info("Read configuration from " + confFileUrl); return confObj; } catch (IllegalArgumentException e) { //FIXME: it does not catch the exception throw new InvalidPropertyException(properties.getComponentName(), e); } }
From source file:com.nec.nsgui.model.biz.framework.menu.NSMenuFactory.java
/** * parse the inputStream and create NSMenusBean object. * @param inputStream/*from w w w . ja v a 2 s . co m*/ * @return * @throws Exception */ private static NSMenusBean parse(InputStream inputStream) throws Exception { Digester digester = new Digester(); digester.setValidating(false); digester.setUseContextClassLoader(true); //parse root and create nsmenus object. digester.addObjectCreate(CONFIG_FILE_TAG_NSMENUS, NSMenusBean.class); //parse Category and create a CategoryBean object. String categoryStr = CONFIG_FILE_TAG_NSMENUS + CONFIG_FILE_TAG_SEPARATER + CONFIG_FILE_TAG_CATEGORY; digester.addObjectCreate(categoryStr, CategoryBean.class); digester.addSetProperties(categoryStr); digester.addSetNext(categoryStr, "addCategoryMap"); //parse SubCategory and create SubCategoryBean object. String subCategoryStr = categoryStr + CONFIG_FILE_TAG_SEPARATER + CONFIG_FILE_TAG_SUBCATEGORY; digester.addObjectCreate(subCategoryStr, SubCategoryBean.class); digester.addSetProperties(subCategoryStr); digester.addSetNext(subCategoryStr, "addSubCategoryMap"); //parse Item and create ItemBean object. String itemStr = subCategoryStr + CONFIG_FILE_TAG_SEPARATER + CONFIG_FILE_TAG_ITEM; digester.addObjectCreate(itemStr, ItemBean.class); digester.addSetProperties(itemStr); String hiddenStr = itemStr + CONFIG_FILE_TAG_SEPARATER + CONFIG_FILE_TAG_HIDDEN; digester.addCallMethod(hiddenStr, "addHiddenMap", 2); digester.addCallParam(hiddenStr, 0, "name"); digester.addCallParam(hiddenStr, 1, "value"); digester.addSetNext(itemStr, "addItemMap"); return (NSMenusBean) digester.parse(inputStream); }
From source file:com.threerings.cast.bundle.tools.MetadataBundlerTask.java
protected ArrayList<?> parseList(Digester digester, File path) throws BuildException { try {//w w w . j a va 2s . c o m FileInputStream fin = new FileInputStream(path); BufferedInputStream bin = new BufferedInputStream(fin); ArrayList<Object> setlist = Lists.newArrayList(); digester.push(setlist); // now fire up the digester to parse the stream try { digester.parse(bin); } catch (Exception e) { throw new BuildException("Parsing error.", e); } return setlist; } catch (FileNotFoundException fnfe) { String errmsg = "Unable to load metadata definition file " + "[path=" + path + "]."; throw new BuildException(errmsg, fnfe); } }
From source file:crfsvm.svm.org.itc.irst.tcc.sre.util.StemmerFactory.java
/** * Constructs a <code>StemmerFactory</code> object. * *///from w ww . j a va 2 s. c om private StemmerFactory() { initParams = new Properties(); try { Digester digester = new Digester(); digester.push(this); digester.addCallMethod("jsre-config/stemmer-list/stemmer", "addStemmer", 2); digester.addCallParam("jsre-config/stemmer-list/stemmer/stemmer-name", 0); digester.addCallParam("jsre-config/stemmer-list/stemmer/stemmer-class", 1); String configFile = System.getProperty("config.file"); if (configFile == null) { logger.debug("StemmerFactory uses the default config file: jsre-config.xml"); digester.parse("jsre-config.xml"); } else { logger.debug("StemmerFactory uses the config file: " + configFile); digester.parse(configFile); } } catch (Exception e) { logger.error(e); } }
From source file:eu.planets_project.pp.plato.xml.TreeLoader.java
public PolicyTree loadFreeMindPolicyTree(InputStream in) { MindMap map = new MindMap(); // load content into temporary structure Digester digester = new Digester(); digester.setSchema("/data/schemas/freemind.xsd"); digester.setValidating(true);//from ww w . j ava 2 s .c o m digester.push(map); digester.addObjectCreate("*/node", "eu.planets_project.pp.plato.xml.freemind.Node"); digester.addSetProperties("*/node"); digester.addSetNext("*/node", "addChild"); try { //InputStream s = Thread.currentThread().getContextClassLoader().getResourceAsStream(file); digester.setUseContextClassLoader(true); digester.parse(in); } catch (IOException e) { log.error("Error loading Freemind file. Cause: " + e.getMessage()); return null; } catch (SAXException e) { log.error("Document is not a valid Freemind file. Cause: " + e.getMessage()); return null; } PolicyTree tree = new PolicyTree(); tree.setRoot(map.getPolicyTreeRoot()); return tree; }