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:eu.eidas.auth.commons.EIDASUtil.java

@SuppressWarnings("CollectionDeclaredAsConcreteClass")
@Nonnull/*from   www .  j  a va2  s  . c  o  m*/
static ImmutableMap<String, String> immutableMap(@Nullable Properties properties) {
    if (null == properties || properties.isEmpty()) {
        return ImmutableMap.of();
    }
    return Maps.fromProperties(properties);
}

From source file:de.pawlidi.openaletheia.utils.CipherUtils.java

/**
 * /*w  ww . j a v a  2s.c  o  m*/
 * @param properties
 * @return
 */
public static byte[] computeSignature(Properties properties) {
    if (properties != null && !properties.isEmpty()) {
        StringBuilder builder = new StringBuilder();
        ArrayList keys = new ArrayList<Object>(properties.keySet());
        Collections.sort(keys);
        for (Object key : keys) {
            Object value = properties.get(key);
            if (value != null) {
                builder.append(key);
                builder.append("=");
                builder.append(value);
                builder.append("\n");
            }
        }
        String pattern = builder.toString();
        if (!pattern.isEmpty()) {
            return computeSignature(Converter.getBytesIso8859(pattern));
        }
    }
    return null;
}

From source file:com.taobao.tddl.jdbc.atom.common.TAtomConfParser.java

public static TAtomDsConfDO parserTAtomDsConfDO(String globaConfStr, String appConfStr) {
    TAtomDsConfDO pasObj = new TAtomDsConfDO();
    if (TStringUtil.isNotBlank(globaConfStr)) {
        Properties globaProp = TAtomConfParser.parserConfStr2Properties(globaConfStr);
        if (!globaProp.isEmpty()) {
            String ip = TStringUtil.trim(globaProp.getProperty(TAtomConfParser.GLOBA_IP_KEY));
            if (TStringUtil.isNotBlank(ip)) {
                pasObj.setIp(ip);/*from  ww w  .j  a va2  s.  c o m*/
            }
            String port = TStringUtil.trim(globaProp.getProperty(TAtomConfParser.GLOBA_PORT_KEY));
            if (TStringUtil.isNotBlank(port)) {
                pasObj.setPort(port);
            }
            String dbName = TStringUtil.trim(globaProp.getProperty(TAtomConfParser.GLOBA_DB_NAME_KEY));
            if (TStringUtil.isNotBlank(dbName)) {
                pasObj.setDbName(dbName);
            }
            String dbType = TStringUtil.trim(globaProp.getProperty(TAtomConfParser.GLOBA_DB_TYPE_KEY));
            if (TStringUtil.isNotBlank(dbType)) {
                pasObj.setDbType(dbType);
            }
            String dbStatus = TStringUtil.trim(globaProp.getProperty(TAtomConfParser.GLOBA_DB_STATUS_KEY));
            if (TStringUtil.isNotBlank(dbStatus)) {
                pasObj.setDbStatus(dbStatus);
            }
        }
    }
    if (TStringUtil.isNotBlank(appConfStr)) {
        Properties appProp = TAtomConfParser.parserConfStr2Properties(appConfStr);
        if (!appProp.isEmpty()) {
            String userName = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_USER_NAME_KEY));
            if (TStringUtil.isNotBlank(userName)) {
                pasObj.setUserName(userName);
            }
            String oracleConType = TStringUtil
                    .trim(appProp.getProperty(TAtomConfParser.APP_ORACLE_CON_TYPE_KEY));
            if (TStringUtil.isNotBlank(oracleConType)) {
                pasObj.setOracleConType(oracleConType);
            }
            String minPoolSize = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_MIN_POOL_SIZE_KEY));
            if (TStringUtil.isNotBlank(minPoolSize) && TStringUtil.isNumeric(minPoolSize)) {
                pasObj.setMinPoolSize(Integer.valueOf(minPoolSize));
            }
            String maxPoolSize = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_MAX_POOL_SIZE_KEY));
            if (TStringUtil.isNotBlank(maxPoolSize) && TStringUtil.isNumeric(maxPoolSize)) {
                pasObj.setMaxPoolSize(Integer.valueOf(maxPoolSize));
            }
            String idleTimeout = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_IDLE_TIMEOUT_KEY));
            if (TStringUtil.isNotBlank(idleTimeout) && TStringUtil.isNumeric(idleTimeout)) {
                pasObj.setIdleTimeout(Long.valueOf(idleTimeout));
            }
            String blockingTimeout = TStringUtil
                    .trim(appProp.getProperty(TAtomConfParser.APP_BLOCKING_TIMEOUT_KEY));
            if (TStringUtil.isNotBlank(blockingTimeout) && TStringUtil.isNumeric(blockingTimeout)) {
                pasObj.setBlockingTimeout(Integer.valueOf(blockingTimeout));
            }
            String preparedStatementCacheSize = TStringUtil
                    .trim(appProp.getProperty(TAtomConfParser.APP_PREPARED_STATEMENT_CACHE_SIZE_KEY));
            if (TStringUtil.isNotBlank(preparedStatementCacheSize)
                    && TStringUtil.isNumeric(preparedStatementCacheSize)) {
                pasObj.setPreparedStatementCacheSize(Integer.valueOf(preparedStatementCacheSize));
            }

            String writeRestrictTimes = TStringUtil
                    .trim(appProp.getProperty(TAtomConfParser.APP_WRITE_RESTRICT_TIMES));
            if (TStringUtil.isNotBlank(writeRestrictTimes) && TStringUtil.isNumeric(writeRestrictTimes)) {
                pasObj.setWriteRestrictTimes(Integer.valueOf(writeRestrictTimes));
            }

            String readRestrictTimes = TStringUtil
                    .trim(appProp.getProperty(TAtomConfParser.APP_READ_RESTRICT_TIMES));
            if (TStringUtil.isNotBlank(readRestrictTimes) && TStringUtil.isNumeric(readRestrictTimes)) {
                pasObj.setReadRestrictTimes(Integer.valueOf(readRestrictTimes));
            }
            String threadCountRestrict = TStringUtil
                    .trim(appProp.getProperty(TAtomConfParser.APP_THREAD_COUNT_RESTRICT));
            if (TStringUtil.isNotBlank(threadCountRestrict) && TStringUtil.isNumeric(threadCountRestrict)) {
                pasObj.setThreadCountRestrict(Integer.valueOf(threadCountRestrict));
            }
            String timeSliceInMillis = TStringUtil
                    .trim(appProp.getProperty(TAtomConfParser.APP_TIME_SLICE_IN_MILLS));
            if (TStringUtil.isNotBlank(timeSliceInMillis) && TStringUtil.isNumeric(timeSliceInMillis)) {
                pasObj.setTimeSliceInMillis(Integer.valueOf(timeSliceInMillis));
            }

            String conPropStr = TStringUtil.trim(appProp.getProperty(TAtomConfParser.APP_CON_PROP_KEY));
            Map<String, String> connectionProperties = parserConPropStr2Map(conPropStr);
            if (null != connectionProperties && !connectionProperties.isEmpty()) {
                pasObj.setConnectionProperties(connectionProperties);
            }
        }
    }
    return pasObj;
}

