Example usage for java.io StringWriter append

List of usage examples for java.io StringWriter append

Introduction

In this page you can find the example usage for java.io StringWriter append.

Prototype

public StringWriter append(char c) 

Source Link

Document

Appends the specified character to this writer.

Usage

From source file:com.espertech.esper.epl.expression.core.ExprNodeUtility.java

public static void toExpressionStringParameterList(List<ExprNode> parameters, StringWriter buffer) {
    String delimiter = "";
    for (ExprNode param : parameters) {
        buffer.append(delimiter);
        delimiter = ",";
        buffer.append(ExprNodeUtility.toExpressionStringMinPrecedenceSafe(param));
    }// w  w w . ja v a  2  s  .  com
}

From source file:com.espertech.esper.epl.expression.core.ExprNodeUtility.java

public static void toExpressionStringParameterList(ExprNode[] childNodes, StringWriter buffer) {
    String delimiter = "";
    for (ExprNode childNode : childNodes) {
        buffer.append(delimiter);
        buffer.append(ExprNodeUtility.toExpressionStringMinPrecedenceSafe(childNode));
        delimiter = ",";
    }/*from  www .  j ava2s . c o m*/
}

From source file:com.amalto.core.server.MDMTransaction.java

@Override
public String getCreationStackTrace() {
    String eol = System.getProperty("line.separator"); //$NON-NLS-1$
    StringWriter writer = new StringWriter();
    if (this.creationStackTrace != null) {
        writer.write(/*  ww w  . j av a  2 s . c o m*/
                "==================================================================================" + eol); //$NON-NLS-1$
        writer.write("MDM Transaction creation stacktrace:" + eol); //$NON-NLS-1$
        for (StackTraceElement s : this.creationStackTrace) {
            writer.append(s.toString());
            writer.append(eol);
        }
        writer.write(
                "==================================================================================" + eol); //$NON-NLS-1$
    } else {
        writer.append("No creationStackTrace captured at transaction creation. Activate DEBUG on " //$NON-NLS-1$
                + MDMTransaction.class.getCanonicalName() + " to capture future transactions."); //$NON-NLS-1$
    }
    return writer.toString();
}

From source file:com.ibm.watson.developer_cloud.professor_languo.model.stack_exchange.Post.java

@Override
public String toString() {
    StringWriter w = new StringWriter();
    w.append("\n<Post>\n");
    w.append("\t{id: " + id.toString() + "\n");
    w.append("\tpostType: " + printIfNotNull(postType) + "\n");
    w.append("\tparentId: " + printIfNotNull(parentId) + "\n");
    w.append("\ttitle: " + printIfNotNull(title) + "\n");
    w.append("\tbody: " + printIfNotNull(body) + "\n");
    w.append("\ttags: " + printIfNotNull(tags) + "\n");
    w.append("\tacceptedAnswerId: " + printIfNotNull(acceptedAnswerId) + "\n");
    w.append("\tscore: " + printIfNotNull(score) + "\n");
    w.append("\tviewCount: " + printIfNotNull(viewCount) + "\n");
    w.append("\townerUserId: " + printIfNotNull(ownerUserId) + "\n");
    w.append("\tlastEditorUserId: " + printIfNotNull(lastEditorUserId) + "\n");
    w.append("\tcreationDate: " + printIfNotNull(creationDate) + "\n");
    w.append("\tclosedDate: " + printIfNotNull(closedDate) + "\n");
    w.append("\tlastEditDate: " + printIfNotNull(lastEditDate) + "\n");
    w.append("\tlastActivityDate: " + printIfNotNull(lastActivityDate) + "\n");
    w.append("\tanswerCount: " + printIfNotNull(answerCount) + "\n");
    w.append("\tcommentCount: " + printIfNotNull(commentCount) + "\n");
    w.append("\tfavoriteCount: " + printIfNotNull(favoriteCount));
    w.append("\n\t}\n");
    return w.toString();
}

From source file:com.espertech.esper.epl.expression.core.ExprNodeUtility.java

public static String toExpressionStringMinPrecedence(ExprNode[] nodes) {
    StringWriter writer = new StringWriter();
    String delimiter = "";
    for (ExprNode node : nodes) {
        writer.append(delimiter);
        node.toEPL(writer, ExprPrecedenceEnum.MINIMUM);
        delimiter = ",";
    }/*from  ww  w  . j  ava 2 s  . c o m*/
    return writer.toString();
}

From source file:nl.knaw.dans.dccd.rest.AbstractProjectResource.java

protected void appendProjectObjectTypesAsXml(java.io.StringWriter sw, DccdSB dccdSB) {
    if (dccdSB.hasTridasObjectType()) {
        // avoid duplicates
        List<String> types = StringUtil.getUniqueStrings(dccdSB.getTridasObjectType());

        sw.append("<objectTypes>");
        for (String type : types) {
            sw.append(getXMLElementString("objectType", type));
        }/*from ww w . j a  va  2s.  co  m*/
        sw.append("</objectTypes>");
    }
    // Note: what to do with normal and normalId ?
}

