Example usage for org.apache.commons.digester Digester addCallParam

List of usage examples for org.apache.commons.digester Digester addCallParam

Introduction

In this page you can find the example usage for org.apache.commons.digester Digester addCallParam.

Prototype

public void addCallParam(String pattern, int paramIndex, int stackIndex) 

Source Link

Document

Add a "call parameter" rule that sets a parameter from the stack.

Usage

From source file:net.erdfelt.android.sdkfido.git.GitMirrors.java

/**
 * Load specific gitmirror xml file./*w w w . j  a v  a2s  . c o m*/
 * 
 * @param mirrorxml
 *            the mirrorxml to load
 * @return a GitMirrors object, with information from the mirrorxml, or empty (if mirrorxml not found)
 */
public static GitMirrors load(File mirrorxml) {
    if (!mirrorxml.exists()) {
        return new GitMirrors();
    }
    Digester digester = new Digester();
    digester.addObjectCreate("mirrors", GitMirrors.class);

    digester.addCallMethod("mirrors/mirror", "addMirror", 2);
    digester.addCallParam("mirrors/mirror", 0, "url");
    digester.addCallParam("mirrors/mirror", 1, "mirrorurl");

    try {
        return (GitMirrors) digester.parse(mirrorxml);
    } catch (IOException e) {
        LOG.log(Level.WARNING, "Unable to load GitMirrors: " + mirrorxml, e);
    } catch (SAXException e) {
        LOG.log(Level.WARNING, "Unable to load GitMirrors: " + mirrorxml, e);
    }
    return new GitMirrors();
}

From source file:barrysw19.calculon.opening.OpeningBook.java

