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

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

Introduction

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

Prototype

public static boolean contains(final CharSequence seq, final CharSequence searchSeq) 

Source Link

Document

Checks if CharSequence contains a search CharSequence, handling null .

Usage

From source file:com.yqboots.security.access.RoleHierarchyImpl.java

/**
 * Retrieves the hierarchy roles./*from   w  ww .  ja v  a2  s  . com*/
 *
 * @param role the granted authority
 * @return the roles from hierarchy
 */
protected Collection<? extends GrantedAuthority> retrieveHierarchyRoles(GrantedAuthority role) {
    final Set<GrantedAuthority> results = new HashSet<>();
    // /R001/R002/R003 ...
    String roleStr = role.getAuthority();

    if (StringUtils.startsWith(roleStr, "ROLE_") && StringUtils.contains(roleStr, "/")) {
        roleStr = StringUtils.substringAfter(roleStr, "ROLE_");
    }

    while (StringUtils.isNotBlank(roleStr)) {
        results.add(new SimpleGrantedAuthority(roleStr));
        if (!StringUtils.contains(roleStr, "/")) {
            break;
        }

        roleStr = StringUtils.substringBeforeLast(roleStr, "/");
    }

    return results;
}

From source file:com.thoughtworks.go.matchers.ConsoleOutMatcher.java

public static TypeSafeMatcher<String> printedBuildingInfo(final Object jobIdentifer) {
    return new TypeSafeMatcher<String>() {
        private String consoleOut;
        public String stdout;

        public boolean matchesSafely(String consoleOut) {
            this.consoleOut = consoleOut;
            stdout = format("Start to build %s", jobIdentifer.toString());
            return StringUtils.contains(consoleOut, stdout);
        }/*from ww  w.  j  av  a2s  .co m*/

        public void describeTo(Description description) {
            description.appendText("expected console to contain [" + stdout + "]" + " but was " + consoleOut);
        }
    };
}

From source file:com.feilong.core.lang.StringUtilTest.java

/**
 * Test contains.//from  w w  w.  jav  a 2  s .c  om
 */
@Test
public void testContains() {
    assertEquals(false, StringUtils.contains(null, ""));
    assertEquals(true, StringUtils.contains("", ""));
    assertEquals(true, StringUtils.contains("jiiiiiinxin.feilong", "xin"));
}

From source file:io.wcm.devops.conga.plugins.sling.fileheader.OsgiConfigFileHeaderTest.java

@Test
public void testApply() throws Exception {
    File file = new File("target/generation-test/fileHeader.config");
    FileUtils.write(file, "myscript", StandardCharsets.UTF_8);

    List<String> lines = ImmutableList.of("**********", "", "Der Jodelkaiser", "aus dem Oetztal",
            "ist wieder daheim.", "**********");
    FileHeaderContext context = new FileHeaderContext().commentLines(lines);

    FileContext fileContext = new FileContext().file(file);
    assertTrue(underTest.accepts(fileContext, context));
    underTest.apply(fileContext, context);

    assertTrue(StringUtils.contains(FileUtils.readFileToString(file, StandardCharsets.UTF_8),
            "# Der Jodelkaiser aus dem Oetztal ist wieder daheim."));

    FileHeaderContext extractContext = underTest.extract(fileContext);
    assertEquals(ImmutableList.of("Der Jodelkaiser aus dem Oetztal ist wieder daheim."),
            extractContext.getCommentLines());

    file.delete();/*w  w w. jav a 2 s  .c o m*/
}

From source file:io.netty.example.http.helloworld.HttpHelloWorldServer.java

