You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Angelo Immediata <an...@libero.it> on 2005/10/26 23:38:04 UTC
Hel in writing my own transformer.
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");
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.AbstractProcessingPipeline.handleException(AbstractProcessingPipeline.java:940)
at org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.processXMLPipeline(AbstractCachingProcessingPipeline.java:281)
at org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.process(AbstractProcessingPipeline.java:783)
at org.apache.cocoon.components.source.impl.SitemapSource.toSAX(SitemapSource.java:413)
at org.apache.cocoon.components.source.SourceUtil.toSAX(SourceUtil.java:142)
at org.apache.cocoon.components.source.SourceUtil.toSAX(SourceUtil.java:100)
at org.apache.cocoon.components.source.SourceUtil.toDOM(SourceUtil.java:332)
at org.apache.cocoon.components.flow.util.PipelineUtil.processToDOM(PipelineUtil.java:173)
Can anybody help me? Thanks to all.