cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mattom" <web.schnir...@gmx.at>
Subject Re: 2.1[.7]: XSP: Include XML from Java-[J]DOM
Date Tue, 05 Apr 2005 11:45:14 GMT
Write a custom generator, I followed the tutorial at 

http://people.apache.org/~reinhard/2.2/tutorial/tutorial-rmi-generator.html

or take my code snippet as example (stripped some code that you wont need, i
am not sure wether this is compileable)

package at.schnirkel.cocoon.generator.test;

import java.io.IOException;
import java.io.Serializable;
import java.io.StringReader;
import java.rmi.RemoteException;

import org.apache.cocoon.generation.AbstractGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;


public class CocoonGeneratorHelloWorldExample extends AbstractGenerator  
{
	private CompositeXfaceFactory  xfaceFactory = null;
	private Log log =
LogFactory.getFactory().getInstance(this.getClass().getName());
    //AttributesImpl emptyAttr = new AttributesImpl();

    public void generate() throws SAXException
    
    {
       
      // the org.xml.sax.ContentHandler is inherited 
      // through org.apache.cocoon.xml.AbstractXMLProducer 

      /*contentHandler.startDocument();
      
      contentHandler.startElement("", "document", "document", emptyAttr);
      
      contentHandler.startElement("", "title", "title", emptyAttr);
      
      contentHandler.characters("A dynamic Hello World!".toCharArray(),0,
                                  "A dynamic Hello World!".length());

      contentHandler.endElement("","title", "title");
      
      contentHandler.startElement("", "content","content", emptyAttr);
      contentHandler.startElement("","para","para", emptyAttr);
      
      contentHandler.characters("A dynamic Hello World
Text!".toCharArray(),0,
            "A dynamic Hello World Text!".length());

      contentHandler.endElement("","para", "para");
      
      contentHandler.endElement("","content", "content");
      
      contentHandler.endElement("","document", "document");
      
      contentHandler.endDocument();*/

		
        InputSource tVertragXMLInputSrc=null;
        
    	
      String message = "<document><title>A dynamic Hello World
!</title><content><para>A wonderful cool text coming from a java
class</para></content></document>";
    	
      XMLReader xmlreader = XMLReaderFactory.createXMLReader();
      xmlreader.setContentHandler(super.xmlConsumer);
      InputSource source = new InputSource(new StringReader(message));
      try {
		xmlreader.parse(source);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (SAXException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}    	

    }
}


-- 
Handyrechnung zu hoch? Tipp: SMS und MMS mit GMX
Seien Sie so frei: Alle Infos unter http://www.gmx.net/de/go/freesms

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message