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.opennms.tools.jmxconfiggenerator.helper.NameTools.java

public static void loadInternalDictionary() {
    Properties properties = new Properties();
    try {//from   w w w .  j a  v  a  2s.  com
        BufferedInputStream stream = new BufferedInputStream(
                NameTools.class.getClassLoader().getResourceAsStream("dictionary.properties"));
        properties.load(stream);
        stream.close();
    } catch (IOException ex) {
        logger.error("Load dictionary entires from internal properties files error: '{}'", ex.getMessage());
    }
    logger.info("Loaded '{}' internal dictionary entiers", properties.size());
    for (Object key : properties.keySet()) {
        dictionary.put(key.toString(), properties.get(key).toString());
    }
    logger.info("Dictionary entries loaded: '{}'", dictionary.size());
}

From source file:ren.hankai.cordwood.data.jpa.config.JpaDataSourceConfig.java

/**
 * ???????????? ???/*from   ww  w  .j  a  v a2  s.c  om*/
 *
 * @return ??
 * @author hankai
 * @since Jun 21, 2016 10:45:48 AM
 */
private static Properties loadExternalConfig(String fileName) {
    Properties props = null;
    try {
        props = new Properties();
        props.load(new FileInputStream(Preferences.getDbConfigFile(fileName)));
    } catch (final IOException ex) {
        logger.warn("Failed to load external database configuration file for production profile.", ex);
    }
    if ((props != null) && (props.size() > 0)) {
        return props;
    }
    return null;
}

From source file:org.kalypso.simulation.ui.calccase.ModelNature.java

private static IValueVariable[] registerValueVariablesFromProperties(final IStringVariableManager svm,
        final Properties properties) {
    final IValueVariable[] variables = new IValueVariable[properties.size()];
    int count = 0;
    for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
        final String name = (String) entry.getKey();
        final String value = (String) entry.getValue();

        final IValueVariable valueVariable = svm.newValueVariable(name, value, true, value);
        variables[count++] = valueVariable;

        try {//www .  j ava 2  s  .  com
            final IValueVariable existingVariable = svm.getValueVariable(name);
            if (existingVariable == null) {
                // add each variable separatedly, because it may have allready been registered
                svm.addVariables(new IValueVariable[] { valueVariable });
            } else {
                existingVariable.setValue(value);
            }
        } catch (final CoreException e) {
            System.out.println("Variable already exists: " + name); //$NON-NLS-1$
            e.printStackTrace();
            // ignore it, its already there -> ?
        }
    }

    return variables;
}

From source file:org.opennms.features.jmxconfiggenerator.Starter.java

public static Map<String, String> loadInternalDictionary() {
    Map<String, String> internalDictionary = new HashMap<String, String>();
    Properties properties = new Properties();
    try {/*w ww.  ja  va2s . c o  m*/
        BufferedInputStream stream = new BufferedInputStream(
                Starter.class.getClassLoader().getResourceAsStream("dictionary.properties"));
        properties.load(stream);
        stream.close();
    } catch (IOException ex) {
        logger.error("Load dictionary entries from internal properties files error: '{}'", ex.getMessage());
    }
    logger.info("Loaded '{}' internal dictionary entries", properties.size());
    for (final Entry<?, ?> entry : properties.entrySet()) {
        final Object key = entry.getKey();
        final Object value = entry.getValue();
        internalDictionary.put(key.toString(), value == null ? null : value.toString());
    }
    logger.info("Dictionary entries loaded: '{}'", internalDictionary.size());
    return internalDictionary;
}

From source file:org.springframework.test.context.support.TestPropertySourceUtils.java

/**
 * Convert the supplied <em>inlined properties</em> (in the form of <em>key-value</em>
 * pairs) into a map keyed by property name, preserving the ordering of property names
 * in the returned map.//from w  w  w  . j  a v  a2 s  .  co  m
 * <p>Parsing of the key-value pairs is achieved by converting all pairs
 * into <em>virtual</em> properties files in memory and delegating to
 * {@link Properties#load(java.io.Reader)} to parse each virtual file.
 * <p>For a full discussion of <em>inlined properties</em>, consult the Javadoc
 * for {@link TestPropertySource#properties}.
 * @param inlinedProperties the inlined properties to convert; potentially empty
 * but never {@code null}
 * @return a new, ordered map containing the converted properties
 * @since 4.1.5
 * @throws IllegalStateException if a given key-value pair cannot be parsed, or if
 * a given inlined property contains multiple key-value pairs
 * @see #addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
 */
