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:nl.knaw.dans.dccd.web.search.SearchResultDataConverter.java

private static String getDetailedXML(final DccdSB dccdSB, final ProjectPermissionLevel effectivelevel) {
    java.io.StringWriter sw = new StringWriter();

    // add extra object level information
    // type, title and location is allready handled
    // so nothing more, just go into the element level
    sw.append(getElementXML(dccdSB, effectivelevel));
    sw.append(getSeriesXML(dccdSB, effectivelevel));

    return sw.toString();
}

From source file:com.espertech.esper.epl.spec.PatternStreamSpecRaw.java

private static String getPatternSubexEventType(String statementId, String objectType,
        Deque<Integer> subexpressionIdStack) {
    StringWriter writer = new StringWriter();
    writer.append(statementId);
    writer.append("_");
    writer.append(objectType);//from   w w  w  .j  av  a 2 s  . com
    for (Integer num : subexpressionIdStack) {
        writer.append("_");
        writer.append(Integer.toString(num));
    }
    return writer.toString();
}

From source file:com.alibaba.jstorm.yarn.utils.JstormYarnUtils.java

public static String stringify(Throwable t) {
    StringWriter sw = new StringWriter();
    sw.append(t.toString()).append('\n');
    t.printStackTrace(new PrintWriter(sw));
    return sw.toString();
}

From source file:nl.knaw.dans.dccd.web.search.SearchResultDataConverter.java

private static String getLocationXML(final DccdSB dccdSB, final boolean isAllowedToViewLocation) {
    java.io.StringWriter sw = new StringWriter();

    // Get the Lat and Lng 
    if (dccdSB.hasLatLng()) {
        //logger.debug("Geo location: (" + dccdSB.getLng() + "," + dccdSB.getLat() + ")");
        if (isAllowedToViewLocation) {
            // Note, not sure if we are certain to have decimal '.' ???
            sw.append(getXMLElementString(NAME_LONGITUDE, dccdSB.getLng().toString()));
            sw.append(getXMLElementString(NAME_LATITUDE, dccdSB.getLat().toString()));
        } else {/*from   w  w  w.  j a v  a 2  s .co m*/
            // not permitted
            sw.append(getXMLElementString(NAME_LONGITUDE, VALUE_NOT_PERMITTED));
            sw.append(getXMLElementString(NAME_LATITUDE, VALUE_NOT_PERMITTED));
        }
    } else {
        // add empty elements
        sw.append(getXMLElementString(NAME_LONGITUDE, ""));
        sw.append(getXMLElementString(NAME_LATITUDE, ""));
    }

    return sw.toString();
}

From source file:com.yunshan.cloudstack.vmware.util.VmwareHelper.java

public static String getExceptionMessage(Throwable e, boolean printStack) {
    // TODO: in vim 5.1, exceptions do not have a base exception class,
    // MethodFault becomes a FaultInfo that we can only get
    // from individual exception through getFaultInfo, so we have to use
    // reflection here to get MethodFault information.
    try {//from   ww  w.ja va 2s . com
        Class<? extends Throwable> cls = e.getClass();
        Method mth = cls.getDeclaredMethod("getFaultInfo", (Class<?>) null);
        if (mth != null) {
            Object fault = mth.invoke(e, (Object[]) null);
            if (fault instanceof MethodFault) {
                final StringWriter writer = new StringWriter();
                writer.append("Exception: " + fault.getClass().getName() + "\n");
                writer.append("message: " + ((MethodFault) fault).getFaultMessage() + "\n");

                if (printStack) {
                    writer.append("stack: ");
                    e.printStackTrace(new PrintWriter(writer));
                }
                return writer.toString();
            }
        }
    } catch (Exception ex) {

    }

    return ExceptionUtil.toString(e, printStack);
}

From source file:dk.statsbiblioteket.util.xml.DOM.java

/**
 * Extracts all textual and CDATA content from the given node and its
 * children.//from  w  w  w  .  j a  va  2 s  .  c  om
 *
 * @param node the node to get the content from.
 * @return the textual content of node.
 */
public static String getElementNodeValue(Node node) {
    StringWriter sw = new StringWriter(2000);
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        NodeList all = node.getChildNodes();
        for (int i = 0; i < all.getLength(); i++) {
            if (all.item(i).getNodeType() == Node.TEXT_NODE
                    || all.item(i).getNodeType() == Node.CDATA_SECTION_NODE) {
                // TODO: Check if we exceed the limit for getNodeValue
                sw.append(all.item(i).getNodeValue());
            }
        }
    }
    return sw.toString();
}

From source file:nl.knaw.dans.dccd.web.search.SearchResultDataConverter.java

