List of usage examples for org.apache.commons.configuration DefaultConfigurationBuilder DefaultConfigurationBuilder
public DefaultConfigurationBuilder(URL url) throws ConfigurationException
DefaultConfigurationBuilder
and sets the specified configuration definition file. From source file:nl.salp.warcraft4j.config.Warcraft4jConfigFactory.java
/** * Read a {@link PropertyWarcraft4jConfig} from a file. * * @param configFile The path of the configuration file. * * @return The {@link PropertyWarcraft4jConfig} with the configuration from the file. * * @throws Warcraft4jConfigException When the file configuration was invalid. *//* w ww . ja v a 2s . c om*/ public PropertyWarcraft4jConfig fromFile(String configFile) throws Warcraft4jConfigException { try { return new PropertyWarcraft4jConfig(new DefaultConfigurationBuilder(configFile).getConfiguration()); } catch (org.apache.commons.configuration.ConfigurationException e) { throw new Warcraft4jConfigException( format("Error loading Warcraft4J configuration from file %s", configFile), e); } }
From source file:org.apache.james.user.file.UsersFileRepositoryTest.java
@SuppressWarnings("deprecation") @Override/*from w w w . ja v a 2 s .c o m*/ protected AbstractUsersRepository getUsersRepository() throws Exception { FileSystem fs = new FileSystem() { @Override public File getBasedir() throws FileNotFoundException { return new File("."); } @Override public InputStream getResource(String url) throws IOException { return new FileInputStream(getFile(url)); } @Override 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; }
From source file:org.dspace.servicemanager.config.DSpaceConfigurationService.java
/** * Loads up the configuration from the DSpace configuration files. * <P>// ww w . j a v a2 s . co m * Determines the home directory of DSpace, and then loads the configurations * based on the configuration definition file in that location * (using Apache Commons Configuration). * @param providedHome DSpace home directory, or null. */ private void loadInitialConfig(String providedHome) { // Determine the DSpace home directory homePath = getDSpaceHome(providedHome); // Based on homePath get full path to the configuration definition String configDefinition = homePath + File.separatorChar + DSPACE_CONFIG_DEFINITION_PATH; // Check if our configuration definition exists in the homePath File configDefFile = new File(configDefinition); if (!configDefFile.exists()) { try { //If it doesn't exist, check for a configuration definition on Classpath // (NOTE: This is mostly for Unit Testing to find the test config-definition.xml) ClassPathResource resource = new ClassPathResource(DSPACE_CONFIG_DEFINITION_PATH); configDefinition = resource.getFile().getAbsolutePath(); } catch (IOException ioe) { log.error("Error attempting to load configuration definition from classpath", ioe); } } try { // Load our configuration definition, which in turn loads all our config files/settings // See: http://commons.apache.org/proper/commons-configuration/userguide_v1.10/howto_configurationbuilder.html configurationBuilder = new DefaultConfigurationBuilder(configDefinition); // Actually parser our configuration definition & return the resulting Configuration configuration = configurationBuilder.getConfiguration(); } catch (ConfigurationException ce) { log.error("Unable to load configurations based on definition at " + configDefinition); System.err.println("Unable to load configurations based on definition at " + configDefinition); throw new RuntimeException(ce); } // Finally, set any dynamic, default properties setDynamicProperties(); log.info("Started up configuration service and loaded settings: " + toString()); }
From source file:org.sakaiproject.nakamura.imap.NakamuraNioImapServer.java
public void activate(ComponentContext componentContext) throws Exception { dnsServer = new DNSServer(); URL dnsConfigUrl = getClass().getResource("/dns-config.xml"); if (dnsConfigUrl == null) { throw new IllegalArgumentException( "Unalbe to configure DNS server, cant find configuration file dns-config.xml"); }// w ww .j av a 2s . c om DefaultConfigurationBuilder dnsConfig = new DefaultConfigurationBuilder(dnsConfigUrl); dnsConfig.load(); dnsServer.setLog(jcLog); dnsServer.configure(dnsConfig); dnsServer.init(); GlobalMailboxSessionJCRRepository sessionRepos = new GlobalMailboxSessionJCRRepository(slingRepository, null, "admin", "admin"); // Register imap cnd file org/apache/james/imap/jcr/imap.cnd when the bundle starts up // JCRUtils.registerCnd(repository, workspace, user, pass); Authenticator userManager = new Authenticator() { public boolean isAuthentic(String userid, CharSequence passwd) { System.err.println("Said " + userid + " with password " + passwd + " was Ok"); return true; // delegate authentication to JCR, the JCR session should use the same user as the imap session. We might want to // integrate this with the sling authentication handlers. } }; //TODO: Fix the scaling stuff so the tests will pass with max scaling too // TODO: this node locker will only work with non-clustered jcr per the developer's // notes in the class JCRVmNodeLocker nodeLocker = new JCRVmNodeLocker(); JCRMailboxSessionMapperFactory jcrMailboxSessionMapperFactory = new JCRMailboxSessionMapperFactory( sessionRepos, nodeLocker); JCRSubscriptionManager jcrSubscriptionManager = new JCRSubscriptionManager(jcrMailboxSessionMapperFactory); // MailboxManager mailboxManager = new JCRMailboxManager( jcrMailboxSessionMapperFactory, userManager, jcrSubscriptionManager ); MailboxManager mailboxManager = new JCRMailboxManager(jcrMailboxSessionMapperFactory, userManager, nodeLocker); MailboxSession session = mailboxManager.createSystemSession("test", jcLog); mailboxManager.startProcessingRequest(session); //mailboxManager.deleteEverything(session); mailboxManager.endProcessingRequest(session); mailboxManager.logout(session, false); decoder = new DefaultImapDecoderFactory().buildImapDecoder(); encoder = new DefaultImapEncoderFactory().buildImapEncoder(); processor = DefaultImapProcessorFactory.createDefaultProcessor(mailboxManager, jcrSubscriptionManager); setDNSService(dnsServer); setLog(jcLog); URL configUrl = getClass().getResource("/imap-config.xml"); if (configUrl == null) { throw new IllegalArgumentException( "Unalbe to configure IMAP server, cant find configuration file imap-config.xml"); } DefaultConfigurationBuilder config = new DefaultConfigurationBuilder(configUrl); config.load(); configure(config); init(); }
From source file:org.topazproject.mulgara.resolver.FilterResolverFactory.java
/** * Instantiate a {@link FilterResolverFactory}. *//* ww w . j a v a2 s. c om*/ private FilterResolverFactory(ResolverFactoryInitializer resolverFactoryInitializer) throws InitializerException { // Validate parameters if (resolverFactoryInitializer == null) throw new IllegalArgumentException("Null \"resolverFactoryInitializer\" parameter"); // Claim the filter graph type resolverFactoryInitializer.addModelType(FilterResolver.GRAPH_TYPE, this); /* Nasty hack to deal with change from "models" to "graphs" Necessary for WebAppListenerInitModels.dropObsoleteGraphs() to work TODO: Remove this after 0.9.2 */ resolverFactoryInitializer.addModelType(URI.create("http://topazproject.org/models#filter"), this); // end nasty hack // remember the database uri dbURI = resolverFactoryInitializer.getDatabaseURI(); // remember the system-graph type sysGraphType = resolverFactoryInitializer.getSystemModelType(); // load the configuration Configuration config = null; String fConf = System.getProperty(CONFIG_FACTORY_CONFIG_PROPERTY, DEFAULT_FACTORY_CONFIG); URL fConfUrl = null; try { fConfUrl = fConf.startsWith("/") ? getClass().getResource(fConf) : new URL(fConf); if (fConfUrl == null) throw new InitializerException("'" + fConf + "' not found in classpath"); logger.info("Using filter-resolver config '" + fConfUrl + "'"); DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(fConfUrl); config = builder.getConfiguration(); } catch (MalformedURLException mue) { throw new InitializerException("Error parsing '" + fConf + "'", mue); } catch (ConfigurationException ce) { throw new InitializerException("Error reading '" + fConfUrl + "'", ce); } catch (RuntimeException re) { throw new InitializerException("Configuration error '" + fConfUrl + "'", re); } String base = "topaz.fr"; config = config.subset(base); // Set up the filter handlers SessionFactory sf = resolverFactoryInitializer.getSessionFactory(); List<FilterHandler> hList = new ArrayList<FilterHandler>(); for (int idx = 0;; idx++) { String handlerClsName = config.getString("filterHandler.class_" + idx, null); if (handlerClsName == null) break; handlerClsName = handlerClsName.trim(); if (handlerClsName.length() == 0) continue; hList.add(instantiateHandler(handlerClsName, config, base, sf, dbURI)); logger.info("Loaded handler '" + handlerClsName + "'"); } if (hList.size() == 0) logger.info("No handlers configured"); handlers = hList.toArray(new FilterHandler[hList.size()]); }
From source file:uk.ac.ox.it.ords.api.statistics.configuration.MetaConfiguration.java
/** * Load meta-configuration/*from ww w .j a va2s. com*/ */ private static void load() { try { String ordsConfigurationLocation = ""; final String ORDS_CONF_DIR = System.getenv("ORDS_CONF_DIR"); if (ORDS_CONF_DIR != null) { ordsConfigurationLocation = ORDS_CONF_DIR + File.separator + ORDS_CONFIG_FILENAME; } else { ordsConfigurationLocation = ORDS_CONFIG_FILENAME; } DefaultConfigurationBuilder factory = new DefaultConfigurationBuilder(ordsConfigurationLocation); factory.load(); config = factory.getConfiguration(); } catch (Exception e) { config = null; e.printStackTrace(); log.warn("No server configuration location set; using defaults"); } }
From source file:uk.ac.ox.it.ords.security.configuration.MetaConfiguration.java
/** * Load meta-configuration// www. j av a2 s.c o m */ private static void load() { try { String ordsConfigurationLocation = ""; final String ORDS_CONF_DIR = System.getenv("ORDS_CONF_DIR"); if (ORDS_CONF_DIR != null) { ordsConfigurationLocation = ORDS_CONF_DIR + File.separator + ORDS_CONFIG_FILENAME; } else { ordsConfigurationLocation = ORDS_CONFIG_FILENAME; } DefaultConfigurationBuilder factory = new DefaultConfigurationBuilder(ordsConfigurationLocation); factory.load(); config = factory.getConfiguration(); } catch (Exception e) { config = null; log.warn("No server configuration location set; using defaults"); } }