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.wso2.carbon.dataservices.sql.driver.TDriver.java

@SuppressWarnings("unchecked")
private Properties getProperties(String url, Properties info) throws SQLException {
    if (url == null) {
        throw new SQLException("JDBC URL cannot be NULL");
    }/*from  w w  w  .j a  va 2 s.c  om*/
    Properties props = new Properties();
    for (Enumeration<String> e = (Enumeration<String>) info.propertyNames(); e.hasMoreElements();) {
        String key = e.nextElement();
        String value = info.getProperty(key);
        if (value != null) {
            props.setProperty(key.toUpperCase(), value);
        }
    }
    int pos = 0;
    StringBuilder token = new StringBuilder();
    pos = getNextTokenPos(url, pos, token);
    if (!Constants.JDBC_PREFIX.equalsIgnoreCase(token.toString())) {
        throw new SQLException("Malformed URL");
    }
    pos = getNextTokenPos(url, pos, token);
    if (!Constants.PROVIDER_PREFIX.equalsIgnoreCase(token.toString())) {
        throw new SQLException("Malformed URL");
    }
    pos = getNextTokenPos(url, pos, token);
    if (!Constants.EXCEL_PREFIX.equalsIgnoreCase(token.toString())
            && !Constants.GSPRED_PREFIX.equalsIgnoreCase(token.toString())) {
        throw new SQLException("Malformed URL");
    }
    props.setProperty(Constants.DRIVER_PROPERTIES.DATA_SOURCE_TYPE, token.toString());
    pos = getNextTokenPos(url, pos, token);
    if (Constants.DRIVER_PROPERTIES.FILE_PATH.equals(token.toString())) {
        isFilePath = true;
        pos = getNextTokenPos(url, pos, token);
        String propValue = token.toString();
        if (propValue == null || "".equals(propValue)) {
            throw new SQLException("File path attribute is missing");
        }
        props.setProperty(Constants.DRIVER_PROPERTIES.FILE_PATH, propValue);
    }

    Object dsType = props.getProperty(Constants.DRIVER_PROPERTIES.DATA_SOURCE_TYPE);
    if (dsType != null && Constants.GSPRED_PREFIX.equals(dsType.toString())) {
        pos = getNextTokenPos(url, pos, token);
        if (Constants.DRIVER_PROPERTIES.SHEET_NAME.equals(token.toString())) {
            pos = getNextTokenPos(url, pos, token);
            String propValue = token.toString();
            if (propValue == null || "".equals(propValue)) {
                throw new SQLException("Sheet name attribute is missing");
            }
            props.setProperty(Constants.DRIVER_PROPERTIES.SHEET_NAME, propValue);
        }
    }
    Properties optionalProps = getOptionalProperties(url, pos, token);
    /* check for maxColumns property */
    this.checkForHasHeaderProperty(optionalProps);

    for (Enumeration<String> e = (Enumeration<String>) optionalProps.propertyNames(); e.hasMoreElements();) {
        String key = e.nextElement();
        props.setProperty(key, optionalProps.getProperty(key));
    }
    return props;
}

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