public static Map<String, Object> convertInlinedPropertiesToMap(String... inlinedProperties) {
    Assert.notNull(inlinedProperties, "'inlinedProperties' must not be null");
    Map<String, Object> map = new LinkedHashMap<>();
    Properties props = new Properties();

    for (String pair : inlinedProperties) {
        if (!StringUtils.hasText(pair)) {
            continue;
        }
        try {
            props.load(new StringReader(pair));
        } catch (Exception ex) {
            throw new IllegalStateException("Failed to load test environment property from [" + pair + "]", ex);
        }
        Assert.state(props.size() == 1,
                () -> "Failed to load exactly one test environment property from [" + pair + "]");
        for (String name : props.stringPropertyNames()) {
            map.put(name, props.getProperty(name));
        }
        props.clear();
    }

    return map;
}

From source file:org.wso2.carbon.registry.core.utils.MediaTypesUtils.java

/**
 * Method to obtain the collection media types.
 *
 * @param configSystemRegistry a configuration system registry instance.
 *
 * @return a String of collection media types, in the format name:type,name:type,...
 * @throws RegistryException if the operation failed.
 *//* w  ww.  ja  va 2  s  .  com*/
public static String getCollectionMediaTypeMappings(Registry configSystemRegistry) throws RegistryException {

    RegistryContext registryContext = configSystemRegistry.getRegistryContext();

    if (getCollectionMediaTypeMappings(registryContext) != null) {
        return getCollectionMediaTypeMappings(registryContext);
    }

    Resource resource;
    String mediaTypeString = null;

    String resourcePath = MIME_TYPE_COLLECTION + RegistryConstants.PATH_SEPARATOR + RESOURCE_MIME_TYPE_INDEX;

    // TODO: Adding the media types should ideally be done by the handler associated with the
    // media type
    if (!configSystemRegistry.resourceExists(resourcePath)) {
        getResourceMediaTypeMappings(configSystemRegistry);
    }
    if (!configSystemRegistry
            .resourceExists(resourcePath + RegistryConstants.PATH_SEPARATOR + COLLECTION_MIME_TYPE_INDEX)) {
        resource = configSystemRegistry.newResource();
        resource.setDescription("This resource contains the media Types associated with "
                + "collections on the Registry. Add, Edit or Delete properties to Manage Media " + "Types.");
        configSystemRegistry.put(resourcePath + RegistryConstants.PATH_SEPARATOR + COLLECTION_MIME_TYPE_INDEX,
                resource);
    } else {
        resource = configSystemRegistry
                .get(resourcePath + RegistryConstants.PATH_SEPARATOR + COLLECTION_MIME_TYPE_INDEX);
    }
    Properties properties = resource.getProperties();
    if (properties.size() > 0) {
        Set<Object> keySet = properties.keySet();
        for (Object key : keySet) {
            if (key instanceof String) {
                String ext = (String) key;
                if (RegistryUtils.isHiddenProperty(ext)) {
                    continue;
                }
                String value = resource.getProperty(ext);
                String mediaTypeMapping = ext + ":" + value;
                if (mediaTypeString == null) {
                    mediaTypeString = mediaTypeMapping;
                } else {
                    mediaTypeString = mediaTypeString + "," + mediaTypeMapping;
                }
            }
        }
    }
    registryContext.setCollectionMediaTypes(mediaTypeString);
    return mediaTypeString;
}

From source file:org.wso2.carbon.registry.core.utils.MediaTypesUtils.java

/**
 * Method to obtain the custom UI media types.
 *
 * @param configSystemRegistry a configuration system registry instance.
 *
 * @return a String of custom UI media types, in the format name:type,name:type,...
 * @throws RegistryException if the operation failed.
 *//*from   w  w  w .j  a va 2s  .c o m*/
