Example usage for org.apache.commons.lang StringUtils contains

List of usage examples for org.apache.commons.lang StringUtils contains

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils contains.

Prototype

public static boolean contains(String str, String searchStr) 

Source Link

Document

Checks if String contains a search String, handling null.

Usage

From source file:com.haulmont.cuba.web.log.AppLog.java

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public void log(ErrorEvent event) {
    Throwable t = event.getThrowable();

    if (t instanceof SilentException)
        return;// w  w w  .  j  a  v  a 2s . c  o  m

    if (t instanceof Validator.InvalidValueException)
        return;

    if (t instanceof SocketException || ExceptionUtils.getRootCause(t) instanceof SocketException) {
        // Most likely client browser closed socket
        LogItem item = new LogItem(LogLevel.WARNING,
                "SocketException in CommunicationManager. Most likely client (browser) closed socket.", null);
        log(item);
        return;
    }

    // Support Tomcat 8 ClientAbortException
    if (StringUtils.contains(ExceptionUtils.getMessage(t), "ClientAbortException")) {
        // Most likely client browser closed socket
        LogItem item = new LogItem(LogLevel.WARNING,
                "ClientAbortException on write response to client. Most likely client (browser) closed socket.",
                null);
        log(item);
        return;
    }

    Throwable rootCause = ExceptionUtils.getRootCause(t);
    if (rootCause == null)
        rootCause = t;
    Logging annotation = rootCause.getClass().getAnnotation(Logging.class);
    Logging.Type loggingType = annotation == null ? Logging.Type.FULL : annotation.value();
    if (loggingType == Logging.Type.NONE)
        return;

    // Finds the original source of the error/exception
    AbstractComponent component = DefaultErrorHandler.findAbstractComponent(event);

    StringBuilder msg = new StringBuilder();
    msg.append("Exception");
    if (component != null)
        msg.append(" in ").append(component.getClass().getName());
    msg.append(": ");

    if (loggingType == Logging.Type.BRIEF) {
        error(msg + rootCause.toString());
    } else {
        LogItem item = new LogItem(LogLevel.ERROR, msg.toString(), t);
        log(item);
    }
}

From source file:com.ms.app.web.commons.valve.BaseWebUserBuilderValve.java

protected PipelineResult getToLogin(HttpServletRequest request) {
    String url = loginUrl;/* www. j  ava  2s .  c  om*/
    String uri = request.getRequestURI();
    // ????returnurl
    if (request.getParameterMap().isEmpty() && !StringUtils.contains("/login", uri)) {
        url = loginUrl + "?returnurl=" + uri;
    }
    return PipelineResult.gotoFinally("gotoLogin", url);
}

From source file:gemlite.core.util.CmdUtils.java

/**
     * (;/*ww  w  .  j a  va 2  s .  c o  m*/
    bgL}
     * @param cmd
     * @return
     * @throws IOException
     * @throws Exception
     */
    public static String exeCmd(String cmd) throws IOException, Exception {
        //,eMn
        ConfigService service = JpaContext.getService(ConfigService.class);
        Map<String, String> map = service.getConfig(ConfigTypes.clusterconfig.getValue());
        //0:hh;:h
        String cluster_primaryip = map.get(ConfigKeys.cluster_primaryip.getValue());
        String username = map.get(ConfigKeys.cluster_username.getValue());
        String password = map.get(ConfigKeys.cluster_userpsw.getValue());
        password = DESUtil.decrypt(password);
        Connection conn = new Connection(cluster_primaryip);
        Session sess = null;
        StringBuilder sb = new StringBuilder();
        try {
            conn.connect();
            boolean isAuthenticated = conn.authenticateWithPassword(username, password);
            if (isAuthenticated == false)
                throw new IOException("Authentication failed.");
            sess = conn.openSession();
            sess.execCommand(cmd);
            InputStream stdout = sess.getStdout();
            BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
            String line = br.readLine();
            if (!StringUtils.contains(cmd, "&"))
                while (true) {
                    if (line == null)
                        break;
                    sb.append(line);
                    line = br.readLine();
                }
        } catch (IOException e) {
            throw e;
        } catch (Exception e) {
            throw e;
        } finally {
            sess.close();
            conn.close();
        }
        return sb.toString();
    }

From source file:com.iisigroup.cap.component.impl.ByteArrayDownloadResult.java

