Example usage for java.lang StringBuffer deleteCharAt

List of usage examples for java.lang StringBuffer deleteCharAt

Introduction

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

Prototype

@Override
public synchronized StringBuffer deleteCharAt(int index) 

Source Link

Usage

From source file:org.opennms.netmgt.mib2events.Mib2Events.java

public static String getTrapEventDescr(MibValueSymbol trapValueSymbol) {
    String description = ((SnmpType) trapValueSymbol.getType()).getDescription();

    // FIXME There a lot of detail here (like removing the last \n) that can go away when we don't need to match mib2opennms exactly

    final String descrStartingNewlines = description.replaceAll("^", "\n<p>");

    final String descrEndingNewlines = descrStartingNewlines.replaceAll("$", "</p>\n");

    //final String descrTabbed = descrEndingNewlines.replaceAll("(?m)^", "\t");
    //final StringBuffer dbuf = new StringBuffer(descrTabbed);

    final StringBuffer dbuf = new StringBuffer(descrEndingNewlines);
    if (dbuf.charAt(dbuf.length() - 1) == '\n') {
        dbuf.deleteCharAt(dbuf.length() - 1); // delete the \n at the end
    }//from  ww  w . jav  a  2 s  .com

    //if (dbuf.lastIndexOf("\n") != -1) {
    //    dbuf.insert(dbuf.lastIndexOf("\n") + 1, '\t');
    //}

    //final StringBuffer dbuf = new StringBuffer(descrEndingNewlines);
    //dbuf.append("\n");

    dbuf.append("<table>");
    dbuf.append("\n");
    int vbNum = 1;
    for (MibValue vb : getTrapVars(trapValueSymbol)) {
        dbuf.append("\t<tr><td><b>\n\n\t").append(vb.getName());
        dbuf.append("</b></td><td>\n\t%parm[#").append(vbNum).append("]%;</td><td><p>");

        SnmpObjectType snmpObjectType = ((SnmpObjectType) ((ObjectIdentifierValue) vb).getSymbol().getType());
        if (snmpObjectType.getSyntax().getClass().equals(IntegerType.class)) {
            IntegerType integerType = (IntegerType) snmpObjectType.getSyntax();

            if (integerType.getAllSymbols().length > 0) {
                SortedMap<Integer, String> map = new TreeMap<Integer, String>();
                for (MibValueSymbol sym : integerType.getAllSymbols()) {
                    map.put(new Integer(sym.getValue().toString()), sym.getName());
                }

                dbuf.append("\n");
                for (Entry<Integer, String> entry : map.entrySet()) {
                    dbuf.append("\t\t").append(entry.getValue()).append("(").append(entry.getKey())
                            .append(")\n");
                }
                dbuf.append("\t");
            }
        }

        dbuf.append("</p></td></tr>\n");
        vbNum++;
    }

    if (dbuf.charAt(dbuf.length() - 1) == '\n') {
        dbuf.deleteCharAt(dbuf.length() - 1); // delete the \n at the end
    }
    dbuf.append("</table>\n\t");

    return dbuf.toString();
}

From source file:org.dspace.app.dav.DAVServlet.java

/**
 * Return portion of URI path relevant to the DAV resource. We go through
 * the extra pain of chopping up getRequestURI() because it is NOT
 * URL-decoded by the Servlet container, while unfortunately getPathInfo()
 * IS pre-decoded, leaving a redudndant "/" (and who knows what else) in the
 * handle. Since the "handle" may not even be a CNRI Handle, we don't want
 * to assume it even has a "/" (escaped or not).
 * <p>/*  w w w  .ja v a  2 s  . com*/
 * Finally, search for doubled-up '/' separators and coalesce them.
 * 
 * @param request the request
 * 
 * @return String of undecoded path NOT starting with '/'.
 */
private static String getDavResourcePath(HttpServletRequest request) {
    String path = request.getRequestURI();
    String ppath = path.substring(request.getContextPath().length());
    String scriptName = request.getServletPath();
    if (ppath.startsWith(scriptName)) {
        ppath = ppath.substring(scriptName.length());
    }
    // log.debug("Got DAV URI: BEFORE // FIXUP: PATH_INFO=\"" + ppath+"\"");
    // turn all double '/' ("//") in URI into single '/'
    StringBuffer sb = new StringBuffer(ppath);
    int i = ppath.length() - 2;
    if (i > 0) {
        while ((i = ppath.lastIndexOf("//", i)) > -1) {
            sb.deleteCharAt(i + 1);
            --i;
        }
    }
    // remove leading '/'
    if (sb.length() > 0 && sb.charAt(0) == '/') {
        sb.deleteCharAt(0);
    }
    ppath = sb.toString();
    log.debug("Got DAV URI: PATH_INFO=\"" + ppath + "\"");
    return ppath;
}

