Example usage for java.util Properties propertyNames

List of usage examples for java.util Properties propertyNames

Introduction

In this page you can find the example usage for java.util Properties propertyNames.

Prototype

public Enumeration<?> propertyNames() 

Source Link

Document

Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Usage

From source file:org.apache.stratos.metadata.service.registry.CarbonRegistry.java

/**
 * Get Properties of clustor//from w w w. java 2  s.  c  o  m
 *
 * @param applicationName
 * @param clusterId
 * @return
 * @throws RegistryException
 */
public List<Property> getClusterProperties(String applicationName, String clusterId) throws RegistryException {
    Registry tempRegistry = getRegistry();
    String resourcePath = mainResource + applicationName + "/" + clusterId;

    if (!tempRegistry.resourceExists(resourcePath)) {
        return null;
        //throw new RegistryException("Cluster does not exist at " + resourcePath);
    }

    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
    ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

    Resource regResource = tempRegistry.get(resourcePath);

    ArrayList<Property> newProperties = new ArrayList<Property>();

    Properties props = regResource.getProperties();
    Enumeration<?> x = props.propertyNames();
    while (x.hasMoreElements()) {
        String key = (String) x.nextElement();
        List<String> values = regResource.getPropertyValues(key);
        Property property = new Property();
        property.setKey(key);
        String[] valueArr = new String[values.size()];
        property.setValues(values.toArray(valueArr));

        newProperties.add(property);
    }

    return newProperties;
}

From source file:org.hyperic.hq.agent.AgentConfig.java

private static synchronized boolean loadProps(Properties props, File propFile) throws AgentConfigException {
    Properties tmpProps;
    try {// www .  j  av  a  2 s .  co m
        tmpProps = PropertyUtil.loadProperties(propFile.getPath());
    } catch (PropertyUtilException exc) {
        throw new AgentConfigException(exc.getMessage());
    }
    if (!propFile.exists()) {
        logger.error(propFile + " does not exist");
        return false;
    }
    if (!propFile.canRead()) {
        logger.error("can't read " + propFile);
        return false;
    }
    try {
        String propEncKey = PropertyEncryptionUtil
                .getPropertyEncryptionKey(AgentConfig.DEFAULT_PROP_ENC_KEY_FILE);

        for (Enumeration<?> propKeys = tmpProps.propertyNames(); propKeys.hasMoreElements();) {
            String key = (String) propKeys.nextElement();
            String value = tmpProps.getProperty(key);

            // if property is defined in the prop file
            if (value != null) {
                // if encrypted, replace with decrypted value
                if (SecurityUtil.isMarkedEncrypted(value)) {
                    value = SecurityUtil.decrypt(SecurityUtil.DEFAULT_ENCRYPTION_ALGORITHM, propEncKey, value);
                    // if not encrypted, although it should have, mark as candidate for encryption in the file
                }
                value = value.trim();
            }

            props.put(key, value);
        }
        return true;
    } catch (Exception e) {
        logger.error(e);
        return false;
    }
}

From source file:org.springframework.web.servlet.handler.SimpleMappingExceptionResolver.java

/**
 * Find a matching view name in the given exception mappings
 * @param exceptionMappings mappings between exception class names and error view names
 * @param ex the exception that got thrown during handler execution
 * @return the view name, or <code>null</code> if none found
 * @see #setExceptionMappings/*w w w  .  ja v  a2  s. co  m*/
 */
protected String findMatchingViewName(Properties exceptionMappings, Exception ex) {
    String viewName = null;
    int deepest = Integer.MAX_VALUE;
    for (Enumeration names = exceptionMappings.propertyNames(); names.hasMoreElements();) {
        String exceptionMapping = (String) names.nextElement();
        int depth = getDepth(exceptionMapping, ex);
        if (depth >= 0 && depth < deepest) {
            deepest = depth;
            viewName = exceptionMappings.getProperty(exceptionMapping);
        }
    }
    return viewName;
}

