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

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

Introduction

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

Prototype

public static int lastIndexOf(String str, String searchStr, int startPos) 

Source Link

Document

Finds the first index within a String, handling null.

Usage

From source file:hydrograph.ui.dataviewer.find.StyledTextEventListener.java

/**
 *  The function will move cursor in reverse direction.
 * @param styledText/*from w w w  .  j  av a  2s  .c  om*/
 * @param text
 * @param prevLineIndex
 * @param nextLineIndex
 * @return int[]
 */
public int[] prevButtonListener(StyledText styledText, String text, int prevLineIndex, int nextLineIndex) {
    logger.debug("StyledText prev button selected");
    if (prevLineIndex == 0) {
        prevLineIndex = styledText.getText().length() - 1;
    }
    int lastIndex = StringUtils.lastIndexOf(StringUtils.lowerCase(styledText.getText()),
            StringUtils.lowerCase(text), prevLineIndex - 1);

    if (lastIndex < 0) {
        prevLineIndex = styledText.getText().length() - 1;
        prevLineIndex = StringUtils.lastIndexOf(StringUtils.lowerCase(styledText.getText()),
                StringUtils.lowerCase(text), prevLineIndex - 1);
        styledText.setSelection(prevLineIndex);
        setStyledRange(styledText, prevLineIndex, text.length(), null,
                Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));
        nextLineIndex = prevLineIndex + 1;
        return new int[] { prevLineIndex, nextLineIndex };
    } else {
        setStyledRange(styledText, lastIndex, text.length(), null,
                Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));
        styledText.setSelection(lastIndex);
        prevLineIndex = lastIndex;
        nextLineIndex = lastIndex + 1;
        styledText.redraw();
    }
    return new int[] { prevLineIndex, nextLineIndex };
}

From source file:com.antsdb.saltedfish.sql.vdm.FuncSubstringIndex.java

private String lastIndexOf(String str, String delim, Long count) {
    int pos = str.length();
    for (int i = 0; i < count; i++) {
        pos = StringUtils.lastIndexOf(str, delim, pos - 1);
        if (pos < 0) {
            return str;
        }//from w w w.  j av a2s .c  o m
    }
    return str.substring(pos + 1);
}

From source file:com.edgenius.wiki.service.impl.SitemapServiceImpl.java

public boolean removePage(String pageUuid) throws IOException {
    boolean removed = false;
    String sitemapIndex = metadata.getSitemapIndex(pageUuid);
    if (sitemapIndex == null) {
        log.warn("Page {} does not exist in sitemap", pageUuid);
        return removed;
    }//from   w w w  . j  a  va 2 s  . c  o m

    String sitemapZip = SITEMAP_NAME_PREFIX + sitemapIndex + ".xml.gz";
    File sizemapZipFile = new File(mapResourcesRoot.getFile(), sitemapZip);
    if (!sizemapZipFile.exists()) {
        throw new IOException("Remove pageUuid " + pageUuid + " from sitemap failed becuase sitemap not found");
    }

    PipedInputStream bis = new PipedInputStream();
    PipedOutputStream bos = new PipedOutputStream(bis);
    InputStream zipfile = new FileInputStream(sizemapZipFile);
    GZIPInputStream gzipstream = new GZIPInputStream(zipfile);
    byte[] bytes = new byte[1024 * 1000];
    int len = 0;
    while ((len = gzipstream.read(bytes)) > 0) {
        bos.write(bytes, 0, len);
    }

    IOUtils.closeQuietly(zipfile);
    IOUtils.closeQuietly(gzipstream);

    String pageUrl = metadata.getPageUrl(pageUuid);
    String body = IOUtils.toString(bis);
    int loc = body.indexOf("<loc>" + pageUrl + "</loc>");
    if (loc != -1) {
        int start = StringUtils.lastIndexOf(body, "<url>", loc);
        int end = StringUtils.indexOf(body, "</url>", loc);
        if (start != -1 && end != -1) {
            //remove this URL
            body = StringUtils.substring(body, start, end + 6);
            zipToFile(sizemapZipFile, body.getBytes());
            removed = true;
        }
    }

    metadata.removePageMap(pageUuid);

    return removed;
}