private void doRun(EventLoopGroup bossGroup, EventLoopGroup workerGroup,
        Class<? extends ServerChannel> serverChannelClass) throws InterruptedException {
    try {/*from w  ww .jav a  2  s .  c  o m*/
        String os_arch = System.getProperty("os.arch");
        boolean isARM = StringUtils.contains(os_arch, "arm");

        ServerBootstrap b = new ServerBootstrap();

        if (isARM) {
            b.childOption(ChannelOption.ALLOCATOR, new UnpooledByteBufAllocator(false));
        } else {
            b.childOption(ChannelOption.ALLOCATOR, new PooledByteBufAllocator(true));
        }

        b.childOption(ChannelOption.MAX_MESSAGES_PER_READ, Integer.MAX_VALUE);
        b.childOption(ChannelOption.SO_REUSEADDR, true);
        b.option(ChannelOption.MAX_MESSAGES_PER_READ, Integer.MAX_VALUE);
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.option(ChannelOption.SO_REUSEADDR, true);

        b.group(bossGroup, workerGroup).channel(serverChannelClass)
                .childHandler(new HttpHelloWorldServerInitializer());

        Channel ch = b.bind(port).sync().channel();

        System.out.printf("Httpd started. Listening on: %s%n", ch.localAddress().toString());

        ch.closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:ch.cyberduck.ui.cocoa.controller.FileController.java

@Override
public boolean validate() {
    if (StringUtils.contains(inputField.stringValue(), Path.DELIMITER)) {
        return false;
    }/*ww w  . java2s  .c om*/
    if (StringUtils.isNotBlank(inputField.stringValue())) {
        if (cache.get(workdir)
                .contains(new Path(workdir, inputField.stringValue(), EnumSet.of(Path.Type.file)))) {
            return false;
        }
        if (cache.get(workdir)
                .contains(new Path(workdir, inputField.stringValue(), EnumSet.of(Path.Type.directory)))) {
            return false;
        }
        return true;
    }
    return false;
}

From source file:ch.cyberduck.core.AbstractExceptionMappingService.java

public BackgroundException map(final String message, final T failure, final Path file) {
    final BackgroundException exception = this.map(failure);
    final StringBuilder m = new StringBuilder();
    final String formatted = MessageFormat
            .format(StringUtils.chomp(LocaleFactory.localizedString(message, "Error")), file.getName());
    if (StringUtils.contains(formatted, String.format("%s ", file.getName()))
            || StringUtils.contains(formatted, String.format(" %s", file.getName()))) {
        this.append(m, formatted);
    } else {/*from   w  w  w .j a v  a2s .  com*/
        this.append(m,
                String.format("%s (%s)",
                        MessageFormat.format(StringUtils.chomp(LocaleFactory.localizedString(message, "Error")),
                                file.getName()),
                        file.getAbsolute()));
    }
    exception.setMessage(m.toString());
    exception.setFile(file);
    return exception;
}

From source file:com.gargoylesoftware.htmlunit.WebResponseDataTest.java

/**
 * Tests that gzipped content is handled correctly.
 * @throws Exception if the test fails//from w  ww.j a  v  a 2  s .c om
 */
@Test
public void gZippedContent() throws Exception {
    final InputStream stream = getClass().getClassLoader().getResourceAsStream(GZIPPED_FILE);
    final byte[] zippedContent = IOUtils.toByteArray(stream);

    final List<NameValuePair> headers = new ArrayList<>();
    headers.add(new NameValuePair("Content-Encoding", "gzip"));

    final WebResponseData data = new WebResponseData(zippedContent, HttpStatus.SC_OK, "OK", headers);
    final String body = new String(data.getBody(), "UTF-8");
    assertTrue(StringUtils.contains(body, "Test"));
}

From source file:com.haulmont.cuba.web.gui.components.table.AbbreviatedColumnGenerator.java

@Override
public Object generateCell(com.vaadin.v7.ui.Table source, Object itemId, Object columnId) {
    Property property = source.getItem(itemId).getItemProperty(columnId);
    Object value = property.getValue();

    if (value == null) {
        return null;
    }//from w w w.j  a  v a  2  s. c om

    String stringValue = value.toString();
    if (columnId instanceof MetaPropertyPath) {
        MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
        if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
            stringValue = dynamicAttributesTools.getDynamicAttributeValueAsString(metaProperty, value);
        }
    }
    String cellValue = stringValue;
    boolean isMultiLineCell = StringUtils.contains(stringValue, "\n");
    if (isMultiLineCell) {
        cellValue = StringUtils.replaceChars(cellValue, '\n', ' ');
    }

    int maxTextLength = column.getMaxTextLength();
    if (stringValue.length() > maxTextLength + MAX_TEXT_LENGTH_GAP || isMultiLineCell) {
        return StringUtils.abbreviate(cellValue, maxTextLength);
    } else {
        return cellValue;
    }
}

From source file:com.feilong.servlet.http.RequestUtilTemp.java

/**
 * ??,sendDirect #,???./*ww  w.j  a v  a 2  s .  c o m*/
 * 
 * @param request
 *            the request
 * @param paramName
 *            the param name
 * @return ??,sendDirect #,???
 * @deprecated ??
 */
@Deprecated
public static String getParameterWithoutSharp(HttpServletRequest request, String paramName) {
    String returnValue = RequestUtil.getParameter(request, paramName);
    if (isNotNullOrEmpty(returnValue)) {
        if (StringUtils.contains(returnValue, FRAGMENT)) {
            returnValue = substring(returnValue, null, FRAGMENT);
        }
    }
    return returnValue;
}