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

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

Introduction

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

Prototype

public static String substring(final String str, int start) 

Source Link

Document

Gets a substring from the specified String avoiding exceptions.

A negative start position can be used to start n characters from the end of the String.

A null String will return null .

Usage

From source file:jenkins.plugins.asqatasun.ProjectAsqatasunAction.java

private String doBuildAuditResultUrl(String line, String webappUrl) {
    String auditId = StringUtils.substring(line, StringUtils.indexOf(line, ":") + 1).trim();
    if (StringUtils.endsWith(webappUrl, "/")) {
        return webappUrl + URL_PREFIX_RESULT + auditId;
    } else {//from  ww  w.ja  va  2 s.  c  om
        return webappUrl + "/" + URL_PREFIX_RESULT + auditId;
    }
}

From source file:com.vwf5.base.utils.DataUtil.java

/**
 * Lower first characater// w w  w .  j av  a 2 s  .  c o m
 *
 * @param input
 * @return
 */
public static String lowerFirstChar(String input) {
    if (StringUtils.isBlank(input)) {
        return input;
    }
    return input.substring(0, 1).toLowerCase() + StringUtils.substring(input, 1);
}

From source file:ch.cyberduck.core.s3.S3SearchFeatureTest.java

@Test
public void testSearchInBucket() throws Exception {
    final S3Session session = new S3Session(new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(),
            new Credentials(System.getProperties().getProperty("s3.key"),
                    System.getProperties().getProperty("s3.secret"))));
    final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(),
            new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    service.connect(session, PathCache.empty(), new DisabledCancelCallback());
    final String name = new AlphanumericRandomStringService().random();
    final Path bucket = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new S3TouchFeature(session).touch(new Path(bucket, name, EnumSet.of(Path.Type.file)),
            new TransferStatus());
    final S3SearchFeature feature = new S3SearchFeature(session);
    assertNotNull(feature.search(bucket, new SearchFilter(name), new DisabledListProgressListener())
            .find(new SimplePathPredicate(file)));
    assertNotNull(feature.search(bucket, new SearchFilter(StringUtils.substring(name, 2)),
            new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    assertNotNull(feature.search(bucket, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    final Path subdir = new Path(bucket, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.directory));
    assertNull(feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener())
            .find(new SimplePathPredicate(file)));
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();//ww  w  .j a v a 2  s. c  o m
}

From source file:ch.cyberduck.core.b2.B2SearchFeatureTest.java

@Test
public void testSearchInBucket() throws Exception {
    final B2Session session = new B2Session(new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
            new Credentials(System.getProperties().getProperty("b2.user"),
                    System.getProperties().getProperty("b2.key"))));
    final LoginConnectionService service = new LoginConnectionService(new DisabledLoginCallback(),
            new DisabledHostKeyCallback(), new DisabledPasswordStore(), new DisabledProgressListener());
    service.connect(session, PathCache.empty(), new DisabledCancelCallback());
    final String name = new AlphanumericRandomStringService().random();
    final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new B2TouchFeature(session).touch(new Path(bucket, name, EnumSet.of(Path.Type.file)),
            new TransferStatus());
    final B2SearchFeature feature = new B2SearchFeature(session);
    assertNotNull(feature.search(bucket, new SearchFilter(name), new DisabledListProgressListener())
            .find(new SimplePathPredicate(file)));
    // Supports prefix matching only
    assertNull(feature.search(bucket, new SearchFilter(StringUtils.substring(name, 2)),
            new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    assertNotNull(feature.search(bucket, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener()).find(new SimplePathPredicate(file)));
    final Path subdir = new Path(bucket, new AlphanumericRandomStringService().random(),
            EnumSet.of(Path.Type.directory));
    assertNull(feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener())
            .find(new SimplePathPredicate(file)));
    new B2DeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
    session.close();//from  w w w .jav a  2s .c om
}

From source file:ch.cyberduck.core.sds.SDSSearchFeatureTest.java

@Test
public void testSearch() throws Exception {
    final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials(
            System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key")));
    final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final String name = new AlphanumericRandomStringService().random();
    final Path room = new SDSDirectoryFeature(session)
            .mkdir(new Path(new AlphanumericRandomStringService().random(),
                    EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus());
    final Path directory = new SDSDirectoryFeature(session).mkdir(
            new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)),
            null, new TransferStatus());
    final Path file = new SDSTouchFeature(session).touch(new Path(directory, name, EnumSet.of(Path.Type.file)),
            new TransferStatus());
    final SDSSearchFeature feature = new SDSSearchFeature(session);
    assertTrue(feature.search(room, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    assertTrue(feature//from w ww  .j a  v a 2  s .  co  m
            .search(room, new SearchFilter(StringUtils.substring(name, 2)), new DisabledListProgressListener())
            .contains(file));
    assertTrue(feature.search(room, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener()).contains(file));
    assertTrue(feature.search(directory, new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener()).contains(file));
    try {
        assertFalse(feature.search(
                new Path(room, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)),
                new SearchFilter(name), new DisabledListProgressListener()).contains(file));
        fail();
    } catch (NotfoundException e) {
        //
    }
    final Path subdir = new SDSDirectoryFeature(session).mkdir(new Path(directory,
            new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), null,
            new TransferStatus());
    assertNull(feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener())
            .find(new SimplePathPredicate(file)));
    final Path filesubdir = new SDSTouchFeature(session).touch(
            new Path(subdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)),
            new TransferStatus());
    {
        final AttributedList<Path> result = feature.search(directory, new SearchFilter(filesubdir.getName()),
                new DisabledListProgressListener());
        assertNotNull(result.find(new SimplePathPredicate(filesubdir)));
        assertEquals(subdir, result.find(new SimplePathPredicate(filesubdir)).getParent());
    }
    new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
}

