You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2015/01/12 18:36:25 UTC
svn commit: r1651150 - in /sling/trunk/bundles/scripting/jsp-taglib: pom.xml
src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java
Author: olli
Date: Mon Jan 12 17:36:25 2015
New Revision: 1651150
URL: http://svn.apache.org/r1651150
Log:
SLING-4298 make BufferedServletOutputStream and CaptureResponseWrapper available to other scripting implementations
* add new dependency org.apache.sling.scripting.core
* replace BufferedServletOutputStream and CaptureResponseWrapper by the ones from org.apache.sling.scripting.core
Modified:
sling/trunk/bundles/scripting/jsp-taglib/pom.xml
sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java
Modified: sling/trunk/bundles/scripting/jsp-taglib/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/pom.xml?rev=1651150&r1=1651149&r2=1651150&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/pom.xml (original)
+++ sling/trunk/bundles/scripting/jsp-taglib/pom.xml Mon Jan 12 17:36:25 2015
@@ -93,6 +93,12 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.scripting.core</artifactId>
+ <version>2.0.29-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.scripting.jsp</artifactId>
<version>2.0.8</version>
<!-- using compile scope to help IDEs -->
Modified: sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java?rev=1651150&r1=1651149&r2=1651150&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java (original)
+++ sling/trunk/bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib/IncludeTagHandler.java Mon Jan 12 17:36:25 2015
@@ -32,6 +32,8 @@ import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyContent;
import org.apache.commons.io.IOUtils;
+import org.apache.sling.scripting.core.servlet.BufferedServletOutputStream;
+import org.apache.sling.scripting.core.servlet.CaptureResponseWrapper;
/**
* The <code>IncludeTagHandler</code> implements the
@@ -124,128 +126,5 @@ public class IncludeTagHandler extends A
}
return PageContext.PAGE_SCOPE;
}
-
- /**
- * Extends the HttpServletResponse to wrap the response and capture the results.
- */
- private static final class CaptureResponseWrapper extends HttpServletResponseWrapper {
- private final String encoding;
- private final ServletOutputStream ops;
- private boolean isBinaryResponse = false;
- private PrintWriter writer = null;
-
- /**
- * Construct a new CaptureResponseWrapper.
- *
- * @param response
- * the response to wrap
- * @param ops
- * the output stream to write to
- */
- CaptureResponseWrapper(HttpServletResponse response,
- ServletOutputStream ops) {
- super(response);
- this.encoding = response.getCharacterEncoding();
- this.ops = ops;
- }
-
- /**
- * Returns true if the response is binary.
- *
- * @return
- */
- public boolean isBinaryResponse() {
- return isBinaryResponse;
- }
-
-
- /*
- * (non-Javadoc)
- * @see javax.servlet.ServletResponseWrapper#flushBuffer()
- */
- @Override
- public void flushBuffer() throws IOException {
- if (isBinaryResponse()) {
- getResponse().getOutputStream().flush();
- } else {
- writer.flush();
- }
- }
- /*
- * (non-Javadoc)
- * @see javax.servlet.ServletResponseWrapper#getOutputStream()
- */
- @Override
- public ServletOutputStream getOutputStream() throws IOException {
- if (writer != null) {
- throw new IOException("'getWriter()' has already been invoked for a character data response.");
- }
- isBinaryResponse = true;
- return getResponse().getOutputStream();
- }
-
- /*
- * (non-Javadoc)
- * @see javax.servlet.ServletResponseWrapper#getWriter()
- */
- @Override
- public PrintWriter getWriter() throws IOException {
- if (writer != null) {
- return writer;
- }
- if (isBinaryResponse) {
- throw new IOException("'getOutputStream()' has already been invoked for a binary data response.");
- }
- writer = new PrintWriter(new OutputStreamWriter(ops, encoding));
- return writer;
- }
-
- }
-
- /**
- * Extends the ServletOutputStream to capture the results into a byte array.
- */
- private static final class BufferedServletOutputStream extends ServletOutputStream {
- private final ByteArrayOutputStream baops = new ByteArrayOutputStream();
- private final String encoding;
-
- /**
- * Constructs a new BufferedServletOutputStream.
- *
- * @param encoding the encoding string
- */
- public BufferedServletOutputStream(String encoding) {
- this.encoding = encoding;
- }
-
- /**
- * Gets the byte buffer as a string.
- *
- * @return the byte buffer
- * @throws IOException
- */
- public String getBuffer() throws IOException {
- return baops.toString(encoding);
- }
-
- /*
- * (non-Javadoc)
- * @see java.io.OutputStream#close()
- */
- @Override
- public void close() throws IOException {
- baops.reset();
- super.close();
- }
-
- /*
- * (non-Javadoc)
- * @see java.io.OutputStream#write(int)
- */
- @Override
- public void write(int b) throws IOException {
- baops.write(b);
- }
- }
}