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.flume.node.PropertiesFileConfigurationProvider.java

private Map<String, String> toMap(Properties properties) {
    Map<String, String> result = Maps.newHashMap();
    Enumeration<?> propertyNames = properties.propertyNames();
    while (propertyNames.hasMoreElements()) {
        String name = (String) propertyNames.nextElement();
        String value = properties.getProperty(name);
        result.put(name, value);/* ww w . ja v  a 2  s  . c  om*/
    }
    return result;
}

From source file:org.gnieh.blue.launcher.Main.java

/**
 * <p>//from  w  w  w. ja  v a2s  . c o  m
 * Loads the properties in the system property file associated with the
 * framework installation into <tt>System.setProperty()</tt>. These properties
 * are not directly used by the framework in anyway. By default, the system
 * property file is located in the <tt>conf/</tt> directory of the Felix
 * installation directory and is called "<tt>system.properties</tt>". The
 * installation directory of Felix is assumed to be the parent directory of
 * the <tt>felix.jar</tt> file as found on the system class path property.
 * The precise file from which to load system properties can be set by
 * initializing the "<tt>felix.system.properties</tt>" system property to an
 * arbitrary URL.
 * </p>
**/
public static void loadSystemProperties() {
    // The system properties file is either specified by a system
    // property or it is in the same directory as the Felix JAR file.
    // Try to load it from one of these places.

    // See if the property URL was specified as a property.
    URL propURL = null;
    String custom = System.getProperty(SYSTEM_PROPERTIES_PROP);
    if (custom != null) {
        try {
            propURL = new URL(custom);
        } catch (MalformedURLException ex) {
            System.err.print("Main: " + ex);
            return;
        }
    } else {
        // Determine where the configuration directory is by figuring
        // out where felix.jar is located on the system class path.
        File confDir = null;
        String classpath = System.getProperty("java.class.path");
        int index = classpath.toLowerCase().indexOf("felix.jar");
        int start = classpath.lastIndexOf(File.pathSeparator, index) + 1;
        if (index >= start) {
            // Get the path of the felix.jar file.
            String jarLocation = classpath.substring(start, index);
            // Calculate the conf directory based on the parent
            // directory of the felix.jar directory.
            confDir = new File(new File(new File(jarLocation).getAbsolutePath()).getParent(), CONFIG_DIRECTORY);
        } else {
            // Can't figure it out so use the current directory as default.
            confDir = new File(System.getProperty("user.dir"), CONFIG_DIRECTORY);
        }

        try {
            propURL = new File(confDir, SYSTEM_PROPERTIES_FILE_VALUE).toURI().toURL();
        } catch (MalformedURLException ex) {
            System.err.print("Main: " + ex);
            return;
        }
    }

    // Read the properties file.
    Properties props = new Properties();
    InputStream is = null;
    try {
        is = propURL.openConnection().getInputStream();
        props.load(is);
        is.close();
    } catch (FileNotFoundException ex) {
        // Ignore file not found.
    } catch (Exception ex) {
        System.err.println("Main: Error loading system properties from " + propURL);
        System.err.println("Main: " + ex);
        try {
            if (is != null)
                is.close();
        } catch (IOException ex2) {
            // Nothing we can do.
        }
        return;
    }

    // Perform variable substitution on specified properties.
    for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
        String name = (String) e.nextElement();
        System.setProperty(name, Util.substVars(props.getProperty(name), name, null, null));
    }
}

From source file:org.cloudfoundry.identity.uaa.integration.TestProfileEnvironment.java

private TestProfileEnvironment() {

    List<Resource> resources = new ArrayList<Resource>();

    for (String location : DEFAULT_PROFILE_CONFIG_FILE_LOCATIONS) {
        location = environment.resolvePlaceholders(location);
        Resource resource = recourceLoader.getResource(location);
        if (resource != null && resource.exists()) {
            resources.add(resource);//from ww  w .  ja v  a 2  s .  co m
        }
    }

    YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
    factory.setResources(resources.toArray(new Resource[resources.size()]));
    factory.setDocumentMatchers(Collections.singletonMap("platform",
            environment.acceptsProfiles("postgresql") ? "postgresql" : "hsqldb"));
    factory.setResolutionMethod(ResolutionMethod.OVERRIDE_AND_IGNORE);
    Properties properties = factory.getObject();

    logger.debug("Decoding environment properties: " + properties.size());
    if (!properties.isEmpty()) {
        for (Enumeration<?> names = properties.propertyNames(); names.hasMoreElements();) {
            String name = (String) names.nextElement();
            String value = properties.getProperty(name);
            if (value != null) {
                properties.setProperty(name, environment.resolvePlaceholders(value));
            }
        }
        if (properties.containsKey("spring_profiles")) {
            properties.setProperty(StandardEnvironment.ACTIVE_PROFILES_PROPERTY_NAME,
                    properties.getProperty("spring_profiles"));
        }
        // System properties should override the ones in the config file, so add it last
        environment.getPropertySources().addLast(new PropertiesPropertySource("uaa.yml", properties));
    }

    EnvironmentPropertiesFactoryBean environmentProperties = new EnvironmentPropertiesFactoryBean();
    environmentProperties.setEnvironment(environment);
    environmentProperties.setDefaultProperties(properties);
    Map<String, ?> debugProperties = environmentProperties.getObject();
    logger.debug("Environment properties: " + debugProperties);
}