private List<Property> getRegistryResourceProperties(String registryResourcePath, String applicationId)
        throws RegistryException, MetadataException {
    Registry tempRegistry = getRegistry();
    if (!tempRegistry.resourceExists(registryResourcePath)) {
        return null;
    }//from w  w  w.  j av  a  2  s  .  c o  m

    // We are using only super tenant registry to persist
    PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
    ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

    Resource regResource = tempRegistry.get(registryResourcePath);
    ArrayList<Property> newProperties = new ArrayList<>();
    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:com.attribyte.essem.BasicAuth.java

/**
 * Create from properties of the form username:password=index0,index1,...
 * @param props The properties.//ww  w.  ja v a 2 s .c  om
 */
public BasicAuth(final Properties props) {

    Map<HashCode, Set<String>> authMap = Maps.newHashMapWithExpectedSize(16);
    Set<String> indexSet = Sets.newLinkedHashSetWithExpectedSize(16);
    Splitter indexSplitter = Splitter.on(CharMatcher.anyOf(", \t")).trimResults().omitEmptyStrings();

    Enumeration names = props.propertyNames();
    while (names.hasMoreElements()) {

        String key = ((String) names.nextElement()).trim();
        String up = key.replace('|', ':');
        String expectedValue = "Basic " + EncodingUtil.encodeBase64(up.getBytes(Charsets.UTF_8));

        HashCode expectedValueCode = hashFunction.hashString(expectedValue, Charsets.UTF_8);
        Set<String> allowSet = authMap.get(expectedValueCode);
        if (allowSet == null) {
            allowSet = Sets.newLinkedHashSetWithExpectedSize(16);
            authMap.put(expectedValueCode, allowSet);
        }

        String indexStr = props.getProperty(key).trim();
        for (String index : indexSplitter.split(indexStr)) {
            if (!index.equals("*")) {
                indexSet.add(index);
            }
            allowSet.add(index);
        }
    }

    this.authorizedIndexes = ImmutableSet.copyOf(indexSet);

    ImmutableMap.Builder<HashCode, ImmutableSet<String>> builder = ImmutableMap.builder();
    for (Map.Entry<HashCode, Set<String>> entry : authMap.entrySet()) {
        builder.put(entry.getKey(), ImmutableSet.copyOf(entry.getValue()));
    }
    this.authMap = builder.build();
}

From source file:jp.terasoluna.fw.web.struts.action.GlobalMessageResources.java

/**
 * v?peBt@C?A}bvl?s?B/* ww w  .j a va 2 s.c o m*/
 */
private synchronized void globalInit() {

    // ?bZ?[WNA
    fwMessages.clear();

    // ?bZ?[W\?[Xt@C??[h?B
    Properties prop = PropertyUtil.loadProperties(this.config);
    if (prop == null) {
        // ???s?I?B
        return;
    }
    Enumeration keyEnum = prop.propertyNames();
    while (keyEnum.hasMoreElements()) {
        Object keyObj = keyEnum.nextElement();
        Object value = prop.get(keyObj);
        if (log.isDebugEnabled()) {
            log.debug("Saving framework message key [" + keyObj + "]" + "value [" + value + "]");
        }
        fwMessages.put((String) keyObj, (String) value);
    }
}

From source file:org.ops4j.pax.runner.platform.felix.internal.FelixPlatformBuilderF100T122.java

/**
 * @see org.ops4j.pax.runner.platform.PlatformBuilder
 *      #getVMOptions(org.ops4j.pax.runner.platform.PlatformContext)
 *//* w  w  w  .  ja v a2 s  .co m*/
public String[] getVMOptions(final PlatformContext context) {
    NullArgumentException.validateNotNull(context, "Platform context");

    final Collection<String> vmOptions = new ArrayList<String>();
    final File workingDirectory = context.getWorkingDirectory();
    vmOptions.add("-Dfelix.config.properties=" + context.getFilePathStrategy()
            .normalizeAsUrl(new File(new File(workingDirectory, CONFIG_DIRECTORY), CONFIG_INI)));
    vmOptions.add("-Dfelix.cache.dir=" + context.getFilePathStrategy()
            .normalizeAsPath(new File(new File(workingDirectory, CONFIG_DIRECTORY), CACHE_DIRECTORY)));
    final Properties frameworkProperties = context.getProperties();
    if (frameworkProperties != null) {
        final Enumeration enumeration = frameworkProperties.propertyNames();
        while (enumeration.hasMoreElements()) {
            final String key = (String) enumeration.nextElement();
            vmOptions.add("-D" + key + "=" + frameworkProperties.getProperty(key));
        }
    }
    return vmOptions.toArray(new String[vmOptions.size()]);
}

From source file:com.suse.studio.api.Studio.java

private Properties getConfig() throws StudioException {
    // Read in Studio.properties
    String configFile = this.getClass().getSimpleName() + ".properties";
    InputStream configFileIn = this.getClass().getClassLoader().getResourceAsStream(configFile);
    if (configFileIn == null) {
        throw new StudioException(String.format("Cannot find config file '%s'.", configFile));
    }//from  w ww.  j  a  v  a2 s.  c om
    Properties config = new Properties();
    try {
        config.load(configFileIn);
    } catch (IOException e) {
        throw new StudioException(String.format("Cannot parse config file '%s'.", configFile));
    }

    // Check that all property names are valid
    for (@SuppressWarnings("unchecked")
    Enumeration<String> e = (Enumeration<String>) config.propertyNames(); e.hasMoreElements();) {
        String propertyName = e.nextElement();
        boolean found = false;
        for (String key : KNOWN_KEYS) {
            if (propertyName.equals(key)) {
                found = true;
                break;
            }
        }
        if (!found) {
            throw new StudioException(String.format("Error reading config file '%s': unknown property '%s'.",
                    configFile, propertyName));
        }
    }

    return config;
}

From source file:org.ebayopensource.turmeric.tools.codegen.ServiceGeneratorSharedConsumerTest.java

private void createInterfacePropsFile(File basedir, Properties props) throws IOException {
    File file = new File(basedir, "service_intf_project.properties");
    Properties pro = loadProperties(file);
    Enumeration<?> names = props.propertyNames();
    while (names.hasMoreElements()) {
        String key = (String) names.nextElement();
        String value = props.getProperty(key);
        pro.setProperty(key, value);/*from  w  w  w .j  av  a2  s .c om*/
    }
    writeProperties(file, pro);
}

From source file:blast.config.spring.GroupingPropertiesPlaceholderConfigurer.java

protected String resolveAll(Properties props, String match) {
    String prefix = match;/*from  w w w  . j av a2  s.  c  o m*/
    int i = match.indexOf('(');
    if (i != -1) {
        if (i > match.length() - 1) {
            prefix = match.substring(i + 1);
        } else {
            prefix = "";
        }
        match = match.substring(0, i) + prefix;
    }

    StringBuffer sb = new StringBuffer();
    Enumeration<?> names = props.propertyNames();
    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        if (name.startsWith(match) && name.length() > match.length()) {
            sb.append(prefix);
            sb.append(name.substring(match.length()));
            sb.append('=');
            sb.append(props.getProperty(name));
            sb.append('\n');
        }
    }
    return sb.toString();
}

