Example usage for java.util Properties stringPropertyNames

List of usage examples for java.util Properties stringPropertyNames

Introduction

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

Prototype

public Set<String> stringPropertyNames() 

Source Link

Document

Returns an unmodifiable set of keys from this property list where the key and its corresponding value are strings, 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.falcon.workflow.engine.FalconWorkflowEngine.java

private InstancesResult.Instance performAction(String cluster, Entity entity, JobAction action,
        ExecutionInstance instance) throws FalconException {
    EntityExecutor executor = EXECUTION_SERVICE.getEntityExecutor(entity, cluster);
    InstancesResult.Instance instanceInfo = null;
    LOG.debug("Retrieving information for {} for action {}", instance.getId(), action);
    if (StringUtils.isNotEmpty(instance.getExternalID())) {
        instanceInfo = DAGEngineFactory.getDAGEngine(cluster).info(instance.getExternalID());
    } else {// w  w  w .ja va  2s. c  o m
        instanceInfo = new InstancesResult.Instance();
    }
    switch (action) {
    case KILL:
        executor.kill(instance);
        instanceInfo.status = InstancesResult.WorkflowStatus.KILLED;
        break;
    case SUSPEND:
        executor.suspend(instance);
        instanceInfo.status = InstancesResult.WorkflowStatus.SUSPENDED;
        break;
    case RESUME:
        executor.resume(instance);
        instanceInfo.status = InstancesResult.WorkflowStatus
                .valueOf(STATE_STORE.getExecutionInstance(instance.getId()).getCurrentState().name());
        break;
    case RERUN:
        break;
    case STATUS:
        if (StringUtils.isNotEmpty(instance.getExternalID())) {
            List<InstancesResult.InstanceAction> instanceActions = DAGEngineFactory.getDAGEngine(cluster)
                    .getJobDetails(instance.getExternalID());
            instanceInfo.actions = instanceActions
                    .toArray(new InstancesResult.InstanceAction[instanceActions.size()]);
        }
        break;

    case PARAMS:
        // Mask details, log
        instanceInfo.details = null;
        instanceInfo.logFile = null;
        Properties props = DAGEngineFactory.getDAGEngine(cluster).getConfiguration(instance.getExternalID());
        InstancesResult.KeyValuePair[] keyValuePairs = new InstancesResult.KeyValuePair[props.size()];
        int i = 0;
        for (String name : props.stringPropertyNames()) {
            keyValuePairs[i++] = new InstancesResult.KeyValuePair(name, props.getProperty(name));
        }
        break;
    default:
        throw new IllegalArgumentException("Unhandled action " + action);
    }
    return instanceInfo;
}

From source file:se.sics.kompics.p2p.experiment.dsl.SimulationScenario.java

/**
 * Prepare instrumentation exceptions.// w w w.  java 2s . co  m
 */