private static String getSeriesXML(final DccdSB dccdSB, final ProjectPermissionLevel effectivelevel) {
    java.io.StringWriter sw = new StringWriter();

    if (ProjectPermissionLevel.SERIES.isPermittedBy(effectivelevel)) {
        // measurementseries.firstyear, lastyear, pithyear, deathyear
        //sw.append(getXMLElementString(NAME_SERIES_ID, getSeriesIdentfierString(dccdSB)));
        // NOTE Series ID was always empty, not sure why
        sw.append(getXMLElementString(NAME_SERIES_FIRSTYEAR, getFirstYearString(dccdSB)));
        sw.append(getXMLElementString(NAME_SERIES_LASTYEAR, getLastYearString(dccdSB)));
        sw.append(getXMLElementString(NAME_SERIES_PITHYEAR, getPithYearString(dccdSB)));
        sw.append(getXMLElementString(NAME_SERIES_DEATHYEAR, getDeathYearString(dccdSB)));

        // TODO ? woodcompleteness.nrofrings , nrofsapwoodrings
        //getTridasRadiusWoodcompletenessSapwoodNrofsapwoodrings()
        // but .nrofrings is not indexed right now!
        // woodcompleteness is available on Radius and Series level, but indexed on radius?
        // however just show it under series, using this deeper (saver) permission level!
        // Ehhhh, woodcompleness is only indexed with data from Radius level, not series...
        // so this would need changing a lot of code and reindex...
    } else {/*w w w .  jav  a  2s  . co m*/
        // not permitted
        //sw.append(getXMLElementString(NAME_SERIES_ID, VALUE_NOT_PERMITTED));
        // NOTE Series ID was always empty, not sure why
        sw.append(getXMLElementString(NAME_SERIES_FIRSTYEAR, VALUE_NOT_PERMITTED));
        sw.append(getXMLElementString(NAME_SERIES_LASTYEAR, VALUE_NOT_PERMITTED));
        sw.append(getXMLElementString(NAME_SERIES_PITHYEAR, VALUE_NOT_PERMITTED));
        sw.append(getXMLElementString(NAME_SERIES_DEATHYEAR, VALUE_NOT_PERMITTED));
    }

    return sw.toString();
}

From source file:nl.knaw.dans.dccd.web.search.SearchResultDataConverter.java

public static String getResultsAsXML(final SearchResult<? extends DccdSB> searchResults, final DccdUser user) {
    java.io.StringWriter sw = new StringWriter();

    int index = 0; // for logging
    for (SearchHit<? extends DccdSB> hit : searchResults.getHits()) {
        DccdSB dccdSB = hit.getData();//from w  w  w.j  a va 2s.  c om
        index++;
        // Determine if it is permitted to show it
        logger.debug("Hit(" + index + "): " + dccdSB.getId() + " level: " + dccdSB.getPermissionDefaultLevel());

        sw.append("<" + NAME_RESULT + ">");
        // project
        sw.append(getXMLElementString(NAME_PROJECT_LAB, getProjectLabString(dccdSB)));
        sw.append(getXMLElementString(NAME_PROJECT_ID, getProjectIdentfierString(dccdSB)));
        sw.append(getXMLElementString(NAME_PROJECT_TITLE, getProjectTitleString(dccdSB)));
        // object
        sw.append(getXMLElementString(NAME_OBJECT_TITLE, getObjectTitleString(dccdSB)));
        sw.append(getXMLElementString(NAME_OBJECT_TYPE, getObjectTypeString(dccdSB)));

        // Location info
        // The location is from the ObjectEntity 'Level'
        // allow only if admin, or owner, or level is "object" or better...
        ProjectPermissionLevel effectivelevel = dccdSB.getEffectivePermissionLevel(user);
        Boolean isAllowedToViewLocation = ProjectPermissionLevel.OBJECT.isPermittedBy(effectivelevel);
        sw.append(getLocationXML(dccdSB, isAllowedToViewLocation));

        // Detailed info below
        // Note that we need to specify if the data is there but we are not allowed to see it
        // and what do we do with multiple instances; comma seperated in Solr!
        sw.append(getDetailedXML(dccdSB, effectivelevel));

        sw.append("</" + NAME_RESULT + ">");
    }

    return sw.toString();
}

From source file:com.cloud.hypervisor.vmware.util.VmwareHelper.java

public static String getExceptionMessage(Throwable e, boolean printStack) {
    //TODO: in vim 5.1, exceptions do not have a base exception class, MethodFault becomes a FaultInfo that we can only get
    // from individual exception through getFaultInfo, so we have to use reflection here to get MethodFault information.
    try {/*  ww w.  ja v a 2s .c o m*/
        Class<? extends Throwable> cls = e.getClass();
        Method mth = cls.getDeclaredMethod("getFaultInfo", (Class<?>) null);
        if (mth != null) {
            Object fault = mth.invoke(e, (Object[]) null);
            if (fault instanceof MethodFault) {
                final StringWriter writer = new StringWriter();
                writer.append("Exception: " + fault.getClass().getName() + "\n");
                writer.append("message: " + ((MethodFault) fault).getFaultMessage() + "\n");

                if (printStack) {
                    writer.append("stack: ");
                    e.printStackTrace(new PrintWriter(writer));
                }
                return writer.toString();
            }
        }
    } catch (Exception ex) {
        s_logger.info("[ignored]" + "failed toi get message for exception: " + e.getLocalizedMessage());
    }

    return ExceptionUtil.toString(e, printStack);
}

From source file:de.micromata.genome.gwiki.page.gspt.ExtendedTemplate.java

/**
 * Escape quote.//from  w w  w. j av  a 2s . com
 *
 * @param text the text
 * @param quoteChar the quote char
 * @return the string
 */
public static String escapeQuote(String text, char quoteChar) {
    StringWriter ret = new StringWriter();
    for (int i = 0; i < text.length(); ++i) {
        char c = text.charAt(i);
        if (c == quoteChar)
            ret.append("\\").append(c);
        else
            ret.append(c);
    }
    return ret.toString();
}