Example usage for java.lang StringBuffer indexOf

List of usage examples for java.lang StringBuffer indexOf

Introduction

In this page you can find the example usage for java.lang StringBuffer indexOf.

Prototype

@Override
public int indexOf(String str) 

Source Link

Usage

From source file:org.hyperic.util.jdbc.DBUtil.java

public static void replacePlaceHolder(StringBuffer buf, String repl) {
    int index = buf.indexOf("?");
    if (index >= 0)
        buf.replace(index, index + 1, repl);
}

From source file:org.guzz.util.PropertyUtil.java

/**
 * >= JDK1.4//from  w  w  w.j  av a 2  s. c om
 * resolve ${...} placeholders in the @param text , then trim() the value and return.
 * @param props Map
 * @param text the String text to replace
 * @return the resolved value
 * 
 * @see #PLACEHOLDER_PREFIX
 * @see #PLACEHOLDER_SUFFIX
 */
public static String getTrimStringMatchPlaceholdersInMap(Map props, String text) {
    if (text == null || props == null || props.isEmpty()) {
        return text;
    }

    StringBuffer buf = new StringBuffer(text);

    int startIndex = buf.indexOf(PLACEHOLDER_PREFIX);
    while (startIndex != -1) {
        int endIndex = buf.indexOf(PLACEHOLDER_SUFFIX, startIndex + PLACEHOLDER_PREFIX.length());
        if (endIndex != -1) {
            String placeholder = buf.substring(startIndex + PLACEHOLDER_PREFIX.length(), endIndex);
            String propVal = (String) props.get(placeholder);
            if (propVal != null) {
                buf.replace(startIndex, endIndex + PLACEHOLDER_SUFFIX.length(), propVal);
                startIndex = buf.indexOf(PLACEHOLDER_PREFIX, startIndex + propVal.length());
            } else {
                log.warn("Could not resolve placeholder '" + placeholder + "' in [" + text + "]");
                startIndex = buf.indexOf(PLACEHOLDER_PREFIX, endIndex + PLACEHOLDER_SUFFIX.length());
            }
        } else {
            startIndex = -1;
        }
    }

    return buf.toString().trim();
}

From source file:org.openlaszlo.utils.LZHttpUtils.java

/**
 * @return the URL for the request // with the query string?
 * @param req the request//from  w ww.  j a  v a 2 s .  c o m
 */
public static URL getRequestURL(HttpServletRequest req) {
    StringBuffer surl = req.getRequestURL();
    if (surl.indexOf("https") == 0) {
        try {
            System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
            Class<?> provClass = Class.forName("com.sun.net.ssl.internal.ssl.Provider");
            Provider provider = (Provider) provClass.newInstance();
            Security.addProvider(provider);
        } catch (InstantiationException e) {
            throw new ChainedException(e);
        } catch (IllegalAccessException e) {
            throw new ChainedException(e);
        } catch (ClassNotFoundException e) {
            throw new ChainedException(e);
        }
    }
    // surl.append("?");
    // surl.append(req.getQueryString());
    try {
        return new URL(surl.toString());
    } catch (Exception e) {
        throw new ChainedException(e);
    }
}

From source file:net.duckling.ddl.service.task.TakerWrapper.java

private static String getSome(List<TaskTaker> takers, int index) {
    StringBuffer sb = new StringBuffer();
    String split = " | ";
    if (CommonUtil.isNullArray(takers)) {
        sb.append("");
        return sb.toString();
    }/*from w  w w  . j a va  2 s. com*/
    for (TaskTaker taker : takers) {
        if (taker == null || CommonUtil.isNullStr(taker.getUserId())) {
            continue;
        }
        try {
            sb.append(taker.getUserId().split("%")[index]).append(split);
        } catch (Exception e) {
            continue;
        }
    }
    if (sb.indexOf(split) > 0) {
        sb.delete(sb.length() - split.length(), sb.length());
    }
    return sb.toString();
}

From source file:com.tactfactory.harmony.utils.TactFileUtils.java

/**
 * Append String to at the end of a file
 * if it doesn't exists in the file yet.
 * @param content The content to append/*from www.j  av  a2 s  .c  o  m*/
 * @param file The file to write to
 * @return true if the content has been correctly appended
 */
public static boolean appendToFile(final String content, final File file) {
    boolean success = false;
    final StringBuffer buffer = TactFileUtils.fileToStringBuffer(file);
    //If content doesn't exists in the file yet
    if (buffer.indexOf(content) == -1) {
        final int offset = buffer.length();
        buffer.insert(offset, content);
        TactFileUtils.stringBufferToFile(buffer, file);
        success = true;
    }
    return success;
}

From source file:com.tactfactory.harmony.utils.TactFileUtils.java

/**
 * Add String after a given String in the given file.
 * (Only if it doesn't already exists in the file)
 * @param content The content to append/*from  www .j  ava2s  .  c o m*/
 * @param after The String after which the content must be added
 * @param file The file to write to
 * @return true if the content has been correctly appended
 */
