Example usage for java.util Properties isEmpty

List of usage examples for java.util Properties isEmpty

Introduction

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

Prototype

@Override
    public boolean isEmpty() 

Source Link

Usage

From source file:com.dangdang.config.service.web.mb.PropertyGroupManagedBean.java

@Deprecated
private void savePropertyGroupOld(String fileName, String group, InputStream inputstream) throws IOException {
    Reader reader = new InputStreamReader(inputstream, Charsets.UTF_8);
    Properties properties = new Properties();
    properties.load(reader);
    if (!properties.isEmpty()) {
        String authedNode = ZKPaths.makePath(nodeAuth.getAuthedNode(), versionMB.getSelectedVersion());
        String groupPath = ZKPaths.makePath(authedNode, group);
        boolean created = nodeService.createProperty(groupPath, null);
        if (created) {
            Map<String, String> map = Maps.fromProperties(properties);
            for (Entry<String, String> entry : map.entrySet()) {
                nodeService.createProperty(ZKPaths.makePath(groupPath, entry.getKey()), entry.getValue());
            }/*  w w  w  . j  a  va 2  s  .  co m*/
            refreshGroup();
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage("Succesful", fileName + " is uploaded."));
        } else {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, "Create group with file error.", fileName));
        }
    } else {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "File is empty.", fileName));
    }
}

From source file:io.fabric8.vertx.maven.plugin.SetupMojoTest.java

@Test
public void testAddVertxMavenPluginWithVertxVersion() throws Exception {

    System.setProperty("vertxVersion", "3.4.0");

    InputStream pomFile = getClass().getResourceAsStream("/unit/setup/vmp-setup-pom.xml");
    assertNotNull(pomFile);//from w w w . jav a2  s.c o m
    MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
    Model model = xpp3Reader.read(pomFile);

    MavenProject project = new MavenProject(model);

    Optional<Plugin> vmPlugin = MojoUtils.hasPlugin(project, "io.fabric8:vertx-maven-plugin");
    assertFalse(vmPlugin.isPresent());

    Plugin vertxMavenPlugin = plugin("io.fabric8", "vertx-maven-plugin",
            MojoUtils.getVersion("vertx-maven-plugin-version"));

    PluginExecution pluginExec = new PluginExecution();
    pluginExec.addGoal("initialize");
    pluginExec.addGoal("package");
    pluginExec.setId("vmp-init-package");
    vertxMavenPlugin.addExecution(pluginExec);

    vertxMavenPlugin.setConfiguration(configuration(element("redeploy", "true")));

    model.getBuild().getPlugins().add(vertxMavenPlugin);

    String vertxVersion = System.getProperty("vertxVersion") == null
            ? MojoUtils.getVersion("vertx-core-version")
            : System.getProperty("vertxVersion");

    model.getProperties().putIfAbsent("vertx.version", vertxVersion);

    Dependency vertxBom = dependency("io.vertx", "vertx-dependencies", "${vertx.version}");
    vertxBom.setType("pom");
    vertxBom.setScope("import");

    addDependencies(model, vertxBom);

    MavenXpp3Writer xpp3Writer = new MavenXpp3Writer();
    StringWriter updatedPom = new StringWriter();

    xpp3Writer.write(updatedPom, model);
    updatedPom.flush();
    updatedPom.close();

    //System.out.println(updatedPom);

    //Check if it has been added

    model = xpp3Reader.read(new StringReader(updatedPom.toString()));
    project = new MavenProject(model);
    vmPlugin = MojoUtils.hasPlugin(project, "io.fabric8:vertx-maven-plugin");
    assertTrue(vmPlugin.isPresent());
    Plugin vmp = project.getPlugin("io.fabric8:vertx-maven-plugin");
    assertNotNull(vmp);
    Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration();
    assertNotNull(pluginConfig);
    String redeploy = pluginConfig.getChild("redeploy").getValue();
    assertNotNull(redeploy);
    assertTrue(Boolean.valueOf(redeploy));
    Properties projectProps = project.getProperties();
    assertNotNull(projectProps);
    assertFalse(projectProps.isEmpty());
    assertEquals(projectProps.getProperty("vertx.version"), vertxVersion);
}

