Example usage for java.lang StringBuffer append

List of usage examples for java.lang StringBuffer append

Introduction

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

Prototype

@Override
    public synchronized StringBuffer append(double d) 

Source Link

Usage

From source file:Main.java

private static String parseEndXMLCData(String strValue) {
    int pos = strValue.indexOf("]]>");
    StringBuffer sb = new StringBuffer();
    if (pos > -1) {
        sb.append("<![CDATA[");
        sb.append(strValue.substring(0, pos + 1));
        sb.append("]]>");
        sb.append(parseEndXMLCData(strValue.substring(pos + 1)));
    } else {/*from   w ww . j a  v a 2  s .  c  o  m*/
        sb.append("<![CDATA[");
        sb.append(strValue);
        sb.append("]]>");
    }
    return sb.toString();
}

From source file:Main.java

private static void initPattern() {
    StringBuffer buf = new StringBuffer();
    buf.append('<');
    buf.append(whitespace);/* ww w  .j  a v a2 s  .  co  m*/
    buf.append(titleTag);
    buf.append('>');
    buf.append("(.*?)"); //$NON-NLS-1$
    buf.append('<');
    buf.append(whitespace);
    buf.append('/');
    buf.append(whitespace);
    buf.append(titleTag);
    buf.append('>');

    titlePattern = Pattern.compile(buf.toString());
}

From source file:Main.java

public static String toTitleCase(String givenString) {
    if (givenString.length() > 0) {
        String[] arr = givenString.split(" ");
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr.length; i++) {
            sb.append(Character.toUpperCase(arr[i].charAt(0))).append(arr[i].substring(1)).append(" ");
        }//from   w ww.  j a va2  s  .c o m
        return sb.toString().trim();
    }
    return "";
}

From source file:Main.java

public static Templates TrAXPath(String xpath) throws TransformerConfigurationException {
    StringBuffer sb = new StringBuffer();

    sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
    sb.append("<xsl:stylesheet version=\"1.0\" ");
    sb.append(" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">");
    sb.append("<xsl:output method=\"xml\" indent=\"yes\"/>");
    sb.append("<xsl:template match=\"" + xpath + "\">");
    sb.append("<xsl:copy-of select=\".\"/>");
    sb.append("</xsl:template>");
    sb.append("<xsl:template match=\"*|@*|text()\">");
    sb.append("<xsl:apply-templates />");
    sb.append("</xsl:template>");
    sb.append("</xsl:stylesheet>");

    TransformerFactory tf = TransformerFactory.newInstance();
    String stylesheet = sb.toString();
    Reader r = new StringReader(stylesheet);
    StreamSource ssrc = new StreamSource(r);

    return tf.newTemplates(ssrc);
}

From source file:Main.java

/**
 * returns a string where each object in the give {@code Collection} is placed on a new line
 * (i.e [foo, bar, bizz] -> <br/> foo <br/> bar <br/> bizz)
 * @param collection a given {@code Collection} of type {@code T}
 * @return/*from   w  ww . ja va  2 s  .c o  m*/
 */
public static <T> String lineSeparatedCollection(Collection<T> collection) {
    StringBuffer sb = new StringBuffer("");
    for (T item : collection) {
        sb.append(item.toString()).append(LINE_SEPARATOR);
    }
    return sb.deleteCharAt(sb.lastIndexOf(LINE_SEPARATOR)).toString();
}

From source file:Main.java

/**
 * returns a string where each object in the give {@code Collection} is placed on a new line
 * (i.e [foo, bar, bizz] -> <br/> foo <br/> bar <br/> bizz)
 * @param collection a given {@code Array} of type {@code T}
 * @return//from w  w w.  j a va  2s.co  m
 */
public static <T> String lineSeparatedCollection(T... collection) {
    StringBuffer sb = new StringBuffer("");
    for (T item : collection) {
        sb.append(item.toString()).append(LINE_SEPARATOR);
    }
    return sb.deleteCharAt(sb.lastIndexOf(LINE_SEPARATOR)).toString();
}

From source file:Main.java

/**
 * prints the passed array/*from w  w  w.j  a v a2  s.  c  o  m*/
 * @param _tag the tag for the print
 * @param arr the array to print
 */
public static void printArray(String _tag, double[] arr) {
    StringBuffer sb = new StringBuffer();

    for (int i = 0; i < arr.length; i++) {
        sb.append(arr[i]);
        sb.append("\n");
    }
    Log.e(_tag, sb.toString());
    Log.e(_tag, "--------------------");
}

From source file:Main.java

private static StringBuffer getHeaderXMLChunk() {

    StringBuffer header = new StringBuffer();

    header.append("<Header>");

    header.append("<From>");
    header.append("<Credential domain=\"DUNS\">");
    header.append("<Identity>" + vendorDUNSNumber + "</Identity>");
    header.append("</Credential>");
    header.append("</From>");

    header.append("<To>");
    header.append("<Credential domain=\"DUNS\">");
    header.append("<Identity>IU</Identity>");
    header.append("</Credential>");
    header.append("</To>");

    header.append("<Sender>");
    header.append("<Credential domain=\"DUNS\">");
    header.append("<Identity>" + vendorDUNSNumber + "</Identity>");
    header.append("<SharedSecret>INDIANA</SharedSecret>");
    header.append("</Credential>");
    header.append("<UserAgent/>");
    header.append("</Sender>");

    header.append("</Header>");

    return header;
}

From source file:Main.java

/**
 * Returns attribute's setter method. If the method not found then
 * NoSuchMethodException will be thrown.
 * /*from w  w  w.  j  a v a  2s . c om*/
 * @param cls
 *          the class the attribute belongs to
 * @param attr
 *          the attribute's name
 * @param type
 *          the attribute's type
 * @return attribute's setter method
 * @throws NoSuchMethodException
 *           if the setter was not found
 */
public final static Method getAttributeSetter(Class cls, String attr, Class type) throws NoSuchMethodException {
    StringBuffer buf = new StringBuffer(attr.length() + 3);
    buf.append("set");
    if (Character.isLowerCase(attr.charAt(0))) {
        buf.append(Character.toUpperCase(attr.charAt(0))).append(attr.substring(1));
    } else {
        buf.append(attr);
    }

    return cls.getMethod(buf.toString(), new Class[] { type });
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static String map2Xml(Map map, String encode, String root) {
    StringBuffer sb = new StringBuffer();
    sb.append("<" + root + ">");// <?xml version=\"1.0\"
    // encoding=\""+encode+"\"?>
    mapToXml(map, sb);/*from  w  ww.  jav  a2s. co  m*/
    sb.append("</" + root + ">");
    try {
        return sb.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}