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.impetus.client.neo4j.Neo4JClient.java

/**
 * Returns instance of {@link BatchInserter}.
 * //  ww  w. j av  a2 s.c o m
 * @return the batch inserter
 */
protected BatchInserter getBatchInserter() {
    PersistenceUnitMetadata puMetadata = kunderaMetadata.getApplicationMetadata()
            .getPersistenceUnitMetadata(getPersistenceUnit());
    Properties props = puMetadata.getProperties();

    // Datastore file path
    String datastoreFilePath = (String) props.get(PersistenceProperties.KUNDERA_DATASTORE_FILE_PATH);
    if (StringUtils.isEmpty(datastoreFilePath)) {
        throw new PersistenceException(
                "For Neo4J, it's mandatory to specify kundera.datastore.file.path property in persistence.xml");
    }

    // Shut down Graph DB, at a time only one service may have lock on DB
    // file
    if (factory.getConnection() != null) {
        factory.getConnection().shutdown();
    }

    BatchInserter inserter = null;

    // Create Batch inserter with configuration if specified
    Neo4JSchemaMetadata nsmd = Neo4JPropertyReader.nsmd;
    ClientProperties cp = nsmd != null ? nsmd.getClientProperties() : null;
    if (cp != null) {
        DataStore dataStore = nsmd != null ? nsmd.getDataStore() : null;
        Properties properties = dataStore != null && dataStore.getConnection() != null
                ? dataStore.getConnection().getProperties()
                : null;

        if (properties != null) {
            Map<String, String> config = new HashMap<String, String>((Map) properties);
            inserter = BatchInserters.inserter(datastoreFilePath, config);
        }
    }

    // Create Batch inserter without configuration if not provided
    if (inserter == null) {
        inserter = BatchInserters.inserter(datastoreFilePath);
    }
    return inserter;
}

From source file:org.openmrs.web.controller.report.CohortReportFormController.java

/**
 * @see org.springframework.web.servlet.mvc.SimpleFormController#referenceData(javax.servlet.http.HttpServletRequest)
 *//*w w  w . j  a  va  2s .  c  o m*/
@Override
protected Map<String, Object> referenceData(HttpServletRequest request) throws Exception {
    Map<String, Object> ret = new HashMap<String, Object>();

    List<Class<?>> classes = new ArrayList<Class<?>>();
    classes.add(Date.class);
    classes.add(Integer.class);
    classes.add(Double.class);
    classes.add(Location.class);
    ret.put("parameterClasses", classes);

    ReportObjectService rs = (ReportObjectService) Context.getService(ReportObjectService.class);
    List<AbstractReportObject> searches = rs
            .getReportObjectsByType(OpenmrsConstants.REPORT_OBJECT_TYPE_PATIENTSEARCH);
    Map<String, String> map = new LinkedHashMap<String, String>();
    for (AbstractReportObject o : searches) {
        if (o instanceof PatientSearchReportObject) {
            StringBuilder searchName = new StringBuilder(o.getName());
            List<Parameter> parameters = ((PatientSearchReportObject) o).getPatientSearch().getParameters();
            if (parameters != null && !parameters.isEmpty()) {
                searchName.append("|");
                for (Iterator<Parameter> i = parameters.iterator(); i.hasNext();) {
                    Parameter p = i.next();
                    searchName.append(p.getName()).append("=${?}");
                    if (i.hasNext()) {
                        searchName.append(",");
                    }
                }
            }
            map.put(searchName.toString(), o.getDescription());
        } else {
            map.put(o.getName(), o.getDescription());
        }
    }
    ret.put("patientSearches", map);

    ReportService rptSvc = (ReportService) Context.getService(ReportService.class);
    Properties macros = rptSvc.getReportXmlMacros();
    map = new LinkedHashMap<String, String>();
    for (Map.Entry<Object, Object> e : macros.entrySet()) {
        if (!e.getKey().toString().equals("macroPrefix") && !e.getKey().toString().equals("macroSuffix"))
            map.put(e.getKey().toString(), e.getValue().toString());
    }
    ret.put("macros", map);
    ret.put("macroPrefix", macros.get("macroPrefix"));
    ret.put("macroSuffix", macros.get("macroSuffix"));

    return ret;
}

From source file:com.wabacus.config.ConfigLoadManager.java

