-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I'm currently writing a serializer which uses Tidy instead of xalan. I hope to have fewer problems with serializing well formatted HTML. The serializer is mixed out of AbstractSerializer and HTMLGenerator. It compiles without errors, but I always get an empty output. No warning, no error. When I extract the code into a test program, it works without problems. I hope someone can give me a hint. I've marked the problem with "PROBLEM:" and given some explainations what I've already tried. Oh yes, the serializer is avalaible for inclusing, should it work some time. I think it's very slow, as it uses DOM and not SAX, but it is OK for command line mode and for testing.
Thanks in advance Torsten Knodt -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (GNU/Linux) iD8DBQE99TKkvxZktkzSmiwRAuD9AJ9rWmHJmEd7XLl9wVBu7zIyB+oBPACfaWPB lKjwIu7gGFfZRa8iX0z6zzs= =4lKD -----END PGP SIGNATURE-----
/* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.serialization; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.ResourceNotFoundException; import org.apache.cocoon.caching.CacheableProcessingComponent; import org.apache.cocoon.components.source.SourceUtil; import org.apache.cocoon.xml.XMLUtils; import org.apache.cocoon.xml.dom.DOMBuilder; import org.apache.excalibur.source.Source; import org.apache.excalibur.source.SourceException; import org.apache.excalibur.source.SourceValidity; import org.apache.excalibur.source.impl.validity.NOPValidity; import org.w3c.tidy.Tidy; import org.w3c.tidy.DOMDocumentImpl; import org.w3c.dom.Document; import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.util.Properties; /** * @author <a href="mailto:[EMAIL PROTECTED]">Torsten Knodt</a> */ public class TidySerializer extends DOMBuilder implements Configurable, CacheableProcessingComponent, Serializer, DOMBuilder.Listener { /** * The <code>OutputStream</code> used by this serializer. */ protected OutputStream output; /** JTidy properties */ private Properties properties; public TidySerializer() { super((Listener) null, Tidy.createEmptyDocument()); listener = this; } /** * Receive notification of a successfully completed DOM tree generation. */ public void notify(Document doc) { // Setup an instance of Tidy. Tidy tidy = new Tidy(); //Import Jtidy properties tidy.setConfigurationFromProps (this.properties); //Set Jtidy warnings on-off tidy.setShowWarnings(getLogger().isWarnEnabled()); //Set Jtidy final result summary on-off tidy.setQuiet(!getLogger().isInfoEnabled()); //Set Jtidy infos to a String (will be logged) instead of System.out StringWriter stringWriter = new StringWriter(); PrintWriter errorWriter = new PrintWriter(stringWriter); tidy.setErrout(errorWriter); // FIXME: Jtidy doesn't warn or strip duplicate attributes in same // tag; stripping. XMLUtils.stripDuplicateAttributes(doc, null); if (this.output == null && getLogger().isErrorEnabled()) getLogger().error("Output is null"); if (! (doc instanceof DOMDocumentImpl) && getLogger().isErrorEnabled()) getLogger().error("Document is not of jTidy's DOM Document Implementation"); /* PROBLEM: Always results in no output - even when I replace doc with Tidy.createEmptyDocument() - or this.output with System.out - No errors, no warnings, no Info Has someone a hint what goes wrong? */ tidy.pprint (doc, this.output); errorWriter.flush(); errorWriter.close(); final String errStr = stringWriter.toString(); if(getLogger().isWarnEnabled() && errStr != null && ! "".equals (errStr)){ getLogger().warn(stringWriter.toString()); } } /** * Get the mime-type of the output of this <code>Serializer</code> * This default implementation returns null to indicate that the * mime-type specified in the sitemap is to be used */ public String getMimeType() { /* FIXME: Set MIME-Type based on tidy configuration */ return null; } /** * Set the {@link OutputStream} where the requested resource should * be serialized. */ public void setOutputStream(OutputStream out) throws IOException { this.output = out; } /** * configure TidySerializer * Properties are read via parameters */ public void configure(Configuration config) throws ConfigurationException { this.properties = Parameters.toProperties (Parameters.fromConfiguration (config)); } /** * Recycle serializer by removing references */ public void recycle() { super.recycle(); this.output = null; } /** * Test if the component wants to set the content length */ public boolean shouldSetContentLength() { return false; } /** * Generate the unique key. * This key must be unique inside the space of this component. * This method must be invoked before the generateValidity() method. * * @return The generated key or <code>0</code> if the component * is currently not cacheable. */ public java.io.Serializable generateKey() { return "1"; } /** * Generate the validity object. * Before this method can be invoked the generateKey() method * must be invoked. * * @return The generated validity object or <code>null</code> if the * component is currently not cacheable. */ public SourceValidity generateValidity() { return NOPValidity.SHARED_INSTANCE; } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]