List of usage examples for java.util Properties size
@Override public int size()
From source file:org.apache.sqoop.SqoopOptions.java
/** * This method encodes the property key values found in the provided * properties instance <tt>values</tt> into another properties instance * <tt>props</tt>. The specified <tt>prefix</tt> is used as a namespace * qualifier for keys when inserting. This allows easy introspection of the * property key values in <tt>props</tt> instance to later separate out all * the properties that belong to the <tt>values</tt> instance. * @param props the container properties instance * @param prefix the prefix for qualifying contained property keys. * @param values the contained properties instance, all of whose elements will * be added to the container properties instance. * * @see #getPropertiesAsNetstedProperties(Properties, String) *//*from w w w.j av a2s. c o m*/ private void setPropertiesAsNestedProperties(Properties props, String prefix, Properties values) { String nestedPropertyPrefix = prefix + "."; if (null == values || values.size() == 0) { Iterator<String> it = props.stringPropertyNames().iterator(); while (it.hasNext()) { String name = it.next(); if (name.startsWith(nestedPropertyPrefix)) { props.remove(name); } } } else { Iterator<String> it = values.stringPropertyNames().iterator(); while (it.hasNext()) { String name = it.next(); putProperty(props, nestedPropertyPrefix + name, values.getProperty(name)); } } }
From source file:org.apache.sling.maven.slingstart.PreparePackageMojo.java
/** * Build the settings for the given packaging run mode */// w w w . j av a 2s . co m private void buildSettings(final Model model, final String packageRunMode, final File outputDir) throws MojoExecutionException { final Properties settings = new Properties(); final Feature launchpadFeature = model.getFeature(ModelConstants.FEATURE_LAUNCHPAD); if (launchpadFeature != null) { final RunMode launchpadRunMode = launchpadFeature.getRunMode(null); if (launchpadRunMode != null) { for (final Map.Entry<String, String> entry : launchpadRunMode.getSettings()) { settings.put(entry.getKey(), deescapeVariablePlaceholders(entry.getValue())); } } } final Feature bootFeature = model.getFeature(ModelConstants.FEATURE_BOOT); if (bootFeature != null) { final RunMode bootRunMode = bootFeature.getRunMode(null); if (bootRunMode != null) { for (final Map.Entry<String, String> entry : bootRunMode.getSettings()) { settings.put(entry.getKey(), deescapeVariablePlaceholders(entry.getValue())); } } } for (final Feature f : model.getFeatures()) { final RunMode packageRM = f.getRunMode(new String[] { packageRunMode }); if (packageRM != null) { for (final Map.Entry<String, String> entry : packageRM.getSettings()) { settings.put(entry.getKey(), deescapeVariablePlaceholders(entry.getValue())); } } } if (settings.size() > 0) { final File settingsFile = new File(outputDir, PROPERTIES_FILE); getLog().debug(String.format("Creating settings at %s", settingsFile.getPath())); FileWriter writer = null; try { writer = new FileWriter(settingsFile); settings.store(writer, null); } catch (final IOException ioe) { throw new MojoExecutionException("Unable to write properties file.", ioe); } finally { IOUtils.closeQuietly(writer); } } }
From source file:org.opencastproject.capture.impl.CaptureAgentImpl.java
/** * Creates the agent's scheduler/*from ww w . j ava 2 s . c o m*/ * * @param schedulerProps * @param jobname * @param jobtype */ private void createScheduler(Properties schedulerProps, String jobname, String jobtype) { // Either create the scheduler or empty out the existing one try { if (agentScheduler != null) { // Clear the existing jobs and reschedule everything for (String name : agentScheduler.getJobNames(jobtype)) { if (jobname.equals(name)) { agentScheduler.deleteJob(name, JobParameters.RECURRING_TYPE); } } } else { StdSchedulerFactory scheduleFactory = null; if (schedulerProps.size() > 0) { scheduleFactory = new StdSchedulerFactory(schedulerProps); } else { scheduleFactory = new StdSchedulerFactory(); } // Create and start the scheduler agentScheduler = scheduleFactory.getScheduler(); agentScheduler.start(); } } catch (SchedulerException e) { logger.error("Scheduler exception in State Service: {}.", e); return; } }
From source file:org.jahia.services.usermanager.JahiaGroupManagerService.java
public Set<JCRGroupNode> searchGroups(String siteKey, Properties searchCriterias, String[] providers, boolean excludeProtected, JCRSessionWrapper session) { try {//w ww.ja va 2 s . com Set<JCRGroupNode> groups = new HashSet<JCRGroupNode>(); if (session.getWorkspace().getQueryManager() != null) { StringBuilder query = new StringBuilder(128); // Add provider to query if (providers != null) { List<JCRStoreProvider> onProviders = getProviders(siteKey, providers, session); if (!onProviders.isEmpty()) { query.append("("); for (JCRStoreProvider provider : onProviders) { query.append(query.length() > 1 ? " OR " : ""); if (provider.isDefault()) { query.append("g.[j:external] = false"); } else { query.append("ISDESCENDANTNODE('").append(provider.getMountPoint()).append("')"); } } query.append(")"); } else { return groups; } } if (searchCriterias != null && searchCriterias.size() > 0) { // Avoid wildcard attribute if (!(searchCriterias.containsKey("*") && searchCriterias.size() == 1 && searchCriterias.getProperty("*").equals("*"))) { Iterator<Map.Entry<Object, Object>> objectIterator = searchCriterias.entrySet().iterator(); if (objectIterator.hasNext()) { query.append(query.length() > 0 ? " AND " : "").append(" ("); while (objectIterator.hasNext()) { Map.Entry<Object, Object> entry = objectIterator.next(); String propertyKey = (String) entry.getKey(); if ("groupname".equals(propertyKey)) { propertyKey = "j:nodename"; } String propertyValue = (String) entry.getValue(); if ("*".equals(propertyValue)) { propertyValue = "%"; } else { if (propertyValue.indexOf('*') != -1) { propertyValue = Patterns.STAR.matcher(propertyValue).replaceAll("%"); } else { propertyValue = propertyValue + "%"; } } propertyValue = JCRContentUtils.sqlEncode(propertyValue); if ("*".equals(propertyKey)) { query.append("(CONTAINS(g.*,'") .append(QueryParser .escape(Patterns.PERCENT.matcher(propertyValue).replaceAll(""))) .append("') OR LOWER(g.[j:nodename]) LIKE '") .append(propertyValue.toLowerCase()).append("') "); } else { query.append("LOWER(g.[") .append(Patterns.DOT.matcher(propertyKey).replaceAll("\\\\.")) .append("])").append(" LIKE '").append(propertyValue.toLowerCase()) .append("'"); } if (objectIterator.hasNext()) { query.append(" OR "); } } query.append(")"); } } } if (query.length() > 0) { query.insert(0, " and "); } if (excludeProtected) { for (String g : PROTECTED_GROUPS) { query.insert(0, " and [j:nodename] <> '" + g + "'"); } } String s = (siteKey == null) ? "/groups/" : "/sites/" + siteKey + "/groups/"; query.insert(0, "SELECT * FROM [" + Constants.JAHIANT_GROUP + "] as g where isdescendantnode(g,'" + JCRContentUtils.sqlEncode(s) + "')"); query.append(" ORDER BY g.[j:nodename]"); if (logger.isDebugEnabled()) { logger.debug(query.toString()); } Query q = session.getWorkspace().getQueryManager().createQuery(query.toString(), Query.JCR_SQL2); QueryResult qr = q.execute(); NodeIterator ni = qr.getNodes(); while (ni.hasNext()) { groups.add((JCRGroupNode) ni.nextNode()); } } return groups; } catch (RepositoryException e) { logger.error("Error while searching for groups", e); return new HashSet<JCRGroupNode>(); } }
From source file:org.apache.sqoop.SqoopOptions.java
/** * This method decodes the property key values found in the provided * properties instance <tt>props</tt> that have keys beginning with the * given prefix. Matching elements from this properties instance are modified * so that their prefix is dropped./* w ww . j a v a 2s. c o m*/ * @param props the properties container * @param prefix the prefix qualifying properties that need to be removed * @return a new properties instance that contains all matching elements from * the container properties. */ private Properties getPropertiesAsNetstedProperties(Properties props, String prefix) { Properties nestedProps = new Properties(); String nestedPropertyPrefix = prefix + "."; int index = nestedPropertyPrefix.length(); if (props != null && props.size() > 0) { Iterator<String> it = props.stringPropertyNames().iterator(); while (it.hasNext()) { String name = it.next(); if (name.startsWith(nestedPropertyPrefix)) { String shortName = name.substring(index); nestedProps.put(shortName, props.get(name)); } } } return nestedProps; }
From source file:org.rhq.enterprise.server.installer.InstallerServiceImpl.java
@Override public HashMap<String, String> getServerProperties() throws Exception { final File serverPropertiesFile = getServerPropertiesFile(); final PropertiesFileUpdate propsFile = new PropertiesFileUpdate(serverPropertiesFile.getAbsolutePath()); final Properties props = propsFile.loadExistingProperties(); // the default algorithm that RHQ will use in the comm layer will be defined at runtime based on the VM // but if the user mistakenly set the algorithm to the Sun value while using IBM JVM, then force // some hardcoded defaults so it can more likely work for IBM JVMs. final boolean isIBM = System.getProperty("java.vendor", "").contains("IBM"); if (isIBM) {/* w ww . j av a2s. c o m*/ for (String algPropName : ServerProperties.IBM_ALGOROTHM_SETTINGS) { if (props.getProperty(algPropName, "").equalsIgnoreCase("SunX509")) { props.setProperty(algPropName, "IbmX509"); } } } // GWT can't handle Properties - convert to HashMap final HashMap<String, String> map = new HashMap<String, String>(props.size()); for (Object property : props.keySet()) { map.put(property.toString(), props.getProperty(property.toString())); } return map; }
From source file:org.opencms.loader.CmsResourceManager.java
/** * Initialize the MIME types.<p>// w w w . j a v a 2s . c om * * MIME types are configured in the OpenCms <code>opencms-vfs.xml</code> configuration file.<p> * * For legacy reasons, the MIME types are also read from a file <code>"mimetypes.properties"</code> * that must be located in the default <code>"classes"</code> folder of the web application.<p> */ private void initMimeTypes() { // legacy MIME type initialization: try to read properties file Properties mimeTypes = new Properties(); try { // first try: read MIME types from default package mimeTypes.load(getClass().getClassLoader().getResourceAsStream("mimetypes.properties")); } catch (Throwable t) { try { // second try: read MIME types from loader package (legacy reasons, there are no types by default) mimeTypes.load( getClass().getClassLoader().getResourceAsStream("org/opencms/loader/mimetypes.properties")); } catch (Throwable t2) { if (LOG.isInfoEnabled()) { LOG.info(Messages.get().getBundle().key(Messages.LOG_READ_MIMETYPES_FAILED_2, "mimetypes.properties", "org/opencms/loader/mimetypes.properties")); } } } // initialize the Map with all available MIME types List<CmsMimeType> combinedMimeTypes = new ArrayList<CmsMimeType>( mimeTypes.size() + m_configuredMimeTypes.size()); // first add all MIME types from the configuration combinedMimeTypes.addAll(m_configuredMimeTypes); // now add the MIME types from the properties Iterator<Map.Entry<Object, Object>> i = mimeTypes.entrySet().iterator(); while (i.hasNext()) { Map.Entry<Object, Object> entry = i.next(); CmsMimeType mimeType = new CmsMimeType(entry.getKey().toString(), entry.getValue().toString(), false); if (!combinedMimeTypes.contains(mimeType)) { // make sure no MIME types from the XML configuration are overwritten combinedMimeTypes.add(mimeType); } } // create a lookup Map for the MIME types m_mimeTypes = new HashMap<String, String>(mimeTypes.size()); Iterator<CmsMimeType> j = combinedMimeTypes.iterator(); while (j.hasNext()) { CmsMimeType mimeType = j.next(); m_mimeTypes.put(mimeType.getExtension(), mimeType.getType()); } if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info( Messages.get().getBundle().key(Messages.INIT_NUM_MIMETYPES_1, new Integer(m_mimeTypes.size()))); } }
From source file:org.hyperic.hq.common.server.session.ServerConfigManagerImpl.java
/** * Set the server Configuration/*from w w w . j a v a2 s . c om*/ * @param prefix The config prefix to use when setting properties. The * prefix is used for namespace protection and property scoping. * @param newProps The Properties to set. * @throws ConfigPropertyException - if the props object is missing a key * that's currently in the database * */ @Transactional public void setConfig(AuthzSubject subject, String prefix, Properties newProps) throws ApplicationException, ConfigPropertyException { Properties tempProps = new Properties(); tempProps.putAll(newProps); // get all properties Collection<ConfigProperty> allProps = serverConfigCache.getProps(prefix); createChangeAudits(subject, allProps, newProps); for (ConfigProperty configProp : allProps) { // check if the props object has a key matching String key = configProp.getKey(); if (newProps.containsKey(key)) { tempProps.remove(key); String propValue = (String) newProps.get(key); // delete null values from prefixed properties if (prefix != null && (propValue == null || propValue.equals("NULL"))) { configPropertyDAO.remove(configProp); serverConfigCache.remove(key); } else { // non-prefixed properties never get deleted. configProp.setValue(propValue); serverConfigCache.put(key, propValue); // Fix Bug 1285064/HQ-4793: Save the property in DB configPropertyDAO.save(configProp); if (HQConstants.HQGUID.equals(key)) { // Came from read only method so need to flush the session configPropertyDAO.flushSession(); if (log.isDebugEnabled()) log.debug("Saving HQ-GUID in DB [" + propValue + "]"); } } } else if (prefix == null) { // Bomb out if props are missing for non-prefixed properties throw new ConfigPropertyException("Updated configuration missing required key: " + key); } } // create properties that are still left in tempProps if (tempProps.size() > 0) { Enumeration propsToAdd = tempProps.propertyNames(); while (propsToAdd.hasMoreElements()) { String key = (String) propsToAdd.nextElement(); String propValue = tempProps.getProperty(key); // create the new property configPropertyDAO.create(prefix, key, propValue, propValue); serverConfigCache.put(key, propValue); } } }
From source file:org.olat.core.util.i18n.I18nManager.java
/** * Count the i18n items in a bundle/*from ww w . j a v a 2s .c om*/ * * @param locale * @param limitToBundleName The name of a bundle for which the keys should be * counted or NULL to count keys in every available bundle * @param includeBundlesChildren true: also count the keys of the bundles * children; false: count only the keys of the exact bundle name. * When limitToBundeName is set to NULL the includeBundlesChildren * will always be set to true * @return */ public int countI18nItems(Locale locale, String limitToBundleName, boolean includeBundlesChildren) { List<String> allBundles = I18nModule.getBundleNamesContainingI18nFiles(); int counter = 0; for (String bundleName : allBundles) { if (limitToBundleName == null || limitToBundleName.equals(bundleName) || (includeBundlesChildren && bundleName.startsWith(limitToBundleName))) { Properties properties = getResolvedProperties(locale, bundleName); counter += properties.size(); } } return counter; }
From source file:org.olat.core.util.i18n.I18nManager.java
/** * Copy the given set of languages from the given jar to the configured i18n * source directories. This method can only be called in a translation * server environment./* ww w . jav a 2 s .c o m*/ * * @param jarFile * @param toCopyI18nKeys */ public void copyLanguagesFromJar(File jarFile, Collection<String> toCopyI18nKeys) { if (!I18nModule.isTransToolEnabled()) { throw new AssertException( "Programming error - can only copy i18n files from a language pack to the source when in translation mode"); } JarFile jar = null; try { jar = new JarFile(jarFile); Enumeration<JarEntry> jarEntries = jar.entries(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); String jarEntryName = jarEntry.getName(); // Check if this entry is a language file for (String i18nKey : toCopyI18nKeys) { if (jarEntryName.endsWith(I18N_DIRNAME + "/" + I18nModule.LOCAL_STRINGS_FILE_PREFIX + i18nKey + I18nModule.LOCAL_STRINGS_FILE_POSTFIX)) { File targetBaseDir; if (i18nKey.equals("de") || i18nKey.equals("en")) { targetBaseDir = I18nModule.getTransToolApplicationLanguagesSrcDir(); } else { targetBaseDir = I18nModule.getTransToolApplicationOptLanguagesSrcDir(); } // Copy file File targetFile = new File(targetBaseDir, jarEntryName); targetFile.getParentFile().mkdirs(); FileUtils.save(jar.getInputStream(jarEntry), targetFile); // Check that saved properties file is empty, if so remove it Properties props = new Properties(); props.load(new FileInputStream(targetFile)); if (props.size() == 0) { targetFile.delete(); // Delete empty parent dirs recursively File parent = targetFile.getParentFile(); while (parent != null && parent.list() != null && parent.list().length == 0) { parent.delete(); parent = parent.getParentFile(); } } // Continue with next jar entry break; } } } } catch (IOException e) { throw new OLATRuntimeException( "Error when copying up i18n files from a jar::" + jarFile.getAbsolutePath(), e); } finally { IOUtils.closeQuietly(jar); } }