From source file:org.jasig.portal.spring.security.preauth.PortalPreAuthenticatedProcessingFilter.java

@Override
public void afterPropertiesSet() {
    super.afterPropertiesSet();

    this.credentialTokens = new HashMap<String, String>(1);
    this.principalTokens = new HashMap<String, String>(1);

    try {//w ww  . j  a v  a 2  s. c  om
        String key;
        // We retrieve the tokens representing the credential and principal
        // parameters from the security properties file.
        Properties props = ResourceLoader.getResourceAsProperties(getClass(),
                "/properties/security.properties");
        Enumeration propNames = props.propertyNames();
        while (propNames.hasMoreElements()) {
            String propName = (String) propNames.nextElement();
            String propValue = props.getProperty(propName);
            if (propName.startsWith("credentialToken.")) {
                key = propName.substring(16);
                this.credentialTokens.put(key, propValue);
            }
            if (propName.startsWith("principalToken.")) {
                key = propName.substring(15);
                this.principalTokens.put(key, propValue);
            }
        }
    } catch (PortalException pe) {
        logger.error("LoginServlet::static ", pe);
    } catch (IOException ioe) {
        logger.error("LoginServlet::static ", ioe);
    }
}

From source file:org.ops4j.pax.runner.platform.felix.internal.FelixPlatformBuilderF140T141.java

/**
 * @see org.ops4j.pax.runner.platform.PlatformBuilder
 *      #getVMOptions(org.ops4j.pax.runner.platform.PlatformContext)
 *///from   w  w  w. j  a v  a  2  s.c om
public String[] getVMOptions(final PlatformContext context) {
    NullArgumentException.validateNotNull(context, "Platform context");

    final Collection<String> vmOptions = new ArrayList<String>();
    final File workingDirectory = context.getWorkingDirectory();
    vmOptions.add("-Dfelix.config.properties=" + context.getFilePathStrategy()
            .normalizeAsUrl(new File(new File(workingDirectory, CONFIG_DIRECTORY), CONFIG_INI)));
    final Properties frameworkProperties = context.getProperties();
    if (frameworkProperties != null) {
        final Enumeration enumeration = frameworkProperties.propertyNames();
        while (enumeration.hasMoreElements()) {
            final String key = (String) enumeration.nextElement();
            vmOptions.add("-D" + key + "=" + frameworkProperties.getProperty(key));
        }
    }
    return vmOptions.toArray(new String[vmOptions.size()]);
}