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

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

Introduction

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

Prototype

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

Source Link

Document

Finds the first index within a String, handling null.

Usage

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

private String indexOf(String str, String delim, Long count) {
    int pos = -1;
    for (int i = 0; i < count; i++) {
        pos = StringUtils.indexOf(str, delim, pos + 1);
        if (pos < 0) {
            return str;
        }// w ww.  j a v  a 2 s. c o m
    }
    return str.substring(0, pos);
}

From source file:info.magnolia.cms.filters.RepositoryMappingFilter.java

@Override
public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    String uri = MgnlContext.getAggregationState().getCurrentURI();
    int firstSelectorDelimiterPos = StringUtils.indexOf(uri, Path.SELECTOR_DELIMITER,
            StringUtils.lastIndexOf(uri, '/'));
    String path;//  w  ww .j a  va  2 s.c  o m
    // TODO Warning - this might change in the future - see MAGNOLIA-2343 for details.
    String selector;
    if (firstSelectorDelimiterPos > -1) {
        int lastSelectorDelimiterPos = StringUtils.lastIndexOf(uri, Path.SELECTOR_DELIMITER);
        path = StringUtils.substring(uri, 0, firstSelectorDelimiterPos);
        selector = StringUtils.substring(uri, firstSelectorDelimiterPos + 1, lastSelectorDelimiterPos);
    } else {
        // no tilde (and no extension)
        path = uri;
        selector = "";
    }

    URI2RepositoryMapping mapping = uri2RepositoryManager.getMapping(uri);

    // remove prefix if any
    path = mapping.getHandle(path);

    final AggregationState aggregationState = MgnlContext.getAggregationState();
    aggregationState.setRepository(mapping.getRepository());
    aggregationState.setHandle(path);

    // selector could potentially be set from some other place, but we have no better idea for now :)
    aggregationState.setSelector(selector);

    chain.doFilter(request, response);
}

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

/**
 * The function will move the cursor in forward direction.
 * @param styledText//  w w  w  . j  a  v a  2s.  co m
 * @param text
 * @param prevLineIndex
 * @param nextLineIndex
 * @return int[]
 */
public int[] nextButtonListener(StyledText styledText, String text, int prevLineIndex, int nextLineIndex) {
    logger.debug("StyledText next button selected");
    int txtIndex = StringUtils.indexOf(StringUtils.lowerCase(styledText.getText()), StringUtils.lowerCase(text),
            nextLineIndex);

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

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

/**
 * The function will change selected text background color.
 * @param styledText//from  w  ww .j ava  2 s .co  m
 * @param text
 * @param foreground
 * @param background
 */
public void allButtonListener(StyledText styledText, String text, Color foreground, Color background,
        Label label) {
    logger.debug("StyledText All button selected");
    int index = 0;
    int recordCount = 0;
    if (styledText == null) {
        return;
    }
    for (; index < styledText.getText().length();) {
        int lastIndex = StringUtils.indexOf(StringUtils.lowerCase(styledText.getText()),
                StringUtils.lowerCase(text), index);

        if (lastIndex < 0) {
            return;
        } else {
            setStyledRange(styledText, lastIndex, text.length(), null, background);
            index = lastIndex + 1;
            recordCount++;
            label.setVisible(true);
            label.setText("Matching count - " + recordCount);
        }
    }
}

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 v  a  2s . 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;
}

From source file:com.xx_dev.apn.proxy.ApnProxyUserAgentForwardHandler.java

private String getPartialUrl(String fullUrl) {
    if (StringUtils.startsWith(fullUrl, "http")) {
        int idx = StringUtils.indexOf(fullUrl, "/", 7);
        return idx == -1 ? "/" : StringUtils.substring(fullUrl, idx);
    }/* w  ww.  java 2  s.  com*/

    return fullUrl;
}

From source file:com.s3d.webapps.util.time.DateUtils.java

/**
 * Index of sign charaters (i.e. '+' or '-').
 * // w w  w . jav  a  2  s . c  o m
 * @param str The string to search
 * @param startPos The start position
 * @return the index of the first sign character or -1 if not found
 */
private static int indexOfSignChars(String str, int startPos) {
    int idx = StringUtils.indexOf(str, '+', startPos);
    if (idx < 0) {
        idx = StringUtils.indexOf(str, '-', startPos);
    }
    return idx;
}

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

private boolean isTextExist(StyledText styledText, String text) {
    if (StringUtils.isNotBlank(styledText.getText())) {
        int textIndex = StringUtils.indexOf(StringUtils.lowerCase(styledText.getText()),
                StringUtils.lowerCase(text), 0);
        if (textIndex < 0) {
            label.setVisible(true);// ww  w.  j  av a 2s  .  c  om
            label.setText(labelText);
            return true;
        } else {
            label.setVisible(false);
            return false;
        }
    } else {
        return false;
    }

}

From source file:com.ibm.bi.dml.runtime.instructions.cp.VariableCPInstruction.java

@Override
public void updateInstructionThreadID(String pattern, String replace) throws DMLRuntimeException {
    if (opcode == VariableOperationCode.CreateVariable || opcode == VariableOperationCode.SetFileName) {
        //replace in-memory instruction
        input2.set_name(input2.getName().replaceAll(pattern, replace));

        // Find a start position of file name string.
        int iPos = StringUtils.ordinalIndexOf(instString, Lop.OPERAND_DELIMITOR, CREATEVAR_FILE_NAME_VAR_POS);
        // Find a end position of file name string.
        int iPos2 = StringUtils.indexOf(instString, Lop.OPERAND_DELIMITOR, iPos + 1);

        StringBuilder sb = new StringBuilder();
        sb.append(instString.substring(0, iPos + 1)); // It takes first part before file name.
        // This will replace 'pattern' with 'replace' string from file name.
        sb.append(ProgramConverter.saveReplaceFilenameThreadID(instString.substring(iPos + 1, iPos2 + 1),
                pattern, replace));/*from   w w w .ja  v  a 2s.  com*/
        sb.append(instString.substring(iPos2 + 1)); // It takes last part after file name.

        instString = sb.toString();
    }
}

From source file:org.apache.sysml.runtime.instructions.cp.VariableCPInstruction.java

@Override
public void updateInstructionThreadID(String pattern, String replace) throws DMLRuntimeException {
    if (opcode == VariableOperationCode.CreateVariable || opcode == VariableOperationCode.SetFileName) {
        //replace in-memory instruction
        input2.setName(input2.getName().replaceAll(pattern, replace));

        // Find a start position of file name string.
        int iPos = StringUtils.ordinalIndexOf(instString, Lop.OPERAND_DELIMITOR, CREATEVAR_FILE_NAME_VAR_POS);
        // Find a end position of file name string.
        int iPos2 = StringUtils.indexOf(instString, Lop.OPERAND_DELIMITOR, iPos + 1);

        StringBuilder sb = new StringBuilder();
        sb.append(instString.substring(0, iPos + 1)); // It takes first part before file name.
        // This will replace 'pattern' with 'replace' string from file name.
        sb.append(ProgramConverter.saveReplaceFilenameThreadID(instString.substring(iPos + 1, iPos2 + 1),
                pattern, replace));// w ww  .jav a 2  s.com
        sb.append(instString.substring(iPos2 + 1)); // It takes last part after file name.

        instString = sb.toString();
    }
}