List of usage examples for java.util Properties get
@Override
public Object get(Object key)
From source file:jp.terasoluna.fw.web.struts.action.GlobalMessageResources.java
/** * v?peBt@C?A}bvl?s?B/* ww w . j a v a 2 s . c o m*/ */ private synchronized void globalInit() { // ?bZ?[WNA fwMessages.clear(); // ?bZ?[W\?[Xt@C??[h?B Properties prop = PropertyUtil.loadProperties(this.config); if (prop == null) { // ???s?I?B return; } Enumeration keyEnum = prop.propertyNames(); while (keyEnum.hasMoreElements()) { Object keyObj = keyEnum.nextElement(); Object value = prop.get(keyObj); if (log.isDebugEnabled()) { log.debug("Saving framework message key [" + keyObj + "]" + "value [" + value + "]"); } fwMessages.put((String) keyObj, (String) value); } }
From source file:com.agiletec.plugins.jpcrowdsourcing.aps.system.services.idea.ApiIdeaInterface.java
public StringApiResponse addIdea(JAXBIdea jaxbIdea, Properties properties) throws ApiException, Throwable { StringApiResponse response = new StringApiResponse(); try {//from w w w.j a v a2s.c o m UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER); String langCode = (String) properties.get(SystemConstants.API_LANG_CODE_PARAMETER); String instanceCode = jaxbIdea.getInstanceCode(); IdeaInstance instance = this.getIdeaInstanceManager().getIdeaInstance(instanceCode); if (null == instance) { _logger.warn("instance {} not found", instanceCode); throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "IdeaInstance with code '" + instanceCode + "' does not exist", Response.Status.CONFLICT); } if (!isAuthOnInstance(user, instance)) { _logger.warn("the current user is not granted to any group required by instance {}", instance.getCode()); throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "IdeaInstance with code '" + instance.getCode() + "' does not exist", Response.Status.CONFLICT); } if (StringUtils.isBlank(jaxbIdea.getTitle())) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Title is required", Response.Status.CONFLICT); } if (StringUtils.isBlank(jaxbIdea.getDescr())) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Description is required", Response.Status.CONFLICT); } if (null == jaxbIdea.getTags() || jaxbIdea.getTags().isEmpty()) { throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Tags is required", Response.Status.CONFLICT); } Set<String> tags = this.joinCategories(jaxbIdea, langCode); Idea idea = jaxbIdea.getIdea(); idea.setTags(new ArrayList<String>(tags)); idea.setUsername(user.getUsername()); this.getIdeaManager().addIdea(idea); response.setResult(IResponseBuilder.SUCCESS, null); } catch (ApiException ae) { response.addErrors(ae.getErrors()); response.setResult(IResponseBuilder.FAILURE, null); } catch (Throwable t) { _logger.error("Error on add idea", t); throw new ApsSystemException("Error on add idea", t); } return response; }
From source file:it.geosolutions.geobatch.imagemosaic.ImageMosaicUpdater.java
/** * Try to update the datastore using the passed command and the * mosaicDescriptor as data and/* w ww . j a v a 2 s . com*/ * * @param mosaicProp * @param dataStoreProp * @param mosaicDescriptor * @param cmd * @return boolean representing the operation success (true) or failure * (false) * @throws IOException * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException * @throws IllegalArgumentException */ protected static boolean updateDataStore(Properties mosaicProp, Properties dataStoreProp, ImageMosaicGranulesDescriptor mosaicDescriptor, ImageMosaicCommand cmd) throws IOException { if (mosaicProp == null) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Unable to get mosaic properties."); } return false; } DataStore dataStore = null; try { // create the datastore dataStore = getDataStore(dataStoreProp); boolean absolute = isTrue(mosaicProp.get(org.geotools.gce.imagemosaic.Utils.Prop.ABSOLUTE_PATH)); // does the layer use absolute path? if (!absolute) { /* * if we have some absolute path into delFile list we have to * skip those files since the layer is relative and acceptable * (to deletion) passed path are to be relative */ List<File> files = null; if ((files = cmd.getDelFiles()) != null) { for (File file : files) { if (file.isAbsolute()) { /* * this file can still be acceptable since it can be * child of the layer baseDir */ final String path = file.getAbsolutePath(); if (!path.contains(cmd.getBaseDir().getAbsolutePath())) { // the path is absolute AND the file is outside // the layer baseDir! // files.remove(file); // remove it // TODO move into a recoverable path to // rollback! // log as warning if (LOGGER.isWarnEnabled()) { LOGGER.warn("Layer specify a relative pattern for files but the " + "incoming xml command file has an absolute AND outside the layer baseDir file into the " + "delFile list! This file will NOT be removed from the layer: " + file.getAbsolutePath()); } } } } } } // TODO check object cast // the attribute key location final String locationKey = (String) mosaicProp .get(org.geotools.gce.imagemosaic.Utils.Prop.LOCATION_ATTRIBUTE); final String store = mosaicDescriptor.getCoverageStoreId(); final List<File> delList = cmd.getDelFiles(); Filter delFilter = null; // query if (!CollectionUtils.isEmpty(delList)) { try { delFilter = getQuery(delList, absolute, locationKey); } catch (Exception e) { if (LOGGER.isErrorEnabled()) { LOGGER.error("Unable to build a query. Message: " + e, e); } return false; } // REMOVE features if (!removeFeatures(dataStore, store, delFilter)) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Failed to remove features."); } } else { // // should we remove the files for good? #81 // do we want to back them up? #84 // final File backUpDirectory = cmd.getBackupDirectory(); if (cmd.isDeleteGranules()) { boolean delete = true; if (backUpDirectory != null) { //if we don't manage to move, we try to cancel delete = (!backUpGranulesFiles(cmd.getDelFiles(), backUpDirectory)); } // delete if (delete) { deleteGranulesFiles(cmd.getDelFiles()); } } } } else { if (LOGGER.isInfoEnabled()) { LOGGER.info("No items to delete"); } } //======================================== // Handle the addFiles list //======================================== // if it's empty, we'll return anyway. The config is telling us if it's a problem or not. // Notice that a un/marshalled empty list willb e probabily set to null if (CollectionUtils.isEmpty(cmd.getAddFiles())) { if (cmd.isIgnoreEmptyAddList()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("No items to add"); } return true; } else { if (LOGGER.isErrorEnabled()) { LOGGER.error("addFiles list is empty."); } return false; } } // Remove from addList the granules already in the mosaic. // TODO remove (ALERT please remove existing file from destination // for the copyListFileToNFS() if (!purgeAddFileList(cmd.getAddFiles(), dataStore, store, locationKey, cmd.getBaseDir(), absolute)) { return false; } // ////////////////////////////////// if (cmd.getAddFiles() == null) { // side effect in previous method call? should not happen. if (LOGGER.isErrorEnabled()) { LOGGER.error("Filtered addFiles list is null."); } return false; } else if (cmd.getAddFiles().isEmpty()) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("All requested files are already in the mosaic."); } return true; } else if (cmd.getAddFiles().size() > 0) { /* * copy purged addFiles list of files to the baseDir and replace * addFiles list with the new copied file list */ // store copied file for rollback purpose List<File> addedFile = null; if (!absolute) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Starting file copy (" + cmd.getAddFiles().size() + " file/s)"); } addedFile = Copy.copyListFileToNFS(cmd.getAddFiles(), cmd.getBaseDir(), false, cmd.getNFSCopyWait()); } if (!addFileToStore(addedFile, dataStore, store, locationKey, cmd.getBaseDir())) { if (LOGGER.isErrorEnabled()) LOGGER.error("Unable to update the new layer, removing copied files..."); // if fails rollback the copied files if (addedFile != null) { for (File file : addedFile) { if (LOGGER.isWarnEnabled()) LOGGER.warn("ImageMosaicAction: DELETING -> " + file.getAbsolutePath()); // this is done since addedFiles are copied not moved file.delete(); } } } } // addFiles size > 0 } catch (Exception e) { if (LOGGER.isErrorEnabled()) { LOGGER.error(e.getLocalizedMessage(), e); } return false; } finally { if (dataStore != null) { try { dataStore.dispose(); } catch (Throwable t) { if (LOGGER.isWarnEnabled()) { LOGGER.warn(t.getLocalizedMessage(), t); } } } } return true; }
From source file:info.magnolia.cms.beans.config.PropertiesInitializer.java
private void resolveNestedProperties() { Properties sysProps = SystemProperty.getProperties(); for (Iterator<Object> it = sysProps.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); String oldValue = (String) sysProps.get(key); String value = parseStringValue(oldValue, new HashSet<String>()); SystemProperty.getProperties().put(key, value.trim()); }/*w ww . java2 s. c om*/ }
From source file:de.uzk.hki.da.grid.IrodsCommandLineConnector.java
/** * Parses parses result set for a given AVU * @author Jens Peters//from w w w .j a va 2s. c o m * @param result * @param field * @return * @throws IOException */ private String parseResultForAVUField(String result, String field) throws IOException { String[] props = result.split("------------------------------------------------------------"); for (int i = 0; i < props.length; i++) { Properties properties = new Properties(); StringReader sr = new StringReader(props[i]); properties.load(sr); sr.close(); if (properties.get(field) != null) { return properties.get(field).toString(); } } return ""; }
From source file:net.padlocksoftware.padlock.license.LicenseImpl.java
protected LicenseImpl(Properties properties) { logger = Logger.getLogger(getClass().getName()); props = new Properties(); for (String key : propertyNames(properties)) { props.put(key, properties.get(key)); }// ww w .ja v a2s . c o m // Check for mandatory fields // Creation Date must exist Date creationDate = getCreationDate(); if (creationDate == null) { throw new ImportException("Creation date is invalid"); } // Start date must exist Date startDate = getStartDate(); if (startDate == null) { throw new ImportException("Start date is invalid"); } // Manually get the expiration date, since the public method may // return null. We need to differentiate a missing date from an // invalid date. String expString = props.getProperty("expirationDate"); if (expString != null) { try { new Date(Long.parseLong(expString)); } catch (NumberFormatException e) { throw new ImportException("Expiration date is invalid"); } } // If the license has a version entry, it must be valid String version = props.getProperty("version"); if (version != null) { try { Integer.parseInt(version); } catch (Exception e) { throw new ImportException("License version is invalid"); } } }
From source file:com.photon.phresco.impl.ConfigManagerImpl.java
private void createProperties(Element configNode, Properties properties) { Set<Object> keySet = properties.keySet(); for (Object key : keySet) { String value = (String) properties.get(key); Element propNode = document.createElement(key.toString()); propNode.setTextContent(value);//from w w w.jav a 2s . c o m configNode.appendChild(propNode); } }
From source file:com.impetus.kundera.tests.crossdatastore.useraddress.AssociationBase.java
private void truncateRedis() { if (RedisPropertyReader.rsmd != null) { PersistenceUnitMetadata puMetadata = kunderaMetadata.getApplicationMetadata() .getPersistenceUnitMetadata("redis"); Properties props = puMetadata.getProperties(); String contactNode = RedisPropertyReader.rsmd.getHost() != null ? RedisPropertyReader.rsmd.getHost() : (String) props.get(PersistenceProperties.KUNDERA_NODES); String defaultPort = RedisPropertyReader.rsmd.getPort() != null ? RedisPropertyReader.rsmd.getPort() : (String) props.get(PersistenceProperties.KUNDERA_PORT); String password = RedisPropertyReader.rsmd.getPassword() != null ? RedisPropertyReader.rsmd.getPassword() : (String) props.get(PersistenceProperties.KUNDERA_PASSWORD); Jedis connection = new Jedis(contactNode, Integer.valueOf(defaultPort)); connection.auth(password);//w ww. j ava 2 s . c om connection.connect(); connection.flushDB(); } }
From source file:com.iver.utiles.connections.ConnectionDB.java
/** * Returns the data of the connection/*w ww.j av a 2s.c o m*/ * * @return Array of data connections * * @throws IOException */ public ConnectionTrans[] getPersistence() throws IOException { ArrayList conns = new ArrayList(); String directory = FileUtils.getAppHomeDir() + "connections"; File dir = new File(directory); File[] files = dir.listFiles(); if (files == null) return null; for (int i = 0; i < files.length; i++) { Properties properties = new Properties(); FileInputStream in = new FileInputStream(files[i]); properties.load(in); in.close(); ConnectionTrans ct = new ConnectionTrans(); ct.setDriver(properties.get("jdbc.drivers").toString()); ct.setName(properties.get("jdbc.name").toString()); ct.setHost(properties.get("jdbc.host").toString()); ct.setPort(properties.get("jdbc.port").toString()); ct.setUser(properties.get("jdbc.username").toString()); boolean isSave = Boolean.valueOf(properties.get("jdbc.savepassword").toString()).booleanValue(); ct.setSavePassword(isSave); if (isSave) { ct.setPassword(properties.get("jdbc.password").toString()); } ct.setDb(properties.get("jdbc.database").toString()); ct.setConnBegining(properties.get("jdbc.connBeginning").toString()); conns.add(ct); } return (ConnectionTrans[]) conns.toArray(new ConnectionTrans[0]); }
From source file:com.glaf.jbpm.connection.HikariCPConnectionProvider.java
public void configure(Properties props) throws RuntimeException { Properties properties = new Properties(); properties.putAll(props);//from w w w . j a v a2s.com for (Iterator<?> ii = props.keySet().iterator(); ii.hasNext();) { String key = (String) ii.next(); if (key.startsWith("hikari.")) { String newKey = key.substring(7); properties.put(newKey, props.get(key)); } } String jdbcDriverClass = properties.getProperty(Environment.DRIVER); String jdbcUrl = properties.getProperty(Environment.URL); Properties connectionProps = ConnectionProviderFactory.getConnectionProperties(properties); log.info("HikariCP using driver: " + jdbcDriverClass + " at URL: " + jdbcUrl); log.info("Connection properties: " + PropertiesHelper.maskOut(connectionProps, Environment.PASS)); autocommit = PropertiesHelper.getBoolean(Environment.AUTOCOMMIT, props); log.info("autocommit mode: " + autocommit); if (jdbcDriverClass == null) { log.warn("No JDBC Driver class was specified by property " + Environment.DRIVER); } else { try { Class.forName(jdbcDriverClass); } catch (ClassNotFoundException cnfe) { try { ClassUtils.classForName(jdbcDriverClass); } catch (Exception e) { String msg = "JDBC Driver class not found: " + jdbcDriverClass; log.error(msg, e); throw new RuntimeException(msg, e); } } } try { String validationQuery = properties.getProperty(ConnectionConstants.PROP_VALIDATIONQUERY); Integer initialPoolSize = PropertiesHelper.getInteger(ConnectionConstants.PROP_INITIALSIZE, properties); Integer minPoolSize = PropertiesHelper.getInteger(ConnectionConstants.PROP_MINACTIVE, properties); Integer maxPoolSize = PropertiesHelper.getInteger(ConnectionConstants.PROP_MAXACTIVE, properties); if (initialPoolSize == null && minPoolSize != null) { properties.put(ConnectionConstants.PROP_INITIALSIZE, String.valueOf(minPoolSize).trim()); } Integer maxWait = PropertiesHelper.getInteger(ConnectionConstants.PROP_MAXWAIT, properties); if (maxPoolSize == null) { maxPoolSize = 50; } String dbUser = properties.getProperty(Environment.USER); String dbPassword = properties.getProperty(Environment.PASS); if (dbUser == null) { dbUser = ""; } if (dbPassword == null) { dbPassword = ""; } HikariConfig config = new HikariConfig(); config.setDriverClassName(jdbcDriverClass); config.setJdbcUrl(jdbcUrl); config.setUsername(dbUser); config.setPassword(dbPassword); config.setMaximumPoolSize(maxPoolSize); config.setDataSourceProperties(properties); if (StringUtils.isNotEmpty(validationQuery)) { config.setConnectionTestQuery(validationQuery); } if (maxWait != null) { config.setConnectionTimeout(maxWait * 1000L); } config.setMaxLifetime(1000L * 3600 * 8); String isolationLevel = properties.getProperty(Environment.ISOLATION); if (isolationLevel == null) { isolation = null; } else { isolation = new Integer(isolationLevel); log.info("JDBC isolation level: " + Environment.isolationLevelToString(isolation.intValue())); } if (StringUtils.isNotEmpty(isolationLevel)) { config.setTransactionIsolation(isolationLevel); } ds = new HikariDataSource(config); } catch (Exception ex) { ex.printStackTrace(); log.error("could not instantiate HikariCP connection pool", ex); throw new RuntimeException("Could not instantiate HikariCP connection pool", ex); } }