Example usage for java.lang StringBuffer setCharAt

List of usage examples for java.lang StringBuffer setCharAt

Introduction

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

Prototype

@Override
public synchronized void setCharAt(int index, char ch) 

Source Link

Usage

From source file:jdiff.API.java

/** 
 * Convert text with stuffed HTML tags ("lEsS_tHaN", etc) into HTML text.
 *///  w  w  w . j  av  a 2 s  . com
public static String showHTMLTags(String text) {
    StringBuffer sb = new StringBuffer(text);
    StringBuffer res = new StringBuffer();
    int len = sb.length();
    res.setLength(len);
    int i = 0;
    int resIdx = 0;
    while (i < len) {
        char c = sb.charAt(i);
        if (len - i > 8 && c == 'l' && sb.charAt(i + 1) == 'E' && sb.charAt(i + 2) == 's'
                && sb.charAt(i + 3) == 'S' && sb.charAt(i + 4) == '_' && sb.charAt(i + 5) == 't'
                && sb.charAt(i + 6) == 'H' && sb.charAt(i + 7) == 'a' && sb.charAt(i + 8) == 'N') {
            res.setCharAt(resIdx, '<');
            i += 8;
        } else if (len - i > 9 && c == 'q' && sb.charAt(i + 1) == 'U' && sb.charAt(i + 2) == 'o'
                && sb.charAt(i + 3) == 'T' && sb.charAt(i + 4) == 'e' && sb.charAt(i + 5) == '_'
                && sb.charAt(i + 6) == 'c' && sb.charAt(i + 7) == 'H' && sb.charAt(i + 8) == 'a'
                && sb.charAt(i + 9) == 'R') {
            res.setCharAt(resIdx, '"');
            i += 9;
        } else if (len - i > 7 && c == 'a' && sb.charAt(i + 1) == 'N' && sb.charAt(i + 2) == 'd'
                && sb.charAt(i + 3) == '_' && sb.charAt(i + 4) == 'c' && sb.charAt(i + 5) == 'H'
                && sb.charAt(i + 6) == 'a' && sb.charAt(i + 7) == 'R') {
            res.setCharAt(resIdx, '&');
            i += 7;
        } else {
            res.setCharAt(resIdx, c);
        }
        i++;
        resIdx++;
    }
    res.setLength(resIdx);
    return res.toString();
}

From source file:com.flipkart.polyguice.dropwiz.DropConfigProvider.java

private String getNameFromMethod(Method method) {
    if (method.getParameterCount() > 0) {
        return null;
    }/*from  www .j  a  v a  2 s  .  co  m*/
    if (method.getReturnType().equals(Void.TYPE)) {
        return null;
    }

    String mthdName = method.getName();
    if (mthdName.startsWith("get")) {
        if (mthdName.length() <= 3) {
            return null;
        }
        if (method.getReturnType().equals(Boolean.class) || method.getReturnType().equals(Boolean.TYPE)) {
            return null;
        }
        StringBuffer buffer = new StringBuffer(StringUtils.removeStart(mthdName, "get"));
        buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0)));
        return buffer.toString();
    } else if (!mthdName.startsWith("is")) {
        if (mthdName.length() <= 2) {
            return null;
        }
        if (!method.getReturnType().equals(Boolean.class) && !method.getReturnType().equals(Boolean.TYPE)) {
            return null;
        }
        StringBuffer buffer = new StringBuffer(StringUtils.removeStart(mthdName, "is"));
        buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0)));
        return buffer.toString();
    }
    return null;
}

From source file:org.medici.bia.controller.search.SimpleSearchController.java

/**
 * This controller act as a dispatcher for result view.
 *  //w ww  .  j a  v a 2 s.  c  o  m
 * @param command
 * @param result
 * @return
 */
