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:09:13 GMT
sylvain     2002/12/01 14:09:12

  Modified:    .        Tag: cocoon_2_0_3_branch changes.xml
               src/documentation/xdocs/userdocs/generators Tag:
                        cocoon_2_0_3_branch html-generator.xml
               src/java/org/apache/cocoon/generation Tag:
                        cocoon_2_0_3_branch HTMLGenerator.java
  Log:
  The HTMLGenerator now accepts a JTidy configuration file for fine-grained control on the
generated document.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.138.2.74 +5 -1      xml-cocoon2/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/changes.xml,v
  retrieving revision 1.138.2.73
  retrieving revision 1.138.2.74
  diff -u -r1.138.2.73 -r1.138.2.74
  --- changes.xml	30 Nov 2002 10:23:54 -0000	1.138.2.73
  +++ changes.xml	1 Dec 2002 22:09:11 -0000	1.138.2.74
  @@ -39,6 +39,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="CH" type="fix">
      New Logicsheet for use with InputModules.
     </action>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +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.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- html-generator.xml	3 Jan 2002 12:31:04 -0000	1.1
  +++ html-generator.xml	1 Dec 2002 22:09:12 -0000	1.1.2.1
  @@ -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>
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.14.2.2  +50 -3     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.14.2.1
  retrieving revision 1.14.2.2
  diff -u -r1.14.2.1 -r1.14.2.2
  --- HTMLGenerator.java	29 Nov 2002 08:52:16 -0000	1.14.2.1
  +++ HTMLGenerator.java	1 Dec 2002 22:09:12 -0000	1.14.2.2
  @@ -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;
  @@ -60,11 +64,13 @@
   import org.apache.cocoon.caching.CacheValidity;
   import org.apache.cocoon.caching.Cacheable;
   import org.apache.cocoon.caching.TimeStampCacheValidity;
  +import org.apache.cocoon.components.url.URLFactory;
   import org.apache.avalon.excalibur.xml.xpath.XPathProcessor;
   import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.cocoon.environment.Request;
   import org.apache.cocoon.environment.Source;
   import org.apache.cocoon.environment.SourceResolver;
  +import org.apache.cocoon.environment.URLFactorySourceResolver;
   import org.apache.cocoon.util.HashUtil;
   import org.apache.cocoon.xml.dom.DOMStreamer;
   import org.apache.cocoon.xml.XMLUtils;
  @@ -83,15 +89,17 @@
   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>
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @author <a href="mailto:barozzi@nicolaken.com">Nicola Ken Barozzi</a>
  + * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
    * @version CVS $Id$
    */
   public class HTMLGenerator extends ComposerGenerator
  -implements Cacheable, Disposable {
  +implements Configurable, Cacheable, Disposable {
   
       /** The  source */
       private Source inputSource;
  @@ -101,6 +109,9 @@
   
       /** XPath Processor */
       private XPathProcessor processor = null;
  +    
  +    /** JTidy properties */
  +    private Properties properties;
   
       public void compose(ComponentManager manager)
       throws ComponentException {
  @@ -112,6 +123,36 @@
           }
       }
   
  +    public void configure(Configuration config) throws ConfigurationException {
  +
  +        String configUrl = config.getChild("jtidy-config").getValue(null);
  +
  +        if(configUrl != null) {
  +            URLFactory urlFactory = null;
  +            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.
        * All instance variables are set to <code>null</code>.
  @@ -196,7 +237,13 @@
               // Setup an instance of Tidy.
               Tidy tidy = new Tidy();
               tidy.setXmlOut(true);
  -            tidy.setXHTML(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