Java 类org.apache.commons.configuration.DefaultConfigurationBuilder 实例源码

项目:atf-toolbox-java    文件:ConfigurationManager.java   
private void loadConfiguration() {
    Properties sysProps = System.getProperties();
    String configFileName = sysProps.getProperty("test.config.filename");

    if (StringUtils.isEmpty(configFileName)) {
        configFileName = defaultConfigurationFileName;
    }

    try {
        AllConfiguration = new DefaultConfigurationBuilder(configFileName).getConfiguration();
        ((HierarchicalConfiguration) AllConfiguration).setExpressionEngine(new XPathExpressionEngine());
    } catch (Exception e) {
        Fail.fail("failed to read config file", e);
        log.error("Failed to read config file", e);
    }
}
项目:cloudstorage    文件:CloudStorageTest.java   
@BeforeClass
public static void setup() {
    Configuration config = null;
    try {
        DefaultConfigurationBuilder configBuilder = new DefaultConfigurationBuilder("config.xml");
        config = configBuilder.getConfiguration();
    } catch (ConfigurationException e) {
        log.error("Error reading config file", e);
        fail("error reading config file");
    }
    storage = new S3CloudStorage(
            new BasicAWSCredentials(
                    config.getString("s3.accesskey"),
                    config.getString("s3.secretkey")),
            new BasicAWSCredentials(
                    config.getString("s3.urlgen.accesskey"),
                    config.getString("s3.urlgen.secretkey")),
            Regions.fromName(config.getString("s3.bucket.region")));
    bucketName = config.getString("s3.bucket");
    assertNotNull("bucketName is null", bucketName);
}
项目:metron    文件:ConfigurationManager.java   
/**
 * Common method to load content of all configuration resources defined in
 * 'config-definition.xml'.
 * 
 * @param configDefFilePath
 *          the config def file path
 * @return Configuration
 */
public static Configuration getConfiguration(String configDefFilePath) {
  if (configurationsCache.containsKey(configDefFilePath)) {
    return configurationsCache.get(configDefFilePath);
  }
  CombinedConfiguration configuration = null;
  synchronized (configurationsCache) {
    if (configurationsCache.containsKey(configDefFilePath)) {
      return configurationsCache.get(configDefFilePath);
    }
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
    String filePath = getConfigDefFilePath(configDefFilePath);
    LOGGER.info("loading from 'configDefFilePath' : {}", filePath);
    builder.setFile(new File(filePath));
    try {
      configuration = builder.getConfiguration(true);
      configurationsCache.put(filePath, configuration);
    } catch (ConfigurationException|ConfigurationRuntimeException e) {
      LOGGER.info("Exception in loading property files.", e);
    }
  }
  return configuration;
}
项目:opensoc-streaming    文件:ConfigurationManager.java   
/**
 * Common method to load content of all configuration resources defined in
 * 'config-definition.xml'.
 * 
 * @param configDefFilePath
 *          the config def file path
 * @return Configuration
 */
public static Configuration getConfiguration(String configDefFilePath) {
  if (configurationsCache.containsKey(configDefFilePath)) {
    return configurationsCache.get(configDefFilePath);
  }
  CombinedConfiguration configuration = null;
  synchronized (configurationsCache) {
    if (configurationsCache.containsKey(configDefFilePath)) {
      return configurationsCache.get(configDefFilePath);
    }
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
    String fielPath = getConfigDefFilePath(configDefFilePath);
    LOGGER.info("loading from 'configDefFilePath' :" + fielPath);
    builder.setFile(new File(fielPath));
    try {
      configuration = builder.getConfiguration(true);
      configurationsCache.put(fielPath, configuration);
    } catch (ConfigurationException e) {
      LOGGER.info("Exception in loading property files.", e);
    }
  }
  return configuration;
}
项目:James    文件:JDBCMailRepositoryTest.java   
/**
 * @return
 * @throws ServiceException
 * @throws ConfigurationException
 * @throws Exception
 */