From source file:org.wso2.carbon.identity.notification.mgt.email.bean.EmailSubscription.java

/**
 * Set endpoints to the email subscription
 *
 * @param prefix              prefix of the subscription
 * @param endpointsProperties Properties which are related to endpoints
 *//*from w w w.ja v a 2  s .  com*/
private void setEndpoints(String prefix, Properties endpointsProperties) {

    Properties endpointNames = NotificationManagementUtils.getSubProperties(prefix, endpointsProperties);
    Enumeration endpointNameSet = endpointNames.propertyNames();
    // Build all the endpoints by iterating through properties
    while (endpointNameSet.hasMoreElements()) {
        String key = (String) endpointNameSet.nextElement();
        String endpointName = (String) endpointNames.remove(key);
        // Build endpoint key using endpoint name
        String endpointKey = prefix + "." + endpointName;
        Properties endpointProperties = NotificationManagementUtils.getPropertiesWithPrefix(endpointKey,
                endpointsProperties);
        // Build and add email endpoint object to subscription
        try {
            emailEndpointInfoList.add(buildEndpoint(endpointKey, endpointProperties));
        } catch (NotificationManagementException e) {
            // If the particular endpoint building fails, An error message will be printed at the startup time.
            // And continue with building other endpoints
            log.error("Error while building endpoint object for endpoint with key " + endpointKey, e);
        }
    }
}

From source file:edu.amc.sakai.user.ResourcePropertiesEditStub.java

public ResourcePropertiesEditStub(Properties defaultConfig, Properties configOverrides) {
    super();/*from w  ww .j a  va 2 s  . c  om*/
    if (defaultConfig != null && !(defaultConfig.isEmpty())) {
        for (Enumeration i = defaultConfig.propertyNames(); i.hasMoreElements();) {
            String propertyName = (String) i.nextElement();
            String propertyValue = StringUtils.trimToNull((String) defaultConfig.getProperty(propertyName));
            if (propertyValue == null) {
                continue;
            }
            String[] propertyValues = propertyValue.split(";");
            if (propertyValues.length > 1) {
                for (String splitPropertyValue : propertyValues) {
                    super.addPropertyToList(propertyName, splitPropertyValue);
                }
            } else {
                super.addProperty(propertyName, propertyValue);
            }
        }
    }

    if (configOverrides != null && !(configOverrides.isEmpty())) {
        // slightly different... configOverrides are treated as complete
        // overwrites of existing values.
        for (Enumeration i = configOverrides.propertyNames(); i.hasMoreElements();) {
            String propertyName = (String) i.nextElement();
            super.removeProperty(propertyName);
            String propertyValue = StringUtils.trimToNull((String) configOverrides.getProperty(propertyName));
            String[] propertyValues = propertyValue.split(";");
            if (propertyValues.length > 1) {
                for (String splitPropertyValue : propertyValues) {
                    super.addPropertyToList(propertyName, splitPropertyValue);
                }
            } else {
                super.addProperty(propertyName, propertyValue);
            }
        }
    }
}

From source file:org.openflamingo.engine.configuration.ConfigurationManager.java

/**
 * Flamingo Site XML ??   Key Value Map .
 *
 * @param configuration {@link org.openflamingo.model.site.Configuration}
 * @return Key Value Map/* www  .  j  a  v a 2 s  .  c o  m*/
 */
public Map getConfiguratioMap(org.openflamingo.model.site.Configuration configuration) {
    List<Property> properties = configuration.getProperty();
    Map<String, String> map = new TreeMap<String, String>();
    for (Property property : properties) {
        if (!StringUtils.isEmpty(property.getName())) {
            String name = property.getName();
            String value = property.getValue();
            propertyMap.put(name, property);

            if (StringUtils.isEmpty(value)) {
                String defautlVaule = property.getDefautlVaule();
                if (!StringUtils.isEmpty(defautlVaule)) {
                    map.put(name, defautlVaule);
                }
            } else {
                map.put(name, value);
            }
        }
    }

    // if applySystemProperties = true, then inject System Properties to Map
    if (applySystemProperties) {
        Properties props = System.getProperties();
        Enumeration<?> names = props.propertyNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            String value = System.getProperty(name);
            map.put(name, value);
        }
    }
    return map;
}

From source file:com.honnix.yaacs.admin.lifecycle.Lifecycle.java

private void createAdapterServers() {
    Properties props = PropertiesLoader.loadProperties(ACPropertiesConstant.ADAPTER_PROPERTIES_FILE_NAME);

    adapterServerMap = new HashMap<String, AdapterServer>(props.size());

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

    while (propEnum.hasMoreElements()) {
        String key = (String) propEnum.nextElement();
        String value = props.getProperty(key);

        try {//from  w w w. j  a va  2  s  .  c om
            AdapterServer adapterServer = (AdapterServer) Class.forName(value).getConstructor(ACServer.class)
                    .newInstance(acServer);

            adapterServerMap.put(key, adapterServer);
        } catch (Exception e) {
            StringBuilder sb = new StringBuilder("Error create adapter server \"").append(value).append("\".");

            LOG.error(sb.toString(), e);
        }
    }
}

