You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Sylvain Desvé <sy...@gmail.com> on 2008/06/19 21:42:26 UTC

Setting up Saxon in a Maven built Cocoon application

Hi,

I followed the tutorials at http://cocoon.apache.org/1370_1_1.html to  
create my first Cocoon application. It worked fine.

But now I need to use Saxon instead of Xalan because my XSLT files are  
using XSLT 2.0 features. I found how to do that at http://wiki.apache.org/cocoon/Saxon

It explains that I need to add the Saxon component to the  
cocoon.xconf. The problem is I don't have a cocoon.xconf file anywhere  
in my Maven built project.

Can someone explain me how I can do that ?

Thanks,
Sylvain

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


Re: Setting up Saxon in a Maven built Cocoon application

Posted by Alexander Daniel <al...@gmx.at>.
We had problems with the XmlFileInputModule when having Saxon in the  
classpath [4]. The reason for that is that both Xalan and Saxon set  
the TransformerFactoryImpl via META-INF/services/ 
javax.xml.transform.TransformerFactory [1] (Java Services API) and  
Saxon was in the load order before Xalan in Tomcat.

We solved that by setting the javax.xml.transform.TransformerFactory  
system property explicitly to Xalan. This works because  
TransformerFactory.newInstance uses the system property before  
consulting the Java Services API [1].

I have seen two other workarounds
- removing the META-INF folder within the saxon-X.X.jar [2]
- prefixing the saxon-X.X.jar with z-. Then Tomcat loads it after  
Xalan and the TransformerFactory is set by Xalan via the Services API  
[3]

The advantage of the system property is that it plays nicely with Maven.

Alex

[1] http://java.sun.com/javase/6/docs/api/javax/xml/transform/TransformerFactory.html#newInstance()
[2] http://marc.info/?l=xml-cocoon-dev&m=108015075700034&w=2
[3] http://marc.info/?l=xml-cocoon-users&m=122467833601554&w=2
[4] java.lang.IllegalArgumentException: Unknown type of result: class  
javax.xml.transform.dom.DOMResult
          
net 
.sf.saxon.event.SerializerFactory.getReceiver(SerializerFactory.java: 
154)
          
net 
.sf 
.saxon 
.IdentityTransformerHandler 
.startDocument(IdentityTransformerHandler.java:94)
          
org 
.apache.cocoon.xml.AbstractXMLPipe.startDocument(AbstractXMLPipe.java: 
47)
          
org.apache.xerces.parsers.AbstractSAXParser.startDocument(Unknown  
Source)
          
org.apache.xerces.impl.dtd.XMLDTDValidator.startDocument(Unknown Source)
          
org.apache.xerces.impl.XMLDocumentScannerImpl.startEntity(Unknown  
Source)
          
org.apache.xerces.impl.XMLVersionDetector.startDocumentParsing(Unknown  
Source)
         org.apache.xerces.parsers.XML11Configuration.parse(Unknown  
Source)
         org.apache.xerces.parsers.XML11Configuration.parse(Unknown  
Source)
         org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
         org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown  
Source)
         org.apache.xerces.jaxp.SAXParserImpl 
$JAXPSAXParser.parse(Unknown Source)
          
org.apache.cocoon.core.xml.impl.JaxpSAXParser.parse(JaxpSAXParser.java: 
196)
          
org 
.apache 
.cocoon.core.xml.avalon.DefaultSAXParser.parse(DefaultSAXParser.java:47)
          
org.apache.excalibur.xmlizer.DefaultXMLizer.toSAX(DefaultXMLizer.java: 
127)
          
org 
.apache.cocoon.components.source.util.SourceUtil.toSAX(SourceUtil.java: 
180)
          
org 
.apache.cocoon.components.source.util.SourceUtil.toDOM(SourceUtil.java: 
318)
         org.apache.cocoon.components.modules.input.XMLFileModule 
$DocumentHelper.getDocument(XMLFileModule.java:178)
          
org 
.apache 
.cocoon 
.components 
.modules.input.XMLFileModule.getContextObject(XMLFileModule.java:380)
          
org 
.apache 
.cocoon 
.components 
.modules.input.XMLFileModule.getAttribute(XMLFileModule.java:402)
          
org 
.apache 
.cocoon 
.components 
.modules.input.XMLFileModule.getAttribute(XMLFileModule.java:391)



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


