cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kees Broenink" <kees.broen...@backbase.com>
Subject RE: Suggestion for XHTMLSerializer
Date Fri, 05 Aug 2005 12:09:16 GMT
You basically removed one line of code in the configure() method, right?

        this.format.put(OutputKeys.METHOD,"xml");

Cool!!

I will adopt this and see if it works with xalan, saxon and xsltc.

Thanks,

Kees


-----Oorspronkelijk bericht-----
Van: news [mailto:news@sea.gmane.org] Namens BURGHARD Éric
Verzonden: Friday, August 05, 2005 1:50 PM
Aan: dev@cocoon.apache.org
Onderwerp: Re: Suggestion for XHTMLSerializer


Thorsten Scherler wrote:

> On Tue, 2005-08-02 at 11:25 +0200, Antonio Fiol Bonnín wrote:
>> Hello,
>> 
>> I am finding a problem with empty elements when serving content with 
>> the text/html content type on Firefox.
> 
>> For example, collapsed empty div elements cause havoc in firefox. A 
>> possible workaround would be implementing the compatibility 
>> guidelines indicated in the W3C recommendations.
>> 
>> In particular, I would add the same check already present for style, 
>> script and textarea for any element whose end tag is required in HTML

>> 4.01.
>> 
> 

I found a simple solution to this problem.

In fact the XMLSerializer didn't take the 'method' parameter into
account. At least in saxon8 (never test with other xslt processor, but
it should work too), if you put <xsl:output method="xhtml"/> all tags
like div, script, or inputarea remains unclosed.

I think this is a bug with XMLSerializer which enforce the method to be
'xml'. The folowing simple class let you choose the serialization
method.

public class XMLSerializer2 extends AbstractTextSerializer {

    /**
     * Set the configurations for this serializer.
     */
    public void configure(Configuration conf)
    throws ConfigurationException {
        super.configure( conf );
    }

    /**
     * Set the {@link OutputStream} where the requested resource should
     * be serialized.
     */
    public void setOutputStream(OutputStream out) throws IOException {
        super.setOutputStream(out);
        try {
            TransformerHandler handler = this.getTransformerHandler();
            handler.getTransformer().setOutputProperties(this.format);
            handler.setResult(new StreamResult(this.output));
            this.setContentHandler(handler);
            this.setLexicalHandler(handler);
        } catch (Exception e) {
            final String message = "Cannot set XMLSerializer
outputstream"; 
            throw new CascadingIOException(message, e);
        }
    }

}

Now just configure this serializer in sitemap.xmap like you do with
regular XMLSerializer.

<map:serializer logger="sitemap.serializer.xhtml" mime-type="text/html"
name="xhtml" pool-grow="2" pool-max="64" pool-min="2"
src="org.apache.cocoon.serialization.XMLSerializer2">
                <doctype-public>-//W3C//DTD XHTML 1.0
Strict//EN</doctype-public>

<doctype-system>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</docty
pe-system>
                <encoding>UTF-8</encoding>
                <!-- for i6 compat mode-->
                <omit-xml-declaration>yes</omit-xml-declaration>
                <method>xhtml</method>
<transformer-factory>net.sf.saxon.TransformerFactoryImpl</transformer-fa
ctory>
</map:serializer>

I wrote a much more powerfull solution: the XSLSerializer, which let you
control the serialization through an xsl stylesheet (an so use the
xsl:output tag as well as some template rules to make final cleanup like
namespace deletion or href contextualization). I need to do some
cleanup, and i will submit a patch.

Regards



Mime
View raw message