You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jean-Claude Vogel <vo...@gmail.com> on 2007/11/19 15:43:18 UTC

XSLT custom implementation (or XSLTTransformer initialization)

Hello,

Sorry to send several questions on the mailing list.

I would like to know what I have to configure to make my own class
implementing XSLTTransformer in spring and to use it in the sitemap. I am a
newbie with Cocoon so if somebody would have an example it would be famous.

Here is an extract of my sitemap :
    <map:resources>
        <map:resource name="transform-my">
            <map:transform type="exportXSLTTransformer" />
        </map:resource>
    </map:resources>

an extract of the applicationContext.xml :
    <!-- Export XSLT transformer -->
    <bean name="org.apache.cocoon.transformation.Transformer
/exportXSLTTransformer"
        scope="prototype"
        class="xxxx.ExportXSLTTransformer">
        <property name="xmlFormatManager">
            <ref bean="xmlFormatManager" />
        </property>
    </bean>

and my implementation class (code not finalised) :
public class ExportXSLTTransformer extends XSLTTransformer {
    /** General log stream */
    private static final Log log = LogFactory.getLog(
ExportXSLTTransformer.class);

    /** HTTP parameter name for format parameter */
    static private final String FORMAT_PARAM_NAME = "format";
    static private final String DEFAULT_FORMAT_NAME = "Live";

    /** XSD validator implementations */
    private XmlFormatManager xmlFormatManager;
    /** HTTP request */
    private Request request;

    @SuppressWarnings("unchecked")
    public void setup(SourceResolver resolver,
                      Map objectModel,
                      String src,
                      Parameters parameters) throws SAXException,
ProcessingException, IOException {

        request = ObjectModelHelper.getRequest(objectModel);

        String formatName = request.getParameter(FORMAT_PARAM_NAME);

        if(formatName == null) {
            formatName = DEFAULT_FORMAT_NAME;
        }

        String fileName = xmlFormatManager.getStylesheetMaxmlExportFileName
(formatName);


        super.enableLogging(new CLLoggerWrapper(this.log)); // HERE I FORCE
ENABLELOGGING TO MAKE WORK A LITTLE BETTER

        super.setup(resolver, objectModel, fileName, parameters);
    }

    /**
     * XSD validators and XSLT stylesheets manager setter
     *
     * @param xmlFormatManager XSD validators and XSLT stylesheets manager
     */
    public void setXmlFormatManager(XmlFormatManager xmlFormatManager) {
        this.xmlFormatManager = xmlFormatManager;
    }
}

When I execute it there are NullPointerException :
                  -  org.apache.cocoon.transformation.XSLTTransformer.setup(
XSLTTransformer.java:292) if I don't force the enableLogging()
                   - org.apache.cocoon.transformation.XSLTTransformer.setup(
XSLTTransformer.java:304) if I force the enableLogging()

It seems that my class is not initialized by Cocoon, I looked in the Cocoon
code the XSLTTansformer initialization but didn't found it.

Can somebody help me please ?

Re: XSLT custom implementation (or XSLTTransformer initialization)

Posted by Joerg Heinicke <jo...@gmx.de>.
On 21.11.2007 8:17 Uhr, Jean-Claude Vogel wrote:
> I saw that the default XSLT transformer is not XSLTTransformer like I
> belived but is TraxTransformer. So I tried to use it. But I have ever the
> same error :

 From what I understand all the sitemap components are still Avalon 
beans. But nothing prevents you from setting up an Avalon component with 
dependency injection. When you move them to Spring you lose the marker 
interface injection though, instead you have to set up the components in 
Spring yourself and declare all the dependencies. Might this be an 
explanation for your NPE? What exactly is null in your case?

Joerg

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


Re: XSLT custom implementation (or XSLTTransformer initialization)

Posted by Jean-Claude Vogel <vo...@gmail.com>.
I saw that the default XSLT transformer is not XSLTTransformer like I
belived but is TraxTransformer. So I tried to use it. But I have ever the
same error :

     [exec] java.lang.NullPointerException:
     [exec]     at org.apache.cocoon.transformation.TraxTransformer.setup(
TraxTransformer.java:293)
     [exec]     at
xxxxxxxxxxxxxxx.exportmodule.transformer.ExportXSLTTransformer.setup
(ExportXSLTT
ransformer.java:59)
     [exec]     at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.setupPipeline
(AbstractProcessingPipe
line.java:354)
     [exec]     at
org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.setupPipeline
(AbstractCa
chingProcessingPipeline.java:727)
     [exec]     at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.preparePipeline
(AbstractProcessingPi
peline.java:464)
     [exec]     at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.process(
AbstractProcessingPipeline.j
ava:409)
     [exec]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
     [exec]     at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
     [exec]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
     [exec]     at java.lang.reflect.Method.invoke(Method.java:585)
     [exec]     at
org.apache.cocoon.core.container.spring.avalon.PoolableProxyHandler.invoke(
PoolableProxyHandler.java:
72)
     [exec]     at $Proxy10.process(Unknown Source)
     [exec]     at