@Override
public void respondResult(ServletResponse response) {
    int length = -1;
    InputStream in = null;//from   ww w  . j  av a2  s .c  om
    OutputStream output = null;
    try {
        response.setContentType(getContentType());
        response.setContentLength(_byteArray.length);
        if (getOutputName() != null && response instanceof HttpServletResponse) {
            HttpServletResponse resp = (HttpServletResponse) response;
            HttpServletRequest req = (HttpServletRequest) _request.getServletRequest();
            String userAgent = req.getHeader("USER-AGENT");
            if (StringUtils.contains(userAgent, "MSIE")) {
                resp.setHeader("Content-Disposition", "attachment; filename=\"" + _outputName + "\"");
            } else {
                resp.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + _outputName);
            }
            resp.setHeader("Cache-Control", "public");
            resp.setHeader("Pragma", "public");
        }
        output = response.getOutputStream();
        // Stream to the requester.
        byte[] bbuf = new byte[1024 * 1024];

        in = new ByteArrayInputStream(_byteArray);
        while ((in != null) && ((length = in.read(bbuf)) != -1)) {
            output.write(bbuf, 0, length);
        }
        output.flush();
    } catch (IOException e) {
        e.getMessage();
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(output);
    }
}

From source file:hydrograph.ui.communication.utilities.SCPUtility.java

private Message getErrorMessage(Exception e) {
    if (StringUtils.contains(e.getMessage(), UNKNOWN_HOST_EXCEPTION)) {
        return new Message(MessageType.UNKNOWN_HOST, UNKNOWN_HOST_MESSAGE);
    } else if (StringUtils.contains(e.getMessage(), AUTH_FAIL_EXCEPTION)) {
        return new Message(MessageType.INVALID_USERNAME_PASSWORD, AUTHENTICATION_FAILED_MESSAGE);
    } else {//w w w . ja va  2  s  .  c o  m
        return new Message(MessageType.ERROR, GENERAL_ERROR_MESSAGE);
    }
}

From source file:com.hangum.tadpole.engine.sql.util.sqlscripts.scripts.PostgreSQLDDLScript.java

@Override
public String getTableScript(TableDAO tableDAO) throws Exception {
    SqlMapClient client = TadpoleSQLManager.getInstance(userDB);
    List<HashMap> srcList = client.queryForList("getTableScript", tableDAO.getName());

    StringBuilder result = new StringBuilder("");
    //      result.append("/* DROP TABLE " + tableDAO.getName() + " ; */ \n\n");
    result.append("CREATE TABLE " + tableDAO.getName() + "( \n");
    for (int i = 0; i < srcList.size(); i++) {
        HashMap<String, Object> source = srcList.get(i);

        result.append("\t");
        if (i > 0)
            result.append(",");
        result.append(source.get("column_name")).append(" ");
        result.append(source.get("data_type"));

        if (source.get("data_precision") != null && ((Integer) source.get("data_precision") > 0)) {
            result.append("(" + source.get("data_precision"));
            if (source.get("data_scale") != null && ((Integer) source.get("data_scale") > 0)) {
                result.append("," + source.get("data_scale"));
            }//w w w  . ja  v a2 s  .  co  m

            result.append(")");
        } else if ((Integer) source.get("data_length") > 0) {
            result.append("(" + source.get("data_length") + ")");
        } else {
            result.append(" ");
        }

        if (source.get("data_default") != null && !"".equals(source.get("data_default"))) {
            if (StringUtils.contains((String) source.get("data_type"), "text")) {
                result.append(" DEFAULT '" + source.get("data_default") + "'");
            } else {
                result.append(" DEFAULT " + source.get("data_default"));
            }
        }

        if (!"NULL".equals(source.get("nullable"))) {
            result.append(" NOT NULL ");
        }
        result.append("\n");
    }

    // primary key 
    List<HashMap> srcPkList = client.queryForList("getTableScript.pk", tableDAO.getName());
    for (int i = 0; i < srcPkList.size(); i++) {
        HashMap<String, Object> source = srcPkList.get(i);
        if (i == 0) {
            result.append("\t,CONSTRAINT ").append(source.get("constraint_name")).append(" PRIMARY KEY ( ")
                    .append(source.get("column_name"));
        } else {
            result.append(", " + source.get("column_name"));
        }

        if (i == srcPkList.size() - 1) {
            result.append(") \n");
        }
    }

    result.append(");\n");

    // table, column comments
    result.append("\n\n");
    List<String> srcCommentList = client.queryForList("getTableScript.comments", tableDAO.getName());
    String commentStr = "";
    if (srcCommentList.size() == 0) {
        result.append("COMMENT ON TABLE " + tableDAO.getName() + " is ''; /* table comment is empty.*/\n");
        result.append("COMMENT ON COLUMN " + tableDAO.getName()
                + ".[column name] is ''; /* column comment is empty.*/\n");
    }
    for (int i = 0; i < srcCommentList.size(); i++) {
        commentStr = srcCommentList.get(i);
        if (!"".equals(commentStr)) {
            result.append(srcCommentList.get(i) + ";\n");
        }
    }

    // foreign key

    // column constraint (? ?  )

    // partition table define

    // storage option

    // iot_type table define

    // table grant

    // table trigger
    result.append("\n\n");
    List<String> srcTriggerScripts = client.queryForList("getTableScript.trigger", tableDAO.getName());
    String scriptSource = "";
    for (int i = 0; i < srcTriggerScripts.size(); i++) {
        scriptSource = srcTriggerScripts.get(i);
        if (!"".equals(scriptSource)) {
            result.append(srcTriggerScripts.get(i) + ";\n");
        }
    }

    // table synonyms

    return result.toString();
}