@RequestMapping(method = { RequestMethod.POST })
public ModelAndView processSubmit(@ModelAttribute("command") SimpleSearchCommand command,
        BindingResult result) {
    Map<String, Object> model = new HashMap<String, Object>(0);

    try {
        command.setText(URIUtil.decode(command.getText(), "UTF-8"));
    } catch (URIException e) {
    }
    if (StringUtils.countMatches(command.getText(), "\"") % 2 != 0) {
        StringBuffer tempString = new StringBuffer(command.getText());
        tempString.setCharAt(tempString.lastIndexOf("\""), ' ');
        command.setText(tempString.toString());
    }

    model.put("yourSearch", command.getText());
    // RR: we consider single quote equivalent to double quotes
    model.put("textSearch", command.getText().replace("'", "%22").replace("\"", "%22"));

    // This number is used to generate an unique id for new search
    UUID uuid = UUID.randomUUID();
    command.setSearchUUID(uuid.toString());
    model.put("searchUUID", uuid.toString());

    // Add outputFields;
    List<String> outputFields = getOutputFields(command.getSimpleSearchPerimeter());
    model.put("outputFields", outputFields);
    return new ModelAndView("search/SimpleSearchResult", model);
}

From source file:com.netfinworks.rest.convert.MultiPartFormDataParamConvert.java

private <T> Object getPropertyValue(T pojo, Class<?> clazz, String propertyName, String prefix)
        throws NoSuchMethodException {
    StringBuffer buf = new StringBuffer(propertyName);
    int char0 = buf.charAt(0);
    buf.setCharAt(0, (char) (char0 >= 97 ? char0 - 32 : char0));
    buf.insert(0, prefix);//from   ww w . j a  v  a 2 s  .  c o  m
    Method m = null;
    try {
        m = clazz.getMethod(buf.toString(), emptyClazzArray);
        return m.invoke(pojo, new Object[0]);
    } catch (SecurityException e) {
        logger.debug("property can't be access! ");
        return null;
    } catch (NoSuchMethodException e) {
        logger.debug("property '{}' doesn't exist! ", buf.toString());
        throw e;
    } catch (IllegalArgumentException e) {
        logger.debug("method can't be invoke! wrong argument. " + e.toString());
        return null;
    } catch (IllegalAccessException e) {
        logger.debug("method can't be invoke! access exception. " + e.toString());
        return null;
    } catch (InvocationTargetException e) {
        logger.debug("method can't be invoke! invocation target. " + e.toString());
        return null;
    }

}

From source file:org.medici.bia.controller.search.ExpandResultsSimpleSearchController.java

/**
 * This controller act as a dispatcher for result view.
 *  //from  w  w w. ja  v a  2s  . c  om
 * @param command
 * @param result
 * @return
 */
@RequestMapping(method = { RequestMethod.GET })
public ModelAndView processSubmit(@ModelAttribute("command") ExpandResultsSimpleSearchCommand command,
        BindingResult result) {
    Map<String, Object> model = new HashMap<String, Object>(0);

    try {
        command.setsSearch(URIUtil.decode(command.getsSearch(), "UTF-8"));
    } catch (URIException e) {
    }
    if (StringUtils.countMatches(command.getsSearch(), "\"") % 2 != 0) {
        StringBuffer tempString = new StringBuffer(command.getsSearch());
        tempString.setCharAt(tempString.lastIndexOf("\""), ' ');
        command.setsSearch(tempString.toString());
    }
    //This code is for highlight the correct words
    StringBuffer yourSearch = new StringBuffer();
    if (command.getsSearch().contains("\"")) {
        StringTokenizer stringTokenizer = new StringTokenizer(command.getsSearch().replace('"', ' '), " ");
        while (stringTokenizer.hasMoreTokens()) {
            String currentToken = stringTokenizer.nextToken();
            if (currentToken.length() > 0 && currentToken != "") {
                if (yourSearch.toString().length() > 0)
                    yourSearch.append(" " + currentToken);
                else
                    yourSearch.append(currentToken);
            }
        }
    } else {
        yourSearch.append(command.getsSearch());
    }
    model.put("yourSearch", yourSearch.toString());

    if (command.getsSearch().contains("\"")) {
        command.setsSearch(command.getsSearch().replace("\"", "\\\""));
    }

    // This number is used to generate an unique id for new search
    UUID uuid = UUID.randomUUID();
    command.setSearchUUID(uuid.toString());
    model.put("searchUUID", uuid.toString());

    // Add outputFields;
    List<String> outputFields = getOutputFields(command.getSimpleSearchPerimeter());
    model.put("outputFields", outputFields);
    return new ModelAndView("search/ExpandSimpleSearchResult", model);
}

