Example usage for java.util Dictionary keys

List of usage examples for java.util Dictionary keys

Introduction

In this page you can find the example usage for java.util Dictionary keys.

Prototype

public abstract Enumeration<K> keys();

Source Link

Document

Returns an enumeration of the keys in this dictionary.

Usage

From source file:org.openengsb.itests.util.AbstractExamTestHelper.java

@SuppressWarnings("rawtypes")
private static String explode(Dictionary dictionary) {
    Enumeration keys = dictionary.keys();
    StringBuffer result = new StringBuffer();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        result.append(String.format("%s=%s", key, dictionary.get(key)));
        if (keys.hasMoreElements()) {
            result.append(", ");
        }/*from  w ww .  ja  v a2s  .  c om*/
    }
    return result.toString();
}

From source file:org.opentaps.notes.repository.impl.NoteRepositoryImpl.java

private static BasicDBObject noteToDbObject(Note note) {
    if (note == null) {
        return null;
    }/*from   w ww  . j  a v a2  s  . com*/
    BasicDBObject noteDoc = (BasicDBObject) BasicDBObjectBuilder.start()
            .add(Note.Fields.noteId.getName(), note.getNoteId())
            .add(Note.Fields.noteText.getName(), note.getNoteText())
            .add(Note.Fields.clientDomain.getName(), note.getClientDomain()).get();

    User user = note.getCreatedByUser();
    if (user != null) {
        BasicDBObject userDoc = (BasicDBObject) BasicDBObjectBuilder.start().get();
        @SuppressWarnings("unchecked")
        Dictionary<String, Object> props = user.getProperties();
        if (props != null && !props.isEmpty()) {
            Enumeration<String> keys = props.keys();
            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                userDoc.append(key, props.get(key));
            }
        }
        noteDoc.append(Note.Fields.createdByUser.getName(), userDoc);
    }

    // look for custom fields
    for (String field : note.getAttributeNames()) {
        noteDoc.put(field, note.getAttribute(field));
    }

    return noteDoc;
}

From source file:Main.java

/**
 * Return a Dictionary object which is a subset of the given Dictionary,
 * where the tags all <b>begin</b> with the given tag.
 * //  w  w w  .j ava  2s.  c  om
 * Hastables and Properties can be used as they are Dictionaries.
 * 
 * @param superset
 *            .
 * 
 * 
 * @param tag
 *            String
 * @param result
 *            Dictionary<String,Object>
 */
public static void getSubset(Dictionary<String, Object> superset, String tag,
        Dictionary<String, Object> result) {
    if ((result == null) || (tag == null) || (superset == null)) {
        throw new IllegalArgumentException("Invalid arguments specified : superset = " + superset + " tag = "
                + tag + " result = " + result);
    }

    String key;
    Enumeration<String> enumKey = superset.keys();

    while (enumKey.hasMoreElements()) {
        key = enumKey.nextElement();

        if (key.startsWith(tag)) {
            result.put(key, superset.get(key));
        }
    }
}

From source file:org.opencastproject.ingest.scanner.InboxScannerService.java

public static Map<String, String> getCfgAsMap(Dictionary<String, String> d, String key)
        throws ConfigurationException {
    HashMap<String, String> config = new HashMap<String, String>();
    for (Enumeration<String> e = d.keys(); e.hasMoreElements();) {
        String dKey = (String) e.nextElement();
        if (dKey.startsWith(key))
            config.put(dKey.substring(key.length() + 1), (String) d.get(dKey));
    }//w w  w  .  j a  va 2  s.  com
    return config;
}

From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java

@SuppressWarnings("unchecked")
public static Map<String, MetadataField<?>> getDublinCoreProperties(Dictionary configProperties) {
    Map<String, MetadataField<?>> dublinCorePropertyMapByConfigurationName = new HashMap<String, MetadataField<?>>();
    for (Object configObject : Collections.list(configProperties.keys())) {
        String property = configObject.toString();
        if (getDublinCorePropertyName(property).isSome()) {
            MetadataField<?> dublinCoreProperty = dublinCorePropertyMapByConfigurationName
                    .get(getDublinCorePropertyName(property).get());
            if (dublinCoreProperty == null) {
                dublinCoreProperty = new MetadataField();
            }/*from   w w w . j a v  a2s. c  om*/
            dublinCoreProperty.setValue(getDublinCorePropertyKey(property).get(),
                    configProperties.get(property).toString());
            dublinCorePropertyMapByConfigurationName.put(getDublinCorePropertyName(property).get(),
                    dublinCoreProperty);
        }
    }
    Map<String, MetadataField<?>> dublinCorePropertyMap = new TreeMap<String, MetadataField<?>>();
    for (MetadataField dublinCoreProperty : dublinCorePropertyMapByConfigurationName.values()) {
        dublinCorePropertyMap.put(dublinCoreProperty.getOutputID(), dublinCoreProperty);
    }
    return dublinCorePropertyMap;
}

