Example usage for java.util Properties clear

List of usage examples for java.util Properties clear

Introduction

In this page you can find the example usage for java.util Properties clear.

Prototype

@Override
    public synchronized void clear() 

Source Link

Usage

From source file:org.mule.config.bootstrap.SimpleRegistryBootstrap.java

private void registerObjects(Properties props, Registry registry) throws Exception {
    for (Map.Entry<Object, Object> entry : props.entrySet()) {
        registerObject((String) entry.getKey(), (String) entry.getValue(), registry);
    }// w w w .java  2s .c om
    props.clear();
}

From source file:org.mule.config.bootstrap.SimpleRegistryBootstrap.java

private void registerUnnamedObjects(Properties props, Registry registry) throws Exception {
    for (Map.Entry<Object, Object> entry : props.entrySet()) {
        final String key = String.format("%s#%s", entry.getKey(), UUID.getUUID());
        registerObject(key, (String) entry.getValue(), registry);
    }/* w w  w .ja  va 2  s . c  om*/
    props.clear();
}

From source file:org.ojb.web.portal.WebPortalApplicationContextInitializer.java

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    ConfigurableEnvironment environment = applicationContext.getEnvironment();

    Properties props = new Properties();
    String activeProfiles = "";

    try {/* w  w  w  .  j  a v  a2  s.  c  o  m*/
        props.load(applicationContext.getClassLoader()
                .getResourceAsStream("config/ojb_web_external_resource.cfg"));
        activeProfiles = props.getProperty("spring.activeProfiles");
    } catch (IOException e) {
        LOG.info(
                "Unable to load spring profiles from external resource, will load default from ojb_web_portal.cfg");
    }

    if (StringUtils.isBlank(activeProfiles)) {
        try {
            props.clear();
            props.load(applicationContext.getClassLoader().getResourceAsStream("config/ojb-web-portal.cfg"));
            activeProfiles = props.getProperty("spring.activeProfiles");
        } catch (IOException e) {
            LOG.info("Unable to load spring profiles from ojb_web_portal.cfg");
        }
    }

    if (StringUtils.isBlank(activeProfiles)) {
        LOG.info("No spring profiles set, will run in 'standalone' mode");
        environment.setDefaultProfiles("standalone");
    } else {
        LOG.info("Setting default profiles to:" + activeProfiles);
        environment.setDefaultProfiles(activeProfiles.split(","));
    }
}

From source file:org.opencastproject.capture.impl.CaptureAgentImplTest.java

@Before
public void setUp() throws ConfigurationException, IOException, URISyntaxException {
    if (!gstreamerInstalled)
        return;/*ww w  . java2 s  . com*/
    // Create the configuration manager
    config = new ConfigurationManager();
    File testDir = new File("./target", "capture-agent-test" + File.separator + "cache" + File.separator
            + "captures" + File.separator + recordingID);
    if (testDir.exists()) {
        FileUtils.deleteQuietly(testDir);
        logger.info("Removing  " + testDir.getAbsolutePath());
    } else {
        logger.info("Didn't Delete " + testDir.getAbsolutePath());
    }

    Properties p = loadProperties("config/capture.properties");
    p.put("org.opencastproject.storage.dir", new File("./target", "capture-agent-test").getAbsolutePath());
    p.put("org.opencastproject.server.url", "http://localhost:8080");
    p.put(CaptureParameters.CAPTURE_SCHEDULE_REMOTE_POLLING_INTERVAL, -1);
    p.put("M2_REPO", getClass().getClassLoader().getResource("m2_repo").getFile());
    config.updated(p);
    // creates agent, initially idle
    captureAgentImpl = new CaptureAgentImpl();
    captureAgentImpl.setConfigService(config);
    captureAgentImpl.setCaptureFramework(new GStreamerCaptureFramework());
    Assert.assertNull(captureAgentImpl.getAgentState());
    captureAgentImpl.activate(null);
    Assert.assertEquals(AgentState.IDLE, captureAgentImpl.getAgentState());
    p.clear();
    //NB:  agent's .updated() function takes a Quartz properties file, *NOT* the agent's.  Hence the load here.
    p = loadProperties("config/scheduler.properties");
    captureAgentImpl.updated(p);
    // setup testing properties
    properties = new Properties();
    properties.setProperty(CaptureParameters.RECORDING_ID, recordingID);
    properties.setProperty(CaptureParameters.RECORDING_END, "something");
    waiter = new WaitForState();
}

From source file:org.openmrs.messagesource.impl.MutableResourceBundleMessageSource.java

/**
 * Convenience method to scan the available properties files, looking for the one that has a
 * definition for the given code.// w w  w .  j ava 2  s  .c o m
 *
 * @param code
 * @return the file which defines the code, or null if not found
 */
private File findPropertiesFileFor(String code) {
    Properties props = new Properties();
    File foundFile = null;

    for (File propertiesFile : findPropertiesFiles()) {
        props.clear();
        try {
            OpenmrsUtil.loadProperties(props, propertiesFile);
        } catch (Exception e) {
            log.error("Error generated", e);
        }
        if (props.containsKey(code)) {
            foundFile = propertiesFile;
            break;
        }
    }
    return foundFile;
}

From source file:org.openTwoFactor.client.util.TwoFactorClientCommonUtils.java

/**
 * read properties from a resource, dont modify the properties returned since they are cached
 * @param resourceName//from w w  w . j  ava  2 s  . co m
 * @param useCache 
 * @param exceptionIfNotExist 
 * @param classInJar if not null, then look for the jar where this file is, and look in the same dir
 * @param callingLog 
 * @return the properties or null if not exist
 */