From source file:com.aliyun.android.oss.http.OSSHttpTool.java

public static String encodeUri(String uri) {
    StringBuffer encodeBuffer = new StringBuffer();
    String[] splitArray = uri.split("/");

    for (String part : splitArray) {
        try {//from   w ww.j  av  a 2 s .co m
            encodeBuffer.append(URLEncoder.encode(part, "UTF-8")).append("/");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    if (!uri.endsWith("/")) {
        encodeBuffer.deleteCharAt(encodeBuffer.length() - 1);
    }
    return encodeBuffer.toString();
}

From source file:ac.elements.parser.ExtendedFunctions.java

/**
 * Trim all occurences of the supplied character from the given String.
 * //from  w  w  w  .j a v a2 s.c o  m
 * @param str
 *            the String to check
 * @param ter
 *            the character to be trimmed
 * @return the trimmed String
 */
public static String trimCharacter(String str, char character) {
    if (str == null || str.length() == 0) {
        return str;
    }
    StringBuffer buf = new StringBuffer(str);
    while (buf.length() > 0 && buf.charAt(0) == character) {
        buf.deleteCharAt(0);
    }

    while (buf.length() > 0 && buf.charAt(buf.length() - 1) == character) {
        buf.deleteCharAt(buf.length() - 1);
    }
    return buf.toString();
}

From source file:org.apache.tajo.engine.query.TestJoinQuery.java

private static String buildSchemaString(String tableName) throws TajoException {
    TableDesc desc = client.getTableDesc(tableName);
    StringBuffer sb = new StringBuffer();
    for (Column column : desc.getSchema().getRootColumns()) {
        sb.append(column.getSimpleName()).append(" ").append(column.getDataType().getType());
        TajoDataTypes.DataType dataType = column.getDataType();
        if (dataType.getLength() > 0) {
            sb.append("(").append(dataType.getLength()).append(")");
        }/*from w  ww .  ja  va2 s .  c  om*/
        sb.append(",");
    }
    sb.deleteCharAt(sb.length() - 1);
    return sb.toString();
}

From source file:com.edgenius.core.Global.java

public static void syncTo(GlobalSetting setting) {

    setting.setDefaultDirection(Global.DefaultDirection);
    setting.setDefaultLanguage(Global.DefaultLanguage);
    setting.setDefaultCountry(Global.DefaultCountry);
    setting.setDefaultTimeZone(Global.DefaultTimeZone);
    setting.setDefaultLoginKey(Global.DefaultLoginKey);
    setting.setHostProtocol(Global.SysHostProtocol);
    if (StringUtils.indexOf(Global.SysHostAddress, ':') != -1) {
        String[] addr = StringUtils.split(Global.SysHostAddress, ':');
        setting.setHostName(addr[0]);/*from w ww. jav  a  2s.c o m*/
        setting.setHostPort(Integer.parseInt(addr[1]));
    } else {
        setting.setHostName(Global.SysHostAddress);
        if (Global.SysHostProtocol != null && Global.SysHostProtocol.startsWith("https:"))
            setting.setHostPort(443);
        else
            setting.setHostPort(80);
    }

    setting.setPublicSearchEngineAllow(Global.PublicSearchEngineAllow);
    setting.setContextPath(StringUtils.trim(Global.SysContextPath));
    setting.setEncryptAlgorithm(Global.PasswordEncodingAlgorithm);
    setting.setEncryptPassword(Global.EncryptPassword);
    setting.setSpaceQuota(Global.SpaceQuota);
    setting.setDelayRemoveSpaceHours(Global.DelayRemoveSpaceHours);
    setting.setEnableAdminPermControl(Global.EnableAdminPermControl);
    setting.setDelayOfflineSyncMinutes(Global.DelayOfflineSyncMinutes);
    setting.setRegisterMethod(Global.registerMethod);
    setting.setMaintainJobCron(Global.MaintainJobCron);
    setting.setCommentsNotifierCron(Global.CommentsNotifierCron);
    setting.setMaxCommentsNotifyPerDay(Global.MaxCommentsNotifyPerDay);
    setting.setAutoFixLinks(Global.AutoFixLinks);
    setting.setDefaultNotifyMail(Global.DefaultNotifyMail);
    setting.setCcToSystemAdmin(Global.ccToSystemAdmin);
    setting.setDefaultReceiverMailAddress(Global.DefaultReceiverMail);
    setting.setSystemTitle(Global.SystemTitle);

    setting.setAdsense(enable(Global.ADSENSE));
    setting.setTextnut(enable(Global.TEXTNUT));
    setting.setSkin(Global.Skin);

    setting.setWebservice(enable(Global.webServiceEnabled));
    setting.setWebserviceAuthenticaton(
            StringUtils.isBlank(Global.webServiceAuth) ? "basic" : Global.webServiceAuth);

    setting.setRestservice(enable(Global.restServiceEnabled));
    setting.setRestserviceAuthenticaton(
            StringUtils.isBlank(Global.restServiceAuth) ? "basic" : Global.restServiceAuth);

    setting.setDetectLocaleFromRequest(Global.DetectLocaleFromRequest);

    setting.setVersionCheck(Global.VersionCheck);
    setting.setVersionCheckCron(Global.VersionCheckCron);
    setting.setPurgeDaysOldActivityLog(Global.PurgeDaysOldActivityLog);

    //convert suppress value to names 
    StringBuffer supStr = new StringBuffer();
    if (Global.suppress > 0) {
        for (SUPPRESS sup : SUPPRESS.values()) {
            if ((sup.getValue() & Global.suppress) > 0) {
                supStr.append(sup.name()).append(",");
            }
        }
        if (supStr.length() > 0) {
            supStr.deleteCharAt(supStr.length() - 1);
        }
    }
    setting.setSuppress(supStr.toString());

    setting.setTwitterOauthConsumerKey(Global.TwitterOauthConsumerKey);
    setting.setTwitterOauthConsumerSecret(Global.TwitterOauthConsumerSecret);
}

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);
        url.insert(index, change, 0, 3);
        contains = url.toString().contains(character);
    }//from  www  .j a  va 2s . c o m
}