public static OpeningBook getDefaultBook() {
    if (defaultBook != null) {
        return defaultBook;
    }//w w  w .j ava 2 s .co m

    Digester digester = new Digester();
    digester.addObjectCreate("calculon/opening-book", OpeningBook.class);
    digester.addObjectCreate("calculon/opening-book/moves", OpeningBook.MoveList.class);

    digester.addCallMethod("calculon/opening-book/moves/move", "addMove", 2,
            new Class[] { String.class, Integer.class });
    digester.addCallParam("calculon/opening-book/moves/move", 0, "pgn");
    digester.addCallParam("calculon/opening-book/moves/move", 1, "count");

    digester.addCallMethod("calculon/opening-book/moves/position", "setPosition", 1);
    digester.addCallParam("calculon/opening-book/moves/position", 0);

    digester.addSetNext("calculon/opening-book/moves", "addMoveList");

    try {
        log.fine("Creating opening book");
        defaultBook = (OpeningBook) digester.parse(OpeningBook.class.getResourceAsStream("/calculon.xml"));
        return defaultBook;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.redhat.rhn.frontend.nav.NavDigester.java

/**
 * buildTree, method to take a url and parse the contents
 * into a NavTree// ww w .j a  va 2 s  . c  o m
 * @param url the file to parse
 * @return NavTree the tree represented by the file
 * @throws Exception if something breaks. XXX: fix to be tighter
 */
public static NavTree buildTree(URL url) throws Exception {
    if (url == null) {
        throw new IllegalArgumentException(
                "URL is null, your definition tag " + "probably points to a non existing file.");
    }
    Digester digester = new Digester();
    digester.setValidating(false);

    digester.addObjectCreate("rhn-navi-tree", NavTree.class);
    digester.addSetProperties("rhn-navi-tree");
    digester.addSetProperties("rhn-navi-tree", "acl_mixins", "aclMixins");

    digester.addObjectCreate("*/rhn-tab", NavNode.class);
    digester.addSetProperties("*/rhn-tab", "active-image", "activeImage");
    digester.addSetProperties("*/rhn-tab", "inactive-image", "inactiveImage");
    digester.addSetProperties("*/rhn-tab", "target", "target");

    digester.addCallMethod("*/rhn-tab", "addPrimaryURL", 1);
    digester.addCallParam("*/rhn-tab", 0, "url");

    digester.addCallMethod("*/rhn-tab/rhn-tab-url", "addURL", 0);
    digester.addCallMethod("*/rhn-tab/rhn-tab-directory", "addDirectory", 0);

    digester.addSetNext("*/rhn-tab", "addNode");
    return (NavTree) digester.parse(url.openStream());
}

From source file:com.dianping.avatar.cache.configuration.CacheItemConfig.java

/**
 * Parse configuraiton file/*from  w  w  w  .  j  a va2s  .c  om*/
 */
private void init(String file) {
    try {

        Digester digester = new Digester();

        digester.addCallMethod("dpcache/import", "addImport", 1, new Class[] { String.class });
        digester.addCallParam("dpcache/import", 0, "file");

        digester.addObjectCreate("dpcache/add", CacheKeyType.class);
        digester.addSetProperties("dpcache/add", "name", "category");
        digester.addSetProperties("dpcache/add", "index", "indexTemplate");
        digester.addSetProperties("dpcache/add", "duration", "duration");
        digester.addSetProperties("dpcache/add", "indexDesc", "indexParamDescs");
        digester.addSetProperties("dpcache/add", "type", "cacheType");

        digester.addSetNext("dpcache/add", "addCacheKeyType");

        InputStream in = resourceLoader.getResource(file).getInputStream();

        digester.push(this);
        digester.parse(in);

        in.close();

        for (String importFile : importFiles) {
            CacheItemConfig config = new CacheItemConfig();
            config.init(importFile);
            this.cacheKeyTypes.putAll(config.cacheKeyTypes);
        }
    } catch (Exception e) {
        throw new SystemException("Failed to initialize cache items config file", e);
    }
}

From source file:net.jetrix.config.ServerRuleSet.java

public void addRuleInstances(Digester digester) {
    // server parameters
    digester.addCallMethod("tetrinet-server/name", "setName", 0);
    digester.addCallMethod("tetrinet-server", "setHost", 1);
    digester.addCallParam("tetrinet-server", 0, "host");
    digester.addCallMethod("tetrinet-server/language", "setLocale", 0);
    digester.addCallMethod("tetrinet-server/timeout", "setTimeout", 0, new Class[] { Integer.TYPE });
    digester.addCallMethod("tetrinet-server/max-channels", "setMaxChannels", 0, new Class[] { Integer.TYPE });
    digester.addCallMethod("tetrinet-server/max-players", "setMaxPlayers", 0, new Class[] { Integer.TYPE });
    digester.addCallMethod("tetrinet-server/max-connections", "setMaxConnections", 0,
            new Class[] { Integer.TYPE });
    digester.addCallMethod("tetrinet-server/op-password", "setOpPassword", 0);
    digester.addCallMethod("tetrinet-server/admin-password", "setAdminPassword", 0);
    digester.addCallMethod("tetrinet-server/access-log", "setAccessLogPath", 1);
    digester.addCallParam("tetrinet-server/access-log", 0, "path");
    digester.addCallMethod("tetrinet-server/error-log", "setErrorLogPath", 1);
    digester.addCallParam("tetrinet-server/error-log", 0, "path");
    digester.addCallMethod("tetrinet-server/channels", "setChannelsFile", 1);
    digester.addCallParam("tetrinet-server/channels", 0, "path");

    // command definitions
    digester.addObjectCreate("*/command", null, "class");
    digester.addSetNext("*/command", "addCommand", "net.jetrix.commands.Command");
    digester.addCallMethod("*/command", "setAccessLevel", 1, new Class[] { Integer.TYPE });
    digester.addCallParam("*/command", 0, "access-level");

    // listeners/*  w  w  w .jav  a  2  s . c  om*/
    digester.addObjectCreate("*/listener", null, "class");
    digester.addSetProperties("*/listener");
    digester.addCallMethod("*/listener", "setAutoStart", 1, new Class[] { Boolean.TYPE });
    digester.addCallParam("*/listener", 0, "auto-start");
    digester.addSetNext("*/listener", "addListener", "net.jetrix.Listener");

    // services
    digester.addObjectCreate("*/service", null, "class");
    digester.addSetProperties("*/service");
    digester.addCallMethod("*/service", "setAutoStart", 1, new Class[] { Boolean.TYPE });
    digester.addCallParam("*/service", 0, "auto-start");
    digester.addSetProperty("*/service/param", "name", "value");
    digester.addSetNext("*/service", "addService", "net.jetrix.Service");

    // banlist
    digester.addCallMethod("tetrinet-server/ban/host", "addBannedHost", 0);

    // datasource
    digester.addObjectCreate("*/datasource", "net.jetrix.config.DataSourceConfig");
    digester.addSetNext("*/datasource", "addDataSource", "net.jetrix.config.DataSourceConfig");
    digester.addCallMethod("*/datasource", "setName", 1);
    digester.addCallParam("*/datasource", 0, "name");
    digester.addCallMethod("*/datasource/driver", "setDriver", 0);
    digester.addCallMethod("*/datasource/url", "setUrl", 0);
    digester.addCallMethod("*/datasource/username", "setUsername", 0);
    digester.addCallMethod("*/datasource/password", "setPassword", 0);
    digester.addCallMethod("*/datasource/min-idle", "setMinIdle", 0);
    digester.addCallMethod("*/datasource/max-active", "setMaxActive", 0);

    // mail session
    digester.addObjectCreate("*/mailserver", "net.jetrix.config.MailSessionConfig");
    digester.addSetNext("*/mailserver", "setMailSessionConfig", "net.jetrix.config.MailSessionConfig");
    digester.addCallMethod("*/mailserver", "setHostname", 1);
    digester.addCallParam("*/mailserver", 0, "host");
    digester.addCallMethod("*/mailserver", "setPort", 1, new Class[] { Integer.TYPE });
    digester.addCallParam("*/mailserver", 0, "port");
    digester.addCallMethod("*/mailserver", "setAuth", 1, new Class[] { Boolean.TYPE });
    digester.addCallParam("*/mailserver", 0, "auth");
    digester.addCallMethod("*/mailserver", "setUsername", 1);
    digester.addCallParam("*/mailserver", 0, "username");
    digester.addCallMethod("*/mailserver", "setPassword", 1);
    digester.addCallParam("*/mailserver", 0, "password");
    digester.addCallMethod("*/mailserver", "setDebug", 1, new Class[] { Boolean.TYPE });
    digester.addCallParam("*/mailserver", 0, "debug");

    // extended properties
    digester.addCallMethod("*/properties/property", "setProperty", 2);
    digester.addCallParam("*/properties/property", 0, "name");
    digester.addCallParam("*/properties/property", 1, "value");
}

From source file:com.alibaba.antx.config.descriptor.ConfigDescriptorLoader.java

/** ?validators.xmlvalidator */
private Digester loadValidatorPlugins() {
    Digester digester = new Digester();

    digester.setRules(new PluginRules());

    digester.addObjectCreate("config-property-validators", HashMap.class);

    digester.addCallMethod("config-property-validators/validator", "put", 2);
    digester.addCallParam("config-property-validators/validator", 0, "id");
    digester.addCallParam("config-property-validators/validator", 1, "class");

    digester.addRule("config-property-validators/validator", new PluginDeclarationRule());

    InputStream istream = getClass().getResourceAsStream("validators.xml");

    try {//from w  w w .  ja v  a  2  s  . c o  m
        digester.push(digester.parse(istream));
    } catch (Exception e) {
        throw new ConfigException("Failed to load validators", e);
    } finally {
        if (istream != null) {
            try {
                istream.close();
            } catch (IOException e) {
            }
        }
    }

    digester.getRules().clear();

    return digester;
}

From source file:com.nec.nsgui.model.biz.framework.menu.NSMenuFactory.java

/**
 * parse the inputStream and create NSMenusBean object.
 * @param inputStream//  ww w  .j  a  v  a 2 s.c  om
 * @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:net.sibcolombia.sibsp.model.factory.ExtensionFactory.java

/**
 * Builds an extension from the supplied input stream.
 * /*w  w w .j  av  a2s . c  o  m*/
 * @param is For the XML
 * @return The extension
 */
public Extension build(InputStream is) throws IOException, SAXException, ParserConfigurationException {

    // in order to deal with arbitrary namespace prefixes we need to parse namespace aware!
    Digester digester = new Digester(saxf.newSAXParser());
    digester.setRuleNamespaceURI(EXTENSION_NAMESPACE);

    Extension e = new Extension();
    digester.push(e);

    digester.addCallMethod("*/extension", "setTitle", 1);
    digester.addRule("*/extension", new CallParamNoNSRule(0, "title"));

    digester.addCallMethod("*/extension", "setName", 1);
    digester.addCallParam("*/extension", 0, "name");

    digester.addCallMethod("*/extension", "setNamespace", 1);
    digester.addCallParam("*/extension", 0, "namespace");

    digester.addCallMethod("*/extension", "setRowType", 1);
    digester.addCallParam("*/extension", 0, "rowType");

    digester.addCallMethod("*/extension", "setLink", 1);
    digester.addRule("*/extension", new CallParamNoNSRule(0, "relation"));

    digester.addCallMethod("*/extension", "setDescription", 1);
    digester.addRule("*/extension", new CallParamNoNSRule(0, "description"));

    digester.addCallMethod("*/extension", "setSubject", 1);
    digester.addRule("*/extension", new CallParamNoNSRule(0, "subject"));

    // build the properties
    digester.addObjectCreate("*/property", ExtensionProperty.class);

    digester.addCallMethod("*/property", "setQualname", 1);
    digester.addCallParam("*/property", 0, "qualName");

    digester.addCallMethod("*/property", "setName", 1);
    digester.addCallParam("*/property", 0, "name");

    digester.addCallMethod("*/property", "setNamespace", 1);
    digester.addCallParam("*/property", 0, "namespace");

    digester.addCallMethod("*/property", "setGroup", 1);
    digester.addCallParam("*/property", 0, "group");

    digester.addCallMethod("*/property", "setRequired", 1);
    digester.addCallParam("*/property", 0, "required");

    digester.addCallMethod("*/property", "setLink", 1);
    digester.addRule("*/property", new CallParamNoNSRule(0, "relation"));

    digester.addCallMethod("*/property", "setDescription", 1);
    digester.addRule("*/property", new CallParamNoNSRule(0, "description"));

    digester.addCallMethod("*/property", "setExamples", 1);
    digester.addCallParam("*/property", 0, "examples");

    digester.addCallMethod("*/property", "setType", 1);
    digester.addCallParam("*/property", 0, "type");

    // This is a special rule that will use the url2ThesaurusMap
    // to set the Vocabulary based on the attribute "thesaurus"
    digester.addRule("*/property", thesaurusRule);

    digester.addSetNext("*/property", "addProperty");

    digester.parse(is);

    return e;
}

From source file:com.coroptis.coidi.core.services.impl.ConfigurationServiceImpl.java

/**
 * Creates {@link Properties} instance. Properties are read from the
 * specified XML file and XML elements.//  ww w.  j av  a  2 s. co m
 * 
 * @param configurationSection
 *            pattern that matches an element in configuration
 * @param resourceUrl
 *            specifies where configuration file is located
 * @return Map loaded from XML configuration file
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private HashMap<String, String> createProperties(String configurationSection, Resource configurationResource) {
    Digester digester = new Digester();
    digester.addObjectCreate("configuration/" + configurationSection, HashMap.class);
    // TODO refactor it, add test
    // call the put method on the top object on the digester stack
    // passing the key attribute as the 0th parameterw
    // and the element body text as the 1th parameter..
    digester.addCallMethod("configuration/" + configurationSection + "/property", "put", 2);
    digester.addCallParam("configuration/" + configurationSection + "/property", 0, "name");
    digester.addCallParam("configuration/" + configurationSection + "/property", 1);

    InputStream inputStream = null;
    HashMap properties = null;
    try {
        inputStream = configurationResource.openStream();
        properties = (HashMap) digester.parse(inputStream);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    } catch (SAXException e) {
        logger.error(e.getMessage(), e);
    } finally {
        try {
            if (inputStream != null) {
                inputStream.close();
            }
        } catch (IOException e) {
            logger.warn("Unable to close input stream after reading configuration file.");
        }
    }
    return properties;
}

From source file:com.npower.dm.setup.task.ModelFetchTask.java

protected Digester createManufacturerDigester() {
    // Initialize the digester
    Digester digester = new Digester();
    digester.setValidating(false);/*from  ww w  . ja v  a2s. co  m*/

    // Model stage
    digester.addObjectCreate("*/Models/Model", ModelFetchItem.class);
    digester.addSetNext("*/Models/Model", "add");

    // Basic information
    digester.addBeanPropertySetter("*/Models/Model/ExternalID", "externalID");
    digester.addBeanPropertySetter("*/Models/Model/Manufacturer", "manufacturerExternalID");
    // Specifications
    digester.addCallMethod("*/Models/Model/Specifications/Specification", "setSpecification", 3);
    digester.addCallParam("*/Models/Model/Specifications/Specification", 0, "category");
    digester.addCallParam("*/Models/Model/Specifications/Specification", 1, "name");
    digester.addCallParam("*/Models/Model/Specifications/Specification", 2, "value");

    return (digester);
}