From source file:io.reactiverse.vertx.maven.plugin.SetupMojoTest.java

@Test
public void testAddVertxMavenPluginWithVertxVersion() throws Exception {

    System.setProperty("vertxVersion", "3.4.0");

    InputStream pomFile = getClass().getResourceAsStream("/unit/setup/vmp-setup-pom.xml");
    assertNotNull(pomFile);/*  ww w .  j  a va 2s  .  c  om*/
    MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
    Model model = xpp3Reader.read(pomFile);

    MavenProject project = new MavenProject(model);

    Optional<Plugin> vmPlugin = MojoUtils.hasPlugin(project, "io.reactiverse:vertx-maven-plugin");
    assertFalse(vmPlugin.isPresent());

    Plugin vertxMavenPlugin = plugin("io.reactiverse", "vertx-maven-plugin",
            MojoUtils.getVersion("vertx-maven-plugin-version"));

    PluginExecution pluginExec = new PluginExecution();
    pluginExec.addGoal("initialize");
    pluginExec.addGoal("package");
    pluginExec.setId("vmp-init-package");
    vertxMavenPlugin.addExecution(pluginExec);

    vertxMavenPlugin.setConfiguration(configuration(element("redeploy", "true")));

    model.getBuild().getPlugins().add(vertxMavenPlugin);

    String vertxVersion = System.getProperty("vertxVersion") == null
            ? MojoUtils.getVersion("vertx-core-version")
            : System.getProperty("vertxVersion");

    model.getProperties().putIfAbsent("vertx.version", vertxVersion);

    Dependency vertxBom = dependency("io.vertx", "vertx-dependencies", "${vertx.version}");
    vertxBom.setType("pom");
    vertxBom.setScope("import");

    addDependencies(model, vertxBom);

    MavenXpp3Writer xpp3Writer = new MavenXpp3Writer();
    StringWriter updatedPom = new StringWriter();

    xpp3Writer.write(updatedPom, model);
    updatedPom.flush();
    updatedPom.close();

    //System.out.println(updatedPom);

    //Check if it has been added

    model = xpp3Reader.read(new StringReader(updatedPom.toString()));
    project = new MavenProject(model);
    vmPlugin = MojoUtils.hasPlugin(project, "io.reactiverse:vertx-maven-plugin");
    assertTrue(vmPlugin.isPresent());
    Plugin vmp = project.getPlugin("io.reactiverse:vertx-maven-plugin");
    assertNotNull(vmp);
    Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration();
    assertNotNull(pluginConfig);
    String redeploy = pluginConfig.getChild("redeploy").getValue();
    assertNotNull(redeploy);
    assertTrue(Boolean.valueOf(redeploy));
    Properties projectProps = project.getProperties();
    assertNotNull(projectProps);
    assertFalse(projectProps.isEmpty());
    assertEquals(projectProps.getProperty("vertx.version"), vertxVersion);
}

From source file:com.ottogroup.bi.asap.operator.twitter.consumer.TwitterStreamConsumer.java

/**
 * @see com.ottogroup.bi.asap.component.Component#init(java.util.Properties)
 *//*ww  w. j a v  a  2  s .c  o  m*/
