Package java.io

Examples of java.io.StringWriter


        return "tables.jsp";
    }

    private String getStackTrace(int id, Throwable e, boolean isH2) {
        try {
            StringWriter writer = new StringWriter();
            e.printStackTrace(new PrintWriter(writer));
            String stackTrace = writer.toString();
            stackTrace = PageParser.escapeHtml(stackTrace);
            if (isH2) {
                stackTrace = linkToSource(stackTrace);
            }
            stackTrace = StringUtils.replaceAll(stackTrace, "\t", "    ");
View Full Code Here


        return vs;
    }

    @Override
    public String toString() {
        final StringWriter sw = new StringWriter();
        final SAXSerializer ser = new SAXSerializer(new SAXWriter(sw), sw);
        try {
            ser.emit(this);
        } catch (XQueryException e) {
            return "failed at " + e.getStackTrace()[1] + "!\n" + e.getMessage();
        }
        return sw.toString();
    }
View Full Code Here

    @Override
    public String toString() {
        if(_citem == null) {
            return "ContextItem is not set.";
        }
        final StringWriter sw = new StringWriter();
        final SAXWriter writer = new SAXWriter(sw);
        writer.setXMLDeclaration(false);
        final SAXSerializer ser = new SAXSerializer(writer, sw);
        try {
            ser.emit(_citem);
        } catch (XQueryException e) {
            throw new XQRTException("eval failed!: " + e.getMessage());
        }
        return sw.toString();
    }
View Full Code Here

        return (T) this;
    }

    @Override
    public String toString() {
        StringWriter sw = new StringWriter();
        SAXWriter saxwriter = new SAXWriter(sw);
        saxwriter.setXMLDeclaration(false);
        SAXSerializer ser = new SAXSerializer(saxwriter, sw);
        try {
            ser.emit(this);
        } catch (XQueryException e) {
            return "failed at " + e.getStackTrace()[1] + ".\n" + e.getMessage();
        }
        return sw.toString();
    }
View Full Code Here

            context.put("generalUtil", GENERAL_UTIL);

            context.put("page", page);
            context.put("title", page.getTitle());

            StringWriter buffer = new StringWriter();
            page.writeBody(OutputConverter.getWriter(buffer));
            context.put("body", buffer.toString());

            if (page instanceof HTMLPage) {
                HTMLPage htmlPage = (HTMLPage) page;
                buffer = new StringWriter();
                htmlPage.writeHead(OutputConverter.getWriter(buffer));
                context.put("head", buffer.toString());
            }

            //Rendering the content
            VelocityEngine velocityEngine = VelocityManager.getInstance().getVelocityEngine();

            Template template = velocityEngine.getTemplate(decorator.getPage());
            StringWriter tempWriter = new StringWriter();
            template.merge(context, tempWriter);
            String renderResult = tempWriter.toString();

            response.getWriter().print(renderResult);

            while (decorator.getInitParameterNames().hasNext()) {
                String initParam = (String) decorator.getInitParameterNames().next();
View Full Code Here

        }
    }

    public static String getRenderedTemplateWithoutSwallowingErrors(String templateName, Context context) throws Exception {
        Template template = getTemplate(templateName);
        StringWriter tempWriter = new StringWriter();
        template.merge(context, tempWriter);
        return tempWriter.toString();
    }
View Full Code Here

        return template;
    }

    public static String getRenderedContent(String templateContent, Map contextMap) {
        try {
            StringWriter tempWriter = new StringWriter();
            VelocityContext context = new VelocityContext(contextMap);

            VelocityManager.getInstance().getVelocityEngine().evaluate(context, tempWriter, "getRenderedContent", templateContent);
            return tempWriter.toString();
        } catch (Exception e) {
            log.error("Error occurred rendering template content", e);
            throw new InfrastructureException("Error occurred rendering template content", e);
        }
    }
View Full Code Here

    public static String getStackTrace(Throwable t) {
        if (t == null) {
            return "";
        } else {
            StringWriter sw = new StringWriter();
            t.printStackTrace(new PrintWriter(sw));
            return sw.toString();
        }
    }
View Full Code Here

        if (response == null)
            throw new IOException("No response object in context.");

        try {
            String decoratorName = (String) node.jjtGetChild(0).value(adapter);
            StringWriter bodyContent = new StringWriter(1024);

            int bodyNode = 1;
            if (node.jjtGetNumChildren() == 3)
                bodyNode = 2;
            node.jjtGetChild(bodyNode).render(adapter, bodyContent);

            Factory factory = PortletContext.getContext().getSiteMeshFactory();
            Decorator decorator = factory.getDecoratorMapper().getNamedDecorator(request, decoratorName);
            if (decorator != null) {
                com.opensymphony.module.sitemesh.PageParser parser = factory.getPageParser("text/html");
                HTMLPage page = (HTMLPage) ((FastPageParser) parser).parse(new StringReader(bodyContent.toString()));
                Context context = VelocityManager.getInstance()
                        .createContext(ActionContext.getContext().getValueStack(), request, response);
                context.put("page", page);
                if (node.jjtGetNumChildren() == 3)
                    context.put("title", (String) node.jjtGetChild(1).value(adapter));
                else
                    context.put("title", page.getTitle());
                StringWriter buffer = new StringWriter();
                page.writeBody(OutputConverter.getWriter(buffer));
                context.put("body", buffer.toString());
                buffer = new StringWriter();
                page.writeHead(OutputConverter.getWriter(buffer));
                context.put("head", buffer.toString());
                context.put("params", params);
                writer.write(VelocityUtils.getRenderedTemplate(decorator.getPage(), context));
            } else {
                throw new IOException("could not find decorator with name: " + decoratorName);
            }
View Full Code Here

        sb.append(": ");
        sb.append(message);
        sb.append(lineSeparator);
        if (record.getThrown() != null) {
            try {
                StringWriter sw = new StringWriter();
                PrintWriter pw = new PrintWriter(sw);
                record.getThrown().printStackTrace(pw);
                pw.close();
                sb.append(sw.toString());
            } catch (Exception ex) {
            }
        }
        return sb.toString();
    }
View Full Code Here

TOP

Related Classes of java.io.StringWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.