Example usage for org.apache.commons.configuration MapConfiguration setProperty

List of usage examples for org.apache.commons.configuration MapConfiguration setProperty

Introduction

In this page you can find the example usage for org.apache.commons.configuration MapConfiguration setProperty.

Prototype

public void setProperty(String key, Object value) 

Source Link

Usage

From source file:org.apache.marmotta.platform.core.services.modules.ModuleServiceImpl.java

@PostConstruct
public void initialize() {

    //default_container_name = configurationService.getStringConfiguration("kiwi.pages.default_container.name",default_container_name);
    //default_container_number = configurationService.getIntConfiguration("kiwi.pages.default_container.number",default_container_number);

    modules = new HashSet<String>();
    containers = new HashMap<String, ArrayList<String>>();
    container_weight = new HashMap<String, Integer>();

    configurationMap = new HashMap<String, Configuration>();
    jarURLs = new HashMap<String, Configuration>();

    try {/*  w  w w.ja v a  2s  . c  o  m*/
        Enumeration<URL> modulePropertiesEnum = this.getClass().getClassLoader()
                .getResources("kiwi-module.properties");

        while (modulePropertiesEnum.hasMoreElements()) {
            URL moduleUrl = modulePropertiesEnum.nextElement();

            Configuration moduleProperties = null;
            try {
                Set<Configuration> configurations = new HashSet<Configuration>();

                // get basic module configuration
                moduleProperties = new PropertiesConfiguration(moduleUrl);
                configurations.add(moduleProperties);

                String moduleName = moduleProperties.getString("name");
                modules.add(moduleName);

                String c_name = moduleProperties.getString("container") != null
                        ? moduleProperties.getString("container")
                        : default_container_name;

                if (containers.get(c_name) == null) {
                    containers.put(c_name, new ArrayList<String>());
                }
                containers.get(c_name).add(moduleName);

                if (container_weight.get(c_name) == null) {
                    container_weight.put(c_name, -1);
                }

                if (moduleProperties.getString("container.weight") != null) {
                    container_weight.put(c_name, Math.max(container_weight.get(c_name),
                            moduleProperties.getInt("container.weight", -1)));
                }

                URLConnection urlConnection = moduleUrl.openConnection();
                URL jarUrl;
                if (urlConnection instanceof JarURLConnection) {
                    JarURLConnection conn = (JarURLConnection) urlConnection;
                    jarUrl = conn.getJarFileURL();
                } else {
                    String fileUrl = moduleUrl.toString();
                    jarUrl = new URL(fileUrl.substring(0, fileUrl.lastIndexOf("/")));
                }

                // get the build information
                try {
                    PropertiesConfiguration buildInfo = new PropertiesConfiguration(
                            new URL("jar:" + jarUrl.toString() + "!/buildinfo.properties"));
                    buildInfo.setDelimiterParsingDisabled(true);
                    configurations.add(buildInfo);
                } catch (ConfigurationException ex) {
                }

                // alternative: maven buildinfo plugin
                try {
                    PropertiesConfiguration buildInfo = new PropertiesConfiguration(
                            new URL("jar:" + jarUrl.toString() + "!/build.info"));
                    buildInfo.setDelimiterParsingDisabled(true);
                    configurations.add(buildInfo);
                } catch (ConfigurationException ex) {
                }

                // create runtime configuration
                MapConfiguration runtimeConfiguration = new MapConfiguration(new HashMap<String, Object>());
                runtimeConfiguration.setProperty("runtime.jarfile", jarUrl.toString());
                configurations.add(runtimeConfiguration);

                CompositeConfiguration moduleConfiguration = new CompositeConfiguration(configurations);
                configurationMap.put(moduleName, moduleConfiguration);
                jarURLs.put(jarUrl.toString(), moduleConfiguration);

            } catch (ConfigurationException e) {
                log.error("error parsing kiwi-module.properties file at {}", moduleUrl, e);
            }

        }
        //TODO container should be sortable
    } catch (IOException ex) {
        log.error("I/O error while trying to retrieve kiwi-module.properties file", ex);
    }
}

From source file:org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ProgramVertexProgramStep.java

@Override
public VertexProgram generateProgram(final Graph graph, final Memory memory) {
    final MapConfiguration base = new MapConfiguration(this.configuration);
    base.setDelimiterParsingDisabled(true);
    PureTraversal.storeState(base, ROOT_TRAVERSAL,
            TraversalHelper.getRootTraversal(this.getTraversal()).clone());
    base.setProperty(STEP_ID, this.getId());
    if (memory.exists(TraversalVertexProgram.HALTED_TRAVERSERS))
        TraversalVertexProgram.storeHaltedTraversers(base,
                memory.get(TraversalVertexProgram.HALTED_TRAVERSERS));
    return VertexProgram.createVertexProgram(graph, base);
}

From source file:org.sonar.server.configuration.ConfigurationFactory.java

private Configuration getDirectoriesConfiguration(ServletContextEvent sce) {
    MapConfiguration result = new MapConfiguration(new HashMap());
    String webAppDir = autodetectWebappDeployDirectory(sce);
    result.setProperty(CoreConfiguration.DEPLOY_DIR, webAppDir);
    return result;
}