Search in sources :

Example 31 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project oxCore by GluuFederation.

the class FileConfiguration method loadProperties.

protected void loadProperties() {
    try {
        this.propertiesConfiguration = new PropertiesConfiguration(this.fileName);
        this.loaded = true;
    } catch (ConfigurationException ex) {
        LOG.debug(String.format("Failed to load '%s' configuration file from config folder", this.fileName));
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 32 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project winery by eclipse.

the class CsarExporter method addNamespacePrefixes.

/**
 * Writes the configured mapping namespaceprefix -> namespace to the archive
 * <p>
 * This is kind of a quick hack. TODO: during the import, the prefixes should be extracted using JAXB and stored in
 * the NamespacesResource
 */
private void addNamespacePrefixes(ArchiveOutputStream zos, IRepository repository) throws IOException {
    Configuration configuration = repository.getConfiguration(new NamespacesId());
    if (configuration instanceof PropertiesConfiguration) {
        // Quick hack: direct serialization only works for PropertiesConfiguration
        PropertiesConfiguration pconf = (PropertiesConfiguration) configuration;
        ArchiveEntry archiveEntry = new ZipArchiveEntry(CsarExporter.PATH_TO_NAMESPACES_PROPERTIES);
        zos.putArchiveEntry(archiveEntry);
        try {
            pconf.save(zos);
        } catch (ConfigurationException e) {
            CsarExporter.LOGGER.debug(e.getMessage(), e);
            zos.write("#Could not export properties".getBytes());
            zos.write(("#" + e.getMessage()).getBytes());
        }
        zos.closeArchiveEntry();
    }
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) NamespacesId(org.eclipse.winery.common.ids.admin.NamespacesId) ConfigurationException(org.apache.commons.configuration.ConfigurationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) ArchiveEntry(org.apache.commons.compress.archivers.ArchiveEntry) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 33 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project winery by eclipse.

the class CsarImporter method importNamespacePrefixes.

/**
 * Import namespace prefixes. This is kind of a quick hack. TODO: during the import, the prefixes should be
 * extracted using JAXB and stored in the NamespacesResource
 *
 * @param rootPath the root path of the extracted CSAR
 */
private void importNamespacePrefixes(Path rootPath) {
    NamespaceManager namespaceManager = RepositoryFactory.getRepository().getNamespaceManager();
    Path properties = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_PROPERTIES);
    if (Files.exists(properties)) {
        PropertiesConfiguration pconf;
        try {
            pconf = new PropertiesConfiguration(properties.toFile());
        } catch (ConfigurationException e) {
            CsarImporter.LOGGER.debug(e.getMessage(), e);
            return;
        }
        Iterator<String> namespaces = pconf.getKeys();
        while (namespaces.hasNext()) {
            boolean addToStorage = false;
            String namespace = namespaces.next();
            if (namespaceManager.hasPrefix(namespace)) {
                String storedPrefix = namespaceManager.getPrefix(namespace);
                // QUICK HACK to check whether the prefix is a generated one
                // We assume we know the internal generation routine
                Matcher m = CsarImporter.GENERATED_PREFIX_PATTERN.matcher(storedPrefix);
                if (m.matches()) {
                    // the stored prefix is a generated one
                    // replace it by the one stored in the exported properties
                    addToStorage = true;
                }
            } else {
                addToStorage = true;
            }
            if (addToStorage) {
                String prefix = pconf.getString(namespace);
                namespaceManager.setPrefix(namespace, prefix);
            }
        }
    }
}
Also used : NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) ConfigurationException(org.apache.commons.configuration.ConfigurationException) Matcher(java.util.regex.Matcher) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 34 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project grakn by graknlabs.

the class QueueConfig method parseFileToMap.

private static Map<String, List<Object>> parseFileToMap(Path configPath) {
    Map<String, List<Object>> map = new HashMap<>();
    try {
        PropertiesConfiguration props = new PropertiesConfiguration(configPath.toFile());
        props.getKeys().forEachRemaining(key -> map.put(key, props.getList(key)));
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
    return map;
}
Also used : HashMap(java.util.HashMap) ConfigurationException(org.apache.commons.configuration.ConfigurationException) List(java.util.List) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 35 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project gocd by gocd.

the class AgentAutoRegistrationPropertiesImpl method scrubRegistrationProperties.

@Override
public void scrubRegistrationProperties() {
    if (!exist()) {
        return;
    }
    try {
        PropertiesConfiguration config = new PropertiesConfiguration();
        config.setIOFactory(new FilteringOutputWriterFactory());
        PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(config);
        layout.setLineSeparator("\n");
        layout.load(reader());
        try (FileWriter out = new FileWriter(this.configFile)) {
            layout.save(out);
        }
        loadProperties();
    } catch (ConfigurationException | IOException e) {
        LOG.warn("[Agent Auto Registration] Unable to scrub registration key.", e);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) PropertiesConfigurationLayout(org.apache.commons.configuration.PropertiesConfigurationLayout)

Aggregations

ConfigurationException (org.apache.commons.configuration.ConfigurationException)66 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)31 File (java.io.File)20 IOException (java.io.IOException)19 ActionEvent (java.awt.event.ActionEvent)6 Configuration (org.apache.commons.configuration.Configuration)6 ActionListener (java.awt.event.ActionListener)5 FileInputStream (java.io.FileInputStream)5 MalformedURLException (java.net.MalformedURLException)5 ArrayList (java.util.ArrayList)5 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)5 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)4 FileNotFoundException (java.io.FileNotFoundException)3 FileWriter (java.io.FileWriter)3 HashMap (java.util.HashMap)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 CommonsConfiguration (com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration)2 BufferedWriter (java.io.BufferedWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2