cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r563600 [1/2] - in /cocoon/trunk/blocks: cocoon-portal/cocoon-portal-portlet-impl/src/main/java/org/apache/cocoon/portal/pluto/adapter/ cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/ut...
Date Tue, 07 Aug 2007 18:16:37 GMT
Author: cziegeler
Date: Tue Aug  7 11:16:36 2007
New Revision: 563600

URL: http://svn.apache.org/viewvc?view=rev&rev=563600
Log:
Move charsets to own module and add convenient impls for serializers.

Added:
    cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/EncodingSerializer.java   (with props)
    cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/HTMLSerializer.java   (with props)
    cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XHTMLSerializer.java   (with props)
    cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XMLSerializer.java   (with props)
Removed:
    cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-impl/src/main/java/org/apache/cocoon/components/serializers/EncodingSerializer.java
Modified:
    cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-impl/src/main/java/org/apache/cocoon/portal/pluto/adapter/PortletAdapter.java
    cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-impl/src/main/java/org/apache/cocoon/components/serializers/HTMLSerializer.java
    cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-impl/src/main/java/org/apache/cocoon/components/serializers/XHTMLSerializer.java
    cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-impl/src/main/java/org/apache/cocoon/components/serializers/XMLSerializer.java

Modified: cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-impl/src/main/java/org/apache/cocoon/portal/pluto/adapter/PortletAdapter.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-impl/src/main/java/org/apache/cocoon/portal/pluto/adapter/PortletAdapter.java?view=diff&rev=563600&r1=563599&r2=563600
==============================================================================
--- cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-impl/src/main/java/org/apache/cocoon/portal/pluto/adapter/PortletAdapter.java (original)
+++ cocoon/trunk/blocks/cocoon-portal/cocoon-portal-portlet-impl/src/main/java/org/apache/cocoon/portal/pluto/adapter/PortletAdapter.java Tue Aug  7 11:16:36 2007
@@ -30,8 +30,7 @@
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.cocoon.components.serializers.EncodingSerializer;
-import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.components.serializers.util.EncodingSerializer;
 import org.apache.cocoon.environment.http.HttpEnvironment;
 import org.apache.cocoon.portal.Constants;
 import org.apache.cocoon.portal.PortalException;
