cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sylv...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/generation HTMLGenerator.java
Date Sun, 01 Dec 2002 22:11:24 GMT
sylvain     2002/12/01 14:11:24

  Modified:    .        changes.xml
               src/documentation/xdocs/userdocs/generators
                        html-generator.xml
               src/java/org/apache/cocoon/generation HTMLGenerator.java
  Log:
  The HTMLGenerator now accepts a JTidy configuration file for fine-grained control on the
generated document.
  
  Revision  Changes    Path
  1.295     +5 -1      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.294
  retrieving revision 1.295
  diff -u -r1.294 -r1.295
  --- changes.xml	28 Nov 2002 23:34:32 -0000	1.294
  +++ changes.xml	1 Dec 2002 22:11:24 -0000	1.295
  @@ -40,6 +40,10 @@
    </devs>
   
    <release version="@version@" date="@date@">
  +  <action dev="SW" type="update">
  +   The HTMLGenerator now accepts a JTidy configuration file for fine-grained
  +   control on the generated document.
  +  </action>
     <action dev="NKB" type="update">
       Removed ./tools/build-i.xml and moved the interactive targets in main build.
       Removed ./tools/build-s.xml and removed all references to scratchpad builds (not used).
   
  
  
  
  1.2       +22 -1     xml-cocoon2/src/documentation/xdocs/userdocs/generators/html-generator.xml
  
  Index: html-generator.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/documentation/xdocs/userdocs/generators/html-generator.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- html-generator.xml	3 Jan 2002 12:31:04 -0000	1.1
  +++ html-generator.xml	1 Dec 2002 22:11:24 -0000	1.2
  @@ -8,6 +8,7 @@
   		<type>Technical document</type>
   		<authors>
   			<person name="Carsten Ziegeler" email="cziegeler@apache.org"/>
  +			<person name="Sylvain Wallez" email="sylvain@apache.org"/>
   		 </authors>
   		 <abstract>This document describes the html generator of Cocoon.</abstract>
   	</header>
  @@ -15,7 +16,8 @@
   		<s1 title="HTML Generator">
   			<p>The html generator reads an html document from the local file system or from
any url.
   	               It acts similar to the file generator with the difference that it reads
  -                     html documents and converts them using jtidy to xhtml.</p>
  +                     html documents and converts them using <link href="http://sourceforge.net/projects/jtidy">JTidy</link>
  +                     to xhtml.</p>
   			<p>This generator is optional and requires the jtidy package
                        in the lib directory when building Cocoon. However,
                        the distribution includes this package already.</p>
  @@ -31,6 +33,25 @@
     <map:generate src="document.html" type="html"/>
        ]]>
   </source>
  +		</s1>
  +		<s1 title="Configuring JTidy">
  +		  <p>Without any configuration, the generator produces an XHTML document, with
the proper namespace. However,
  +		     JTidy offers a full range of options for converting the HTML document to XML.</p>
  +		  <p>These options can be specified in a properties file (key=value pairs) whose
location is given in the
  +		     component configuration :</p>
  +		  <source>
  +		    <![CDATA[
  +  <map:generator type="html" src="org.apache.cocoon.generation.HTMLGenerator">
  +    <jtidy-config>jtidy.properties</jtidy-config>
  +  </map:generator>
  +		    ]]>
  +		  </source>
  +		  <p>The <code>jtidy-config</code> URL can be either relative (to the
application context), one of Cocoon's special
  +		     protocols such as <code>resouce:</code> which searches the file in the
classpath.</p>
  +		  <p>For more information on the available configurations, please refer to the
  +		     <link href="http://www.w3.org/People/Raggett/tidy/">original Tidy page</link>.
Beware that configuration
  +		     examples shown there use the ':' as a separator when JTidy requires a '=' as it
is a standard Java properties file.
  +		  </p>
   		</s1>
   
   	</body>
  
  
  
  1.20      +48 -2     xml-cocoon2/src/java/org/apache/cocoon/generation/HTMLGenerator.java
  
  Index: HTMLGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/generation/HTMLGenerator.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- HTMLGenerator.java	6 Sep 2002 14:25:45 -0000	1.19
  +++ HTMLGenerator.java	1 Dec 2002 22:11:24 -0000	1.20
  @@ -50,6 +50,10 @@
   */
   package org.apache.cocoon.generation;
   
  +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.activity.Disposable;
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentManager;
  @@ -58,11 +62,13 @@
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.ResourceNotFoundException;
   import org.apache.cocoon.caching.CacheableProcessingComponent;
  +import org.apache.cocoon.components.url.URLFactory;
   import org.apache.avalon.excalibur.xml.xpath.XPathProcessor;
   import org.apache.cocoon.components.source.SourceUtil;
   import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.cocoon.environment.Request;
   import org.apache.cocoon.environment.SourceResolver;
  +import org.apache.cocoon.environment.URLFactorySourceResolver;
   import org.apache.cocoon.xml.dom.DOMStreamer;
   import org.apache.cocoon.xml.XMLUtils;
   import org.apache.excalibur.source.Source;
  @@ -83,6 +89,7 @@
   import java.io.IOException;
   import java.util.Enumeration;
   import java.util.Map;
  +import java.util.Properties;
   
   /**
    * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
  @@ -91,7 +98,7 @@
    * @version CVS $Id$
    */
   public class HTMLGenerator extends ComposerGenerator
  -implements CacheableProcessingComponent, Disposable {
  +implements Configurable, CacheableProcessingComponent, Disposable {
   
       /** The  source */
       private Source inputSource;
  @@ -102,11 +109,44 @@
       /** XPath Processor */
       private XPathProcessor processor = null;
   
  +    /** JTidy properties */
  +    private Properties properties;
  +
       public void compose(ComponentManager manager)
       throws ComponentException {
           super.compose( manager );
           this.processor = (XPathProcessor)this.manager.lookup(XPathProcessor.ROLE);
       }
  +    
  +    public void configure(Configuration config) throws ConfigurationException {
  +
  +        String configUrl = config.getChild("jtidy-config").getValue(null);
  +
  +        if(configUrl != null) {
  +            URLFactory urlFactory = null;
  +            org.apache.cocoon.environment.Source configSource = null;
  +            try {
  +                urlFactory = (URLFactory)this.manager.lookup(URLFactory.ROLE);
  +                URLFactorySourceResolver urlResolver = new URLFactorySourceResolver(urlFactory,
this.manager);
  +                configSource = urlResolver.resolve(configUrl);
  +                if (getLogger().isDebugEnabled()) {
  +                    getLogger().debug("Loading configuration from " + configSource.getSystemId());
  +                }
  +                
  +                this.properties = new Properties();
  +                this.properties.load(configSource.getInputStream());
  +                
  +            } catch (Exception e) {
  +                getLogger().warn("Cannot load configuration from " + configUrl);
  +                throw new ConfigurationException("Cannot load configuration from " + configUrl,
e);
  +            } finally {
  +                this.manager.release(urlFactory);
  +                if (configSource != null) {
  +                    configSource.recycle();
  +                }
  +            }
  +        }
  +    }
   
       /**
        * Recycle this component.
  @@ -190,7 +230,13 @@
               // Setup an instance of Tidy.
               Tidy tidy = new Tidy();
               tidy.setXmlOut(true);
  +            
  +            if (this.properties == null) {
               tidy.setXHTML(true);
  +            } else {
  +                tidy.setConfigurationFromProps(this.properties);
  +            }
  +
               //Set Jtidy warnings on-off
               tidy.setShowWarnings(getLogger().isWarnEnabled());
               //Set Jtidy final result summary on-off
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message