struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [01/10] struts git commit: WW-4749 Implements buffered write
Date Wed, 10 May 2017 14:39:51 GMT
Repository: struts
Updated Branches:
  refs/heads/master 0314ddcb5 -> 5a0f2e1aa


WW-4749 Implements buffered write


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/d739be34
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/d739be34
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/d739be34

Branch: refs/heads/master
Commit: d739be34bccebbde2972c9e2c6225b94bad68d27
Parents: 8f75e1a
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Wed Apr 26 08:42:42 2017 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Wed Apr 26 08:42:42 2017 +0200

----------------------------------------------------------------------
 .../views/freemarker/FreemarkerResult.java      | 22 ++++++++++++--------
 1 file changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/d739be34/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java
b/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java
index 52ad637..0c7de59 100644
--- a/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java
+++ b/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerResult.java
@@ -112,6 +112,8 @@ public class FreemarkerResult extends StrutsResultSupport {
     protected FreemarkerManager freemarkerManager;
     private Writer writer;
     private boolean writeIfCompleted = false;
+    private String useBufferedWriter;
+
     /*
      * Struts results are constructed for each result execution
      *
@@ -194,11 +196,18 @@ public class FreemarkerResult extends StrutsResultSupport {
         // Give subclasses a chance to hook into preprocessing
         if (preTemplateProcess(template, model)) {
             try {
+                final boolean willUseBufferedWriter;
+                if (useBufferedWriter != null) {
+                    willUseBufferedWriter = Boolean.parseBoolean(useBufferedWriter);
+                } else {
+                    willUseBufferedWriter = isWriteIfCompleted() || template.getTemplateExceptionHandler()
== TemplateExceptionHandler.RETHROW_HANDLER;
+                }
+
                 // Process the template
                 Writer writer = getWriter();
-                if (isWriteIfCompleted() || configuration.getTemplateExceptionHandler() ==
TemplateExceptionHandler.RETHROW_HANDLER) {
+                if (willUseBufferedWriter){
                     CharArrayWriter parentCharArrayWriter = (CharArrayWriter) req.getAttribute(PARENT_TEMPLATE_WRITER);
-                    boolean isTopTemplate = false;
+                    boolean isTopTemplate;
                     if (isTopTemplate = (parentCharArrayWriter == null)) {
                         //this is the top template
                         parentCharArrayWriter = new CharArrayWriter();
@@ -213,18 +222,13 @@ public class FreemarkerResult extends StrutsResultSupport {
                             parentCharArrayWriter.flush();
                             parentCharArrayWriter.writeTo(writer);
                         }
-                    } catch (TemplateException e) {
+                    } catch (TemplateException | IOException e) {
                         if (LOG.isErrorEnabled()) {
                             LOG.error("Error processing Freemarker result!", e);
                         }
                         throw e;
-                    } catch (IOException e) {
-                        if (LOG.isErrorEnabled()){
-                            LOG.error("Error processing Freemarker result!", e);
-                        }
-                        throw e;
                     } finally {
-                        if (isTopTemplate && parentCharArrayWriter != null) {
+                        if (isTopTemplate) {
                             req.removeAttribute(PARENT_TEMPLATE_WRITER);
                             parentCharArrayWriter.close();
                         }


Mime
View raw message