List of usage examples for java.util Properties size
@Override public int size()
From source file:org.callistasoftware.maven.plugins.propertyscanner.MyMojo.java
private Properties loadProperties(Log logger) throws MojoExecutionException { FilenameFilter filter = new SuffixFileFilter(".properties"); Properties allProperties = new Properties(); for (File propertiesDirectory : propertiesDirectories) { if (!propertiesDirectory.exists()) { throw new MojoExecutionException("Could not find properties directory: " + propertiesDirectory); }/*from w ww . j a v a2s . c om*/ File[] propertiesFiles = propertiesDirectory.listFiles(filter); for (File propertiesFile : propertiesFiles) { if (!propertiesFile.exists()) { throw new MojoExecutionException("Could not find properties file: " + propertiesFile); } //loading properties Properties properties = new Properties(); FileReader r = null; try { r = new FileReader(propertiesFile); properties.load(r); } catch (IOException e) { throw new MojoExecutionException( "Error loading properties from translation file: " + propertiesFile, e); } finally { try { r.close(); } catch (Exception e) { //nothing } } logger.debug("Loaded properties, read " + properties.size() + " entries"); allProperties.putAll(properties); } } logger.info("Total properties loaded: " + allProperties.size()); return allProperties; }
From source file:org.globus.gsi.stores.PEMKeyStore.java
/** * Load the keystore from the supplied input stream. Unlike many other * implementations of keystore (most notably the default JKS * implementation), the input stream does not hold the keystore objects. * Instead, it must be a properties file defining the locations of the * keystore objects. The password is not used. * * @param inputStream/* www. j av a 2 s . c om*/ * An input stream to the properties file. * @param chars * The password is not used. * @throws IOException * @throws NoSuchAlgorithmException * @throws CertificateException */ @Override public void engineLoad(InputStream inputStream, char[] chars) throws IOException, NoSuchAlgorithmException, CertificateException { try { Properties properties = new Properties(); if (inputStream != null) { properties.load(inputStream); if (properties.size() == 0) { throw new CertificateException("Properties file for configuration was empty?"); } } else { if (chars == null) { // keyStore.load(null,null) -> in memory only keystore inMemoryOnly = true; } } String defaultDirectoryString = properties.getProperty(DEFAULT_DIRECTORY_KEY); String directoryListString = properties.getProperty(DIRECTORY_LIST_KEY); String proxyFilename = properties.getProperty(PROXY_FILENAME); String certFilename = properties.getProperty(CERTIFICATE_FILENAME); String keyFilename = properties.getProperty(KEY_FILENAME); initialize(defaultDirectoryString, directoryListString, proxyFilename, certFilename, keyFilename); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { logger.info("Error closing inputStream", e); } } } }
From source file:org.wso2.carbon.registry.app.RemoteRegistry.java
/** * This will generate extension element and that will add to the entry , the created element * will be something like <node1name> <node2Name> + <name></name> * <value></value> </node2Name> </node1name> * * @param properties List of Name value pairs * @param factory Abdera Factory// w ww . ja va2 s .co m * @param entry Instance of entry where extension element need to add * @param node1name Name of node 1 * @param node2Name Name of node 2 */ public static void addPropertyExtensionElement(java.util.Properties properties, Factory factory, ExtensibleElement entry, QName node1name, QName node2Name) { if (properties != null && properties.size() != 0) { Properties propertyElement = factory.newExtensionElement(node1name); for (Object keyObj : properties.keySet()) { String key = (String) keyObj; Property property = factory.newExtensionElement(node2Name); PropertyName pn = factory.newExtensionElement(PropertyExtensionFactory.PROPERTY_NAME); pn.setPropertyName(key); property.addName(pn); Object valueList = properties.get(key); if (valueList instanceof List) { for (Object value : (List) valueList) { // null values can be treated in the same manner as Strings, since casting // wouldn't change null. if (value == null || value instanceof String) { PropertyValue pv = factory.newExtensionElement(PropertyExtensionFactory.PROPERTY_VALUE); pv.setPropertyValue((String) value); property.addValue(pv); } } propertyElement.setProperty(property); } } entry.addExtension(propertyElement); } }
From source file:org.artifactory.storage.db.build.service.BuildStoreServiceImpl.java
private Set<BuildProperty> createProperties(long buildId, Build build) { Properties properties = build.getProperties(); Set<BuildProperty> buildProperties; if (properties != null && !properties.isEmpty()) { buildProperties = new HashSet<>(properties.size()); for (Map.Entry<Object, Object> entry : properties.entrySet()) { buildProperties.add(new BuildProperty(dbService.nextId(), buildId, entry.getKey().toString(), entry.getValue().toString())); }// w w w . j a v a 2 s . c o m } else { buildProperties = new HashSet<>(1); } return buildProperties; }
From source file:org.apache.openaz.xacml.rest.XACMLPdpServlet.java
protected void doPutConfig(String config, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from w ww. j a v a 2s . co m // prevent multiple configuration changes from stacking up if (XACMLPdpServlet.queue.remainingCapacity() <= 0) { logger.error("Queue capacity reached"); response.sendError(HttpServletResponse.SC_CONFLICT, "Multiple configuration changes waiting processing."); return; } // // Read the properties data into an object. // Properties newProperties = new Properties(); newProperties.load(request.getInputStream()); // should have something in the request if (newProperties.size() == 0) { logger.error("No properties in PUT"); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT must contain at least one property"); return; } // // Which set of properties are they sending us? Whatever they send gets // put on the queue (if there is room). // if (config.equals("policies")) { newProperties = XACMLProperties.getPolicyProperties(newProperties, true); if (newProperties.size() == 0) { logger.error("No policy properties in PUT"); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT with cache=policies must contain at least one policy property"); return; } XACMLPdpServlet.queue.offer(new PutRequest(newProperties, null)); } else if (config.equals("pips")) { newProperties = XACMLProperties.getPipProperties(newProperties); if (newProperties.size() == 0) { logger.error("No pips properties in PUT"); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT with cache=pips must contain at least one pip property"); return; } XACMLPdpServlet.queue.offer(new PutRequest(null, newProperties)); } else if (config.equals("all")) { Properties newPolicyProperties = XACMLProperties.getPolicyProperties(newProperties, true); if (newPolicyProperties.size() == 0) { logger.error("No policy properties in PUT"); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT with cache=all must contain at least one policy property"); return; } Properties newPipProperties = XACMLProperties.getPipProperties(newProperties); if (newPipProperties.size() == 0) { logger.error("No pips properties in PUT"); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT with cache=all must contain at least one pip property"); return; } XACMLPdpServlet.queue.offer(new PutRequest(newPolicyProperties, newPipProperties)); } else { // // Invalid value // logger.error("Invalid config value: " + config); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Config must be one of 'policies', 'pips', 'all'"); return; } } catch (Exception e) { logger.error("Failed to process new configuration.", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); return; } }
From source file:org.kaaproject.kaa.sandbox.web.services.SandboxServiceImpl.java
@Override public void afterPropertiesSet() throws Exception { try {/*w ww.j ava 2 s . c o m*/ LOG.info("Initializing Sandbox Service..."); LOG.info("sandboxHome [{}]", Environment.getServerHomeDir()); LOG.info("guiChangeHostEnabled [{}]", guiChangeHostEnabled); LOG.info("kaaNodeWebPort [{}]", kaaNodeWebPort); LOG.info("enableAnalytics [{}]", enableAnalytics); prepareAnalytics(); JAXBContext jc = JAXBContext.newInstance("org.kaaproject.kaa.examples.common.projects"); Unmarshaller unmarshaller = jc.createUnmarshaller(); String demoProjectsXmlFile = Environment.getServerHomeDir() + "/" + DEMO_PROJECTS_FOLDER + "/" + DEMO_PROJECTS_XML_FILE; ProjectsConfig projectsConfig = (ProjectsConfig) unmarshaller.unmarshal(new File(demoProjectsXmlFile)); for (Project project : projectsConfig.getProjects()) { projectsMap.put(project.getId(), project); LOG.info("Demo project: id [{}] name [{}]", project.getId(), project.getName()); } for (Bundle bundle : projectsConfig.getBundles()) { bundlesMap.put(bundle.getId(), bundle); LOG.info("Demo projects bundle: id [{}] name [{}]", bundle.getId(), bundle.getName()); } if (sandboxEnv == null) { Properties sandboxEnvProperties = org.kaaproject.kaa.server.common.utils.FileUtils .readResourceProperties(SANDBOX_ENV_FILE); sandboxEnv = new String[sandboxEnvProperties.size()]; int i = 0; for (Object key : sandboxEnvProperties.keySet()) { String keyValue = key + "=" + sandboxEnvProperties.getProperty(key.toString()); sandboxEnv[i++] = keyValue; LOG.info("Sandbox env: [{}]", keyValue); } } LOG.info("Initialized Sandbox Service."); } catch (JAXBException e) { LOG.error("Unable to initialize Sandbox Service", e); throw e; } }
From source file:org.eclipse.gemini.blueprint.context.support.OsgiPropertyEditorRegistrar.java
OsgiPropertyEditorRegistrar(ClassLoader userClassLoader) { this.userClassLoader = userClassLoader; // load properties Properties editorsConfig = new Properties(); InputStream stream = null;/*from w w w .j a va 2 s. c o m*/ try { stream = getClass().getResourceAsStream(PROPERTIES_FILE); editorsConfig.load(stream); } catch (IOException ex) { throw (RuntimeException) new IllegalStateException( "cannot load default propertiy editorsConfig configuration").initCause(ex); } finally { if (stream != null) { try { stream.close(); } catch (IOException ex) { } } } if (log.isTraceEnabled()) log.trace("Loaded property editors configuration " + editorsConfig); editors = new LinkedHashMap<Class<?>, Class<? extends PropertyEditor>>(editorsConfig.size()); createEditors(editorsConfig); }
From source file:org.apache.jcs.engine.control.CompositeCacheManager.java
/** * Configure from specific properties file. * * @param propFile/*from w ww . ja v a 2 s . c o m*/ * Path <u>within classpath </u> to load configuration from */ public void configure(String propFile) { log.info("Creating cache manager from config file: " + propFile); Properties props = new Properties(); InputStream is = getClass().getResourceAsStream(propFile); if (is != null) { try { props.load(is); if (log.isDebugEnabled()) { log.debug("File [" + propFile + "] contained " + props.size() + " properties"); } } catch (IOException ex) { log.error("Failed to load properties for name [" + propFile + "]", ex); throw new IllegalStateException(ex.getMessage()); } finally { try { is.close(); } catch (Exception ignore) { // Ignored } } } else { log.error("Failed to load properties for name [" + propFile + "]"); throw new IllegalStateException("Failed to load properties for name [" + propFile + "]"); } configure(props); }
From source file:org.nanoframework.orm.mybatis.plugin.AbstractDataSourceFactory.java
@Override public void setProperties(Properties properties) { Properties driverProperties = new Properties(); MetaObject metaDataSource = SystemMetaObject.forObject(dataSource); for (Object key : properties.keySet()) { String propertyName = (String) key; if (metaDataSource.hasSetter(propertyName)) { String value = (String) properties.get(propertyName); /** */ if (StringUtils.isNotEmpty(value) && value.startsWith("${") && value.endsWith("}")) { continue; }//from w w w .j av a2 s. c om Object convertedValue = convertValue(metaDataSource, propertyName, value); metaDataSource.setValue(propertyName, convertedValue); } else { throw new DataSourceException("Unknown DataSource property: " + propertyName); } } if (driverProperties.size() > 0) { metaDataSource.setValue("driverProperties", driverProperties); } }
From source file:org.artifactory.storage.db.build.service.BuildStoreServiceImpl.java
private void insertModules(long buildId, Build build) throws SQLException { List<Module> modules = build.getModules(); if (modules == null || modules.isEmpty()) { // Nothing to do here return;/*from w ww .j a v a2 s .com*/ } for (Module module : modules) { BuildModule dbModule = new BuildModule(dbService.nextId(), buildId, module.getId()); Properties properties = module.getProperties(); Set<ModuleProperty> moduleProperties; if (properties != null && !properties.isEmpty()) { moduleProperties = Sets.newHashSetWithExpectedSize(properties.size()); for (Map.Entry<Object, Object> entry : properties.entrySet()) { moduleProperties.add(new ModuleProperty(dbService.nextId(), dbModule.getModuleId(), entry.getKey().toString(), entry.getValue().toString())); } } else { moduleProperties = Sets.newHashSetWithExpectedSize(1); } dbModule.setProperties(moduleProperties); buildModulesDao.createBuildModule(dbModule); List<Artifact> artifacts = module.getArtifacts(); List<BuildArtifact> dbArtifacts; if (artifacts != null && !artifacts.isEmpty()) { dbArtifacts = Lists.newArrayListWithExpectedSize(artifacts.size()); for (Artifact artifact : artifacts) { // Artifact properties are not inserted in DB dbArtifacts.add(new BuildArtifact(dbService.nextId(), dbModule.getModuleId(), artifact.getName(), artifact.getType(), artifact.getSha1(), artifact.getMd5())); } } else { dbArtifacts = Lists.newArrayListWithExpectedSize(1); } buildArtifactsDao.createBuildArtifacts(dbArtifacts); List<Dependency> dependencies = module.getDependencies(); List<BuildDependency> dbDependencies; if (dependencies != null && !dependencies.isEmpty()) { dbDependencies = Lists.newArrayListWithExpectedSize(dependencies.size()); for (Dependency dependency : dependencies) { // Dependency properties are not inserted in DB dbDependencies.add(new BuildDependency(dbService.nextId(), dbModule.getModuleId(), dependency.getId(), dependency.getScopes(), dependency.getType(), dependency.getSha1(), dependency.getMd5())); } } else { dbDependencies = Lists.newArrayListWithExpectedSize(1); } buildDependenciesDao.createBuildDependencies(dbDependencies); } }