cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Philipp Suter <p.su...@netbreeze.ch>
Subject Re: 2.1[.7]: XSP: Include XML from Java-[J]DOM
Date Wed, 06 Apr 2005 08:18:14 GMT
Here is my solution witth the JDOM SAXOutputter (if anybody has a 
similar problem):

package some.package;

import org.apache.cocoon.generation.AbstractGenerator;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.SAXOutputter;
import org.xml.sax.SAXException;

import ch.netbreeze.sindbad.cocoon.data.NetPageConnector;
import ch.netbreeze.sindbad.cocoon.user.UserSettingsList;
import ch.netbreeze.sindbad.cocoon.util.StackTrace;
import ch.netbreeze.sindbad.xml.XMLUtility;

public class ImmoDataGenerator extends AbstractGenerator{
  private String path;
  private UserSettingsList userSettings;
  private NetPageConnector pageHandler;

  private void init() throws Exception{
    pageHandler = new NetPageConnector();
    userSettings = new UserSettingsList(
            XMLUtility.loadDoc(path).getRootElement());
  }
 
  public void generate() throws SAXException{
    try{
      this.init();
      SAXOutputter saxOut = new SAXOutputter(super.xmlConsumer);
      saxOut.output(getFilteredData(getFilterPath()));
    } catch (Exception e) {
        getLogger().fatalError(StackTrace.getStackTrace(e));
    }
  }
 
  private String getFilterPath() throws Exception{
     
  }
 
  private Document getFilteredData (String queryExtension) throws 
Exception {
     
  }

 
}

Cheers
ph

Mattom wrote:

>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();
>	}    	
>
>    }
>}
>
>
>  
>

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


Mime
View raw message