List of usage examples for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration
public PropertiesConfiguration(URL url) throws ConfigurationException
From source file:fr.inria.atlanmod.neoemf.graph.blueprints.datastore.BlueprintsPersistenceBackendFactory.java
@Override public BlueprintsPersistenceBackend createPersistentBackend(File file, Map<?, ?> options) throws InvalidDataStoreException { BlueprintsPersistenceBackend graphDB = null; PropertiesConfiguration neoConfig = null; PropertiesConfiguration configuration = null; try {/* w w w .j ava2s. com*/ // Try to load previous configurations Path path = Paths.get(file.getAbsolutePath()).resolve(CONFIG_FILE); try { configuration = new PropertiesConfiguration(path.toFile()); } catch (ConfigurationException e) { throw new InvalidDataStoreException(e); } // Initialize value if the config file has just been created if (!configuration.containsKey(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE)) { configuration.setProperty(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE, BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE_DEFAULT); } else if (options.containsKey(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE)) { // The file already existed, check that the issued options // are not conflictive String savedGraphType = configuration .getString(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE); String issuedGraphType = options.get(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE) .toString(); if (!savedGraphType.equals(issuedGraphType)) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, "Unable to create graph as type " + issuedGraphType + ", expected graph type was " + savedGraphType + ")"); throw new InvalidDataStoreException("Unable to create graph as type " + issuedGraphType + ", expected graph type was " + savedGraphType + ")"); } } // Copy the options to the configuration for (Entry<?, ?> e : options.entrySet()) { configuration.setProperty(e.getKey().toString(), e.getValue().toString()); } // Check we have a valid graph type, it is needed to get the // graph name String graphType = configuration.getString(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE); if (graphType == null) { throw new InvalidDataStoreException("Graph type is undefined for " + file.getAbsolutePath()); } String[] segments = graphType.split("\\."); if (segments.length >= 2) { String graphName = segments[segments.length - 2]; String upperCaseGraphName = Character.toUpperCase(graphName.charAt(0)) + graphName.substring(1); String configClassQualifiedName = MessageFormat.format( "fr.inria.atlanmod.neoemf.graph.blueprints.{0}.config.Blueprints{1}Config", graphName, upperCaseGraphName); try { ClassLoader classLoader = BlueprintsPersistenceBackendFactory.class.getClassLoader(); Class<?> configClass = classLoader.loadClass(configClassQualifiedName); Field configClassInstanceField = configClass.getField("eINSTANCE"); AbstractBlueprintsConfig configClassInstance = (AbstractBlueprintsConfig) configClassInstanceField .get(configClass); Method configMethod = configClass.getMethod("putDefaultConfiguration", Configuration.class, File.class); configMethod.invoke(configClassInstance, configuration, file); Method setGlobalSettingsMethod = configClass.getMethod("setGlobalSettings"); setGlobalSettingsMethod.invoke(configClassInstance); } catch (ClassNotFoundException e1) { NeoLogger.log(NeoLogger.SEVERITY_WARNING, "Unable to find the configuration class " + configClassQualifiedName); e1.printStackTrace(); } catch (NoSuchFieldException e2) { NeoLogger.log(NeoLogger.SEVERITY_WARNING, MessageFormat.format( "Unable to find the static field eINSTANCE in class Blueprints{0}Config", upperCaseGraphName)); e2.printStackTrace(); } catch (NoSuchMethodException e3) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, MessageFormat.format( "Unable to find configuration methods in class Blueprints{0}Config", upperCaseGraphName)); e3.printStackTrace(); } catch (InvocationTargetException e4) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, MessageFormat.format( "An error occured during the exection of a configuration method", upperCaseGraphName)); e4.printStackTrace(); } catch (IllegalAccessException e5) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, MessageFormat.format( "An error occured during the exection of a configuration method", upperCaseGraphName)); e5.printStackTrace(); } } else { NeoLogger.log(NeoLogger.SEVERITY_WARNING, "Unable to compute graph type name from " + graphType); } Graph baseGraph = null; try { baseGraph = GraphFactory.open(configuration); } catch (RuntimeException e) { throw new InvalidDataStoreException(e); } if (baseGraph instanceof KeyIndexableGraph) { graphDB = new BlueprintsPersistenceBackend((KeyIndexableGraph) baseGraph); } else { NeoLogger.log(NeoLogger.SEVERITY_ERROR, "Graph type " + file.getAbsolutePath() + " does not support Key Indices"); throw new InvalidDataStoreException( "Graph type " + file.getAbsolutePath() + " does not support Key Indices"); } // Save the neoconfig file Path neoConfigPath = Paths.get(file.getAbsolutePath()).resolve(NEO_CONFIG_FILE); try { neoConfig = new PropertiesConfiguration(neoConfigPath.toFile()); } catch (ConfigurationException e) { throw new InvalidDataStoreException(e); } if (!neoConfig.containsKey(BACKEND_PROPERTY)) { neoConfig.setProperty(BACKEND_PROPERTY, BLUEPRINTS_BACKEND); } } finally { if (configuration != null) { try { configuration.save(); } catch (ConfigurationException e) { // Unable to save configuration, supposedly it's a minor error, // so we log it without rising an exception NeoLogger.log(NeoLogger.SEVERITY_ERROR, e); } } if (neoConfig != null) { try { neoConfig.save(); } catch (ConfigurationException e) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, e); } } } return graphDB; }
From source file:com.gs.obevo.db.apps.reveng.TableSyncher.java
public void execute(DbFileMergerArgs args) { Configuration config;//w ww.j a v a 2 s . c o m try { config = new PropertiesConfiguration(args.getDbMergeConfigFile()); } catch (ConfigurationException e) { throw new RuntimeException(e); } MutableCollection<DbMergeInfo> dbMergeInfos = DbMergeInfo.parseFromProperties(config); MutableCollection<TableSyncSide> tableSyncSides = dbMergeInfos .collect(new Function<DbMergeInfo, TableSyncSide>() { @Override public TableSyncSide valueOf(DbMergeInfo dbMergeInfo) { DataSource ds = ds(dbMergeInfo.getDriverClassName(), dbMergeInfo.getUrl(), dbMergeInfo.getUsername(), dbMergeInfo.getPassword()); return new TableSyncSide(ds, new PhysicalSchema(dbMergeInfo.getPhysicalSchema())); } }); this.syncSchemaTables(DbPlatformConfiguration.getInstance().valueOf(config.getString("dbType")), tableSyncSides, args.getOutputDir()); }
From source file:gov.va.chir.tagline.beans.Configuration.java
public Configuration(final String filename) { this.filename = filename; // Load configuration file try {/*from ww w . j a v a 2s. c o m*/ config = new PropertiesConfiguration(filename); } catch (ConfigurationException e) { config = null; e.printStackTrace(); } }
From source file:com.github.aynu.mosir.core.standard.util.PropertiesHelper.java
/** * ????/*from w w w .j av a 2 s. c om*/ * @param baseName ?? * @return ?? */ private PropertiesConfiguration getPropertiesConfiguration(final String baseName) { final String languageTag = String.format("%s-%s", SystemUtils.USER_LANGUAGE, SystemUtils.USER_COUNTRY); final Control control = Control.getControl(Control.FORMAT_DEFAULT); final Collection<Locale> locales = control.getCandidateLocales("messages", Locale.forLanguageTag(languageTag)); final StringBuilder builder = new StringBuilder(); for (final Locale locale : locales) { final String bundleName = control.toBundleName(baseName, locale); final String resourceName = control.toResourceName(bundleName, "properties"); final URL url = getClass().getResource("/" + resourceName); // final URL url = ClassLoader.getSystemResource(resourceName); if (url != null) { if (builder.length() > 0) { LOG.debug("Resource could not be found ({}).", builder.toString()); } LOG.debug("Resource could be found ({}).", resourceName); try { return new PropertiesConfiguration(url); } catch (final ConfigurationException e) { throw new RuntimeException(e); } } builder.append(" " + resourceName); } throw new RuntimeException(String.format("PROPERTY is NOT_FOUND. [baseName=%s]", baseName)); }
From source file:edu.utexas.cs.tactex.core.BrokerPropertiesService.java
/** * Loads the properties from classpath, default config file, * and user-specified config file, just in case it's not already been * loaded. This is done when properties are first requested, to ensure * that the logger has been initialized. Because the CompositeConfiguration * treats its config sources in FIFO order, this should be called <i>after</i> * any user-specified config is loaded.//from w ww . j a v a 2s . c om */ void lazyInit() { // only do this once if (initialized) return; initialized = true; // find and load the default properties file log.debug("lazyInit"); try { File defaultProps = new File("broker.properties"); log.info("adding " + defaultProps.getName()); config.addConfiguration(new PropertiesConfiguration(defaultProps)); } catch (Exception e1) { log.warn("broker.properties not found: " + e1.toString()); } // set up the classpath props try { Resource[] xmlResources = context.getResources("classpath*:config/properties.xml"); for (Resource xml : xmlResources) { if (validXmlResource(xml)) { log.info("loading config from " + xml.getURI()); XMLConfiguration xconfig = new XMLConfiguration(); xconfig.load(xml.getInputStream()); config.addConfiguration(xconfig); } } Resource[] propResources = context.getResources("classpath*:config/*.properties"); for (Resource prop : propResources) { if (validPropResource(prop)) { if (null == prop) { log.error("Null resource"); } log.info("loading config from " + prop.getURI()); PropertiesConfiguration pconfig = new PropertiesConfiguration(); pconfig.load(prop.getInputStream()); config.addConfiguration(pconfig); } } } catch (ConfigurationException e) { log.error("Problem loading configuration: " + e.toString()); } catch (Exception e) { log.error("Error loading configuration: " + e.toString()); } // set up the configurator configurator.setConfiguration(config); }
From source file:com.manydesigns.portofino.modules.MailModule.java
@Override public void init() { CompositeConfiguration mailConfiguration = new CompositeConfiguration(); mailConfiguration.addConfiguration(configuration); try {//from w w w . j av a2 s .co m mailConfiguration .addConfiguration(new PropertiesConfiguration(getClass().getResource("mail.properties"))); } catch (ConfigurationException e) { logger.error("Could not load mail configuration defaults"); } mailQueueSetup = new MailQueueSetup(mailConfiguration); mailQueueSetup.setup(); SimpleMenuAppender group = SimpleMenuAppender.group("mail", null, "Mail", 4.0); adminMenu.menuAppenders.add(group); SimpleMenuAppender link = SimpleMenuAppender.link("mail", "Mail", null, "Mail", MailSettingsAction.URL_BINDING, 1.0); adminMenu.menuAppenders.add(link); servletContext.setAttribute(MAIL_CONFIGURATION, mailQueueSetup.getMailConfiguration()); MailQueue mailQueue = mailQueueSetup.getMailQueue(); if (mailQueue == null) { logger.info("Mail queue not enabled"); return; } servletContext.setAttribute(MAIL_QUEUE, mailQueue); servletContext.setAttribute(MAIL_SENDER, mailQueueSetup.getMailSender()); status = ModuleStatus.ACTIVE; }
From source file:com.github.aynu.yukar.framework.util.PropertiesHelper.java
/** * ????// ww w . ja va2 s. c o m * @param baseName ?? * @return ?? */ private PropertiesConfiguration getPropertiesConfiguration(final String baseName) { final String languageTag = String.format("%s-%s", SystemUtils.USER_LANGUAGE, SystemUtils.USER_COUNTRY); final Control control = Control.getControl(Control.FORMAT_DEFAULT); final Collection<Locale> locales = control.getCandidateLocales("messages", Locale.forLanguageTag(languageTag)); final StringBuilder builder = new StringBuilder(); for (final Locale locale : locales) { try { final String bundleName = control.toBundleName(baseName, locale); final String resourceName = control.toResourceName(bundleName, "properties"); final URL url = getClass().getResource("/" + resourceName); // final URL url = ClassLoader.getSystemResource(resourceName); if (url != null) { if (builder.length() > 0) { LOG.debug("Resource could not be found ({}).", builder.toString()); } LOG.debug("Resource could be found ({}).", resourceName); return new PropertiesConfiguration(url); } builder.append(" " + resourceName); } catch (final ConfigurationException e) { LOG.warn(e.toString(), e); throw new StandardRuntimeException(e); } } throw new StandardRuntimeException(String.format("PROPERTY is NOT_FOUND. [baseName=%s]", baseName)); }
From source file:fr.inria.atlanmod.neoemf.eclipse.ui.commands.OpenNeoEMFDbCommand.java
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event); ISelectionService service = window.getSelectionService(); ISelection selection = service.getSelection(); folder = null;/* ww w. j ava 2s. co m*/ if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; Object elt = structuredSelection.getFirstElement(); if (elt instanceof IFolder) { folder = (IFolder) elt; } } if (folder == null) return null; new UIJob(window.getShell().getDisplay(), "Create Dynamic Instance") { @Override public IStatus runInUIThread(IProgressMonitor monitor) { PersistenceBackendFactoryRegistry.getFactories().put(NeoBlueprintsURI.NEO_GRAPH_SCHEME, new BlueprintsPersistenceBackendFactory()); PersistenceBackendFactoryRegistry.getFactories().put(NeoMapURI.NEO_MAP_SCHEME, new MapPersistenceBackendFactory()); System.out.println(folder.getRawLocation().toOSString() + "/" + AbstractPersistenceBackendFactory.NEO_CONFIG_FILE); File neoConfigFile = new File(folder.getRawLocation().toOSString() + "/" + AbstractPersistenceBackendFactory.NEO_CONFIG_FILE); PropertiesConfiguration neoConfig = null; try { neoConfig = new PropertiesConfiguration(neoConfigFile); } catch (ConfigurationException e1) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, "Unable to find neoconfig.properties file"); return new Status(IStatus.ERROR, NeoEMFUiPlugin.PLUGIN_ID, "Unable to open the editor", e1); } String backendType = neoConfig.getString(AbstractPersistenceBackendFactory.BACKEND_PROPERTY); URI uri = null; if (backendType == null) { NeoLogger.log(NeoLogger.SEVERITY_ERROR, "neoconfig.properties does not contain " + AbstractPersistenceBackendFactory.BACKEND_PROPERTY + " property"); return new Status(IStatus.ERROR, NeoEMFUiPlugin.PLUGIN_ID, "Unable to open editor"); } else if (backendType.equals(MapPersistenceBackendFactory.MAPDB_BACKEND)) { uri = NeoMapURI.createNeoMapURI(new File(folder.getRawLocation().toOSString())); } else if (backendType.equals(BlueprintsPersistenceBackendFactory.BLUEPRINTS_BACKEND)) { uri = NeoBlueprintsURI.createNeoGraphURI(new File(folder.getRawLocation().toOSString())); } // URI uri= NeoBlueprintsURI.createNeoGraphURI(new File(folder.getRawLocation().toOSString())); URIEditorInput editorInput = new URIEditorInput(uri); if (editorInput != null) { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage(); try { page.openEditor(editorInput, NeoEMFEditor.EDITOR_ID); } catch (PartInitException e) { return new Status(IStatus.ERROR, NeoEMFUiPlugin.PLUGIN_ID, "Unable to open editor", e); } } return Status.OK_STATUS; } }.schedule(); return null; }
From source file:com.beginner.core.utils.PropertyUtil.java
/** * org.apache.commons.configuration.Configuration?properties??TestResourcesUtil * <p>/*from w ww . j a v a 2 s .com*/ * ????properties?<br> * 1?classpathkey=type fileName=beginner.properties -mysql<br> * 2?key=type fileName=/data/app/beginner.properties -mysql<br> * 3?key=type fileName=D:/data/app/beginner.properties -mysql<br> * </p> * @param key key * @param fileName +??+??? * @return String keyvalue * @throws Exception IO */ public static String getProperties(String key, String fileName) throws Exception { if (StringUtils.isBlank(key)) throw new IllegalArgumentException("The key cannot be null and cannot be empty."); if (StringUtils.isBlank(fileName)) throw new IllegalArgumentException("The fileName cannot be null and cannot be empty."); String properties = StringUtils.EMPTY; Configuration config = null; try { config = new PropertiesConfiguration(fileName); properties = config.getString(key); } catch (Exception e) { throw new Exception(); } return properties; }
From source file:fr.inria.atlanmod.neoemf.data.AbstractPersistenceBackendFactory.java
/** * Creates and saves the NeoEMF configuration. * * @param directory the directory where the configuration must be stored. *//* w ww. ja v a2 s .com*/ protected void processGlobalConfiguration(File directory) throws InvalidDataStoreException { PropertiesConfiguration configuration; Path path = Paths.get(directory.getAbsolutePath()).resolve(CONFIG_FILE); try { configuration = new PropertiesConfiguration(path.toFile()); } catch (ConfigurationException e) { throw new InvalidDataStoreException(e); } if (!configuration.containsKey(BACKEND_PROPERTY)) { configuration.setProperty(BACKEND_PROPERTY, getName()); } try { configuration.save(); NeoLogger.debug("Configuration stored at " + path); } catch (ConfigurationException e) { /* * Unable to save configuration. * Supposedly it's a minor error, so we log it without rising an exception. */ NeoLogger.warn(e); } }