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:de.quist.samy.remocon.RemoteSession.java

private String getRegistrationPayload(String ip) throws IOException {
    StringWriter writer = new StringWriter();
    writer.append((char) 0x64);
    writer.append((char) 0x00);
    writeBase64Text(writer, ip);//  w w w.  j a v  a2  s .com
    writeBase64Text(writer, uniqueId);
    writeBase64Text(writer, applicationName);
    writer.flush();
    return writer.toString();
}

From source file:org.jasig.cas.web.report.InternalConfigStateController.java

/**
 * Handle request.//from   www.j  a  v a  2 s  .c  om
 *
 * @param request the request
 * @param response the response
 * @return the model and view
 * @throws Exception the exception
 */
@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {

    final Map<String, Object> list = getBeans(this.applicationContext);
    LOGGER.debug("Found [{}] beans to report", list.size());

    final JsonSerializer<Object> serializer = new BeanObjectJsonSerializer();
    final StringBuilder builder = new StringBuilder();
    builder.append('[');

    final Set<Map.Entry<String, Object>> entries = list.entrySet();
    final Iterator<Map.Entry<String, Object>> it = entries.iterator();

    while (it.hasNext()) {
        final Map.Entry<String, Object> entry = it.next();
        final Object obj = entry.getValue();

        final StringWriter writer = new StringWriter();
        writer.append('{');
        writer.append('\"' + entry.getKey() + "\":");
        serializer.toJson(writer, obj);
        writer.append('}');
        builder.append(writer);

        if (it.hasNext()) {
            builder.append(',');
        }
    }
    builder.append(']');
    final ModelAndView mv = new ModelAndView(VIEW_CONFIG);
    final String jsonData = StringEscapeUtils.escapeJson(builder.toString());

    mv.addObject("jsonData", jsonData);
    mv.addObject("properties", casProperties.entrySet());
    return mv;
}

From source file:com.espertech.esper.epl.expression.ExprNewNode.java

public String toExpressionString() {
    StringWriter writer = new StringWriter();
    writer.write("new { ");
    String delimiter = "";
    for (int i = 0; i < this.getChildNodes().length; i++) {
        writer.append(delimiter);
        writer.append(columnNames[i]);//from   w w  w .  jav  a 2s  .co m
        ExprNode expr = this.getChildNodes()[i];

        boolean outputexpr = true;
        if (expr instanceof ExprIdentNode) {
            ExprIdentNode prop = (ExprIdentNode) expr;
            if (prop.getResolvedPropertyName().equals(columnNames[i])) {
                outputexpr = false;
            }
        }

        if (outputexpr) {
            writer.append(" = ");
            writer.append(expr.toExpressionString());
        }
        delimiter = ", ";
    }
    writer.write(" }");
    return writer.toString();
}

From source file:org.rascalmpl.library.experiments.Compiler.RVM.Interpreter.help.HelpManager.java

void appendHyperlink(StringWriter w, String conceptName) {
    w.append("<a href=\"http://localhost:");
    w.append(String.valueOf(getPort()));
    appendURL(w, conceptName);//from  ww  w.j a v a  2 s .  co  m
    w.append("\">").append(conceptName).append("</a>");
}

From source file:it.tidalwave.northernwind.core.impl.filter.XsltMacroFilter.java

/*******************************************************************************************************************
 *
 ******************************************************************************************************************/
