Example usage for java.util Properties keys

List of usage examples for java.util Properties keys

Introduction

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

Prototype

@Override
    public Enumeration<Object> keys() 

Source Link

Usage

From source file:org.pepstock.jem.node.StartUpSystem.java

/**
 * load the listeners of the jem configuration checking if they are
 * configured//from  www  . j  av  a 2  s . co  m
 * 
 * @param conf the jem node config
 * @param substituter a VariableSubstituter containing all the System
 *            properties
 * @throws ConfigurationException if some error occurs
 */
private static void loadListeners() throws ConfigurationException {
    // load listeners, checking if they are configured. If not, they are
    // optional, so go ahead
    List<Listener> listeners = JEM_ENV_CONFIG.getListeners();
    if (listeners != null && !listeners.isEmpty()) {
        // for all listener checking which have the right className. If
        // not, execption occurs, otherwise it's loaded
        for (Listener listener : listeners) {
            if (listener.getClassName() != null) {
                String className = listener.getClassName();
                try {
                    // load by Class.forName of listener
                    ObjectAndClassPathContainer oacp = ClassLoaderUtil.loadAbstractPlugin(listener, PROPERTIES);
                    Object objectListener = oacp.getObject();

                    // check if it's a JobLifecycleListener. if not,
                    // exception occurs. if yes, it's loaded on a
                    // EventListenerManager
                    if (objectListener instanceof JobLifecycleListener) {
                        JobLifecycleListener lister = (JobLifecycleListener) objectListener;
                        Main.JOB_LIFECYCLE_LISTENERS_SYSTEM.addListener(JobLifecycleListener.class, lister);
                        // gets properties defined. If not empty,
                        // substitutes the value of property with
                        // variables
                        Properties propsOfListener = listener.getProperties();
                        if (propsOfListener != null) {
                            if (!propsOfListener.isEmpty()) {
                                // scans all properties
                                for (Enumeration<Object> e = propsOfListener.keys(); e.hasMoreElements();) {
                                    // gets key and value
                                    String key = e.nextElement().toString();
                                    String value = propsOfListener.getProperty(key);
                                    // substitutes variables if present
                                    // and sets new value for the key
                                    propsOfListener.setProperty(key, substituteVariable(value));
                                }
                            }
                        } else {
                            // creates however an empty collection to
                            // avoid null pointer
                            propsOfListener = new Properties();
                        }
                        // initialize the listener passing parameters
                        // properties
                        lister.init(propsOfListener);
                        LogAppl.getInstance().emit(NodeMessage.JEMC037I, className);
                    } else {
                        LogAppl.getInstance().emit(NodeMessage.JEMC036E, className);
                        throw new ConfigurationException(
                                NodeMessage.JEMC036E.toMessage().getFormattedMessage(className));
                    }
                } catch (Exception e) {
                    LogAppl.getInstance().emit(NodeMessage.JEMC031E, e, className);
                    throw new ConfigurationException(
                            NodeMessage.JEMC031E.toMessage().getFormattedMessage(className));
                }
                // in this case the class name is null so ignore,
                // emitting a warning
            } else {
                LogAppl.getInstance().emit(NodeMessage.JEMC038W, ConfigKeys.LISTENER_ALIAS,
                        listener.toString());
            }
        }
    }
}

From source file:eu.gloriaproject.tools.userreservations.UserReservationController.java

private void configurePortlet(long companyId, long ownerId, int ownerType, long plid, String portletId,
        Properties properties) {

    try {/*w  ww  . ja  v  a 2  s.  c o m*/

        PortletPreferences prefs = PortletPreferencesLocalServiceUtil.getPreferences(companyId, ownerId,
                ownerType, plid, portletId);
        Enumeration<Object> propertiesList = properties.keys();

        while (propertiesList.hasMoreElements()) {
            String propertyName = (String) propertiesList.nextElement();
            prefs.setValue(propertyName, properties.getProperty(propertyName));
        }

        PortletPreferencesLocalServiceUtil.updatePreferences(ownerId, ownerType, plid, portletId, prefs);

    } catch (SystemException e) {
        log.error("Error to configure portlet (system):" + e.getMessage());
    } catch (ReadOnlyException e) {
        log.error("Error to configure portlet (readonly):" + e.getMessage());
    }

}

