Example usage for java.lang StringBuffer charAt

List of usage examples for java.lang StringBuffer charAt

Introduction

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

Prototype

@Override
public synchronized char charAt(int index) 

Source Link

Usage

From source file:com.bdaum.juploadr.uploadapi.locrrest.LocrMethod.java

private void appendNVP(StringBuffer url, String name, String value) {
    if (url.length() == 0) {
        url.append("?"); //$NON-NLS-1$
    }//from   w  w w .  java 2s.  com
    char lastChar = url.charAt(url.length() - 1);
    if (lastChar != '&' && lastChar != '?') {
        url.append("&"); //$NON-NLS-1$
    }
    url.append(name);
    url.append("="); //$NON-NLS-1$
    url.append(encode(value));
}

From source file:com.alkacon.opencms.geomap.CmsGoogleMapWidget.java

/**
 * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
 *///from   ww w.ja  v a2  s.co m
public String getDialogWidget(final CmsObject cms, final I_CmsWidgetDialog widgetDialog,
        final I_CmsWidgetParameter param) {

    final String id = param.getId();
    final CmsGoogleMapWidgetValue value = new CmsGoogleMapWidgetValue(param.getStringValue(cms));
    final CmsXmlMessages templates = new CmsXmlMessages(cms, CmsGoogleMapWidget.TEMPLATE_FILE);

    // create macro resolver with macros for form field value replacement
    final CmsMacroResolver resolver = new CmsXmlMessages(cms, CmsGoogleMapWidget.MESSAGES_FILE)
            .getMacroResolver();
    // set cms object and localized messages in resolver
    resolver.setCmsObject(cms);
    resolver.addMacro("id", id);
    resolver.addMacro("value", value.toString());
    resolver.addMacro("options", getWidgetOption().getEditString());
    resolver.addMacro("button", resolver.resolveMacros(templates.key("Button")));
    resolver.addMacro("node", param.getName());
    resolver.addMacro("width", "" + value.getWidth());
    resolver.addMacro("height", "" + value.getHeight());

    final StringBuffer sbInline = new StringBuffer();
    final Iterator<CmsGoogleMapOption> itInline = getWidgetOption().getInline().iterator();
    while (itInline.hasNext()) {
        final CmsGoogleMapOption prop = itInline.next();
        final StringBuffer xpath = new StringBuffer(prop.toString());
        xpath.setCharAt(0, Character.toUpperCase(xpath.charAt(0)));
        sbInline.append(resolver.resolveMacros(templates.key(xpath.toString())));
    }
    resolver.addMacro("inline.properties", sbInline.toString());

    final StringBuffer sbPopup = new StringBuffer();
    final Iterator<CmsGoogleMapOption> itPopup = getWidgetOption().getPopup().iterator();
    while (itPopup.hasNext()) {
        final CmsGoogleMapOption prop = itPopup.next();
        final StringBuffer xpath = new StringBuffer(prop.toString());
        xpath.setCharAt(0, Character.toUpperCase(xpath.charAt(0)));
        sbPopup.append(resolver.resolveMacros(templates.key(xpath.toString())));
    }
    resolver.addMacro("popup.properties", sbPopup.toString());

    final StringBuffer result = new StringBuffer(4096);
    result.append("<td class=\"xmlTd\">");
    result.append(resolver.resolveMacros(templates.key("Main")));
    result.append("</td>");

    return result.toString();
}

From source file:org.apache.axis.utils.JavaUtils.java

/**
 * Makes the value passed in <code>initValue</code> unique among the
 * {@link String} values contained in <code>values</code> by suffixing
 * it with a decimal digit suffix./*from   w w w .j a  v a2 s .co m*/
 */
public static String getUniqueValue(Collection values, String initValue) {

    if (!values.contains(initValue)) {
        return initValue;
    } else {

        StringBuffer unqVal = new StringBuffer(initValue);
        int beg = unqVal.length(), cur, end;
        while (Character.isDigit(unqVal.charAt(beg - 1))) {
            beg--;
        }
        if (beg == unqVal.length()) {
            unqVal.append('1');
        }
        cur = end = unqVal.length() - 1;

        while (values.contains(unqVal.toString())) {

            if (unqVal.charAt(cur) < '9') {
                unqVal.setCharAt(cur, (char) (unqVal.charAt(cur) + 1));
            }

            else {

                while (cur-- > beg) {
                    if (unqVal.charAt(cur) < '9') {
                        unqVal.setCharAt(cur, (char) (unqVal.charAt(cur) + 1));
                        break;
                    }
                }

                // See if there's a need to insert a new digit.
                if (cur < beg) {
                    unqVal.insert(++cur, '1');
                    end++;
                }
                while (cur < end) {
                    unqVal.setCharAt(++cur, '0');
                }

            }

        }

        return unqVal.toString();

    } /*  For  else  clause  of  selection-statement   If(!values ...   */

}