protected MailRepository getMailRepository() throws Exception {
    MockFileSystem fs = new MockFileSystem();
    DataSource datasource = getDataSource();
    JDBCMailRepository mr = new JDBCMailRepository();

    DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder();
    defaultConfiguration.addProperty("[@destinationURL]", "db://maildb/mr/testrepo");
    defaultConfiguration.addProperty("sqlFile", "file://conf/sqlResources.xml");
    defaultConfiguration.addProperty("[@type]", "MAIL");
    mr.setFileSystem(fs);
    mr.setDatasource(datasource);
    mr.setLog(LoggerFactory.getLogger("MockLog"));
    mr.configure(defaultConfiguration);
    mr.init();
    return mr;
}
项目:James    文件:DNSJavaServiceTest.java   
protected void setUp() throws Exception {
    dnsServer = new TestableDNSServer();
    DefaultConfigurationBuilder db = new DefaultConfigurationBuilder();

    db.load(new ByteArrayInputStream("<dnsserver><autodiscover>true</autodiscover><authoritative>false</authoritative></dnsserver>".getBytes()));
    dnsServer.setLog(LoggerFactory.getLogger("MockLog"));
    dnsServer.configure(db);
    dnsServer.init();

    defaultCache = Lookup.getDefaultCache(DClass.IN);
    defaultResolver = Lookup.getDefaultResolver();
    defaultSearchPaths = Lookup.getDefaultSearchPath();
    Lookup.setDefaultCache(null, DClass.IN);
    Lookup.setDefaultResolver(null);
    Lookup.setDefaultSearchPath(new Name[] {});
}
项目:James    文件:AbstractStateCompositeProcessorTest.java   
private HierarchicalConfiguration createConfig(List<String> states) throws ConfigurationException {

        StringBuilder sb = new StringBuilder();
        sb.append("<?xml version=\"1.0\"?>");
        sb.append("<processors>");
        for (int i = 0 ; i < states.size(); i++) {
            sb.append("<processor state=\"");
            sb.append(states.get(i));
            sb.append("\"/>");
        }
        sb.append("</processors>");

        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
        builder.load(new ByteArrayInputStream(sb.toString().getBytes()));
        return builder;
    }
项目:James    文件:MailetConfigImplTest.java   
public void testParamWithXmlSpace() throws ConfigurationException {
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
    builder.setDelimiterParsingDisabled(true);
    builder.load(new ByteArrayInputStream("<mailet><whatever xml:space=\"preserve\"> some text </whatever></mailet>".getBytes()));

    MailetConfigImpl config = new MailetConfigImpl();
    config.setConfiguration(builder);

    String param = config.getInitParameterNames().next();
    assertEquals("whatever", param);
    assertEquals(" some text ", config.getInitParameter(param));

    List<String> parms = new ArrayList<String>();
    Iterator<String> iter = config.getInitParameterNames();
    while (iter.hasNext())
    {
        parms.add(iter.next());
    }
    assertEquals(parms.size(), 1);             
}
项目:James    文件:UsersFileRepository.java   
@PostConstruct
public void init() throws Exception {
    try {
        // TODO Check how to remove this!
        // prepare Configurations for object and stream repositories
        final DefaultConfigurationBuilder objectConfiguration = new DefaultConfigurationBuilder();

        objectConfiguration.addProperty("[@destinationURL]", destination);

        objectRepository = new FilePersistentObjectRepository();
        objectRepository.setLog(getLogger());
        objectRepository.setFileSystem(fs);
        objectRepository.configure(objectConfiguration);
        objectRepository.init();
        if (getLogger().isDebugEnabled()) {
            StringBuffer logBuffer = new StringBuffer(192).append(this.getClass().getName()).append(" created in ").append(destination);
            getLogger().debug(logBuffer.toString());
        }
    } catch (Exception e) {
        if (getLogger().isErrorEnabled()) {
            getLogger().error("Failed to initialize repository:" + e.getMessage(), e);
        }
        throw e;
    }
}
项目:James    文件:MBoxMailRepositoryTest.java   
protected MailRepository getMailRepository() throws Exception {
    MBoxMailRepository mr = new MBoxMailRepository();

    DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder();

    File fInbox = new MockFileSystem().getFile("file://conf/org/apache/james/mailrepository/testdata/Inbox");
    String mboxPath = "mbox://" + fInbox.toURI().toString().substring(new File("").toURI().toString().length());

    defaultConfiguration.addProperty("[@destinationURL]", mboxPath);
    defaultConfiguration.addProperty("[@type]", "MAIL");
    mr.setLog(LoggerFactory.getLogger("MockLog"));
    ;
    mr.configure(defaultConfiguration);

    return mr;
}
项目:hotwind    文件:AppConfig.java   
public static synchronized Configuration load() {
    if (loaded == null) {
        DefaultConfigurationBuilder configBuilder = new DefaultConfigurationBuilder();
        URL url = AppConfig.class.getClassLoader().getResource(
                "app-config-files.xml");
        configBuilder.setURL(url);
        try {
            loaded = configBuilder.getConfiguration(true);
        } catch (ConfigurationException e) {
            logger.warn(
                    "load 'app-config-files.xml' failed, this will use a empty properties.",
                    e);
            loaded = new PropertiesConfiguration();
        }
    }
    return loaded;
}
项目:floe2    文件:FloeConfig.java   
/**
 * To retrieve the config object.
 * FIXME: This is not a Thread Safe Function (for the first initialization)
 *
 * @return Fully initialized configuration object
 * (instance of Apache Commons Configuration)
 */