public void init(Properties props) throws RequiredInputMissingException {

    if (props == null || props.isEmpty())
        throw new RequiredInputMissingException("Missing required configuration");

    //////////////////////////////////////////////////////////
    // extract required configurational data 
    this.consumerKey = props.getProperty(CFG_TWITTER_CONSUMER_KEY);
    this.consumerSecret = props.getProperty(CFG_TWITTER_CONSUMER_SECRET);
    this.tokenKey = props.getProperty(CFG_TWITTER_TOKEN_KEY);
    this.tokenSecret = props.getProperty(CFG_TWITTER_TOKEN_SECRET);
    this.id = props.getProperty(CFG_COMPONENT_ID);

    String inSearchTerms = props.getProperty(CFG_TWITTER_TWEET_SEARCH_TERMS);
    String[] splittedSearchTerms = (inSearchTerms != null ? inSearchTerms.split(",") : null);
    if (splittedSearchTerms != null) {
        for (String sst : splittedSearchTerms) {
            this.searchTerms.add(StringUtils.trim(sst));
        }
    }

    String inLanguages = props.getProperty(CFG_TWITTER_TWEET_LANGUAGES);
    String[] splittedLanguages = (inLanguages != null ? inLanguages.split(",") : null);
    if (splittedLanguages != null) {
        for (String s : splittedLanguages) {
            this.languages.add(StringUtils.trim(s));
        }
    }

    String inProfiles = props.getProperty(CFG_TWITTER_PROFILES);
    String[] splittedProfiles = (inProfiles != null ? inProfiles.split(",") : null);
    if (splittedProfiles != null) {
        for (String sp : splittedProfiles) {
            if (StringUtils.isNotBlank(sp)) {
                try {
                    this.profiles.add(Long.parseLong(sp.trim()));
                } catch (Exception e) {
                    logger.error("Failed to parse profile identifier from input '" + sp + "'");
                }
            }
        }
    }
    //
    //////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////////////////////
    // validate provided input before attempting to establish connection with stream.twitter.com
    if (StringUtils.isBlank(id))
        throw new RequiredInputMissingException("Missing required component identifier");
    if (StringUtils.isBlank(this.consumerKey))
        throw new RequiredInputMissingException(
                "Missing required consumer key to establish connection with stream.twitter.com");
    if (StringUtils.isBlank(this.consumerSecret))
        throw new RequiredInputMissingException(
                "Missing required consumer secrect to establish connection with stream.twitter.com");
    if (StringUtils.isBlank(this.tokenKey))
        throw new RequiredInputMissingException(
                "Missing required token key to establish connection with stream.twitter.com");
    if (StringUtils.isBlank(this.tokenSecret))
        throw new RequiredInputMissingException(
                "Missing required token secret to establish connection with stream.twitter.com");

    boolean isFilterTermsEmpty = (this.searchTerms == null || this.searchTerms.isEmpty());
    boolean isLanguagesEmpty = (this.languages == null || this.languages.isEmpty());
    boolean isUserAccountEmpty = (this.profiles == null || this.profiles.isEmpty());
    boolean isLocationsEmpty = (this.locations == null || this.locations.isEmpty());

    if (isFilterTermsEmpty && isLanguagesEmpty && isUserAccountEmpty && isLocationsEmpty)
        throw new RequiredInputMissingException(
                "Mishandle sing information what to filter twitter stream for: terms, languages, user accounts or locations");
    //
    ////////////////////////////////////////////////////////////////////////////////////////////

    //////////////////////////////////////////////////////////
    // establish connection with stream.twitter.com
    Authentication auth = new OAuth1(this.consumerKey, this.consumerSecret, this.tokenKey, this.tokenSecret);
    StatusesFilterEndpoint filterEndpoint = new StatusesFilterEndpoint();
    if (!isFilterTermsEmpty)
        filterEndpoint.trackTerms(searchTerms);
    if (!isLanguagesEmpty)
        filterEndpoint.languages(languages);
    if (!isUserAccountEmpty)
        filterEndpoint.followings(profiles);
    if (!isLocationsEmpty)
        filterEndpoint.locations(locations);

    if (this.twitterClient == null) {
        this.twitterClient = new ClientBuilder().name(id).hosts(Constants.STREAM_HOST).endpoint(filterEndpoint)
                .authentication(auth).processor(new StringDelimitedProcessor(streamMessageQueue)).build();
        this.twitterClient.connect();
    }
    //
    //////////////////////////////////////////////////////////

    this.isRunning = true;

}

From source file:com.liferay.portal.security.ldap.BasePortalToLDAPConverter.java

public Modifications getLDAPContactModifications(Contact contact,
        Map<String, Serializable> contactExpandoAttributes, Properties contactMappings,
        Properties contactExpandoMappings) throws Exception {

    if (contactMappings.isEmpty() && contactExpandoMappings.isEmpty()) {
        return null;
    }/*from   www  .ja v  a  2  s.  c  o m*/

    Modifications modifications = getModifications(contact, contactMappings, _reservedContactFieldNames);

    populateCustomAttributeModifications(contact, contact.getExpandoBridge(), contactExpandoAttributes,
            contactExpandoMappings, modifications);

    return modifications;
}