From source file:org.apache.syncope.client.console.SyncopeConsoleApplication.java

@SuppressWarnings("unchecked")
protected void populatePageClasses(final Properties props) {
    Enumeration<String> propNames = (Enumeration<String>) props.propertyNames();
    while (propNames.hasMoreElements()) {
        String name = propNames.nextElement();
        if (name.startsWith("page.")) {
            try {
                Class<?> clazz = ClassUtils.getClass(props.getProperty(name));
                if (BasePage.class.isAssignableFrom(clazz)) {
                    pageClasses.put(StringUtils.substringAfter("page.", name),
                            (Class<? extends BasePage>) clazz);
                } else {
                    LOG.warn("{} does not extend {}, ignoring...", clazz.getName(), BasePage.class.getName());
                }/*from  www .  j a va2s .c o  m*/
            } catch (ClassNotFoundException e) {
                LOG.error("While looking for class identified by property '{}'", name, e);
            }
        }
    }
}

From source file:org.metaeffekt.dcc.controller.execution.BaseExecutor.java

@Override
public void evaluateTemplateResources() {
    final File solutionDir = getExecutionContext().getSolutionDir();
    Validate.notNull(solutionDir);/*w w w .ja  v  a  2 s.co  m*/

    String[] includes = new String[SOLUTION_ADDON_FOLDERS.length];
    for (int i = 0; i < includes.length; i++) {
        includes[i] = SOLUTION_ADDON_FOLDERS[i] + "/**/__*__";
    }

    DirectoryScanner directoryScanner = new DirectoryScanner();
    directoryScanner.setBasedir(solutionDir);
    directoryScanner.setIncludes(includes);
    directoryScanner.scan();
    String[] files = directoryScanner.getIncludedFiles();

    // build project containing all available properties from the profile
    final LoggingProjectAdapter project = new LoggingProjectAdapter();
    PropertiesHolder propertiesHolder = getExecutionContext().getPropertiesHolder();
    final Map<String, Properties> propertiesMap = propertiesHolder.getPropertiesMap();
    final FilterSet filterSet = new FilterSet();
    for (Map.Entry<String, Properties> entry : propertiesMap.entrySet()) {
        Properties p = entry.getValue();
        String identifiable = entry.getKey();

        final Enumeration<?> properties = p.propertyNames();
        while (properties.hasMoreElements()) {
            Object object = (Object) properties.nextElement();

            StringBuilder key = new StringBuilder();
            key.append(identifiable);
            key.append(".");
            key.append(object);

            filterSet.addFilter(key.toString(), String.valueOf(p.getProperty(object.toString())));
        }
    }

    // and now copy the file in filtering mode
    Copy copy = new Copy();
    copy.setProject(project);
    copy.setEncoding("UTF-8");
    copy.setOverwrite(true);
    final FilterSet copyFilterSet = copy.createFilterSet();
    copyFilterSet.setProject(project);
    copyFilterSet.setBeginToken("${");
    copyFilterSet.setEndToken("}");
    copyFilterSet.addConfiguredFilterSet(filterSet);

    for (String file : files) {
        File sourceFile = new File(solutionDir, file);
        String filename = sourceFile.getName();
        // cut away the underscores
        filename = filename.substring(2, filename.length() - 2);
        File targetFile = new File(sourceFile.getParent(), filename);
        copy.setFile(sourceFile);
        copy.setTofile(targetFile);
        copy.execute();
    }
}

From source file:com.all.ultrapeer.UltrapeerConfig.java

private void fillConfigMap(Properties properties) {
    @SuppressWarnings("unchecked")
    Enumeration<String> propertyNames = (Enumeration<String>) properties.propertyNames();
    while (propertyNames.hasMoreElements()) {
        String property = propertyNames.nextElement();
        if (config.containsKey(property)) {
            throw new IllegalStateException("Duplicated property name.");
        }/* ww w.  j  a  v a2 s.  c o  m*/
        config.put(property, properties);
    }
}

From source file:org.intermine.api.mines.FriendlyMineManager.java

