Example usage for java.lang StringBuilder lastIndexOf

List of usage examples for java.lang StringBuilder lastIndexOf

Introduction

In this page you can find the example usage for java.lang StringBuilder lastIndexOf.

Prototype

@Override
    public int lastIndexOf(String str) 

Source Link

Usage

From source file:org.dita.dost.module.BranchFilterModule.java

static URI generateCopyTo(final URI href, final Branch filter) {
    final StringBuilder buf = new StringBuilder(href.toString());
    final Optional<String> suffix = filter.resourceSuffix;
    suffix.ifPresent(s -> {/*from w  ww . j  a va2 s  .co m*/
        final int sep = buf.lastIndexOf(URI_SEPARATOR);
        final int i = buf.lastIndexOf(".");
        if (i != -1 && (sep == -1 || i > sep)) {
            buf.insert(i, s);
        } else {
            buf.append(s);
        }
    });
    final Optional<String> prefix = filter.resourcePrefix;
    prefix.ifPresent(s -> {
        final int i = buf.lastIndexOf(URI_SEPARATOR);
        if (i != -1) {
            buf.insert(i + 1, s);
        } else {
            buf.insert(0, s);
        }
    });
    return toURI(buf.toString());
}

From source file:org.sakaiproject.profile2.util.ProfileUtils.java

/**
 * Trims and abbreviates text to the given maximum number of displayed
 * characters (less 3 characters, in case "..." must be appended).
 * Supports HTML and preserves formatting.
 * //w w w . j av a2  s . com
 * @param s             the string
 * @param maxNumOfChars    num chars to keep. If HTML, it's the number of content chars, ignoring tags.
 * @param isHtml       is the string HTML?
 * @return
 */
public static String truncateAndAbbreviate(String s, int maxNumOfChars, boolean isHtml) {

    if (StringUtils.isBlank(s)) {
        return "";
    }

    //html
    if (isHtml) {
        StringBuilder trimmedHtml = new StringBuilder();

        boolean trimmed = FormattedText.trimFormattedText(s, maxNumOfChars - 3, trimmedHtml);

        if (trimmed) {
            int index = trimmedHtml.lastIndexOf("</");
            if (-1 != index) {
                trimmedHtml.insert(index, "...");
            } else {
                trimmedHtml.append("...");
            }
        }
        return trimmedHtml.toString();
    }

    //plain text
    return StringUtils.abbreviate(s, maxNumOfChars);

}

From source file:org.springframework.jdbc.datasource.init.ScriptUtils.java

private static void appendSeparatorToScriptIfNecessary(StringBuilder scriptBuilder,
        @Nullable String separator) {
    if (separator == null) {
        return;/*from   www .  ja  v a2  s  . com*/
    }
    String trimmed = separator.trim();
    if (trimmed.length() == separator.length()) {
        return;
    }
    // separator ends in whitespace, so we might want to see if the script is trying
    // to end the same way
    if (scriptBuilder.lastIndexOf(trimmed) == scriptBuilder.length() - trimmed.length()) {
        scriptBuilder.append(separator.substring(trimmed.length()));
    }
}

From source file:org.jcommon.com.util.JsonUtils.java

public static String toJson(String[] keys, String[] values, boolean encode) {
    if (keys == null || values == null) {
        logger.warn("json key or vlaue is null");
        return null;
    }/*from   www  .  java2  s. c o m*/
    if (keys.length != values.length) {
        logger.warn("key' length must be same with vlaue");
        return null;
    }

    StringBuilder sb = new StringBuilder();
    try {
        sb.append("{");
        for (int i = 0; i < keys.length; i++) {
            if (values[i] == null || keys[i] == null)
                continue;
            if (encode)
                sb.append(
                        "\"" + CoderUtils.encode(keys[i]) + "\"" + ":\"" + CoderUtils.encode(values[i]) + "\"");
            else
                sb.append("\"" + keys[i] + "\"" + ":\"" + values[i] + "\"");
            sb.append(",");
        }
        if (sb.lastIndexOf(",") == sb.length() - 1)
            sb.deleteCharAt(sb.length() - 1);
        sb.append("}");
    } catch (Exception e) {
        logger.error("", e);
    }

    return sb.toString();
}

From source file:Haze.CHazeManager.java

public static void loadHazeInfo() {

    String strOutput = "";

    try {/* w ww  .j  a va  2  s  .  co  m*/
        strOutput = CNetworkFactory.createHazeRequest().sendRequest();
    } catch (IOException ex) {
    }

    if (strOutput.isEmpty()) {
        return;
    }

    JSONArray aryRegions = XML.toJSONObject(strOutput).getJSONObject("channel").getJSONObject("item")
            .getJSONArray("region");

    StringBuilder objSB = new StringBuilder();
    objSB.append("[");

    for (int i = 0; i < aryRegions.length(); i++) {

        objSB.append("{\"region\" : ");

        JSONObject objRegion = (JSONObject) aryRegions.get(i);

        objSB.append("\"");
        objSB.append(objRegion.getString("id"));
        objSB.append("\",");

        JSONArray aryReadings = objRegion.getJSONObject("record").getJSONArray("reading");

        for (int x = 0; x < aryReadings.length(); x++) {

            JSONObject objReading = (JSONObject) aryReadings.get(x);

            if (objReading.getString("type").equalsIgnoreCase("NPSI")) {

                objSB.append("\"psi\" : ");
                objSB.append(objReading.getInt("value"));
                objSB.append("},");
            }

        }
    }

    objSB.deleteCharAt(objSB.lastIndexOf(","));

    objSB.append("]");

    sendInfoToCPU(objSB.toString(), 33010);

}