From source file:org.springframework.integration.history.MessageHistory.java

@SuppressWarnings("unchecked")
public static <T> Message<T> write(Message<T> message, NamedComponent component,
        MessageBuilderFactory messageBuilderFactory) {
    Assert.notNull(message, "Message must not be null");
    Assert.notNull(component, "Component must not be null");
    Properties metadata = extractMetadata(component);
    if (!metadata.isEmpty()) {
        MessageHistory previousHistory = message.getHeaders().get(HEADER_NAME, MessageHistory.class);
        List<Properties> components = (previousHistory != null) ? new ArrayList<Properties>(previousHistory)
                : new ArrayList<Properties>();
        components.add(metadata);//  w w  w . ja v a2s. co  m
        MessageHistory history = new MessageHistory(components);

        if (message instanceof MutableMessage) {
            message.getHeaders().put(HEADER_NAME, history);
        } else if (message instanceof ErrorMessage) {
            IntegrationMessageHeaderAccessor headerAccessor = new IntegrationMessageHeaderAccessor(message);
            headerAccessor.setHeader(HEADER_NAME, history);
            Throwable payload = ((ErrorMessage) message).getPayload();
            ErrorMessage errorMessage = new ErrorMessage(payload, headerAccessor.toMessageHeaders());
            message = (Message<T>) errorMessage;
        } else if (message instanceof AdviceMessage) {
            IntegrationMessageHeaderAccessor headerAccessor = new IntegrationMessageHeaderAccessor(message);
            headerAccessor.setHeader(HEADER_NAME, history);
            message = new AdviceMessage<T>(message.getPayload(), headerAccessor.toMessageHeaders(),
                    ((AdviceMessage<?>) message).getInputMessage());
        } else {
            if (!(message instanceof GenericMessage)
                    && (messageBuilderFactory instanceof DefaultMessageBuilderFactory
                            || messageBuilderFactory instanceof MutableMessageBuilderFactory)) {
                if (logger.isWarnEnabled()) {
                    logger.warn("MessageHistory rebuilds the message and produces the result of the ["
                            + messageBuilderFactory + "], not an instance of the provided type ["
                            + message.getClass() + "]. Consider to supply a custom MessageBuilderFactory "
                            + "to retain custom messages during MessageHistory tracking.");
                }
            }
            message = messageBuilderFactory.fromMessage(message).setHeader(HEADER_NAME, history).build();
        }
    }
    return message;
}