From source file:org.wso2.carbon.identity.openidconnect.OpenIDConnectClaimFilterImpl.java

private boolean isNotEmpty(Properties properties) {

    return properties != null && !properties.isEmpty();
}

From source file:org.mule.context.DefaultMuleContextFactory.java

/**
 * Creates a new {@link MuleContext} instance from the resource provided.
 * Implementations of {@link MuleContextFactory} can either use a default
 * {@link ConfigurationBuilder} to implement this, or do some auto-detection to
 * determine the {@link ConfigurationBuilder} that should be used. Properties if
 * provided are used to replace "property placeholder" value in configuration
 * files.//from   w ww. j  a va  2s.  com
 */
public MuleContext createMuleContext(String configResources, Properties properties)
        throws InitialisationException, ConfigurationException {
    // Create MuleContext
    MuleContext muleContext = doCreateMuleContext(new DefaultMuleContextBuilder());

    // Configure with startup properties
    if (properties != null && !properties.isEmpty()) {
        new SimpleConfigurationBuilder(properties).configure(muleContext);
    }

    // Automatically resolve Configuration to be used and delegate configuration
    // to it.
    new AutoConfigurationBuilder(configResources).configure(muleContext);

    notifyMuleContextConfiguration(muleContext);

    return muleContext;
}

From source file:org.apache.ftpserver.message.MessageResourceImpl.java

/**
 * Save properties in file./*  w w w. j  ava 2  s. c om*/
 */
