Example usage for java.util Properties getProperty

List of usage examples for java.util Properties getProperty

Introduction

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

Prototype

public String getProperty(String key) 

Source Link

Document

Searches for the property with the specified key in this property list.

Usage

From source file:org.tonguetied.test.common.PersistenceTestBase.java

/**
 * @param properties//from  www .  ja  v a  2 s .  co m
 * @return the configuration object for running this test class
 * @throws MappingException
 */
protected static AnnotationConfiguration createConfiguration(Properties properties) throws MappingException {
    AnnotationConfiguration config = new AnnotationConfiguration();
    config.setProperty(Environment.DRIVER, properties.getProperty(KEY_JDBC_DRIVER));
    config.setProperty(Environment.URL, properties.getProperty(KEY_JDBC_URL));
    config.setProperty(Environment.USER, properties.getProperty(KEY_JDBC_USER_NAME));
    config.setProperty(Environment.PASS, properties.getProperty(KEY_JDBC_PASSWORD));
    config.setProperty(Environment.POOL_SIZE, "1");
    config.setProperty(Environment.AUTOCOMMIT, "true");
    config.setProperty(Environment.CACHE_PROVIDER, "org.hibernate.cache.HashtableCacheProvider");
    config.setProperty(Environment.SHOW_SQL, "false");
    config.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
    config.setProperty(Environment.DIALECT, properties.getProperty(KEY_HIBERNATE_DIALECT));

    for (int i = 0; i < ANNOTATED_CLASSES.length; i++) {
        config.addAnnotatedClass(ANNOTATED_CLASSES[i]);
    }

    return config;
}

From source file:com.fluke.database.DatabaseProperty.java