From source file:org.vmguys.reflect.BeanSearchUtil.java

/** Processes entire properties list, evokes setter values on the bean, and optionally removes
 * <code>Properties</code> keys  that are found.
 * @param properties object to analyze.//from  w  w w.j a  v  a 2 s.  com
 * @param prefix optional prefix value; the method name will be assumed data passed the prefix and
 * separator.  For example, "com.stuff.x.RunWork". If "com.stuff.x." is the prefix, "RunWork" will
 * be called.  All properties that do not start with the prefix will be ignored.
 * @param obj bean to call setters.
 * @param removeFoundKeys if <code>true</code>, keys that are found will be removed from the
 * <code>Properties</code> instance.
 * @throws IllegalArgumentException if error occurs calling set method.
 */
public void processProperties(Properties p, Object obj, boolean removeFoundKeys, String prefix) {
    StringBuffer notFound = new StringBuffer();
    Enumeration e = p.propertyNames();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        if (prefix != null) {
            if (key.startsWith(prefix)) {
                key = key.substring(prefix.length());
            } else { // Ignore
                key = null;
            }
        }
        if (key != null) {
            if (evokeWriteMethod(obj, key, p.getProperty(key)) && removeFoundKeys) {
                p.remove(key);
            }
        }
    }
}

From source file:org.agiso.tempel.starter.Bootstrap.java

@Override
public void run(String... args) throws Exception {
    // Konfiguracja opcji i parsowanie argumentw:
    Options options = configureTempelOptions();

    // Parsowanie parametrw wejciowych:
    CommandLine cmd = parseTempelCommandArgs(options, args);

    // Wywietlanie pomocy dla wywoania z parametrem 'help':
    if (cmd.hasOption('h')) {
        printTempelHelp(options);/*ww w.  j  ava2 s  . c  o  m*/
        System.exit(0);
    }

    // Okrelanie katalogu roboczego i katalogu repozytorium:
    String workDir = determineWorkDir(cmd);

    // Pobieranie nazwy szablonu do wykonania:
    String templateName;
    if (cmd.getArgList().size() != 1) {
        System.err.println("Incorrect params. Use \"tpl --help\" for help.");
        System.exit(-1);
    }
    templateName = String.valueOf(cmd.getArgList().get(0));

    // Budowanie mapy parametrw dodatkowych (okrelanych przez -Dkey=value):
    Map<String, String> params = new HashMap<String, String>();
    Properties properties = cmd.getOptionProperties("D");
    Enumeration<?> propertiesEnumeration = properties.propertyNames();
    while (propertiesEnumeration.hasMoreElements()) {
        String key = (String) propertiesEnumeration.nextElement();
        params.put(key, properties.getProperty(key));
    }

    // Uruchamianie generatora dla okrelonego szablonu:
    starterLogger.info(Logs.LOG_01, ansiString(GREEN, templateName));

    try {
        if (PARAM_READER != null) {
            tempel.setParamReader(PARAM_READER);
        }
        tempel.startTemplate(templateName, params, workDir);
        starterLogger.info(Logs.LOG_02, ansiString(GREEN, templateName));
    } catch (Exception e) {
        starterLogger.error(e, Logs.LOG_06, ansiString(RED, e.getMessage()));
        System.exit(-4);
    }
}

From source file:org.atomserver.core.validators.XSDValidator.java

public void setNamespaceMappings(Properties properties)
        throws SAXNotSupportedException, SAXNotRecognizedException, IOException {
    parser = new DOMParser();
    parser.setFeature("http://xml.org/sax/features/validation", true);
    Enumeration<?> uris = properties.propertyNames();
    while (uris.hasMoreElements()) {
        String uri = (String) uris.nextElement();
        String xsdLocation = properties.getProperty(uri);
        File tmpFile = File.createTempFile("temp", ".xsd");
        InputStream s = getClass().getClassLoader().getResourceAsStream(xsdLocation);
        if (s != null) {
            IOUtils.copy(s, new FileWriter(tmpFile));
            log.debug("found " + xsdLocation + " as a classpath resource");
        } else {/*from ww w. ja  v  a  2s.co  m*/
            File fileLoc = new File(xsdLocation);
            if (fileLoc.exists() && fileLoc.isFile()) {
                FileUtils.copyFile(fileLoc, tmpFile);
                log.debug("found " + xsdLocation + " as a file system resource");
            } else {
                try {
                    URL urlLoc = new URL(xsdLocation);
                    FileUtils.copyURLToFile(urlLoc, tmpFile);
                    log.debug("found " + xsdLocation + " as a url resource");
                } catch (MalformedURLException e) {
                    throw new IllegalArgumentException("could not find XSD resource:" + xsdLocation);
                }
            }
        }

        parser.setProperty(uri, tmpFile.getAbsolutePath());
    }
    parser.setErrorHandler(this);
}