From source file:org.lockss.util.UrlUtil.java

public static String normalizeUrlEncodingCase(String str) {
    if (!normalizeUrlEncodingCase) {
        return str;
    }//  www. j  av  a 2 s. co m
    int pos = str.indexOf('%');
    if (pos < 0) {
        return str;
    }
    StringBuffer sb = new StringBuffer(str);
    int len = str.length();
    do {
        if (len < pos + 3) {
            break;
        }
        char ch;
        if (Character.isLowerCase(ch = sb.charAt(pos + 1))) {
            sb.setCharAt(pos + 1, Character.toUpperCase(ch));
        }
        if (Character.isLowerCase(ch = sb.charAt(pos + 2))) {
            sb.setCharAt(pos + 2, Character.toUpperCase(ch));
        }
    } while ((pos = str.indexOf('%', pos + 3)) >= 0);
    return sb.toString();
}

From source file:org.zebrafish.feature.AbstractFieldList.java

public String toURLString() {
    if (isEmpty()) {
        return StringUtils.EMPTY;
    }//from w w w.  j ava2  s  .  co  m

    StringBuffer sb = createStringBuffer();
    for (T t : this) {
        String fieldURLString = t.toURLString();
        if (StringUtils.isNotEmpty(fieldURLString)) {
            sb.append(fieldURLString);
            sb.append(getSeparator());
        }
    }

    return sb.charAt(sb.length() - 1) == Separator.EQUAL.getSymbol() ? StringUtils.EMPTY
            : sb.deleteCharAt(sb.length() - 1).toString();
}

From source file:org.apache.velocity.runtime.parser.node.PropertyExecutor.java

/**
 * @param clazz//  ww  w .  j  av a2  s  . com
 * @param property
 */
protected void discover(final Class clazz, final String property) {
    /*
     *  this is gross and linear, but it keeps it straightforward.
     */

    try {
        Object[] params = {};

        StringBuffer sb = new StringBuffer("get");
        sb.append(property);

        setMethod(introspector.getMethod(clazz, sb.toString(), params));

        if (!isAlive()) {
            /*
             *  now the convenience, flip the 1st character
             */

            char c = sb.charAt(3);

            if (Character.isLowerCase(c)) {
                sb.setCharAt(3, Character.toUpperCase(c));
            } else {
                sb.setCharAt(3, Character.toLowerCase(c));
            }

            setMethod(introspector.getMethod(clazz, sb.toString(), params));
        }
    }
    /**
     * pass through application level runtime exceptions
     */
    catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        String msg = "Exception while looking for property getter for '" + property;
        Logger.error(this, msg, e);
        throw new VelocityException(msg, e);
    }
}

From source file:org.xwiki.rendering.internal.parser.reference.GenericLinkReferenceParser.java

/**
 * Count the number of escape chars before a given character and if that number is odd then that character should be
 * escaped.//from  www.j  a v a 2 s  .  co m
 * 
 * @param content the content in which to check for escapes
 * @param charPosition the position of the char for which to decide if it should be escaped or not
 * @return true if the character should be escaped
 */
private boolean shouldEscape(StringBuffer content, int charPosition) {
    int counter = 0;
    int pos = charPosition - 1;
    while (pos > -1 && content.charAt(pos) == ESCAPE_CHAR) {
        counter++;
        pos--;
    }
    return (counter % 2 != 0);
}

From source file:org.chiba.xml.xforms.xpath.ExtensionFunctionsHelper.java

/**
 * Returns a date parsed from a date/dateTime string formatted accorings to
 * ISO 8601 rules.// www.  j  a  v a  2s .  c om
 *
 * @param date the formatted date/dateTime string.
 * @return the parsed date.
 * @throws ParseException if the date/dateTime string could not be parsed.
 */