Re: Setting up Saxon in a Maven built Cocoon application

Posted by Alexander Daniel <al...@gmx.at>.
On 20.06.2008, at 20:48, Sylvain Desvé wrote:

> RESOLVED
>
> I finally managed to do it. For those who encounter the same  
> problem, here's what I did.

Thanks a lot for sharing!


> 3. I edited sitemap.xmap and added a component :
>
> <map:components>
>     <map:transformers default="xslt">
>       <map:transformer name="xslt-saxon" pool-grow="2" pool-max="32"  
> pool-min="8"
>           src="org.apache.cocoon.transformation.TraxTransformer">
>         <use-request-parameters>false</use-request-parameters>
>         <use-browser-capabilities-db>false</use-browser-capabilities- 
> db>
>         <xslt-processor-role>saxon</xslt-processor-role>
>       </map:transformer>
>     </map:transformers>
>   </map:components>

You can also put this declaration into META-INF/cocoon/avalon which  
keeps your sitemap free of component declarations (example at [1]).


> 5. I created an avalon directory in src/main/resources/META-INF/ 
> cocoon and created a saxon-config.xconf file in it :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <components>
>   <component logger="core.xslt-processor"
>       role="org.apache.excalibur.xml.xslt.XSLTProcessor/saxon"
>       class="org.apache.excalibur.xml.xslt.XSLTProcessorImpl">
>     <parameter name="use-store" value="true"/>
>     <parameter name="incremental-processing" value="false"/>
>     <parameter name="transformer-factory"  
> value="net.sf.saxon.TransformerFactoryImpl"/>
>   </component>
> </components>

It is better to use org.apache.cocoon.components.xslt.TraxProcessor as  
class instead of org.apache.excalibur.xml.xslt.XSLTProcessorImpl.  
TraxProcessor is an adaptation of Excalibur's XSLTProcessor  
implementation to allow better error reporting [2]. The built-in XSLT  
transformers of Cocoon 2.2 also use TraxProcessor [3].


> 6. I added the saxon dependency in the pom.xml
>
>     <dependency>
>       <groupId>net.sf.saxon</groupId>
>       <artifactId>saxon</artifactId>
>       <version>8.7</version>
>     </dependency>

It is even possible to create a saxon-transformer block which contains  
3, 5 and 6 and use it from other blocks where you need Saxon. Then you  
just have to add the saxon-transformer block as a dependency in the  
pom.xml and you can use Saxon right away in your project.

Alex

[1] http://svn.apache.org/repos/asf/cocoon/trunk/core/cocoon-core/src/main/resources/META-INF/cocoon/avalon/cocoon-core-sitemapcomponents.xconf
[2] http://svn.apache.org/repos/asf/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-components/src/main/java/org/apache/cocoon/components/xslt/TraxProcessor.java
[3] http://svn.apache.org/repos/asf/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-components/src/main/resources/META-INF/cocoon/avalon/cocoon-core-xslt-xalan.xconf
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Setting up Saxon in a Maven built Cocoon application

Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
Sylvain Desvé pisze:
> RESOLVED
> 
> I finally managed to do it. For those who encounter the same problem, 
> here's what I did.
> 
> 1. I followed the tutorial at cocoon.apache.org 
> <http://cocoon.apache.org> abd created a block using maven
> 2. I created a source XML file and a XSLT 2.0 file
> 3. I edited sitemap.xmap and added a component :
> 
> <map:components>
>     <map:transformers default="xslt">
>       <map:transformer name="xslt-saxon" pool-grow="2" pool-max="32" 
> pool-min="8"
>           src="org.apache.cocoon.transformation.TraxTransformer">
>         <use-request-parameters>false</use-request-parameters>
>         <use-browser-capabilities-db>false</use-browser-capabilities-db>
>         <xslt-processor-role>saxon</xslt-processor-role>
>       </map:transformer>
>     </map:transformers>
>   </map:components>
> 
> 4. I edited sitemap.xmap to add the pipeline
> 
> <map:pipeline>
>   <map:match pattern="test">
>     <map:generate src="test/mySource.xml" type="file" />
>     <map:transform src="style/myStyle.xslt" type="xslt-saxon" />
>     <map:serialize type="html" />
>   </map:match>
> </map:pipeline>
> 
> 5. I created an avalon directory in src/main/resources/META-INF/cocoon 
> and created a saxon-config.xconf file in it :
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <components>
>   <component logger="core.xslt-processor"
>       role="org.apache.excalibur.xml.xslt.XSLTProcessor/saxon"
>       class="org.apache.excalibur.xml.xslt.XSLTProcessorImpl">
>     <parameter name="use-store" value="true"/>
>     <parameter name="incremental-processing" value="false"/>
>     <parameter name="transformer-factory" 
> value="net.sf.saxon.TransformerFactoryImpl"/>
>   </component>
> </components>
> 

