Example usage for org.apache.commons.lang3 StringUtils isNotEmpty

List of usage examples for org.apache.commons.lang3 StringUtils isNotEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isNotEmpty.

Prototype

public static boolean isNotEmpty(final CharSequence cs) 

Source Link

Document

Checks if a CharSequence is not empty ("") and not null.

 StringUtils.isNotEmpty(null)      = false StringUtils.isNotEmpty("")        = false StringUtils.isNotEmpty(" ")       = true StringUtils.isNotEmpty("bob")     = true StringUtils.isNotEmpty("  bob  ") = true 

Usage

From source file:de.knightsoftnet.mtwidgets.client.ui.widget.oracle.PhoneNumberUriRestOracle.java

@Override
protected boolean needSuggest(final String pentry) {
    return StringUtils.isNotEmpty(pentry) && StringUtils.countMatches(pentry, "-") < 2;
}

From source file:com.glaf.core.jdbc.DBConnectionFactory.java

public static boolean checkConnection(java.util.Properties props) {
    Connection connection = null;
    try {//w ww .  j av a  2  s  .c om
        if (StringUtils.isNotEmpty(props.getProperty(DBConfiguration.JDBC_DATASOURCE))) {
            InitialContext ctx = new InitialContext();
            DataSource ds = (DataSource) ctx.lookup(props.getProperty(DBConfiguration.JDBC_DATASOURCE));
            connection = ds.getConnection();
        } else {
            ConnectionProvider provider = ConnectionProviderFactory.createProvider(props);
            if (provider != null) {
                connection = provider.getConnection();
            }
        }
        if (connection != null) {
            return true;
        }
    } catch (Exception ex) {
        logger.error(ex);
        ex.printStackTrace();
    } finally {
        JdbcUtils.close(connection);
    }
    return false;
}

From source file:de.knightsoftnet.mtwidgets.client.ui.widget.oracle.PhoneNumberE123RestOracle.java

@Override
protected boolean needSuggest(final String pentry) {
    return StringUtils.isNotEmpty(pentry) && StringUtils.countMatches(pentry, " ") < 2
            && !StringUtils.contains(pentry, ')');
}

From source file:com.thruzero.common.jsf.support.SimpleOutputComponentBuilder.java

