Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 68838 invoked from network); 9 Feb 2006 17:18:12 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Feb 2006 17:18:12 -0000 Received: (qmail 79494 invoked by uid 500); 9 Feb 2006 17:18:11 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 79437 invoked by uid 500); 9 Feb 2006 17:18:10 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 79426 invoked by uid 99); 9 Feb 2006 17:18:10 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Feb 2006 09:18:10 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 09 Feb 2006 09:18:09 -0800 Received: (qmail 68708 invoked by uid 65534); 9 Feb 2006 17:17:49 -0000 Message-ID: <20060209171749.68705.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r376354 - in /cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers: EncodingSerializer.java HTMLSerializer.java XHTMLSerializer.java XMLSerializer.java Date: Thu, 09 Feb 2006 17:17:48 -0000 To: cvs@cocoon.apache.org From: pier@apache.org X-Mailer: svnmailer-1.0.6 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: pier Date: Thu Feb 9 09:17:45 2006 New Revision: 376354 URL: http://svn.apache.org/viewcvs?rev=376354&view=rev Log: Better handling of DocTypes. Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/EncodingSerializer.java cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/HTMLSerializer.java cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XHTMLSerializer.java cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/EncodingSerializer.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/EncodingSerializer.java?rev=376354&r1=376353&r2=376354&view=diff ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/EncodingSerializer.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/EncodingSerializer.java Thu Feb 9 09:17:45 2006 @@ -36,9 +36,26 @@ import org.xml.sax.SAXException; /** + *

An abstract serializer supporting multiple encodings.

* + *

This serializer can accept the following configuration whenever it + * is declared into a sitemap:

* - * @author Pier Fumagalli, February 2003 + *
+ * <serializer class="org.apache.cocoon.components.serializers..." ... >
+ *   <encoding>myencoding</encoding>
+ *   <indent>myindenting</indent>
+ * </serializer>
+ * 
+ * + *

The value indicated by myencoding must be replaced with a valid + * charset encoding (this serializer does not rely on the JVM for character + * encoding, you can look into the cocoon-serializers-charsets + * JAR file for a list).

+ * + *

The value indicated by myindenting will control the indenting + * level for each element.

