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:org.apache.hive.jdbc.beeline.OptionsProcessor.java

public boolean processArgs(String[] argv) {
    try {/*www  .  ja  v  a 2 s . c  o m*/
        commandLine = new GnuParser().parse(options, argv);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        printUsage();
        return false;
    }

    if (commandLine.hasOption('H')) {
        printUsage();
        return false;
    }

    if (commandLine.hasOption('S')) {
        pMode = PrintMode.SILENT;
    } else if (commandLine.hasOption('v')) {
        pMode = PrintMode.VERBOSE;
    } else {
        pMode = PrintMode.NORMAL;
    }

    hiveConfs = commandLine.getOptionValue("hiveconf", "");
    hiveVars = commandLine.getOptionValue("define", "");
    hiveVars += commandLine.getOptionValue("hivevar", "");
    sessVars = commandLine.getOptionValue("sessvar", "");
    database = commandLine.getOptionValue("database", "");
    execString = commandLine.getOptionValue('e');
    fileName = commandLine.getOptionValue('f');
    host = (String) commandLine.getOptionValue('h');
    port = Integer.parseInt((String) commandLine.getOptionValue('p', "10000"));

    if (execString != null && fileName != null) {
        System.err.println("The '-e' and '-f' options cannot be specified simultaneously");
        printUsage();
        return false;
    }

    if (commandLine.hasOption("hiveconf")) {
        Properties confProps = commandLine.getOptionProperties("hiveconf");
        for (String propKey : confProps.stringPropertyNames()) {
            cmdProperties.setProperty(propKey, confProps.getProperty(propKey));
        }
    }

    return true;
}

From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.pom.AbstractPOMGenerator.java