public static boolean addToFile(final String content, final String after, final File file) {
    boolean success = false;
    final StringBuffer buffer = TactFileUtils.fileToStringBuffer(file);
    //If content doesn't exists in the file yet
    if (buffer.indexOf(content) == -1) {
        final int offset = buffer.indexOf(after) + after.length();
        buffer.insert(offset, content);
        TactFileUtils.stringBufferToFile(buffer, file);
        success = true;
    }
    return success;
}

From source file:org.jahia.services.applications.pluto.JahiaPortalURLParserImpl.java

private static void replaceChar(StringBuffer url, String character, String change) {
    boolean contains = url.toString().contains(character);
    while (contains) {
        int index = url.indexOf(character);
        url.deleteCharAt(index);/*ww w. j a  v a 2 s  .  co  m*/
        url.insert(index, change, 0, 3);
        contains = url.toString().contains(character);
    }
}

From source file:br.org.indt.ndg.common.MD5.java

public static String getMD5FromSurvey(StringBuffer input) throws IOException, NoSuchAlgorithmException {

    StringBuffer inputMD5 = new StringBuffer(input);

    // remove XML header
    String xmlStartFlag = "<?";
    String xmlEndFlag = "?>";

    int xmlFlagStartPosition = inputMD5.indexOf(xmlStartFlag);
    int xmlFlagEndPosition = inputMD5.indexOf(xmlEndFlag);

    if ((xmlFlagStartPosition >= 0) && (xmlFlagEndPosition >= 0)) {
        inputMD5.delete(xmlFlagStartPosition, xmlFlagEndPosition + xmlEndFlag.length() + 1);
    }/*from  w  w  w . j a  va2s .c  om*/

    // remove checksum key
    String checksumFlag = "checksum=\"";
    int checksumFlagStartPosition = inputMD5.indexOf(checksumFlag) + checksumFlag.length();
    int checksumKeySize = 32;

    inputMD5.replace(checksumFlagStartPosition, checksumFlagStartPosition + checksumKeySize, "");

    // we need to remove last '\n' once NDG editor calculates its md5
    // checksum without it (both input and inputMD5)
    if (input.charAt(input.toString().length() - 1) == '\n') {
        input.deleteCharAt(input.toString().length() - 1);
    }

    if (inputMD5.charAt(inputMD5.toString().length() - 1) == '\n') {
        inputMD5.deleteCharAt(inputMD5.toString().length() - 1);
    }

    MessageDigest messageDigest = java.security.MessageDigest.getInstance("MD5");
    messageDigest.update(inputMD5.toString().getBytes("UTF-8"));
    byte[] byteArrayMD5 = messageDigest.digest();

    String surveyFileMD5 = getByteArrayAsString(byteArrayMD5);

    return surveyFileMD5;
}

From source file:info.magnolia.link.LinkUtil.java

/**
 * Appends a parameter to the given url, using ?, or & if there are already
 * parameters in the given url. <strong>Warning:</strong> It does not
 * <strong>replace</strong> an existing parameter with the same name.
 *///w  w  w.j ava2 s.co  m
public static void addParameter(StringBuffer uri, String name, String value) {
    if (uri.indexOf("?") < 0) {
        uri.append('?');
    } else {
        uri.append('&');
    }
    uri.append(name).append('=');
    try {
        uri.append(URLEncoder.encode(value, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("It seems your system does not support UTF-8 !?", e);
    }
}

From source file:gov.nih.nci.caintegrator.ui.graphing.util.ImageMapUtil.java

/**
 * Write the image map for the collection of bounding entities.
 * @param writer//from www. j  a  v a 2s  . com
 * @param name
 * @param boundingEntities
 * @param useOverlibToolTip
 */
private static void writeBoundingRectImageMap(PrintWriter writer, String name,
        Collection<ChartEntity> boundingEntities, boolean useOverlibToolTip) {
    System.out.println("Num entities=" + boundingEntities.size());
    StringBuffer sb = new StringBuffer();
    ChartEntity chartEntity;
    String areaTag;

    StandardToolTipTagFragmentGenerator ttg = new StandardToolTipTagFragmentGenerator();
    StandardURLTagFragmentGenerator urlg = new StandardURLTagFragmentGenerator();
    sb.append("<map id=\"" + name + "\" name=\"" + name + "\">");
    sb.append(StringUtils.getLineSeparator());
    for (Iterator i = boundingEntities.iterator(); i.hasNext();) {
        chartEntity = (ChartEntity) i.next();
        areaTag = chartEntity.getImageMapAreaTag(ttg, urlg).trim();
        if (areaTag.length() > 0) {
            if (sb.indexOf(chartEntity.getImageMapAreaTag(ttg, urlg)) == -1) {
                sb.append(chartEntity.getImageMapAreaTag(ttg, urlg));
                sb.append(StringUtils.getLineSeparator());
            }
        }
    }
    sb.append("</map>");
    writer.println(sb.toString());
}