Java Code Examples for org.apache.commons.digester.Digester#setClassLoader()

The following examples show how to use org.apache.commons.digester.Digester#setClassLoader() . 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: DigesterLoader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given the digester rules XML file, a class loader, and an input stream,
 * this method parses the input into Java objects. The class loader
 * is used by the digester to create the Java objects.
 * @param digesterRules URL to the XML document defining the digester rules
 * @param classLoader the ClassLoader to register with the digester
 * @param reader Reader over the XML file to parse into Java objects
 * @return an Object which is the root of the network of Java objects
 * created by digesting fileURL
 */
public static Object load(
                            URL digesterRules, 
                            ClassLoader classLoader,
                            Reader reader) 
                                throws 
                                    IOException, 
                                    SAXException, 
                                    DigesterLoadingException {
    Digester digester = createDigester(digesterRules);
    digester.setClassLoader(classLoader);
    try {
        return digester.parse(reader);
    } catch (XmlLoadException ex) {
        // This is a runtime exception that can be thrown by
        // FromXmlRuleSet#addRuleInstances, which is called by the Digester
        // before it parses the file.
        throw new DigesterLoadingException(ex.getMessage(), ex);
    }
}
 
Example 2
Source File: DigesterLoader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given the digester rules XML file, a class loader, and an input stream,
 * this method parses the input into Java objects. The class loader
 * is used by the digester to create the Java objects.
 * @param digesterRules URL to the XML document defining the digester rules
 * @param classLoader the ClassLoader to register with the digester
 * @param input InputStream over the XML file to parse into Java objects
 * @param rootObject an Object to push onto the digester's stack, prior
 * to parsing the input
 * @return an Object which is the root of the network of Java objects
 * created by digesting fileURL
 */
public static Object load(URL digesterRules, ClassLoader classLoader,
                          InputStream input, Object rootObject) throws IOException, SAXException,
        DigesterLoadingException {
    Digester digester = createDigester(digesterRules);
    digester.setClassLoader(classLoader);
    digester.push(rootObject);
    try {
        return digester.parse(input);
    } catch (XmlLoadException ex) {
        // This is a runtime exception that can be thrown by
        // FromXmlRuleSet#addRuleInstances, which is called by the Digester
        // before it parses the file.
        throw new DigesterLoadingException(ex.getMessage(), ex);
    }
}
 
Example 3
Source File: DigesterLoader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given the digester rules XML file, a class loader, and an input stream,
 * this method parses the input into Java objects. The class loader
 * is used by the digester to create the Java objects.
 * @param digesterRules URL to the XML document defining the digester rules
 * @param classLoader the ClassLoader to register with the digester
 * @param input Reader over the XML file to parse into Java objects
 * @param rootObject an Object to push onto the digester's stack, prior
 * to parsing the input
 * @return an Object which is the root of the network of Java objects
 * created by digesting fileURL
 */
public static Object load(
                            URL digesterRules, 
                            ClassLoader classLoader,
                            Reader input, 
                            Object rootObject) 
                                throws 
                                    IOException, 
                                    SAXException,
                                    DigesterLoadingException {
    Digester digester = createDigester(digesterRules);
    digester.setClassLoader(classLoader);
    digester.push(rootObject);
    try {
        return digester.parse(input);
    } catch (XmlLoadException ex) {
        // This is a runtime exception that can be thrown by
        // FromXmlRuleSet#addRuleInstances, which is called by the Digester
        // before it parses the file.
        throw new DigesterLoadingException(ex.getMessage(), ex);
    }
}
 
Example 4
Source File: ExtractChangeLogParser.java    From jenkins-test-harness with MIT License 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public ExtractChangeLogSet parse(AbstractBuild build, InputStream changeLogStream) throws IOException, SAXException {

    ArrayList<ExtractChangeLogEntry> changeLog = new ArrayList<ExtractChangeLogEntry>();

    Digester digester = new Digester();
    digester.setClassLoader(ExtractChangeLogSet.class.getClassLoader());
    digester.push(changeLog);
    digester.addObjectCreate("*/extractChanges/entry", ExtractChangeLogEntry.class);

    digester.addBeanPropertySetter("*/extractChanges/entry/zipFile");

    digester.addObjectCreate("*/extractChanges/entry/file",
            FileInZip.class);
    digester.addBeanPropertySetter("*/extractChanges/entry/file/fileName");
    digester.addSetNext("*/extractChanges/entry/file", "addFile");
    digester.addSetNext("*/extractChanges/entry", "add");

    digester.parse(changeLogStream);

    return new ExtractChangeLogSet(build, changeLog);
}
 
Example 5
Source File: DigesterLoader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Given the digester rules XML file, a class loader, and an input stream,
 * this method parses the input into Java objects. The class loader
 * is used by the digester to create the Java objects.
 * @param digesterRules URL to the XML document defining the digester rules
 * @param classLoader the ClassLoader to register with the digester
 * @param input InputStream over the XML file to parse into Java objects
 * @return an Object which is the root of the network of Java objects
 * created by digesting fileURL
 */
public static Object load(URL digesterRules, ClassLoader classLoader,
                          InputStream input) throws IOException, SAXException, DigesterLoadingException {
    Digester digester = createDigester(digesterRules);
    digester.setClassLoader(classLoader);
    try {
        return digester.parse(input);
    } catch (XmlLoadException ex) {
        // This is a runtime exception that can be thrown by
        // FromXmlRuleSet#addRuleInstances, which is called by the Digester
        // before it parses the file.
        throw new DigesterLoadingException(ex.getMessage(), ex);
    }
}
 
Example 6
Source File: TestConfigFactory.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a factory instance.
 */