public static Map convertPropertiesToResources(Properties props) {
    Map mResults = new HashMap();
    if (props == null || props.isEmpty()) {
        return null;
    }/*from   w ww  .j  a  va  2  s. c  o m*/
    Iterator itKeys = props.keySet().iterator();
    while (itKeys.hasNext()) {
        String key = (String) itKeys.next();
        String value = (String) props.get(key);
        //                try
        //                    e.printStackTrace();
        if (mResults.containsKey(key)) {
            throw new WabacusConfigLoadingException(
                    "??key" + key + "???");
        }
        mResults.put(key, value);
    }
    return mResults;
}

From source file:org.springweb.core.MutilPropertyPlaceholderConfigurer.java

@Override
protected Properties mergeProperties() throws IOException {
    Properties mergeProperties = super.mergeProperties();
    // properties
    this.properties = new Properties();
    // ,mode//from  w ww  .j a v  a 2  s  .co m
    String mode = System.getProperty(PRODUCTION_MODE);
    if (StringUtils.isEmpty(mode)) {
        String str = mergeProperties.getProperty(PRODUCTION_MODE);
        mode = str != null ? str : "ONLINE";
    }
    properties.put(PRODUCTION_MODE, mode);
    String[] modes = mode.split(",");
    Set<Entry<Object, Object>> es = mergeProperties.entrySet();
    for (Entry<Object, Object> entry : es) {
        String key = (String) entry.getKey();
        int idx = key.lastIndexOf('_');
        String realKey = idx == -1 ? key : key.substring(0, idx);
        if (!properties.containsKey(realKey)) {
            Object value = null;
            for (String md : modes) {
                value = mergeProperties.get(realKey + "_" + md);
                if (value != null) {
                    properties.put(realKey, value);
                    break;
                }
            }
            if (value == null) {
                value = mergeProperties.get(realKey);
                if (value != null) {
                    properties.put(realKey, value);
                } else {
                    throw new RuntimeException("impossible empty property for " + realKey);
                }
            }
        }
    }
    return properties;
}

From source file:eu.earthobservatory.org.StrabonEndpoint.Authenticate.java

/**
 * Authenticate user/*from  ww w  .j  av  a  2  s . co m*/
 * @throws IOException 
 * */
public boolean authenticateUser(String authorization, ServletContext context) throws IOException {
    Properties properties = new Properties();
    if (authorization == null)
        return false; // no authorization

    if (!authorization.toUpperCase().startsWith("BASIC "))
        return false; // only BASIC authentication

    // get encoded user and password, comes after "BASIC "
    String userpassEncoded = authorization.substring(6);
    // decode 
    String userpassDecoded = new String(Base64.decodeBase64(userpassEncoded));

    Pattern pattern = Pattern.compile(":");
    String[] credentials = pattern.split(userpassDecoded);
    // get credentials.properties as input stream
    InputStream input = new FileInputStream(context.getRealPath(CREDENTIALS_PROPERTIES_FILE));

    // load the properties
    properties.load(input);

    // close the stream
    input.close();

    // check if the given credentials are allowed       
    if (!userpassDecoded.equals(":") && credentials[0].equals(properties.get("username"))
            && credentials[1].equals(properties.get("password")))
        return true;
    else
        return false;
}

From source file:org.geoserver.wps.gs.GeorectifyConfiguration.java

/**
 * Load the configured parameters through the properties file. TODO: Move to XML instead of
 * properties file//from w w  w. ja  v  a 2  s  .  c o  m
 * 
 * @throws IOException
 */
