You mis one argument in new AttributesImpl();

it should be new AttributesImpl(attr), see comments in text

AS

> Hi all. I need to implement a my own transform that does a 
> link rewriter. the scope is to change the href value of <a 
> tag in a html file (a well formed html file checked by jtidy 
> as you can check in the file jtidy.xml). I have realize for 
> now the code:
> 
> package it.transformers;
> 
> import org.apache.cocoon.transformation.AbstractSAXTransformer;
> import org.xml.sax.Attributes;
> import java.io.IOException;
> import java.util.Map;
> import org.apache.cocoon.ProcessingException;
> import org.apache.cocoon.portal.transformation.CopletTransformer;
> import org.apache.avalon.framework.parameters.Parameters;
> import org.xml.sax.SAXException;
> import org.apache.cocoon.environment.SourceResolver;
> import org.apache.cocoon.xml.AttributesImpl;
> import java.util.Stack;
> 
> public class HTMLLinkTransformer extends AbstractSAXTransformer {
> 
>     protected Stack elementStack = new Stack();
> 
>     public void recycle() {
>         super.recycle();
>         this.elementStack.clear();
>     }
> 
>     public void setup(SourceResolver resolver,
>                       Map objectModel,
>                       String src,
>                       Parameters par)
>     throws ProcessingException, SAXException, IOException {
>         super.setup(resolver, objectModel, src, par);
> 
>     }
> 
>     public void startElement(String uri, String name, String 
> raw, Attributes attr)
>     throws SAXException {
>         if ("a".equalsIgnoreCase(name) || 
> "xhtml:a".equalsIgnoreCase( name ) ) {
> 
>             AttributesImpl newAttr = new AttributesImpl();
>             newAttr.setValue(attr.getIndex("href"),"ciao");

Here is the mistake. newAttr is empty! So, attr.getIndex("href") returns an 
index that newAttr does not have. 

AttributesImpl newAttr = new AttributesImpl(); -> AttributesImpl newAttr = new 
AttributesImpl(attr); does the job

>             attr = newAttr;
>         }
>         super.startElement( uri, name, raw,attr );
>     }
> 
>     public void endElement(String uri, String name, String 
> raw) throws SAXException {
>         super.endElement(uri, name, raw);
>     }
> }
> 
> By using it i have this error:
> ERROR   (2005-10-26) 23:35.13:739   [sitemap.handled-errors] 
> (/pmm/portal/coplets/S062/execute.service) 
> http-8080-Processor8/ErrorHandlerHelper: Error executing pipeline.
> org.apache.cocoon.ProcessingException: Error executing 
> pipeline.: org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: 
> An attempt was made to insert a node where it is not permitted. 
>       at 
> org.apache.cocoon.components.pipeline.AbstractProcessingPipeli
> ne.handleException(AbstractProcessingPipeline.java:940)
>       at 
> org.apache.cocoon.components.pipeline.impl.AbstractCachingProc
> essingPipeline.processXMLPipeline(AbstractCachingProcessingPip
> eline.java:281)
>       at 
> org.apache.cocoon.components.pipeline.AbstractProcessingPipeli
> ne.process(AbstractProcessingPipeline.java:783)
>       at 
> org.apache.cocoon.components.source.impl.SitemapSource.toSAX(S
> itemapSource.java:413)
>       at 
> org.apache.cocoon.components.source.SourceUtil.toSAX(SourceUti
> l.java:142)
>       at 
> org.apache.cocoon.components.source.SourceUtil.toSAX(SourceUti
> l.java:100)
>       at 
> org.apache.cocoon.components.source.SourceUtil.toDOM(SourceUti
> l.java:332)
>       at 
> org.apache.cocoon.components.flow.util.PipelineUtil.processToD
> OM(PipelineUtil.java:173)
> 
> 
> Can anybody help me? Thanks to all.
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]