private Map<String, Mine> readConfig(InterMineAPI im, String localMineName) {
    mines = new LinkedHashMap<String, Mine>();
    Properties props = PropertiesUtil.stripStart("intermines",
            PropertiesUtil.getPropertiesStartingWith("intermines", webProperties));

    Enumeration<?> propNames = props.propertyNames();

    while (propNames.hasMoreElements()) {
        String mineId = (String) propNames.nextElement();
        mineId = mineId.substring(0, mineId.indexOf("."));
        Properties mineProps = PropertiesUtil.stripStart(mineId,
                PropertiesUtil.getPropertiesStartingWith(mineId, props));

        String mineName = mineProps.getProperty("name");
        String url = mineProps.getProperty("url");
        String logo = mineProps.getProperty("logo");
        String defaultValues = mineProps.getProperty("defaultValues");
        String bgcolor = mineProps.getProperty("bgcolor");
        String frontcolor = mineProps.getProperty("frontcolor");
        String description = mineProps.getProperty("description");

        if (StringUtils.isEmpty(mineName) || StringUtils.isEmpty(url)) {
            final String msg = "InterMine configured incorrectly in web.properties.  "
                    + "Cannot generate friendly mine linkouts: " + mineId;
            LOG.error(msg);//  w  w  w .jav a 2  s.c o m
            continue;
        }

        if (mineName.equals(localMineName)) {
            if (localMine.getUrl() == null) {
                parseLocalConfig(url, logo, defaultValues, bgcolor, frontcolor, description);
            }
        } else {
            Mine mine = mines.get(mineId);
            if (mine == null) {
                parseRemoteConfig(mineName, mineId, defaultValues, url, logo, bgcolor, frontcolor, description);
            }
        }
    }
    return mines;
}

From source file:org.jsecurity.jndi.JndiTemplate.java

/**
 * Create a new JNDI initial context. Invoked by {@link #execute}.
 * <p>The default implementation use this template's environment settings.
 * Can be subclassed for custom contexts, e.g. for testing.
 *
 * @return the initial Context instance// w w w . j a  va  2s . c  o  m
 * @throws NamingException in case of initialization errors
 */
@SuppressWarnings({ "unchecked" })
protected Context createInitialContext() throws NamingException {
    Properties env = getEnvironment();
    Hashtable icEnv = null;
    if (env != null) {
        icEnv = new Hashtable(env.size());
        for (Enumeration en = env.propertyNames(); en.hasMoreElements();) {
            String key = (String) en.nextElement();
            icEnv.put(key, env.getProperty(key));
        }
    }
    return new InitialContext(icEnv);
}

From source file:org.wso2.carbon.identity.event.EventMgtConfigBuilder.java

/**
 * Build and store per module configuration objects
 *//* ww  w  . j av  a 2s .c o m*/
private void build() {
    Properties moduleNames = EventManagementUtils.getSubProperties("module.name",
            notificationMgtConfigProperties);
    Enumeration propertyNames = moduleNames.propertyNames();
    // Iterate through events and build event objects
    while (propertyNames.hasMoreElements()) {
        String key = (String) propertyNames.nextElement();
        String moduleName = (String) moduleNames.remove(key);
        moduleConfiguration.put(moduleName, buildModuleConfigurations(moduleName));
    }
}

From source file:cn.vlabs.duckling.vwb.service.config.impl.ContainerConfig.java

private void writeToFile(Properties prop) {
    FileInputStream in;/*from www  .j  a v a2 s .com*/
    try {
        PropertyWriter pw = new PropertyWriter();
        in = new FileInputStream(configFile);
        pw.load(in);
        in.close();
        Enumeration<?> iter = prop.propertyNames();
        while (iter.hasMoreElements()) {
            String key = (String) iter.nextElement();
            pw.setProperty(key, prop.getProperty(key));
        }

        FileOutputStream out = new FileOutputStream(configFile);
        pw.store(out);
        out.close();
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }
}