public static String getCustomUIMediaTypeMappings(Registry configSystemRegistry) throws RegistryException {

    RegistryContext registryContext = configSystemRegistry.getRegistryContext();

    if (getCustomUIMediaTypeMappings(registryContext) != null) {
        return getCustomUIMediaTypeMappings(registryContext);
    }

    Resource resource;
    String mediaTypeString = null;

    String resourcePath = MIME_TYPE_COLLECTION + RegistryConstants.PATH_SEPARATOR + RESOURCE_MIME_TYPE_INDEX;

    // TODO: Adding the media types should ideally be done by the handler associated with the
    // media type
    if (!configSystemRegistry.resourceExists(resourcePath)) {
        getResourceMediaTypeMappings(configSystemRegistry);
    }
    if (!configSystemRegistry
            .resourceExists(resourcePath + RegistryConstants.PATH_SEPARATOR + CUSTOM_UI_MIME_TYPE_INDEX)) {
        resource = configSystemRegistry.newResource();
        resource.setProperty("profiles", "application/vnd.wso2-profiles+xml");
        //resource.setProperty("service", "application/vnd.wso2-service+xml");
        resource.setDescription("This resource contains the media Types associated with "
                + "custom user interfaces on the Registry. Add, Edit or Delete properties to "
                + "Manage Media Types.");
        configSystemRegistry.put(resourcePath + RegistryConstants.PATH_SEPARATOR + CUSTOM_UI_MIME_TYPE_INDEX,
                resource);
    } else {
        resource = configSystemRegistry
                .get(resourcePath + RegistryConstants.PATH_SEPARATOR + CUSTOM_UI_MIME_TYPE_INDEX);
    }
    Properties properties = resource.getProperties();
    if (properties.size() > 0) {
        Set<Object> keySet = properties.keySet();
        for (Object key : keySet) {
            if (key instanceof String) {
                String ext = (String) key;
                if (RegistryUtils.isHiddenProperty(ext)) {
                    continue;
                }
                String value = resource.getProperty(ext);
                String mediaTypeMapping = ext + ":" + value;
                if (mediaTypeString == null) {
                    mediaTypeString = mediaTypeMapping;
                } else {
                    mediaTypeString = mediaTypeString + "," + mediaTypeMapping;
                }
            }
        }
    }
    registryContext.setCustomUIMediaTypes(mediaTypeString);
    return mediaTypeString;
}

From source file:com.whizzosoftware.hobson.rest.v1.JSONMarshaller.java

public static JSONObject createTaskJSON(HobsonRestContext ctx, HobsonTask task, boolean details,
        boolean properties) {
    JSONObject json = new JSONObject();
    json.put("name", task.getName());
    json.put("type", task.getType().toString());
    JSONObject links = new JSONObject();
    links.put("self", ctx.getApiRoot() + new Template(TaskResource.PATH)
            .format(createDoubleEntryMap(ctx, "providerId", task.getProviderId(), "taskId", task.getId())));
    json.put("links", links);

    if (details) {
        json.put("provider", task.getProviderId());
        json.put("conditions", task.getConditions());
        json.put("actions", task.getActions());
    }/*from   w w  w . jav a  2  s .  c o m*/

    if (properties) {
        Properties p = task.getProperties();
        if (p != null && p.size() > 0) {
            JSONObject props = new JSONObject();
            for (Object o : p.keySet()) {
                String key = o.toString();
                props.put(o.toString(), p.get(key));
            }
            json.put("properties", props);
        }
    }

    return json;
}

From source file:org.wso2.carbon.registry.core.utils.MediaTypesUtils.java

/**
 * Method to obtain the resource media types.
 *
 * @param configSystemRegistry a configuration system registry instance.
 *
 * @return a String of resource media types, in the format extension:type,extension:type,...
 * @throws RegistryException if the operation failed.
 *///from w ww  .  ja  v  a 2  s .  c  om