From source file:org.wso2.carbon.ui.AbstractCarbonUIAuthenticator.java

/**
 * Regenerates session id after each login attempt.
 * @param request//from w w w.j  a va2  s  .c o  m
 */
private void regenrateSession(HttpServletRequest request) {

    HttpSession oldSession = request.getSession();

    Enumeration attrNames = oldSession.getAttributeNames();
    Properties props = new Properties();

    while (attrNames != null && attrNames.hasMoreElements()) {
        String key = (String) attrNames.nextElement();
        props.put(key, oldSession.getAttribute(key));
    }

    oldSession.invalidate();
    HttpSession newSession = request.getSession(true);
    attrNames = props.keys();

    while (attrNames != null && attrNames.hasMoreElements()) {
        String key = (String) attrNames.nextElement();
        newSession.setAttribute(key, props.get(key));
    }
}

From source file:net.zypr.api.Voice.java

public TextToSpeechVO tts(String service, Properties options)
        throws APIProtocolException, APICommunicationException, APIServerErrorException {
    if (service == null || service.equalsIgnoreCase(SERVICE_NAME_DEFAULT))
        service = getDefaultServiceForTTS();
    if (!doesVerbExist(service, APIVerbs.VOICE_TTS))
        throw new APIInvalidServiceException(APIVerbs.VOICE_TTS, service);
    Hashtable<String, String> parameters = buildParameters();
    parameters.put("service", service);
    JSONArray jsonArray = new JSONArray();
    for (Enumeration enumeration = options.keys(); enumeration.hasMoreElements();) {
        String key = (String) enumeration.nextElement();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", key);
        jsonObject.put("value", options.getProperty(key));
        jsonArray.add(jsonObject);/*from   w  w  w .j a v a 2 s .  co  m*/
    }
    JSONObject jsonObjectData = new JSONObject();
    jsonObjectData.put("data", jsonArray);
    parameters.put("options", jsonObjectData.toJSONString());
    TextToSpeechVO textToSpeechVO = new TextToSpeechVO();
    try {
        JSONObject jsonObject = getJSON(APIVerbs.VOICE_TTS, parameters);
        if (getStatusCode(jsonObject) == StatusCode.SUCCESSFUL) {
            JSONArray jsonData = getDataArrayJSON(jsonObject);
            textToSpeechVO = new TextToSpeechVO((JSONObject) jsonData.get(0));
        } else {
            throw new APIServerErrorException(getStatusMessage(jsonObject));
        }
    } catch (ClassCastException classCastException) {
        throw new APIProtocolException(classCastException);
    } catch (NullPointerException nullPointerException) {
        throw new APIProtocolException(nullPointerException);
    }
    return (textToSpeechVO);
}

From source file:org.intermine.bio.dataconversion.WormbaseAcedbConverter.java

/**
* This method is automatically called if "key.file" property set 
* for source in project XML./*from   www  .  j  a  va2 s . c o  m*/
* 
* Reads key/value file loader will use.
* File must be in the format
* 
* className.key = value
* 
* For example:
* BioEntity.key = primaryIdentifier
* This line will set the primaryIdentifier field as primary key
* for all children of BioEntity.  Precedence granted to more
* specific keys.
* 
 * @param keyFilePath
 * @throws Exception
 */
