Example usage for java.util Properties get

List of usage examples for java.util Properties get

Introduction

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

Prototype

@Override
    public Object get(Object key) 

Source Link

Usage

From source file:com.photon.phresco.impl.IPhoneApplicationProcessor.java

public void storeConfigObjAsPlist(Configuration keyValueObj, String plistPath) throws Exception {
    XMLPropertyListConfiguration plist = new XMLPropertyListConfiguration();
    Properties properties = keyValueObj.getProperties();
    Enumeration em = properties.keys();
    while (em.hasMoreElements()) {
        String str = (String) em.nextElement();
        plist.addProperty(str, properties.get(str));
    }//w  ww  . java  2s  .  c  o m
    plist.save(plistPath);

}

From source file:org.imsglobal.lti2.LTI2Servlet.java

@SuppressWarnings("unused")
protected void doLaunch(HttpServletRequest request, HttpServletResponse response) {

    String profile = PERSIST.get("profile");
    response.setContentType("text/html");

    String output = null;/*from  w  w w . jav  a  2  s .  co  m*/
    if (profile == null) {
        output = "Missing profile";
    } else {
        JSONObject providerProfile = (JSONObject) JSONValue.parse(profile);

        List<Properties> profileTools = new ArrayList<Properties>();
        Properties info = new Properties();
        String retval = LTI2Util.parseToolProfile(profileTools, info, providerProfile);
        String launch = null;
        String parameter = null;
        for (Properties profileTool : profileTools) {
            launch = (String) profileTool.get("launch");
            parameter = (String) profileTool.get("parameter");
        }
        JSONObject security_contract = (JSONObject) providerProfile.get(LTI2Constants.SECURITY_CONTRACT);

        String shared_secret = (String) security_contract.get(LTI2Constants.SHARED_SECRET);
        System.out.println("launch=" + launch);
        System.out.println("shared_secret=" + shared_secret);

        Properties ltiProps = LTI2SampleData.getLaunch();
        ltiProps.setProperty(BasicLTIConstants.LTI_VERSION, BasicLTIConstants.LTI_VERSION_2);

        Properties lti2subst = LTI2SampleData.getSubstitution();
        String settings_url = getServiceURL(request) + SVC_Settings + "/";
        lti2subst.setProperty("LtiLink.custom.url", settings_url + LTI2Util.SCOPE_LtiLink + "/"
                + ltiProps.getProperty(BasicLTIConstants.RESOURCE_LINK_ID));
        lti2subst.setProperty("ToolProxyBinding.custom.url", settings_url + LTI2Util.SCOPE_ToolProxyBinding
                + "/" + ltiProps.getProperty(BasicLTIConstants.CONTEXT_ID));
        lti2subst.setProperty("ToolProxy.custom.url", settings_url + LTI2Util.SCOPE_ToolProxy + "/" + TEST_KEY);
        lti2subst.setProperty("Result.url", getServiceURL(request) + SVC_Result + "/"
                + ltiProps.getProperty(BasicLTIConstants.RESOURCE_LINK_ID));

        // Do the substitutions
        Properties custom = new Properties();
        LTI2Util.mergeLTI2Parameters(custom, parameter);
        LTI2Util.substituteCustom(custom, lti2subst);

        // Place the custom values into the launch
        LTI2Util.addCustomToLaunch(ltiProps, custom);

        ltiProps = BasicLTIUtil.signProperties(ltiProps, launch, "POST", TEST_KEY, shared_secret, null, null,
                null);

        boolean dodebug = true;
        output = BasicLTIUtil.postLaunchHTML(ltiProps, launch, dodebug);
    }

    try {
        PrintWriter out = response.getWriter();
        out.println(output);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.github.fedorchuck.webstore.config.DataConfig.java

/**
 * annotation and xml don't want work, like i want. but wrote configuration data in code i don't want. so.. :(
 *//*from   w w  w  . j a  v  a2s.  c  om*/
@SuppressWarnings("unchecked")
private void readConfig() {
    Properties property = new Properties();
    try (InputStream is = res.getInputStream()) {
        property.load(is);
        Field[] fields = this.getClass().getSuperclass().getDeclaredFields();
        String canonicalField;
        String[] parts;

        for (Field field : fields) {

            parts = field.getName().split("DataConfig.");
            canonicalField = parts[0];

            if (property.containsKey("jdbc." + canonicalField)) {
                field.setAccessible(true);
                field.set(this, property.get("jdbc." + canonicalField));
            }
        }

    } catch (IOException | IllegalAccessException | NullPointerException e) {
        logger.error("problem read config. reason: ", e);
    }
}

From source file:de.kaiserpfalzEdv.infopir.backend.db.PersistenceConfiguration.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
    entityManagerFactoryBean.setDataSource(dataSource());
    entityManagerFactoryBean.setPersistenceProviderClass(HibernatePersistenceProvider.class);
    entityManagerFactoryBean//from ww w .j  a  va2  s .co  m
            .setPackagesToScan(env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));

    Properties hibProperties = hibProperties();
    entityManagerFactoryBean.setJpaProperties(hibProperties);

    LOG.debug("Packages to scan: {}", env.getRequiredProperty(PROPERTY_NAME_ENTITYMANAGER_PACKAGES_TO_SCAN));
    LOG.debug("Data Source: {}", dataSource());
    LOG.debug("Persistent Provider: {}", HibernatePersistenceProvider.class.getCanonicalName());
    LOG.trace("HBM2DDL Auto Setting: {}", hibProperties.getProperty(AvailableSettings.HBM2DDL_AUTO));
    LOG.trace("Hibernate Dialect: {}", hibProperties.getProperty(AvailableSettings.DIALECT));
    LOG.trace("Show SQL: {}", hibProperties.get(AvailableSettings.SHOW_SQL));
    return entityManagerFactoryBean;
}