From source file:com.hihframework.core.utils.BeanUtils.java

public static String getConditions(Object obj, String... excludes) {
    String[] fieldsName = ReflectUtil.getAllFieldsName(obj);
    ArrayList<Object> args = new ArrayList<Object>();
    StringBuffer sb = new StringBuffer();
    for (String fieldName : fieldsName) {
        Object value = ReflectUtil.getFieldValue(obj, fieldName);
        if (fieldName.equals("id"))
            continue;
        for (String exclude : excludes) {
            if (fieldName.equals(exclude))
                continue;
        }/* www  .j a va  2  s.co  m*/
        if (value != null) {
            sb.append(" and " + fieldName + "=?,");
            args.add(value);
        }
    }
    String sql = sb.toString();
    if (sql.endsWith(",")) {
        sb.deleteCharAt(sb.length() - 1);
        sql = sb.toString();
    }
    return sql;
}

From source file:org.wso2.andes.configuration.AndesConfigurationManager.java

private static String getKey(Stack<String> nameStack) {
    StringBuffer key = new StringBuffer();
    for (int i = 0; i < nameStack.size(); i++) {
        String name = nameStack.elementAt(i);
        key.append(name).append(".");
    }//from w  ww . j a v  a 2  s.c o  m
    key.deleteCharAt(key.lastIndexOf("."));

    return key.toString();
}

From source file:com.mg.framework.utils.StringUtils.java

/**
 * Make sure the string starts with a forward slash but does not end with one; converts
 * back-slashes to forward-slashes; if in String is null or empty, returns zero length string.
 *///from  w w  w  .ja  v  a 2s.  co m
public static String cleanUpPathPrefix(String prefix) {
    if (prefix == null || prefix.length() == 0)
        return "";

    StringBuffer cppBuff = new StringBuffer(prefix.replace('\\', '/'));

    if (cppBuff.charAt(0) != '/') {
        cppBuff.insert(0, '/');
    }
    if (cppBuff.charAt(cppBuff.length() - 1) == '/') {
        cppBuff.deleteCharAt(cppBuff.length() - 1);
    }
    return cppBuff.toString();
}