1. opensymphony
  2. webwork

Commits

rebelutionary  committed 87595d4

Fix for WW-537 I think - seems to work for me, I haven't tried the examples though. I'll keep testing it with all our internal apps today.

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@411573baa09-0c28-0410-bef9-dab3c582ae83

  • Participants
  • Parent commits c6549e3
  • Branches master

Comments (0)

Files changed (1)

File src/java/com/opensymphony/webwork/views/velocity/AbstractTagDirective.java

View file
 import com.opensymphony.webwork.ServletActionContext;
 import com.opensymphony.webwork.config.Configuration;
 import com.opensymphony.webwork.views.jsp.ParamTag;
-
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.util.OgnlUtil;
 import com.opensymphony.xwork.util.OgnlValueStack;
-
 import ognl.Ognl;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.apache.velocity.app.event.EventCartridge;
 import org.apache.velocity.context.Context;
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.runtime.resource.Resource;
 import org.apache.velocity.util.introspection.IntrospectionCacheData;
 
-import java.io.IOException;
-import java.io.Writer;
-
-import java.util.*;
-
+import javax.servlet.*;
+import javax.servlet.http.HttpSession;
 import javax.servlet.jsp.JspException;
+import javax.servlet.jsp.JspWriter;
 import javax.servlet.jsp.PageContext;
 import javax.servlet.jsp.tagext.BodyContent;
 import javax.servlet.jsp.tagext.BodyTag;
 import javax.servlet.jsp.tagext.IterationTag;
 import javax.servlet.jsp.tagext.Tag;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.*;
 
 
 /**
      * todo enable this params to be reloaded or reset
      */
     protected static Map tagclassMap = new HashMap();
