Example usage for java.util Dictionary put

List of usage examples for java.util Dictionary put

Introduction

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

Prototype

public abstract V put(K key, V value);

Source Link

Document

Maps the specified key to the specified value in this dictionary.

Usage

From source file:org.opencastproject.dictionary.impl.DictionaryScanner.java

/**
 * {@inheritDoc}/*  ww  w.  j av a  2s. c  o m*/
 * 
 * @see org.apache.felix.fileinstall.ArtifactInstaller#install(java.io.File)
 */
@Override
public void install(File artifact) throws Exception {
    Integer numAllW = 1;
    String language = artifact.getName().split("\\.")[0];

    // Make sure we are not importing something that already exists
    if (Arrays.asList(dictionaryService.getLanguages()).contains(language)) {
        logger.debug("Skipping existing dictionary '{}'", language);
    } else {
        logger.info("Loading language pack from {}", artifact);
        // read csv file and fill dictionary index
        BufferedReader br = null;
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(artifact), "utf-8"), 1024 * 1024);
            String wordLine;
            while ((wordLine = br.readLine()) != null) {
                if (wordLine.startsWith("#")) {
                    if (wordLine.startsWith("#numAllW")) {
                        numAllW = Integer.valueOf(wordLine.split(":")[1]);
                    }
                    continue;
                }
                String[] arr = wordLine.split(",");
                String word = arr[0];
                Integer count = Integer.valueOf(arr[1]);
                Double weight = 1.0 * count / numAllW;
                try {
                    dictionaryService.addWord(word, language, count, weight);
                } catch (Exception e) {
                    logger.warn("Unable to add word '{}' to the {} dictionary: {}",
                            new String[] { word, language, e.getMessage() });
                }
            }
        } finally {
            IOUtils.closeQuietly(br);
        }
        logger.info("Finished loading language pack from {}", artifact);
    }

    sumInstalledFiles++;

    // Determine the number of available profiles
    String[] filesInDirectory = artifact.getParentFile().list(new FilenameFilter() {
        public boolean accept(File arg0, String name) {
            return name.endsWith(".csv");
        }
    });

    // Once all profiles have been loaded, announce readiness
    if (filesInDirectory.length == sumInstalledFiles) {
        Dictionary<String, String> properties = new Hashtable<String, String>();
        properties.put(ARTIFACT, "dictionary");
        logger.debug("Indicating readiness of dictionnaries");
        bundleCtx.registerService(ReadinessIndicator.class.getName(), new ReadinessIndicator(), properties);
        logger.info("All {} dictionaries installed", filesInDirectory.length);
    } else {
        logger.info("{} of {} dictionaries installed", sumInstalledFiles, filesInDirectory.length);
    }
}

From source file:org.paxle.gui.impl.servlets.LoginView.java

/**
 * This function is called the OSGI DS during component activation 
 * @param context/*from w w w  .  j  ava 2s. co m*/
 */
@Activate
protected void activate(Map<String, Object> props) {
    // check if an Administrator group is already available
    Group admins = (Group) userAdmin.getRole("Administrators");
    if (admins == null) {
        admins = (Group) userAdmin.createRole("Administrators", Role.GROUP);
    }

    User admin = (User) userAdmin.getRole("Administrator");
    if (admin == null) {
        // create a default admin user
        admin = (User) userAdmin.createRole("Administrator", Role.USER);
        admins.addMember(admin);

        // configure http-login data
        @SuppressWarnings("unchecked")
        Dictionary<String, Object> authprops = admin.getProperties();
        authprops.put(HttpAuthManager.USER_HTTP_LOGIN, "admin");

        @SuppressWarnings("unchecked")
        Dictionary<String, Object> credentials = admin.getCredentials();
        credentials.put(HttpAuthManager.USER_HTTP_PASSWORD, "");
    }
}

From source file:org.opennaas.itests.roadm.alarms.CompleteAlarmsWorkflowTest.java

private void generateRawSocketEvent(String transportId, String message) {

    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    properties.put(RawSocketTransport.MESSAGE_PROPERTY_NAME, message);
    properties.put(RawSocketTransport.TRANSPORT_ID_PROPERTY_NAME, transportId);
    long creationTime = new Date().getTime();
    properties.put(RawSocketTransport.ARRIVAL_TIME_PROPERTY_NAME, creationTime);

    Event event = new Event(RawSocketTransport.MSG_RCVD_EVENT_TOPIC, properties);

    eventManager.publishEvent(event);//from   w w  w  . j a va  2s. c  o  m
    log.debug("RawSocketTransport Event generated! " + message + " at " + creationTime);
}