protected void generateDeployPOM(MavenProject project) throws MojoExecutionException {
    File outputFile = getOutputFile();
    File templateFile = getTemplateFile();
    getLog().info(templateFile.getAbsolutePath());
    InputStream builtinTemplateFile = getBuiltinTemplateFile();

    getLog().info(getGenerationMessage() + "'" + outputFile.getAbsolutePath() + "'");

    try {//ww  w  .  java 2  s .c o  m
        outputFile.getParentFile().mkdirs();
        outputFile.createNewFile();
        if (templateFile != null && templateFile.exists() && !getTemplateMerge()) {
            FileUtils.copyFile(templateFile, outputFile); // if a template deploy POM exists and we don't want to merge with built-in one: use it
        } else {
            // otherwise : use the one included in the plugin
            FileOutputStream fos = new FileOutputStream(outputFile);
            IOUtils.copy(builtinTemplateFile, fos);
        }
    } catch (IOException e) {
        throw new MojoExecutionException(getFailureMessage());
    }

    try {
        Model model = POMManager.getModelFromPOM(outputFile, this.getLog());
        if (templateFile != null && templateFile.exists() && getTemplateMerge()) {
            model = POMManager.mergeModelFromPOM(templateFile, model, this.getLog()); // if a template deploy POM exists and we want to merge with built-in one: merge it
        }

        model.setGroupId(project.getGroupId());
        model.setArtifactId(project.getArtifactId());
        model.setVersion(project.getVersion());

        Properties originalProperties = getProject().getProperties();
        for (String property : originalProperties.stringPropertyNames()) {
            if (property != null && property.startsWith(deploymentPropertyPrefix)) {
                model.getProperties().put(property.substring(deploymentPropertyPrefix.length()),
                        originalProperties.getProperty(property));
            }
            if (property != null && deploymentProperties.contains(property)) {
                model.getProperties().put(property, originalProperties.getProperty(property));
            }
        }

        model = updateModel(model, project);

        POMManager.writeModelToPOM(model, outputFile, getLog());

        attachFile(outputFile);
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } catch (XmlPullParserException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:org.tolven.deploy.glassfish3.GlassFish3Deploy.java

private String getASAdminPropertyString(Properties properties) {
    List<String> keys = new ArrayList<String>(properties.stringPropertyNames());
    Iterator<String> it = keys.iterator();
    StringBuffer buff = new StringBuffer();
    while (it.hasNext()) {
        String key = it.next();//from w w  w.  ja  va2  s  . c om
        String value = properties.getProperty(key);
        buff.append(key);
        buff.append("=");
        buff.append(value);
        if (it.hasNext()) {
            buff.append(":");
        }
    }
    return buff.toString();
}

From source file:org.syncope.core.init.ContentLoader.java

@Transactional
public void load() {
    // 0. DB connection, to be used below
    Connection conn = DataSourceUtils.getConnection(dataSource);

    // 1. Check wether we are allowed to load default content into the DB
    Statement statement = null;//ww  w  .  j a v a2 s.  c  om
    ResultSet resultSet = null;
    boolean existingData = false;
    try {
        statement = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

        resultSet = statement.executeQuery("SELECT * FROM " + SyncopeConf.class.getSimpleName());
        resultSet.last();

        existingData = resultSet.getRow() > 0;
    } catch (SQLException e) {
        LOG.error("Could not access to table " + SyncopeConf.class.getSimpleName(), e);

        // Setting this to true make nothing to be done below
        existingData = true;
    } finally {
        try {
            if (resultSet != null) {
                resultSet.close();
            }
        } catch (SQLException e) {
            LOG.error("While closing SQL result set", e);
        }
        try {
            if (statement != null) {
                statement.close();
            }
        } catch (SQLException e) {
            LOG.error("While closing SQL statement", e);
        }
    }

    if (existingData) {
        LOG.info("Data found in the database, leaving untouched");
        return;
    }

    LOG.info("Empty database found, loading default content");

    // 2. Create views
    LOG.debug("Creating views");
    try {
        InputStream viewsStream = getClass().getResourceAsStream("/views.xml");
        Properties views = new Properties();
        views.loadFromXML(viewsStream);

        for (String idx : views.stringPropertyNames()) {
            LOG.debug("Creating view {}", views.get(idx).toString());

            try {
                statement = conn.createStatement();
                statement.executeUpdate(views.get(idx).toString().replaceAll("\\n", " "));
                statement.close();
            } catch (SQLException e) {
                LOG.error("Could not create view ", e);
            }
        }

        LOG.debug("Views created, go for indexes");
    } catch (Throwable t) {
        LOG.error("While creating views", t);
    }

    // 3. Create indexes
    LOG.debug("Creating indexes");
    try {
        InputStream indexesStream = getClass().getResourceAsStream("/indexes.xml");
        Properties indexes = new Properties();
        indexes.loadFromXML(indexesStream);

        for (String idx : indexes.stringPropertyNames()) {
            LOG.debug("Creating index {}", indexes.get(idx).toString());

            try {
                statement = conn.createStatement();
                statement.executeUpdate(indexes.get(idx).toString());
                statement.close();
            } catch (SQLException e) {
                LOG.error("Could not create index ", e);
            }
        }

        LOG.debug("Indexes created, go for default content");
    } catch (Throwable t) {
        LOG.error("While creating indexes", t);
    } finally {
        DataSourceUtils.releaseConnection(conn, dataSource);
    }

    try {
        conn.close();
    } catch (SQLException e) {
        LOG.error("While closing SQL connection", e);
    }

    // 4. Load default content
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
        SAXParser parser = factory.newSAXParser();
        parser.parse(getClass().getResourceAsStream("/content.xml"), importExport);
        LOG.debug("Default content successfully loaded");
    } catch (Throwable t) {
        LOG.error("While loading default content", t);
    }
}

From source file:org.apache.falcon.oozie.process.NativeOozieProcessWorkflowBuilder.java

private void copyPropsWithoutOverride(Properties buildProps, Properties suppliedProps) {
    if (suppliedProps == null || suppliedProps.isEmpty()) {
        return;//  w  w w.  j a  va 2 s.  c  om
    }
    for (String propertyName : suppliedProps.stringPropertyNames()) {
        if (buildProps.containsKey(propertyName)) {
            LOG.warn("User provided property {} is already declared in the entity and will be ignored.",
                    propertyName);
            continue;
        }
        String propertyValue = suppliedProps.getProperty(propertyName);
        buildProps.put(propertyName, propertyValue);
    }
}

From source file:org.openmrs.module.reporting.test.CustomMessageSource.java

/**
 * Refreshes the cache, merged from the custom source and the parent source
 *//*from  ww  w .  j  a v a2s .  c  o m*/
public synchronized void refreshCache() {
    cache = new HashMap<Locale, PresentationMessageMap>();
    PresentationMessageMap pmm = new PresentationMessageMap(Locale.ENGLISH);
    Properties messages = ObjectUtil.loadPropertiesFromClasspath("messages.properties");
    for (String code : messages.stringPropertyNames()) {
        String message = messages.getProperty(code);
        message = message.replace("{{", "'{{'");
        message = message.replace("}}", "'}}'");
        pmm.put(code, new PresentationMessage(code, Locale.ENGLISH, message, null));
    }
    cache.put(Locale.ENGLISH, pmm);
}

From source file:org.opencastproject.kernel.mail.BaseSmtpService.java

public void configure() {
    mailProperties.clear();//from   w w  w . j av a  2s. c  om
    defaultMailSession = null;

    if (!("smtp".equals(mailTransport) || "smtps".equals(mailTransport))) {
        if (mailTransport != null)
            logger.warn("'{}' procotol not supported. Reverting to default: '{}'", mailTransport,
                    DEFAULT_MAIL_TRANSPORT);
        logger.debug("Mail transport protocol defaults to '{}'", DEFAULT_MAIL_TRANSPORT);
        mailProperties.put(OPT_MAIL_TRANSPORT, DEFAULT_MAIL_TRANSPORT);
    } else {
        logger.debug("Mail transport protocol is '{}'", mailTransport);
        mailProperties.put(OPT_MAIL_TRANSPORT, mailTransport);
    }

    mailProperties.put(OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_HOST_SUFFIX, host);
    logger.debug("Mail host is {}", host);

    mailProperties.put(OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_PORT_SUFFIX, port);
    logger.debug("Mail server port is '{}'", port);

    // User and Authentication
    String propName = OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_AUTH_SUFFIX;
    if (StringUtils.isNotBlank(user)) {
        mailProperties.put(OPT_MAIL_USER, user);
        mailProperties.put(propName, Boolean.toString(true));
        logger.debug("Mail user is '{}'", user);
    } else {
        mailProperties.put(propName, Boolean.toString(false));
        logger.debug("Sending mails to {} without authentication", host);
    }

    if (StringUtils.isNotBlank(password)) {
        mailProperties.put(OPT_MAIL_PASSWORD, password);
        logger.debug("Mail password set");
    }

    if (StringUtils.isNotBlank(sender)) {
        mailProperties.put(OPT_MAIL_FROM, sender);
        logger.debug("Mail sender is '{}'", sender);
    } else {
        logger.debug("Mail sender defaults not set");
    }

    mailProperties.put(OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_TLS_ENABLE_SUFFIX, ssl);
    if (ssl) {
        logger.debug("TLS over SMTP is enabled");
    } else {
        logger.debug("TLS over SMTP is disabled");
    }

    mailProperties.put(OPT_MAIL_DEBUG, Boolean.toString(debug));
    logger.debug("Mail debugging is {}", debug ? "enabled" : "disabled");

    logger.info("Mail service configured with {}", host);
    Properties props = getSession().getProperties();
    for (String key : props.stringPropertyNames())
        logger.info("{}: {}", key, props.getProperty(key));
}

From source file:org.apache.atlas.web.security.AtlasPamAuthenticationProvider.java

private Authentication getPamAuthentication(Authentication authentication) {
    try {//from   w ww .j  av a 2s .  c o  m
        DefaultJaasAuthenticationProvider jaasAuthenticationProvider = new DefaultJaasAuthenticationProvider();
        String loginModuleName = "org.apache.atlas.web.security.PamLoginModule";
        AppConfigurationEntry.LoginModuleControlFlag controlFlag = AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
        Properties properties = ConfigurationConverter
                .getProperties(ApplicationProperties.get().subset("atlas.authentication.method.pam"));
        Map<String, String> options = new HashMap<>();
        for (String key : properties.stringPropertyNames()) {
            String value = properties.getProperty(key);
            options.put(key, value);
        }
        if (!options.containsKey("service"))
            options.put("service", "atlas-login");
        AppConfigurationEntry appConfigurationEntry = new AppConfigurationEntry(loginModuleName, controlFlag,
                options);
        AppConfigurationEntry[] appConfigurationEntries = new AppConfigurationEntry[] { appConfigurationEntry };
        Map<String, AppConfigurationEntry[]> appConfigurationEntriesOptions = new HashMap<String, AppConfigurationEntry[]>();
        appConfigurationEntriesOptions.put("SPRINGSECURITY", appConfigurationEntries);
        Configuration configuration = new InMemoryConfiguration(appConfigurationEntriesOptions);
        jaasAuthenticationProvider.setConfiguration(configuration);
        UserAuthorityGranter authorityGranter = new UserAuthorityGranter();
        UserAuthorityGranter[] authorityGranters = new UserAuthorityGranter[] { authorityGranter };
        jaasAuthenticationProvider.setAuthorityGranters(authorityGranters);
        jaasAuthenticationProvider.afterPropertiesSet();

        String userName = authentication.getName();
        String userPassword = "";
        if (authentication.getCredentials() != null) {
            userPassword = authentication.getCredentials().toString();
        }

        // getting user authenticated
        if (userName != null && userPassword != null && !userName.trim().isEmpty()
                && !userPassword.trim().isEmpty()) {
            final List<GrantedAuthority> grantedAuths = getAuthorities(userName);

            final UserDetails principal = new User(userName, userPassword, grantedAuths);

            final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal,
                    userPassword, grantedAuths);

            authentication = jaasAuthenticationProvider.authenticate(finalAuthentication);
            authentication = getAuthenticationWithGrantedAuthority(authentication);
            return authentication;
        } else {
            return authentication;
        }

    } catch (Exception e) {
        logger.debug("Pam Authentication Failed:", e);
    }
    return authentication;
}