private void loadConfig() throws IOException {
    final boolean hasPropertiesFile = configFile != null && configFile.getType() == Type.RESOURCE;

    if (hasPropertiesFile) {
        Properties props = new Properties();
        InputStream fis = null;
        try {
            fis = configFile.in();
            props.load(fis);
            Iterator<Object> keys = props.keySet().iterator();
            envVariables = Maps.newHashMap();
            while (keys.hasNext()) {
                String key = (String) keys.next();
                if (key.equalsIgnoreCase(GRKeys.GDAL_CACHEMAX)) {
                    // Setting GDAL_CACHE_MAX Environment variable if available
                    String cacheMax = null;
                    try {
                        cacheMax = (String) props.get(GRKeys.GDAL_CACHEMAX);
                        if (cacheMax != null) {
                            int gdalCacheMaxMemory = Integer.parseInt(cacheMax); // Only for validation
                            envVariables.put(GRKeys.GDAL_CACHEMAX, cacheMax);
                        }
                    } catch (NumberFormatException nfe) {
                        if (LOGGER.isLoggable(Level.WARNING)) {
                            LOGGER.log(Level.WARNING,
                                    "Unable to parse the specified property as a number: " + cacheMax, nfe);
                        }
                    }
                } else if (key.equalsIgnoreCase(GRKeys.GDAL_DATA)
                        || key.equalsIgnoreCase(GRKeys.GDAL_LOGGING_DIR)
                        || key.equalsIgnoreCase(GRKeys.TEMP_DIR)) {
                    // Parsing specified folder path
                    String path = (String) props.get(key);
                    if (path != null) {
                        final File directory = new File(path);
                        if (directory.exists() && directory.isDirectory()
                                && ((key.equalsIgnoreCase(GRKeys.GDAL_DATA) && directory.canRead())
                                        || directory.canWrite())) {
                            envVariables.put(key, path);
                        } else {
                            if (LOGGER.isLoggable(Level.WARNING)) {
                                LOGGER.log(Level.WARNING, "The specified folder for " + key
                                        + " variable isn't valid, "
                                        + "or it doesn't exist or it isn't a readable directory or it is a "
                                        + "destination folder which can't be written: " + path);
                            }
                        }
                    }
                } else if (key.equalsIgnoreCase(GRKeys.EXECUTION_TIMEOUT)) {
                    // Parsing execution timeout
                    String timeout = null;
                    try {
                        timeout = (String) props.get(GRKeys.EXECUTION_TIMEOUT);
                        if (timeout != null) {
                            executionTimeout = Long.parseLong(timeout); // Only for validation
                        }
                    } catch (NumberFormatException nfe) {
                        if (LOGGER.isLoggable(Level.WARNING)) {
                            LOGGER.log(Level.WARNING,
                                    "Unable to parse the specified property as a number: " + timeout, nfe);
                        }
                    }
                } else if (key.equalsIgnoreCase(GRKeys.GDAL_WARP_PARAMS)
                        || key.equalsIgnoreCase(GRKeys.GDAL_TRANSLATE_PARAMS)) {
                    // Parsing gdal operations custom option parameters
                    String param = (String) props.get(key);
                    if (param != null) {
                        if (key.equalsIgnoreCase(GRKeys.GDAL_WARP_PARAMS)) {
                            gdalWarpingParameters = param.trim();
                        } else {
                            gdalTranslateParameters = param.trim();
                        }
                    }
                } else if (key.endsWith("PATH")) {
                    // Dealing with properties like LD_LIBRARY_PATH, PATH, ...
                    String param = (String) props.get(key);
                    if (param != null) {
                        envVariables.put(key, param);
                    }
                }
            }

        } catch (FileNotFoundException e) {
            if (LOGGER.isLoggable(Level.WARNING)) {
                LOGGER.log(Level.WARNING, "Unable to parse the config file: " + configFile.path(), e);
            }

        } catch (IOException e) {
            if (LOGGER.isLoggable(Level.WARNING)) {
                LOGGER.log(Level.WARNING, "Unable to parse the config file: " + configFile.path(), e);
            }
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (Throwable t) {
                    // Does nothing
                }
            }
        }
    }
}

From source file:com.flexive.tests.browser.AbstractSeleniumTest.java

/**
 * Selenium setup code. Override this method in your actual test class and don't forget
 * to add the @BeforeClass annotation.//from   www  .  ja  v  a 2  s  .c o m
 */