From source file:org.apache.sling.resourceresolver.impl.legacy.LegacyResourceProviderWhiteboard.java

protected void bindResourceProvider(final ServiceReference ref) {
    final BundleContext bundleContext = ref.getBundle().getBundleContext();
    final ResourceProvider provider = (ResourceProvider) bundleContext.getService(ref);
    if (provider != null) {
        final String[] propertyNames = ref.getPropertyKeys();
        final boolean ownsRoot = toBoolean(ref.getProperty(OWNS_ROOTS), false);

        final List<ServiceRegistration> newServices = new ArrayList<ServiceRegistration>();
        for (final String path : PropertiesUtil.toStringArray(ref.getProperty(ROOTS), new String[0])) {
            if (path != null && !path.isEmpty()) {
                final Dictionary<String, Object> newProps = new Hashtable<String, Object>();
                newProps.put(PROPERTY_AUTHENTICATE, AuthType.no.toString());
                newProps.put(PROPERTY_MODIFIABLE, provider instanceof ModifyingResourceProvider);
                newProps.put(PROPERTY_ADAPTABLE, provider instanceof Adaptable);
                newProps.put(PROPERTY_ATTRIBUTABLE, provider instanceof AttributableResourceProvider);
                newProps.put(PROPERTY_REFRESHABLE, provider instanceof RefreshableResourceProvider);
                newProps.put(PROPERTY_NAME, provider.getClass().getName());
                newProps.put(PROPERTY_ROOT, normalizePath(path));
                if (ArrayUtils.contains(propertyNames, SERVICE_PID)) {
                    newProps.put(ORIGINAL_SERVICE_PID, ref.getProperty(SERVICE_PID));
                }/*from w  w w .jav a 2 s. c o m*/
                if (ArrayUtils.contains(propertyNames, USE_RESOURCE_ACCESS_SECURITY)) {
                    newProps.put(PROPERTY_USE_RESOURCE_ACCESS_SECURITY,
                            ref.getProperty(USE_RESOURCE_ACCESS_SECURITY));
                }
                if (ArrayUtils.contains(propertyNames, SERVICE_RANKING)) {
                    newProps.put(SERVICE_RANKING, ref.getProperty(SERVICE_RANKING));
                }

                String[] languages = PropertiesUtil.toStringArray(ref.getProperty(LANGUAGES), new String[0]);
                ServiceRegistration reg = bundleContext.registerService(
                        org.apache.sling.spi.resource.provider.ResourceProvider.class.getName(),
                        new LegacyResourceProviderAdapter(provider, languages, ownsRoot), newProps);
                newServices.add(reg);
            }
        }
        registrations.put(provider, newServices);
    }
}

From source file:com.activecq.samples.eventhandlers.impl.SampleEventPublisher.java

private boolean fowardEvent(final String path) throws Exception {
    boolean isDistributableEvent = false;
    boolean sendAsync = true;

    // It is highly recommended to stick w String and Scalar datatypes to avoid
    // issues marshalling data across the wire to other servers in the cluster
    // All value Objects must be serializable
    final Dictionary<String, Object> eventProperties = new Hashtable<String, Object>();
    // The topic must be set in the Event's properties
    eventProperties.put(EventUtil.PROPERTY_JOB_TOPIC, JOB_TOPIC_POKED);

    // Add any other data that Event Handler will need to process this Event
    eventProperties.put("resourcePath", path);

    // Create event object;
    Event pokedEvent;/*from ww w  .  ja v  a 2  s .  c om*/

    if (isDistributableEvent) {
        // Send this event to other servers in the cluster; This is rarely
        // what you want.
        pokedEvent = EventUtil.createDistributableEvent(EventUtil.TOPIC_JOB, eventProperties);
    } else {
        // Send the event out to this server's event queue.
        // This is almost always what you want
        pokedEvent = new Event(EventUtil.TOPIC_JOB, eventProperties);
    }

    // Send the new event out into the world to be handled
    if (sendAsync) {
        // send ASYNCHRONOUSLY
        // This is the usual method
        eventAdmin.postEvent(pokedEvent);
    } else {
        // send SYNCHRONOUSLY
        // Can cause delays in application execution waiting for event to execute
        eventAdmin.sendEvent(pokedEvent);
    }

    return true;
}