public TestConfigFactory() {
    digester = new Digester();
    digester.setClassLoader(Thread.currentThread().getContextClassLoader());
    digester.addObjectCreate("testportlet-config", ArrayList.class);


    digester.addObjectCreate("testportlet-config/testsuite-config",
                             TestConfig.class);

    digester.addBeanPropertySetter("testportlet-config/testsuite-config/name",
                                   "name");
    digester.addBeanPropertySetter("testportlet-config/testsuite-config/class",
                                   "testClassName");
    digester.addBeanPropertySetter("testportlet-config/testsuite-config/display-uri",
                                   "displayURI");

    digester.addCallMethod("testportlet-config/testsuite-config/init-param", "addInitParameter", 2);
    digester.addCallParam("testportlet-config/testsuite-config/init-param/name", 0);
    digester.addCallParam("testportlet-config/testsuite-config/init-param/value", 1);

    digester.addCallMethod("testportlet-config/testsuite-config/action-param", "addActionParameter", 2);
    digester.addCallParam("testportlet-config/testsuite-config/action-param/name", 0);
    digester.addCallParam("testportlet-config/testsuite-config/action-param/value", 1);

    digester.addCallMethod("testportlet-config/testsuite-config/render-param", "addRenderParameter", 2);
    digester.addCallParam("testportlet-config/testsuite-config/render-param/name", 0);
    digester.addCallParam("testportlet-config/testsuite-config/render-param/value", 1);

    digester.addSetRoot("testportlet-config/testsuite-config", "add");

}
 
Example 7
Source File: VariableManager.java    From jsqsh with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes the variable manager with variables as described by
 * the XML file pointed to by URL.
 */
public void load(ClassLoader loader, String location, InputStream in) {
    
    String path;
    Digester digester = new Digester();
    digester.setValidating(false);
    
    if (loader != null) {
        
        digester.setClassLoader(loader);
    }
    
    path = "Variables/String";
    digester.addObjectCreate(path, "org.sqsh.variables.StringVariable");
    digester.addSetNext(path, "putUnremoveable", "org.sqsh.Variable");
    digester.addCallMethod(path, 
        "setName", 1, new Class[] { java.lang.String.class });
        digester.addCallParam(path, 0, "name");
    digester.addCallMethod(path, 
        "setValue", 1, new Class[] { java.lang.String.class });
        digester.addCallParam(path, 0, "value");
        
    path = "Variables/Integer";
    digester.addObjectCreate(path, "org.sqsh.variables.IntegerVariable");
    digester.addSetNext(path, "putUnremoveable", "org.sqsh.Variable");
    digester.addCallMethod(path, 
        "setName", 1, new Class[] { java.lang.String.class });
        digester.addCallParam(path, 0, "name");
    digester.addCallMethod(path, 
        "setMinValue", 1, new Class[] { java.lang.Integer.class });
        digester.addCallParam(path, 0, "min");
    digester.addCallMethod(path, 
        "setMaxValue", 1, new Class[] { java.lang.Integer.class });
        digester.addCallParam(path, 0, "max");
    digester.addCallMethod(path, 
        "setValue", 1, new Class[] { java.lang.String.class });
        digester.addCallParam(path, 0);
        
    path = "Variables/Dynamic";
    digester.addObjectCreate(path, "org.sqsh.Variable", "class");
    digester.addSetNext(path, "putUnremoveable", "org.sqsh.Variable");
    digester.addCallMethod(path, 
        "setName", 1, new Class[] { java.lang.String.class });
        digester.addCallParam(path, 0, "name");
    digester.addCallMethod(path, 
        "setValue", 1, new Class[] { java.lang.String.class });
        digester.addCallParam(path, 0, "value");
        
    path = "Variables/Property";
    digester.addObjectCreate(path,  "org.sqsh.variables.PropertyVariable");
    digester.addSetNext(path, "putUnremoveable", "org.sqsh.Variable");
    digester.addCallMethod(path, 
        "setName", 1, new Class[] { java.lang.String.class });
        digester.addCallParam(path, 0, "name");
    digester.addCallMethod(path, 
        "setBean", 1, new Class[] { java.lang.String.class });
        digester.addCallParam(path, 0, "bean");
    digester.addCallMethod(path, 
        "setProperty", 1, new Class[] { java.lang.String.class });
        digester.addCallParam(path, 0, "property");
    digester.addCallMethod(path, 
        "setSettable", 1, new Class[] { java.lang.Boolean.class });
        digester.addCallParam(path, 0, "settable");
    digester.addCallMethod(path, 
        "setQuiet", 1, new Class[] { java.lang.Boolean.class });
        digester.addCallParam(path, 0, "quiet");
        
    path = "*/Description";
    digester.addCallMethod(path, 
        "setDescription", 1, new Class[] { java.lang.String.class });
        digester.addCallParam(path, 0);
    path = "*/HelpLocation";
    digester.addCallMethod(path, 
        "setHelpLocation", 1, new Class[] { java.lang.String.class });
        digester.addCallParam(path, 0);
        
    digester.push(this); 
    try {
        
        digester.parse(in);
    }
    catch (Exception e) {
        
        LOG.severe("Failed to parse variable definition file '"
            + location + "': " + e.getMessage());
    }
}
 
Example 8
Source File: ResourceConfigReader.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
private ResourceConfigReader() {
    digester = new Digester();
    // digester.setLogger(LOG);  // Too many log messages.
    digester.setClassLoader(Thread.currentThread().getContextClassLoader());
    init();
}
 
Example 9
Source File: DigesterLoader.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a new digester which rules are defined by analyzing the digester
 * annotations in the target class.
 *
 * @param target the class has to be analyzed.
 * @return a new Digester instance.
 */
public Digester createDigester(final Class<?> target) {
    Digester digester = new Digester();
    digester.setClassLoader(target.getClassLoader());
    addRules(target, digester);
    return digester;
}