+ * * @version CVS $Id$ */ public abstract class EncodingSerializer implements Serializer, Locator, Recyclable, Configurable { Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/HTMLSerializer.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/HTMLSerializer.java?rev=376354&r1=376353&r2=376354&view=diff ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/HTMLSerializer.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/HTMLSerializer.java Thu Feb 9 09:17:45 2006 @@ -15,16 +15,38 @@ */ package org.apache.cocoon.components.serializers; +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.cocoon.components.serializers.encoding.HTMLEncoder; import org.apache.cocoon.components.serializers.util.DocType; import org.apache.cocoon.components.serializers.util.SGMLDocType; import org.xml.sax.SAXException; - /** + *

A serializer converting XHTML into plain old HTML.

+ * + *

For configuration options of this serializer, please look at the + * {@link XHTMLSerializer} and {@link EncodingSerializer}.

+ * + *

Any of the XHTML document type declared or used will be converted into + * its HTML 4.01 counterpart, and in addition to those a "compatible" doctype + * can be supported to exploit a couple of shortcuts into MSIE's rendering + * engine. The values for the doctype-default can then be:

+ * + *
+ *
"none"
+ *
Not to emit any dococument type declaration.
+ *
"compatible"
+ *
The HTML 4.01 Transitional (exploiting MSIE shortcut).
+ *
"strict"
+ *
The HTML 4.01 Strict document type.
+ *
"loose"
+ *
The HTML 4.01 Transitional document type.
+ *
"frameset"
+ *
The HTML 4.01 Frameset document type.
+ *
* - * @author Pier Fumagalli, February 2003 - * @version CVS $Id: HTMLSerializer.java,v 1.4 2004/04/30 22:57:22 joerg Exp $ + * @version CVS $Id$ */ public class HTMLSerializer extends XHTMLSerializer { @@ -58,6 +80,30 @@ super(HTML_ENCODER); } + /** + * Configure this instance by selecting the default document type to use. + */ + public void configure(Configuration conf) + throws ConfigurationException { + super.configure(conf); + + String doctype = conf.getChild("doctype-default").getValue(null); + if ("none".equalsIgnoreCase(doctype)) { + this.doctype_default = null; + } else if ("compatible".equalsIgnoreCase(doctype)) { + this.doctype_default = HTML401_DOCTYPE_COMPATIBLE; + } else if ("strict".equalsIgnoreCase(doctype)) { + this.doctype_default = HTML401_DOCTYPE_STRICT; + } else if ("loose".equalsIgnoreCase(doctype)) { + this.doctype_default = HTML401_DOCTYPE_TRANSITIONAL; + } else if ("frameset".equalsIgnoreCase(doctype)) { + this.doctype_default = HTML401_DOCTYPE_FRAMESET; + } else { + /* Default is compatible (MSIE hack) */ + this.doctype_default = HTML401_DOCTYPE_COMPATIBLE; + } + } + /* ====================================================================== */ /** Empty namespaces declaration. */ @@ -99,22 +145,22 @@ + this.getLocation()); } - if (this.doctype == null) { - this.doctype = HTML401_DOCTYPE_COMPATIBLE; - } else if (XHTML1_DOCTYPE_STRICT.equals(this.doctype)) { + if (this.doctype == null) this.doctype = this.doctype_default; + + if (XHTML1_DOCTYPE_STRICT.equals(this.doctype)) { this.doctype = HTML401_DOCTYPE_STRICT; } else if (XHTML1_DOCTYPE_TRANSITIONAL.equals(this.doctype)) { this.doctype = HTML401_DOCTYPE_TRANSITIONAL; } else if (XHTML1_DOCTYPE_FRAMESET.equals(this.doctype)) { this.doctype = HTML401_DOCTYPE_FRAMESET; } else { + /* The root element is uppercase, always!!! */ this.doctype = new DocType(this.doctype.getName().toUpperCase(), this.doctype.getPublicId(), this.doctype.getSystemId()); } super.body(XHTML1_NAMESPACE, name, name); } - /** * Receive notification of the beginning of an element. Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XHTMLSerializer.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XHTMLSerializer.java?rev=376354&r1=376353&r2=376354&view=diff ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XHTMLSerializer.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XHTMLSerializer.java Thu Feb 9 09:17:45 2006 @@ -19,11 +19,35 @@ import org.apache.cocoon.components.serializers.util.DocType; import org.xml.sax.SAXException; - /** + *

A pedantinc XHTML serializer encoding all recognized entities with their + * proper HTML names.

+ * + *

For configuration options of this serializer, please look at the + * {@link EncodingSerializer}, in addition to those, this serializer also + * support the specification of a default doctype. This default will be used + * if no document type is received in the SAX events, and can be configured + * in the following way:

* + *
+ * <serializer class="org.apache.cocoon.components.serializers..." ... >
+ *   <doctype-default>mytype</doctype-default>
+ * </serializer>
+ * 
+ * + *

The value mytype can be one of:

+ * + *
+ *
"none"
+ *
Not to emit any dococument type declaration.
+ *
"strict"
+ *
The XHTML 1.0 Strict document type.
+ *
"loose"
+ *
The XHTML 1.0 Transitional document type.
+ *
"frameset"
+ *
The XHTML 1.0 Frameset document type.
+ *
* - * @author Pier Fumagalli, February 2003 * @version CVS $Id$ */ public class XHTMLSerializer extends XMLSerializer { @@ -51,6 +75,13 @@ private static final XHTMLEncoder XHTML_ENCODER = new XHTMLEncoder(); + /* ====================================================================== */ + + /** The DocType instance representing the document. */ + protected DocType doctype_default = null; + + /* ====================================================================== */ + /** * Create a new instance of this XHTMLSerializer */ @@ -73,6 +104,28 @@ return("text/html; charset=" + this.charset.getName()); } + /** + * Configure this instance by selecting the default document type to use. + */ + public void configure(Configuration conf) + throws ConfigurationException { + super.configure(conf); + + String doctype = conf.getChild("doctype-default").getValue(null); + if ("none".equalsIgnoreCase(doctype)) { + this.doctype_default = null; + } else if ("strict".equalsIgnoreCase(doctype)) { + this.doctype_default = XHTML1_DOCTYPE_STRICT; + } else if ("loose".equalsIgnoreCase(doctype)) { + this.doctype_default = XHTML1_DOCTYPE_TRANSITIONAL; + } else if ("frameset".equalsIgnoreCase(doctype)) { + this.doctype_default = XHTML1_DOCTYPE_FRAMESET; + } else { + /* Default is transitional */ + this.doctype_default = XHTML1_DOCTYPE_TRANSITIONAL; + } + } + /* ====================================================================== */ /** @@ -84,7 +137,7 @@ */ public void body(String uri, String local, String qual) throws SAXException { - if (this.doctype == null) this.doctype = XHTML1_DOCTYPE_TRANSITIONAL; + if (this.doctype == null) this.doctype = this.doctype_default; if (this.namespaces.getUri("").length() == 0) { this.namespaces.push("", XHTML1_NAMESPACE); } Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java?rev=376354&r1=376353&r2=376354&view=diff ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java Thu Feb 9 09:17:45 2006 @@ -24,8 +24,11 @@ import org.xml.sax.SAXException; /** + *

A fancy XML serializer not relying on the JAXP API.

+ * + *

For configuration options of this serializer, please look at the + * {@link EncodingSerializer}.

* - * @author Pier Fumagalli, February 2003 * @version CVS $Id$ */ public class XMLSerializer extends EncodingSerializer {