Hi, i want to create a new transformer that gets sax events from a XSP Generator created by me.
i'm using cocoon 2.0.4 under a XP with java version 1.4.1_03. bellow i will post the XSP code of the generator <!--Begin of start.xsp------------------------------------------------------------> <xsp:page language="java" xmlns:xsp="http://apache.org/xsp" xmlns:util="http://apache.org/xsp/util/2.0"> <xsp:structure> <xsp:include>pt.laseeb.dae.xmlDbApi.daeXmlDbApi</xsp:include> <xsp:include>org.xmldb.api.base.ResourceIterator</xsp:include> <xsp:include>org.xmldb.api.base.Resource</xsp:include> <xsp:include>org.xmldb.api.base.XMLDBException</xsp:include> <xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil.*</xsp :include> </xsp:structure> <document xmlns:dae="http://laseeb/dae/sgDae"> <xsp:logic> try { Resource res = null; String resStr = null; daeXmlDbApi daeApi = new daeXmlDbApi(); ResourceIterator results; results = daeApi.getArticleSection("1").getIterator(); while (results.hasMoreResources()) { res = results.nextResource(); resStr = (String) res.getContent(); <util:include-expr><util:expr><xsp:expr>resStr</xsp:expr></util:expr></util: include-expr> } } catch(Exception e) { } </xsp:logic> </document> </xsp:page> <!--End of start.xsp------------------------------------------------------------> when i create a pipeline with only this genrator and a html serializer like, <map:pipeline> <map:match pattern="daestart"> <map:generate type="serverpages" src="daexsps/start.xsp"/> <map:serialize type="html"/> </map:match> </map:pipeline> i get the following result, <!-------------------------------------------------------------------------- ----> <document xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:util="http://apache.org/xsp/util/2.0" xmlns:xsp="http://apache.org/xsp" xmlns:dae="http://laseeb/dae/sgDae"> <dae:article id="1" rating="2" sectionid="1" xmlns:dae="http://laseeb/dae/sgDae" xmlns:src="http://xml.apache.org/xindice/Query" src:col="/db/daeDocuments" src:key="1"> <dae:title>Titulo com rating 2</dae:title> <dae:text>Texto</dae:text> </dae:article> <dae:article id="2" rating="1" sectionid="1" xmlns:dae="http://laseeb/dae/sgDae" xmlns:src="http://xml.apache.org/xindice/Query" src:col="/db/daeDocuments" src:key="2"> <dae:title>Titulo do artigo com rating igual a 1</dae:title> <dae:text>texto do artigo com rating igual a 1</dae:text> <dae:image>img1.jpg</dae:image> </dae:article> <dae:article id="3" rating="2" sectionid="1" xmlns:dae="http://laseeb/dae/sgDae" xmlns:src="http://xml.apache.org/xindice/Query" src:col="/db/daeDocuments" src:key="3"> <dae:title>Titulo do artigo com rating igual a 2</dae:title> <dae:text>texto do artigo com rating igual a 2</dae:text> <dae:image>img1.jpg</dae:image> </dae:article> <dae:article id="4" rating="2" sectionid="1" xmlns:dae="http://laseeb/dae/sgDae" xmlns:src="http://xml.apache.org/xindice/Query" src:col="/db/daeDocuments" src:key="4"> <dae:title>Titulo do artigo com rating igual a 2</dae:title> <dae:text>texto do artigo com rating igual a 2</dae:text> <dae:image>img1.jpg</dae:image> </dae:article> </document> <!-------------------------------------------------------------------------- > wich is the right one. But when i try to apply one transformer created by me, deaTransformer.java (bellow are the methods setup, startElement and endElement that i had to implement, <!--Begin of daeTransformer.java--------------------------------------------------------- ---> public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException { this.mode = MODE_NONE; } public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException { if (namespaceURI != null && namespaceURI.equals(NAMESPACE) ) { AttributesImpl newAttr = new AttributesImpl(); if (localName.equals(ARTICLE_ELEMENT) == true) { newAttr.addAttribute(namespaceURI, ARTICLE_ELEMENT, qName, "color", "red"); super.startElement(namespaceURI, ARTICLE_ELEMENT, qName, newAttr); } else if (localName.equals(ARTICLE_TITLE_ELEMENT) == true) { this.mode = MODE_TITLE; super.startElement(namespaceURI, localName, qName, attributes); } else if (localName.equals(ARTICLE_TEXT_ELEMENT) == true) { this.mode = MODE_TEXT; super.startElement(namespaceURI, localName, qName, attributes); } else if (localName.equals(ARTICLE_IMAGE_ELEMENT) == true) { this.mode = MODE_IMAGE; super.startElement(namespaceURI, localName, qName, attributes); } else { throw new SAXException("Unknown element " + localName); } } else { // Not for us super.startElement(namespaceURI, localName, qName, attributes); } } public void characters(char[] buffer, int start, int length) throws SAXException { switch (this.mode) { case MODE_NONE : super.characters(buffer, start, length); break; case MODE_TITLE : this.articleTitle.append(buffer, start, length); break; case MODE_TEXT : this.articleText.append(buffer, start, length); break; case MODE_IMAGE : this.articleImage.append(buffer, start, length); break; } } public void endElement(String namespaceURI, String localName, String qName) throws SAXException { if (namespaceURI != null && namespaceURI.equals(NAMESPACE)) { if (localName.equals(ARTICLE_ELEMENT) == true) { String text; try { //text = "Sending mail to " + this.toAddress + " was successful."; } catch (Exception any) { this.getLogger().error("Exception during sending of mail", any); // failure message //text = "Sending mail to " + this.toAddress + " failed!"; } // create SAX events for success/failure super.endElement(NAMESPACE, ARTICLE_ELEMENT, ""); } else if (localName.equals(ARTICLE_TITLE_ELEMENT) == true) { // mailto received super.characters(this.articleTitle.toString().toCharArray(), 0, this.articleTitle.length()); super.endElement(NAMESPACE, ARTICLE_TITLE_ELEMENT, ""); this.mode = MODE_NONE; } else if (localName.equals(ARTICLE_TEXT_ELEMENT) == true) { super.characters(this.articleText.toString().toCharArray(), 0, this.articleText.length()); super.endElement(NAMESPACE, ARTICLE_TEXT_ELEMENT, ""); this.mode = MODE_NONE; } else if (localName.equals(ARTICLE_IMAGE_ELEMENT) == true) { super.characters(this.articleImage.toString().toCharArray(), 0, this.articleImage.length()); super.endElement(NAMESPACE, ARTICLE_IMAGE_ELEMENT, ""); this.mode = MODE_NONE; } else { throw new SAXException("Unknown element " + localName); } } else { // not for us super.endElement(namespaceURI, localName, qName); } } <!--End of daeTransformer.java--------------------------------------------------------- ---> and using a pipeline like, <map:pipeline> <map:match pattern="daestart"> <map:generate type="serverpages" src="daexsps/start.xsp"/> <map:transform type="dae"/> <map:serialize type="html"/> </map:match> </map:pipeline> i get, Cocoon 2 - Internal server error ---------------------------------------------------------------------------- ---- type internal-server-error message Exception in ServerPagesGenerator.generate() description org.apache.cocoon.ProcessingException: Exception in ServerPagesGenerator.generate(): java.lang.NullPointerException sender org.apache.cocoon.servlet.CocoonServlet source Cocoon servlet exception org.apache.cocoon.ProcessingException: Exception in ServerPagesGenerator.generate(): java.lang.NullPointerException request-uri /dae/daestart original exception Original exception : java.lang.NullPointerException at org.apache.cocoon.serialization.AbstractTextSerializer.startElement(Abstract TextSerializer.java:271) at org.apache.cocoon.xml.AbstractXMLPipe.startElement(AbstractXMLPipe.java:87) at pt.laseeb.dae.transformer.daeTransformer.startElement(daeTransformer.java:11 6) ..... and it goes on... :( Im sorry for the size of the mail, but if you have read this far and have a clue of what i am doing wrong, i would be thakfull if you give me a hint. :) thanks in advance Miguel Carvalho --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]