public void setKeyFile(String keyFilePath) throws Exception {
    this.keyFilePath = keyFilePath;
    keyMapping = new HashMap<String, String>();
    Properties keyFileProps = new Properties();
    try {
        keyFileProps.load(new FileReader(keyFilePath));
    } catch (Exception e) {
        System.out.println("Problem loading keyfile:[" + keyFilePath + "]");
        e.printStackTrace();
        throw e;
    }
    Enumeration keyEnum = keyFileProps.keys();
    while (keyEnum.hasMoreElements()) {
        String key = (String) keyEnum.nextElement();
        int index = key.indexOf(".key");
        if (index > 0) {
            keyMapping.put(key.substring(0, index), keyFileProps.getProperty(key));

        }
    }
    System.out.println("Processed key file: [" + keyFilePath + "]");
}

From source file:it.geosolutions.httpproxy.service.impl.ProxyConfigImpl.java

/**
 * Override this fields with a location properties
 * /*from w w  w  .  j  av a 2 s . c o  m*/
 * @param location
 * 
 * @throws IOException if read properties throw an error
 */
private void overrideProperties(Resource location) throws IOException {
    Properties props = new Properties();
    props.load(location.getInputStream());
    Enumeration<Object> keys = props.keys();
    while (keys.hasMoreElements()) {
        try {
            String key = (String) keys.nextElement();
            if (key.startsWith(beanName + ".")) {
                String parameter = key.replace(beanName + ".", "");
                Field field = ReflectionUtils.findField(this.getClass(), parameter);
                ReflectionUtils.makeAccessible(field);
                ReflectionUtils.setField(field, this, props.getProperty(key));
                LOGGER.log(Level.INFO, "[override]: " + key + "=" + props.getProperty(key));
            }
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Error overriding the proxy configuration ", e);
        }
    }
}

From source file:org.opencastproject.index.service.resources.list.impl.ListProvidersScanner.java

/**
 * Add a list provider based upon a configuration file.
 *
 * @param artifact// ww  w . j a  v  a  2  s. co  m
 *          The File representing the configuration file for the list.
 */
public void addResourceListProvider(File artifact) throws IOException {
    logger.debug("Adding {}", artifact.getAbsolutePath());
    // Format name
    FileInputStream in = null;
    Properties properties = new Properties();
    try {
        in = new FileInputStream(artifact);
        properties.load(in);
    } finally {
        IOUtils.closeQuietly(in);
    }

    String listName = "";
    if (properties.getProperty(LIST_NAME_KEY) != null) {
        listName = properties.getProperty(LIST_NAME_KEY).toString();
    }

    String orgId = "";
    logger.debug("Found list with name '{}'", listName);
    if (!"".equals(listName)) {
        HashMap<String, Object> list = new HashMap<String, Object>();
        Enumeration<Object> keys = properties.keys();
        while (keys.hasMoreElements()) {
            Object key = keys.nextElement();
            String keyString = key.toString();
            if (!keyString.equalsIgnoreCase(LIST_NAME_KEY) && !keyString.equalsIgnoreCase(LIST_ORG_KEY)) {
                String value = properties.get(key).toString();
                list.put(keyString, value);
                logger.debug("Found key:{} value:{}", keyString, value);
            } else if (keyString.equalsIgnoreCase(LIST_ORG_KEY)) {
                orgId = properties.get(key).toString();
                logger.debug("Found org:{}", orgId);
            } else {
                logger.debug("Skipping key:{}", keyString);
            }
        }

        SingleResourceListProviderImpl singleResourceListProviderImpl = new SingleResourceListProviderImpl(
                listName, list);
        if (orgId != null && !"".equals(orgId)) {
            singleResourceListProviderImpl.setOrg(orgId);
        }
        listProvidersService.addProvider(singleResourceListProviderImpl.getListName(),
                singleResourceListProviderImpl);
        fileToListNames.put(artifact.getAbsolutePath(), singleResourceListProviderImpl.getListName());
    } else {
        logger.error(
                "Unable to add {} as a list provider because the {} entry was empty. Please add it to get this list provider to work.",
                new Object[] { artifact.getAbsolutePath(), LIST_NAME_KEY, listName });
    }
}