public synchronized static Properties propertiesFromResourceName(String resourceName, boolean useCache,
        boolean exceptionIfNotExist, Class<?> classInJar, StringBuilder callingLog) {

    Properties properties = resourcePropertiesCache.get(resourceName);

    if (!useCache || !resourcePropertiesCache.containsKey(resourceName)) {

        properties = new Properties();

        boolean success = false;

        URL url = computeUrl(resourceName, true);
        InputStream inputStream = null;
        try {
            inputStream = url.openStream();
            properties.load(inputStream);
            success = true;
            String theLog = "Reading resource: " + resourceName + ", from: " + url.toURI();
            if (LOG != null) {
                LOG.debug(theLog);
            }
            if (callingLog != null) {
                callingLog.append(theLog);
            }
        } catch (Exception e) {

            //clear out just in case
            properties.clear();

            //lets look next to jar
            File jarFile = classInJar == null ? null : jarFile(classInJar);
            File parentDir = jarFile == null ? null : jarFile.getParentFile();
            String fileName = parentDir == null ? null
                    : (stripLastSlashIfExists(fileCanonicalPath(parentDir)) + File.separator + resourceName);
            File configFile = fileName == null ? null : new File(fileName);

            try {
                //looks like we have a match
                if (configFile != null && configFile.exists() && configFile.isFile()) {
                    inputStream = new FileInputStream(configFile);
                    properties.load(inputStream);
                    success = true;
                    String theLog = "Reading resource: " + resourceName + ", from: "
                            + fileCanonicalPath(configFile);
                    if (LOG != null) {
                        LOG.debug(theLog);
                    }
                    if (callingLog != null) {
                        callingLog.append(theLog);
                    }
                }

            } catch (Exception e2) {
                if (LOG != null) {
                    LOG.debug("Error reading from file for resource: " + resourceName + ", file: " + fileName,
                            e2);
                }
            }
            if (!success) {
                properties = null;
                if (exceptionIfNotExist) {
                    throw new RuntimeException("Problem with resource: '" + resourceName + "'", e);
                }
            }
        } finally {
            closeQuietly(inputStream);

            if (useCache && properties != null && properties.size() > 0) {
                resourcePropertiesCache.put(resourceName, properties);
            }
        }
    }

    return properties;
}

From source file:org.springframework.test.context.support.TestPropertySourceUtils.java

/**
 * Convert the supplied <em>inlined properties</em> (in the form of <em>key-value</em>
 * pairs) into a map keyed by property name, preserving the ordering of property names
 * in the returned map./*w  ww .jav a2 s. c o  m*/
 * <p>Parsing of the key-value pairs is achieved by converting all pairs
 * into <em>virtual</em> properties files in memory and delegating to
 * {@link Properties#load(java.io.Reader)} to parse each virtual file.
 * <p>For a full discussion of <em>inlined properties</em>, consult the Javadoc
 * for {@link TestPropertySource#properties}.
 * @param inlinedProperties the inlined properties to convert; potentially empty
 * but never {@code null}
 * @return a new, ordered map containing the converted properties
 * @since 4.1.5
 * @throws IllegalStateException if a given key-value pair cannot be parsed, or if
 * a given inlined property contains multiple key-value pairs
 * @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
 */
public static Map<String, Object> convertInlinedPropertiesToMap(String... inlinedProperties) {
    Assert.notNull(inlinedProperties, "'inlinedProperties' must not be null");
    Map<String, Object> map = new LinkedHashMap<>();
    Properties props = new Properties();

    for (String pair : inlinedProperties) {
        if (!StringUtils.hasText(pair)) {
            continue;
        }
        try {
            props.load(new StringReader(pair));
        } catch (Exception ex) {
            throw new IllegalStateException("Failed to load test environment property from [" + pair + "]", ex);
        }
        Assert.state(props.size() == 1,
                () -> "Failed to load exactly one test environment property from [" + pair + "]");
        for (String name : props.stringPropertyNames()) {
            map.put(name, props.getProperty(name));
        }
        props.clear();
    }

    return map;
}

From source file:org.wso2.developerstudio.eclipse.distribution.project.editor.DistProjectEditorPage.java

private void transformProperties(Properties properties) {
    Map<String, String> oldServerRoleList = new HashMap<String, String>();
    for (Dependency dependency : (List<Dependency>) parentPrj.getDependencies()) {
        oldServerRoleList.put(DistProjectUtils.getArtifactInfoAsString(dependency),
                DistProjectUtils.getServerRole(parentPrj, dependency));
    }/*from  w w  w . j  a v  a2  s .co  m*/

    properties.clear();
    Map<String, String> map = oldServerRoleList;
    for (String key : oldServerRoleList.keySet()) {
        properties.setProperty(key, oldServerRoleList.get(key));
    }

    // change maven-car-plugin version to 2.0.5 and car-deploy version 1.0.4
    List<Plugin> pluginList = parentPrj.getBuildPlugins();
    for (Plugin plugin : pluginList) {
        if (plugin.getArtifactId().equalsIgnoreCase("maven-car-plugin")) {
            plugin.setVersion(MavenConstants.MAVEN_CAR_VERSION);
        } else if (plugin.getArtifactId().equalsIgnoreCase("maven-car-deploy-plugin")) {
            plugin.setVersion(MavenConstants.MAVEN_CAR_DEPLOY_VERSION);
        }
    }
    setPageDirty(true);
    updateDirtyState();
}