From source file:com.backelite.sonarqube.commons.surefire.SurefireStaxHandler.java

private static String getTestCaseName(SMInputCursor testCaseCursor) throws XMLStreamException {
    String classname = testCaseCursor.getAttrValue("classname");
    String name = testCaseCursor.getAttrValue("name");
    if (StringUtils.contains(classname, "$")) {
        return StringUtils.substringAfter(classname, "$") + "/" + name;
    }/*from   w w w. j a  v a2 s.c  o m*/
    return name;
}

From source file:com.exxonmobile.ace.hybris.storefront.controllers.misc.StoreSessionController.java

protected String getReturnRedirectUrlForUrlEncoding(final HttpServletRequest request, final String old,
        final String current) {
    final String referer = request.getHeader("Referer");
    if (referer != null && !referer.isEmpty() && StringUtils.contains(referer, "/" + old)) {
        return REDIRECT_PREFIX + StringUtils.replace(referer, "/" + old, "/" + current);
    }//from  www.jav  a2 s .c  om
    return REDIRECT_PREFIX + '/';
}

From source file:edu.ku.brc.af.core.db.AutoNumberGeneric.java

public void setProperties(final Properties properties) {
    String className = properties.getProperty("class"); //$NON-NLS-1$
    if (StringUtils.isNotEmpty(className)) {
        isGeneric = StringUtils.contains(className, "Generic"); //$NON-NLS-1$

        DBTableInfo tblInfo = DBTableIdMgr.getInstance().getByClassName(className);
        if (tblInfo != null) {
            classObj = tblInfo.getClassObj();
            fieldName = properties.getProperty("field"); //$NON-NLS-1$
        } else {//from   w w w .  j  a v  a2  s .c om
            throw new RuntimeException("Class property [" + className + "] was not found."); //$NON-NLS-1$ //$NON-NLS-2$
        }
    } else {
        throw new RuntimeException("Class property was null/empty."); //$NON-NLS-1$
    }
}

From source file:edu.ku.brc.specify.toycode.L18NStringResApp.java

/**
 * @param inputText//from  w ww  . j a  v  a  2 s. c o  m
 */
protected String translate(final String inputText) {
    if (inputText.isEmpty())
        return "";
    //System.out.println("\n"+inputText);

    Translate.setHttpReferrer("http://www.specifysoftware.org");

    try {
        String text = inputText;

        boolean hasSpecialChars = false;
        while (StringUtils.contains(text, "%d") || StringUtils.contains(text, "%s")
                || StringUtils.contains(text, "\\n")) {
            text = StringUtils.replace(text, "%d", "99");
            text = StringUtils.replace(text, "%s", "88");
            text = StringUtils.replace(text, "\\n", " 77 ");
            hasSpecialChars = true;
        }

        Language lang = getLangFromCode(destLocale.getLanguage());
        //System.out.println(text);
        String newText = Translate.execute(text, Language.ENGLISH, lang);

        if (hasSpecialChars) {
            while (StringUtils.contains(newText, "77") || StringUtils.contains(newText, "88")
                    || StringUtils.contains(newText, "99")) {
                newText = StringUtils.replace(newText, "99", "%d");
                newText = StringUtils.replace(newText, "88", "%s");
                newText = StringUtils.replace(newText, " 77 ", " \\n ");
                newText = StringUtils.replace(newText, "77 ", "\\n ");
                newText = StringUtils.replace(newText, " 77", " \\n");
            }
        }
        //System.out.println(newText);
        return newText;

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}