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

The following examples show how to use org.apache.commons.digester3.Digester#addSetProperties() . 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: FindBugsParser.java    From analysis-model with MIT License 6 votes vote down vote up
/**
 * Pre-parses a file for some information not available from the FindBugs parser. Creates a mapping of FindBugs
 * warnings to messages. A bug is represented by its unique hash code. Also obtains original categories for bug
 * types.
 *
 * @param file
 *         the FindBugs XML file
 *
 * @return the map of warning messages
 * @throws SAXException
 *         if the file contains no valid XML
 * @throws IOException
 *         signals that an I/O exception has occurred.
 */
@VisibleForTesting
List<XmlBugInstance> preParse(final Reader file) throws SAXException, IOException {
    Digester digester = new SecureDigester(FindBugsParser.class);

    String rootXPath = "BugCollection/BugInstance";
    digester.addObjectCreate(rootXPath, XmlBugInstance.class);
    digester.addSetProperties(rootXPath);

    String fileXPath = rootXPath + "/LongMessage";
    digester.addCallMethod(fileXPath, "setMessage", 0);

    digester.addSetNext(rootXPath, "add", Object.class.getName());
    ArrayList<XmlBugInstance> bugs = new ArrayList<>();
    digester.push(bugs);
    digester.parse(file);

    return bugs;
}
 
Example 2
Source File: DupFinderParser.java    From analysis-model with MIT License 6 votes vote down vote up
@Override
protected void configureParser(final Digester digester) {
    String duplicationXPath = "*/DuplicatesReport/Duplicates/Duplicate";
    digester.addObjectCreate(duplicationXPath, Duplicate.class);
    digester.addSetProperties(duplicationXPath, "Cost", "cost");
    digester.addSetNext(duplicationXPath, "add");

    String fragmentXPath = duplicationXPath + "/Fragment";
    digester.addObjectCreate(fragmentXPath, Fragment.class);
    digester.addBeanPropertySetter(fragmentXPath + "/FileName", "fileName");
    digester.addBeanPropertySetter(fragmentXPath + "/Text", "text");
    digester.addSetNext(fragmentXPath, "addFragment", Fragment.class.getName());

    String lineRangeXPath = fragmentXPath + "/LineRange";
    digester.addObjectCreate(lineRangeXPath, Range.class);
    digester.addSetProperties(lineRangeXPath, "Start", "start");
    digester.addSetProperties(lineRangeXPath, "End", "end");
    digester.addSetNext(lineRangeXPath, "setLineRange", Range.class.getName());

    String offsetRangeXPath = fragmentXPath + "/OffsetRange";
    digester.addObjectCreate(offsetRangeXPath, Range.class);
    digester.addSetProperties(offsetRangeXPath, "Start", "start");
    digester.addSetProperties(offsetRangeXPath, "End", "end");
    digester.addSetNext(offsetRangeXPath, "setOffsetRange", Range.class.getName());
}
 
Example 3
Source File: RuleSet.java    From formatter-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the rule instances.
 *
 * @param digester
 *            the digester
 * 
 * @see org.apache.commons.digester3.RuleSetBase#addRuleInstances(org.apache.commons.digester3.Digester)
 */
@Override
public void addRuleInstances(Digester digester) {
    digester.addObjectCreate("profiles", Profiles.class);
    digester.addObjectCreate(PROFILES_PROFILE, Profile.class);
    digester.addObjectCreate(PROFILES_PROFILE_SETTING, Setting.class);

    digester.addSetNext(PROFILES_PROFILE, "addProfile");
    digester.addSetNext(PROFILES_PROFILE_SETTING, "addSetting");

    digester.addSetProperties(PROFILES_PROFILE, "kind", "kind");
    digester.addSetProperties(PROFILES_PROFILE_SETTING, "id", "id");
    digester.addSetProperties(PROFILES_PROFILE_SETTING, "value", "value");
}
 