From source file:org.openengsb.core.common.internal.VirtualConnectorManager.java

protected ServiceRegistration registerConnectorFactoryService(VirtualConnectorProvider virtualConnectorProvider,
        DomainProvider p) {/*from www .j  a  v  a  2 s .c  o  m*/
    ConnectorInstanceFactory factory = virtualConnectorProvider.createFactory(p);
    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    properties.put(org.openengsb.core.api.Constants.DOMAIN_KEY, p.getId());
    properties.put(org.openengsb.core.api.Constants.CONNECTOR_KEY, virtualConnectorProvider.getId());
    return bundleContext.registerService(ConnectorInstanceFactory.class.getName(), factory, properties);
}

From source file:org.apache.sling.models.impl.ModelPackageBundleListener.java

/**
 * Registers an adapter factory for a annotated sling models class.
 * @param adapterTypes Adapter (either the class itself, or interface or superclass of it)
 * @param adaptableTypes Classes to adapt from
 * @param implType Type of the implementation class
 * @param condition Condition (optional)
 * @return Service registration//w w w  .j a v  a2  s . co  m
 */
private ServiceRegistration registerAdapterFactory(Class<?>[] adapterTypes, Class<?>[] adaptableTypes,
        Class<?> implType, String condition) {
    Dictionary<String, Object> registrationProps = new Hashtable<String, Object>();
    registrationProps.put(AdapterFactory.ADAPTER_CLASSES, toStringArray(adapterTypes));
    registrationProps.put(AdapterFactory.ADAPTABLE_CLASSES, toStringArray(adaptableTypes));
    registrationProps.put(PROP_IMPLEMENTATION_CLASS, implType.getName());

    if (StringUtils.isNotBlank(condition)) {
        registrationProps.put(PROP_ADAPTER_CONDITION, condition);
    }
    return bundleContext.registerService(AdapterFactory.SERVICE_NAME, factory, registrationProps);
}

From source file:org.openengsb.core.common.internal.VirtualConnectorManager.java

private ServiceRegistration registerConnectorProviderService(VirtualConnectorProvider virtualConnectorProvider,
        DomainProvider p) {//www .  j a  va 2s  .c  o m
    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    properties.put(org.openengsb.core.api.Constants.DOMAIN_KEY, p.getId());
    properties.put(org.openengsb.core.api.Constants.CONNECTOR_KEY, virtualConnectorProvider.getId());
    return bundleContext.registerService(ConnectorProvider.class.getCanonicalName(), virtualConnectorProvider,
            properties);

}

From source file:org.openmuc.extensions.core.configurator.Configurator.java

private void updateConfigurations(File configFile) throws ConfigurationException, IOException {

    if (configAdmin == null) {
        logger.error("cannot update configurations because OSGi ConfigurationAdmin service is not available");
        return;//from w w w . j a va 2  s. c  o  m
    }

    XMLConfiguration config = new XMLConfiguration(configFile);

    List<HierarchicalConfiguration> componentConfigs = config.configurationsAt("component");

    for (HierarchicalConfiguration componentConfig : componentConfigs) {
        String componentName = componentConfig.getString("[@name]");

        if (componentName != null) {

            Configuration osgiConfig = configAdmin.getConfiguration(componentName, null);

            Iterator<String> keys = componentConfig.getKeys();
            Dictionary<String, String> properties = new Hashtable<String, String>();

            while (keys.hasNext()) {
                String key = keys.next();
                properties.put(key, componentConfig.getString(key, ""));
            }

            osgiConfig.update(properties);

        } else {
            logger.warn("found component configuration, but name attribute is missing");
        }
    } // foreach component config
}

From source file:org.openengsb.connector.virtual.filewatcher.internal.FileWatcherConnectorTest.java

private ConfigPersistenceService registerConfigPersistence() {
    DummyConfigPersistenceService<String> backend = new DummyConfigPersistenceService<String>();
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put(Constants.CONFIGURATION_ID, Constants.CONFIG_CONNECTOR);
    props.put(Constants.BACKEND_ID, "dummy");
    DefaultConfigPersistenceService configPersistence = new DefaultConfigPersistenceService(backend);
    registerService(configPersistence, props, ConfigPersistenceService.class);
    return configPersistence;
}