@@ -201,8 +200,7 @@
                 HtmlSaxParser.parseString(content, HtmlSaxParser.getContentFilter(contentHandler));
             } else {
                 // stream out the include for the serializer
-                final org.apache.cocoon.environment.Request request = ObjectModelHelper.getRequest(this.portalService.getProcessInfoProvider().getObjectModel());
-                EncodingSerializer.include(content, request, contentHandler);
+                EncodingSerializer.include(content, this.portalService.getRequestContext().getRequest(), contentHandler);
             }
         } catch (SAXException se) {
             throw se;

Added: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/EncodingSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/EncodingSerializer.java?view=auto&rev=563600
==============================================================================
--- cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/EncodingSerializer.java (added)
+++ cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/EncodingSerializer.java Tue Aug  7 11:16:36 2007
@@ -0,0 +1,567 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.components.serializers.util;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.cocoon.components.serializers.encoding.Charset;
+import org.apache.cocoon.components.serializers.encoding.CharsetFactory;
+import org.apache.cocoon.components.serializers.encoding.Encoder;
+import org.apache.commons.lang.SystemUtils;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * <p>An abstract serializer supporting multiple encodings.</p>
+ *
+ * This serializer is reusable. Inbetween uses, {@link #recycle()} should be
+ * called, folled by {@link #setup(HttpServletRequest)} when starting a new serialization.
+ *
+ * @version $Id$
+ */
+public abstract class EncodingSerializer implements Locator  {
+
+    /** The line separator string */
+    private static final char S_EOL[] = SystemUtils.LINE_SEPARATOR.toCharArray();
+
+    /* ====================================================================== */
+
+    /** The position of the namespace URI in the attributes array. */
+    public static final int ATTRIBUTE_NSURI = 0;
+
+    /** The position of the local name in the attributes array. */
+    public static final int ATTRIBUTE_LOCAL = 1;
+
+    /** The position of the qualified name in the attributes array. */
+    public static final int ATTRIBUTE_QNAME = 2;
+
+    /** The position of the value in the attributes array. */
+    public static final int ATTRIBUTE_VALUE = 3;
+
+    /** The length of the array of strings representing an attribute. */
+    public static final int ATTRIBUTE_LENGTH = 4;
+
+    /* ====================================================================== */
+
+    /** Our <code>Encoder</code> instance. */
+    private final Encoder encoder;
+
+    /** Our <code>Locator</code> instance. */
+    private Locator locator;
+
+    /** Our <code>Writer</code> instance. */
+    private OutputStreamWriter out;
+
+    /** Flag indicating if the document prolog is being processed. */
+    private boolean prolog = true;
+
+    /** Flag indicating if the document is being processed. */
+    private boolean processing = false;
+
+    /** Current nesting level */
+    private int level = 0;
+
+    /** Whitespace buffer for indentation */
+    private char[] indentBuffer;
+
+    /* ====================================================================== */
+
+    /** The <code>Charset</code> associated with the character encoding. */
+    protected Charset charset;
+
+    /** The <code>Namespace</code> associated with this instance. */
+    protected Namespaces namespaces;
+
+    /** Per level indent spaces */
+    protected int indentPerLevel = 0;
+    /* ====================================================================== */
+
+    protected HttpServletRequest request;
+
+    protected static final String CONTENT_LIST_ATTRIBUTE = EncodingSerializer.class.getName() + "/ContentList";
+
+    public static final String NAMESPACE = "http://apache.org/cocoon/serializers/include";
+
+    /**
+     * Create a new instance of this <code>EncodingSerializer</code>
+     */
+    protected EncodingSerializer(Encoder encoder) {
+        this.encoder = encoder;
+        this.recycle();
+    }
+
+    /* ====================================================================== */
+
+    public void setup(HttpServletRequest request) {
+        this.request = request;
+    }
+
+    /**
+     * Add the content to the output without sending it through the pipeline.
+     * @param content
+     * @param request
+     * @param handler
+     */
+    public static void include(String content, HttpServletRequest request, ContentHandler handler)
+    throws SAXException {
+        if ( content != null ) {
+            List values = (List)request.getAttribute(CONTENT_LIST_ATTRIBUTE);
+            if ( values == null ) {
+                values = new ArrayList();
+            }
+            values.add(content);
+            request.setAttribute(CONTENT_LIST_ATTRIBUTE, values);
+            handler.startPrefixMapping("encser", NAMESPACE);
+            final AttributesImpl attr = new AttributesImpl();
+            attr.addAttribute("", "index", "index", "CDATA", String.valueOf(values.size() - 1));
+            handler.startElement(NAMESPACE, "include", "encser:include", attr);
+            handler.endElement(NAMESPACE, "include", "encser:include");
+            handler.endPrefixMapping("encser");
+        }
+    }
+
+    /**
+     * Reset this <code>EncodingSerializer</code>.
+     */
+    public void recycle() {
+        if (processing) throw new IllegalStateException();
+        this.namespaces = new Namespaces();
+        this.locator = null;
+        this.out = null;
+        this.prolog = true;
+    }
+
+    /**
+     * Set the <code>OutputStream</code> where this serializer will
+     * write data to.
+     *
+     * @param out The <code>OutputStream</code> used for output.
+     */
+    public void setOutputStream(OutputStream out)
+    throws IOException {
+        if (out == null) throw new NullPointerException("Null output");
+
+        this.out = new OutputStreamWriter(out, this.charset.getName());
+    }
+
+    public void setEncoding(String encoding)
+    throws UnsupportedEncodingException {
+        this.charset = CharsetFactory.newInstance().getCharset(encoding);
+    }
+
+    public void setIndentPerLevel(int i) {
+        indentPerLevel = i;
+        if (indentPerLevel > 0) {
+            assureIndentBuffer(indentPerLevel * 6);
+        }
+    }
+
+    /* ====================================================================== */
+
+    private char[] assureIndentBuffer( int size ) {
+        if (indentBuffer == null || indentBuffer.length < size) {
+            indentBuffer = new char[size];
+            Arrays.fill(indentBuffer,' ');
+        }
+        return indentBuffer;
+    }
+
+    /**
+     * Encode and write a <code>String</code>
+     */
+    protected void encode(String data)
+    throws SAXException {
+        char array[] = data.toCharArray();
+        this.encode(array, 0, array.length);
+    }
+
+    /**
+     * Encode and write an array of characters.
+     */
+    protected void encode(char data[])
+    throws SAXException {
+        this.encode(data, 0, data.length);
+    }
+
+    /**
+     * Encode and write a specific part of an array of characters.
+     */
+    protected void encode(char data[], int start, int length)
+    throws SAXException {
+        int end = start + length;
+
+        if (data == null) throw new NullPointerException("Null data");
+        if ((start < 0) || (start > data.length) || (length < 0) ||
+            (end > data.length) || (end < 0))
+            throw new IndexOutOfBoundsException("Invalid data");
+        if (length == 0) return;
+
+        for (int x = start; x < end; x++) {
+            char c = data[x];
+
+            if (this.charset.allows(c) && this.encoder.allows(c)) {
+                continue;
+            }
+
+            if (start != x) this.write(data, start, x - start );
+            this.write(this.encoder.encode(c));
+            start = x + 1;
+            continue;
+        }
+        if (start != end) this.write(data, start, end - start );
+    }
+
+    /* ====================================================================== */
+
+    /**
+     * Receive an object for locating the origin of SAX document events.
+     */
+    public final void setDocumentLocator(Locator locator) {
+        this.locator = locator;
+    }
+
+    /**
+     * Return the public identifier for the current document event.
+     *
+     * @return A <code>String</code> containing the public identifier,
+     *         or <b>null</b> if none is available.
+     */
+    public String getPublicId() {
+        return(this.locator == null? null: this.locator.getPublicId());
+    }
+
+    /**
+     * Return the system identifier for the current document event.
+     *
+     * @return A <code>String</code> containing the system identifier,
+     *         or <b>null</b> if none is available.
+     */
+    public String getSystemId() {
+        return(this.locator == null? null: this.locator.getSystemId());
+    }
+
+    /**
+     * Return the line number where the current document event ends.
+     *
+     * @return The line number, or -1 if none is available.
+     */
+    public int getLineNumber() {
+        return(this.locator == null? -1: this.locator.getLineNumber());
+    }
+
+    /**
+     * Return the column number where the current document event ends.
+     *
+     * @return The column number, or -1 if none is available.
+     */
+    public int getColumnNumber() {
+        return(this.locator == null? -1: this.locator.getColumnNumber());
+    }
+
+    /**
+     * Return a <code>String</code> describing the current location.
+     */
+    protected String getLocation() {
+        if (this.locator == null) return("");
+        StringBuffer buf = new StringBuffer(" (");
+        if (this.getSystemId() != null) {
+            buf.append(this.getSystemId());
+            buf.append(' ');
+        }
+        buf.append("line " + this.getLineNumber());
+        buf.append(" col " + this.getColumnNumber());
+        buf.append(')');
+        return(buf.toString());
+    }
+
+    /* ====================================================================== */
+
+    /**
+     * Flush the stream.
+     */
+    protected void flush()
+    throws SAXException {
+        try {
+            this.out.flush();
+        } catch (IOException e) {
+            throw new SAXException("I/O error flushing: " + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Write an array of characters.
+     */
+    protected void write(char data[])
+    throws SAXException {
+        try {
+            this.out.write(data, 0, data.length);
+        } catch (IOException e) {
+            throw new SAXException("I/O error writing: " + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Write a portion of an array of characters.
+     */
+    protected void write(char data[], int start, int length)
+    throws SAXException {
+        try {
+            this.out.write(data, start, length);
+        } catch (IOException e) {
+            throw new SAXException("I/O error writing: " + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Write a single character.
+     */
+    protected void write(int c)
+    throws SAXException {
+        try {
+            this.out.write(c);
+        } catch (IOException e) {
+            throw new SAXException("I/O error writing: " + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Write a string.
+     */
+    protected void write(String data)
+    throws SAXException {
+        try {
+            this.out.write(data);
+        } catch (IOException e) {
+            throw new SAXException("I/O error writing: " + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Write a portion of a string.
+     */
+    protected void write(String data, int start, int length)
+    throws SAXException {
+        try {
+            this.out.write(data, start, length);
+        } catch (IOException e) {
+            throw new SAXException("I/O error writing: " + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Write a end-of-line character.
+     */
+    protected void writeln()
+    throws SAXException {
+        try {
+            this.out.write(S_EOL);
+        } catch (IOException e) {
+            throw new SAXException("I/O error writing: " + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Write a string and a end-of-line character.
+     */
+    protected void writeln(String data)
+    throws SAXException {
+        try {
+            this.out.write(data);
+            this.out.write(S_EOL);
+        } catch (IOException e) {
+            throw new SAXException("I/O error writing: " + e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Write out character to indent the output according
+     * to the level of nesting
+     * @param indent
+     * @throws SAXException
+     */
+    protected void writeIndent(int indent) throws SAXException {
+        this.charactersImpl("\n".toCharArray(),0,1);
+        if (indent > 0) {
+            this.charactersImpl(assureIndentBuffer(indent),0,indent);
+        }
+    }
+
+    /* ====================================================================== */
+
+    /**
+     * Receive notification of the beginning of a document.
+     */
+    public void startDocument()
+    throws SAXException {
+        this.processing = true;
+        this.level = 0;
+    }
+
+    /**
+     * Receive notification of the end of a document.
+     */
+    public void endDocument()
+    throws SAXException {
+        this.processing = false;
+        this.flush();
+    }
+
+    /**
+     * Begin the scope of a prefix-URI Namespace mapping.
+     */
+    public void startPrefixMapping(String prefix, String uri)
+    throws SAXException {
+        this.namespaces.push(prefix, uri);
+    }
+
+    /**
+     * End the scope of a prefix-URI mapping.
+     */
+    public void endPrefixMapping(String prefix)
+    throws SAXException {
+        this.namespaces.pop(prefix);
+    }
+
+    /**
+     * Receive notification of the beginning of an element.
+     */
+    public void startElement(String nsuri, String local, String qual,
+                                   Attributes attributes)
+    throws SAXException {
+        if (NAMESPACE.equals(nsuri)) {
+            final String contentId = attributes.getValue("index");
+            final int index = Integer.valueOf(contentId).intValue();
+
+            String value = null;
+            final List values = (List)this.request.getAttribute(CONTENT_LIST_ATTRIBUTE);
+            if ( values != null ) {
+                value = (String)values.get(index);
+            }
+            if ( value != null ) {
+                this.write(value);
+            }
+            return;
+        }
+        if (indentPerLevel > 0) {
+            this.writeIndent(indentPerLevel*level);
+            level++;
+        }
+
+        String name = this.namespaces.qualify(nsuri, local, qual);
+
+        if (this.prolog) {
+            this.body(nsuri, local, name);
+            this.prolog = false;
+        }
+
+        String ns[][] = this.namespaces.commit();
+
+        String at[][] = new String [attributes.getLength()][4];
+        for (int x = 0; x < at.length; x++) {
+            at[x][ATTRIBUTE_NSURI] = attributes.getURI(x);
+            at[x][ATTRIBUTE_LOCAL] = attributes.getLocalName(x);
+            at[x][ATTRIBUTE_QNAME] = namespaces.qualify(
+                            attributes.getURI(x),
+                            attributes.getLocalName(x),
+                            attributes.getQName(x));
+            at[x][ATTRIBUTE_VALUE] = attributes.getValue(x);
+        }
+
+        this.startElementImpl(nsuri, local, name, ns, at);
+    }
+
+    public void characters (char ch[], int start, int length)
+    throws SAXException {
+        if (indentPerLevel > 0) {
+            this.writeIndent(indentPerLevel*level + 1);
+        }
+        this.charactersImpl(ch, start, length);
+    }
+
+    /**
+     * Receive notification of the end of an element.
+     */
+    public void endElement(String nsuri, String local, String qual)
+    throws SAXException {
+        if (NAMESPACE.equals(nsuri)) {
+            return;
+        }
+        if (indentPerLevel > 0) {
+            level--;
+            this.writeIndent(indentPerLevel*level);
+        }
+
+        String name = this.namespaces.qualify(nsuri, local, qual);
+        this.endElementImpl(nsuri, local, name);
+    }
+
+    /**
+     * Receive notification of the beginning of the document body.
+     *
+     * @param uri The namespace URI of the root element.
+     * @param local The local name of the root element.
+     * @param qual The fully-qualified name of the root element.
+     */
+    public abstract void body(String uri, String local, String qual)
+    throws SAXException;
+
+    /**
+     * Receive notification of the beginning of an element.
+     *
+     * @param uri The namespace URI of the root element.
+     * @param local The local name of the root element.
+     * @param qual The fully-qualified name of the root element.
+     * @param namespaces An array of <code>String</code> objects containing
+     *                   the namespaces to be declared by this element.
+     * @param attributes An array of <code>String</code> objects containing
+     *                   all attributes of this element.
+     */
+    public abstract void startElementImpl(String uri, String local, String qual,
+                                  String namespaces[][], String attributes[][])
+    throws SAXException;
+
+    /**
+     * Receive character notifications
+     * @param ch
+     * @param start
+     * @param length
+     * @throws SAXException
+     */
+    public abstract void charactersImpl (char ch[], int start, int length)
+    throws SAXException;
+
+    /**
+     * Receive notification of the end of an element.
+     *
+     * @param uri The namespace URI of the root element.
+     * @param local The local name of the root element.
+     * @param qual The fully-qualified name of the root element.
+     */
+    public abstract void endElementImpl(String uri, String local, String qual)
+    throws SAXException;
+}

Propchange: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/EncodingSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/EncodingSerializer.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/HTMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/HTMLSerializer.java?view=auto&rev=563600
==============================================================================
--- cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/HTMLSerializer.java (added)
+++ cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/HTMLSerializer.java Tue Aug  7 11:16:36 2007
@@ -0,0 +1,241 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.components.serializers.util;
+
+import org.apache.cocoon.components.serializers.encoding.HTMLEncoder;
+import org.xml.sax.SAXException;
+
+/**
+ * <p>A serializer converting XHTML into plain old HTML.</p>
+ *
+ * <p>For configuration options of this serializer, please look at the
+ * {@link XHTMLSerializer} and {@link EncodingSerializer}.</p>
+ *
+ * <p>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 <code>doctype-default</code> can then be:</p>
+ *
+ * <dl>
+ *   <dt>"<code>none</code>"</dt>
+ *   <dd>Not to emit any dococument type declaration.</dd>
+ *   <dt>"<code>compatible</code>"</dt>
+ *   <dd>The HTML 4.01 Transitional (exploiting MSIE shortcut).</dd>
+ *   <dt>"<code>strict</code>"</dt>
+ *   <dd>The HTML 4.01 Strict document type.</dd>
+ *   <dt>"<code>loose</code>"</dt>
+ *   <dd>The HTML 4.01 Transitional document type.</dd>
+ *   <dt>"<code>frameset</code>"</dt>
+ *   <dd>The HTML 4.01 Frameset document type.</dd>
+ * </dl>
+ *
+ * @version $Id$
+ */
+public class HTMLSerializer extends XHTMLSerializer {
+
+    /** A cross-browser compatible very simple document type declaration. */
+    public static final DocType HTML401_DOCTYPE_COMPATIBLE = new SGMLDocType(
+            "HTML", "-//W3C//DTD HTML 4.01 Transitional//EN", null);
+
+    /** A representation of the HTML 4.01 strict document type. */
+    public static final DocType HTML401_DOCTYPE_STRICT = new SGMLDocType(
+            "HTML", "-//W3C//DTD HTML 4.01//EN",
+            "http://www.w3.org/TR/html4/strict.dtd");
+
+    /** A representation of the HTML 4.01 transitional document type. */
+    public static final DocType HTML401_DOCTYPE_TRANSITIONAL = new SGMLDocType(
+            "HTML", "-//W3C//DTD HTML 4.01 Transitional//EN",
+            "http://www.w3.org/TR/html4/loose.dtd");
+
+    /** A representation of the HTML 4.01 frameset document type. */
+    public static final DocType HTML401_DOCTYPE_FRAMESET = new SGMLDocType(
+            "HTML", "-//W3C//DTD HTML 4.01 Frameset//EN",
+            "http://www.w3.org/TR/html4/frameset.dtd");
+
+    /* ====================================================================== */
+
+    private static final HTMLEncoder HTML_ENCODER = new HTMLEncoder();
+
+    protected boolean encodeCharacters = true;
+
+    /**
+     * Create a new instance of this <code>HTMLSerializer</code>
+     */
+    public HTMLSerializer() {
+        super(HTML_ENCODER);
+    }
+
+    public void setDoctypeDefault(String doctype) {
+        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. */
+    private static final String NAMESPACES[][] = new String[0][0];
+
+    /** Check if the URI is allowed by this serializer. */
+    private boolean checkNamespace(String nsuri) {
+        if (nsuri.length() == 0) return(true);
+        if (XHTML1_NAMESPACE.equals(nsuri)) return(true);
+        return(false);
+    }
+
+    /* ====================================================================== */
+
+    /**
+     * Write the XML document header.
+     * <p>
+     * This method overrides the default <code>XMLSerializer</code>.behaviour.
+     * </p>
+     */
+    public void head()
+    throws SAXException {
+        // NO NOTHING!
+    }
+
+    /**
+     * Receive notification of the beginning of the document body.
+     *
+     * @param nsuri The namespace URI of the root element.
+     * @param local The local name of the root element.
+     * @param qual The fully-qualified name of the root element.
+     */
+    public void body(String nsuri, String local, String qual)
+    throws SAXException {
+        String name = local.toUpperCase();
+        if (! this.checkNamespace(nsuri)) {
+            throw new SAXException("Unsupported namespace \"" + nsuri + "\" "
+                                   + "for HTML root element \"" + qual + "\""
+                                   + this.getLocation());
+        }
+
+        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 if (this.doctype != null) {
+            /* The root element is uppercase, always!!! */
+            this.doctype = new SGMLDocType(this.doctype.getName().toUpperCase(),
+                                       this.doctype.getPublicId(),
+                                       this.doctype.getSystemId());
+        }
+        super.body(XHTML1_NAMESPACE, name, name);
+    }
+
+    /**
+     * Receive notification of the beginning of an element.
+     */
+    public void startElementImpl(String nsuri, String local, String qual,
+                             String namespaces[][], String attributes[][])
+    throws SAXException {
+        String name = local.toUpperCase();
+        if (! this.checkNamespace(nsuri)) {
+            throw new SAXException("Unsupported namespace \"" + nsuri + "\" "
+                                   + "for HTML element \"" + qual + "\""
+                                   + this.getLocation());
+        }
+
+        int length = 0;
+        for (int x = 0; x < attributes.length; x ++) {
+            if (checkNamespace(attributes[x][ATTRIBUTE_NSURI])) length ++;
+        }
+
+        String at[][] = new String[length][ATTRIBUTE_LENGTH];
+        length = 0;
+        for (int x = 0; x < attributes.length; x ++) {
+            if (!checkNamespace(attributes[x][ATTRIBUTE_NSURI])) continue;
+
+            String at_name = attributes[x][ATTRIBUTE_LOCAL].toLowerCase();
+            at[length][ATTRIBUTE_NSURI] = XHTML1_NAMESPACE;
+            at[length][ATTRIBUTE_LOCAL] = at_name;
+            at[length][ATTRIBUTE_QNAME] = at_name;
+            at[length][ATTRIBUTE_VALUE] = attributes[x][ATTRIBUTE_VALUE];
+            length++;
+        }
+
+        // script and style are CDATA sections by default, so no encoding
+        if ( "SCRIPT".equals(name) || "STYLE".equals(name) ) {
+            this.encodeCharacters = false;
+        }
+        super.startElementImpl(XHTML1_NAMESPACE, name, name, NAMESPACES, at);
+    }
+
+    /**
+     * Receive notification of the end of an element.
+     */
+    public void endElementImpl(String nsuri, String local, String qual)
+    throws SAXException {
+        this.closeElement(false);
+
+        String name = local.toUpperCase();
+        if (! this.checkNamespace(nsuri)) {
+            throw new SAXException("Unsupported namespace \"" + nsuri + "\" "
+                                   + "for HTML element \"" + qual + "\""
+                                   + this.getLocation());
+        }
+
+        if (name.equals("AREA")) return;
+        if (name.equals("BASE")) return;
+        if (name.equals("BASEFONT")) return;
+        if (name.equals("BR")) return;
+        if (name.equals("COL")) return;
+        if (name.equals("FRAME")) return;
+        if (name.equals("HR")) return;
+        if (name.equals("IMG")) return;
+        if (name.equals("INPUT")) return;
+        if (name.equals("ISINDEX")) return;
+        if (name.equals("LINK")) return;
+        if (name.equals("META")) return;
+        if (name.equals("PARAM")) return;
+
+        // script and style are CDATA sections by default, so no encoding
+        if ( "SCRIPT".equals(name) || "STYLE".equals(name) ) {
+            this.encodeCharacters = true;
+        }
+        super.endElementImpl(XHTML1_NAMESPACE, name, name);
+    }
+
+    /**
+     * Encode and write a specific part of an array of characters.
+     */
+    protected void encode(char data[], int start, int length)
+    throws SAXException {
+        if ( !this.encodeCharacters ) {
+            this.write(data, start, length);
+            return;
+        }
+        super.encode(data, start, length);
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/HTMLSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/HTMLSerializer.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XHTMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XHTMLSerializer.java?view=auto&rev=563600
==============================================================================
--- cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XHTMLSerializer.java (added)
+++ cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XHTMLSerializer.java Tue Aug  7 11:16:36 2007
@@ -0,0 +1,215 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.components.serializers.util;
+
+import org.apache.cocoon.components.serializers.encoding.XHTMLEncoder;
+import org.xml.sax.SAXException;
+
+/**
+ * <p>A pedantinc XHTML serializer encoding all recognized entities with their
+ * proper HTML names.</p>
+ *
+ * <p>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:</p>
+ *
+ * <pre>
+ * &lt;serializer class="org.apache.cocoon.components.serializers..." ... &gt;
+ *   &lt;doctype-default&gt;mytype&lt;/doctype-default&gt;
+ * &lt;/serializer&gt;
+ * </pre>
+ *
+ * <p>The value <i>mytype</i> can be one of:</p>
+ *
+ * <dl>
+ *   <dt>"<code>none</code>"</dt>
+ *   <dd>Not to emit any dococument type declaration.</dd>
+ *   <dt>"<code>strict</code>"</dt>
+ *   <dd>The XHTML 1.0 Strict document type.</dd>
+ *   <dt>"<code>loose</code>"</dt>
+ *   <dd>The XHTML 1.0 Transitional document type.</dd>
+ *   <dt>"<code>frameset</code>"</dt>
+ *   <dd>The XHTML 1.0 Frameset document type.</dd>
+ * </dl>
+ *
+ * @version $Id$
+ */
+public class XHTMLSerializer extends XMLSerializer {
+
+    /** The namespace URI for XHTML 1.0. */
+    public static final String XHTML1_NAMESPACE =
+            "http://www.w3.org/1999/xhtml";
+
+    /** A representation of the XHTML 1.0 strict document type. */
+    public static final DocType XHTML1_DOCTYPE_STRICT = new DocType(
+            "html", "-//W3C//DTD XHTML 1.0 Strict//EN",
+            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
+
+    /** A representation of the XHTML 1.0 transitional document type. */
+    public static final DocType XHTML1_DOCTYPE_TRANSITIONAL = new DocType(
+            "html", "-//W3C//DTD XHTML 1.0 Transitional//EN",
+            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
+
+    /** A representation of the XHTML 1.0 frameset document type. */
+    public static final DocType XHTML1_DOCTYPE_FRAMESET = new DocType(
+            "html", "-//W3C//DTD XHTML 1.0 Frameset//EN",
+            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd");
+
+    /* ====================================================================== */
+
+    private static final XHTMLEncoder XHTML_ENCODER = new XHTMLEncoder();
+
+    /* ====================================================================== */
+
+    /** The <code>DocType</code> instance representing the document. */
+    protected DocType doctype_default = null;
+
+    /** Define whether to put XML declaration in the head of the document. */
+    private String omitXmlDeclaration = null;
+
+    /* ====================================================================== */
+
+    /**
+     * Create a new instance of this <code>XHTMLSerializer</code>
+     */
+    public XHTMLSerializer() {
+        super(XHTML_ENCODER);
+    }
+
+    /**
+     * Create a new instance of this <code>XHTMLSerializer</code>
+     */
+    protected XHTMLSerializer(XHTMLEncoder encoder) {
+        super(encoder);
+    }
+
+    /**
+     * Return the MIME Content-Type produced by this serializer.
+     */
+    public String getMimeType() {
+        if (this.charset == null) return("text/html");
+        return("text/html; charset=" + this.charset.getName());
+    }
+
+    public void setDoctypeDefault(String doctype) {
+        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;
+        }
+    }
+
+    public void setOmitXmlDeclaration(String value) {
+        this.omitXmlDeclaration = value;
+    }
+
+    /* ====================================================================== */
+
+    /**
+     * Write the XML document header.
+     * <p>
+     * This method will write out the <code>&lt;?xml version=&quot;1.0&quot
+     * ...&gt;</code> header unless omit-xml-declaration is set.
+     * </p>
+     */
+    protected void head()
+    throws SAXException {
+        if (!"yes".equals(this.omitXmlDeclaration)) {
+            super.head();
+        }
+    }
+
+    /**
+     * Receive notification of the beginning of the document body.
+     *
+     * @param uri The namespace URI of the root element.
+     * @param local The local name of the root element.
+     * @param qual The fully-qualified name of the root element.
+     */
+    public void body(String uri, String local, String qual)
+    throws SAXException {
+        if (this.doctype == null) this.doctype = this.doctype_default;
+        if (this.namespaces.getUri("").length() == 0) {
+            this.namespaces.push("", XHTML1_NAMESPACE);
+        }
+        super.body(uri, local, qual);
+    }
+
+    /**
+     * Receive notification of the beginning of an element.
+     *
+     * @param uri The namespace URI of the root element.
+     * @param local The local name of the root element.
+     * @param qual The fully-qualified name of the root element.
+     * @param namespaces An array of <code>String</code> objects containing
+     *                   the namespaces to be declared by this element.
+     * @param attributes An array of <code>String</code> objects containing
+     *                   all attributes of this element.
+     */
+    public void startElementImpl(String uri, String local, String qual,
+                                 String namespaces[][], String attributes[][])
+    throws SAXException {
+        if (uri.length() == 0) uri = XHTML1_NAMESPACE;
+        super.startElementImpl(uri, local, qual, namespaces, attributes);
+    }
+
+    /**
+     * Receive notification of the end of an element.
+     *
+     * @param uri The namespace URI of the root element.
+     * @param local The local name of the root element.
+     * @param qual The fully-qualified name of the root element.
+     */
+    public void endElementImpl(String uri, String local, String qual)
+    throws SAXException {
+        if (uri.length() == 0) uri = XHTML1_NAMESPACE;
+
+        if (XHTML1_NAMESPACE.equals(uri)) {
+            if ((local.equalsIgnoreCase("textarea")) ||
+                (local.equalsIgnoreCase("script")) ||
+                (local.equalsIgnoreCase("style"))) {
+                this.closeElement(false);
+            } else if (local.equalsIgnoreCase("head")) {
+                String loc = "meta";
+                String qua = namespaces.qualify(XHTML1_NAMESPACE, loc, "meta");
+                String nsp[][] = new String[0][0];
+                String att[][] = new String[2][ATTRIBUTE_LENGTH];
+
+                att[0][ATTRIBUTE_NSURI] = att[1][ATTRIBUTE_NSURI] = "";
+                att[0][ATTRIBUTE_LOCAL] = att[0][ATTRIBUTE_QNAME] = "http-equiv";
+                att[1][ATTRIBUTE_LOCAL] = att[1][ATTRIBUTE_QNAME] = "content";
+                att[0][ATTRIBUTE_VALUE] = "Content-Type";
+                att[1][ATTRIBUTE_VALUE] = this.getMimeType();
+
+                this.closeElement(false);
+                this.startElementImpl(XHTML1_NAMESPACE, loc, qua, nsp, att);
+                this.endElementImpl(XHTML1_NAMESPACE, loc, qua);
+            }
+        }
+        super.endElementImpl(uri, local, qual);
+    }
+
+}

Propchange: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XHTMLSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XHTMLSerializer.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XMLSerializer.java?view=auto&rev=563600
==============================================================================
--- cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XMLSerializer.java (added)
+++ cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XMLSerializer.java Tue Aug  7 11:16:36 2007
@@ -0,0 +1,447 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.components.serializers.util;
+
+import java.io.CharArrayWriter;
+
+import org.apache.cocoon.components.serializers.encoding.XMLEncoder;
+import org.apache.commons.lang.SystemUtils;
+import org.xml.sax.SAXException;
+
+/**
+ * <p>A fancy XML serializer not relying on the JAXP API.</p>
+ *
+ * <p>For configuration options of this serializer, please look at the
+ * {@link EncodingSerializer}.</p>
+ *
+ * @version CVS $Id$
+ */
+public class XMLSerializer extends EncodingSerializer {
+
+    private static final XMLEncoder XML_ENCODER = new XMLEncoder();
+
+    private static final char S_EOL[] = SystemUtils.LINE_SEPARATOR.toCharArray();
+
+    private static final char S_DOCUMENT_1[] = "<?xml version=\"1.0".toCharArray();
+    private static final char S_DOCUMENT_2[] = "\" encoding=\"".toCharArray();
+    private static final char S_DOCUMENT_3[] = "\"?>".toCharArray();
+
+    private static final char S_ELEMENT_1[] = "=\"".toCharArray();
+    private static final char S_ELEMENT_2[] = "</".toCharArray();
+    private static final char S_ELEMENT_3[] = " />".toCharArray();
+    private static final char S_ELEMENT_4[] = " xmlns".toCharArray();
+
+    private static final char S_CDATA_1[] = "<[CDATA[".toCharArray();
+    private static final char S_CDATA_2[] = "]]>".toCharArray();
+
+    private static final char S_COMMENT_1[] = "<!--".toCharArray();
+    private static final char S_COMMENT_2[] = "-->".toCharArray();
+
+    private static final char S_PROCINSTR_1[] = "<?".toCharArray();
+    private static final char S_PROCINSTR_2[] = "?>".toCharArray();
+
+    private static final char C_LT = '<';
+    private static final char C_GT = '>';
+    private static final char C_SPACE = ' ';
+    private static final char C_QUOTE = '"';
+    private static final char C_NSSEP = ':';
+
+    private static final boolean DEBUG = false;
+
+    /* ====================================================================== */
+
+    /** Whether an element is left open like &quot;&lt;name &quot;. */
+    private boolean hanging_element = false;
+
+    /** True if we are processing the prolog. */
+    private boolean processing_prolog = true;
+
+    /** True if we are processing the DTD. */
+    private boolean processing_dtd = false;
+
+    /** A <code>Writer</code> for prolog elements. */
+    private PrologWriter prolog = new PrologWriter();
+
+    /* ====================================================================== */
+
+    /** The <code>DocType</code> instance representing the document. */
+    protected DocType doctype = null;
+
+    /* ====================================================================== */
+
+    /**
+     * Create a new instance of this <code>XMLSerializer</code>
+     */
+    public XMLSerializer() {
+        super(XML_ENCODER);
+    }
+
+    /**
+     * Create a new instance of this <code>XMLSerializer</code>
+     */
+    protected XMLSerializer(XMLEncoder encoder) {
+        super(encoder);
+    }
+
+    /**
+     * Reset this <code>XMLSerializer</code>.
+     */
+    public void recycle() {
+        super.recycle();
+        this.doctype = null;
+        this.hanging_element = false;
+        this.processing_prolog = true;
+        this.processing_dtd = false;
+        if (this.prolog != null) this.prolog.reset();
+    }
+
+    /**
+     * Return the MIME Content-Type produced by this serializer.
+     */
+    public String getMimeType() {
+        if (this.charset == null) return("text/xml");
+        return("text/xml; charset=" + this.charset.getName());
+    }
+
+    /* ====================================================================== */
+
+    /**
+     * Receive notification of the beginning of a document.
+     */
+    public void startDocument()
+    throws SAXException {
+        super.startDocument();
+        this.head();
+    }
+
+    /**
+     * Receive notification of the end of a document.
+     */
+    public void endDocument()
+    throws SAXException {
+        this.writeln();
+        super.endDocument();
+    }
+
+    /**
+     * Write the XML document header.
+     * <p>
+     * This method will write out the <code>&lt;?xml version=&quot;1.0&quot
+     * ...&gt;</code> header.
+     * </p>
+     */
+    protected void head()
+    throws SAXException {
+        this.write(S_DOCUMENT_1); // [<?xml version="1.0]
+        if (this.charset != null) {
+            this.write(S_DOCUMENT_2); // [" encoding="]
+            this.write(this.charset.getName());
+        }
+        this.write(S_DOCUMENT_3); // ["?>]
+        this.writeln();
+    }
+
+    /**
+     * Report the start of DTD declarations, if any.
+     */
+    public void startDTD(String name, String public_id, String system_id)
+    throws SAXException {
+        this.processing_dtd = true;
+        this.doctype = new DocType(name, public_id, system_id);
+    }
+
+    /**
+     * Report the start of DTD declarations, if any.
+     */
+    public void endDTD()
+    throws SAXException {
+        this.processing_dtd = false;
+    }
+
+    /**
+     * Receive notification of the beginning of the document body.
+     *
+     * @param uri The namespace URI of the root element.
+     * @param local The local name of the root element.
+     * @param qual The fully-qualified name of the root element.
+     */
+    public void body(String uri, String local, String qual)
+    throws SAXException {
+        this.processing_prolog = false;
+        this.writeln();
+
+        /* We have a document type. */
+        if (this.doctype != null) {
+
+            String root_name = this.doctype.getName();
+            /* Check the DTD and the root element */
+            if (!root_name.equals(qual)) {
+                throw new SAXException("Root element name \"" + root_name
+                        + "\" declared by document type declaration differs "
+                        + "from actual root element name \"" + qual + "\"");
+            }
+            /* Output the <!DOCTYPE ...> declaration. */
+            this.write(this.doctype.toString());
+        }
+
+        /* Output all PIs and comments we cached in the prolog */
+        this.prolog.writeTo(this);
+        this.writeln();
+    }
+
+    /**
+     * Receive notification of the beginning of an element.
+     *
+     * @param uri The namespace URI of the root element.
+     * @param local The local name of the root element.
+     * @param qual The fully-qualified name of the root element.
+     * @param namespaces An array of <code>String</code> objects containing
+     *                   the namespaces to be declared by this element.
+     * @param attributes An array of <code>String</code> objects containing
+     *                   all attributes of this element.
+     */
+    public void startElementImpl(String uri, String local, String qual,
+                                 String namespaces[][], String attributes[][])
+    throws SAXException {
+        this.closeElement(false);
+        this.write(C_LT); // [<]
+        if (DEBUG) {
+            this.write('[');
+            this.write(uri);
+            this.write(']');
+        }
+        this.write(qual);
+
+        for (int x = 0; x < namespaces.length; x++) {
+            this.write(S_ELEMENT_4); // [ xmlns]
+            if (namespaces[x][Namespaces.NAMESPACE_PREFIX].length() > 0) {
+                this.write(C_NSSEP); // [:]
+                this.write(namespaces[x][Namespaces.NAMESPACE_PREFIX]);
+            }
+            this.write(S_ELEMENT_1); // [="]
+            this.encode(namespaces[x][Namespaces.NAMESPACE_URI]);
+            this.write(C_QUOTE); // ["]
+        }
+
+        for (int x = 0; x < attributes.length; x++) {
+            this.write(C_SPACE); // [ ]
+            if (DEBUG) {
+                this.write('[');
+                this.write(attributes[x][ATTRIBUTE_NSURI]);
+                this.write(']');
+            }
+            this.write(attributes[x][ATTRIBUTE_QNAME]);
+            this.write(S_ELEMENT_1); // [="]
+            this.encode(attributes[x][ATTRIBUTE_VALUE]);
+            this.write(C_QUOTE); // ["]
+        }
+
+        this.hanging_element = true;
+    }
+
+    /**
+     * Receive notification of the end of an element.
+     *
+     * @param uri The namespace URI of the root element.
+     * @param local The local name of the root element.
+     * @param qual The fully-qualified name of the root element.
+     */
+    public void endElementImpl(String uri, String local, String qual)
+    throws SAXException {
+        if (closeElement(true)) return;
+        this.write(S_ELEMENT_2); // [</]
+        if (DEBUG) {
+            this.write('[');
+            this.write(uri);
+            this.write(']');
+        }
+        this.write(qual);
+        this.write(C_GT); // [>]
+    }
+
+    /**
+     * Write the end part of a start element (if necessary).
+     *
+     * @param end_element Whether this method was called because an element
+     *                    is being closed or not.
+     * @return <b>true</b> if this call successfully closed the element (and
+     *         no further <code>&lt;/element&gt;</code> is required.
+     */
+    protected boolean closeElement(boolean end_element)
+    throws SAXException {
+        if (!hanging_element) return false;
+        if (end_element) this.write(S_ELEMENT_3); // [ />]
+        else this.write(C_GT); // [>]
+        this.hanging_element = false;
+        return true;
+    }
+
+    /**
+     * Report the start of a CDATA section.
+     */
+    public void startCDATA()
+    throws SAXException {
+        if (this.processing_prolog) return;
+        this.closeElement(false);
+        this.write(S_CDATA_1); // [<[CDATA[]
+    }
+
+    /**
+     * Report the end of a CDATA section.
+     */
+    public void endCDATA()
+    throws SAXException {
+        if (this.processing_prolog) return;
+        this.closeElement(false);
+        this.write(S_CDATA_2); // []]>]
+    }
+
+    /**
+     * Receive notification of character data.
+     */
+    public void charactersImpl(char data[], int start, int length)
+    throws SAXException {
+        if (this.processing_prolog) return;
+        this.closeElement(false);
+        this.encode(data, start, length);
+    }
+
+    /**
+     * Receive notification of ignorable whitespace in element content.
+     */
+    public void ignorableWhitespace(char data[], int start, int length)
+    throws SAXException {
+        this.charactersImpl(data, start, length);
+    }
+
+    /**
+     * Report an XML comment anywhere in the document.
+     */
+    public void comment(char data[], int start, int length)
+    throws SAXException {
+        if (this.processing_dtd) return;
+
+        if (this.processing_prolog) {
+            this.prolog.write(S_COMMENT_1); // [<!--]
+            this.prolog.write(data, start, length);
+            this.prolog.write(S_COMMENT_2); // [-->]
+            this.prolog.write(S_EOL);
+            return;
+        }
+
+        this.closeElement(false);
+        this.write(S_COMMENT_1); // [<!--]
+        this.write(data, start, length);
+        this.write(S_COMMENT_2); // [-->]
+    }
+
+    /**
+     * Receive notification of a processing instruction.
+     */
+    public void processingInstruction(String target, String data)
+    throws SAXException {
+        if (this.processing_dtd) return;
+
+        if (this.processing_prolog) {
+            this.prolog.write(S_PROCINSTR_1); // [<?]
+            this.prolog.write(target);
+            if (data != null) {
+                this.prolog.write(C_SPACE); // [ ]
+                this.prolog.write(data);
+            }
+            this.prolog.write(S_PROCINSTR_2);  // [?>]
+            this.prolog.write(S_EOL);
+            return;
+        }
+
+        this.closeElement(false);
+
+        this.write(S_PROCINSTR_1); // [<?]
+        this.write(target);
+        if (data != null) {
+            this.write(C_SPACE); // [ ]
+            this.write(data);
+        }
+        this.write(S_PROCINSTR_2);  // [?>]
+    }
+
+    /**
+     * Report the beginning of some internal and external XML entities.
+     */
+    public void startEntity(String name)
+    throws SAXException {
+    }
+
+    /**
+     * Report the end of an entity.
+     */
+    public void endEntity(String name)
+    throws SAXException {
+    }
+
+    /**
+     * Receive notification of a skipped entity.
+     */
+    public void skippedEntity(String name)
+    throws SAXException {
+    }
+
+    /* ====================================================================== */
+
+    /**
+     * The <code>PrologWriter</code> is a simple extension to a
+     * <code>CharArrayWriter</code>.
+     */
+    private static final class PrologWriter extends CharArrayWriter {
+
+        /** Create a new <code>PrologWriter</code> instance. */
+        private PrologWriter() {
+            super();
+        }
+
+        /**
+         * Write an array of characters.
+         * <p>
+         * The <code>CharArrayWriter</code> implementation of this method
+         * throws an unwanted <code>IOException</code>.
+         * </p>
+         */
+        public void write(char c[]) {
+            this.write(c, 0, c.length);
+        }
+
+        /**
+         * Write a <code>String</code>.
+         * <p>
+         * The <code>CharArrayWriter</code> implementation of this method
+         * throws an unwanted <code>IOException</code>.
+         * </p>
+         */
+        public void write(String str) {
+            this.write(str, 0, str.length());
+        }
+
+        /**
+         * Write our contents to a <code>BaseSerializer</code> without
+         * copying the buffer.
+         */
+        public void writeTo(XMLSerializer serializer)
+        throws SAXException {
+            serializer.write(this.buf, 0, this.count);
+        }
+    }
+}

Propchange: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XMLSerializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-charsets/src/main/java/org/apache/cocoon/components/serializers/util/XMLSerializer.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-impl/src/main/java/org/apache/cocoon/components/serializers/HTMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-impl/src/main/java/org/apache/cocoon/components/serializers/HTMLSerializer.java?view=diff&rev=563600&r1=563599&r2=563600
==============================================================================
--- cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-impl/src/main/java/org/apache/cocoon/components/serializers/HTMLSerializer.java (original)
+++ cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-impl/src/main/java/org/apache/cocoon/components/serializers/HTMLSerializer.java Tue Aug  7 11:16:36 2007
@@ -16,11 +16,22 @@
  */
 package org.apache.cocoon.components.serializers;
 
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.avalon.excalibur.pool.Recyclable;
+import org.apache.avalon.framework.configuration.Configurable;
 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.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.environment.http.HttpEnvironment;
+import org.apache.cocoon.serialization.Serializer;
+import org.apache.cocoon.sitemap.SitemapModelComponent;
 import org.xml.sax.SAXException;
 
 /**
@@ -49,204 +60,43 @@
  *
  * @version $Id$
  */
-public class HTMLSerializer extends XHTMLSerializer {
-
-    /** A cross-browser compatible very simple document type declaration. */
-    public static final DocType HTML401_DOCTYPE_COMPATIBLE = new SGMLDocType(
-            "HTML", "-//W3C//DTD HTML 4.01 Transitional//EN", null);
-
-    /** A representation of the HTML 4.01 strict document type. */
-    public static final DocType HTML401_DOCTYPE_STRICT = new SGMLDocType(
-            "HTML", "-//W3C//DTD HTML 4.01//EN",
-            "http://www.w3.org/TR/html4/strict.dtd");
-
-    /** A representation of the HTML 4.01 transitional document type. */
-    public static final DocType HTML401_DOCTYPE_TRANSITIONAL = new SGMLDocType(
-            "HTML", "-//W3C//DTD HTML 4.01 Transitional//EN",
-            "http://www.w3.org/TR/html4/loose.dtd");
-
-    /** A representation of the HTML 4.01 frameset document type. */
-    public static final DocType HTML401_DOCTYPE_FRAMESET = new SGMLDocType(
-            "HTML", "-//W3C//DTD HTML 4.01 Frameset//EN",
-            "http://www.w3.org/TR/html4/frameset.dtd");
-
-    /* ====================================================================== */
-
-    private static final HTMLEncoder HTML_ENCODER = new HTMLEncoder();
-
-    protected boolean encodeCharacters = true;
-
-    /**
-     * Create a new instance of this <code>HTMLSerializer</code>
-     */
-    public HTMLSerializer() {
-        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. */
-    private static final String NAMESPACES[][] = new String[0][0];
-
-    /** Check if the URI is allowed by this serializer. */
-    private boolean checkNamespace(String nsuri) {
-        if (nsuri.length() == 0) return(true);
-        if (XHTML1_NAMESPACE.equals(nsuri)) return(true);
-        return(false);
-    }
-
-    /* ====================================================================== */
+public class HTMLSerializer
+    extends org.apache.cocoon.components.serializers.util.HTMLSerializer
+    implements Serializer, SitemapModelComponent, Recyclable, Configurable  {
 
     /**
-     * Write the XML document header.
-     * <p>
-     * This method overrides the default <code>XMLSerializer</code>.behaviour.
-     * </p>
+     * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
      */
-    public void head()
-    throws SAXException {
-        // NO NOTHING!
+    public void setup(SourceResolver resolver,
+                      Map            objectModel,
+                      String         src,
+                      Parameters     par)
+    throws ProcessingException, SAXException, IOException {
+        this.setup((HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT));
     }
 
-    /**
-     * Receive notification of the beginning of the document body.
-     *
-     * @param nsuri The namespace URI of the root element.
-     * @param local The local name of the root element.
-     * @param qual The fully-qualified name of the root element.
-     */
-    public void body(String nsuri, String local, String qual)
-    throws SAXException {
-        String name = local.toUpperCase();
-        if (! this.checkNamespace(nsuri)) {
-            throw new SAXException("Unsupported namespace \"" + nsuri + "\" "
-                                   + "for HTML root element \"" + qual + "\""
-                                   + this.getLocation());
-        }
-
-        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 if (this.doctype != null) {
-            /* The root element is uppercase, always!!! */
-            this.doctype = new SGMLDocType(this.doctype.getName().toUpperCase(),
-                                       this.doctype.getPublicId(),
-                                       this.doctype.getSystemId());
-        }
-        super.body(XHTML1_NAMESPACE, name, name);
-    }
 
     /**
-     * Receive notification of the beginning of an element.
+     * Test if the component wants to set the content length.
      */
-    public void startElementImpl(String nsuri, String local, String qual,
-                             String namespaces[][], String attributes[][])
-    throws SAXException {
-        String name = local.toUpperCase();
-        if (! this.checkNamespace(nsuri)) {
-            throw new SAXException("Unsupported namespace \"" + nsuri + "\" "
-                                   + "for HTML element \"" + qual + "\""
-                                   + this.getLocation());
-        }
-
-        int length = 0;
-        for (int x = 0; x < attributes.length; x ++) {
-            if (checkNamespace(attributes[x][ATTRIBUTE_NSURI])) length ++;
-        }
-
-        String at[][] = new String[length][ATTRIBUTE_LENGTH];
-        length = 0;
-        for (int x = 0; x < attributes.length; x ++) {
-            if (!checkNamespace(attributes[x][ATTRIBUTE_NSURI])) continue;
-
-            String at_name = attributes[x][ATTRIBUTE_LOCAL].toLowerCase();
-            at[length][ATTRIBUTE_NSURI] = XHTML1_NAMESPACE;
-            at[length][ATTRIBUTE_LOCAL] = at_name;
-            at[length][ATTRIBUTE_QNAME] = at_name;
-            at[length][ATTRIBUTE_VALUE] = attributes[x][ATTRIBUTE_VALUE];
-            length++;
-        }
-
-        // script and style are CDATA sections by default, so no encoding
-        if ( "SCRIPT".equals(name) || "STYLE".equals(name) ) {
-            this.encodeCharacters = false;
-        }
-        super.startElementImpl(XHTML1_NAMESPACE, name, name, NAMESPACES, at);
+    public boolean shouldSetContentLength() {
+        return false;
     }
 
     /**
-     * Receive notification of the end of an element.
+     * Set the configurations for this serializer.
      */
-    public void endElementImpl(String nsuri, String local, String qual)
-    throws SAXException {
-        this.closeElement(false);
-
-        String name = local.toUpperCase();
-        if (! this.checkNamespace(nsuri)) {
-            throw new SAXException("Unsupported namespace \"" + nsuri + "\" "
-                                   + "for HTML element \"" + qual + "\""
-                                   + this.getLocation());
-        }
-
-        if (name.equals("AREA")) return;
-        if (name.equals("BASE")) return;
-        if (name.equals("BASEFONT")) return;
-        if (name.equals("BR")) return;
-        if (name.equals("COL")) return;
-        if (name.equals("FRAME")) return;
-        if (name.equals("HR")) return;
-        if (name.equals("IMG")) return;
-        if (name.equals("INPUT")) return;
-        if (name.equals("ISINDEX")) return;
-        if (name.equals("LINK")) return;
-        if (name.equals("META")) return;
-        if (name.equals("PARAM")) return;
-
-        // script and style are CDATA sections by default, so no encoding
-        if ( "SCRIPT".equals(name) || "STYLE".equals(name) ) {
-            this.encodeCharacters = true;
+    public void configure(Configuration conf)
+    throws ConfigurationException {
+        String encoding = conf.getChild("encoding").getValue(null);
+        try {
+            this.setEncoding(encoding);
+        } catch (UnsupportedEncodingException exception) {
+            throw new ConfigurationException("Encoding not supported: "
+                                             + encoding, exception);
         }
-        super.endElementImpl(XHTML1_NAMESPACE, name, name);
-    }
 
-    /**
-     * Encode and write a specific part of an array of characters.
-     */
-    protected void encode(char data[], int start, int length)
-    throws SAXException {
-        if ( !this.encodeCharacters ) {
-            this.write(data, start, length);
-            return;
-        }
-        super.encode(data, start, length);
+        this.setIndentPerLevel(conf.getChild("indent").getValueAsInteger(0));
+        this.setDoctypeDefault(conf.getChild("doctype-default").getValue(null));
     }
 }

Modified: cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-impl/src/main/java/org/apache/cocoon/components/serializers/XHTMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-impl/src/main/java/org/apache/cocoon/components/serializers/XHTMLSerializer.java?view=diff&rev=563600&r1=563599&r2=563600
==============================================================================
--- cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-impl/src/main/java/org/apache/cocoon/components/serializers/XHTMLSerializer.java (original)
+++ cocoon/trunk/blocks/cocoon-serializers/cocoon-serializers-impl/src/main/java/org/apache/cocoon/components/serializers/XHTMLSerializer.java Tue Aug  7 11:16:36 2007
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,16 +16,28 @@
  */
 package org.apache.cocoon.components.serializers;
 
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.avalon.excalibur.pool.Recyclable;
+import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.cocoon.components.serializers.encoding.XHTMLEncoder;
-import org.apache.cocoon.components.serializers.util.DocType;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.cocoon.environment.http.HttpEnvironment;
+import org.apache.cocoon.serialization.Serializer;
+import org.apache.cocoon.sitemap.SitemapModelComponent;
 import org.xml.sax.SAXException;
 
 /**
  * <p>A pedantinc XHTML serializer encoding all recognized entities with their
- * proper HTML names.</p> 
- * 
+ * proper HTML names.</p>
+ *
  * <p>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
@@ -37,187 +49,61 @@
  *   &lt;doctype-default&gt;mytype&lt;/doctype-default&gt;
  * &lt;/serializer&gt;
  * </pre>
- * 
+ *
  * <p>The value <i>mytype</i> can be one of:</p>
- * 
+ *
  * <dl>
  *   <dt>"<code>none</code>"</dt>
- *   <dd>Not to emit any dococument type declaration.</dd> 
+ *   <dd>Not to emit any dococument type declaration.</dd>
  *   <dt>"<code>strict</code>"</dt>
- *   <dd>The XHTML 1.0 Strict document type.</dd> 
+ *   <dd>The XHTML 1.0 Strict document type.</dd>
  *   <dt>"<code>loose</code>"</dt>
- *   <dd>The XHTML 1.0 Transitional document type.</dd> 
+ *   <dd>The XHTML 1.0 Transitional document type.</dd>
  *   <dt>"<code>frameset</code>"</dt>
  *   <dd>The XHTML 1.0 Frameset document type.</dd>
- * </dl> 
+ * </dl>
  *
  * @version $Id$
  */
-public class XHTMLSerializer extends XMLSerializer {
-
-    /** The namespace URI for XHTML 1.0. */
-    public static final String XHTML1_NAMESPACE =
-            "http://www.w3.org/1999/xhtml";
-
-    /** A representation of the XHTML 1.0 strict document type. */
-    public static final DocType XHTML1_DOCTYPE_STRICT = new DocType(
-            "html", "-//W3C//DTD XHTML 1.0 Strict//EN",
-            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
-
-    /** A representation of the XHTML 1.0 transitional document type. */
-    public static final DocType XHTML1_DOCTYPE_TRANSITIONAL = new DocType(
-            "html", "-//W3C//DTD XHTML 1.0 Transitional//EN",
-            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd");
-
-    /** A representation of the XHTML 1.0 frameset document type. */
-    public static final DocType XHTML1_DOCTYPE_FRAMESET = new DocType(
-            "html", "-//W3C//DTD XHTML 1.0 Frameset//EN",
-            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd");
-
-    /* ====================================================================== */
-
-    private static final XHTMLEncoder XHTML_ENCODER = new XHTMLEncoder();
-
-    /* ====================================================================== */
-
-    /** The <code>DocType</code> instance representing the document. */
-    protected DocType doctype_default = null;
-    
-    /** Define whether to put XML declaration in the head of the document. */
-    private String omitXmlDeclaration = null;
-
-    /* ====================================================================== */
+public class XHTMLSerializer
+    extends org.apache.cocoon.components.serializers.util.XHTMLSerializer
+    implements Serializer, SitemapModelComponent, Recyclable, Configurable  {
 
     /**
-     * Create a new instance of this <code>XHTMLSerializer</code>
+     * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
      */
-    public XHTMLSerializer() {
-        super(XHTML_ENCODER);
+    public void setup(SourceResolver resolver,
+                      Map            objectModel,
+                      String         src,
+                      Parameters     par)
+    throws ProcessingException, SAXException, IOException {
+        this.setup((HttpServletRequest) objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT));
     }
 
+
     /**
-     * Create a new instance of this <code>XHTMLSerializer</code>
-     */
-    protected XHTMLSerializer(XHTMLEncoder encoder) {
-        super(encoder);
-    }
-    
-    /**
-     * Return the MIME Content-Type produced by this serializer.
+     * Test if the component wants to set the content length.
      */
-    public String getMimeType() {
-        if (this.charset == null) return("text/html");
-        return("text/html; charset=" + this.charset.getName());
+    public boolean shouldSetContentLength() {
+        return false;
     }
 
     /**
-     * Configure this instance by selecting the default document type to use.
+     * Set the configurations for this serializer.
      */
     public void configure(Configuration conf)
     throws ConfigurationException {
-        super.configure(conf);
-
-        this.omitXmlDeclaration = conf.getChild("omit-xml-declaration").getValue(null);
-
-        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;
-        }
-    }
-
-    /* ====================================================================== */
-
-    /**
-     * Write the XML document header.
-     * <p>
-     * This method will write out the <code>&lt;?xml version=&quot;1.0&quot
-     * ...&gt;</code> header unless omit-xml-declaration is set.
-     * </p>
-     */
-    protected void head()
-    throws SAXException {
-        if (!"yes".equals(this.omitXmlDeclaration)) {
-            super.head();
-        }
-    }
-
-    /**
-     * Receive notification of the beginning of the document body.
-     *
-     * @param uri The namespace URI of the root element.
-     * @param local The local name of the root element.
-     * @param qual The fully-qualified name of the root element.
-     */
-    public void body(String uri, String local, String qual)
-    throws SAXException {
-        if (this.doctype == null) this.doctype = this.doctype_default;
-        if (this.namespaces.getUri("").length() == 0) {
-            this.namespaces.push("", XHTML1_NAMESPACE);
+        String encoding = conf.getChild("encoding").getValue(null);
+        try {
+            this.setEncoding(encoding);
+        } catch (UnsupportedEncodingException exception) {
+            throw new ConfigurationException("Encoding not supported: "
+                                             + encoding, exception);
         }
-        super.body(uri, local, qual);
-    }
 
-    /**
-     * Receive notification of the beginning of an element.
-     *
-     * @param uri The namespace URI of the root element.
-     * @param local The local name of the root element.
-     * @param qual The fully-qualified name of the root element.
-     * @param namespaces An array of <code>String</code> objects containing
-     *                   the namespaces to be declared by this element.
-     * @param attributes An array of <code>String</code> objects containing
-     *                   all attributes of this element.
-     */
-    public void startElementImpl(String uri, String local, String qual,
-                                 String namespaces[][], String attributes[][])
-    throws SAXException {
-        if (uri.length() == 0) uri = XHTML1_NAMESPACE;
-        super.startElementImpl(uri, local, qual, namespaces, attributes);
+        this.setIndentPerLevel(conf.getChild("indent").getValueAsInteger(0));
+        this.setOmitXmlDeclaration(conf.getChild("omit-xml-declaration").getValue(null));
+        this.setDoctypeDefault(conf.getChild("doctype-default").getValue(null));
     }
 
-    /**
-     * Receive notification of the end of an element.
-     *
-     * @param uri The namespace URI of the root element.
-     * @param local The local name of the root element.
-     * @param qual The fully-qualified name of the root element.
-     */
-    public void endElementImpl(String uri, String local, String qual)
-    throws SAXException {
-        if (uri.length() == 0) uri = XHTML1_NAMESPACE;
-
-        if (XHTML1_NAMESPACE.equals(uri)) {
-            if ((local.equalsIgnoreCase("textarea")) ||
-                (local.equalsIgnoreCase("script")) ||
-                (local.equalsIgnoreCase("style"))) {
-                this.closeElement(false);
-            } else if (local.equalsIgnoreCase("head")) {
-                String loc = "meta";
-                String qua = namespaces.qualify(XHTML1_NAMESPACE, loc, "meta");
-                String nsp[][] = new String[0][0];
-                String att[][] = new String[2][ATTRIBUTE_LENGTH];
-
-                att[0][ATTRIBUTE_NSURI] = att[1][ATTRIBUTE_NSURI] = "";
-                att[0][ATTRIBUTE_LOCAL] = att[0][ATTRIBUTE_QNAME] = "http-equiv";
-                att[1][ATTRIBUTE_LOCAL] = att[1][ATTRIBUTE_QNAME] = "content";
-                att[0][ATTRIBUTE_VALUE] = "Content-Type";
-                att[1][ATTRIBUTE_VALUE] = this.getMimeType();
-
-                this.closeElement(false);
-                this.startElementImpl(XHTML1_NAMESPACE, loc, qua, nsp, att);
-                this.endElementImpl(XHTML1_NAMESPACE, loc, qua);
-            }
-        }
-        super.endElementImpl(uri, local, qual);
-    }
-    
 }



Mime
View raw message