From source file:com.iisigroup.cap.mvc.i18n.MessageBundleScriptCreator.java

/**
 * properties?json?/* ww w . j  av  a 2  s  .  c o m*/
 *
 * @param props
 *            properties
 * @param filterList
 *            filter
 * @return String
 */
public static String generateJson(Properties props, Set<String> filterList) {
    AjaxFormResult result = new AjaxFormResult();
    String filterReg = generateFilterReg(filterList);
    if (props != null && !props.isEmpty()) {
        if (CapString.isEmpty(filterReg)) {
            for (Entry<Object, Object> entry : props.entrySet()) {
                result.set((String) entry.getKey(), (String) entry.getValue());
            }
        } else {
            for (Entry<Object, Object> entry : props.entrySet()) {
                if (CapString.checkRegularMatch((String) entry.getKey(), filterReg)) {
                    result.set(((String) entry.getKey()).replaceAll("js.", ""), (String) entry.getValue());
                }
            }
        }
    }
    return result.getResult();
}

From source file:org.smartfrog.avalanche.client.sf.apps.utils.SystemUtils.java

public static void addUser(String user, Properties props) throws UtilsException {

    if ((null == user) || (user.length() == 0)) {
        log.error("User name cannot be null");
        throw new UtilsException("User name cannot be null");
    }//from  w w  w . j  a  v  a  2s .  c  o  m

    String cmd = "adduser";

    if ((null == props) || (props.isEmpty())) {
        log.error("Please provide user information....");
        throw new UtilsException("Please provide user information....");
    }

    String passwd = (String) props.getProperty("-p");
    if ((null == passwd) || (passwd.length() == 0)) {
        log.error("Password is not provided....Cannot create user");
        throw new UtilsException("Password is not provided...." + "Cannot create user");
    }
    String epasswd = jcrypt.crypt("Tb", passwd);
    if (epasswd.length() == 0) {
        log.error("Error in encrypting passwd...");
        throw new UtilsException("Error in encrypting passwd...");
    }
    props.setProperty("-p", epasswd);
    props.setProperty("-c", "User-" + user);

    String key = null;
    String value = null;
    Enumeration e = props.keys();
    while (e.hasMoreElements()) {
        key = (String) e.nextElement();
        value = (String) props.getProperty(key);
        if ((null != value) || (value.length() != 0))
            cmd += " " + key + " " + value;
        else
            cmd += " " + key;
    }

    cmd += " " + user;

    Process p = null;
    Runtime rt = Runtime.getRuntime();
    BufferedReader cmdError = null;
    int exitVal = 0;
    try {
        p = rt.exec(cmd);
        exitVal = p.waitFor();
        cmdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        if (exitVal != 0) {
            String err = "Error in adding user " + user + "... returned with exit value 0 : ";
            log.error(err);
            String line = null;
            while ((line = cmdError.readLine()) != null) {
                log.error(line);
                err += line;
            }
            throw new UtilsException(err);
        }
    } catch (IOException ioe) {
        log.error(ioe);
        throw new UtilsException(ioe);
    } catch (InterruptedException ie) {
        log.error(ie);
        throw new UtilsException(ie);
    }

    log.info("User " + user + " added successfully");
}

From source file:org.wso2.carbon.datasource.MiscellaneousHelper.java

