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


Java XMLConfiguration.getProperty方法代码示例

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


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

示例1: getHierarchicalExample

import org.apache.commons.configuration.XMLConfiguration; //导入方法依赖的package包/类
/**
 * 获取树状结构数据
 */
public void getHierarchicalExample() {

    try {
        XMLConfiguration config = new XMLConfiguration("properties-website-job.xml");
        log.info(config.getFileName());
        //   log.info(config.getStringByEncoding("jdbc.oracle.work.235.url", "GBK"));

        //包含 websites.site.name 的集合
        Object prop = config.getProperty("websites.site.name");

        if (prop instanceof Collection) {
            //  System.out.println("Number of tables: " + ((Collection<?>) prop).size());
            Collection<String> c = (Collection<String>) prop;
            int i = 0;

            for (String s : c) {

                System.out.println("sitename :" + s);

                List<HierarchicalConfiguration> fields = config.configurationsAt("websites.site(" + String.valueOf(i) + ").fields.field");
                for (HierarchicalConfiguration sub : fields) {
                    // sub contains all data about a single field
                    //此处可以包装成 bean
                    String name = sub.getString("name");
                    String type = sub.getString("type");
                    System.out.println("name :" + name + " , type :" + type);
                }

                i++;
                System.out.println(" === ");
            }
        }
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }


}
 
开发者ID:h819,项目名称:spring-boot,代码行数:42,代码来源:MyConfigurationXMLUtils.java

示例2: getPolicyParameter

import org.apache.commons.configuration.XMLConfiguration; //导入方法依赖的package包/类
protected Object getPolicyParameter(XMLConfiguration config, int currentRule)
		throws ClassNotFoundException, IllegalAccessException, InstantiationException, Exception {
		//If there aren't any properties: short circuit and return null.
//		Properties tempParameters = config.getProperties("AccessControlRules.AccessControlRule(" + currentRule + ").Parameters.Parameter[@name]");
		Object property = config.getProperty("AccessControlRules.AccessControlRule(" + currentRule + ").Parameters.Parameter[@name]");
		if(property == null) {
			return null;
		}
		
		int numberOfProperties = 0;		
		if(property instanceof Collection) {
			numberOfProperties = ((Collection)property).size(); 
		} else {
			numberOfProperties = 1;
		}
		logger.info(Logger.EVENT_SUCCESS, "Number of properties: " + numberOfProperties);
		
		if(numberOfProperties < 1) {
			return null;
		}
		String parametersLoaderClassName = config.getString("AccessControlRules.AccessControlRule(" + currentRule + ").Parameters[@parametersLoader]");
		if("".equals(parametersLoaderClassName) || parametersLoaderClassName == null) {
			//this default should have a properties file override option
			parametersLoaderClassName = "org.owasp.esapi.reference.accesscontrol.policyloader.DynaBeanACRParameterLoader";
		}
		logger.info(Logger.EVENT_SUCCESS, "Parameters Loader:" + parametersLoaderClassName);
		ACRParameterLoader acrParamaterLoader = 
			(ACRParameterLoader)
			Class.forName(parametersLoaderClassName).newInstance();
		return acrParamaterLoader.getParameters(config, currentRule);		
	}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:32,代码来源:ACRPolicyFileLoader.java


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