+    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
             applyAttributes(contextAdapter, node, object);
 
             if (object instanceof Tag) {
-                PageContext pageContext = ServletActionContext.getPageContext();
+                WrappedPageContext pageContext = new WrappedPageContext(ServletActionContext.getPageContext());
 
                 if (currentTag instanceof Tag) {
                     ((Tag) object).setParent((Tag) currentTag);
     /**
      *
      */
-    protected boolean processTag(PageContext pageContext, Tag tag, InternalContextAdapter context, Writer writer, Node node, Node bodyNode) throws ParseErrorException, IOException, MethodInvocationException, ResourceNotFoundException {
+    protected boolean processTag(WrappedPageContext pageContext, Tag tag, InternalContextAdapter context, Writer velocityWriter, Node node, Node bodyNode) throws ParseErrorException, IOException, MethodInvocationException, ResourceNotFoundException {
         tag.setPageContext(pageContext);
-        writer = pageContext.getOut();
+        Writer writer = pageContext.getOut();
 
         try {
             Map paramMap = null;
             }
 
             tag.doEndTag();
+            velocityWriter.write(pageContext.getContent());
         } catch (JspException e) {
             String gripe = "Fatal exception caught while processing tag,  " + tag.getClass().getName();
             log.warn(gripe, e);
             return obj;
         }
     }
+
+    class WrappedPageContext extends PageContext
+    {
+        PageContext delegatedContext;
+        JspWriter jspWriter;
+        StringWriter contentWriter;
+
+        public WrappedPageContext(PageContext delegatedContext)
+        {
+            this.delegatedContext = delegatedContext;
+            contentWriter = new StringWriter();
+            jspWriter = new JspWriter(1024, false) {
+                public void clear()
+                {
+                    throw new UnsupportedOperationException();
+                }
+
+                public void clearBuffer()
+                {
+                    throw new UnsupportedOperationException();
+                }
+
+                public void close()
+                {
+                    throw new UnsupportedOperationException();
+                }
+
+                public void flush()
+                {
+                    throw new UnsupportedOperationException();
+                }
+
+                public int getRemaining()
+                {
+                    throw new UnsupportedOperationException();
+                }
+
+                public void newLine()
+                {
+                    println();
+                }
+
+                public void print(boolean b)
+                {
+                    contentWriter.write(Boolean.toString(b));
+                }
+
+                public void print(char c)
+                {
+                    contentWriter.write(c);
+                }
+
+                public void print(char[] chars) throws IOException
+                {
+                    contentWriter.write(chars);
+                }
+
+                public void print(double v)
+                {
+                    contentWriter.write(Double.toString(v));
+                }
+
+                public void print(float v)
+                {
+                    contentWriter.write(Float.toString(v));
+                }
+
+                public void print(int i)
+                {
+                    contentWriter.write(Integer.toString(i));
+                }
+
+                public void print(long l)
+                {
+                    contentWriter.write(Long.toString(l));
+                }
+
+                public void print(Object o)
+                {
+                    contentWriter.write(o.toString());
+                }
+
+                public void print(String s)
+                {
+                    contentWriter.write(s);
+                }
+
+                public void println()
+                {
+                    contentWriter.write(LINE_SEPARATOR);
+                }
+
+                public void println(boolean b)
+                {
+                    print(b);
+                    println();
+                }
+
+                public void println(char c)
+                {
+                    print(c);
+                    println();
+                }
+
+                public void println(char[] chars) throws IOException
+                {
+                    print(chars);
+                    println();
+                }
+
+                public void println(double v)
+                {
+                    print(v);
+                    println();
+                }
+
+                public void println(float v)
+                {
+                    print(v);
+                    println();
+                }
+
+                public void println(int i)
+                {
+                    print(i);
+                    println();
+                }
+
+                public void println(long l)
+                {
+                    print(l);
+                    println();
+                }
+
+                public void println(Object o)
+                {
+                    print(o);
+                    println();
+                }
+
+                public void println(String s)
+                {
+                    print(s);
+                    println();
+                }
+
+                public void write(char cbuf[], int off, int len)
+                {
+                    contentWriter.write(cbuf, off, len);
+                }
+            };
+        }
+
+        public String getContent()
+        {
+            return contentWriter.toString();
+        }
+
+        public JspWriter getOut()
+        {
+            return jspWriter;
+        }
+
+        public void initialize(Servlet servlet, ServletRequest servletRequest, ServletResponse servletResponse, String s, boolean b, int i, boolean b1) throws IOException, IllegalStateException, IllegalArgumentException
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        public void release()
+        {
+            delegatedContext.release();
+        }
+
+        public void setAttribute(String s, Object o)
+        {
+            delegatedContext.setAttribute(s, o);
+        }
+
+        public void setAttribute(String s, Object o, int i)
+        {
+            delegatedContext.setAttribute(s, o, i);
+        }
+
+        public Object getAttribute(String s)
+        {
+            return delegatedContext.getAttribute(s);
+        }
+
+        public Object getAttribute(String s, int i)
+        {
+            return delegatedContext.getAttribute(s, i);
+        }
+
+        public Object findAttribute(String s)
+        {
+            return delegatedContext.findAttribute(s);
+        }
+
+        public void removeAttribute(String s)
+        {
+            delegatedContext.removeAttribute(s);
+        }
+
+        public void removeAttribute(String s, int i)
+        {
+            delegatedContext.removeAttribute(s, i);
+        }
+
+        public int getAttributesScope(String s)
+        {
+            return delegatedContext.getAttributesScope(s);
+        }
+
+        public Enumeration getAttributeNamesInScope(int i)
+        {
+            return delegatedContext.getAttributeNamesInScope(i);
+        }
+
+        public HttpSession getSession()
+        {
+            return delegatedContext.getSession();
+        }
+
+        public Object getPage()
+        {
+            return delegatedContext.getPage();
+        }
+
+        public ServletRequest getRequest()
+        {
+            return delegatedContext.getRequest();
+        }
+
+        public ServletResponse getResponse()
+        {
+            return null;
+        }
+
+        public Exception getException()
+        {
+            return delegatedContext.getException();
+        }
+
+        public ServletConfig getServletConfig()
+        {
+            return delegatedContext.getServletConfig();
+        }
+
+        public ServletContext getServletContext()
+        {
+            return delegatedContext.getServletContext();
+        }
+
+        public void forward(String s) throws ServletException, IOException
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        public void include(String s) throws ServletException, IOException
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        public void handlePageException(Exception e) throws ServletException, IOException
+        {
+            throw new UnsupportedOperationException();
+        }
+
+        public void handlePageException(Throwable throwable) throws ServletException, IOException
+        {
+            throw new UnsupportedOperationException();
+        }
+    }
 }