当前位置: 首页>>代码示例>>Java>>正文


Java Digester.parse方法代码示例

本文整理汇总了Java中org.apache.commons.digester3.Digester.parse方法的典型用法代码示例。如果您正苦于以下问题:Java Digester.parse方法的具体用法?Java Digester.parse怎么用?Java Digester.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.digester3.Digester的用法示例。


在下文中一共展示了Digester.parse方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import org.apache.commons.digester3.Digester; //导入方法依赖的package包/类
/**
 * <p>Parse the XML document at the specified URL using the configured
 * <code>RuleSet</code>, registering catalogs with nested chains and
 * commands as they are encountered.  Use this method <strong>only</strong>
 * if you have included one or more <code>factory</code> elements in your
 * configuration resource.</p>
 *
 * @param <K> the type of keys maintained by the context associated with this command
 * @param <V> the type of mapped values
 * @param <C> Type of the context associated with this command
 * @param url <code>URL</code> of the XML document to be parsed
 * @return a CatalogFactory instance parsed from the given location
 * @exception ChainConfigurationException if a parsing error occurs
 */
public <K extends String, V extends Object, C extends Map<K, V>> CatalogFactory<K, V, C> parse(URL url) {
    // Prepare our Digester instance
    Digester digester = getDigester();
    digester.clear();

    // Parse the configuration document
    try {
        digester.parse(url);
    } catch (Exception e) {
        String msg = String.format(
                "Error parsing digester configuration at url: %s",
                url);
        throw new ChainConfigurationException(msg, e);
    }
    // FIXME get rid of singleton pattern and create a new instance here
    return CatalogFactoryBase.getInstance();
}
 
开发者ID:Dotosoft,项目名称:dot4command-core,代码行数:32,代码来源:XmlConfigParser.java

示例2: testLoadRules

import org.apache.commons.digester3.Digester; //导入方法依赖的package包/类
/**
 * JAVADOC Method Level Comments
 *
 * @throws Exception JAVADOC.
 */
@Test
public void testLoadRules()
    throws Exception {
    Resource rulesResource = new InputStreamResource(new ByteArrayInputStream(
                SIMPLE_RULES.getBytes()));
    DigesterRulesModule module = new DigesterRulesModule(rulesResource);
    DigesterLoader loader = DigesterLoader.newLoader(module);
    Digester digester = loader.newDigester();

    digester.push(new Container());

    Container cont = digester.parse(new StringReader(SIMPLE_DATA));

    assertNotNull("Container is null", cont);
    assertNotNull("startState is null", cont.getStartState());
}
 
开发者ID:cucina,项目名称:opencucina,代码行数:22,代码来源:DigesterRulesModuleTest.java

示例3: loadProfile

import org.apache.commons.digester3.Digester; //导入方法依赖的package包/类
public static Profiles loadProfile(ProbeContext context, File inputFile){
		Profiles retVal = null;
		if(inputFile.exists()){
			System.out.println("Loading profile from["+inputFile.getAbsolutePath()+"]");
		    try {
		        Digester digester = getDigester();
		        retVal = (Profiles)digester.parse( inputFile );
		      } catch( Exception exc ) {
		        exc.printStackTrace();
		      }
		} else {
//			Logger.getRootLogger().debug("File does not exist["+inputFile.getAbsolutePath()+"]");
			System.out.println("File does not exist["+inputFile.getAbsolutePath()+"]");
		}
	    return retVal;
	}
 
开发者ID:PRTG,项目名称:JMXMiniProbe,代码行数:17,代码来源:ProfileFactory.java

示例4: read

import org.apache.commons.digester3.Digester; //导入方法依赖的package包/类
/**
 * Read from the
 * <code>input</code> and return it's configuration settings as a
 * {@link Map}.
 *
 * @param 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 SAXException
 * @throws IOException
 * @throws ConfigReadException
 */