public static Configuration getConfig() {
    if (config == null) {
        DefaultConfigurationBuilder builder =
                new DefaultConfigurationBuilder();
        builder.setFile(new File("config.xml"));
        try {
            config = builder.getConfiguration(true);
        } catch (ConfigurationException e) {
            throw new RuntimeException(
                    "Missing configuration description file.");
        }
    }
    return config;
}
项目:James    文件:JDBCRecipientRewriteTableTest.java   
/**
 * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest#getRecipientRewriteTable()
 */
protected AbstractRecipientRewriteTable getRecipientRewriteTable() throws Exception {
    JDBCRecipientRewriteTable virtualUserTable = new JDBCRecipientRewriteTable();
    virtualUserTable.setLog(LoggerFactory.getLogger("MockLog"));
    virtualUserTable.setDataSource(getDataSource());
    virtualUserTable.setFileSystem(new MockFileSystem());
    DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder();
    defaultConfiguration.addProperty("[@destinationURL]", "db://maildb/RecipientRewriteTable");
    defaultConfiguration.addProperty("sqlFile", "file://conf/sqlResources.xml");
    virtualUserTable.configure(defaultConfiguration);
    virtualUserTable.init();
    return virtualUserTable;
}
项目:James    文件:DefaultUsersJdbcRepositoryTest.java   
/**
 * @param res
 * @param tableString
 * @throws Exception
 * @throws ConfigurationException
 */
protected void configureAbstractJdbcUsersRepository(AbstractJdbcUsersRepository res, String tableString) throws Exception, ConfigurationException {
    res.setFileSystem(new MockFileSystem());
    DataSource dataSource = getDataSource();

    res.setDatasource(dataSource);

    DefaultConfigurationBuilder configuration = new DefaultConfigurationBuilder();
    configuration.addProperty("[@destinationURL]", "db://maildb/" + tableString);
    configuration.addProperty("sqlFile", "file://conf/sqlResources.xml");
    res.setLog(LoggerFactory.getLogger("MockLog"));
    res.configure(configuration);
    res.init();
}
项目:James    文件:JamesUsersJdbcRepositoryTest.java   
/**
 * @param res
 * @param tableString
 * @throws Exception
 * @throws ConfigurationException
 */
protected void configureAbstractJdbcUsersRepository(AbstractJdbcUsersRepository res, String tableString) throws Exception, ConfigurationException {
    res.setFileSystem(new MockFileSystem());
    DataSource dataSource = getDataSource();
    res.setDatasource(dataSource);
    DefaultConfigurationBuilder configuration = new DefaultConfigurationBuilder();
    configuration.addProperty("[@destinationURL]", "db://maildb/" + tableString);
    configuration.addProperty("sqlFile", "file://conf/sqlResources.xml");
    res.setLog(LoggerFactory.getLogger("MockLog"));
    res.configure(configuration);
    res.init();
}
项目:James    文件:JcrUserRepositoryTest.java   
protected UsersRepository getUsersRepository() throws Exception {
    JCRUsersRepository repos = new JCRUsersRepository();
    repos.setRepository(repository);
    DefaultConfigurationBuilder config = new DefaultConfigurationBuilder();
    config.addProperty("username", "admin");
    config.addProperty("password", "test");
    repos.configure(config);
    repos.setLog(LoggerFactory.getLogger("MockLog"));
    return repos;
}
项目:James    文件:HBaseRecipientRewriteTableTest.java   
/**
 * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest#getRecipientRewriteTable()
 */