org.apache.cocoon.components.treeprocessor.sitemap.SerializeNode.invoke(
SerializeNode.java:144)
     [exec]     at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes
(AbstractParentPro
cessingNode.java:55)
     [exec]     at
org.apache.cocoon.components.treeprocessor.sitemap.MatchNode.invoke(
MatchNode.java:87)
     [exec]     at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes
(AbstractParentPro
cessingNode.java:77)
     [exec]     at
org.apache.cocoon.components.treeprocessor.sitemap.PipelineNode.invoke(
PipelineNode.java:151)
     [exec]     at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes
(AbstractParentPro
cessingNode.java:77)
     [exec]     at
org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode.invoke(
PipelinesNode.java:93)
     [exec]     at
org.apache.cocoon.components.treeprocessor.ConcreteTreeProcessor.process(
ConcreteTreeProcessor.java:2
40)
     [exec]     at
org.apache.cocoon.components.treeprocessor.ConcreteTreeProcessor.process(
ConcreteTreeProcessor.java:1
71)
     [exec]     at
org.apache.cocoon.components.treeprocessor.TreeProcessor.process(
TreeProcessor.java:251)
     [exec]     at org.apache.cocoon.servlet.RequestProcessor.process(
RequestProcessor.java:357)
     [exec]     at org.apache.cocoon.servlet.RequestProcessor.service(
RequestProcessor.java:171)
     [exec]     at org.apache.cocoon.sitemap.SitemapServlet.service(
SitemapServlet.java:64)
     [exec]     at javax.servlet.http.HttpServlet.service(HttpServlet.java
:856)
     [exec]     at
org.apache.cocoon.servletservice.ServletServiceContext$PathDispatcher.forward
(ServletServiceContext.j
ava:567)
     [exec]     at
org.apache.cocoon.servletservice.ServletServiceContext$PathDispatcher.forward
(ServletServiceContext.j
ava:544)
     [exec]     at
org.apache.cocoon.servletservice.spring.ServletFactoryBean$ServiceInterceptor.invoke
(ServletFactoryBe
an.java:230)
     [exec]     at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
ReflectiveMethodInvocation.java:
166)

For information I am using Cocoon 2.2.


2007/11/21, Jean-Claude Vogel <vo...@gmail.com>:
>
> I tried to addin my bean declaration :
>         <property name="manager"
>             ref="org.apache.avalon.framework.service.ServiceManager"/>
>
> and
>     public void setManager(ServiceManager manager) throws ServiceException
> {
>         super.service(manager);
>         this.manager=manager;
>       }
>
> in my transformer implementation. But it doesn't work, I have still :
>                    -
> org.apache.cocoon.transformation.XSLTTransformer.setup (
> XSLTTransformer.java :304)
>
> 2007/11/19, Jean-Claude Vogel <vo...@gmail.com>:
> >
> > Hello,
> >
> > Sorry to send several questions on the mailing list.
> >
> > I would like to know what I have to configure to make my own class
> > implementing XSLTTransformer in spring and to use it in the sitemap. I am a
> > newbie with Cocoon so if somebody would have an example it would be famous.
> >
> > Here is an extract of my sitemap :
> >     <map:resources>
> >         <map:resource name="transform-my">
> >             <map:transform type="exportXSLTTransformer" />
> >         </map:resource>
> >     </map:resources>
> >
> > an extract of the applicationContext.xml :
> >     <!-- Export XSLT transformer -->
> >     <bean name="org.apache.cocoon.transformation.Transformer/exportXSLTTransformer"
> >
> >         scope="prototype"
> >         class="xxxx.ExportXSLTTransformer">
> >         <property name="xmlFormatManager">
> >             <ref bean="xmlFormatManager" />
> >         </property>
> >     </bean>
> >
> > and my implementation class (code not finalised) :
> > public class ExportXSLTTransformer extends XSLTTransformer {
> >     /** General log stream */
> >     private static final Log log = LogFactory.getLog(
> > ExportXSLTTransformer.class);
> >
> >     /** HTTP parameter name for format parameter */
> >     static private final String FORMAT_PARAM_NAME = "format";
> >     static private final String DEFAULT_FORMAT_NAME = "Live";
> >
> >     /** XSD validator implementations */
> >     private XmlFormatManager xmlFormatManager;
> >     /** HTTP request */
> >     private Request request;
> >
> >     @SuppressWarnings("unchecked")
> >     public void setup(SourceResolver resolver,
> >                       Map objectModel,
> >                       String src,
> >                       Parameters parameters) throws SAXException,
> > ProcessingException, IOException {
> >
> >         request = ObjectModelHelper.getRequest(objectModel);
> >
> >         String formatName = request.getParameter(FORMAT_PARAM_NAME);
> >
> >         if(formatName == null) {
> >             formatName = DEFAULT_FORMAT_NAME;
> >         }
> >
> >         String fileName =
> > xmlFormatManager.getStylesheetMaxmlExportFileName(formatName);
> >
> >
> >         super.enableLogging(new CLLoggerWrapper(this.log)); // HERE I
> > FORCE ENABLELOGGING TO MAKE WORK A LITTLE BETTER
> >
> >         super.setup(resolver, objectModel, fileName, parameters);
> >     }
> >
> >     /**
> >      * XSD validators and XSLT stylesheets manager setter
> >      *
> >      * @param xmlFormatManager XSD validators and XSLT stylesheets
> > manager
> >      */
> >     public void setXmlFormatManager(XmlFormatManager xmlFormatManager) {
> >         this.xmlFormatManager = xmlFormatManager;
> >     }
> > }
> >
> > When I execute it there are NullPointerException :
> >                   -
> > org.apache.cocoon.transformation.XSLTTransformer.setup(
> > XSLTTransformer.java:292) if I don't force the enableLogging()
> >                    -
> > org.apache.cocoon.transformation.XSLTTransformer.setup(
> > XSLTTransformer.java :304) if I force the enableLogging()
> >
> > It seems that my class is not initialized by Cocoon, I looked in the
> > Cocoon code the XSLTTansformer initialization but didn't found it.
> >
> > Can somebody help me please ?
> >
>
>

