Example usage for java.util Properties size

List of usage examples for java.util Properties size

Introduction

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

Prototype

@Override
    public int size() 

Source Link

Usage

From source file:org.globus.security.stores.PEMKeyStore.java

/**
 * Load the keystore from the supplied input stream. Unlike many other
 * implementations of keystore (most notably the default JKS
 * implementation), the input stream does not hold the keystore objects.
 * Instead, it must be a properties file defining the locations of the
 * keystore objects. The password is not used.
 * /*  www  .ja v  a  2s. com*/
 * @param inputStream
 *            An input stream to the properties file.
 * @param chars
 *            The password is not used.
 * @throws IOException
 * @throws NoSuchAlgorithmException
 * @throws CertificateException
 */
@Override
public void engineLoad(InputStream inputStream, char[] chars)
        throws IOException, NoSuchAlgorithmException, CertificateException {
    try {
        Properties properties = new Properties();
        properties.load(inputStream);
        if (properties.size() == 0) {
            throw new CertificateException("Properties file for configuration was null");
        }
        String defaultDirectoryString = properties.getProperty(DEFAULT_DIRECTORY_KEY);
        String directoryListString = properties.getProperty(DIRECTORY_LIST_KEY);
        String proxyFilename = properties.getProperty(PROXY_FILENAME);
        String certFilename = properties.getProperty(CERTIFICATE_FILENAME);
        String keyFilename = properties.getProperty(KEY_FILENAME);
        initialize(defaultDirectoryString, directoryListString, proxyFilename, certFilename, keyFilename);
    } finally {
        try {
            inputStream.close();
        } catch (IOException e) {
            logger.log(Level.INFO, "Error closing inputStream", e);
        }
    }
}

From source file:org.apache.directory.fortress.core.impl.ConfigP.java

/**
 * Method will perform simple validations to ensure the integrity of the {@link Properties} entity targeted for insertion
 * or deletion in directory./*w  w w  .j  av a2 s .  co  m*/
 *
 * @param name contains the name of the cfg node.
 * @param entity contains the name/value properties targeted for operation.
 * @throws org.apache.directory.fortress.core.ValidationException thrown in the event the validations fail.
 */
private void validate(String name, Properties entity) throws ValidationException {
    if (StringUtils.isEmpty(name)) {
        String error = "validate detected null config realm name";
        LOG.warn(error);
        throw new ValidationException(GlobalErrIds.FT_CONFIG_NAME_NULL, error);
    }
    if (name.length() > GlobalIds.OU_LEN) {
        String error = "validate name [" + name + "] invalid length [" + name.length() + "]";
        LOG.warn(error);
        throw new ValidationException(GlobalErrIds.FT_CONFIG_NAME_INVLD, error);
    }
    if (entity == null || entity.size() == 0) {
        String error = "validate name [" + name + "] config props null";
        LOG.warn(error);
        throw new ValidationException(GlobalErrIds.FT_CONFIG_PROPS_NULL, error);
    }
    VUtil.properties(entity);
}

From source file:org.apache.wiki.providers.AbstractFileProvider.java

/**
 * Default validation, validates that key and value is ASCII <code>StringUtils.isAsciiPrintable()</code> and within lengths set up in jspwiki-custom.properties.
 * This can be overwritten by custom FileSystemProviders to validate additional properties
 * See https://issues.apache.org/jira/browse/JSPWIKI-856
 * @since 2.10.2/*from  www .j a  v  a 2 s  .c o m*/
 * @param customProperties the custom page properties being added
 */
protected void validateCustomPageProperties(Properties customProperties) throws IOException {
    // Default validation rules
    if (customProperties != null && !customProperties.isEmpty()) {
        if (customProperties.size() > MAX_PROPLIMIT) {
            throw new IOException("Too many custom properties. You are adding " + customProperties.size()
                    + ", but max limit is " + MAX_PROPLIMIT);
        }
        Enumeration propertyNames = customProperties.propertyNames();
        while (propertyNames.hasMoreElements()) {
            String key = (String) propertyNames.nextElement();
            String value = (String) customProperties.get(key);
            if (key != null) {
                if (key.length() > MAX_PROPKEYLENGTH) {
                    throw new IOException("Custom property key " + key + " is too long. Max allowed length is "
                            + MAX_PROPKEYLENGTH);
                }
                if (!StringUtils.isAsciiPrintable(key)) {
                    throw new IOException("Custom property key " + key + " is not simple ASCII!");
                }
            }
            if (value != null) {
                if (value.length() > MAX_PROPVALUELENGTH) {
                    throw new IOException("Custom property key " + key + " has value that is too long. Value="
                            + value + ". Max allowed length is " + MAX_PROPVALUELENGTH);
                }
                if (!StringUtils.isAsciiPrintable(value)) {
                    throw new IOException("Custom property key " + key
                            + " has value that is not simple ASCII! Value=" + value);
                }
            }
        }
    }
}

From source file:org.sonar.process.logging.Log4JPropertiesBuilderTest.java