From source file:org.wso2.carbon.bpel.ui.InstanceFilterUtil.java

public static String createInstanceFilterStringFromFormData(final InstanceFilter filterData) {
    if (!isValidFilter(filterData)) {
        if (log.isDebugEnabled()) {
            log.debug("Invalid Instance Filter.");
        }/*from ww  w  .  j av a 2  s  . c o m*/
        /*
        * Here we set space as it is the default filter string.
        * */
        return " ";
    }

    StringBuilder filterBuilder = new StringBuilder();
    // Sending space to back-end. Workaround to handle multi-tenant case.
    // Decide to remove "name}}* namespace=*" filter used earlier to get all instances.

    filterBuilder.append(" ");

    if (filterData.getPid() != null && !filterData.getPid().equals("all")
            && !filterData.getPid().equals("noprocesses")) {
        filterBuilder.append("pid=");
        filterBuilder.append(filterData.getPid());
        filterBuilder.append(" ");
    }

    if (filterData.getStatus() != null && filterData.getStatus().length > 0) {
        filterBuilder.append("status=");
        for (String status : filterData.getStatus()) {
            filterBuilder.append(status);
            filterBuilder.append("|");
        }

        filterBuilder.deleteCharAt(filterBuilder.lastIndexOf("|"));
        filterBuilder.append(" ");
    }

    if (filterData.getStarteddate() != null && filterData.getStarteddate().trim().length() == 16) {
        filterBuilder.append("started");
        if (filterData.getStartedopt() != null && filterData.getStartedopt().equals("onb")) {
            filterBuilder.append("<=");
        } else if (filterData.getStartedopt() != null) {
            filterBuilder.append(">=");
        } else {
            filterBuilder.append("=");
        }
        filterBuilder.append(filterData.getStarteddate().trim());
        filterBuilder.append(" ");
    }

    if (filterData.getLadate() != null && filterData.getLadate().trim().length() == 16) {
        filterBuilder.append("last-active");
        if (filterData.getLadateopt() != null && filterData.getLadateopt().equals("onb")) {
            filterBuilder.append("<=");
        } else if (filterData.getLadateopt() != null) {
            filterBuilder.append(">=");
        } else {
            filterBuilder.append("=");
        }
        filterBuilder.append(filterData.getLadate().trim());
        filterBuilder.append(" ");
    }

    String finalFilter = filterBuilder.toString();
    if (log.isDebugEnabled()) {
        log.debug("Instance Filter:" + finalFilter);
    }

    return finalFilter;
}

From source file:org.beangle.ems.database.service.SqlService.java

@SuppressWarnings("deprecation")
public String getLimitString(String sql, PageLimit limit) {
    try {/*from   w  w  w  .j  a v a2  s .c  om*/
        int offset = (limit.getPageNo() - 1) * limit.getPageSize();
        String newSql = dialect.getLimitString(sql, offset, limit.getPageSize());
        StringBuilder sb = new StringBuilder(newSql);
        int index = sb.lastIndexOf("?");
        if (-1 != index)
            sb.replace(index, index + 1, String.valueOf(limit.getPageSize()));

        index = sb.lastIndexOf("?");
        if (-1 != index)
            sb.replace(index, index + 1, String.valueOf(offset));

        return sb.toString();
    } catch (Exception e) {
        throw new RuntimeException("cannot limit sql:" + sql, e);
    }
}

From source file:org.beangle.struts2.view.component.Navmenu.java

/**
 * ???resource(action!method)/* www . ja va 2s .  c  o m*/
 * 
 * @param first
 * @param second
 * @return
 */
private boolean sameAction(String first) {
    StringBuilder firstSb = new StringBuilder(StringUtils.substringBefore(first, "."));
    if (-1 == firstSb.lastIndexOf("!")) {
        firstSb.append("!index");
    }
    return firstSb.toString().equals(uri);
}

From source file:org.beangle.struts2.view.component.Navmenu.java

public Navmenu(ValueStack stack) {
    super(stack);
    StringBuilder sb = new StringBuilder(StringUtils.substringBeforeLast(getRequestURI(), "."));
    if (-1 == sb.lastIndexOf("!")) {
        sb.append("!index");
    }/*  w w  w.  j  a  v a  2s .c o m*/
    this.uri = sb.toString();
}

From source file:com.apt.ajax.controller.AjaxUpload.java

private File checkExist(String filename, String uploadDir) {
    File file = new File(uploadDir + File.separator + filename);
    if (file.exists()) {
        StringBuilder sb = new StringBuilder(filename);
        sb.insert(sb.lastIndexOf("."), new Date().getTime());
        file = new File(uploadDir + File.separator + sb.toString());
    }//from  w  w  w.  j  a  v a 2 s .c o  m
    return file;
}