public static Date parseISODate(String date) throws ParseException {
    String pattern;
    StringBuffer buffer = new StringBuffer(date);

    switch (buffer.length()) {
    case 4:
        // Year: yyyy (eg 1997)
        pattern = "yyyy";
        break;
    case 7:
        // Year and month: yyyy-MM (eg 1997-07)
        pattern = "yyyy-MM";
        break;
    case 10:
        // Complete date: yyyy-MM-dd (eg 1997-07-16)
        pattern = "yyyy-MM-dd";
        break;
    default:
        // Complete date plus hours and minutes: yyyy-MM-ddTHH:mmTZD (eg 1997-07-16T19:20+01:00)
        // Complete date plus hours, minutes and seconds: yyyy-MM-ddTHH:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
        // Complete date plus hours, minutes, seconds and a decimal fraction of a second: yyyy-MM-ddTHH:mm:ss.STZD (eg 1997-07-16T19:20:30.45+01:00)
        pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";

        if (buffer.length() == 16) {
            // add seconds
            buffer.append(":00");
        }
        if (buffer.length() > 16 && buffer.charAt(16) != ':') {
            // insert seconds
            buffer.insert(16, ":00");
        }
        if (buffer.length() == 19) {
            // add milliseconds
            buffer.append(".000");
        }
        if (buffer.length() > 19 && buffer.charAt(19) != '.') {
            // insert milliseconds
            buffer.insert(19, ".000");
        }
        if (buffer.length() == 23) {
            // append timzeone
            buffer.append("+0000");
        }
        if (buffer.length() == 24 && buffer.charAt(23) == 'Z') {
            // replace 'Z' with '+0000'
            buffer.replace(23, 24, "+0000");
        }
        if (buffer.length() == 29 && buffer.charAt(26) == ':') {
            // delete '.' from 'HH:mm'
            buffer.deleteCharAt(26);
        }
    }

    // always set time zone on formatter
    SimpleDateFormat format = new SimpleDateFormat(pattern);
    final String dateFromBuffer = buffer.toString();
    if (dateFromBuffer.length() > 10) {
        format.setTimeZone(TimeZone.getTimeZone("GMT" + dateFromBuffer.substring(23)));
    }
    if (!format.format(format.parse(dateFromBuffer)).equals(dateFromBuffer)) {
        throw new ParseException("Not a valid ISO date", 0);
    }
    format.setTimeZone(TimeZone.getTimeZone("UTC"));

    return format.parse(buffer.toString());
}

From source file:bboss.org.apache.velocity.runtime.parser.node.PropertyExecutor.java

/**
 * @param clazz/*from www  .  j  a v  a2  s .c o m*/
 * @param property
 */
protected void discover(final Class clazz, final String property) {
    /*
     *  this is gross and linear, but it keeps it straightforward.
     */

    try {
        Object[] params = {};

        StringBuffer sb = new StringBuffer("get");
        sb.append(property);

        setMethod(introspector.getMethod(clazz, sb.toString(), params));

        if (!isAlive()) {
            /*
             *  now the convenience, flip the 1st character
             */

            char c = sb.charAt(3);

            if (Character.isLowerCase(c)) {
                sb.setCharAt(3, Character.toUpperCase(c));
            } else {
                sb.setCharAt(3, Character.toLowerCase(c));
            }

            setMethod(introspector.getMethod(clazz, sb.toString(), params));
        }
    }
    /**
     * pass through application level runtime exceptions
     */
    catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        String msg = "Exception while looking for property getter for '" + property;
        log.error(msg, e);
        throw new VelocityException(msg, e);
    }
}

From source file:com.pactera.edg.am.metamanager.extractor.dao.impl.SequenceDaoImpl.java

public String getUuid() {
    StringBuffer uuid = new StringBuffer();
    try {//from   w w w .ja  v  a 2 s.  c om
        uuid.append(UUID.randomUUID().toString());
    } catch (Exception e) {
        this.createUUIDGen();
        uuid.append(uuidGen.nextUUID());
    }
    if (uuid.length() == 0) {
        throw new RuntimeException("UUID generate fail");
    }
    uuid.setCharAt(0, shiftHex(uuid.charAt(0))); //hibernateuuid.hex??
    return uuid.toString().replaceAll("-", "");
}