From source file:com.projity.server.data.MPXConverter.java

public static String removeInvalidChars(String in) { // had case of user with newlines in task names
    if (in == null)
        return null;
    StringBuffer inBuf = new StringBuffer(in);
    for (int i = 0; i < inBuf.length(); i++) {
        char c = inBuf.charAt(i);
        if (c == '\r' || c == '\n' || c == '\t') // using escape chars of the form &#x0000; is not good - they show up in MSP literally. MSP doesn't seem to support newlines anyway
            inBuf.setCharAt(i, ' ');
    }/*w w w  . jav a2 s.  com*/
    return inBuf.toString();

}

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 w ww  . ja va  2  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.atricore.idbus.kernel.main.authn.BaseRoleImpl.java

public String toString() {
    StringBuffer tmp = new StringBuffer(getName());
    tmp.append("(members:");
    Iterator iter = members.keySet().iterator();
    while (iter.hasNext()) {
        tmp.append(iter.next());//from  www .  j  a  v a  2 s .  c  om
        tmp.append(',');
    }
    tmp.setCharAt(tmp.length() - 1, ')');
    return tmp.toString();
}

From source file:org.apache.jackrabbit.standalone.cli.info.Help.java

/**
 * Writes help for all the commands//  w w  w  .j ava 2 s  .  c  o  m
 * @param ctx
 *        the current working <code>Context</code>
 * @throws CommandException
 */
private void helpAll(Context ctx) throws CommandException {
    PrintWriter out = CommandHelper.getOutput(ctx);
    Collection descriptors = factory.getCommandLines();
    Iterator iter = descriptors.iterator();

    // Tab position
    int tabPos = 20;
    while (iter.hasNext()) {
        CommandLine desc = (CommandLine) iter.next();
        if (desc.getName().length() > tabPos) {
            tabPos = desc.getName().length() + 1;
        }
    }

    iter = descriptors.iterator();
    while (iter.hasNext()) {
        CommandLine desc = (CommandLine) iter.next();
        StringBuffer buf = new StringBuffer(desc.getName());
        buf.setLength(tabPos);
        for (int i = desc.getName().length(); i < buf.length(); i++) {
            buf.setCharAt(i, ' ');
        }
        buf.append(desc.getLocalizedDescription());
        hf.printWrapped(out, 70, tabPos, buf.toString());
    }
}

From source file:org.zywx.wbpalmstar.plugin.uexzxing.qrcode.decoder.DecodedBitStreamParser.java

private static void decodeAlphanumericSegment(BitSource bits, StringBuffer result, int count,
        boolean fc1InEffect) throws FormatException {
    // Read two characters at a time
    int start = result.length();
    while (count > 1) {
        int nextTwoCharsBits = bits.readBits(11);
        result.append(toAlphaNumericChar(nextTwoCharsBits / 45));
        result.append(toAlphaNumericChar(nextTwoCharsBits % 45));
        count -= 2;/*from w ww  . ja  v  a 2 s .  c  om*/
    }
    if (count == 1) {
        // special case: one character left
        result.append(toAlphaNumericChar(bits.readBits(6)));
    }
    // See section 6.4.8.1, 6.4.8.2
    if (fc1InEffect) {
        // We need to massage the result a bit if in an FNC1 mode:
        for (int i = start; i < result.length(); i++) {
            if (result.charAt(i) == '%') {
                if (i < result.length() - 1 && result.charAt(i + 1) == '%') {
                    // %% is rendered as %
                    result.deleteCharAt(i + 1);
                } else {
                    // In alpha mode, % should be converted to FNC1 separator 0x1D
                    result.setCharAt(i, (char) 0x1D);
                }
            }
        }
    }
}