Example usage for java.util Properties stringPropertyNames

List of usage examples for java.util Properties stringPropertyNames

Introduction

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

Prototype

public Set<String> stringPropertyNames() 

Source Link

Document

Returns an unmodifiable set of keys from this property list where the key and its corresponding value are strings, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Usage

From source file:com.mirth.connect.server.controllers.DefaultUserController.java

@Override
public void setUserPreferences(Integer userId, Properties properties) throws ControllerException {
    for (String property : properties.stringPropertyNames()) {
        setUserPreference(userId, property, properties.getProperty(property));
    }/*w  w  w  .  j a v  a  2  s .c om*/
}

From source file:com.synopsys.integration.blackduck.configuration.BlackDuckServerConfigBuilder.java

/**
 * @deprecated Please use setProperties.
 *///  w  w w  .j  a v  a2  s . com
@Deprecated
public BlackDuckServerConfigBuilder setFromProperties(Properties properties) {
    Map<String, String> propertiesMap = properties.stringPropertyNames().stream()
            .collect(Collectors.toMap(name -> name, name -> properties.getProperty(name)));

    return setFromProperties(propertiesMap);
}

From source file:annis.libgui.AnnisBaseUI.java

private void loadPropertyFile(File f) {
    if (f.canRead() && f.isFile()) {
        FileInputStream fis = null;
        try {/*from   w ww. java 2  s . c om*/
            fis = new FileInputStream(f);
            Properties p = new Properties();
            p.load(fis);

            // copy all properties to the session
            for (String name : p.stringPropertyNames()) {
                getSession().setAttribute(name, p.getProperty(name));
            }

        } catch (IOException ex) {

        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException ex) {
                    log.error("could not close stream", ex);
                }
            }
        }
    }
}

From source file:de.iew.services.impl.MessageBundleServiceImpl.java

public void loadMessageBundle(Properties messageBundle, String basename, Locale locale) {
    if (log.isDebugEnabled()) {
        log.debug("Synchronisiere MessageBundle " + basename + " fr Locale " + locale + ".");
    }// w ww.jav a2 s  .  co  m

    MessageBundle mb;
    for (String messageKey : messageBundle.stringPropertyNames()) {
        if (log.isTraceEnabled()) {
            log.trace(messageKey + " -> " + messageBundle.getProperty(messageKey));
        }
        mb = this.messageBundleDao.findByTextKeyAndLocale(messageKey, locale.getLanguage(),
                locale.getCountry());
        if (mb == null) {
            TextItem textItem = new TextItem();
            textItem.setLanguageCode(locale.getLanguage());
            textItem.setCountryCode(locale.getCountry());
            textItem.setContent(messageBundle.getProperty(messageKey));

            mb = new MessageBundle();
            mb.setTextKey(messageKey);
            mb.setBasename(basename);
            mb.setTextItem(textItem);

            this.messageBundleDao.save(mb);
        }
    }
}

From source file:org.wso2.carbon.email.mgt.config.RegistryConfigAdd.java

/**
 * This method is used to add a new Email template in a specific tenant space.
 *
 * @param tenantId     - The tenant Id of the tenant that specific email template needs to be add.
 * @param props        - Property configurations of the specific email template.
 * @param resourcePath - Path to be add the specific email template.
 * @throws org.wso2.carbon.email.mgt.exceptions.I18nMgtEmailConfigException
 *///  w ww  .j  a  v  a 2  s  . c  o m