private void verifyPropertiesForConfigureGlobalFileLog(Properties properties,
        String... expectedPropertyKeysAndValuesOrdered) {
    assertThat(properties.get("status")).isEqualTo("ERROR");
    if (expectedPropertyKeysAndValuesOrdered.length == 0) {
        assertThat(properties.size()).isEqualTo(1);
    } else {//from  w  w  w  .j  a v a 2  s .c o m
        assertThat(expectedPropertyKeysAndValuesOrdered.length % 2)
                .describedAs("Number of parameters must be even").isEqualTo(0);
        Set<String> keys = new HashSet<>(expectedPropertyKeysAndValuesOrdered.length / 2 + 1);
        keys.add("status");
        for (int i = 0; i < expectedPropertyKeysAndValuesOrdered.length; i++) {
            String key = expectedPropertyKeysAndValuesOrdered[i++];
            String value = expectedPropertyKeysAndValuesOrdered[i];
            assertThat(properties.get(key)).describedAs("Unexpected value for property " + key)
                    .isEqualTo(value);
            keys.add(key);
        }
        assertThat(properties.keySet()).containsOnly(keys.toArray());
    }
}

From source file:org.sakaiproject.chat2.model.impl.ChatEntityProducer.java

/**
 * try to add synoptic options for this tool to the archive, if they exist
 * @param siteId/*from   w  w w  .j  a  v a 2s .  c o  m*/
 * @param doc
 * @param element
 */
public void archiveSynopticOptions(String siteId, Document doc, Element element) {
    try {
        // archive the synoptic tool options
        Site site = SiteService.getSite(siteId);
        ToolConfiguration synTool = site.getToolForCommonId("sakai.synoptic." + getLabel());
        Properties synProp = synTool.getPlacementConfig();
        if (synProp != null && synProp.size() > 0) {
            Element synElement = doc.createElement(SYNOPTIC_TOOL);
            Element synProps = doc.createElement(PROPERTIES);

            Set synPropSet = synProp.keySet();
            Iterator propIter = synPropSet.iterator();
            while (propIter.hasNext()) {
                String propName = (String) propIter.next();
                Element synPropEl = doc.createElement(PROPERTY);
                synPropEl.setAttribute(NAME, propName);
                synPropEl.setAttribute(VALUE, synProp.getProperty(propName));
                synProps.appendChild(synPropEl);
            }

            synElement.appendChild(synProps);
            element.appendChild(synElement);
        }
    } catch (Exception e) {
        logger.warn("archive: exception archiving synoptic options for service: " + serviceName());
    }
}

From source file:org.dspace.servicemanager.config.DSpaceConfigurationServiceTest.java

/**
 * Test method for {@link org.dspace.servicemanager.config.DSpaceConfigurationService#getProperties()}.
 *//*from w  ww. j  a  v  a 2  s.  c o  m*/
@Test
public void testGetProperties() {
    Properties props = configurationService.getProperties();
    assertNotNull(props);
    assertEquals(numPropsLoaded, props.size());
    assertNotNull(props.get("service.name"));
    assertEquals("DSpace", props.get("service.name"));

    //trash the references
    props = null;
}

From source file:org.kuali.rice.core.impl.config.property.JAXBConfigImpl.java

protected void logPropertyValues(Properties p) {
    LOG.info("Loaded " + p.size() + " properties");
    if (LOG.isDebugEnabled()) {
        String s = getPropertyValuesAsString(p);
        LOG.debug("Displaying " + p.size() + " properties\n\n" + s + "\n");
    }/*from  w  w  w.  j  av a  2  s . c o  m*/
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceObjectProviderBase.java

/**
 * Sets language-dependent default variants. The key in the properties is the language and the
 * value is used a default variant./*from ww  w .  j av  a 2s. co m*/
 *
 * @param aDefaultVariants
 *            the default variant per language
 */
public void setDefaultVariants(Properties aDefaultVariants) {
    if (aDefaultVariants.size() == 0) {
        log.warn("setDefaultVariants called with zero-sized variants map.");
        defaultVariants = null;
    } else {
        defaultVariants = new Properties();
        defaultVariants.putAll(aDefaultVariants);
    }
}

From source file:io.cloudslang.content.database.services.dbconnection.DBConnectionManager.java

private void customizeDbPoolingProperties(Properties dbPoolingProperties) {
    if (dbPoolingProperties != null && dbPoolingProperties.size() > 0) {
        this.dbPoolingProperties = dbPoolingProperties;
        this.isPoolingEnabled = this.getPropBooleanValue(DB_POOL_ENABLE_NAME, DB_POOL_ENABLE_DEFAULT_VALUE);
    }//from  w  w  w .j av a2  s  . c o  m
}

From source file:org.sonar.batch.scan.DefaultProjectBootstrapperTest.java

@Test
public void shouldExtractModuleProperties() {
    Properties props = new Properties();
    props.setProperty("sources", "src/main/java");
    props.setProperty("tests", "src/test/java");
    props.setProperty("foo.sources", "src/main/java");
    props.setProperty("foobar.tests", "src/test/java");
    props.setProperty("foobar.binaries", "target/classes");

    Properties moduleProps = DefaultProjectBootstrapper.extractModuleProperties("bar", props);
    assertThat(moduleProps.size()).isEqualTo(0);

    moduleProps = DefaultProjectBootstrapper.extractModuleProperties("foo", props);
    assertThat(moduleProps.size()).isEqualTo(1);
    assertThat(moduleProps.get("sources")).isEqualTo("src/main/java");

    moduleProps = DefaultProjectBootstrapper.extractModuleProperties("foobar", props);
    assertThat(moduleProps.size()).isEqualTo(2);
    assertThat(moduleProps.get("tests")).isEqualTo("src/test/java");
    assertThat(moduleProps.get("binaries")).isEqualTo("target/classes");
}