private static void prepareInstrumentationExceptions() {
    // well known exceptions
    exceptions.add("java.lang.ref.Reference");
    exceptions.add("java.lang.ref.Finalizer");
    exceptions.add("se.sics.kompics.p2p.simulator.P2pSimulator");
    exceptions.add("org.apache.log4j.PropertyConfigurator");
    exceptions.add("org.apache.log4j.helpers.FileWatchdog");
    exceptions.add("org.mortbay.thread.QueuedThreadPool");
    exceptions.add("org.mortbay.io.nio.SelectorManager");
    exceptions.add("org.mortbay.io.nio.SelectorManager$SelectSet");
    exceptions.add("org.apache.commons.math.stat.descriptive.SummaryStatistics");
    exceptions.add("org.apache.commons.math.stat.descriptive.DescriptiveStatistics");

    // try to add user-defined exceptions from properties file
    InputStream in = ClassLoader.getSystemResourceAsStream("timer.interceptor.properties");
    Properties p = new Properties();
    if (in != null) {
        try {
            p.load(in);
            for (String classname : p.stringPropertyNames()) {
                String value = p.getProperty(classname);
                if (value != null && value.equals("IGNORE")) {
                    exceptions.add(classname);
                    logger.debug("Adding instrumentation exception {}", classname);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        logger.debug("Could not find timer.interceptor.properties");
    }
}

From source file:io.pivotal.github.GithubClient.java

@Autowired
public void setUserMappingResource(@Value("classpath:jira-to-github-users.properties") Resource resource)
        throws IOException {
    Properties properties = new Properties();
    properties.load(resource.getInputStream());
    jiraUsernameToGithubUsername = new HashMap<>();

    for (final String name : properties.stringPropertyNames()) {
        jiraUsernameToGithubUsername.put(name, properties.getProperty(name));
    }//ww w .  j av  a 2 s  .co m
}

From source file:com.qpark.maven.plugin.router.RouterXmlMojo.java

private List<String> getOperationProviderBeanNames(final Properties p) {
    List<String> list = new ArrayList<String>();
    String value;// w w  w.ja  va  2 s  .co  m
    for (String key : p.stringPropertyNames()) {
        if (key != null && key.startsWith(RouterProperitesMojo.ROUTER_OPERATION_PROVIDER_BEAN_NAME)) {
            value = p.getProperty(key);
            if (value != null && value.trim().length() > 0) {
                list.add(value.trim());
            }
        }
    }
    return list;
}

From source file:cat.albirar.framework.sets.registry.impl.SetRegistryDefaultImpl.java

/**
 * {@inheritDoc}// ww  w  . j a  v  a  2 s. com
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public int loadFromProperties(Properties properties) throws ClassNotFoundException {
    Iterator<String> it;
    String nom;
    String valor;
    Matcher matcher;
    INamedSet<?> namedSet;
    String className;
    Class<?> modelClass;
    int n;

    Assert.notNull(properties, "The properties argument are required!");
    if (logger.isTraceEnabled()) {
        logger.trace("Processing set registry from property file!");
    }
    it = properties.stringPropertyNames().iterator();
    while (it.hasNext()) {
        nom = it.next().trim();
        valor = properties.getProperty(nom).trim();
        if (StringUtils.hasText(valor)) {
            matcher = pattern.matcher(valor);
            if (matcher.matches()) {
                className = matcher.group(1);
                // Check if available
                modelClass = getClass().getClassLoader().loadClass(className);
                namedSet = new NamedSetDefaultImpl(modelClass, nom);
                // Process properties
                for (n = 2; n < matcher.groupCount(); n++) {
                    valor = matcher.group(n).trim();
                    if (valor.startsWith(",")) {
                        valor = valor.substring(1).trim();
                    }
                    namedSet.add(valor);
                }
                putSet(namedSet);
            } else {
                logger.error("Error on load from property file. Property '" + nom + "' have incorrect format: '"
                        + valor + "'");
                throw new IllegalArgumentException("When load from property file. The property '" + nom
                        + "' is not in the expected format (" + valor
                        + "). The format should to be compatible with " + REGEX_FORMAT);
            }
        } else {
            logger.error("Error on load from property file. Property '" + nom + "' have no value");
            throw new IllegalArgumentException("When load from property file. The property '" + nom
                    + "' have no value. The format should to be compatible with " + REGEX_FORMAT);
        }
    }

    if (logger.isTraceEnabled()) {
        logger.trace(String.format("Property file processed. %d sets added!", registry.size()));
    }
    return registry.size();
}

From source file:org.apache.zeppelin.interpreter.remote.RemoteInterpreter.java

private Map<String, String> getEnvFromInterpreterProperty(Properties property) {
    Map<String, String> env = new HashMap<String, String>();
    StringBuilder sparkConfBuilder = new StringBuilder();
    for (String key : property.stringPropertyNames()) {
        if (RemoteInterpreterUtils.isEnvString(key)) {
            env.put(key, property.getProperty(key));
        }/*from   w w  w . ja  v  a  2 s  . c  o m*/
        if (key.equals("master")) {
            sparkConfBuilder.append(" --master " + property.getProperty("master"));
        }
        if (isSparkConf(key, property.getProperty(key))) {
            sparkConfBuilder.append(" --conf " + key + "=" + toShellFormat(property.getProperty(key)));
        }
    }
    env.put("ZEPPELIN_SPARK_CONF", sparkConfBuilder.toString());
    return env;
}

From source file:org.wso2.carbon.identity.mgt.IdentityMgtConfig.java

/**
 * This utility method is used to get the parameters from the configuration
 * file for a given policy extension./*  w  w w .j  a  va2 s.co  m*/
 *
 * @param prop         - properties
 * @param extensionKey - extension key which is defined in the
 *                     IdentityMgtConstants
 * @param sequence     - property sequence number in the file
 * @return Map of parameters with key and value from the configuration file.
 */
private Map<String, String> getParameters(Properties prop, String extensionKey, int sequence) {

    Set<String> keys = prop.stringPropertyNames();

    Map<String, String> keyValues = new HashMap<String, String>();

    for (String key : keys) {
        // Get only the provided extensions.
        // Eg.
        // Password.policy.extensions.1
        if (key.contains(extensionKey + "." + String.valueOf(sequence))) {

            Matcher m = propertyPattern.matcher(key);

            // Find the .1. pattern in the property key.
            if (m.find()) {
                int searchIndex = m.end();

                /*
                      * Key length is > matched pattern's end index if it has
                 * parameters
                 * in the config file.
                 */
                if (key.length() > searchIndex) {
                    String propKey = key.substring(searchIndex);
                    String propValue = prop.getProperty(key);
                    keyValues.put(propKey, propValue);
                }
            }

        }
    }

    return keyValues;
}

From source file:nl.armatiek.xslweb.web.servlet.XSLWebServlet.java

private Destination getDestination(WebApp webApp, HttpServletRequest req, HttpServletResponse resp,
        OutputStream os, Properties outputProperties, PipelineStep currentStep, PipelineStep nextStep)
        throws Exception {
    Destination dest;/*from  w ww . j  a  v  a 2  s .c om*/
    if (nextStep == null) {
        Serializer serializer = webApp.getProcessor().newSerializer(os);
        if (outputProperties != null) {
            for (String key : outputProperties.stringPropertyNames()) {
                String value = outputProperties.getProperty(key);
                if (key.equals(OutputKeys.CDATA_SECTION_ELEMENTS)) {
                    value = value.replaceAll("\\{\\}", "{''}");
                }
                Property prop = Property.get(key);
                if (prop == null) {
                    continue;
                }
                serializer.setOutputProperty(prop, value);
            }
        }
        XMLStreamWriter xsw = new CleanupXMLStreamWriter(serializer.getXMLStreamWriter());
        dest = new XMLStreamWriterDestination(xsw);
    } else if (nextStep instanceof TransformerStep || nextStep instanceof SchemaValidatorStep) {
        dest = new XdmSourceDestination();
    } else if (nextStep instanceof JSONSerializerStep) {
        dest = ((JSONSerializerStep) nextStep).getDestination(webApp, req, resp, os, outputProperties);
    } else if (nextStep instanceof ZipSerializerStep) {
        dest = ((ZipSerializerStep) nextStep).getDestination(webApp, req, resp, os, outputProperties);
    } else if (nextStep instanceof ResourceSerializerStep) {
        dest = ((ResourceSerializerStep) nextStep).getDestination(webApp, req, resp, os, outputProperties);
    } else if (nextStep instanceof FopSerializerStep) {
        dest = ((FopSerializerStep) nextStep).getDestination(webApp, req, resp, os, outputProperties);
    } else {
        throw new XSLWebException("Could not determine destination");
    }
    return getDestination(webApp, dest, currentStep);
}

From source file:org.apache.atlas.security.InMemoryJAASConfiguration.java

private void initialize(Properties properties) {
    LOG.debug("==> InMemoryJAASConfiguration.initialize()");

    int prefixLen = JAAS_CONFIG_PREFIX_PARAM.length();

    Map<String, SortedSet<Integer>> jaasClients = new HashMap<>();
    for (String key : properties.stringPropertyNames()) {
        if (key.startsWith(JAAS_CONFIG_PREFIX_PARAM)) {
            String jaasKey = key.substring(prefixLen);
            StringTokenizer tokenizer = new StringTokenizer(jaasKey, ".");
            int tokenCount = tokenizer.countTokens();
            if (tokenCount > 0) {
                String clientId = tokenizer.nextToken();
                SortedSet<Integer> indexList = jaasClients.get(clientId);
                if (indexList == null) {
                    indexList = new TreeSet<>();
                    jaasClients.put(clientId, indexList);
                }//ww  w  .  ja  v a 2s  . c  om
                String indexStr = tokenizer.nextToken();

                int indexId = isNumeric(indexStr) ? Integer.parseInt(indexStr) : -1;

                Integer clientIdIndex = Integer.valueOf(indexId);

                if (!indexList.contains(clientIdIndex)) {
                    indexList.add(clientIdIndex);
                }

            }
        }
    }
    for (String jaasClient : jaasClients.keySet()) {

        for (Integer index : jaasClients.get(jaasClient)) {

            String keyPrefix = JAAS_CONFIG_PREFIX_PARAM + jaasClient + ".";

            if (index > -1) {
                keyPrefix = keyPrefix + String.valueOf(index) + ".";
            }

            String keyParam = keyPrefix + JAAS_CONFIG_LOGIN_MODULE_NAME_PARAM;
            String loginModuleName = properties.getProperty(keyParam);

            if (loginModuleName == null) {
                LOG.error(
                        "Unable to add JAAS configuration for client [{}] as it is missing param [{}]. Skipping JAAS config for [{}]",
                        jaasClient, keyParam, jaasClient);
                continue;
            } else {
                loginModuleName = loginModuleName.trim();
            }

            keyParam = keyPrefix + JAAS_CONFIG_LOGIN_MODULE_CONTROL_FLAG_PARAM;
            String controlFlag = properties.getProperty(keyParam);

            AppConfigurationEntry.LoginModuleControlFlag loginControlFlag = null;
            if (controlFlag != null) {
                controlFlag = controlFlag.trim().toLowerCase();
                switch (controlFlag) {
                case "optional":
                    loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL;
                    break;
                case "requisite":
                    loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUISITE;
                    break;
                case "sufficient":
                    loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT;
                    break;
                case "required":
                    loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
                    break;
                default:
                    String validValues = "optional|requisite|sufficient|required";
                    LOG.warn(
                            "Unknown JAAS configuration value for ({}) = [{}], valid value are [{}] using the default value, REQUIRED",
                            keyParam, controlFlag, validValues);
                    loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
                    break;
                }
            } else {
                LOG.warn("Unable to find JAAS configuration ({}); using the default value, REQUIRED", keyParam);
                loginControlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
            }

            Map<String, String> options = new HashMap<>();
            String optionPrefix = keyPrefix + JAAS_CONFIG_LOGIN_OPTIONS_PREFIX + ".";
            int optionPrefixLen = optionPrefix.length();
            for (String key : properties.stringPropertyNames()) {
                if (key.startsWith(optionPrefix)) {
                    String optionKey = key.substring(optionPrefixLen);
                    String optionVal = properties.getProperty(key);
                    if (optionVal != null) {
                        optionVal = optionVal.trim();

                        try {
                            if (optionKey.equalsIgnoreCase(JAAS_PRINCIPAL_PROP)) {
                                optionVal = SecurityUtil.getServerPrincipal(optionVal, (String) null);
                            }
                        } catch (IOException e) {
                            LOG.warn("Failed to build serverPrincipal. Using provided value:[{}]", optionVal);
                        }
                    }
                    options.put(optionKey, optionVal);
                }
            }

            AppConfigurationEntry entry = new AppConfigurationEntry(loginModuleName, loginControlFlag, options);

            if (LOG.isDebugEnabled()) {
                StringBuilder sb = new StringBuilder();
                sb.append("Adding client: [").append(jaasClient).append("{").append(index).append("}]\n");
                sb.append("\tloginModule: [").append(loginModuleName).append("]\n");
                sb.append("\tcontrolFlag: [").append(loginControlFlag).append("]\n");
                for (String key : options.keySet()) {
                    String val = options.get(key);
                    sb.append("\tOptions:  [").append(key).append("] => [").append(val).append("]\n");
                }
                LOG.debug(sb.toString());
            }

            List<AppConfigurationEntry> retList = applicationConfigEntryMap.get(jaasClient);
            if (retList == null) {
                retList = new ArrayList<>();
                applicationConfigEntryMap.put(jaasClient, retList);
            }

            retList.add(entry);
        }
    }

    LOG.debug("<== InMemoryJAASConfiguration.initialize({})", applicationConfigEntryMap);
}