From source file:nl.knaw.dans.dccd.rest.AbstractProjectResource.java

protected void appendProjectElementTypesAsXml(java.io.StringWriter sw, DccdSB dccdSB) {
    if (dccdSB.hasTridasElementType()) {
        // avoid duplicates
        List<String> types = StringUtil.getUniqueStrings(dccdSB.getTridasElementType());

        sw.append("<elementTypes>");
        for (String type : types) {
            sw.append(getXMLElementString("elementType", type));
        }//from  w w w .  ja  v a 2  s .  c o  m
        sw.append("</elementTypes>");
    }
    // Note: what to do with normal and normalId ?
}

From source file:nl.knaw.dans.dccd.rest.AbstractProjectResource.java

protected void appendProjectTaxonsAsXml(java.io.StringWriter sw, DccdSB dccdSB) {
    if (dccdSB.hasTridasElementTaxon()) {
        // avoid duplicates
        List<String> taxons = StringUtil.getUniqueStrings(dccdSB.getTridasElementTaxon());

        sw.append("<taxons>");
        for (String taxon : taxons) {
            sw.append(getXMLElementString("taxon", taxon));
        }//  ww w .j av a2s  .c  om
        sw.append("</taxons>");
    }
}

From source file:com.espertech.esper.epl.expression.core.ExprNodeUtility.java

public static String printEvaluators(ExprEvaluator[] evaluators) {
    StringWriter writer = new StringWriter();
    String delimiter = "";
    for (ExprEvaluator evaluator : evaluators) {
        writer.append(delimiter);
        writer.append(evaluator.getClass().getSimpleName());
        delimiter = ", ";
    }//  w w  w  . j  a  va2 s  . co m
    return writer.toString();
}

From source file:gate.crowdsource.rest.CrowdFlowerClient.java

/**
 * Create a new entity classification job on CrowdFlower.
 * /*from  ww w. j a  va2 s.  c  o  m*/
 * @param title the job title
 * @param instructions the instructions
 * @param caption a caption for the answer form, which can include an
 *          {{entity}} placeholder which will be replaced by the text
 *          of the entity being classified (e.g.
 *          "choose the most appropriate description for {{entity}}")
 * @param commonOptions common options that should be presented for
 *          all tasks, in addition to the specific options for that
 *          task extracted from the entity annotation. This is
 *          expressed as a List of [value, description] two-element
 *          Lists, one for each option.
 * @return the newly created job ID.
 * @throws IOException
 */
public long createClassificationJob(String title, String instructions, String caption,
        List<List<String>> commonOptions) throws IOException {
    log.debug("Creating classification job");
    log.debug("title: " + title);
    log.debug("instructions: " + instructions);
    log.debug("caption: " + caption);
    log.debug("options: " + commonOptions);
    // load the custom CSS that makes entity highlighting work
    InputStream cssStream = CrowdFlowerClient.class.getResourceAsStream("gate-crowdflower.css");
    String css = null;
    try {
        css = IOUtils.toString(cssStream, "UTF-8");
    } finally {
        cssStream.close();
    }
    StringWriter cml = new StringWriter();

    // construct the CML with the specified caption and common radio
    // options
    cml.append("<h2 id=\"unit_text\">{{text}}</h2>\n\n" + "{% if detail %}\n"
            + "  <div class=\"well\">{{detail}}</div>\n" + "{% endif %}\n"
            + "<cml:radios validates=\"required\" label=\"");
    StringEscapeUtils.escapeXml(cml, caption);
    cml.append("\" name=\"answer\">\n" + "  {% for opt in options %}\n" + "    {% if opt.description %}\n"
            + "      {% assign desc = opt.description %}\n" + "    {% else %}\n"
            + "      {% assign desc = opt.value %}\n" + "    {% endif %}\n"
            + "    <cml:radio value=\"{{opt.value}}\" label=\"{{desc}}\" />\n" + "  {% endfor %}\n");
    if (commonOptions != null) {
        for (List<String> opt : commonOptions) {
            cml.append("  <cml:radio value=\"");
            StringEscapeUtils.escapeXml(cml, opt.get(0));
            cml.append("\" label=\"");
            StringEscapeUtils.escapeXml(cml, opt.get(1));
            cml.append("\" />\n");
        }
    }
    cml.append("</cml:radios>\n");

    log.debug("cml: " + cml.toString());

    log.debug("POSTing to CrowdFlower");
    JsonElement json = post("/jobs", "job[title]", title, "job[instructions]", instructions, "job[cml]",
            cml.toString(), "job[css]", css);
    log.debug("CrowdFlower returned " + json);
    try {
        return json.getAsJsonObject().get("id").getAsLong();
    } catch (Exception e) {
        throw new GateRuntimeException("Failed to create CF job");
    }
}