You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Stephan Coboos <cr...@gmx.net> on 2004/06/09 19:21:19 UTC

My taglib doesn't work

Hello,

I had tried to write my own taglib using the TagTransformer but it 
doesn't work. I can't find some informations about it, so I had copied 
the example and changed something but it doesn't work. I want to use a 
tag <hello/> to print out "HELLO WORLD". My changes in detail:

1.) I had written my own class HelloWorldTag:

package foo.bar.taglib;

import org.apache.cocoon.taglib.XMLProducerTagSupport;
import org.xml.sax.SAXException;
import org.xml.sax.Attributes;

public class HelloWorldTag extends XMLProducerTagSupport {

    public int doStartTag(String namespaceURI, String localName, String 
qName, Attributes atts)
        throws SAXException {
          
        String hello = "HELLO WORLD";
           
        this.xmlConsumer.characters(hello.toCharArray(), 0, hello.length());
       
        this.getLogger().error("T E X T = " + hello);
       
        return this.EVAL_BODY;
    }
}

2.) I had created a subproject tagtest containing a xml file tagtest.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<root xmlns:test="urn:apache:taglib:hello">
  <test:hello/>
</root>

3.) My sitemap looks as follow:

<?xml version="1.0" encoding="UTF-8"?>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">

<map:components>

   <map:transformers default="tag">
      <map:transformer name="tag" 
src="org.apache.cocoon.transformation.TagTransformer" pool-max="64" 
pool-min="0" pool-grow="2" logger="sitemap.transformer.newtag">
        <transformer-hint>tag</transformer-hint>
      </map:transformer>
   </map:transformers>

</map:components>

<map:pipelines>
   <map:pipeline>

      <map:match pattern="">
         <map:generate type="file" src="tagtest.xml"/>
         <map:transform type="tag"/>
         <map:serialize type="xml"/>
      </map:match>

   </map:pipeline>
</map:pipelines>

</map:sitemap>

3.) In cocoon.xconf I had registered the tag :

    <taglib 
class="org.apache.cocoon.components.ExtendedComponentSelector" 
logger="sitemap.taglib.core" name="urn:apache:taglib:hello">
      <tag class="foo.bar.taglib.HelloWorldTag" 
logger="sitemap.taglib.core.source" name="hello"/>
    </taglib>

4.) After calling http://localhost:8080/cocoon/tagtest the tag <hello/> 
will not be replaces by "HELLO WORLD". I got the following output - 
nothing parsed:

<?xml version="1.0" encoding="ISO-8859-1" ?>
- <#>  <root xmlns:test="*urn:apache:taglib:hello*">
      <test:hello />
</root>

What is wrong here? Thank you for your help.

Regards
Stephan

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