@Override
protected AbstractRecipientRewriteTable getRecipientRewriteTable() throws Exception {
    HBaseRecipientRewriteTable rrt = new HBaseRecipientRewriteTable();
    rrt.setLog(LoggerFactory.getLogger("MockLog"));
    rrt.configure(new DefaultConfigurationBuilder());
    return rrt;
}
项目:James    文件:HBaseUsersRepositoryTest.java   
/**
 * @see org.apache.james.user.lib.AbstractUsersRepositoryTest#getUsersRepository()
 */
@Override
protected UsersRepository getUsersRepository() throws Exception {
    HBaseUsersRepository userRepository = new HBaseUsersRepository();
    userRepository.setLog(LoggerFactory.getLogger("MockLog"));
    userRepository.configure(new DefaultConfigurationBuilder());
    return userRepository;
}
项目:James    文件:MailetConfigImpl.java   
/**
 * Set the Avalon Configuration object for the mailet.
 * 
 * @param newConfiguration
 *            the new Configuration for the mailet
 */
@SuppressWarnings("unchecked")
public void setConfiguration(Configuration newConfiguration) {
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();

    // Disable the delimiter parsing. See JAMES-1232
    builder.setDelimiterParsingDisabled(true);
    Iterator<String> keys = newConfiguration.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        String[] values = newConfiguration.getStringArray(key);
        // See JAMES-1177
        // Need to replace ".." with "."
        // See
        // http://commons.apache.org/configuration/userguide-1.2/howto_xml.html
        // Escaping dot characters in XML tags
        key = key.replaceAll("\\.\\.", "\\.");

        // Convert array values to a "," delimited string value
        StringBuilder valueBuilder = new StringBuilder();
        for (int i = 0; i < values.length; i++) {
            valueBuilder.append(values[i]);
            if (i + 1 < values.length) {
                valueBuilder.append(",");
            }
        }
        builder.addProperty(key, valueBuilder.toString());
    }

    configuration = builder;
}
项目:James    文件:AbstractStateMailetProcessorTest.java   
private HierarchicalConfiguration createConfig(Class<?> matcherClass, Class<?> mailetClass, int count) throws ConfigurationException {
    StringBuilder sb = new StringBuilder();
    sb.append("<processor state=\"" + Mail.DEFAULT + "\">");
    sb.append("<mailet match=\"").append(matcherClass.getName()).append("=").append(count).append("\"").append(" class=\"").append(mailetClass.getName()).append("\">");
    sb.append("<state>test</state>");
    sb.append("</mailet>");

    sb.append("</processor>");

    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
    builder.load(new ByteArrayInputStream(sb.toString().getBytes()));
    return builder;
}
项目:James    文件:MailetConfigImplTest.java   
public void testDotParamsFromXML() throws ConfigurationException {
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
    builder.load(new ByteArrayInputStream("<mailet><mail.debug>true</mail.debug></mailet>".getBytes()));

    MailetConfigImpl config = new MailetConfigImpl();
    config.setConfiguration(builder);

    String param = config.getInitParameterNames().next();
    assertEquals("mail.debug", param);
    assertEquals("true", config.getInitParameter(param));
}
项目:James    文件:MailetConfigImplTest.java   
public void testDotParamsFromConfig() throws ConfigurationException {
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
    builder.addProperty("mail.debug", "true");

    MailetConfigImpl config = new MailetConfigImpl();
    config.setConfiguration(builder);

    String param = config.getInitParameterNames().next();
    assertEquals("mail.debug", param);
    assertEquals("true", config.getInitParameter(param));
}
项目:James    文件:MailetConfigImplTest.java   
public void testParamWithComma() throws ConfigurationException {
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
    builder.load(new ByteArrayInputStream("<mailet><whatever>value1,value2</whatever></mailet>".getBytes()));

    MailetConfigImpl config = new MailetConfigImpl();
    config.setConfiguration(builder);

    String param = config.getInitParameterNames().next();
    assertEquals("whatever", param);
    assertEquals("value1,value2", config.getInitParameter(param));
}
项目:James    文件:JPARecipientRewriteTableTest.java   
/**
 * @see org.apache.james.rrt.lib.AbstractRecipientRewriteTableTest#getRecipientRewriteTable()
 */