public List<Profile> read(File normalizedFile) throws IOException, SAXException, ConfigReadException {
    Digester digester = new Digester();
    digester.addRuleSet(new RuleSet());
    Object result = null;
    InputStream configInput = FileUtil.toFileObject(normalizedFile).getInputStream();
    try {
        result = digester.parse(configInput);
    } finally {
        try {
            configInput.close();
        } catch (IOException e) {
        }
    }
    if (result == null && !(result instanceof Profiles)) {
        throw new ConfigReadException("No profiles found in config file");
    }
    Profiles profiles = (Profiles) result;
    return profiles.getProfiles();
}
 
开发者ID:markiewb,项目名称:eclipsecodeformatter_for_netbeans,代码行数:33,代码来源:ConfigReader.java

示例5: read

import org.apache.commons.digester3.Digester; //导入方法依赖的package包/类
/**
 * Parses XML config of QSAdmin Plugin
 */
public static QSAdminPluginConfig read(File input) throws Exception {
	Digester digester = new Digester();
    digester.setValidating(false);

	String mainTag = "qsadmin-plugin";
	
	digester.addObjectCreate(mainTag, QSAdminPluginConfig.class);
	digester.addBeanPropertySetter(mainTag+"/name", "name");
	digester.addBeanPropertySetter(mainTag+"/desc", "desc");
	digester.addBeanPropertySetter(mainTag+"/type", "type");
	digester.addBeanPropertySetter(mainTag+"/main-class", "mainClass");
	digester.addBeanPropertySetter(mainTag+"/active", "active");
	

	logger.fine("Loading Plugin config from xml file : " + input.getAbsolutePath());
	QSAdminPluginConfig psc = (QSAdminPluginConfig) digester.parse(input);
	return psc;
}
 
开发者ID:QuickServerLab,项目名称:QuickServer-Main,代码行数:22,代码来源:PluginConfigReader.java

示例6: parseXMLObject

import org.apache.commons.digester3.Digester; //导入方法依赖的package包/类
public static Object parseXMLObject(final Class clazz, Resource resource) throws RuntimeException {

        try {
            InputSource inputSource;
            Digester digester;
            java.io.InputStream is = resource.getInputStream();
            inputSource = new InputSource(is);
            DigesterLoader loader = newLoader(new FromAnnotationsRuleModule() {

                @Override
                protected void configureRules() {

                    bindRulesFrom(clazz);
                }

            });

            digester = loader.newDigester();
            return digester.parse(inputSource);
        } catch (Exception e) {
            log.error(
                    String.format("Fail to transfer Java Object[class: {" + clazz.getSimpleName() + "}] from {" + resource + "}, reason: "),
                    e);
            e.printStackTrace();
            throw new RuntimeException((new StringBuilder()).append("Fail to parse XML Object of ").append(resource).toString(), e);
        }
    }
 
开发者ID:bill1012,项目名称:AdminEAP,代码行数:28,代码来源:ConfigurationUtil.java

示例7: getSimpleCommands

import org.apache.commons.digester3.Digester; //导入方法依赖的package包/类
public static SimpleCommandSet getSimpleCommands() {
	SimpleCommandSet sms = null;
	try {
        Digester digester = new Digester();
	    digester.setValidating(false);
		//digester.setNamespaceAware(true);
		//String xsd = "" + new File("quickserver_config.xsd").toURI();
		//digester.setSchema(xsd);

		//nested QSAdminServer tag
		String mainTag = "simple-command-set";
		String subTag = "simple-command";
		digester.addObjectCreate(mainTag, SimpleCommandSet.class);
		digester.addObjectCreate(mainTag+"/"+subTag, SimpleCommand.class);
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/name");
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/command");
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/desc");
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/target-needed", "targetNeeded");
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/multi-line-response", "multiLineResponse");
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/version");
		digester.addSetNext(mainTag+"/"+subTag,"addCommand");
		URL configFile = 
			SimpleCommandSet.class.getResource("/org/quickserver/net/qsadmin/gui/conf/MainCommandPanel.xml");
		if(configFile==null)
			throw new RuntimeException("XML File not found : "+"MainCommandPanel.xml");

		InputStream input = configFile.openStream();
		logger.fine("Loading command config from xml file : " + input);
		sms = (SimpleCommandSet) digester.parse(input);			
	} catch(Exception e) {
		logger.severe("Could not init from xml file : " +e);
		logger.fine("StackTrace:\n"+MyString.getStackTrace(e));
	}
	return sms;
}
 