public static DataSource getDataSource() {
    if (source != null) {
        return source;
    }// w w w .  j a  v  a  2  s  .  c  o  m
    Properties props = new Properties();
    FileInputStream fis = null;

    BasicDataSource dataSource = new BasicDataSource();
    try {

        props.load(ClassLoader.getSystemResourceAsStream("config/mysql.properties"));
        dataSource.setDriverClassName(props.getProperty("MYSQL_DB_DRIVER_CLASS"));
        dataSource.setUrl(props.getProperty("MYSQL_DB_URL"));
        dataSource.setUsername(props.getProperty("MYSQL_DB_USERNAME"));
        dataSource.setPassword(props.getProperty("MYSQL_DB_PASSWORD"));

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return source = dataSource;
}

From source file:com.sap.prd.mobile.ios.mios.SCMUtil.java

public static String getConnectionString(final Properties versionInfo,
        final boolean hideConfidentialInformation) throws IOException {

    final String type = versionInfo.getProperty("type");

    final StringBuilder connectionString = new StringBuilder(128);

    if (type != null && type.equals("git")) {

        final String repo = versionInfo.getProperty("repo");

        if (StringUtils.isBlank(repo)) {
            if (!StringUtils.isBlank(versionInfo.getProperty("repo_1"))) {
                throw new IllegalStateException(
                        "Multipe git repositories provided. This use case is not supported. Provide only one git repository.");
            }/*from   www  .j  ava2s.  c o m*/
            throw new IllegalStateException("No git repository provided. ");
        }

        if (hideConfidentialInformation) {
            try {
                URI uri = new URI(repo);
                int port = uri.getPort();
                if (port == -1) {
                    final String scheme = uri.getScheme();
                    if (scheme != null && gitDefaultPorts.containsKey(scheme)) {
                        port = gitDefaultPorts.get(scheme);
                    }
                }
                connectionString.append(port);

                if (uri.getHost() != null) {
                    connectionString.append(uri.getPath());
                }
            } catch (URISyntaxException e) {
                throw new IllegalStateException(String.format("Invalid repository uri: %s", repo));
            }
        } else {
            connectionString.append(PROTOCOL_PREFIX_GIT).append(repo);
        }

    } else {

        final String port = versionInfo.getProperty("port");

        if (StringUtils.isBlank(port))
            throw new IllegalStateException("No SCM port provided.");

        final String depotPath = versionInfo.getProperty("depotpath");

        if (hideConfidentialInformation) {
            try {
                URI perforceUri = new URI("perforce://" + port);

                int _port = perforceUri.getPort();
                if (_port == -1) {
                    _port = PERFORCE_DEFAULT_PORT;
                }
                connectionString.append(_port);
                connectionString.append(depotPath);
            } catch (URISyntaxException e) {
                throw new IllegalStateException(String.format("Invalid port: %s", port));
            }
        } else {

            if (StringUtils.isBlank(depotPath))
                throw new IllegalStateException("No depot path provided.");

            connectionString.append(PROTOCOL_PREFIX_PERFORCE).append(port).append(":")
                    .append(getDepotPath(depotPath));
        }
    }

    return connectionString.toString();
}

From source file:com.liferay.portal.test.TestUtil.java

public static List<String> getPortletConfigLocations(String portletName) throws Exception {
    String basePath = getFullBasePath();

    String docrootPath = "/portlets/" + portletName + "/docroot/";

    String path = basePath + docrootPath + "WEB-INF/src/service.properties";
    Properties props = new Properties();
    FileInputStream fis = new FileInputStream(path);
    props.load(fis);/*w  w w . j ava  2  s .c om*/
    String springConfigs = props.getProperty("spring.configs");
    String[] configs = com.liferay.portal.kernel.util.StringUtil.split(springConfigs, ",");
    List<String> configLocations = new ArrayList<String>();

    for (int i = 0; i < configs.length; i++) {
        String config = configs[i];
        String fullPath = docrootPath + config;
        //Only include files which are actually present, e.g. ext-spring.xml
        // isn't required to be there but is automatically included in the spring.configs
        if (FileUtil.exists(basePath + fullPath)) {
            _log.info("Including config file: " + fullPath);
            configLocations.add(fullPath);
        }
    }

    //Also add in the test xml if present
    String testPath = docrootPath + "WEB-INF/classes/META-INF/ext-spring-test.xml";
    if (FileUtil.exists(basePath + testPath)) {
        configLocations.add(testPath);
    }

    return configLocations;
}

From source file:org.spring.data.gemfire.AbstractGemFireIntegrationTest.java

protected static ServerLauncher startGemFireServer(final long waitTimeout, final String cacheXmlPathname,
        final Properties gemfireProperties) throws IOException {
    String gemfireMemberName = gemfireProperties.getProperty(DistributionConfig.NAME_NAME);
    String serverId = DATE_FORMAT.format(Calendar.getInstance().getTime());

    gemfireMemberName = String.format("%1$s-%2$s",
            (StringUtils.hasText(gemfireMemberName) ? gemfireMemberName : ""), serverId);

    File serverWorkingDirectory = FileSystemUtils.createFile(gemfireMemberName.toLowerCase());

    Assert.isTrue(FileSystemUtils.createDirectory(serverWorkingDirectory),
            String.format("Failed to create working directory (%1$s) in which the GemFire Server will run!",
                    serverWorkingDirectory));

    ServerLauncher serverLauncher = buildServerLauncher(cacheXmlPathname, gemfireProperties, serverId,
            DEFAULT_SERVER_PORT, serverWorkingDirectory);

    List<String> serverCommandLine = buildServerCommandLine(serverLauncher);

    System.out.printf("Starting GemFire Server in (%1$s)...%n", serverWorkingDirectory);

    Process serverProcess = ProcessUtils.startProcess(
            serverCommandLine.toArray(new String[serverCommandLine.size()]), serverWorkingDirectory);

    readProcessStream(serverId, "ERROR", serverProcess.getErrorStream());
    readProcessStream(serverId, "OUT", serverProcess.getInputStream());
    waitOnServer(waitTimeout, serverProcess, serverWorkingDirectory);

    return serverLauncher;
}

From source file:com.pieframework.runtime.core.Installer.java

public static void createConfigFile(Properties prop) {

    try {//from w w  w  .j a va2s  . c  om
        File pieConfig = new File(prop.getProperty("pie.config"));
        //Backup the config file if it exists
        if (pieConfig.exists()) {
            File backup = new File(pieConfig.getPath() + "." + TimeUtils.getCurrentTimeStamp());
            FileUtils.copyFile(pieConfig, backup);
        }

        //Create/Overwrite the config file
        OutputStream out = new FileOutputStream(pieConfig);
        prop.store(out, getComments());
        System.out.println("Created config file: " + pieConfig.getPath());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:de.thischwa.pmcms.tool.ToolVersionInfo.java

private static Map<TYPE, String> getInfoFromMetaPom(final String groupId, final String artifactId) {
    String pomPath = String.format("META-INF/maven/%s/%s/pom.properties", groupId, artifactId);
    Map<TYPE, String> info = new HashMap<TYPE, String>(2);
    info.put(TYPE.title, "unknown");
    info.put(TYPE.version, "n/n");

    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(pomPath);
    if (in != null) {
        Properties properties = new Properties();
        try {//from ww w.ja  v  a 2s  . co m
            in = new BufferedInputStream(in);
            properties.load(in);
        } catch (IOException ex) {
        }

        String title = properties.getProperty("artifactId");
        String version = properties.getProperty("version");
        if (title != null)
            info.put(TYPE.title, title);
        if (version != null)
            info.put(TYPE.version, version);
    }
    return info;
}

From source file:com.github.tddts.jet.util.Util.java

/**
 * Load property with given key from given property file.
 *
 * @param fileName property file path/*  w  ww .  jav a2  s  . c  om*/
 * @param key      property key
 * @return property value
 */
public static String loadProperty(String fileName, String key) {
    try {
        File file = new File(fileName);

        if (!file.exists())
            return null;

        Properties properties = new Properties();

        try (InputStream in = FileUtils.openInputStream(file)) {
            properties.load(in);
        }

        return properties.getProperty(key);

    } catch (IOException e) {
        throw new ApplicationException(e);
    }
}

From source file:com.redhat.poc.jdg.bankofchina.function.TestCase413RemoteMultiThreads.java

public static String jdgProperty(String name) {
    Properties props = new Properties();
    try {/* w  w  w.  j  ava2  s .c om*/
        props.load(TestCase413RemoteMultiThreads.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE));
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    return props.getProperty(name);
}

From source file:org.unbunt.ella.lang.sql.DBUtils.java

public static DriverManagerDataSource createDataSourceFromProps(Properties props, String user, String pass,
        String classOrType) throws DBConnectionFailedException {
    // canonicalize user/username property
    if (props.getProperty("username") != null && props.getProperty("user") == null) {
        props.setProperty("user", props.getProperty("username"));
    } else if (props.getProperty("user") != null && props.getProperty("username") == null) {
        props.setProperty("username", props.getProperty("user"));
    }//from   w  w  w.  j a  v  a 2  s  . c o  m

    String url = props.getProperty("url");
    if (url == null) {
        throw new DBConnectionFailedException("Missing url property");
    }

    if (user == null) {
        user = props.getProperty("username");
    }
    if (pass == null) {
        pass = props.getProperty("password");
    }

    if (classOrType == null) {
        classOrType = props.getProperty("type");
    }
    if (classOrType == null) {
        classOrType = props.getProperty("driverClassName");
    }

    return createDataSourceInternal(props, url, user, pass, classOrType);
}