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.dp2345.interceptor.ListInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    if (modelAndView != null && modelAndView.isReference()) {
        String viewName = modelAndView.getViewName();
        if (StringUtils.startsWith(viewName, REDIRECT_VIEW_NAME_PREFIX)) {
            String listQuery = WebUtils.getCookie(request, LIST_QUERY_COOKIE_NAME);
            if (StringUtils.isNotEmpty(listQuery)) {
                if (StringUtils.startsWith(listQuery, "?")) {
                    listQuery = listQuery.substring(1);
                }//from w w w.j a va  2  s .c om
                if (StringUtils.contains(viewName, "?")) {
                    modelAndView.setViewName(viewName + "&" + listQuery);
                } else {
                    modelAndView.setViewName(viewName + "?" + listQuery);
                }
                WebUtils.removeCookie(request, response, LIST_QUERY_COOKIE_NAME);
            }
        }
    }
}

From source file:cn.cuizuoli.gotour.utils.HtmlHelper.java

/**
 * toTable//from   w w w .j a  v  a 2  s. c  o  m
 * @param text
 * @return
 */
public static String toTable(String text) {
    String[] lines = StringUtils.split(text, "\r\n");
    StringBuffer tableBuffer = new StringBuffer();
    for (String line : lines) {
        Matcher tileMatcher = TITLE_PATTERN.matcher(line);
        if (tileMatcher.matches()) {
            String h4 = new StringBuffer().append("<h4>").append(tileMatcher.group(1)).append("</h4>")
                    .append("\n").append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">")
                    .append("\n").toString();
            tableBuffer.append(h4);
        }
        Matcher tableMatcher = TABLE_PATTERN.matcher(line);
        if (tableMatcher.matches()) {
            String tr = new StringBuffer().append("<tr>").append("\n").append("<th>")
                    .append(tableMatcher.group(1)).append("</th>").append("\n").append("<td>")
                    .append(tableMatcher.group(2)).append("</td>").append("\n").append("</tr>").append("\n")
                    .toString();
            tableBuffer.append(tr);
        }
    }
    tableBuffer.append("</table>\n");
    String table = tableBuffer.toString();
    table = StringUtils.replace(table, "<h4>", "</table>\n<h4>");
    table = StringUtils.replaceOnce(table, "</table>\n<h4>", "<h4>");
    if (!StringUtils.contains(table, "<table")) {
        table = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n" + table;
    }
    return table;
}

From source file:eu.europeana.corelib.search.utils.SearchUtils.java

/**
 * Checks if there is no TYPE facet with an invalid type according to EDM
 *
 *
 * @param refinements/*from  w ww  . j a v  a  2  s  . c o  m*/
 * @return Returns true if there is no TYPE facet or each type facet has
 *         valid value
 */
public static boolean checkTypeFacet(String[] refinements) {
    if (refinements != null) {
        for (String refinement : refinements) {
            if (StringUtils.contains(refinement, "TYPE:") && !StringUtils.contains(refinement, " OR ")) {
                if (DocType.safeValueOf(StringUtils.substringAfter(refinement, "TYPE:")) == null) {
                    return false;
                }
            }
        }
    }
    return true;
}

From source file:gemlite.shell.converters.JobStatusConverter.java

@Override
public boolean supports(Class<?> type, String optionContext) {
    return (String.class.equals(type)) && (StringUtils.contains(optionContext, "param.context.job.status"));
}

From source file:com.edgenius.wiki.render.MarkupUtil.java

/**
 * Markup token has odd number leading slash "\", then convert this markup to <em>HTML entity</em>.
 * @param input/* w  ww  . j  a va  2 s.com*/
 * @return
 */
public static String escapeMarkupToEntity(String input) {
    if (input == null)
        return null;
    int len = input.length();
    StringBuffer sb = new StringBuffer();
    int slash = 0;
    int currLen;
    boolean odd;
    for (int idx = 0; idx < len; idx++) {
        char c = input.charAt(idx);
        if (c == '\\') {
            slash++;
            sb.append(c);
            continue;
        }

        odd = processDoubleSlash(sb, slash);

        //even ">" is not filter pattern keyword, but it use in markup link.
        // For example[view has \\> char>link],here must escape \> to entity, then in LinkFilter could correctly convert \&#(int >); 
        // to  ">", as it will call unescapeMarkupLink() to remove another "\" 
        if (StringUtils.contains(FilterRegxConstants.FILTER_KEYWORD + ">", c) && odd) {
            currLen = sb.length();
            sb.deleteCharAt(currLen - 1);
            //delete last slash
            sb.append(EscapeUtil.toEntity(c));
        } else
            sb.append(c);

        slash = 0;
    }

    //string end by some amount "\"
    if (slash > 0) {
        odd = processDoubleSlash(sb, slash);
        //TDB:  how to handle last single "\"  to entity?
        if (odd) {
            currLen = sb.length();
            sb.deleteCharAt(currLen - 1);
            //delete last slash
            sb.append(ENTITY_SLASH);
        }
    }
    return sb.toString();
}

From source file:net.sf.iqser.plugin.file.parser.pdf.PdfFileParserTest.java