开发者ID:QuickServerLab,项目名称:QuickServer-Main,代码行数:36,代码来源:SimpleCommandSet.java

示例8: getPropertieSet

import org.apache.commons.digester3.Digester; //导入方法依赖的package包/类
public static PropertieSet getPropertieSet() {
	PropertieSet ps = null;
	try {
        Digester digester = new Digester();
	    digester.setValidating(false);
		//digester.setNamespaceAware(true);
		//String xsd = "" + new File("quickserver_config.xsd").toURI();
		//digester.setSchema(xsd);

		//nested QSAdminServer tag
		String mainTag = "propertie-set";
		String subTag = "propertie";
		digester.addObjectCreate(mainTag, PropertieSet.class);
		digester.addObjectCreate(mainTag+"/"+subTag, Propertie.class);
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/name");
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/command");
		digester.addCallMethod(mainTag+"/"+subTag+"/get", "setGet",0);
		digester.addCallMethod(mainTag+"/"+subTag+"/set", "setSet",0);
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/type");
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/desc");
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/select");
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/target-needed", "targetNeeded");
		digester.addBeanPropertySetter(mainTag+"/"+subTag+"/version");
		digester.addSetNext(mainTag+"/"+subTag,"addCommand");

		URL configFile = 
			PropertieSet.class.getResource("/org/quickserver/net/qsadmin/gui/conf/PropertieSet.xml");
		if(configFile==null)
			throw new RuntimeException("XML File not found : "+"PropertieSet.xml");

		InputStream input = configFile.openStream();			
		logger.fine("Loading command config from xml file : " + input);
		ps = (PropertieSet) digester.parse(input);			
	} catch(Exception e) {
		logger.severe("Could not init from xml file : " +e);
		logger.fine("StackTrace:\n"+MyString.getStackTrace(e));
	}
	return ps;
}
 
开发者ID:QuickServerLab,项目名称:QuickServer-Main,代码行数:40,代码来源:PropertieSet.java

示例9: build

import org.apache.commons.digester3.Digester; //导入方法依赖的package包/类
/**
 * Builds a Vocabulary from the supplied input stream
 *
 * @param is For the XML
 * @return The extension
 * @throws SAXException
 * @throws IOException
 * @throws ParserConfigurationException
 */
public Vocabulary build(InputStream is) throws IOException, SAXException, ParserConfigurationException {
  Digester digester = new Digester(saxf.newSAXParser());
  digester.setNamespaceAware(true);
  digester.setXIncludeAware(false);
  digester.setRuleNamespaceURI(VOCABULARY_NAMESPACE);

  Vocabulary tv = new Vocabulary();
  digester.push(tv);

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

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

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

  digester.addCallMethod("*/thesaurus", "setUri", 1);
  digester.addRule("*/thesaurus", new CallParamNoNSRule(0, "URI"));

  // build the concept
  digester.addObjectCreate("*/concept", VocabularyConcept.class);

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

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

  digester.addCallMethod("*/concept", "setUri", 1);
  digester.addRule("*/concept", new CallParamNoNSRule(0, "URI"));

  digester.addCallMethod("*/concept", "setIdentifier", 1);
  digester.addRule("*/concept", new CallParamNoNSRule(0, "identifier"));

  // build the terms
  digester.addObjectCreate("*/preferred/term", VocabularyTerm.class);
  VocabularyTerm t = new VocabularyTerm();

  digester.addCallMethod("*/preferred/term", "setLang", 1);
  digester.addRule("*/preferred/term", new CallParamNoNSRule(0, "lang"));

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

  digester.addSetNext("*/preferred/term", "addPreferredTerm");

  // build alternative terms
  digester.addObjectCreate("*/alternative/term", VocabularyTerm.class);
  VocabularyTerm talt = new VocabularyTerm();

  digester.addCallMethod("*/alternative/term", "setLang", 1);
  digester.addRule("*/alternative/term", new CallParamNoNSRule(0, "lang"));

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

  digester.addSetNext("*/alternative/term", "addAlternativeTerm");

  // add concept
  digester.addSetNext("*/concept", "addConcept");

  digester.parse(is);
  return tv;
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:77,代码来源:VocabularyFactory.java

示例10: build

import org.apache.commons.digester3.Digester; //导入方法依赖的package包/类
/**
 * Builds an extension from the supplied input stream
 *
 * @param is For the XML
 * @return The extension
 * @throws SAXException
 * @throws IOException
 * @throws ParserConfigurationException
 */
public Extension build(InputStream is, URL url, boolean dev) 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(url, dev);
  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", "setType", 1);
  digester.addCallParam("*/property", 0, "type");

  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", "setColumnLength", 1);
  digester.addCallParam("*/property", 0, "columnLength");

  // 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;
}
 