From source file:com.photon.phresco.impl.IPhoneApplicationProcessor.java

private JSONObject envToJsonConverter(Environment env) throws PhrescoException {
    System.out.println("env " + env);
    List<Configuration> configurations = env.getConfigurations();
    JSONObject envJson = new JSONObject();

    envJson.put("-name", env.getName());
    envJson.put("-desc", env.getDesc());
    envJson.put("-default", env.isDefaultEnv());

    for (Configuration config : configurations) {
        JSONObject configJson = new JSONObject();
        configJson.put("-name", config.getName());
        configJson.put("-desc", config.getDesc());
        Properties properties = config.getProperties();
        Enumeration em = properties.keys();

        while (em.hasMoreElements()) {
            String key = (String) em.nextElement();
            Object object = properties.get(key);
            configJson.put(key, object.toString());
        }//from   w w w .j  ava2  s  .c  om
        envJson.put(config.getType(), configJson);
    }
    JSONObject envsJson = new JSONObject();
    envsJson.put("environment", envJson);

    JSONObject finalJson = new JSONObject();
    finalJson.put("environments", envsJson);
    System.out.println("finalJson ====> " + finalJson);
    return finalJson;
}

From source file:com.carrotgarden.maven.aws.cfn.CloudForm.java

protected Map<String, String> loadTemplateParameters(final File templateFile,
        final Map<String, String> pluginParams) throws Exception {

    final Map<String, String> stackParams = new TreeMap<String, String>();

    final Set<String> nameSet = loadParameterNames(templateFile);

    final Properties propsProject = project().getProperties();
    final Properties propsCommand = session().getUserProperties();
    final Properties propsSystem = session().getSystemProperties();

    for (final String name : nameSet) {

        if (pluginParams.containsKey(name)) {
            stackParams.put(name, pluginParams.get(name));
            continue;
        }/*from w  w  w  . j  av  a2s  .c o  m*/

        if (propsProject.containsKey(name)) {
            stackParams.put(name, propsProject.get(name).toString());
            continue;
        }

        if (propsCommand.containsKey(name)) {
            stackParams.put(name, propsCommand.get(name).toString());
            continue;
        }

        if (propsSystem.containsKey(name)) {
            stackParams.put(name, propsSystem.get(name).toString());
            continue;
        }

    }

    return stackParams;

}

From source file:com.gemstone.gemfire.management.internal.cli.commands.ConfigCommandsDUnitTest.java

/**
 * Asserts that altering the runtime config correctly updates the shared configuration.
 * <p>/*from ww  w.j  a v a2 s . co m*/
 * Disabled: this test frequently fails during unit test runs. See ticket #52204
 */
