Example usage for java.io Writer toString

List of usage examples for java.io Writer toString

Introduction

In this page you can find the example usage for java.io Writer toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.urremote.classifier.common.ExceptionHandler.java

public void uncaughtException(Thread t, Throwable e) {
    String timestamp = String.valueOf(System.currentTimeMillis());
    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);
    printWriter.println("Exception Thrown By Thread:" + t.getId() + " '" + t.getName() + "'");
    e.printStackTrace(printWriter);/*w w  w  .  j  a va  2s  .  c om*/
    String stacktrace = result.toString();
    printWriter.close();
    String filename = timestamp + ".stacktrace";
    writeToFile(stacktrace, filename);

    FlurryAgent.onError(e.getMessage(), stacktrace, e.getClass().getCanonicalName());
    //sendToServer(stacktrace, filename);

    defaultUEH.uncaughtException(t, e);
}

From source file:com.glaf.jbpm.web.springmvc.MxJbpmTakeTaskController.java

@RequestMapping
public ModelAndView takeTask(HttpServletRequest request, HttpServletResponse response) {
    Map<String, Object> paramMap = RequestUtils.getParameterMap(request);
    Long processInstanceId = ParamUtils.getLong(paramMap, "processInstanceId");
    Long taskInstanceId = ParamUtils.getLong(paramMap, "taskInstanceId");
    String actorId = RequestUtils.getActorId(request);
    ProcessContainer container = ProcessContainer.getContainer();
    boolean canSubmit = false;
    TaskItem taskItem = null;/*from w w  w  .jav a 2 s .  c  o  m*/
    String processName = null;
    if (taskInstanceId != null && StringUtils.isNotEmpty(actorId)) {
        /**
         * ????
         */
        taskItem = container.getTaskItem(taskInstanceId, actorId);
        if (taskItem != null) {
            if (processInstanceId != null) {
                canSubmit = true;
                processInstanceId = taskItem.getProcessInstanceId();
                processName = taskItem.getProcessName();
            }
        }
    } else if (processInstanceId != null && StringUtils.isNotEmpty(actorId)) {
        /**
         * ?????
         */
        taskItem = container.getMinTaskItem(actorId, processInstanceId);
        if (taskItem != null) {
            canSubmit = true;
            taskInstanceId = taskItem.getTaskInstanceId();
            processName = taskItem.getProcessName();
        }
    }

    /**
     * ???
     */
    if (canSubmit && taskInstanceId != null) {
        String routeMode = CustomProperties.getString(processName + "_routeMode");
        logger.debug("routeMode:" + routeMode);
        if (StringUtils.equals(routeMode, "MANUAL")) {
            if (taskInstanceId != null) {
                Collection<String> transitionNames = container.getTransitionNames(taskInstanceId);
                request.setAttribute("transitionNames", transitionNames);
            }
        } else if (StringUtils.equals(routeMode, "FREE")) {
            int signal = container.getSignal(taskInstanceId);
            if (signal != TaskNode.SIGNAL_LAST) {
                Collection<String> nodeNames = container.getNodeNames(processInstanceId);
                request.setAttribute("nodeNames", nodeNames);
            }
        }
        request.setAttribute("taskItem", taskItem);
    }

    /**
     * ???
     */
    if (processInstanceId != null) {
        List<ActivityInstance> ActivityInstances = container.getActivityInstances(processInstanceId);
        request.setAttribute("ActivityInstances", ActivityInstances);
    }

    /**
     * ?????<br>
     * ?????_take_template??jbpm_take_template
     * WEB-INF\conf\extension??
     */
    String templateId = ParamUtils.getString(paramMap, "z_templateId");

    if (taskItem != null) {
        templateId = CustomProperties.getString(processName + "_" + taskItem.getTaskName() + "_take_template");
    }
    if (StringUtils.isEmpty(templateId)) {
        templateId = CustomProperties.getString(processName + "_take_template");
    }
    if (StringUtils.isEmpty(templateId)) {
        templateId = CustomProperties.getString("jbpm_take_template");
    }
    logger.info("templateId=" + templateId);
    if (StringUtils.isNotEmpty(templateId)) {

        Map<String, Object> context = new java.util.HashMap<String, Object>();
        context.putAll(paramMap);
        context.put("actorId", actorId);
        context.put("contextPath", request.getContextPath());

        context.put("taskItem", taskItem);
        context.put("nodeNames", request.getAttribute("nodeNames"));
        context.put("ActivityInstances", request.getAttribute("ActivityInstances"));
        context.put("transitionNames", request.getAttribute("transitionNames"));
        try {
            logger.debug(context);
            Writer writer = new StringWriter();
            TemplateUtils.evaluate(templateId, context, writer);
            request.setAttribute("templateScript", writer.toString());
            String encoding = request.getParameter("encoding");
            if (encoding == null) {
                encoding = "UTF-8";
            }
            request.setCharacterEncoding(encoding);
            response.setCharacterEncoding(encoding);
            response.setContentType("text/html;charset=" + encoding);
            response.getWriter().write(writer.toString());
            return null;
        } catch (Exception ex) {
            if (LogUtils.isDebug()) {
                ex.printStackTrace();
                logger.debug(ex);
            }
        }
    }

    String jx_view = request.getParameter("jx_view");

    if (StringUtils.isNotEmpty(jx_view)) {
        return new ModelAndView(jx_view);
    }

    String x_view = ViewProperties.getString("jbpm_take.takeTask");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view);
    }

    return new ModelAndView("/jbpm/take");
}

