當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。