开发者ID:gbif,项目名称:dwca-io,代码行数:82,代码来源:ExtensionFactory.java

示例11: parseSchema

import org.apache.commons.digester3.Digester; //导入方法依赖的package包/类
public EntitySchema parseSchema(InputStream inputStream) throws IOException, SAXException {
    Digester digester = createDigester();
    return digester.parse(inputStream);
}
 
开发者ID:SimonXianyu,项目名称:codefather,代码行数:5,代码来源:EntitySchemaParser.java

示例12: createServerList

import org.apache.commons.digester3.Digester; //导入方法依赖的package包/类
/**
 * Creates the rules.
 * 
 * @return The rules all put into a rule chain
 */
private LinkedList createServerList(File data) throws Exception {
    Digester digester = new Digester();
    digester.setUseContextClassLoader(true);

    // Construct server list
    digester.addObjectCreate("config", LinkedList.class);

    // Create servers
    digester.addObjectCreate("config/server", null, "className");
    digester.addSetProperties("config/server");
    // Create rule
    digester.addObjectCreate("config/server/rule", null, "className");
    digester.addSetProperties("config/server/rule");
    digester.addSetNext("config/server/rule", "setRule");
    // Create composite rule
    digester.addObjectCreate("config/server/composite-rule", null,
            "className");
    digester.addSetProperties("config/server/composite-rule");
    digester.addObjectCreate("config/server/composite-rule/rule", null,
            "className");
    digester.addSetProperties("config/server/composite-rule/rule");
    digester.addSetNext("config/server/composite-rule/rule", "addRule");
    digester.addSetNext("config/server/composite-rule", "setRule");
    // Add server to list
    digester.addSetNext("config/server", "add");

    // Create cluster servers
    digester.addObjectCreate("config/cluster-server", null, "className");
    digester.addSetProperties("config/cluster-server");
    // Create the servers in this cluster
    digester.addCallMethod("config/cluster-server/server", "addServer", 2);
    digester.addCallParam("config/cluster-server/server", 0, "domainName");
    digester.addCallParam("config/cluster-server/server", 1, "path");
    // Create rule
    digester.addObjectCreate("config/cluster-server/rule", null,
            "className");
    digester.addSetProperties("config/cluster-server/rule");
    digester.addSetNext("config/cluster-server/rule", "setRule");
    // Create composite rule
    digester.addObjectCreate("config/cluster-server/composite-rule", null,
            "className");
    digester.addSetProperties("config/cluster-server/composite-rule");
    digester.addObjectCreate("config/cluster-server/composite-rule/rule",
            null, "className");
    digester.addSetProperties("config/cluster-server/composite-rule/rule");
    digester.addSetNext("config/cluster-server/composite-rule/rule",
            "addRule");
    digester.addSetNext("config/cluster-server/composite-rule", "setRule");

    // Add server to list
    digester.addSetNext("config/cluster-server", "add");

    return (LinkedList) digester.parse(data);
}
 
开发者ID:dengzhizhi,项目名称:J2EP,代码行数:60,代码来源:ConfigParser.java


注:本文中的org.apache.commons.digester3.Digester.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。