@Override
public void write(int tenantId, Properties props, String resourcePath) throws I18nMgtEmailConfigException {

    if (log.isDebugEnabled()) {
        log.debug("Adding email template to registry path : " + resourcePath);
    }

    RegistryService registry = I18nMgtServiceComponent.getRegistryService();
    try {
        UserRegistry userReg = registry.getConfigSystemRegistry(tenantId);
        Set<String> names = props.stringPropertyNames();
        String[] propsKeyName = names.toArray(new String[names.size()]);
        String[] propsKeyNameSplit = propsKeyName[0].split("\\.");
        String emailTemplateContent = props.getProperty(propsKeyName[0]);

        //Declaring Email Template File/Folder Name & Display Names.
        String emailTemplateDisplayName = propsKeyNameSplit[0];
        String emailTemplateFolderName = emailTemplateDisplayName.replaceAll("\\s", "").toLowerCase();
        String emailTemplateFilename = emailTemplateFolderName + I18nMgtConstants.EMAIL_LOCALE_SEPARATOR
                + propsKeyNameSplit[1];

        //Declaring Email Template File/Folder Resource Paths.
        String emailTemplateFileResourcePath = resourcePath + I18nMgtConstants.EMAIL_FOLDER_SEPARATOR
                + emailTemplateFolderName + I18nMgtConstants.EMAIL_FOLDER_SEPARATOR + emailTemplateFilename;
        String emailTemplateFolderResourcePath = resourcePath + I18nMgtConstants.EMAIL_FOLDER_SEPARATOR
                + emailTemplateFolderName;

        if (log.isDebugEnabled()) {
            log.debug("Adding email template : " + emailTemplateFilename + " to resource location : "
                    + emailTemplateFileResourcePath);
        }

        if (!userReg.resourceExists(emailTemplateFileResourcePath)) {
            //Checking whether there is an already existing folder path for the email template.
            if (!userReg.resourceExists(emailTemplateFolderResourcePath)) {
                // This is done due to casting to List in JDBCRegistryDao when adding a registry property.
                List<String> value = new ArrayList<String>();
                value.add(emailTemplateDisplayName);
                Collection emailCollection = userReg.newCollection();
                emailCollection.setProperty(emailTemplateFolderName, value);
                userReg.put(emailTemplateFolderResourcePath, emailCollection);
                Resource resource = userReg.newResource();
                resource.setMediaType(propsKeyNameSplit[2]);
                resource.setContent(emailTemplateContent);
                userReg.put(emailTemplateFileResourcePath, resource);
            }
            Resource resource = userReg.newResource();
            resource.setMediaType(propsKeyNameSplit[2]);
            resource.setContent(emailTemplateContent);
            userReg.put(emailTemplateFileResourcePath, resource);

            if (log.isDebugEnabled()) {
                log.debug(" Successfully added email template : " + emailTemplateFilename
                        + " to resource location : " + emailTemplateFileResourcePath);
            }

        } else {
            throw new I18nMgtEmailConfigException(
                    "Resource duplication error while adding email template : " + emailTemplateFilename);
        }
    } catch (RegistryException e) {
        throw new I18nMgtEmailConfigException(
                "Error occurred while adding email template to registry path : " + resourcePath, e);
    }
}

From source file:com.urbancode.ud.client.ProcessClient.java

public UUID requestGenericProcess(String processId, String processVersion, String resource,
        Properties properties) throws IOException, JSONException {
    UUID result;/*from w w  w  . ja va  2 s.co m*/
    JSONObject jsonToSend = new JSONObject();
    jsonToSend.put("processId", processId);
    if (processVersion != null) {
        jsonToSend.put("processVersion", processVersion);
    }
    JSONObject propsJson = new JSONObject();
    if (properties != null) {
        for (String propName : properties.stringPropertyNames()) {
            propsJson.put(propName, properties.getProperty(propName));
        }
    }
    jsonToSend.put("resource", resource);
    jsonToSend.put("properties", propsJson);

    String uri = url + "/rest/process/request";
    HttpPost method = new HttpPost(uri);
    method.setEntity(getStringEntity(jsonToSend));
    HttpResponse response = invokeMethod(method);
    String body = getBody(response);
    JSONObject jsonResult = new JSONObject(body);
    result = UUID.fromString((String) jsonResult.get("id"));

    return result;
}

From source file:org.aludratest.cloud.impl.app.CloudManagerApplicationHolder.java

private MutablePreferences readPreferences(File f) {
    SimplePreferences prefs = new SimplePreferences(null);
    if (!f.exists()) {
        return prefs;
    }//from  w  w w.  java 2 s . c o m

    Properties p = new Properties();

    FileInputStream fis = null;
    try {
        fis = new FileInputStream(f);
        p.loadFromXML(fis);

        for (String key : p.stringPropertyNames()) {
            String value = p.getProperty(key);
            if ("".equals(value)) {
                value = null;
            }
            prefs.setValue(key, value);
        }
    } catch (IOException e) {
        LOG.error("Could not read preferences file " + f.getAbsolutePath(), e);
        return prefs;
    } finally {
        IOUtils.closeQuietly(fis);
    }

    return prefs;
}

From source file:org.wso2.carbon.email.mgt.config.RegistryConfigWriter.java

/**
 * This method is used to add a new Email template in a specific tenant space.
 *
 * @param tenantId     - The tenant Id of the tenant that specific email template needs to be add.
 * @param props        - Property configurations of the specific email template.
 * @param resourcePath - Path to be add the specific email template.
 * @throws org.wso2.carbon.email.mgt.exceptions.I18nMgtEmailConfigException
 *///from ww  w.  j a  va  2s.  c o m