public static DataSourceInformation validateAndCreateDataSourceInformation(String name, OMElement element) {
    validateName(name);//from   w w w  . j a v a 2  s  .c  o m
    validateElement(element);
    Properties properties = MiscellaneousHelper.loadProperties(element);

    if (properties == null) {
        handleException("Invalid properties");
    }
    if (properties != null && properties.isEmpty()) {
        handleException("Empty property");
    }
    if (log.isDebugEnabled()) {
        log.debug("Properties " + properties);
    }
    DataSourceInformation information = DataSourceInformationFactory.createDataSourceInformation(name,
            properties);
    validateDataSourceDescription(information);
    if (log.isDebugEnabled()) {
        log.debug("DataSource Description : " + information);
    }
    return information;
}

From source file:com.igormaznitsa.mindmap.model.ModelUtils.java

@Nonnull
public static String makeQueryStringForURI(@Nullable final Properties properties) {
    if (properties == null || properties.isEmpty()) {
        return ""; //NOI18N
    }//from  w  ww  . ja  v  a  2  s  .  c o m
    final StringBuilder buffer = new StringBuilder();

    for (final String k : properties.stringPropertyNames()) {
        try {
            final String encodedKey = URLEncoder.encode(k, "UTF-8"); //NOI18N
            final String encodedValue = URLEncoder.encode(properties.getProperty(k), "UTF-8"); //NOI18N

            if (buffer.length() > 0) {
                buffer.append('&');
            }
            buffer.append(encodedKey).append('=').append(encodedValue);
        } catch (UnsupportedEncodingException ex) {
            LOGGER.error("Can't encode URI query", ex); //NOI18N
            throw new Error("Unexpected exception, can't find UTF-8 charset!"); //NOI18N
        }
    }
    return buffer.toString();
}

From source file:org.wso2.carbon.datasource.ui.DatasourceManagementClient.java

private static DataSourceInformation validateAndCreate(String name, OMElement element) throws AxisFault {
    validateName(name);/*from   w  w w.  j a  v a2 s.  c  o m*/
    validateDataSourceElement(element);
    Properties properties = loadProperties(element);
    if (log.isDebugEnabled()) {
        log.debug("Properties " + properties);
    }
    if (properties.isEmpty()) {
        handleException("Empty property");
    }

    DataSourceInformation information = DataSourceInformationFactory.createDataSourceInformation(name,
            properties);
    validateDataSourceInformation(information);
    if (log.isDebugEnabled()) {
        log.debug("DataSource Description : " + information);
    }
    return information;
}

From source file:gov.nih.nci.logging.api.util.HibernateUtil.java

/**
 * This method creates and returns the Hibernate SessionFactory used by CLM's Query API's.
 * //from  w w w . j  a  va 2  s.  c om
 * @return SessionFactory
 * @throws Exception
 */
private static SessionFactory createSessionFactory() throws Exception {
    LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean();
    String mappingResources[] = { "gov/nih/nci/logging/api/domain/LogMessage.hbm.xml",
            "gov/nih/nci/logging/api/domain/ObjectAttribute.hbm.xml" };
    localSessionFactoryBean.setMappingResources(mappingResources);

    /*
     * BasicDataSource ds = new BasicDataSource();
     * ds.setDriverClassName(props.getProperty("CLMDS.driverClassName"));
     * ds.setUrl(props.getProperty("CLMDS.url"));
     * ds.setUsername(props.getProperty("CLMDS.username"));
     * ds.setPassword(props.getProperty("CLMDS.password"));
     * localSessionFactoryBean.setDataSource(ds);
     */

    if (props == null) {
        java.io.InputStream inputStream = FileLoader.getInstance().getFileAsStream("clm.properties");
        Properties properties = new Properties();
        if (inputStream != null) {
            try {
                properties.load(inputStream);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (!properties.isEmpty()) {
            validateProperties(properties);
            props = properties;
        }
    }

    if (isDataSourceProperties()) {
        String jndiName = props.getProperty("CLMDJndiDS.jndiName");
        Properties properties = new Properties();
        properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
        localSessionFactoryBean.setHibernateProperties(props);
        // set javax.sql.DataSource 
        localSessionFactoryBean.setDataSource(getDataSource(jndiName));
    } else {
        //set JDBC Connection Properties for Hibernate
        localSessionFactoryBean.setHibernateProperties(props);

    }

    try {
        localSessionFactoryBean.afterPropertiesSet();
    } catch (HibernateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    SessionFactory sf = (SessionFactory) localSessionFactoryBean.getObject();
    return sf;
}