List of usage examples for java.util Properties stringPropertyNames
public Set<String> stringPropertyNames()
From source file:org.sculptor.maven.plugin.AbstractGeneratorMojo.java
/** * Deletes the files in the directories marked as 'generated' and the * unmodified one-shot generated files.//from www. j av a2 s . c o m * <p> * The list of all previously generated files is retrieved from the StatusFile * (defined via {@link #statusFile}). Modified one-shot generated files are * detected by a changed file checksum. */ protected boolean deleteGeneratedFiles() { boolean success; // First delete all files in the directories marked as 'generated' cleanDirectory(outletSrcDir); cleanDirectory(outletResDir); cleanDirectory(outletSrcTestDir); cleanDirectory(outletResTestDir); // Finally delete the non-modified one-shot generated files in the other folders File statusFile = getStatusFile(); if (statusFile == null) { // No status file - we can't delete any previously generated files success = true; } else { try { // Read status file and iterate through the list of generated // files Properties statusFileProps = new Properties(); statusFileProps.load(new FileReader(statusFile)); for (String fileName : statusFileProps.stringPropertyNames()) { File file = new File(getProject().getBasedir(), fileName); if (file.exists()) { // For one-shot generated files compare checksum before // deleting boolean delete; if (fileName.startsWith(getProjectRelativePath(outletSrcOnceDir)) || fileName.startsWith(getProjectRelativePath(outletResOnceDir)) || fileName.startsWith(getProjectRelativePath(outletWebrootDir)) || fileName.startsWith(getProjectRelativePath(outletSrcTestOnceDir)) || fileName.startsWith(getProjectRelativePath(outletResTestOnceDir))) { delete = calculateChecksum(file).equals(statusFileProps.getProperty(fileName)); if (!delete && (isVerbose() || getLog().isDebugEnabled())) { getLog().info("Keeping previously generated modified" + " file: " + file); } } else { delete = false; } if (delete) { if (isVerbose() || getLog().isDebugEnabled()) { getLog().info("Deleting previously generated file: " + file); } // We have to make sure the file is deleted on // Windows as well FileUtils.forceDelete(file); // Delete image file generated from dot file if (fileName.endsWith(".dot")) { File imageFile = new File(getProject().getBasedir(), fileName + ".png"); if (imageFile.exists()) { if (isVerbose() || getLog().isDebugEnabled()) { getLog().info("Deleting previously generated file: " + imageFile); } // We have to make sure the file is deleted // on Windows as well FileUtils.forceDelete(imageFile); } } } } } success = true; } catch (IOException e) { getLog().warn("Reading status file failed: " + e.getMessage()); success = false; } } return success; }
From source file:org.xwiki.configuration.internal.CloudConfigurationSource.java
/** * Load remapping definitions from the remapping file and provide them as a configuration source. * * @return A configuration source containing the remappings. null if the file is not present. * @throws Exception if there is an error loading the file. *//*from w ww .j a va2 s .com*/ private ConfigurationSource loadRemappings() throws Exception { InputStream is = this.environment.getResourceAsStream(REMAPPING_FILE); if (is == null) { return null; } Properties properties = new Properties(); try { properties.load(is); } catch (Exception e) { throw new InitializationException(String.format("Unable to read %s", REMAPPING_FILE), e); } BaseConfiguration configuration = new BaseConfiguration(); for (String key : properties.stringPropertyNames()) { configuration.setProperty(key, properties.get(key)); } CommonsConfigurationSource commonsConfigurationSource = new CommonsConfigurationSource(); commonsConfigurationSource.setConfiguration(configuration); return commonsConfigurationSource; }
From source file:org.openhab.binding.nest.handler.NestBridgeHandler.java
/** * Resolves the redirect URL for calls using the {@link NestBindingConstants#NEST_URL}. * * The Jetty client used by {@link HttpUtil} will not pass the Authorization header after a redirect resulting in * "401 Unauthorized error" issues.//from w w w.j a v a2s.c om * * Note that this workaround currently does not use any configured proxy like {@link HttpUtil} does. * * @see https://developers.nest.com/documentation/cloud/how-to-handle-redirects */ private String resolveRedirectUrl() throws FailedResolvingNestUrlException, InvalidAccessTokenException { HttpClient httpClient = new HttpClient(new SslContextFactory()); httpClient.setFollowRedirects(false); Request request = httpClient.newRequest(NestBindingConstants.NEST_URL).method(HttpMethod.GET).timeout(5, TimeUnit.SECONDS); Properties httpHeaders = getHttpHeaders(); for (String httpHeaderKey : httpHeaders.stringPropertyNames()) { request.header(httpHeaderKey, httpHeaders.getProperty(httpHeaderKey)); } ContentResponse response; try { httpClient.start(); response = request.send(); httpClient.stop(); } catch (Exception e) { throw new FailedResolvingNestUrlException("Failed to resolve redirect URL: " + e.getMessage(), e); } int status = response.getStatus(); String redirectUrl = response.getHeaders().get(HttpHeader.LOCATION); if (status != HttpStatus.TEMPORARY_REDIRECT_307) { logger.debug("Redirect status: {}", status); logger.debug("Redirect response: {}", response.getContentAsString()); throw new FailedResolvingNestUrlException("Failed to get redirect URL, expected status " + HttpStatus.TEMPORARY_REDIRECT_307 + " but was " + status); } else if (StringUtils.isEmpty(redirectUrl)) { throw new FailedResolvingNestUrlException("Redirect URL is empty"); } redirectUrl = redirectUrl.endsWith("/") ? redirectUrl.substring(0, redirectUrl.length() - 1) : redirectUrl; logger.debug("Redirect URL: {}", redirectUrl); return redirectUrl; }
From source file:org.wso2.carbon.policy.mgt.core.PolicyDAOTestCase.java
@Test(dependsOnMethods = ("getRoleRelatedPolicySecondTime")) public void getRoleRelatedPolicyThirdTime() throws PolicyManagementException { PolicyAdministratorPoint policyAdministratorPoint = new PolicyAdministratorPointImpl(); List<Policy> policyList = policyAdministratorPoint.getPoliciesOfRole("Role_02"); log.debug("----------Roles related policy third time ---------"); for (Policy policy : policyList) { log.debug("Policy Id : " + policy.getId() + " Policy Name : " + policy.getPolicyName()); List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList(); // for (ProfileFeature profileFeature : profileFeatures) { // log.debug("Feature Content" + profileFeature.getId() + " - " + profileFeature.getContent()); // } List<PolicyCriterion> criteria = policy.getPolicyCriterias(); for (PolicyCriterion criterion : criteria) { log.debug("Criterias " + criterion.getName() + " -- " + criterion.getCriteriaId() + " -- " + criterion.getId()); Properties prop = criterion.getProperties(); for (String key : prop.stringPropertyNames()) { log.debug("Property Names : " + key + " -- " + prop.getProperty(key)); }// w w w . ja v a 2 s. c om } } }
From source file:org.azkfw.business.logic.LogicManager.java
/** * ?/*from www. jav a2 s . c o m*/ * * @param aNamespace ??? * @param aStream * @param aContext * @throws BusinessServiceException ???????? * @throws IOException ???????? */ @SuppressWarnings("unchecked") private void doLoad(final String aNamespace, final InputStream aStream, final Context aContext) throws BusinessServiceException, IOException { List<LogicEntity> logicList = null; try { Digester digester = new Digester(); digester.addObjectCreate("azuki/logics", ArrayList.class); digester.addObjectCreate("azuki/logics/logic", LogicEntity.class); digester.addSetProperties("azuki/logics/logic"); digester.addSetNext("azuki/logics/logic", "add"); logicList = digester.parse(aStream); } catch (SAXException ex) { error(ex); throw new IOException(ex); } catch (IOException ex) { error(ex); throw new IOException(ex); } Map<String, LogicData> m = null; if (logics.containsKey(aNamespace)) { m = logics.get(aNamespace); } else { m = new HashMap<String, LogicData>(); } for (int i = 0; i < logicList.size(); i++) { LogicEntity logic = logicList.get(i); info("Logic loading.[" + logic.name + "]"); if (m.containsKey(logic.getName())) { throw new BusinessServiceException("Duplicate logic name.[" + logic.getName() + "]"); } else { try { LogicData data = new LogicData(); Class<Logic> clazz = (Class<Logic>) Class.forName(logic.getLogic()); // XXX ???????? Map<String, Object> properties = new HashMap<String, Object>(); PropertyFile propertyFile = clazz.getAnnotation(PropertyFile.class); if (null != propertyFile) { String property = propertyFile.value(); if (StringUtility.isNotEmpty(property)) { InputStream is = aContext.getResourceAsStream(property); if (null != is) { Properties p = new Properties(); p.load(is); for (String key : p.stringPropertyNames()) { properties.put(key, p.getProperty(key)); } } else { throw new BusinessServiceException( "Not found logic property file.[" + property + "]"); } } } data.setLogic(clazz); data.setProperties(properties); data.setEntity(logic); m.put(logic.getName(), data); } catch (ClassNotFoundException ex) { error(ex); throw new BusinessServiceException(ex); } } } logics.put(aNamespace, m); }
From source file:gobblin.data.management.policy.CombineSelectionPolicy.java
@SuppressWarnings("unchecked") public CombineSelectionPolicy(Properties props) throws IOException { Preconditions.checkArgument(props.containsKey(VERSION_SELECTION_POLICIES_PREFIX), "Combine operation not specified."); ImmutableList.Builder<VersionSelectionPolicy<FileSystemDatasetVersion>> builder = ImmutableList.builder(); for (String property : props.stringPropertyNames()) { if (property.startsWith(VERSION_SELECTION_POLICIES_PREFIX)) { try { builder.add((VersionSelectionPolicy<FileSystemDatasetVersion>) ConstructorUtils .invokeConstructor(Class.forName(props.getProperty(property)), props)); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException | ClassNotFoundException e) { throw new IllegalArgumentException(e); }/*from w ww.ja v a 2 s . c om*/ } } this.selectionPolicies = builder.build(); if (this.selectionPolicies.size() == 0) { throw new IOException( "No selection policies specified for " + CombineSelectionPolicy.class.getCanonicalName()); } this.combineOperation = CombineOperation .valueOf(props.getProperty(VERSION_SELECTION_COMBINE_OPERATION).toUpperCase()); }
From source file:org.apache.asterix.common.config.AsterixPropertiesAccessor.java
private void loadAsterixBuildProperties() throws AsterixException { Properties gitProperties = new Properties(); try {//w w w. ja v a2s.c o m gitProperties.load(getClass().getClassLoader().getResourceAsStream("git.properties")); for (final String name : gitProperties.stringPropertyNames()) { asterixBuildProperties.put(name, gitProperties.getProperty(name)); } } catch (IOException e) { throw new AsterixException(e); } }
From source file:uk.gov.gchq.gaffer.graph.hook.OperationChainLimiter.java
private void loadMapsFromProperties(final Properties operationScorePropertiesFile, final Properties operationAuthorisationScoreLimitPropertiesFile) { Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>(); for (final String opClassName : operationScorePropertiesFile.stringPropertyNames()) { final Class<? extends Operation> opClass; try {//from w w w .j a v a2s . c om opClass = Class.forName(opClassName).asSubclass(Operation.class); } catch (ClassNotFoundException e) { LOGGER.error("An operation class could not be found for operation score property " + opClassName, e); throw new IllegalArgumentException(e); } final Integer score = Integer.parseInt(operationScorePropertiesFile.getProperty(opClassName)); opScores.put(opClass, score); } setOpScores(sortByValue(opScores)); Map<String, Integer> authScores = new HashMap<>(); for (final String authName : operationAuthorisationScoreLimitPropertiesFile.stringPropertyNames()) { final Integer score = Integer .parseInt(operationAuthorisationScoreLimitPropertiesFile.getProperty(authName)); authScores.put(authName, score); } setAuthScores(authScores); }
From source file:org.wso2.carbon.identity.mgt.config.RegistryConfigWriter.java
@Override public void write(int tenantId, Properties props, String resourcePath) throws IdentityMgtConfigException { if (log.isDebugEnabled()) { log.debug("Writing data to registry path : " + resourcePath); }//from w ww .j ava2 s .c o m RegistryService registry = IdentityMgtServiceComponent.getRegistryService(); try { UserRegistry userReg = registry.getConfigSystemRegistry(tenantId); Resource resource = userReg.newResource(); Set<String> names = props.stringPropertyNames(); // Only key value pairs exists and no multiple values exists a key. for (String keyName : names) { List<String> value = new ArrayList<String>(); String valueStr = props.getProperty(keyName); if (log.isDebugEnabled()) { log.debug("Write key : " + keyName + " value : " + value); } // This is done due to casting to List in JDBCRegistryDao value.add(valueStr); resource.setProperty(keyName, value); } userReg.put(resourcePath, resource); } catch (RegistryException e) { throw new IdentityMgtConfigException( "Error occurred while writing data to registry path : " + resourcePath, e); } }
From source file:com.heliosapm.streams.collector.ds.JDBCDataSourceManager.java
/** * Deploys the passed file as a JDBC data source * @param dsDef The JDBC data source configuration file *///from w w w .j ava 2 s . c o m protected void deployJDBCDataSource(final File dsDef) { try { final Properties p = URLHelper.readProperties(URLHelper.toURL(dsDef)); for (String key : p.stringPropertyNames()) { if (key.trim().equalsIgnoreCase("disabled")) { if (p.getProperty(key, "false").trim().equalsIgnoreCase("true")) { log.info("DataSource Definition [{}] is marked disabled. Skipping.", dsDef); return; } } } log.info(">>> Deploying DataSource from [{}]", dsDef); final HikariConfig config = new HikariConfig(p); config.setMetricRegistry(SharedMetricsRegistry.getInstance()); final String name = dsDef.getName().substring(0, dsDef.getName().length() - 3); config.setPoolName(name); config.setRegisterMbeans(true); final String dsClassName = p.getProperty("dataSourceClassName"); log.info("DataSource Class Name: [{}]", dsClassName); try { Class.forName(dsClassName, true, Thread.currentThread().getContextClassLoader()); } catch (Exception ex) { throw new RuntimeException(ex); } final ManagedHikariDataSource ds = new ManagedHikariDataSource(config, new DataSourceListener() { @Override public void onDataSourceStopped(String poolName, String dataSourceCacheName, String groovySqlCacheName) { dataSources.remove(dsDef.getAbsolutePath()); } }); dataSources.put(dsDef.getAbsolutePath(), ds); gcache.put(ds.dsCacheKey, this); gcache.put(ds.groovydsCacheKey, ds.groovySql); successfulDeploys.increment(); log.info("<<< DataSource [{}] deployed from [{}]", name, dsDef); } catch (Exception ex) { final HikariDataSource ds = dataSources.remove(dsDef.getAbsolutePath()); if (ds != null) { try { ds.close(); } catch (Exception x) { /* No Op */} } failedDeploys.increment(); log.error("Failed to deploy datasource from [{}]", dsDef, ex); throw new RuntimeException("Failed to deploy datasource", ex); } }