You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Harald Wehr <hw...@hs-harz.de> on 2003/01/23 12:18:46 UTC

Castor Transformer

I am using a Cocoon-Developer-Snapshot from October this year.
The Castor Transformer i fetched from CVS. Unfortunately this class uses 
a lot of deprecated stuff. Additionally i have to serialize a 
java-object stored in my xmlform.

So i tried to write my own transformer.  The code is attached here. The 
Castor Marshaller needs a Sax-ContentHandler that I get by calling the 
variable "contentHandler", available in the transformer.

Following Exception do I get. Do I have to set the Sax-Parser in the 
Properties? When I set the Sax-Parser from cocoon.xconf additionally in 
the properties i get a ClassNotFoundException.

When i replace the deprecated Classes from the CVS-transformer same 
things happen.

Any help is appreciated.

Harald



------------Exception--------------------
org.xml.sax.SAXException: System property org.xml.sax.parser not specified
at org.xml.sax.helpers.ParserAdapter.<init>(ParserAdapter.java:104)
at org.exolab.castor.xml.Marshaller.<init>(Unknown Source)
at 
de.mobiharz.cocoon.transformation.MobiHarzXMLFormTransformer.startElement(MobiHarzXMLFormTransformer.java:45)
at 
org.apache.cocoon.xml.AbstractXMLPipe.startElement(AbstractXMLPipe.java:130)
at 
org.apache.cocoon.transformation.AbstractSAXTransformer.startElement(AbstractSAXTransformer.java:340)
at 
org.apache.xerces.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:459)
at 
org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:221)
at 
org.apache.xerces.impl.XMLNamespaceBinder.handleStartElement(XMLNamespaceBinder.java:874)
at 
org.apache.xerces.impl.XMLNamespaceBinder.emptyElement(XMLNamespaceBinder.java:591)
at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:747)
...


----------Transformer---------------------
package de.mobiharz.cocoon.transformation;

import org.apache.cocoon.components.xmlform.Form;
import org.apache.cocoon.transformation.XMLFormTransformer;
import org.apache.commons.jxpath.JXPathContext;
import org.exolab.castor.xml.Marshaller;
import org.xml.sax.AttributeList;
import org.xml.sax.Attributes;
import org.xml.sax.HandlerBase;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

import de.mobiharz.model.buchungen.Unterkunft;


public class MobiHarzXMLFormTransformer extends XMLFormTransformer {

	public void startElement(
		String namespaceURI,
		String localName,
		String qName,
		Attributes attributes)
		throws SAXException {
		if (namespaceURI.equals("") && localName.equals("xmlformergebnis")) {

	try {
		String formName = attributes.getValue("xmlform-id");
		String objectPath = attributes.getValue("xpath");
		Form form = Form.lookup(objectModel, formName);

		JXPathContext context =
			JXPathContext.newContext(form.getModel());

		Object o = context.getValue(objectPath);
//				System.out.println(o);
		super.startElement(
			"",
			"xmlformergebnis",
			"xmlformergebnis",
			attributes);

		Marshaller marshaller = new Marshaller(contentHandler);
		Unterkunft u = (Unterkunft)o;

		marshaller.marshal(o);

	} catch (Exception e) {
		e.printStackTrace();
		super.startElement(
			"",
			"xmlformergebnis",
			"xmlformergebnis",
				attributes);
		}
	} else
		super.startElement(namespaceURI, localName, qName, attributes);
}

public void endElement(String namespaceURI, String localName, String qName)
	throws SAXException {

	if ((namespaceURI != null)) {

		if (namespaceURI.equals("") && localName.equals("xmlformergebnis"))
		super.endElement("", "xmlformergebnis", "xmlformergebnis");
			else
				super.endElement(namespaceURI, localName, qName);
		}
	}

}



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>