Re: XSLT custom implementation (or XSLTTransformer initialization)

Posted by Jean-Claude Vogel <vo...@gmail.com>.
I tried to addin my bean declaration :
        <property name="manager"
            ref="org.apache.avalon.framework.service.ServiceManager"/>

and
    public void setManager(ServiceManager manager) throws ServiceException {

        super.service(manager);
        this.manager=manager;
      }

in my transformer implementation. But it doesn't work, I have still :
                   - org.apache.cocoon.transformation.XSLTTransformer.setup(
XSLTTransformer.java :304)

2007/11/19, Jean-Claude Vogel <vo...@gmail.com>:
>
> Hello,
>
> Sorry to send several questions on the mailing list.
>
> I would like to know what I have to configure to make my own class
> implementing XSLTTransformer in spring and to use it in the sitemap. I am a
> newbie with Cocoon so if somebody would have an example it would be famous.
>
> Here is an extract of my sitemap :
>     <map:resources>
>         <map:resource name="transform-my">
>             <map:transform type="exportXSLTTransformer" />
>         </map:resource>
>     </map:resources>
>
> an extract of the applicationContext.xml :
>     <!-- Export XSLT transformer -->
>     <bean name="org.apache.cocoon.transformation.Transformer/exportXSLTTransformer"
>
>         scope="prototype"
>         class="xxxx.ExportXSLTTransformer">
>         <property name="xmlFormatManager">
>             <ref bean="xmlFormatManager" />
>         </property>
>     </bean>
>
> and my implementation class (code not finalised) :
> public class ExportXSLTTransformer extends XSLTTransformer {
>     /** General log stream */
>     private static final Log log = LogFactory.getLog(
> ExportXSLTTransformer.class);
>
>     /** HTTP parameter name for format parameter */
>     static private final String FORMAT_PARAM_NAME = "format";
>     static private final String DEFAULT_FORMAT_NAME = "Live";
>
>     /** XSD validator implementations */
>     private XmlFormatManager xmlFormatManager;
>     /** HTTP request */
>     private Request request;
>
>     @SuppressWarnings("unchecked")
>     public void setup(SourceResolver resolver,
>                       Map objectModel,
>                       String src,
>                       Parameters parameters) throws SAXException,
> ProcessingException, IOException {
>
>         request = ObjectModelHelper.getRequest(objectModel);
>
>         String formatName = request.getParameter(FORMAT_PARAM_NAME);
>
>         if(formatName == null) {
>             formatName = DEFAULT_FORMAT_NAME;
>         }
>
>         String fileName =
> xmlFormatManager.getStylesheetMaxmlExportFileName(formatName);
>
>
>         super.enableLogging(new CLLoggerWrapper(this.log)); // HERE I
> FORCE ENABLELOGGING TO MAKE WORK A LITTLE BETTER
>
>         super.setup(resolver, objectModel, fileName, parameters);
>     }
>
>     /**
>      * XSD validators and XSLT stylesheets manager setter
>      *
>      * @param xmlFormatManager XSD validators and XSLT stylesheets manager
>
>      */
>     public void setXmlFormatManager(XmlFormatManager xmlFormatManager) {
>         this.xmlFormatManager = xmlFormatManager;
>     }
> }
>
> When I execute it there are NullPointerException :
>                   -
> org.apache.cocoon.transformation.XSLTTransformer.setup(
> XSLTTransformer.java:292) if I don't force the enableLogging()
>                    -
> org.apache.cocoon.transformation.XSLTTransformer.setup(
> XSLTTransformer.java :304) if I force the enableLogging()
>
> It seems that my class is not initialized by Cocoon, I looked in the
> Cocoon code the XSLTTansformer initialization but didn't found it.
>
> Can somebody help me please ?
>