You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by sh...@apache.org on 2001/12/12 04:14:29 UTC
cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/xml TransformSupport.java
shawn 01/12/11 19:14:29
Modified: standard/src/org/apache/taglibs/standard/tag/common/xml
TransformSupport.java
Log:
Optimized TransformSupport per suggestion by Bob Lee. (Change should be
entirely transparent; we just pass output to the page directly, when
needed, instead of buffering it unnecessarily.)
I've called the class "SafeWriter" instead of "FlushIgnoredWriter" since
I block both close() and flush().
Revision Changes Path
1.5 +35 -10 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/xml/TransformSupport.java
Index: TransformSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/xml/TransformSupport.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TransformSupport.java 2001/12/12 02:28:04 1.4
+++ TransformSupport.java 2001/12/12 03:14:26 1.5
@@ -187,20 +187,27 @@
t.transform(xml, doc);
pageContext.setAttribute(var, d, scope);
} else {
- /*
- * We're going to output the text directly. I'd love to
- * construct a StreamResult directly from pageContext.getOut(),
- * but I can't trust the transformer not to flush our writer.
- */
- StringWriter bufferedResult = new StringWriter();
- Result page = new StreamResult(bufferedResult);
+ ////
+ // Replaced in favor of the optimized method below, suggested
+ // by Bob Lee.
+ // /*
+ // * We're going to output the text directly. I'd love to
+ // * construct a StreamResult directly from pageContext.getOut(),
+ // * but I can't trust the transformer not to flush our writer.
+ // */
+ // StringWriter bufferedResult = new StringWriter();
+ // Result page = new StreamResult(bufferedResult);
+ // t.transform(xml, page);
+ // pageContext.getOut().print(bufferedResult);
+
+ Result page =
+ new StreamResult(new SafeWriter(pageContext.getOut()));
t.transform(xml, page);
- pageContext.getOut().print(bufferedResult);
}
return EVAL_PAGE;
- } catch (IOException ex) {
- throw new JspTagException(ex.toString());
+ // } catch (IOException ex) {
+ // throw new JspTagException(ex.toString());
} catch (ParserConfigurationException ex) {
throw new JspTagException(ex.toString());
} catch (TransformerException ex) {
@@ -251,4 +258,22 @@
this.scope = Util.getScope(scope);
}
+
+ //*********************************************************************
+ // Private utility class
+
+ /**
+ * A Writer based on a wrapped Writer but ignoring requests to
+ * close() and flush() it. (Someone must have wrapped the
+ * toilet in my office similarly...)
+ */
+ private static class SafeWriter extends Writer {
+ private Writer w;
+ public SafeWriter(Writer w) { this.w = w; }
+ public void close() { }
+ public void flush() { }
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ w.write(cbuf, off, len);
+ }
+ }
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>