public HtmlOutputText createOutputText(String text, Styles styles) {
    HtmlOutputText result = new HtmlOutputText();

    result.setValue(text);//  w  ww  . j  ava2 s .c  om

    if (StringUtils.isNotEmpty(styles.getInlineStyle())) {
        result.setStyle(styles.getInlineStyle());
    }
    if (StringUtils.isNotEmpty(styles.getStyleClass())) {
        result.setStyleClass(styles.getStyleClass());
    }

    return result;
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesManifestLabeler.java

public static void storeLabels(String managedBySuffix, Map<String, String> labels, Moniker moniker) {
    if (moniker == null) {
        return;//from w w w . j  a va2 s  .  c  o  m
    }

    String appManagedByValue = "spinnaker";

    if (StringUtils.isNotEmpty(managedBySuffix)) {
        appManagedByValue = appManagedByValue + "-" + managedBySuffix;
    }

    // other properties aren't currently set by Spinnaker
    storeLabel(labels, APP_NAME, moniker.getApp());
    storeLabelAndOverwrite(labels, APP_MANAGED_BY, appManagedByValue);
    if (moniker.getSequence() != null) {
        storeLabelAndOverwrite(labels, SEQUENCE, moniker.getSequence() + "");
    }
}

From source file:de.knightsoftnet.mtwidgets.client.ui.widget.oracle.PhoneNumberCommonRestOracle.java

@Override
protected boolean needSuggest(final String pentry) {
    return StringUtils.isNotEmpty(pentry)
            && (pentry.charAt(0) != '0' && StringUtils.countMatches(pentry, " ") < 2
                    || pentry.charAt(0) == '0' && !StringUtils.contains(pentry, '/'));
}

From source file:com.adobe.acs.commons.adobeio.service.impl.AdobeioHealthcheck.java

@Override
public Result execute() {
    final FormattingResultLog resultLog = new FormattingResultLog();

    boolean integrationOk = true;

    resultLog.debug("Health check for Adobe I/O");
    if (StringUtils.isNotEmpty(integrationService.getApiKey())) {
        resultLog.debug("Starting validation for x-api-key {}", integrationService.getApiKey());
    } else {/*from w ww. jav  a 2  s .  c  o m*/
        resultLog.critical("No api key is specified in the OSGi-config");
        integrationOk = false;
    }
    resultLog.debug("Obtaining the access token");
    String accessToken = integrationService.getAccessToken();

    if (StringUtils.isNotEmpty(accessToken)) {
        resultLog.info("Access token succesfully obtained {}", accessToken);
    } else {
        resultLog.critical("Could not obtain the access token");
        integrationOk = false;
    }

    if (!integrationOk) {
        resultLog.info("IntegrationService not healthy; skipping Endpoint checks.");
    }

    if (endpoints == null || endpoints.isEmpty()) {
        resultLog.warn("No Endpoint Services found.");
        return new Result(resultLog);
    }
    for (EndpointService endpoint : endpoints) {
        execute(resultLog, endpoint);
    }

    resultLog.info("Healthcheck completed");

    return new Result(resultLog);
}

From source file:com.glaf.core.startup.MultiDBStartup.java

public void startup(ServletContext context, String text) {
    logger.debug("-----------------MultiDBStartup.startup----------------");
    if (StringUtils.isNotEmpty(text)) {
        JSONObject json = JSON.parseObject(text);
        logger.debug(json.toJSONString());
        String sql = json.getString("sql");
        String dbName = json.getString("dbName");
        if (StringUtils.isNotEmpty(sql) && !DBUtils.isLegalQuerySql(sql)) {
            logger.error(sql);//www.j  a v  a  2 s .  co m
            throw new RuntimeException(" SQL statement illegal ");
        }
        if (StringUtils.isNotEmpty(sql) && StringUtils.isNotEmpty(dbName)) {
            Properties defaultProps = DBConfiguration.getTemplateProperties(Environment.DEFAULT_SYSTEM_NAME);
            Properties props = DBConfiguration.getTemplateProperties(dbName);
            logger.debug(dbName + " props:" + props);
            if (props != null && StringUtils.isNotEmpty(props.getProperty(DBConfiguration.JDBC_URL))) {
                String old_url = props.getProperty(DBConfiguration.JDBC_URL);
                Connection conn = null;
                PreparedStatement stmt = null;
                ResultSet rs = null;
                try {
                    conn = DBConnectionFactory.getConnection();
                    if (conn != null) {
                        DBUpdateThread t = new DBUpdateThread(defaultProps);
                        ThreadFactory.run(t);
                        stmt = conn.prepareStatement(sql);
                        rs = stmt.executeQuery();
                        while (rs.next()) {
                            Map<String, Object> dataMap = new java.util.HashMap<String, Object>();
                            Enumeration<?> e = props.keys();
                            while (e.hasMoreElements()) {
                                String key = (String) e.nextElement();
                                String value = props.getProperty(key);
                                dataMap.put(key, value);
                            }
                            String host = rs.getString(1);
                            String databaseName = rs.getString(2);
                            String name = rs.getString(5);
                            if (databaseName.indexOf("$") != -1) {
                                String url_xy = defaultProps.getProperty(DBConfiguration.JDBC_URL);
                                String driver = defaultProps.getProperty(DBConfiguration.JDBC_DRIVER);
                                String db = null;
                                if (StringUtils.equals(driver,
                                        "com.microsoft.sqlserver.jdbc.SQLServerDriver")) {
                                    db = url_xy.substring(url_xy.lastIndexOf("=") + 1, url_xy.length());
                                } else if (StringUtils.equals(driver, "net.sourceforge.jtds.jdbc.Driver")) {
                                    db = url_xy.substring(url_xy.lastIndexOf("/") + 1, url_xy.length());
                                }
                                if (db != null) {
                                    databaseName = StringTools.replaceIgnoreCase(databaseName, "self", db);
                                }
                            }
                            logger.debug("databaseName:" + databaseName);
                            dataMap.put(DBConfiguration.HOST, host);
                            dataMap.put(DBConfiguration.DATABASE, databaseName);
                            props.put(DBConfiguration.HOST, host);
                            props.put(DBConfiguration.DATABASE, databaseName);
                            props.put(DBConfiguration.JDBC_USER, rs.getString(3));
                            props.put(DBConfiguration.JDBC_PASSWORD, rs.getString(4));

                            logger.debug(dataMap);
                            logger.debug("url:" + old_url);
                            String url = ExpressionTools.evaluate(old_url, dataMap);
                            props.put(DBConfiguration.JDBC_URL, url);
                            host = StringTools.replace(host, ".", "_");
                            props.put(DBConfiguration.JDBC_NAME, name);

                            logger.debug("jdbc url:" + props.getProperty(DBConfiguration.JDBC_URL));

                            /**
                             * ???
                             */
                            if (DBConnectionFactory.checkConnection(props)) {
                                DBConfiguration.addDataSourceProperties(name, props);
                                logger.debug("SQL......");
                                DBUpdateThread thread = new DBUpdateThread(props);
                                ThreadFactory.run(thread);
                            }
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    logger.error(ex);
                } finally {
                    JdbcUtils.close(rs);
                    JdbcUtils.close(stmt);
                    JdbcUtils.close(conn);
                }
            }
        }
    }
}

From source file:controllers.base.SessionedAction.java

public static String getSessionKey(Context ctx) {
    if (ctx == null) {
        ctx = Validate.notNull(Context.current());
    }/*from   ww w.  ja  va2 s.c om*/

    String sessionId = null;

    // try to get the session id from the query string.
    String[] param = ctx.request().queryString().get("session");
    if (param != null && param.length > 0) {
        sessionId = param[0];
        WebSession session = getWebSession(sessionId);
        if (session == null || session.getStatus() != SessionStatus.IMMORTALIZED) {
            sessionId = null;
        }
    }

    // if not, try to get the session id from headers or cookies.
    if (StringUtils.isEmpty(sessionId)) {
        // decrypt it.
        sessionId = StringUtils.defaultString(StringUtils.defaultString(
                ctx.request().getHeader(SARE_SESSION_HEADER), ctx.session().get(SESSION_ID_KEY)));
        if (StringUtils.isNotEmpty(sessionId)) {
            try {
                sessionId = Crypto.decryptAES(sessionId);
            } catch (Throwable e) {
                sessionId = null;
            }
        }
    }

    return UuidUtils.isUuid(sessionId) ? sessionId : null;
}

From source file:com.glaf.activiti.extension.xml.ExtensionWriter.java

public Document write(List<ExtensionEntity> extensions) {
    Document doc = DocumentHelper.createDocument();
    if (extensions != null && extensions.size() > 0) {
        Element root = doc.addElement("bpm-cfg");
        Iterator<ExtensionEntity> iterator = extensions.iterator();
        while (iterator.hasNext()) {
            ExtensionEntity extension = iterator.next();
            if (root.attribute("type") == null && extension.getType() != null) {
                root.addAttribute("type", extension.getType());
            }/* www.  j av  a2  s  .c o  m*/
            if (StringUtils.isNotEmpty(extension.getTaskName())) {
                Element element = root.addElement("taskmgr");
                element.addAttribute("processName", extension.getProcessName());
                element.addAttribute("taskName", extension.getTaskName());
                if (extension.getFieldValue("taskMgmtType") != null) {
                    Element elem = element.addElement("taskMgmtType");
                    elem.setText(extension.getFieldValue("taskMgmtType"));
                }
                if (extension.getFieldValue("handlers") != null) {
                    Element elem = element.addElement("handlers");
                    elem.setText(extension.getFieldValue("handlers"));
                }
                if (extension.getFields() != null && extension.getFields().size() > 0) {
                    Element elem = element.addElement("properties");
                    Iterator<ExtensionFieldEntity> iter = extension.getFields().values().iterator();
                    while (iter.hasNext()) {
                        ExtensionFieldEntity field = iter.next();
                        Element e = elem.addElement("property");
                        e.addAttribute("key", field.getName());
                        e.addCDATA(field.getValue());
                    }
                }
            } else if (StringUtils.isNotEmpty(extension.getName())) {
                Element element = root.addElement("action");
                element.addAttribute("processName", extension.getProcessName());
                element.addAttribute("name", extension.getName());
                if (extension.getFieldValue("sql") != null) {
                    Element elem = element.addElement("sql");
                    elem.addCDATA(extension.getFieldValue("sql"));
                }
                if (extension.getFieldValue("handlers") != null) {
                    Element elem = element.addElement("handlers");
                    elem.setText(extension.getFieldValue("handlers"));
                }
                if (extension.getParams() != null && extension.getParams().size() > 0) {
                    Element em = element.addElement("parameters");
                    Iterator<ExtensionParamEntity> iter = extension.getParams().iterator();
                    while (iter.hasNext()) {
                        ExtensionParamEntity param = iter.next();
                        Element e = em.addElement("parameter");
                        e.addAttribute("name", param.getName());
                        e.addAttribute("type", param.getType());
                        e.addCDATA(param.getValue());
                    }
                }
            }
        }
    }
    return doc;
}