From source file:com.fluidops.iwb.api.ProviderServiceImpl.java

@Override
public List<String> getProviderClasses() throws RemoteException {
    Properties prop = getProvidersProp();

    List<String> result = new ArrayList<String>();

    Enumeration<Object> keys = prop.keys();

    while (keys.hasMoreElements()) {
        String key = keys.nextElement().toString();

        // It will be false if the value is not a valid boolean, no exception will be thrown
        if (Boolean.valueOf(prop.getProperty(key))) {
            try {
                // Test that the class name is correct, class is accessible and visible
                Class c = DynamicScriptingSupport.loadClass(key);

                // Test that instantiation won't cause problems
                c.newInstance();/*from  w w  w. j a va2 s.c  o m*/

                // If everything is ok, include it in the result
                result.add(key);
            } catch (Throwable e) {
                logger.error("Resources for provider " + key + " missing, provider not available!", e);
            }
        }
    }

    return result;
}

From source file:es.mityc.firmaJava.configuracion.Configuracion.java

/**
 * Este mtodo carga la configuracin definida en el fichero SignXML.properties
 *///from   www .  j a  v a2s.  c o  m
public void cargarConfiguracion() {

    Enumeration<Object> enuClaves = null;
    // Intenta cargar el fichero de propiedades externo si lo tiene permitido
    if (chequeaPermiteFicheroExterno()) {
        Properties propiedades = new Properties();
        FileInputStream fis = null;
        try {
            File fichero = new File(System.getProperty(USER_HOME) + File.separator + getNombreDirExterno(),
                    getNombreFicheroExterno());
            fis = new FileInputStream(fichero);
            propiedades.load(fis);
            configuracion = new HashMap<String, String>();
            enuClaves = propiedades.keys();
            boolean hasNext = enuClaves.hasMoreElements();
            while (hasNext) {
                String clave = (String) enuClaves.nextElement();
                hasNext = enuClaves.hasMoreElements();
                configuracion.put(clave, propiedades.getProperty(clave));
            }
        } catch (FileNotFoundException e) {
            cargarConfiguracionPorDefecto();

        } catch (IOException e) {
            cargarConfiguracionPorDefecto();
        }

        finally {
            try {
                if (fis != null) {
                    fis.close();
                }
            } catch (IOException e) {
                log.error(e);
            }
        }
    } else {
        cargarConfiguracionPorDefecto();
    }

}

From source file:org.pentaho.reporting.ui.datasources.olap4j.Olap4JDataSourceEditor.java

protected OlapConnectionProvider createConnectionProvider() {
    final JdbcConnectionDefinition connectionDefinition = (JdbcConnectionDefinition) getDialogModel()
            .getConnections().getSelectedItem();
    final OlapConnectionProvider connectionProvider;
    if (connectionDefinition instanceof JndiConnectionDefinition) {
        final JndiConnectionDefinition jcd = (JndiConnectionDefinition) connectionDefinition;
        final JndiConnectionProvider provider = new JndiConnectionProvider();
        provider.setConnectionPath(jcd.getJndiName());
        provider.setUsername(jcd.getUsername());
        provider.setPassword(jcd.getPassword());
        connectionProvider = provider;//from w w w. ja  va 2  s .  c  om
    } else if (connectionDefinition instanceof DriverConnectionDefinition) {
        final DriverConnectionDefinition dcd = (DriverConnectionDefinition) connectionDefinition;
        final DriverConnectionProvider provider = new DriverConnectionProvider();
        provider.setDriver(dcd.getDriverClass());
        provider.setUrl(dcd.getConnectionString());

        final Properties properties = dcd.getProperties();
        final Enumeration keys = properties.keys();
        while (keys.hasMoreElements()) {
            final String key = (String) keys.nextElement();
            provider.setProperty(key, properties.getProperty(key));
        }
        connectionProvider = provider;
    } else {
        throw new IllegalStateException();
    }
    return connectionProvider;
}