public void disabledtestAlterUpdatesSharedConfig() {
    disconnectAllFromDS();

    final String groupName = "testAlterRuntimeConfigSharedConfigGroup";

    // Start the Locator and wait for shared configuration to be available
    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
        @Override
        public void run() {

            final File locatorLogFile = new File("locator-" + locatorPort + ".log");
            final Properties locatorProps = new Properties();
            locatorProps.setProperty(DistributionConfig.NAME_NAME, "Locator");
            locatorProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
            locatorProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
            try {
                final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
                        locatorLogFile, null, locatorProps);

                DistributedTestCase.WaitCriterion wc = new DistributedTestCase.WaitCriterion() {
                    @Override
                    public boolean done() {
                        return locator.isSharedConfigurationRunning();
                    }

                    @Override
                    public String description() {
                        return "Waiting for shared configuration to be started";
                    }
                };
                DistributedTestCase.waitForCriterion(wc, 5000, 500, true);
            } catch (IOException ioex) {
                fail("Unable to create a locator with a shared configuration");
            }
        }
    });

    // Start the default manager
    Properties managerProps = new Properties();
    managerProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
    managerProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locatorPort);
    createDefaultSetup(managerProps);

    // Create a cache in VM 1
    VM vm = Host.getHost(0).getVM(1);
    vm.invoke(new SerializableCallable() {
        @Override
        public Object call() throws Exception {
            //Make sure no previous shared config is screwing up this test.
            FileUtil.delete(new File("ConfigDiskDir_Locator"));
            FileUtil.delete(new File("cluster_config"));
            Properties localProps = new Properties();
            localProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
            localProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locatorPort);
            localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "error");
            localProps.setProperty(DistributionConfig.GROUPS_NAME, groupName);
            getSystem(localProps);

            assertNotNull(getCache());
            assertEquals("error", system.getConfig().getAttribute(DistributionConfig.LOG_LEVEL_NAME));
            return null;
        }
    });

    // Test altering the runtime config
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
    commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__GROUP, groupName);
    commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, "fine");
    CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());

    // Make sure the shared config was updated
    Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
        @Override
        public void run() {
            SharedConfiguration sharedConfig = ((InternalLocator) Locator.getLocator())
                    .getSharedConfiguration();
            Properties gemfireProperties;
            try {
                gemfireProperties = sharedConfig.getConfiguration(groupName).getGemfireProperties();
                assertEquals("fine", gemfireProperties.get(DistributionConfig.LOG_LEVEL_NAME));
            } catch (Exception e) {
                fail("Error occurred in cluster configuration service", e);
            }
        }
    });
}

From source file:org.openremote.server.inventory.DiscoveryService.java

