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.floreantpos.license.FiveStarPOSLicenseManager.java

/**
 * Get the template file based on command line arguments.
 * //w  w  w. jav a  2 s  .com
 * @param args
 * @return File
 */
private static File getTemplateFile(String[] args) {
    if (args != null) {
        String templateFileUri = null;
        for (String string : args) {
            if (StringUtils.contains(string, "-t=")) {
                templateFileUri = StringUtils.splitByWholeSeparatorPreserveAllTokens(string, "-t=")[1];
                break;
            }
        }
        if (StringUtils.isNotBlank(templateFileUri)) {
            return new File(templateFileUri);
        }
    }
    return new File(TEMPLATE_FILE);
}

From source file:ar.com.zauber.commons.web.filter.JSONPRequestFilter.java

/**
 * @param httpRequest/*from  w ww  .  j  a  va 2 s .c  om*/
 * @return true if this requests expects JSON, JSONP or JavaScript
 */
private boolean acceptsJSONP(final HttpServletRequest httpRequest) {
    final String accept = httpRequest.getHeader("Accept");

    if (StringUtils.isBlank(accept)) {
        return false;
    }

    for (String string : acceptedTypes) {
        if (StringUtils.contains(accept, string)) {
            return true;
        }
    }

    return false;
}

From source file:com.jnj.b2b.storefront.controllers.misc.StoreSessionController.java

protected String getReturnRedirectUrlForUrlEncoding(final HttpServletRequest request, final String old,
        final String current) {
    final String originalReferer = (String) request.getSession()
            .getAttribute(StorefrontFilter.ORIGINAL_REFERER);
    if (StringUtils.isNotBlank(originalReferer)) {
        return REDIRECT_PREFIX + StringUtils.replace(originalReferer, "/" + old + "/", "/" + current + "/");
    }//from   ww w.  j a  va 2 s .  com

    String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath());
    if (!StringUtils.endsWith(referer, "/")) {
        referer = referer + "/";
    }
    if (referer != null && !referer.isEmpty() && StringUtils.contains(referer, "/" + old)) {
        return REDIRECT_PREFIX + StringUtils.replace(referer, "/" + old, "/" + current);
    }
    return REDIRECT_PREFIX + referer;
}

From source file:com.att.aro.core.settings.impl.JvmSettings.java

@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
@Override/*from   w  w w.  ja va2  s  . c o m*/
public String setAttribute(String name, String value) {
    if (!StringUtils.equals("Xmx", name)) {
        throw new IllegalArgumentException("Not a valid property:" + name);
    }
    if (!NumberUtils.isNumber(value)) {
        throw new IllegalArgumentException(
                value + " is not a valid value for memory; Please enter an integer value.");
    }
    validateSize(Long.valueOf(value));
    Path path = Paths.get(CONFIG_FILE_PATH);
    List<String> values = Collections.emptyList();
    if (!path.toFile().exists()) {
        createConfig(CONFIG_FILE_PATH, Collections.singletonList("-Xmx" + value + "m"));
        return value;
    } else {
        try (Stream<String> lines = Files.lines(path)) {
            values = lines.filter((line) -> !StringUtils.contains(line, name)).collect(Collectors.toList());
            values.add(0, "-Xmx" + value + "m");
            FileUtils.deleteQuietly(path.toFile());
        } catch (IOException e) {
            String message = "Counldn't read vm options file";
            LOGGER.error(message, e);
            throw new ARORuntimeException(message, e);
        }
        createConfig(CONFIG_FILE_PATH, values);
    }
    return value;
}

From source file:edu.ku.brc.af.ui.ProcessListUtil.java

/**
 * Returns a list of the process ids that contain the provided text (like greping for text).
 * @param text the text to be search for
 * @return the list if ids/* w ww . ja  v a  2 s  . co  m*/
 */
public static List<Integer> getProcessIdWithText(final String... text) {
    ArrayList<Integer> ids = new ArrayList<Integer>();

    List<List<String>> processList = ProcessListUtil.getRunningProcesses();
    for (List<String> line : processList) {
        //System.out.println("["+line+"]");
        int found = 0;
        for (String field : line) {
            for (int i = 0; i < text.length; i++) {
                //System.out.println("CHK: ["+field.toLowerCase()+"]["+text[i].toLowerCase()+"]");
                if (StringUtils.contains(field.toLowerCase(), text[i].toLowerCase())) {
                    //System.out.print("FND: ["+field.toLowerCase()+"]["+text[i].toLowerCase()+"]");
                    found++;
                }
            }
        }

        //System.out.println("***: fnd["+found+"] toks["+text.length+"]");
        if (found == text.length) {
            ids.add(Integer.parseInt(line.get(1)));
        }
    }
    return ids;
}

