List of usage examples for org.apache.commons.digester3 Digester addRuleSet
public void addRuleSet(RuleSet ruleSet)
From source file:net.revelc.code.formatter.model.ConfigReader.java
/** * Read from the <code>input</code> and return it's configuration settings * as a {@link Map}.//from w w w. ja v a 2 s.c o m * * @param input the 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 IOException Signals that an I/O exception has occurred. * @throws SAXException the SAX exception * @throws ConfigReadException the config read exception */ 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.isEmpty()) { throw new ConfigReadException("No profile in config file of kind: " + Profiles.PROFILE_KIND); } return list.get(0); }
From source file:com.relativitas.maven.plugins.formatter.ConfigReader.java
/** * Read from the <code>input</code> and return it's configuration settings * as a {@link Map}.//from w w w. j ava 2s . co m * * @param input the 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 IOException Signals that an I/O exception has occurred. * @throws SAXException the SAX exception * @throws ConfigReadException the config read exception */ 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); }
From source file:com.dotosoft.dot4command.config.xml.XmlConfigParser.java
/** * <p>Return the <code>Digester</code> instance to be used for * parsing, creating one if necessary.</p> * @return A Digester instance.// w ww . j a v a 2s . c o m */ public Digester getDigester() { Digester digester = new Digester(); RuleSet ruleSet = getRuleSet(); digester.setNamespaceAware(ruleSet.getNamespaceURI() != null); digester.setUseContextClassLoader(getUseContextClassLoader()); digester.setValidating(false); digester.addRuleSet(ruleSet); return digester; }