From source file:de.jcup.egradle.core.util.LinkToTypeConverter.java

private LinkData internalConvertLink(String link) {
    if (link == null) {
        return null;
    }/* w ww.  j  av a  2s  .c  om*/
    if (!isLinkSchemaConvertable(link)) {
        return null;
    }
    try {
        link = URLDecoder.decode(link, UTF_8.name());
    } catch (UnsupportedEncodingException e) {
        return null;
    }
    String typeName = StringUtils.substring(link, DSLConstants.HYPERLINK_TYPE_PREFIX.length());
    if (StringUtils.isBlank(typeName)) {
        return null;
    }

    LinkData data = new LinkData();
    int index = typeName.indexOf("#");
    if (index == -1) {
        /* no property or method - just plain type, so guard close */
        data.mainName = typeName;
        return data;
    }
    return handleMethodOrProperty(typeName, data);
}

From source file:ch.cyberduck.core.googledrive.DriveSearchFeatureTest.java

@Test
public void testSearchFolder() throws Exception {
    final String name = new AlphanumericRandomStringService().random();
    final Path workdir = new DriveDirectoryFeature(session).mkdir(
            new Path(new DriveHomeFinderService(session).find(), new AlphanumericRandomStringService().random(),
                    EnumSet.of(Path.Type.directory)),
            null, new TransferStatus());
    final Path file = new DriveTouchFeature(session).touch(new Path(workdir, name, EnumSet.of(Path.Type.file)),
            new TransferStatus());
    final DriveSearchFeature feature = new DriveSearchFeature(session);
    assertTrue(//w  w  w. ja  va  2 s . co  m
            feature.search(workdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    // Supports prefix matching only
    assertFalse(feature.search(workdir, new SearchFilter(StringUtils.substring(name, 2)),
            new DisabledListProgressListener()).contains(file));
    final AttributedList<Path> result = feature.search(workdir,
            new SearchFilter(StringUtils.substring(name, 0, name.length() - 2)),
            new DisabledListProgressListener());
    assertTrue(result.contains(file));
    assertEquals(workdir, result.get(result.indexOf(file)).getParent());
    final Path subdir = new DriveDirectoryFeature(session).mkdir(
            new Path(workdir, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)),
            null, new TransferStatus());
    assertFalse(
            feature.search(subdir, new SearchFilter(name), new DisabledListProgressListener()).contains(file));
    new DriveDeleteFeature(session).delete(Arrays.asList(file, subdir), new DisabledLoginCallback(),
            new Delete.DisabledCallback());
}

From source file:annis.dao.autogenqueries.AutoSimpleRegexQuery.java

@Override
public void analyzingQuery(SaltProject saltProject) {

    List<String> tokens = new ArrayList<>();
    for (SCorpusGraph g : saltProject.getSCorpusGraphs()) {
        if (g != null) {
            for (SDocument doc : g.getSDocuments()) {
                SDocumentGraph docGraph = doc.getSDocumentGraph();
                EList<SNode> sNodes = docGraph.getSNodes();

                if (sNodes != null) {
                    for (SNode n : sNodes) {
                        if (n instanceof SToken) {
                            tokens.add(CommonHelper.getSpannedText((SToken) n));
                        }//from  w  w w.  j ava  2s . co m
                    }
                }
            }
        }
    }

    // try to find a word with which is contained twice with Capitalize letter.
    text = null;
    for (int i = 0; i < tokens.size(); i++) {
        for (int j = i + 1; j < tokens.size(); j++) {
            if (tokens.get(i).equalsIgnoreCase(tokens.get(j))) {

                if (tokens.get(i).length() > 1 && ((Character.isLowerCase(tokens.get(i).charAt(0))
                        && Character.isUpperCase(tokens.get(j).charAt(0)))
                        || (Character.isLowerCase(tokens.get(j).charAt(0))
                                && Character.isUpperCase(tokens.get(i).charAt(0))))) {
                    text = tokens.get(i);
                    break;
                }
            }
        }
    }

    if (text != null) {
        Character upperLetter = Character.toUpperCase(text.charAt(0));
        Character lowerLetter = Character.toLowerCase(text.charAt(0));
        String rest = StringUtils.substring(text, -(text.length() - 1));

        finalAQL = "/[" + upperLetter + lowerLetter + "]" + rest + "/";
    } else {
        // select one random token from the result
        int tries = 10;
        int r = new Random().nextInt(tokens.size() - 1);
        text = tokens.get(r);
        while ("".equals(text) && tries > 0) {
            r = new Random().nextInt(tokens.size() - 1);
            text = tokens.get(r);
            tries--;
        }

        if (!"".equals(text) && text.length() > 1) {
            Character upperLetter = Character.toUpperCase(text.charAt(0));
            Character lowerLetter = Character.toLowerCase(text.charAt(0));
            String rest = StringUtils.substring(text, -(text.length() - 1));

            finalAQL = "/[" + upperLetter + lowerLetter + "]" + rest + "/";
        } else {
            finalAQL = "";
        }
    }
}

From source file:com.sonicle.webtop.core.versioning.SqlUpgradeScript.java

public SqlUpgradeScript(String jarResourceName) throws IOException, UnsupportedOperationException {
    InputStream is = null;//  ww  w  .  ja v  a  2  s.  c  om
    BufferedReader br = null;

    try {
        String filename = StringUtils.substring(jarResourceName,
                StringUtils.lastIndexOf(jarResourceName, "/") + 1);
        Matcher matcher = PATTERN_JAR_FILENAME.matcher(filename);
        if (!matcher.matches())
            throw new UnsupportedOperationException(MessageFormat.format("Bad resource name [{0}]", filename));

        this.resourceName = jarResourceName;
        this.fileName = matcher.group(1);
        this.fileVersion = new ServiceVersion(matcher.group(2));
        this.fileSequence = matcher.group(3);

        is = LangUtils.findClassLoader(getClass()).getResourceAsStream(jarResourceName);
        if (is == null) {
            is = getClass().getResourceAsStream(jarResourceName);
            if (is == null)
                throw new ResourceNotFoundException("Null InputStream!");
        }
        readFile(new InputStreamReader(is, "ISO-8859-15"), true);
        //br = new BufferedReader(new InputStreamReader(is, "ISO-8859-15"));
        //readFile(br);
    } finally {
        IOUtils.closeQuietly(br);
        IOUtils.closeQuietly(is);
    }
}

From source file:info.magnolia.ui.framework.action.ActivationAction.java

@Override
protected void onError(Exception e) {
    String errorMessage = null;/*from ww w.j a  va2  s  .c om*/
    if (e.getCause() != null && e.getCause() instanceof ExchangeException) {
        errorMessage = e.getCause().getLocalizedMessage();
        errorMessage = StringUtils.substring(errorMessage,
                StringUtils.indexOf(errorMessage, "error detected:"));
    } else {
        errorMessage = getErrorMessage();
    }
    uiContext.openNotification(MessageStyleTypeEnum.ERROR, true, errorMessage);
}