Java Code Examples for org.apache.commons.digester3.Digester#addRuleSet()

The following examples show how to use org.apache.commons.digester3.Digester#addRuleSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigReader.java    From formatter-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Read from the <code>input</code> and return it's configuration settings as a {@link Map}.
 *
 * @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);
}
 
Example 2
Source File: XmlFactoryConfiguration.java    From velocity-tools with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Reads an XML document from an {@link URL}
 * and uses it to configure this {@link FactoryConfiguration}.</p>
 * 
 * @param url the URL to read from
 */
protected void readImpl(URL url) throws IOException
{
    // since beanutils 1.9.4, we need to relax access to the 'class' method
    BeanUtilsBean.getInstance().getPropertyUtils().removeBeanIntrospector(SuppressPropertiesBeanIntrospector.SUPPRESS_CLASS);

    Digester digester = new Digester();
    digester.setNamespaceAware(true);
    digester.setXIncludeAware(true);
    digester.setValidating(false);
    digester.setUseContextClassLoader(true);
    digester.push(this);
    digester.addRuleSet(getRuleSet());
    try
    {
        digester.parse(url);
    }
    catch (SAXException saxe)
    {
        throw new RuntimeException("There was an error while parsing the InputStream", saxe);
    }
    finally
    {
        BeanUtilsBean.getInstance().getPropertyUtils().resetBeanIntrospectors();
    }
}
 
Example 3
Source File: AnyClass.java    From formatter-maven-plugin with Apache License 2.0 votes vote down vote up
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 list.stream()					.filter(profile -> (profile != null && profile.size() != 0))					.findAny().get();		} 
Example 4
Source File: AnyClassCRLF.java    From formatter-maven-plugin with Apache License 2.0 votes vote down vote up
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 list.stream()					.filter(profile -> (profile != null && profile.size() != 0))					.findAny().get();		} 
Example 5
Source File: AnyClassCR.java    From formatter-maven-plugin with Apache License 2.0 votes vote down vote up
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 list.stream()					.filter(profile -> (profile != null && profile.size() != 0))					.findAny().get();		} 
Example 6
Source File: AnyClassLF.java    From formatter-maven-plugin with Apache License 2.0 votes vote down vote up
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 list.stream()					.filter(profile -> (profile != null && profile.size() != 0))					.findAny().get();		}