From source file:org.apache.cxf.dosgi.dsw.OsgiUtils.java

public static Filter createFilterFromProperties(BundleContext bc, Dictionary properties) {

    if (properties == null || properties.isEmpty()) {
        return null;
    }/*from   w w w  . j  a  v a2s  .c o  m*/

    StringBuilder sb = new StringBuilder();
    sb.append("(&");
    for (Enumeration keys = properties.keys(); keys.hasMoreElements();) {
        String key = keys.nextElement().toString();
        String value = properties.get(key).toString();
        sb.append('(').append(key).append('=').append(value).append(')');
    }
    sb.append(')');
    return createFilter(bc, sb.toString());
}

From source file:org.wso2.carbon.application.deployer.AppDeployerUtils.java

public static String getParentAppName(Bundle bundle) {
    Dictionary dictionary = bundle.getHeaders();
    if (dictionary != null) {

        // Iterate through the headers and find the ParentApplication custom header
        for (Enumeration e = dictionary.keys(); e.hasMoreElements();) {

            String headerKey = (String) e.nextElement();
            if (AppDeployerConstants.PARENT_APP_HEADER.equals(headerKey)) {
                // retireve the header value
                String headerValue = (String) dictionary.get(headerKey);
                if (headerValue != null) {
                    return headerValue;
                }// w  w w  .  java 2s.  c  o m
            }
        }
    }
    return null;
}

From source file:org.wso2.carbon.application.deployer.AppDeployerUtils.java

/**
 * Checking whether a bundle contains the WSO2-Application-Deployer header
 *
 * @param bundle - input bundle/*from w ww.  j a  v  a 2s. c om*/
 * @return - if found header - true, else - false
 */
public static boolean isAppDeployer(Bundle bundle) {
    Dictionary dictionary = bundle.getHeaders();
    if (dictionary != null) {

        // Iterate through the headers and find the WSO2-Project-Artifact custom header
        for (Enumeration e = dictionary.keys(); e.hasMoreElements();) {

            String headerKey = (String) e.nextElement();
            if (AppDeployerConstants.WSO2_APP_DEPLOYER_HEADER.equals(headerKey)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.wso2.carbon.application.deployer.AppDeployerUtils.java

/**
 * Check whether the given bundle is a project artifact. If yes, return the app name. If no,
 * return null/*from w  w  w.  j  av a2s  . c  om*/
 *
 * @param bundle - bundle to check
 * @return - app name
 */
public static String getProjectArtifactName(Bundle bundle) {
    Dictionary dictionary = bundle.getHeaders();
    if (dictionary != null) {

        // Iterate through the headers and find the WSO2-Project-Artifact custom header
        for (Enumeration e = dictionary.keys(); e.hasMoreElements();) {

            String headerKey = (String) e.nextElement();
            if (AppDeployerConstants.WSO2_APP_NAME_HEADER.equals(headerKey)) {

                // retireve the header value
                String headerValue = (String) dictionary.get(headerKey);
                if (headerValue != null) {
                    return headerValue;
                }
            }
        }
    }
    return null;
}

From source file:Main.java

private static Manifest getSurrogateManifest(Dictionary compositeManifest, BundleDescription compositeDesc,
        ExportPackageDescription[] matchingExports) {
    Manifest manifest = new Manifest();
    Attributes attributes = manifest.getMainAttributes();
    attributes.putValue("Manifest-Version", "1.0"); //$NON-NLS-1$//$NON-NLS-2$
    // Ignore the manifest version from the map
    // always use bundle manifest version 2
    attributes.putValue(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$
    // Ignore the Equinox composite bundle header
    attributes.putValue(BaseStorageHook.COMPOSITE_HEADER, BaseStorageHook.SURROGATE_BUNDLE);

    if (compositeDesc != null && matchingExports != null) {
        // convert the exports from the composite into imports
        addImports(attributes, compositeDesc, matchingExports);

        // convert the matchingExports from the composite into exports
        addExports(attributes, compositeDesc, matchingExports);
    }/* w ww.j a va  2s  .c  o  m*/

    // add the rest
    for (Enumeration keys = compositeManifest.keys(); keys.hasMoreElements();) {
        Object header = keys.nextElement();
        if (Constants.BUNDLE_MANIFESTVERSION.equals(header) || BaseStorageHook.COMPOSITE_HEADER.equals(header)
                || Constants.IMPORT_PACKAGE.equals(header) || Constants.EXPORT_PACKAGE.equals(header))
            continue;
        if (header instanceof String && compositeManifest.get(header) instanceof String)
            attributes.putValue((String) header, (String) compositeManifest.get(header));
    }
    return manifest;
}