protected AbstractRecipientRewriteTable getRecipientRewriteTable() throws Exception {
    JPARecipientRewriteTable virtualUserTable = new JPARecipientRewriteTable();
    virtualUserTable.setLog(LoggerFactory.getLogger("MockLog"));
    virtualUserTable.setEntityManagerFactory(factory);
    DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder();
    virtualUserTable.configure(defaultConfiguration);
    return virtualUserTable;
}
项目:James    文件:JpaUsersRepositoryTest.java   
@Override
protected UsersRepository getUsersRepository() throws Exception {
    factory = OpenJPAPersistence.getEntityManagerFactory(properties);
    JPAUsersRepository repos = new JPAUsersRepository();
    repos.setLog(LoggerFactory.getLogger("JPA"));
    repos.setEntityManagerFactory(factory);
    repos.configure(new DefaultConfigurationBuilder());
    return repos;
}
项目:James    文件:UsersFileRepositoryTest.java   
/**
 * Create the repository to be tested.
 * 
 * @return the user repository
 * @throws Exception
 */
protected UsersRepository getUsersRepository() throws Exception {
    FileSystem fs = new FileSystem() {

        public File getBasedir() throws FileNotFoundException {
            return new File(".");
        }

        public InputStream getResource(String url) throws IOException {
            return new FileInputStream(getFile(url));
        }

        public File getFile(String fileURL) throws FileNotFoundException {
            return new File(fileURL.substring(FileSystem.FILE_PROTOCOL.length()));
        }

    };

    DefaultConfigurationBuilder configuration = new DefaultConfigurationBuilder("test");
    configuration.addProperty("destination.[@URL]", "file://target/var/users");
    // Configure with ignoreCase = false, we need some more work to support true
    configuration.addProperty("ignoreCase", "false");

    UsersFileRepository res = new UsersFileRepository();

    res.setFileSystem(fs);
    res.setLog(LoggerFactory.getLogger("MockLog"));
    res.configure(configuration);
    res.init();
    return res;
}
项目:James    文件:FileMailRepositoryTest.java   
/**
 * @return
 * @throws ServiceException
 * @throws ConfigurationException
 * @throws Exception
 */
protected MailRepository getMailRepository() throws Exception {
    MockFileSystem fs = new MockFileSystem();
    FileMailRepository mr = new FileMailRepository();
    mr.setFileSystem(fs);
    mr.setLog(LoggerFactory.getLogger("MockLog"));
    DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder();
    defaultConfiguration.addProperty("[@destinationURL]", "file://target/var/mr");
    defaultConfiguration.addProperty("[@type]", "MAIL");
    mr.configure(defaultConfiguration);
    mr.init();
    return mr;
}
项目:James    文件:XMLDomainListTest.java   
private HierarchicalConfiguration setUpConfiguration(boolean auto, boolean autoIP, List<String> names) {
    DefaultConfigurationBuilder configuration = new DefaultConfigurationBuilder();

    configuration.addProperty("autodetect", auto);
    configuration.addProperty("autodetectIP", autoIP);
    for (int i = 0; i < names.size(); i++) {
        configuration.addProperty("domainnames.domainname", names.get(i).toString());
    }
    return configuration;
}
项目:JCLAL    文件:XMLConfigurationReader.java   
private void initReader() {
    experiment = new DefaultConfigurationBuilder(file);
}
项目:JCLAL    文件:XMLConfigurationBuilder.java   
private void initBuilder() {
    experiment = new DefaultConfigurationBuilder();
    experiment.setRootElementName(rootElementName);
}
项目:James    文件:ProtocolHandlerChainImpl.java   
/**
 * Return a DefaultConfiguration build on the given command name and
 * classname.
 * 
 * @param cmdName
 *            The command name
 * @param className
 *            The class name
 * @return DefaultConfiguration
 * @throws ConfigurationException
 */
private HierarchicalConfiguration addHandler(String className) throws ConfigurationException {
    HierarchicalConfiguration hConf = new DefaultConfigurationBuilder();
    hConf.addProperty("[@class]", className);
    return hConf;
}