You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gr...@apache.org on 2001/03/01 17:05:50 UTC
cvs commit: xml-cocoon/src/org/apache/cocoon/framework Page.java
greenrd 01/03/01 08:05:49
Modified: . changes.xml todo.xml
src/org/apache/cocoon Engine.java
src/org/apache/cocoon/formatter FO2PDFFormatter.java
Formatter.java HTMLFormatter.java
TextFormatter.java XHTMLFormatter.java
XMLFormatter.java
src/org/apache/cocoon/framework Page.java
Log:
upgrade to support FOP0.17, Cocoon Formatter interface is changed by this commit
Revision Changes Path
1.214 +7 -1 xml-cocoon/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/xml-cocoon/changes.xml,v
retrieving revision 1.213
retrieving revision 1.214
diff -u -r1.213 -r1.214
--- changes.xml 2001/02/26 21:48:04 1.213
+++ changes.xml 2001/03/01 16:05:31 1.214
@@ -4,7 +4,7 @@
<!--
History of Cocoon changes
- $Id: changes.xml,v 1.213 2001/02/26 21:48:04 greenrd Exp $
+ $Id: changes.xml,v 1.214 2001/03/01 16:05:31 greenrd Exp $
-->
<changes title="History of Changes">
@@ -18,6 +18,12 @@
</devs>
<release version="@version@" date="@date@">
+ <action dev="RDG" type="update" due-to="Kelly Campbell" due-to-email="camk@merlot.channelpoint.com">
+ Updated Cocoon for compatibility with FOP 0.16 and above. Backward compatibility to at least FOP 0.13
+ is still maintained.
+ WARNING: The Formatter interface has been changed. Instead of taking a Writer it now takes
+ an OutputStream. This makes more sense for output types like PDF.
+ </action>
<action dev="RDG" type="add" due-to="Ingo Bruell" due-to-email="ibruell@gmx.de">
Stylesheets (but not logicsheets) can now access a COCOON-BROWSER-ID parameter to identify which
browser they are serving (as an alternative to using different stylesheets for each browser, by
1.72 +1 -4 xml-cocoon/todo.xml
Index: todo.xml
===================================================================
RCS file: /home/cvs/xml-cocoon/todo.xml,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -r1.71 -r1.72
--- todo.xml 2001/02/28 18:11:53 1.71
+++ todo.xml 2001/03/01 16:05:32 1.72
@@ -3,7 +3,7 @@
<!DOCTYPE todo SYSTEM "./xdocs/dtd/todo-v10.dtd">
<!--
- $Id: todo.xml,v 1.71 2001/02/28 18:11:53 greenrd Exp $
+ $Id: todo.xml,v 1.72 2001/03/01 16:05:32 greenrd Exp $
-->
<todo title="Things To Do for Cocoon 1.x">
@@ -19,9 +19,6 @@
<action context="code" bugid="11">
NEEDED URGENTLY FOR TOMCAT 3.3 - because CLASSPATH will be ignored!
Add standard WEB-INF/classes and WEB-INF/lib to XSP classpath.
- </action>
- <action context="code" assigned-to="RDG">
- LiteralFormatter
</action>
<action context="code" assigned-to="RDG">
Make redirect semantics configurable in cocoon.properties
1.53 +16 -17 xml-cocoon/src/org/apache/cocoon/Engine.java
Index: Engine.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Engine.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- Engine.java 2001/01/27 17:26:08 1.52
+++ Engine.java 2001/03/01 16:05:35 1.53
@@ -1,4 +1,4 @@
-/*-- $Id: Engine.java,v 1.52 2001/01/27 17:26:08 greenrd Exp $ --
+/*-- $Id: Engine.java,v 1.53 2001/03/01 16:05:35 greenrd Exp $ --
============================================================================
The Apache Software License, Version 1.1
@@ -76,7 +76,7 @@
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
* @author <a href="mailto:greenrd@hotmail.com">Robin Green</a>
- * @version $Revision: 1.52 $ $Date: 2001/01/27 17:26:08 $
+ * @version $Revision: 1.53 $ $Date: 2001/03/01 16:05:35 $
*/
public class Engine implements Defaults {
@@ -383,20 +383,20 @@
Formatter formatter = formatters.getFormatter(document);
// FIXME: I know it sucks to encapsulate a nice stream into
- // a long String to push it into the cache. In the future,
+ // a long array to push it into the cache. In the future,
// we'll find a smarter way to do it.
// format the page
if (PROFILE) profiler.startEvent (requestMarker, formatter.getClass ());
- StringWriter writer = new StringWriter();
- formatter.format(document, writer, environment);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream ();
+ formatter.format(document, outputStream, environment);
if (PROFILE) profiler.finishEvent (requestMarker, formatter.getClass ());
if (LOG) logger.log(this, "Document formatted", Logger.DEBUG);
// fill the page bean with content
if (PROFILE) profiler.startEvent (requestMarker, OUTPUTTING);
- page.setContent(writer.toString());
+ page.setContent(outputStream.toByteArray());
// set content type together with encoding if appropriate
encoding = formatter.getEncoding();
@@ -439,9 +439,8 @@
// set the response content type
response.setContentType(page.getContentType());
- ByteArrayOutputStream outBuf = new ByteArrayOutputStream ();
boolean isHead = "HEAD".equals (request.getMethod ());
- byte[] content = Utils.getBytes (page.getContent (), encoding);
+ byte[] content = page.getContent ();
int contentLength = content.length;
// set the Last-Modified header if this option is enabled in cocoon.properties
@@ -453,26 +452,26 @@
}
}
- outBuf.write (content);
-
// if verbose mode is on, the output type allows it
// and the HTTP request isn't a HEAD
// print some processing info as a comment
- if (VERBOSE && (page.isText()) && !"HEAD".equals(request.getMethod())) {
+ String comment = null;
+ byte[] commentBytes = null;
+ if (VERBOSE && (page.allowsMarkup()) && !isHead) {
time = System.currentTimeMillis() - time;
- String comment = "\n<!-- This page was served "
+ comment = "\n<!-- This page was served "
+ (wasInCache ? "from cache " : "")
- + "in " + time + " milliseconds by "
+ + "in " + time + " milliseconds by Apache "
+ Cocoon.version() + " -->";
- byte[] commentBytes = Utils.getBytes (comment, encoding);
- outBuf.write (commentBytes);
+ commentBytes = Utils.getBytes (comment, encoding);
contentLength += commentBytes.length;
}
response.setContentLength (contentLength);
if (!isHead) {
OutputStream realOut = response.getOutputStream();
- realOut.write (outBuf.toByteArray ());
+ realOut.write (content);
+ if (comment != null) realOut.write (commentBytes);
realOut.flush ();
}
@@ -484,7 +483,7 @@
} catch (RedirectException ex) {
// Do nothing - this is used to immediately stop Cocoon processing
- // to fix a redirect bug on some servlet engines, e.g. Tomcat.
+ // to fix a redirect problem on some servlet engines, e.g. Tomcat.
} finally {
// if there is a lock make sure it is released,
// otherwise this page could never be served
1.10 +24 -9 xml-cocoon/src/org/apache/cocoon/formatter/FO2PDFFormatter.java
Index: FO2PDFFormatter.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/formatter/FO2PDFFormatter.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- FO2PDFFormatter.java 2001/01/22 03:58:40 1.9
+++ FO2PDFFormatter.java 2001/03/01 16:05:37 1.10
@@ -1,4 +1,4 @@
-/*-- $Id: FO2PDFFormatter.java,v 1.9 2001/01/22 03:58:40 balld Exp $ --
+/*-- $Id: FO2PDFFormatter.java,v 1.10 2001/03/01 16:05:37 greenrd Exp $ --
============================================================================
The Apache Software License, Version 1.1
@@ -65,7 +65,7 @@
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
* @author <a href="mailto:greenrd@hotmail.com">Robin Green</a>
- * @version $Revision: 1.9 $ $Date: 2001/01/22 03:58:40 $
+ * @version $Revision: 1.10 $ $Date: 2001/03/01 16:05:37 $
*/
public class FO2PDFFormatter extends AbstractFormatter implements Actor {
@@ -126,31 +126,46 @@
}
}
- public void format(Document document, Writer writer, Dictionary parameters) throws Exception {
+ public void format(Document document, OutputStream stream, Dictionary parameters) throws Exception {
Driver driver = new Driver();
driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", FOP_VERSION);
driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
- driver.setWriter(new PrintWriter(writer));
+ if (FOP_VERSION_NO > 0.15) {
+ // We use reflection here to avoid compile-time errors
+ // This translates at runtime to
+ //driver.setOutputStream (stream);
+ Driver.class.getMethod ("setOutputStream", new Class [] {OutputStream.class})
+ .invoke (driver, new Object [] {stream});
+ }
+ else {
+ PrintWriter pw = new PrintWriter (new OutputStreamWriter (stream));
+ // We use reflection here to avoid compile-time errors
+ // This translates at runtime to
+ //driver.setWriter (pw);
+ Driver.class.getMethod ("setWriter", new Class [] {PrintWriter.class})
+ .invoke (driver, new Object [] {pw});
+ }
+
if (FOP_VERSION_NO > 0.13) {
driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");
// To workaround the problem that Xalan 1.x does not output DOM2-compliant namespaces,
- // we use a major hack - output xml as a string and read it in again.
+ // we use a major hack - output xml as a byte array and read it in again.
// With a DOM2-compliant parser such as Xerces, this should work fine.
deferredInit ();
- StringWriter tempWriter = new StringWriter ();
- xmlFormatter.format (document, tempWriter, NO_PARAMETERS);
- String tempXml = tempWriter.toString ();
+ ByteArrayOutputStream tempStream = new ByteArrayOutputStream ();
+ xmlFormatter.format (document, tempStream, NO_PARAMETERS);
+ byte[] tempBytes = tempStream.toByteArray ();
// For now, we just use Xerces - it would be more complicated to support
// other parsers here.
SAXParser parser = new SAXParser ();
parser.setFeature("http://xml.org/sax/features/namespaces", true);
- driver.buildFOTree(parser, new InputSource (new StringReader (tempXml)));
+ driver.buildFOTree(parser, new InputSource (new ByteArrayInputStream (tempBytes)));
}
else {
driver.buildFOTree(document);
1.6 +4 -4 xml-cocoon/src/org/apache/cocoon/formatter/Formatter.java
Index: Formatter.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/formatter/Formatter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Formatter.java 2000/04/04 11:11:16 1.5
+++ Formatter.java 2001/03/01 16:05:38 1.6
@@ -1,4 +1,4 @@
-/*-- $Id: Formatter.java,v 1.5 2000/04/04 11:11:16 stefano Exp $ --
+/*-- $Id: Formatter.java,v 1.6 2001/03/01 16:05:38 greenrd Exp $ --
============================================================================
The Apache Software License, Version 1.1
@@ -59,7 +59,7 @@
* into streams.
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.5 $ $Date: 2000/04/04 11:11:16 $
+ * @version $Revision: 1.6 $ $Date: 2001/03/01 16:05:38 $
*/
public interface Formatter {
@@ -67,7 +67,7 @@
/**
* Prints the give document into a page.
*/
- public void format(Document document, Writer writer, Dictionary parameters) throws Exception;
+ public void format(Document document, OutputStream stream, Dictionary parameters) throws Exception;
/**
* Returns the encoding used by this formatter for output.
@@ -79,4 +79,4 @@
*/
public String getMIMEType();
-}
\ No newline at end of file
+}
1.7 +5 -5 xml-cocoon/src/org/apache/cocoon/formatter/HTMLFormatter.java
Index: HTMLFormatter.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/formatter/HTMLFormatter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- HTMLFormatter.java 2000/04/20 22:12:04 1.6
+++ HTMLFormatter.java 2001/03/01 16:05:39 1.7
@@ -1,4 +1,4 @@
-/*-- $Id: HTMLFormatter.java,v 1.6 2000/04/20 22:12:04 stefano Exp $ --
+/*-- $Id: HTMLFormatter.java,v 1.7 2001/03/01 16:05:39 greenrd Exp $ --
============================================================================
The Apache Software License, Version 1.1
@@ -67,7 +67,7 @@
* instead.
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.6 $ $Date: 2000/04/20 22:12:04 $
+ * @version $Revision: 1.7 $ $Date: 2001/03/01 16:05:39 $
*/
public class HTMLFormatter extends AbstractFormatter {
@@ -86,7 +86,7 @@
format.setOmitXMLDeclaration(true);
}
- public void format(Document document, Writer writer, Dictionary p) throws Exception {
- factory.makeSerializer(writer, format).asDOMSerializer().serialize(document);
+ public void format(Document document, OutputStream stream, Dictionary p) throws Exception {
+ factory.makeSerializer(stream, format).asDOMSerializer().serialize(document);
}
-}
\ No newline at end of file
+}
1.6 +5 -5 xml-cocoon/src/org/apache/cocoon/formatter/TextFormatter.java
Index: TextFormatter.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/formatter/TextFormatter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TextFormatter.java 2000/04/04 11:11:16 1.5
+++ TextFormatter.java 2001/03/01 16:05:39 1.6
@@ -1,4 +1,4 @@
-/*-- $Id: TextFormatter.java,v 1.5 2000/04/04 11:11:16 stefano Exp $ --
+/*-- $Id: TextFormatter.java,v 1.6 2001/03/01 16:05:39 greenrd Exp $ --
============================================================================
The Apache Software License, Version 1.1
@@ -61,7 +61,7 @@
* plain text outputs, VRML, CSS, etc..
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.5 $ $Date: 2000/04/04 11:11:16 $
+ * @version $Revision: 1.6 $ $Date: 2001/03/01 16:05:39 $
*/
public class TextFormatter extends AbstractFormatter {
@@ -80,7 +80,7 @@
format.setOmitXMLDeclaration(true);
}
- public void format(Document document, Writer writer, Dictionary p) throws Exception {
- factory.makeSerializer(writer, format).asDOMSerializer().serialize(document);
+ public void format(Document document, OutputStream stream, Dictionary p) throws Exception {
+ factory.makeSerializer(stream, format).asDOMSerializer().serialize(document);
}
-}
\ No newline at end of file
+}
1.2 +6 -6 xml-cocoon/src/org/apache/cocoon/formatter/XHTMLFormatter.java
Index: XHTMLFormatter.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/formatter/XHTMLFormatter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XHTMLFormatter.java 2000/04/20 22:12:04 1.1
+++ XHTMLFormatter.java 2001/03/01 16:05:40 1.2
@@ -1,4 +1,4 @@
-/*-- $Id: XHTMLFormatter.java,v 1.1 2000/04/20 22:12:04 stefano Exp $ --
+/*-- $Id: XHTMLFormatter.java,v 1.2 2001/03/01 16:05:40 greenrd Exp $ --
============================================================================
The Apache Software License, Version 1.1
@@ -62,10 +62,10 @@
* have any semantic information about the document type being formatted,
* this class handles tags like <em><br/></em> and transforms them to
* XHTML that non-XML-aware browsers can understand
- * (for example, <em>< br/></em>).
+ * (for example, <em><br /></em>).
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.1 $ $Date: 2000/04/20 22:12:04 $
+ * @version $Revision: 1.2 $ $Date: 2001/03/01 16:05:40 $
*/
public class XHTMLFormatter extends AbstractFormatter {
@@ -84,7 +84,7 @@
format.setOmitXMLDeclaration(true);
}
- public void format(Document document, Writer writer, Dictionary p) throws Exception {
- factory.makeSerializer(writer, format).asDOMSerializer().serialize(document);
+ public void format(Document document, OutputStream stream, Dictionary p) throws Exception {
+ factory.makeSerializer(stream, format).asDOMSerializer().serialize(document);
}
-}
\ No newline at end of file
+}
1.6 +5 -5 xml-cocoon/src/org/apache/cocoon/formatter/XMLFormatter.java
Index: XMLFormatter.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/formatter/XMLFormatter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XMLFormatter.java 2000/04/04 11:11:17 1.5
+++ XMLFormatter.java 2001/03/01 16:05:41 1.6
@@ -1,4 +1,4 @@
-/*-- $Id: XMLFormatter.java,v 1.5 2000/04/04 11:11:17 stefano Exp $ --
+/*-- $Id: XMLFormatter.java,v 1.6 2001/03/01 16:05:41 greenrd Exp $ --
============================================================================
The Apache Software License, Version 1.1
@@ -58,7 +58,7 @@
/**
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.5 $ $Date: 2000/04/04 11:11:17 $
+ * @version $Revision: 1.6 $ $Date: 2001/03/01 16:05:41 $
*/
public class XMLFormatter extends AbstractFormatter {
@@ -77,7 +77,7 @@
format.setOmitXMLDeclaration(false);
}
- public void format(Document document, Writer writer, Dictionary p) throws Exception {
- factory.makeSerializer(writer, format).asDOMSerializer().serialize(document);
+ public void format(Document document, OutputStream stream, Dictionary p) throws Exception {
+ factory.makeSerializer(stream, format).asDOMSerializer().serialize(document);
}
-}
\ No newline at end of file
+}
1.7 +13 -6 xml-cocoon/src/org/apache/cocoon/framework/Page.java
Index: Page.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/framework/Page.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Page.java 2000/12/22 11:51:08 1.6
+++ Page.java 2001/03/01 16:05:47 1.7
@@ -1,4 +1,4 @@
-/*-- $Id: Page.java,v 1.6 2000/12/22 11:51:08 greenrd Exp $ --
+/*-- $Id: Page.java,v 1.7 2001/03/01 16:05:47 greenrd Exp $ --
============================================================================
The Apache Software License, Version 1.1
@@ -58,22 +58,22 @@
* The Page wrapper class.
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.6 $ $Date: 2000/12/22 11:51:08 $
+ * @version $Revision: 1.7 $ $Date: 2001/03/01 16:05:47 $
*/
public class Page implements java.io.Serializable, Changeable, Cacheable {
- private String content = "text/xml";
+ private byte[] content;
private String contentType;
private boolean cached = false;
private Vector changeables = new Vector(3);
- public String getContent() {
+ public byte[] getContent() {
return this.content;
}
-
- public void setContent(String content) {
+
+ public void setContent(byte[] content) {
this.content = content;
}
@@ -87,6 +87,13 @@
public boolean isText() {
return this.contentType.startsWith("text");
+ }
+
+ public boolean allowsMarkup() {
+ return contentType.equals("text/xml")
+ || contentType.equals("text/html")
+ || contentType.equals("text/svg")
+ || contentType.equals("text/mathml");
}
public Enumeration getChangeables() {