Example 4
Source File: CheckStyleParser.java    From analysis-model with MIT License 5 votes vote down vote up
@Override
public Report parse(final ReaderFactory readerFactory) throws ParsingException {
    Digester digester = new SecureDigester(CheckStyleParser.class);

    String rootXPath = "checkstyle";
    digester.addObjectCreate(rootXPath, CheckStyle.class);
    digester.addSetProperties(rootXPath);

    String fileXPath = "checkstyle/file";
    digester.addObjectCreate(fileXPath, File.class);
    digester.addSetProperties(fileXPath);
    digester.addSetNext(fileXPath, "addFile", File.class.getName());

    String bugXPath = "checkstyle/file/error";
    digester.addObjectCreate(bugXPath, Error.class);
    digester.addSetProperties(bugXPath);
    digester.addSetNext(bugXPath, "addError", Error.class.getName());

    try (Reader reader = readerFactory.create()) {
        CheckStyle checkStyle = digester.parse(reader);
        if (checkStyle == null) {
            throw new ParsingException("Input stream is not a Checkstyle file.");
        }

        return convert(checkStyle);
    }
    catch (IOException | SAXException exception) {
        throw new ParsingException(exception);
    }
}
 
Example 5
Source File: SimianParser.java    From analysis-model with MIT License 5 votes vote down vote up
@Override
protected void configureParser(final Digester digester) {
    String duplicationXPath = "*/simian/check/set";
    digester.addObjectCreate(duplicationXPath, Set.class);
    digester.addSetProperties(duplicationXPath);
    digester.addSetNext(duplicationXPath, "add");

    String fileXPath = duplicationXPath + "/block";
    digester.addObjectCreate(fileXPath, Block.class);
    digester.addSetProperties(fileXPath);
    digester.addSetNext(fileXPath, "addBlock", Block.class.getName());
}
 
Example 6
Source File: CpdParser.java    From analysis-model with MIT License 5 votes vote down vote up
@Override
protected void configureParser(final Digester digester) {
    String duplicationXPath = "*/pmd-cpd/duplication";
    digester.addObjectCreate(duplicationXPath, Duplication.class);
    digester.addSetProperties(duplicationXPath);
    digester.addCallMethod(duplicationXPath + "/codefragment", "setCodeFragment", 0);
    digester.addSetNext(duplicationXPath, "add");

    String fileXPath = duplicationXPath + "/file";
    digester.addObjectCreate(fileXPath, SourceFile.class);
    digester.addSetProperties(fileXPath);
    digester.addSetNext(fileXPath, "addFile", SourceFile.class.getName());
}
 
Example 7
Source File: XmlFactoryConfigurationRuleSet.java    From velocity-tools with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Add the set of Rule instances defined in this RuleSet to the
 * specified <code>Digester</code> instance, associating them with
 * our namespace URI (if any).  This method should only be called
 * by a Digester instance.  These rules assume that an instance of
 * <code>org.apache.velocity.tools.view.ToolboxManager</code> is pushed
 * onto the evaluation stack before parsing begins.</p>
 *
 * @param digester Digester instance to which the new Rule instances
 *        should be added.
 */
public void addRuleInstances(Digester digester)
{
    // create the config objects
    digester.addObjectCreate("tools/property", propertyClass);
    digester.addObjectCreate("tools/*/property", propertyClass);
    digester.addObjectCreate("tools/data", dataClass);
    digester.addObjectCreate("tools/toolbox", toolboxConfigurationClass);
    digester.addObjectCreate("tools/toolbox/tool", toolConfigurationClass);

    // to apply matching attributes to specific setters of config objects
    digester.addSetProperties("tools/property");
    digester.addSetProperties("tools/*/property");
    digester.addSetProperties("tools");
    digester.addSetProperties("tools/data");
    digester.addSetProperties("tools/toolbox");
    digester.addSetProperties("tools/toolbox/tool", "class", "classname");

    // to add all attributes to config via setProperty(name,value)
    digester.addRule("tools", new PropertyAttributeRule());
    digester.addRule("tools/toolbox", new PropertyAttributeRule());
    digester.addRule("tools/toolbox/tool", new PropertyAttributeRule());

    // for config data & properties whose values are in the body of the tag
    digester.addRule("tools/data", new DataValueInBodyRule());
    digester.addRule("tools/*/property", new DataValueInBodyRule());

    // to finish a config and move on to the next
    digester.addSetNext("tools/property", "addProperty");
    digester.addSetNext("tools/*/property", "addProperty");
    digester.addSetNext("tools/data", "addData");
    digester.addSetNext("tools/toolbox", "addToolbox");
    digester.addSetNext("tools/toolbox/tool", "addTool");
}