@BeforeClass
public void beforeClass() {
    final Properties properties = new Properties(defaultProperties);
    if (StringUtils.isNotBlank(configName)) {
        try {
            InputStream inStream = this.getClass().getClassLoader().getResourceAsStream(configName);
            if (inStream == null) {
                String msg = "Missing " + configName
                        + " file in src/framework/tests/java/com/flexive/tests/browser - copy from provided sample";
                LOG.error(msg);
                throw new RuntimeException(msg);
            }
            properties.load(inStream);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    if (this.initialUrl == null) {
        this.initialUrl = (String) properties.get(PROP_BASEURL);
    }
    final int port = Integer.parseInt(properties.getProperty(PROP_PORT, "80"));
    final String host = properties.getProperty(PROP_HOST, "localhost");
    final String browserStart = properties.getProperty(PROP_BROWSER_START, "*firefox");
    if (LOG.isInfoEnabled()) {
        LOG.info("Connecting to Selenium Server at " + host + ":" + port + "...");
        LOG.info("Base URL: " + this.initialUrl);
    }

    /**
     *
     *
     *  *firefox
     *mock
     *firefoxproxy
     *pifirefox
     *chrome
     *iexploreproxy
     *iexplore
     *firefox3
     *safariproxy
     *googlechrome
     *konqueror
     *firefox2
     *safari
     *piiexplore
     *firefoxchrome
     *opera
     *iehta
     */
    //        commandProcessor = new HttpCommandProcessor(host, port, "*iexploreproxy", initialUrl);
    commandProcessor = new HttpCommandProcessor(host, port, browserStart, initialUrl);
    selenium = new FlexiveSelenium(commandProcessor);
    LOG.info("using browser : " + browserStart.substring(1));
    selenium.start();
    selenium.createCookie(FxSharedUtils.COOKIE_FORCE_TEST_DIVISION + "=true", "path=/");
    try {
        LOG.info(selenium.getCookie());
    } catch (Throwable t) {
        LOG.error(t.getMessage());
    }
    //        LOG.error("Create Test-cookie DISABLED!!!");
}

From source file:pl.project13.maven.git.GitCommitIdMojoIntegrationTest.java

@Test
@Parameters(method = "useNativeGit")
public void shouldExtractTagsOnGivenCommit(boolean useNativeGit) throws Exception {
    // given/*from   w  w w .j  a  va 2 s. com*/
    mavenSandbox.withParentProject("my-jar-project", "jar").withNoChildProject()
            .withGitRepoInParent(AvailableGitTestRepo.WITH_COMMIT_THAT_HAS_TWO_TAGS).create();

    try (final Git git = git("my-jar-project")) {
        git.reset().setMode(ResetCommand.ResetType.HARD).setRef("d37a598").call();
    }

    MavenProject targetProject = mavenSandbox.getParentProject();
    setProjectToExecuteMojoIn(targetProject);

    alterMojoSettings("gitDescribe", null);
    alterMojoSettings("useNativeGit", useNativeGit);

    // when
    mojo.execute();

    // then
    Properties properties = targetProject.getProperties();
    assertGitPropertiesPresentInProject(properties);

    assertThat(properties).satisfies(new ContainsKeyCondition("git.tags"));
    assertThat(properties.get("git.tags").toString()).doesNotContain("refs/tags/");

    assertThat(Splitter.on(",").split(properties.get("git.tags").toString())).containsOnly("lightweight-tag",
            "newest-tag");
}

From source file:org.duracloud.duradmin.spaces.controller.SnapshotController.java

@RequestMapping(value = "/spaces/snapshot", method = RequestMethod.GET)
public ModelAndView get(@RequestParam String storeId, @RequestParam String spaceId) {

    Properties props = new Properties();
    try {// www.  j av  a 2  s  .  c om
        ContentStore store = this.contentStoreManager.getContentStore(storeId);
        if (store.contentExists(spaceId, Constants.SNAPSHOT_PROPS_FILENAME)) {
            try (InputStream is = store.getContent(spaceId, Constants.SNAPSHOT_PROPS_FILENAME).getStream()) {
                props.load(is);
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        props.put("error", "Snapshot properties could not be loaded: " + e.getMessage());
    }

    ModelAndView mav = new ModelAndView("jsonView");
    for (Object key : props.keySet()) {
        mav.addObject(key.toString(), props.get(key));
    }
    return mav;
}

From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexerSettings.java

@Override
public void initProperties(Properties properties) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(properties.getProperty("provider", "org.postgresql.Driver"));
    dataSource.setUrl(properties.getProperty("url"));
    dataSource.setUsername(properties.getProperty("username"));
    dataSource.setPassword(properties.getProperty("password"));
    this.setDataSource(dataSource);
    this.setIndexGraph((IndexGraph) properties.get("index-graph"));
    this.tableName = properties.getProperty("index-table");
}