@Override
public void write(int tenantId, Properties props, String resourcePath) throws I18nMgtEmailConfigException {

    if (log.isDebugEnabled()) {
        log.debug("Saving email template at registry path : " + resourcePath);
    }

    RegistryService registry = I18nMgtServiceComponent.getRegistryService();
    try {
        UserRegistry userReg = registry.getConfigSystemRegistry(tenantId);
        Set<String> names = props.stringPropertyNames();

        if (!userReg.resourceExists(resourcePath)) {
            for (String propsKeyName : names) {
                // This is done due to casting to List in JDBCRegistryDao when adding a registry property.
                List<String> value = new ArrayList<String>();
                String[] propertyArray = propsKeyName.split("\\|");
                value.add(propertyArray[1]);
                Collection emailCollection = userReg.newCollection();
                String emailTemplateFolderName = propertyArray[0].replaceAll("\\s", "").toLowerCase();
                String defaultEmailLocale = propertyArray[2];
                emailCollection.setProperty(emailTemplateFolderName, value);

                String emailTemplateFilename = emailTemplateFolderName + I18nMgtConstants.EMAIL_LOCALE_SEPARATOR
                        + defaultEmailLocale;
                String emailTemplateFolderResourcePath = resourcePath + I18nMgtConstants.EMAIL_FOLDER_SEPARATOR
                        + emailTemplateFolderName;
                String emailTemplateFileResourcePath = resourcePath + I18nMgtConstants.EMAIL_FOLDER_SEPARATOR
                        + emailTemplateFolderName + I18nMgtConstants.EMAIL_FOLDER_SEPARATOR
                        + emailTemplateFilename;

                userReg.put(emailTemplateFolderResourcePath, emailCollection);
                Resource resource = userReg.newResource();
                String emailTemplateContent = props.getProperty(propsKeyName);
                resource.setMediaType(propertyArray[3]);
                resource.setContent(emailTemplateContent);
                userReg.put(emailTemplateFileResourcePath, resource);
            }

            if (log.isDebugEnabled()) {
                log.debug("Default email template added to : " + resourcePath + "successfully.");
            }

        } else {
            String[] propsKeyName = names.toArray(new String[names.size()]);
            String[] propsKeyNameSplit = propsKeyName[0].split("\\.");
            String emailTemplateFolderName = propsKeyNameSplit[0];
            String emailTemplateFilename = emailTemplateFolderName + I18nMgtConstants.EMAIL_LOCALE_SEPARATOR
                    + propsKeyNameSplit[1];
            String emailTemplateFileResourcePath = resourcePath + I18nMgtConstants.EMAIL_FOLDER_SEPARATOR
                    + emailTemplateFolderName + I18nMgtConstants.EMAIL_FOLDER_SEPARATOR + emailTemplateFilename;

            Resource resource = userReg.newResource();
            String emailTemplateContent = props.getProperty(propsKeyName[0]);
            resource.setMediaType(propsKeyNameSplit[2]);
            resource.setContent(emailTemplateContent);
            userReg.put(emailTemplateFileResourcePath, resource);

            if (log.isDebugEnabled()) {
                log.debug("Email template : " + emailTemplateFilename + " saved successfully to path "
                        + emailTemplateFileResourcePath);
            }

        }
    } catch (RegistryException e) {
        throw new I18nMgtEmailConfigException(
                "Error occurred while adding email template to registry path : " + resourcePath, e);
    }

}

From source file:com.mozilla.telemetry.pig.eval.json.ValidateTelemetrySubmission.java

protected void readLookupFile() {
    FSDataInputStream fdis = null;/*from   w ww.  j ava2 s  .c o  m*/
    try {
        Properties specProperties = new Properties();
        specValues = new HashMap<String, Object>();
        fdis = getHDFSFile(lookupFilename);
        specProperties.load(fdis);
        for (String key : specProperties.stringPropertyNames()) {
            String specFile = specProperties.getProperty(key);
            LOG.info(key + " " + specFile);
            Map<String, Map<String, Object>> referenceJson = readReferenceJson(specFile);
            specValues.put(key, referenceJson);
        }
    } catch (IOException e) {
        LOG.error("ERROR: failed to process telemetry spec lookup file " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        LOG.error("ERROR: failed to process telemetry spec jsons " + e.getMessage());
    } finally {
        if (fdis != null) {
            try {
                fdis.close();
            } catch (IOException e) {
                LOG.error("ERROR: failed to close telemetry spec lookup file" + e.getMessage());
            }
        }
    }
}

From source file:com.seanbright.osgi.launcher.Daemon.java

private Map<String, String> loadFrameworkProperties(String filename) {
    Map<String, String> properties = new HashMap<String, String>();

    File f = new File(filename);

    if (!f.exists() || !f.isFile() || !f.canRead()) {
        return properties;
    }/*  ww w. j  ava2s . c o m*/

    Properties workingCopy = new Properties();

    FileInputStream stream = null;

    try {
        stream = new FileInputStream(f);

        workingCopy.load(stream);
    } catch (IOException e) {
        e.printStackTrace(System.err);
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                /* Ignore */
            }
        }
    }

    for (String key : workingCopy.stringPropertyNames()) {
        properties.put(key, workingCopy.getProperty(key));
    }

    PropertiesParser.performSubstitutions(properties);

    return properties;
}