cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Davanum Srinivas <d...@yahoo.com>
Subject Re: [C2] [2.1-dev patch] XSLTProcessor component
Date Tue, 14 Aug 2001 15:01:30 GMT
Ovidiu,
Checked in the new components. Please cross-check. This is only in C2.1

Thanks,
dims

--- Ovidiu Predescu <ovidiu@cup.hp.com> wrote:
> 
> Hi,
> 
> The following patch refactors the current TraxTransformer into a
> Transformer and a Component.
> 
> In addition to the functionality needed by the TraxTransformer, the
> new XSLTProcessor component provides a simple method for applying an
> XSLT transformation on a Source object.
> 
> Similar with the way the TraxTransformer worked, the stylesheets are
> cached locally into a Store object for speed.
> 
> Greetings,
> -- 
> Ovidiu Predescu <ovidiu@cup.hp.com>
> http://orion.nsr.hp.com/ (inside HP's firewall only)
> http://sourceforge.net/users/ovidiu/ (my SourceForge page)
> http://www.geocities.com/SiliconValley/Monitor/7464/ (GNU, Emacs, other stuff)
> 
> > Index: src/org/apache/cocoon/cocoon.roles
> ===================================================================
> RCS file: /Repository/Cocoon2/src/org/apache/cocoon/cocoon.roles,v
> retrieving revision 1.1.1.5
> diff -u -u -I\$Id:.*\$ -I\$Revision:.*\$ -I\$Author:.*\$ -r1.1.1.5 cocoon.roles
> --- cocoon.roles	2001/08/10 02:26:16	1.1.1.5
> +++ cocoon.roles	2001/08/14 03:04:58
> @@ -5,6 +5,10 @@
>         shorthand="parser"
>         default-class="org.apache.cocoon.components.parser.JaxpParser"/>
>  
> + <role name="org.apache.cocoon.components.xslt.XSLTProcessor"
> +       shorthand="xslt-processor"
> +       default-class="org.apache.cocoon.components.xslt.XSLTProcessorImpl"/>
> +
>   <role name="org.apache.cocoon.components.browser.Browser"
>         shorthand="browser"
>         default-class="org.apache.cocoon.components.browser.BrowserImpl"/>
> Index: src/org/apache/cocoon/components/xslt/XSLTProcessor.java
> ===================================================================
> RCS file: XSLTProcessor.java
> diff -N XSLTProcessor.java
> --- /dev/null	Tue May  5 13:32:27 1998
> +++ XSLTProcessor.java	Mon Aug 13 20:04:58 2001
> @@ -0,0 +1,76 @@
> +/*****************************************************************************
> + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
> + * ------------------------------------------------------------------------- *
> + * This software is published under the terms of the Apache Software License *
> + * version 1.1, a copy of which has been included  with this distribution in *
> + * the LICENSE file.                                                         *
> + *****************************************************************************/
> +package org.apache.cocoon.components.xslt;
> +
> +import javax.xml.transform.sax.TransformerHandler;
> +import javax.xml.transform.TransformerConfigurationException;
> +import javax.xml.transform.Result;
> +import java.io.IOException;
> +
> +import org.xml.sax.SAXException;
> +import org.apache.cocoon.environment.SourceResolver;
> +import org.apache.cocoon.environment.Source;
> +import org.apache.cocoon.ProcessingException;
> +import org.apache.avalon.framework.parameters.Parameters;
> +
> +/**
> + * This is the interface of the XSLT processor in Cocoon.
> + *
> + * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
> + * @version 1.0
> + * @since   July 11, 2001
> + */
> +public interface XSLTProcessor
> +{
> +  /**
> +   * The role implemented by an <code>XSLTProcessor</code>.
> +   */
> +  String ROLE = "org.apache.cocoon.components.xslt.XSLTProcessor";
> +
> +  /**
> +   * Set the {@link org.apache.cocoon.environment.SourceResolver} for
> +   * this instance. The <code>resolver</code> is invoked to return a
> +   * <code>Source</code> object, given an HREF.
> +   *
> +   * @param resolver a <code>SourceResolver</code> value
> +   */
> +  public void setSourceResolver(SourceResolver resolver);
> +  
> +  /**
> +   * Return a <code>TransformerHandler</code> for a given stylesheet
> +   * <code>Source</code>. This can be used in a pipeline to handle the
> +   * transformation of a stream of SAX events. See {@link
> +   * org.apache.cocoon.transformation.TraxTransformer#setConsumer} for
> +   * an example of how to use this method.
> +   *
> +   * @param stylesheet a <code>Source</code> value
> +   * @return a <code>TransformerHandler</code> value
> +   * @exception ProcessingException if an error occurs
> +   * @see org.apache.cocoon.transformation.TraxTransformer#setConsumer
> +   */
> +  public TransformerHandler getTransformerHandler(Source stylesheet)
> +    throws ProcessingException;
> +
> +  /**
> +   * Applies an XSLT stylesheet to an XML document. The source and
> +   * stylesheet documents are specified as <code>Source</code>
> +   * objects. The result of the transformation is placed in
> +   * <code>result</code>, which should be properly initialized before
> +   * invoking this method. Any additional parameters passed in
> +   * <code>params</code> will become arguments to the stylesheet.
> +   *
> +   * @param source a <code>Source</code> value
> +   * @param stylesheet a <code>Source</code> value
> +   * @param params a <code>Parameters</code> value
> +   * @param result a <code>Result</code> value
> +   * @exception ProcessingException if an error occurs
> +   */
> +  public void transform(Source source, Source stylesheet, Parameters params,
> +                        Result result)
> +    throws ProcessingException;
> +}
> Index: src/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java
> ===================================================================
> RCS file: XSLTProcessorImpl.java
> diff -N XSLTProcessorImpl.java
> --- /dev/null	Tue May  5 13:32:27 1998
> +++ XSLTProcessorImpl.java	Mon Aug 13 20:04:58 2001
> @@ -0,0 +1,342 @@
> +/*****************************************************************************
> + * Copyright (C) The Apache Software Foundation. All rights reserved.        *
> + * ------------------------------------------------------------------------- *
> + * This software is published under the terms of the Apache Software License *
> + * version 1.1, a copy of which has been included  with this distribution in *
> + * the LICENSE file.                                                         *
> + *****************************************************************************/
> +package org.apache.cocoon.components.xslt;
> +
> +import javax.xml.transform.stream.StreamSource;
> +import javax.xml.transform.stream.StreamResult;
> +import javax.xml.transform.sax.TransformerHandler;
> +import javax.xml.transform.sax.TemplatesHandler;
> +import javax.xml.transform.sax.SAXTransformerFactory;
> +import javax.xml.transform.sax.SAXSource;
> +import javax.xml.transform.URIResolver;
> +import javax.xml.transform.TransformerFactory;
> +import javax.xml.transform.TransformerException;
> +import javax.xml.transform.TransformerConfigurationException;
> +import javax.xml.transform.Transformer;
> +import javax.xml.transform.Templates;
> +import javax.xml.transform.Result;
> +import java.util.Map;
> +import java.util.Iterator;
> +import java.util.HashMap;
> +import java.io.Writer;
> +import java.io.StringWriter;
> +import java.io.IOException;
> +import java.io.File;
> +
> +import org.xml.sax.helpers.XMLReaderFactory;
> +import org.xml.sax.XMLReader;
> +import org.xml.sax.SAXException;
> +import org.xml.sax.InputSource;
> +import org.apache.cocoon.util.TraxErrorHandler;
> +import org.apache.cocoon.environment.SourceResolver;
> +import org.apache.cocoon.environment.Source;
> +import org.apache.cocoon.components.store.Store;
> +import org.apache.cocoon.Roles;
> +import org.apache.cocoon.ProcessingException;
> +import org.apache.avalon.framework.parameters.Parameters;
> +import org.apache.avalon.framework.logger.AbstractLoggable;
> +import org.apache.avalon.framework.configuration.ConfigurationException;
> +import org.apache.avalon.framework.configuration.Configuration;
> +import org.apache.avalon.framework.configuration.Configurable;
> +import org.apache.avalon.framework.component.Composable;
> +import org.apache.avalon.framework.component.ComponentManager;
> +import org.apache.avalon.framework.component.ComponentException;
> +import org.apache.avalon.framework.component.Component;
> +import org.apache.avalon.framework.activity.Disposable;
> +
> +/**
> + * This class defines the implementation of the {@link XSLTProcessor}
> + * component.
> + *
> + * To configure it, add the following lines in the
> + * <file>cocoon.xconf</file> file:
> + *
> + * <pre>
> + * &lt;xslt-processor class="org.apache.cocoon.components.xslt.XSLTProcessorImpl"&gt;
> + *    &lt;parameter name="use-store" value="true"/&gt;
> + * &lt;/xslt-processor&gt;
> + * </pre>
> + *
> + * The &lt;use-store&gt; configuration forces the transformer to put the
> + * <code>Templates</code> generated from the XSLT stylesheet into the
> + * <code>Store</code>. This property is true by default.
> + *
> + * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
> + * @version 1.0
> + * @since   July 11, 2001
> + */
> +public class XSLTProcessorImpl
> +  extends AbstractLoggable
> +  implements XSLTProcessor, Composable, Disposable, Configurable, URIResolver, Component
> +{
> +  protected ComponentManager manager;
> +
> +  /** The store service instance */
> +  Store store;
> +
> +  /** The trax TransformerFactory */
> +  SAXTransformerFactory tfactory;
> +
> +  /** Is the store turned on? (default is on) */
> +  boolean useStore = true;
> +
> +  SourceResolver resolver;
> +
> +  public void compose(ComponentManager manager)
> +    throws ComponentException
> +  {
> +    this.manager = manager;
> 
=== message truncated ===> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org


=====
Davanum Srinivas, JNI-FAQ Manager
http://www.jGuru.com/faq/JNI

__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message