@Override// w  w  w  .j av  a  2 s.com
@Nonnull
public String filter(final @Nonnull String text, final @Nonnull String mimeType) {
    if (!mimeType.equals("application/xhtml+xml")) {
        log.debug("Cannot filter resources not in XHTML: {}", mimeType);
        return text;
    }

    // FIXME: buggy and cumbersome
    if (!initialized) {
        try {
            synchronized (this) {
                if (!initialized) {
                    initialize();
                    initialized = true;
                }
            }
        } catch (IOException | NotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    try {
        final DOMResult result = new DOMResult();
        final Transformer transformer = createTransformer();
        // Fix for NW-100
        transformer.transform(new DOMSource(stringToNode(text.replace("xml:lang", "xml_lang"))), result);

        final StringWriter stringWriter = new StringWriter();

        if (text.startsWith(DOCTYPE_HTML)) {
            stringWriter.append(DOCTYPE_HTML).append("\n");
        }

        // Fix for NW-96
        final XhtmlMarkupSerializer xhtmlSerializer = new XhtmlMarkupSerializer(stringWriter);
        xhtmlSerializer.serialize(result.getNode());
        return stringWriter.toString().replace("xml_lang", "xml:lang").replace(" xmlns=\"\"", ""); // FIXME:
    } catch (SAXParseException e) {
        log.error("XML parse error: {} at l{}:c{}", e.getMessage(), e.getLineNumber(), e.getColumnNumber());
        log.error(text);
        throw new RuntimeException(e);
    } catch (TransformerException e) {
        log.error("XSL error: {} at {}", e.toString(), e.getLocationAsString());
        log.error(xslt);
        throw new RuntimeException(e);
    } catch (IOException | SAXException | ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.jboss.windup.decorator.xml.XPathSummaryDecorator.java

protected String convertNode(Node node) throws TransformerException {
    StringWriter sw = new StringWriter();
    Transformer t = TransformerFactory.newInstance().newTransformer();
    t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    sw.append(node.getTextContent());/*from   www  .j  av  a  2 s .  c o  m*/
    return sw.toString();
}

From source file:com.sangupta.shire.tools.ShireBlogImporter.java

/**
 * Appenda  new line with the given text
 * /*from  w w  w  .java2 s .  co  m*/
 * @param writer to which the text is appended
 * 
 * @param text the text that needs to be added
 */
protected void appendLine(StringWriter writer, String text) {
    writer.append(text);
    writer.append(NEW_LINE);
}

From source file:com.jaspersoft.jasperserver.rest.services.RESTUser.java

private String generateSummeryReport(WSUser[] users) throws ServiceException {
    try {//from www .  ja va2  s.c o  m
        StringWriter sw = new StringWriter();

        sw.append("<users>");

        for (int i = 0; i < users.length; i++) {
            // user password shouldn't be in a response
            users[i].setPassword(null);
            restUtils.getMarshaller(WSUser.class, WSRole.class).marshal(users[i], sw);
            if (log.isDebugEnabled()) {
                log.debug("finished marshaling user: " + users[i].getTenantId());
            }
        }
        sw.append("</users>");
        return sw.toString();
    } catch (JAXBException e) {
        throw new ServiceException(e.getLocalizedMessage());
    }
}

From source file:org.tap4j.plugin.model.TapTestResultResult.java

@Override
public String toString() {
    StringWriter pw = new StringWriter();
    pw.append(tapTestResult.getStatus().toString());
    if (tapTestResult.getTestNumber() != null) {
        pw.append(' ' + Integer.toString(tapTestResult.getTestNumber()));
    }/*www  .j  ava2  s  .c o  m*/
    if (StringUtils.isNotBlank(tapTestResult.getDescription())) {
        pw.append(' ' + tapTestResult.getDescription());
    }
    if (tapTestResult.getDirective() != null) {
        pw.append(" # " + tapTestResult.getDirective().getDirectiveValue().toString());
        if (StringUtils.isNotBlank(tapTestResult.getDirective().getReason())) {
            pw.append(' ' + tapTestResult.getDirective().getReason());
        }
    }
    List<Comment> comments = tapTestResult.getComments();
    if (comments.size() > 0) {
        for (Comment comment : comments) {
            if (comment.isInline()) {
                pw.append(' ');
                pw.append("# " + comment.getText());
            } else {
                pw.append("\n");
                pw.append("# " + comment.getText());
            }
        }
    }
    return pw.toString();
}

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

private String getAllResultsAsXMLInParts() {
    logger.debug("Start constructing result for download");
    java.io.StringWriter sw = new StringWriter();

    sw.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"); // XML instruction
    sw.append("<" + NAME_RESULTS + ">");

    logger.debug("Constructing search results in XML for download");

    // do it in parts, a bit like paging
    int partSize = 200;
    SearchData searchData = ((SearchModel) getDefaultModel()).getObject();
    SearchResult<? extends DccdSB> searchResult = (SearchResult<? extends DccdSB>) searchData.getResult();
    int totalNumberOfHits = searchResult.getTotalHits();
    int numberOfParts = (totalNumberOfHits + partSize - 1) / partSize; // round up
    for (int partIndex = 0; partIndex < numberOfParts; partIndex++) {
        int offset = partIndex * partSize;
        logger.debug("Start part at: " + offset);
        SearchResult<? extends DccdSB> searchResults = getResultsFor(offset, partSize);
        sw.append(SearchResultDataConverter.getResultsAsXML(searchResults, user));
    }//  w ww  .  j av  a2  s  . co m

    sw.append("</" + NAME_RESULTS + ">");

    logger.debug("End constructing result for download");

    return sw.toString();
}