cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Harald Wehr <hw...@hs-harz.de>
Subject Castor Transformer
Date Thu, 23 Jan 2003 11:18:46 GMT
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:     <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>


Mime
View raw message