From source file:com.graphaware.test.integration.ServerIntegrationTest.java

/**
 * Populate server configurator with additional configuration. This method should rarely be overridden. In order to
 * register extensions, provide additional server config (including changing the port on which the server runs),
 * please override one of the methods below.
 * <p>/* w  ww.  j  a  v a  2  s. c o m*/
 * This method is only called iff {@link #configFile()} returns <code>null</code>.
 *
 * @param builder to populate.
 */
protected CommunityServerBuilder configure(CommunityServerBuilder builder) throws IOException {
    builder = builder.onAddress(new HostnamePort("localhost", neoServerPort()));

    for (Map.Entry<String, String> mapping : thirdPartyJaxRsPackageMappings().entrySet()) {
        builder = builder.withThirdPartyJaxRsPackage(mapping.getKey(), mapping.getValue());
    }

    builder = builder.withProperty(GraphDatabaseSettings.auth_enabled.name(), Boolean.toString(authEnabled()));

    if (configFile() != null) {
        Properties properties = new Properties();
        properties.load(new ClassPathResource(configFile()).getInputStream());
        for (String key : properties.stringPropertyNames()) {
            builder = builder.withProperty(key, properties.getProperty(key));
        }
    }

    for (Map.Entry<String, String> config : additionalServerConfiguration().entrySet()) {
        builder = builder.withProperty(config.getKey(), config.getValue());
    }

    return builder;
}

From source file:com.izforge.izpack.compiler.data.PropertyManager.java

/**
 * iterate through a set of properties, resolve them then assign them
 *
 * @param props properties to resolve//from   www.j a  v a  2 s  . co m
 * @param prefix prefix to to be automatically added to the property name, can be null
 */
private void addProperties(Properties props, String prefix) throws IOException {
    resolveAllProperties(props);
    for (String name : props.stringPropertyNames()) {
        String value = props.getProperty(name);

        if (prefix != null) {
            name = prefix + name;
        }
        addPropertySubstitute(name, value);
    }
}