public void save(Properties prop, String language) throws FtpException {

    // null properties - nothing to save
    if (prop == null) {
        return;
    }

    // empty properties - nothing to save
    if (prop.isEmpty()) {
        return;
    }

    // get custom resource file name
    File resourceFile = null;
    if (language == null) {
        resourceFile = new File(m_customMessageDir, "FtpStatus.gen");
    } else {
        language = language.toLowerCase();
        resourceFile = new File(m_customMessageDir, "FtpStatus_" + language + ".gen");
    }

    // save resource file
    OutputStream out = null;
    try {
        out = new FileOutputStream(resourceFile);
        prop.store(out, "Custom Messages");
    } catch (IOException ex) {
        m_log.error("MessageResourceImpl.save()", ex);
        throw new FtpException("MessageResourceImpl.save()", ex);
    } finally {
        IoUtils.close(out);
    }

    // assign new messages
    PropertiesPair pair = (PropertiesPair) m_messages.get(language);
    if (pair == null) {
        pair = new PropertiesPair();
        m_messages.put(language, pair);
    }
    pair.m_custom = prop;
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.ResultFileWriter.java

/**
 * Appends the decision variables, objectives and optional properties to
 * the output file.  Constraint violating solutions are not recorded.
 * /*from   www. j ava2 s.  c o m*/
 * @param entry the entry to write
 * @throws IOException if an I/O error occurred
 */
public void append(ResultEntry entry) throws IOException {
    numberOfEntries++;

    //generate list of all feasible solutions
    List<Solution> feasibleSolutions = new ArrayList<Solution>();

    for (Solution solution : entry.getPopulation()) {
        if (!solution.violatesConstraints()) {
            feasibleSolutions.add(solution);
        }
    }

    //ensure a non-empty entry is written
    Properties properties = entry.getProperties();

    if (feasibleSolutions.isEmpty() && ((properties == null) || (properties.isEmpty()))) {
        writer.println("//");
    }

    //write entry
    if ((properties != null) && !properties.isEmpty()) {
        printProperties(properties);
    }

    if (!feasibleSolutions.isEmpty()) {
        for (Solution solution : feasibleSolutions) {
            printSolution(solution);
        }
    }

    writer.println('#');
}

From source file:org.wso2.carbon.identity.sts.passive.processors.RequestProcessor.java

protected SAMLTokenIssuerConfig getSAMLTokenIssuerConfig(AxisService service, boolean isSuperTenant)
        throws Exception {
    UserRegistry systemRegistry = null;/*from   w  w w  .  jav  a  2 s.  co m*/
    String keyAlias = null;
    String keyPassword = null;
    KeyStoreAdmin admin = null;
    KeyStoreData[] keystores = null;
    String privateKeyAlias = null;
    String keyStoreName = null;
    String issuerName = null;
    ServerConfiguration serverConfig = null;
    String ttl;

    systemRegistry = (UserRegistry) IdentityPassiveSTSServiceComponent.getGovernanceSystemRegistry();

    if (systemRegistry == null || service == null) {
        if (log.isDebugEnabled()) {
            log.debug("systemRegistry not set or STS service is unavialable");
        }
        return null;
    }

    serverConfig = ServerConfiguration.getInstance();
    keyAlias = serverConfig.getFirstProperty("Security.KeyStore.KeyAlias");
    keyPassword = serverConfig.getFirstProperty("Security.KeyStore.KeyPassword");
    issuerName = serverConfig.getFirstProperty("HostName");
    ttl = serverConfig.getFirstProperty("STSTimeToLive");

    if (issuerName == null) {
        // HostName not set :-( use wso2wsas-sts
        issuerName = "Identity-passive-sts";
    }

    admin = new KeyStoreAdmin(MultitenantConstants.SUPER_TENANT_ID, systemRegistry);
    keystores = admin.getKeyStores(isSuperTenant);

    for (int i = 0; i < keystores.length; i++) {
        if (KeyStoreUtil.isPrimaryStore(keystores[i].getKeyStoreName())) {
            keyStoreName = keystores[i].getKeyStoreName();
            privateKeyAlias = KeyStoreUtil.getPrivateKeyAlias(KeyStoreManager
                    .getInstance(MultitenantConstants.SUPER_TENANT_ID).getKeyStore(keyStoreName));
            break;
        }
    }

    if (privateKeyAlias != null) {

        String cryptoProvider = ServerCrypto.class.getName();

        Properties props = RampartConfigUtil.getServerCryptoProperties(new String[] { keyStoreName },
                keyStoreName, privateKeyAlias);

        SAMLTokenIssuerConfig stsSamlConfig = new SAMLTokenIssuerConfig(issuerName, cryptoProvider, props);
        stsSamlConfig.setIssuerKeyAlias(keyAlias);
        stsSamlConfig.setIssuerKeyPassword(keyPassword);
        stsSamlConfig.setAddRequestedAttachedRef(true);
        stsSamlConfig.setAddRequestedUnattachedRef(true);
        stsSamlConfig.setKeyComputation(2);
        stsSamlConfig.setProofKeyType(TokenIssuerUtil.BINARY_SECRET);
        stsSamlConfig.setCallbackHandlerName(AttributeCallbackHandler.class.getName());
        if (ttl != null && ttl.length() > 0) {
            try {
                stsSamlConfig.setTtl(Long.parseLong(ttl));
                if (log.isDebugEnabled()) {
                    log.debug("STSTimeToLive read from carbon.xml in passive STS " + ttl);
                }
            } catch (NumberFormatException e) {
                log.error("Error while reading STSTimeToLive from carbon.xml", e);
            }
        }
        String resourcePath = null;
        resourcePath = RegistryResources.SERVICE_GROUPS + ServerConstants.STS_NAME + RegistryResources.SERVICES
                + ServerConstants.STS_NAME + "/trustedServices";
        if (systemRegistry.resourceExists(resourcePath)) {
            Resource trustedService = null;
            Properties properties = null;
            Iterator iterator = null;
            trustedService = systemRegistry.get(resourcePath);
            properties = trustedService.getProperties();
            if (properties != null && !properties.isEmpty()) {
                iterator = properties.entrySet().iterator();
                while (iterator.hasNext()) {
                    Entry entry = (Entry) iterator.next();
                    if (RegistryUtils.isHiddenProperty(entry.getKey().toString())) {
                        continue;
                    }
                    stsSamlConfig.addTrustedServiceEndpointAddress((String) entry.getKey(),
                            (String) ((List) entry.getValue()).get(0));
                }
            }
        }

        return stsSamlConfig;
    }
    return null;
}