From source file:com.wxxr.mobile.core.tools.VelocityTemplateRenderer.java

@Override
public String render(String template, Map<String, Object> attributes) {
    checkWasConfigured();/*from  ww  w  .j a  va  2s . c  o m*/
    customize(false);

    VelocityContext context = createContext(attributes);

    TypeUtils typeUtils = createTypeUtils();
    context.put("types", typeUtils);

    Writer writer = new StringWriter();
    engine.evaluate(context, writer, '"' + template + '"', template);
    String renderedText = writer.toString();

    return postProcess(renderedText, typeUtils);
}

From source file:org.esigate.renderers.ResourceFixupRendererTest.java

public void testRenderBlock1() throws IOException {
    String baseUrl = "http://backend/context";
    String requestUrl = "path/page.html";
    String visibleBaseUrl = baseUrl;
    final String input = "some html";

    UrlRewriter urlRewriter = Mockito.mock(UrlRewriter.class);
    Mockito.when(urlRewriter.rewriteHtml(input, requestUrl, baseUrl, visibleBaseUrl, false))
            .thenReturn("url rewritten html");

    Writer out = new StringBuilderWriter();
    ResourceFixupRenderer tested = new ResourceFixupRenderer(baseUrl, requestUrl, urlRewriter, visibleBaseUrl,
            false);/* w w w  . j a v a2  s.co  m*/
    tested.render(null, input, out);

    Mockito.verify(urlRewriter, Mockito.times(1)).rewriteHtml(input, requestUrl, baseUrl, visibleBaseUrl,
            false);
    assertEquals("url rewritten html", out.toString());
}

From source file:XmlWriter.java

static public void test2() throws IOException {

    Writer writer = new java.io.StringWriter();
    XmlWriter xmlwriter = new XmlWriter(writer);
    xmlwriter.writeComment("Example of XmlWriter running");
    xmlwriter.writeElement("person");
    xmlwriter.writeAttribute("name", "fred");
    xmlwriter.writeAttribute("age", "12");
    xmlwriter.writeElement("phone");
    xmlwriter.writeText("4254343");
    xmlwriter.endElement();/*from  w  w w . j  a  va  2  s .c  o  m*/
    xmlwriter.writeComment("Examples of empty tags");
    //        xmlwriter.setDefaultNamespace("test");
    xmlwriter.writeElement("friends");
    xmlwriter.writeEmptyElement("bob");
    xmlwriter.writeEmptyElement("jim");
    xmlwriter.endElement();
    xmlwriter.writeElementWithText("foo", "This is an example.");
    xmlwriter.endElement();
    xmlwriter.close();
    System.err.println(writer.toString());
}

From source file:com.devnexus.ting.core.service.integration.PrepareMailToRegisterTransformer.java