From source file:de.hybris.platform.ytelcoacceleratorstorefront.filters.cms.CMSSiteFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse,
        final FilterChain filterChain) throws ServletException, IOException {
    final String requestURL = httpRequest.getRequestURL().toString();

    final CmsPageRequestContextData cmsPageRequestContextData = getCmsPageContextService()
            .initialiseCmsPageContextForRequest(httpRequest);

    //check whether exits valid preview data
    if (cmsPageRequestContextData.getPreviewData() == null) {
        //process normal request (i.e. normal browser non-cmscockpit request)
        if (processNormalRequest(httpRequest, httpResponse)) {
            //proceed filters
            filterChain.doFilter(httpRequest, httpResponse);
        }/*from   w ww. j  a v a  2 s .co  m*/
    } else if (StringUtils.contains(requestURL, PREVIEW_TOKEN)) {
        final String redirectURL = processPreviewRequest(httpRequest, cmsPageRequestContextData);

        //redirect to computed URL
        if (redirectURL.charAt(0) == '/') {
            final String contextPath = httpRequest.getContextPath();
            final String encodedRedirectUrl = httpResponse.encodeRedirectURL(contextPath + redirectURL);
            httpResponse.sendRedirect(encodedRedirectUrl);
        } else {
            final String encodedRedirectUrl = httpResponse.encodeRedirectURL(redirectURL);
            httpResponse.sendRedirect(encodedRedirectUrl);
        }

        //next filter in chain won't be invoked!!!
    } else {
        //proceed filters
        filterChain.doFilter(httpRequest, httpResponse);
    }
}

From source file:it.govpay.web.filters.SessionTimeoutFilter.java

/**
 * /*from   w ww.  j  a  v a  2 s  . co m*/
 * session shouldn't be checked for some pages. For example: for timeout page..
 * Since we're redirecting to timeout page from this filter,
 * if we don't disable session control for it, filter will again redirect to it
 * and this will be result with an infinite loop... 
 */
private boolean isSessionControlRequiredForThisResource(HttpServletRequest httpServletRequest) {
    String requestPath = httpServletRequest.getRequestURI();

    boolean controlRequired = false;
    if (StringUtils.contains(requestPath, this.loginErrorPage)
            || StringUtils.contains(requestPath, this.loginPage)) {
        controlRequired = false;
    } else {
        if (this.excludedPages.size() > 0)
            for (String page : this.excludedPages) {
                if (StringUtils.contains(requestPath, page)) {
                    controlRequired = false;
                    break;
                }
            }
        else
            controlRequired = true;
    }

    return controlRequired;
}

From source file:cec.easyshop.storefront.filters.cms.CMSSiteFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse,
        final FilterChain filterChain) throws ServletException, IOException {
    final String requestURL = httpRequest.getRequestURL().toString();

    final CmsPageRequestContextData cmsPageRequestContextData = getCmsPageContextService()
            .initialiseCmsPageContextForRequest(httpRequest);

    // check whether exits valid preview data
    if (cmsPageRequestContextData.getPreviewData() == null) {
        // process normal request (i.e. normal browser non-cmscockpit request)
        if (processNormalRequest(httpRequest, httpResponse)) {
            // proceed filters
            filterChain.doFilter(httpRequest, httpResponse);
        }//from ww w  . j a v a  2 s . c  om
    } else if (StringUtils.contains(requestURL, PREVIEW_TOKEN)) {
        final String redirectURL = processPreviewRequest(httpRequest, cmsPageRequestContextData);

        // redirect to computed URL
        if (redirectURL.charAt(0) == '/') {
            final String contextPath = httpRequest.getContextPath();
            final String encodedRedirectUrl = httpResponse.encodeRedirectURL(contextPath + redirectURL);
            httpResponse.sendRedirect(encodedRedirectUrl);
        } else {
            final String encodedRedirectUrl = httpResponse.encodeRedirectURL(redirectURL);
            httpResponse.sendRedirect(encodedRedirectUrl);
        }

        // next filter in chain won't be invoked!!!
    } else {
        // proceed filters
        filterChain.doFilter(httpRequest, httpResponse);
    }
}

From source file:com.widen.valet.importer.ImportZone.java

private List<ZoneUpdateAction> createZoneUpdateActions(Zone zone) throws IOException {
    List<String> lines = IOUtils.readLines(new FileInputStream(importFile));

    boolean foundZoneRecords = false;

    List<ZoneUpdateAction> actions = new ArrayList<ZoneUpdateAction>();

    for (String l : lines) {
        if (!foundZoneRecords) {
            if (StringUtils.contains(l, ";  Zone records")) {
                foundZoneRecords = true;
            }/*  ww  w . jav  a2s  .  c o  m*/

            continue;
        }

        if (StringUtils.isNotBlank(l) && !l.startsWith(";")) {
            log.debug("processing line: {}", l);

            List<ZoneUpdateAction> actionForRecord = parseRecord(l, zone.name, actions);

            actions.addAll(actionForRecord);
        }
    }

    return actions;
}

From source file:info.magnolia.importexport.DataTransporterTest.java

@Test
public void testRemoveNs() throws Exception {
    InputStream input = getClass().getResourceAsStream("/test-unwantedns.xml");
    File outputFile = File.createTempFile("export-test-", ".xml");
    OutputStream outputStream = new FileOutputStream(outputFile);

    XMLReader reader = XMLReaderFactory.createXMLReader(org.apache.xerces.parsers.SAXParser.class.getName());

    DataTransporter.readFormatted(reader, input, outputStream);

    IOUtils.closeQuietly(outputStream);/*from   w w w.  j  a  v  a  2 s.  co  m*/

    String result = FileUtils.readFileToString(outputFile);
    outputFile.delete();

    assertFalse("'removeme' namespace still found in output file",
            StringUtils.contains(result, "xmlns:removeme"));
    assertTrue("'sv' namespace not found in output file", StringUtils.contains(result, "xmlns:sv"));
    assertTrue("'xsi' namespace not found in output file", StringUtils.contains(result, "xmlns:xsi"));
}