protected Adapter createAdapter(String name, String componentType, UriEndpointComponent component,
        Properties componentProperties) {
    LOG.info("Creating adapter for component: " + name);
    Class<? extends Endpoint> endpointClass = component.getEndpointClass();

    String label = componentProperties.containsKey(COMPONENT_LABEL)
            ? componentProperties.get(COMPONENT_LABEL).toString()
            : null;/*from   w  ww  .j  a  v a2  s  .c  o m*/

    if (label == null)
        throw new RuntimeException("Component missing label property: " + name);

    String discoveryEndpoint = componentProperties.containsKey(COMPONENT_DISCOVERY_ENDPOINT)
            ? componentProperties.get(COMPONENT_DISCOVERY_ENDPOINT).toString()
            : null;

    Adapter adapter = new Adapter(label, name, componentType, discoveryEndpoint);

    ComponentConfiguration config = component.createComponentConfiguration();
    ObjectNode properties = JSON.createObjectNode();
    for (Map.Entry<String, ParameterConfiguration> configEntry : config.getParameterConfigurationMap()
            .entrySet()) {
        try {
            Field field = endpointClass.getDeclaredField(configEntry.getKey());
            if (field.isAnnotationPresent(UriParam.class)) {
                UriParam uriParam = field.getAnnotation(UriParam.class);

                ObjectNode property = JSON.createObjectNode();

                if (uriParam.label().length() > 0) {
                    property.put("label", uriParam.label());
                }

                if (uriParam.description().length() > 0) {
                    property.put("description", uriParam.description());

                }

                if (uriParam.defaultValue().length() > 0) {
                    property.put("defaultValue", uriParam.defaultValue());
                }

                if (uriParam.defaultValueNote().length() > 0) {
                    property.put("defaultValueNote", uriParam.defaultValueNote());
                }

                if (String.class.isAssignableFrom(field.getType())) {
                    property.put("type", "string");
                } else if (Long.class.isAssignableFrom(field.getType())) {
                    property.put("type", "long");
                } else if (Integer.class.isAssignableFrom(field.getType())) {
                    property.put("type", "integer");
                } else if (Double.class.isAssignableFrom(field.getType())) {
                    property.put("type", "double");
                } else if (Boolean.class.isAssignableFrom(field.getType())) {
                    property.put("type", "boolean");
                } else {
                    throw new RuntimeException(
                            "Unsupported type of adapter endpoint property '" + name + "': " + field.getType());
                }

                if (field.isAnnotationPresent(NotNull.class)) {
                    for (Class<?> group : field.getAnnotation(NotNull.class).groups()) {
                        if (ValidationGroupDiscovery.class.isAssignableFrom(group)) {
                            property.put("required", true);
                            break;
                        }
                    }
                }

                String propertyName = uriParam.name().length() != 0 ? uriParam.name() : field.getName();
                LOG.debug("Adding adapter property '" + propertyName + "': " + property);
                properties.set(propertyName, property);
            }
        } catch (NoSuchFieldException ex) {
            // Ignoring config parameter if there is no annotated field on endpoint class
            // TODO: Inheritance of endpoint classes? Do we care?
        }
    }

    try {
        adapter.setProperties(JSON.writeValueAsString(properties));
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    return adapter;
}

From source file:com.mnxfst.testing.client.TestTSClient.java

@Test
public void testExtractAdditionalProperties() throws TSClientConfigurationException, ParseException {

    TSClient client = new TSClient();

    try {/*from www.  j  a  v a2  s .  com*/
        client.extractAdditionalProperties(null);
        Assert.fail("No such file");
    } catch (TSClientConfigurationException e) {
        //
    }

    try {
        client.extractAdditionalProperties("");
        Assert.fail("No such file");
    } catch (TSClientConfigurationException e) {
        //
    }

    try {
        client.extractAdditionalProperties(" ");
        Assert.fail("No such file");
    } catch (TSClientConfigurationException e) {
        //
    }

    try {
        client.extractAdditionalProperties("src/test/resource/noSuchFile.properties");
        Assert.fail("No such file");
    } catch (TSClientConfigurationException e) {
        //
    }

    try {
        client.extractAdditionalProperties("src/test/resources/sampleTestPlan.xml");
    } catch (TSClientConfigurationException e) {
        e.printStackTrace();
    }

    Properties props = client.extractAdditionalProperties("src/test/resources/tsclient.properties");
    Assert.assertNotNull("The result must not be null", props);
    Assert.assertEquals("The size of the properties set must be 9", 9, props.size());
    Assert.assertEquals("The property value must be equal", "001", props.get("scenarioId"));
    Assert.assertEquals("The property value must be equal", "001", props.get("productId"));
    Assert.assertEquals("The property value must be equal", "0001", props.get("runId"));
    Assert.assertEquals("The property value must be equal", "999", props.get("waitTime"));
    Assert.assertEquals("The property value must be equal", "100", props.get("waitTimeDecrement"));
    Assert.assertEquals("The property value must be equal", "vhost0103", props.get("localhostName"));
    Assert.assertEquals("The property value must be equal", "TCO", props.get("measuringPointOutId"));
    Assert.assertEquals("The property value must be equal", "TCI", props.get("measuringPointInId"));
    Assert.assertEquals("The property value must be equal", "lzenener strae", props.get("umlautTest"));

    //      
    //      
    //      String[] args = new String[]{"-addPropsFile", "file123"};
    //      Assert.assertEquals("The name of the file must be file123", "file123", client.extractStringValue(client.parseCommandline(options, args), TSClient.CMD_OPT_PTEST_SERVER_ADDITIONAL_PROPERTIES_FILE, TSClient.CMD_OPT_PTEST_SERVER_ADDITIONAL_PROPERTIES_FILE_SHORT));
    //      
}

From source file:org.esigate.authentication.RequestAuthenticationHandler.java

@Override
public void init(Properties properties) {
    // Attributes for session
    String sessionAttributesProperty = properties.getProperty("forwardSessionAttributes");
    if (sessionAttributesProperty != null) {
        String[] attributes = sessionAttributesProperty.split(",");
        for (String attribute : attributes) {
            this.sessionAttributes.add(attribute.trim());
            if (LOG.isInfoEnabled()) {
                LOG.info("Forwading session attribute: " + attribute);
            }/*from   www  .j  a  va2 s .  c o m*/
        }
    }

    // Attributes for request
    String requestAttributesProperty = (String) properties.get("forwardRequestAttributes");
    if (requestAttributesProperty != null) {
        String[] attributes = requestAttributesProperty.split(",");
        for (String attribute : attributes) {
            this.requestAttributes.add(attribute.trim());
            if (LOG.isInfoEnabled()) {
                LOG.info("Forwading request attribute: " + attribute);
            }
        }
    }

    // Prefix name
    String headerPrefixProperty = (String) properties.get("headerPrefix");
    if (headerPrefixProperty != null) {
        this.headerPrefix = headerPrefixProperty;
    }
}