public String applyMustacheTemplate(RegistrationDetails registrationDetails, String template) {
    Map<String, Object> context = new HashMap<String, Object>();

    context.put("orderId", registrationDetails.getRegistrationFormKey());
    context.put("orderDetails", registrationDetails.getOrderDetails());
    context.put("finalPrice", registrationDetails.getFinalCost().setScale(2).toString());

    Writer writer = new StringWriter();
    MustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache = mf.compile(new StringReader(template), "email-notification");

    try {//from   w  w  w . ja  v  a2 s .com
        mustache.execute(writer, context).flush();
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    return writer.toString();
}

From source file:solidstack.reflect.Dumper.java

public String dump(Object o) {
    Writer out = new StringWriter();
    dumpTo(o, out);
    return out.toString();
}

From source file:com.neatresults.mgnltweaks.ui.action.CreateAppAction.java

@Override
public void execute() throws ActionExecutionException {
    // First Validate
    validator.showValidation(true);//w w  w  .  j a  v a 2s.  co m
    if (validator.isValid()) {

        // we support only JCR item adapters
        if (!(item instanceof JcrItemAdapter)) {
            return;
        }

        // don't save if no value changes occurred on adapter
        if (!((JcrItemAdapter) item).hasChangedProperties()) {
            return;
        }

        if (item instanceof AbstractJcrNodeAdapter) {
            // Saving JCR Node, getting updated node first
            AbstractJcrNodeAdapter nodeAdapter = (AbstractJcrNodeAdapter) item;
            try {
                Node node = nodeAdapter.getJcrItem();

                Context originalCtx = MgnlContext.getInstance();
                InputStream inputStream = null;
                MgnlGroovyConsoleContext groovyCtx = null;
                try {

                    groovyCtx = new MgnlGroovyConsoleContext(originalCtx);
                    groovyCtx.put("appName", item.getItemProperty("appName").getValue());
                    String[] pathArray = StringUtils.split(node.getPath(), "/");
                    if (pathArray.length < 2) {
                        throw new ActionExecutionException(
                                "Can't create app on selected path: " + node.getPath());
                    }
                    groovyCtx.put("appLocation", pathArray[1]);

                    groovyCtx.put("appGroup", item.getItemProperty("appGroup").getValue());
                    groovyCtx.put("appIcon", StringUtils
                            .defaultIfBlank((String) item.getItemProperty("appIcon").getValue(), "icon-items"));
                    groovyCtx.put("appRepository", StringUtils.defaultIfBlank(
                            (String) item.getItemProperty("appRepository").getValue(), "magnolia"));
                    groovyCtx.put("appFolderSupport", item.getItemProperty("appFolderSupport").getValue());

                    MgnlContext.setInstance(groovyCtx);
                    MgnlGroovyConsole console = new MgnlGroovyConsole(new Binding());

                    String inputFile = "/neat-tweaks-developers/appCreationScript.groovy";
                    // First Check
                    URL inFile = ClasspathResourcesUtil.getResource(inputFile);
                    if (inFile == null) {
                        throw new ActionExecutionException("Can't find resource file at " + inputFile);
                    }
                    // Get Input Stream
                    inputStream = ClasspathResourcesUtil.getResource(inputFile).openStream();
                    if (inputStream == null) {
                        throw new ActionExecutionException("Can't find resource file at " + inFile.getFile());
                    }

                    Writer writer = new StringWriter();

                    Object result = console.evaluate(inputStream, console.generateScriptName(), writer);

                    StringBuilder sb = new StringBuilder().append(writer.toString()).append("\n")
                            .append(result);
                    uiContext.openNotification(MessageStyleTypeEnum.INFO, true, sb.toString());

                } finally {
                    // close jcr sessions
                    groovyCtx.release();
                    // close files
                    IOUtils.closeQuietly(inputStream);
                    // restore context
                    MgnlContext.setInstance(originalCtx);
                }
            } catch (RepositoryException | IOException e) {
                log.error("Could not save changes to node", e);
            }
            callback.onSuccess(getDefinition().getName());
        } else if (item instanceof JcrPropertyAdapter) {
            super.execute();
        }
    } else {
        log.debug("Validation error(s) occurred. No save performed.");
    }
}

From source file:org.jannocessor.service.render.VelocityTemplateRenderer.java

@Override
public String render(String template, Map<String, Object> attributes) throws JannocessorException {
    checkWasConfigured();/* w w w. jav a 2s . com*/
    customize(false);

    VelocityContext context = createContext(attributes);

    TypeUtils typeUtils = createTypeUtils();
    context.put("types", typeUtils);

    Writer writer = new StringWriter();
    engine.evaluate(context, writer, '"' + template + '"', template);
    String renderedText = writer.toString();

    return postProcess(renderedText, typeUtils);
}

From source file:com.devnexus.ting.core.service.integration.PrepareAcceptedSessionMailToSpeakerTransformer.java

public String applyMustacheTemplate(CfpSubmission cfpSubmission, String template) {
    Map<String, Object> context = new HashMap<String, Object>();

    context.put("salutation", cfpSubmission.getSpeakersAsString(true));
    context.put("description", cfpSubmission.getDescription());
    context.put("descriptionHtml", cfpSubmission.getDescriptionAsHtml());
    context.put("presentationType", cfpSubmission.getPresentationType().getNameWithDescription());
    context.put("skillLevel", cfpSubmission.getSkillLevel().getName());
    context.put("comments", cfpSubmission.getSlotPreference());
    context.put("topic", cfpSubmission.getTopic());
    context.put("title", cfpSubmission.getTitle());
    context.put("sessionRecordingApproved", cfpSubmission.isSessionRecordingApproved() ? "Yes" : "No");
    context.put("speakers", cfpSubmission.getCfpSubmissionSpeakers());

    Writer writer = new StringWriter();
    MustacheFactory mf = new DefaultMustacheFactory();
    Mustache mustache = mf.compile(new StringReader(template), "email-notification");

    try {//from   w ww.  ja va  2 s.  c o  m
        mustache.execute(writer, context).flush();
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

    return writer.toString();
}