public static String getResourceMediaTypeMappings(Registry configSystemRegistry) throws RegistryException {

    RegistryContext registryContext = configSystemRegistry.getRegistryContext();

    if (getResourceMediaTypeMappings(registryContext) != null) {
        return getResourceMediaTypeMappings(registryContext);
    }

    Resource resource;
    String mediaTypeString = null;

    String resourcePath = MIME_TYPE_COLLECTION + RegistryConstants.PATH_SEPARATOR + RESOURCE_MIME_TYPE_INDEX;

    if (!configSystemRegistry.resourceExists(resourcePath)) {
        resource = configSystemRegistry.newCollection();
    } else {
        resource = configSystemRegistry.get(resourcePath);
        Properties properties = resource.getProperties();
        if (properties.size() > 0) {
            Set<Object> keySet = properties.keySet();
            for (Object key : keySet) {
                if (key instanceof String) {
                    String ext = (String) key;
                    if (RegistryUtils.isHiddenProperty(ext)) {
                        continue;
                    }
                    String value = resource.getProperty(ext);
                    String mediaTypeMapping = ext + ":" + value;
                    if (mediaTypeString == null) {
                        mediaTypeString = mediaTypeMapping;
                    } else {
                        mediaTypeString = mediaTypeString + "," + mediaTypeMapping;
                    }
                }
            }
        }
        registryContext.setResourceMediaTypes(mediaTypeString);
        return mediaTypeString;
    }

    BufferedReader reader;
    try {
        File mimeFile = getMediaTypesFile();
        reader = new BufferedReader(new InputStreamReader(new FileInputStream(mimeFile)));
    } catch (Exception e) {
        String msg = "Failed to read the the media type definitions file. Only a limited "
                + "set of media type definitions will be populated. ";
        log.error(msg, e);
        mediaTypeString = "txt:text/plain,jpg:image/jpeg,gif:image/gif";
        registryContext.setResourceMediaTypes(mediaTypeString);
        return mediaTypeString;
    }

    try {
        while (reader.ready()) {
            String mediaTypeData = reader.readLine().trim();
            if (mediaTypeData.startsWith("#")) {
                // ignore the comments
                continue;
            }

            if (mediaTypeData.length() == 0) {
                // ignore the blank lines
                continue;
            }

            // mime.type file delimits media types:extensions by tabs. if there is no
            // extension associated with a media type, there are no tabs in the line. so we
            // don't need such lines.
            if (mediaTypeData.indexOf('\t') > 0) {

                String[] parts = mediaTypeData.split("\t+");
                if (parts.length == 2 && parts[0].length() > 0 && parts[1].length() > 0) {

                    // there can multiple extensions associated with a single media type. in
                    // that case, extensions are delimited by a space.
                    String[] extensions = parts[1].trim().split(" ");
                    for (String extension : extensions) {
                        if (extension.length() > 0) {
                            String mediaTypeMapping = extension + ":" + parts[0];
                            resource.setProperty(extension, parts[0]);
                            if (mediaTypeString == null) {
                                mediaTypeString = mediaTypeMapping;
                            } else {
                                mediaTypeString = mediaTypeString + "," + mediaTypeMapping;
                            }
                        }
                    }
                }
            }
        }
        resource.setDescription("This collection contains the media Types available for "
                + "resources on the Registry. Add, Edit or Delete properties to Manage Media " + "Types.");
        Resource collection = configSystemRegistry.newCollection();
        collection.setDescription("This collection lists the media types available on the "
                + "Registry Server. Before changing an existing media type, please make sure "
                + "to alter existing resources/collections and related configuration details.");
        configSystemRegistry.put(MIME_TYPE_COLLECTION, collection);
        configSystemRegistry.put(resourcePath, resource);

    } catch (IOException e) {
        String msg = "Could not read the media type mappings file from the location: ";
        throw new RegistryException(msg, e);

    } finally {
        try {
            reader.close();
        } catch (IOException ignore) {
        }
    }
    registryContext.setResourceMediaTypes(mediaTypeString);
    return mediaTypeString;
}

From source file:org.apache.ranger.hadoop.client.config.HadoopConfigHolder.java

private static synchronized void init() {

    if (initialized) {
        return;/*w  ww .j  a v a2  s.c  o  m*/
    }

    try {
        InputStream in = HadoopConfigHolder.class.getClassLoader()
                .getResourceAsStream(DEFAULT_DATASOURCE_PARAM_PROP_FILE);
        if (in != null) {
            Properties prop = new Properties();
            try {
                prop.load(in);
            } catch (IOException e) {
                throw new HadoopException("Unable to get configuration information for Hadoop environments", e);
            } finally {
                try {
                    in.close();
                } catch (IOException e) {
                    // Ignored exception when the stream is closed.
                }
            }

            if (prop.size() == 0)
                return;

            for (Object keyobj : prop.keySet()) {
                String key = (String) keyobj;
                String val = prop.getProperty(key);

                int dotLocatedAt = key.indexOf(".");

                if (dotLocatedAt == -1) {
                    continue;
                }

                String dataSource = key.substring(0, dotLocatedAt);

                String propKey = key.substring(dotLocatedAt + 1);
                int resourceFoundAt = propKey.indexOf(".");
                if (resourceFoundAt > -1) {
                    String resourceName = propKey.substring(0, resourceFoundAt) + ".xml";
                    propKey = propKey.substring(resourceFoundAt + 1);
                    addConfiguration(dataSource, resourceName, propKey, val);
                }

            }
        }

        in = HadoopConfigHolder.class.getClassLoader().getResourceAsStream(GLOBAL_LOGIN_PARAM_PROP_FILE);
        if (in != null) {
            Properties tempLoginProp = new Properties();
            try {
                tempLoginProp.load(in);
            } catch (IOException e) {
                throw new HadoopException(
                        "Unable to get login configuration information for Hadoop environments from file: ["
                                + GLOBAL_LOGIN_PARAM_PROP_FILE + "]",
                        e);
            } finally {
                try {
                    in.close();
                } catch (IOException e) {
                    // Ignored exception when the stream is closed.
                }
            }
            globalLoginProp = tempLoginProp;
        }
    } finally {
        initialized = true;
    }
}