public void testGetContent() throws Exception {
    PdfFileParser parser = new PdfFileParser();
    FileInputStream is = new FileInputStream(
            new File(System.getProperty("testdata.dir", "../file-parser/testdata") + "/ZimbraCommunity.pdf"));
    Content content = parser.getContent("ZimbraCommunity.pdf", is);

    assertNotNull(content);/* w  ww  .j av a2 s  . co  m*/
    assertEquals("PDF Document", content.getType());

    assertNotNull(content.getAttributeByName("FILENAME"));
    assertEquals("ZimbraCommunity.pdf", content.getAttributeByName("FILENAME").getValue());
    assertFalse(content.getAttributeByName("FILENAME").isKey());

    assertNotNull(content.getAttributeByName("TITLE"));
    assertEquals("Zimbra - Community", content.getAttributeByName("TITLE").getValue());
    assertTrue(content.getAttributeByName("TITLE").isKey());

    assertNotNull(content.getAttributeByName("AUTHOR"));
    assertEquals("christian.magnus", content.getAttributeByName("AUTHOR").getValue());
    assertTrue(content.getAttributeByName("AUTHOR").isKey());

    assertNotNull(content.getAttributeByName("CREATIONDATE"));
    assertNotNull(content.getAttributeByName("CREATIONDATE").getValue());
    assertTrue(content.getAttributeByName("CREATIONDATE").isKey());

    assertNotNull(content.getFulltext());
    assertTrue(StringUtils.contains(content.getFulltext(),
            "The Zimbra Collaboration Suite is generally licensed under the terms"));
}

From source file:edu.sampleu.demo.kitchensink.UITestPropertyEditor.java

/**
 * @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
 *//*www  .ja  v a  2 s.co m*/
@Override
public void setAsText(String text) {
    String value = text;
    if (StringUtils.contains(value, "-")) {
        value = StringUtils.replaceOnce(value, "-", "");
    }

    this.setValue(value);
}

From source file:com.adobe.acs.commons.users.impl.AbstractAuthorizable.java

public AbstractAuthorizable(Map<String, Object> config) throws EnsureAuthorizableException {
    String tmp = PropertiesUtil.toString(config.get(EnsureServiceUser.PROP_PRINCIPAL_NAME), null);

    if (StringUtils.contains(tmp, "/")) {
        tmp = StringUtils.removeStart(tmp, getDefaultPath());
        tmp = StringUtils.removeStart(tmp, "/");
        this.principalName = StringUtils.substringAfterLast(tmp, "/");
        this.intermediatePath = PathUtil.makePath(getDefaultPath(),
                StringUtils.removeEnd(tmp, this.principalName));
    } else {//w  ww.j a v  a2  s. c om
        this.principalName = tmp;
        this.intermediatePath = getDefaultPath();
    }

    // Check the principal name for validity
    if (StringUtils.isBlank(this.principalName)) {
        throw new EnsureAuthorizableException("No Principal Name provided to Ensure Service User");
    } else if (ProtectedAuthorizables.isProtected(this.principalName)) {
        throw new EnsureAuthorizableException(String.format(
                "[ %s ] is an System User provided by AEM or ACS AEM Commons. You cannot ensure this user.",
                this.principalName));
    }

    final String[] acesProperty = PropertiesUtil.toStringArray(config.get(EnsureServiceUser.PROP_ACES),
            new String[0]);
    for (String entry : acesProperty) {
        if (StringUtils.isNotBlank(entry)) {
            try {
                aces.add(new Ace(entry));
            } catch (EnsureAuthorizableException e) {
                log.warn("Malformed ACE config [ " + entry + " ] for Service User [ "
                        + StringUtils.defaultIfEmpty(this.principalName, "NOT PROVIDED") + " ]", e);
            }
        }
    }
}

From source file:cn.fastmc.core.jpa.specification.Specifications.java

/**
 * ???/*from   w ww  .ja v  a2 s.  co m*/
 * 
 * @param propertyName ??
 * @param root Query roots always reference entities
 * 
 * @return {@link Path}
 */
public static Path<?> getPath(String propertyName, Root<?> root) {

    Path<?> path = null;

    if (StringUtils.contains(propertyName, ".")) {
        String[] propertys = StringUtils.splitByWholeSeparator(propertyName, ".");
        path = root.get(propertys[0]);
        for (int i = 1; i < propertys.length; i++) {
            path = path.get(propertys[i]);
        }
    } else {
        path = root.get(propertyName);
    }

    return path;
}

From source file:com.adobe.acs.commons.users.impl.ServiceUser.java

public ServiceUser(Map<String, Object> config) throws EnsureServiceUserException {
    String tmp = PropertiesUtil.toString(config.get(EnsureServiceUser.PROP_PRINCIPAL_NAME), null);

    if (StringUtils.contains(tmp, "/")) {
        tmp = StringUtils.removeStart(tmp, PATH_SYSTEM_USERS);
        tmp = StringUtils.removeStart(tmp, "/");
        this.principalName = StringUtils.substringAfterLast(tmp, "/");
        this.intermediatePath = PathUtil.makePath(PATH_SYSTEM_USERS,
                StringUtils.removeEnd(tmp, this.principalName));
    } else {/* www . j a  v  a2s  . c  o  m*/
        this.principalName = tmp;
        this.intermediatePath = "/home/users/system";
    }

    // Check the principal name for validity
    if (StringUtils.isBlank(this.principalName)) {
        throw new EnsureServiceUserException("No Principal Name provided to Ensure Service User");
    } else if (ProtectedSystemUsers.isProtected(this.principalName)) {
        throw new EnsureServiceUserException(String.format(
                "[ %s ] is an System User provided by AEM or ACS AEM Commons. You cannot ensure this user.",
                this.principalName));
    }

    final String[] acesProperty = PropertiesUtil.toStringArray(config.get(EnsureServiceUser.PROP_ACES),
            new String[0]);
    for (String entry : acesProperty) {
        try {
            aces.add(new Ace(entry));
        } catch (EnsureServiceUserException e) {
            log.warn("Malformed ACE config [ " + entry + " ] for Service User [ "
                    + StringUtils.defaultIfEmpty(this.principalName, "NOT PROVIDED") + " ]", e);
        }
    }
}