That's actually a general method for adding config that in 2.1.x was supposed to be put into 
cocoon.xconf. This should be added to FAQ document but this in turn requires some work with our 
documentation publishing system. :-(

> 6. I added the saxon dependency in the pom.xml
> 
>     <dependency>
>       <groupId>net.sf.saxon</groupId>
>       <artifactId>saxon</artifactId>
>       <version>8.7</version>
>     </dependency>
> 
> 7. I ran mvn jetty:run and got to http://localhost:8888/myBlock1/test 
> and voilà !
> 
> That's it !
> 

Thanks for sharing!

-- 
Grzegorz Kossakowski

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


Re: Setting up Saxon in a Maven built Cocoon application

Posted by Sylvain Desvé <sy...@gmail.com>.
RESOLVED
I finally managed to do it. For those who encounter the same problem, here's
what I did.

1. I followed the tutorial at cocoon.apache.org abd created a block using
maven
2. I created a source XML file and a XSLT 2.0 file
3. I edited sitemap.xmap and added a component :

<map:components>
    <map:transformers default="xslt">
      <map:transformer name="xslt-saxon" pool-grow="2" pool-max="32"
pool-min="8"
          src="org.apache.cocoon.transformation.TraxTransformer">
        <use-request-parameters>false</use-request-parameters>
        <use-browser-capabilities-db>false</use-browser-capabilities-db>
        <xslt-processor-role>saxon</xslt-processor-role>
      </map:transformer>
    </map:transformers>
  </map:components>

4. I edited sitemap.xmap to add the pipeline

<map:pipeline>
  <map:match pattern="test">
    <map:generate src="test/mySource.xml" type="file" />
    <map:transform src="style/myStyle.xslt" type="xslt-saxon" />
    <map:serialize type="html" />
  </map:match>
</map:pipeline>

5. I created an avalon directory in src/main/resources/META-INF/cocoon and
created a saxon-config.xconf file in it :

<?xml version="1.0" encoding="UTF-8"?>
<components>
  <component logger="core.xslt-processor"
      role="org.apache.excalibur.xml.xslt.XSLTProcessor/saxon"
      class="org.apache.excalibur.xml.xslt.XSLTProcessorImpl">
    <parameter name="use-store" value="true"/>
    <parameter name="incremental-processing" value="false"/>
    <parameter name="transformer-factory"
value="net.sf.saxon.TransformerFactoryImpl"/>
  </component>
</components>

6. I added the saxon dependency in the pom.xml

    <dependency>
      <groupId>net.sf.saxon</groupId>
      <artifactId>saxon</artifactId>
      <version>8.7</version>
    </dependency>

7. I ran mvn jetty:run and got to http://localhost:8888/myBlock1/test and
voilà !

That's it !

2008/6/20 Sylvain Desvé <sy...@gmail.com>:

> I tried it. My sitemap.xmap looks like the following :
> <map:sitemap ...>
>
>   <map:components>
>     <map:transformers default="xslt">
>       <map:transformer name="xslt-saxon" pool-grow="2" pool-max="32"
> pool-min="8"
>           src="org.apache.cocoon.transformation.TraxTransformer">
>         <use-request-parameters>false</use-request-parameters>
>         <use-browser-capabilities-db>false</use-browser-capabilities-db>
>         <xslt-processor-role>saxon</xslt-processor-role>
>       </map:transformer>
>     </map:transformers>
>   </map:components>
>
>   <map:pipelines>
>     <map:pipeline>
>       <map:match pattern="forms/*">
>         <map:generate src="forms/{1}.xml" type="file" />
>         <map:transform src="transformers/form2html.xslt" type="xslt-saxon"
> />
>         <map:serialize type="html" />
>       </map:match>
>     </map:pipeline>
>
>     ...
>
>   </map:pipelines>
>
> </map:sitemap>
>
> But when I run mvn jetty:run and request the pipeline I get an error. There
> is a full backtrace of it but the root cause is :
> org.apache.avalon.framework.service.ServiceException: Component with
> 'org.apache.excalibur.xml.xslt.XSLTProcessor/saxon' is not defined in this
> service manager. (Key='AvalonServiceManager')
>
> 2008/6/20 Johannes Hoechstaedter <j....@memocomp.de>:
>
> Hi Sylvian,
>>
>> have you tried to add the component to your sitemap.xmap?
>>
>> cheers
>>
>> Sylvain Desvé schrieb:
>>
>>> Hi,
>>>
>>> I followed the tutorials at http://cocoon.apache.org/1370_1_1.html to
>>> create my first Cocoon application. It worked fine.
>>>
>>> But now I need to use Saxon instead of Xalan because my XSLT files are
>>> using XSLT 2.0 features. I found how to do that at
>>> http://wiki.apache.org/cocoon/Saxon
>>>
>>> It explains that I need to add the Saxon component to the cocoon.xconf.
>>> The problem is I don't have a cocoon.xconf file anywhere in my Maven built
>>> project.
>>>
>>> Can someone explain me how I can do that ?
>>>
>>> Thanks,
>>> Sylvain
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>> For additional commands, e-mail: users-help@cocoon.apache.org
>>>
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>>
>

Re: Setting up Saxon in a Maven built Cocoon application

Posted by Sylvain Desvé <sy...@gmail.com>.
I tried it. My sitemap.xmap looks like the following :
<map:sitemap ...>

  <map:components>
    <map:transformers default="xslt">
      <map:transformer name="xslt-saxon" pool-grow="2" pool-max="32"
pool-min="8"
          src="org.apache.cocoon.transformation.TraxTransformer">
        <use-request-parameters>false</use-request-parameters>
        <use-browser-capabilities-db>false</use-browser-capabilities-db>
        <xslt-processor-role>saxon</xslt-processor-role>
      </map:transformer>
    </map:transformers>
  </map:components>

  <map:pipelines>
    <map:pipeline>
      <map:match pattern="forms/*">
        <map:generate src="forms/{1}.xml" type="file" />
        <map:transform src="transformers/form2html.xslt" type="xslt-saxon"
/>
        <map:serialize type="html" />
      </map:match>
    </map:pipeline>

    ...

  </map:pipelines>

</map:sitemap>

But when I run mvn jetty:run and request the pipeline I get an error. There
is a full backtrace of it but the root cause is :
org.apache.avalon.framework.service.ServiceException: Component with
'org.apache.excalibur.xml.xslt.XSLTProcessor/saxon' is not defined in this
service manager. (Key='AvalonServiceManager')

2008/6/20 Johannes Hoechstaedter <j....@memocomp.de>:

> Hi Sylvian,
>
> have you tried to add the component to your sitemap.xmap?
>
> cheers
>
> Sylvain Desvé schrieb:
>
>> Hi,
>>
>> I followed the tutorials at http://cocoon.apache.org/1370_1_1.html to
>> create my first Cocoon application. It worked fine.
>>
>> But now I need to use Saxon instead of Xalan because my XSLT files are
>> using XSLT 2.0 features. I found how to do that at
>> http://wiki.apache.org/cocoon/Saxon
>>
>> It explains that I need to add the Saxon component to the cocoon.xconf.
>> The problem is I don't have a cocoon.xconf file anywhere in my Maven built
>> project.
>>
>> Can someone explain me how I can do that ?
>>
>> Thanks,
>> Sylvain
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>>
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>

Re: Setting up Saxon in a Maven built Cocoon application

Posted by Johannes Hoechstaedter <j....@memocomp.de>.
Hi Sylvian,

have you tried to add the component to your sitemap.xmap?

cheers

Sylvain Desvé schrieb:
> Hi,
>
> I followed the tutorials at http://cocoon.apache.org/1370_1_1.html to 
> create my first Cocoon application. It worked fine.
>
> But now I need to use Saxon instead of Xalan because my XSLT files are 
> using XSLT 2.0 features. I found how to do that at 
> http://wiki.apache.org/cocoon/Saxon
>
> It explains that I need to add the Saxon component to the 
> cocoon.xconf. The problem is I don't have a cocoon.xconf file anywhere 
> in my Maven built project.
>
> Can someone explain me how I can do that ?
>
> Thanks,
> Sylvain
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>

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