Round II:

Here's my transformer code, (I know there's extra imports I don't need just yet):
-----
package com.openweather.cocoon.transformation;

import org.apache.cocoon.transformation.AbstractSAXTransformer;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.ProcessingException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.logger.Logger;

import org.xml.sax.SAXException;
import org.xml.sax.Attributes;

import java.util.Map;
import java.io.IOException;

public class CAPDescriptionTransformer
    extends AbstractSAXTransformer {

    protected String NAMESPACE = "http://www.incident.com/cap/1.0";;
    protected String DESCRIPTION = "description";
    private String text = null;

    public void startElement(String uri, String name, String raw, Attributes attr)
    throws SAXException {

        super.startElement(uri, name, raw, attr);

        if ( NAMESPACE.equals(uri) && DESCRIPTION.equals(name) ) {
            this.text = null;
            startTextRecording();
        }
    }

    public void endElement(String uri, String name, String raw, Attributes attr)
    throws SAXException {

        if ( NAMESPACE.equals(uri) && DESCRIPTION.equals(name) ) {
            // we found the element

            // get the text and process
            this.text = endTextRecording();


// send the processed characters to the next pipeline component characters( process(this.text).toCharArray(), 0, text.length() ); }

        // end the element
        super.endElement(uri, name, raw);
    }

    private String process(String text) {
        System.out.println("inside process()");

        // @TODO: finish me

        // arbitrarily process the text

        System.out.println("leaving process before return():");
        return text.toLowerCase();
    }
}

------


package com.openweather.cocoon.transformation;

import org.apache.cocoon.transformation.AbstractSAXTransformer;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.ProcessingException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.logger.Logger;

import org.xml.sax.SAXException;
import org.xml.sax.Attributes;

import java.util.Map;
import java.io.IOException;

public class CAPDescriptionTransformer
    extends AbstractSAXTransformer {

    protected String NAMESPACE = "http://www.incident.com/cap/1.0";;
    protected String DESCRIPTION = "description";
    private String text = null;

    public void startElement(String uri, String name, String raw, Attributes attr)
    throws SAXException {

        super.startElement(uri, name, raw, attr);

        if ( NAMESPACE.equals(uri) && DESCRIPTION.equals(name) ) {
            this.text = null;
            startTextRecording();
        }
    }

    public void endElement(String uri, String name, String raw, Attributes attr)
    throws SAXException {

        if ( NAMESPACE.equals(uri) && DESCRIPTION.equals(name) ) {
            // we found the element

            // get the text and process
            this.text = endTextRecording();


// send the processed characters to the next pipeline component characters( process(this.text).toCharArray(), 0, text.length() ); }

        // end the element
        super.endElement(uri, name, raw);
    }

    private String process(String text) {
        System.out.println("inside process()");

        // @TODO: finish me

        // arbitrarily process the text

        System.out.println("leaving process before return():");
        return text.toLowerCase();
    }
}

By using the LogTransformer before and after my transformer, it seems that once startRecording() is called, no events are sent to my tranformer. I would assume that calling endRecording() would turn that off, but that doesn't seem to be the case. Can anyone tell me where I'm going wrong? I notices the SourceWritingTransformer keeps a stack... am I going to have to keep track of the elements I see once I've started recording?


Regards,

Tony

Reply via email to