1 16 package org.apache.cocoon.samples.parentcm; 17 18 import java.io.IOException ; 19 import java.util.Date ; 20 import java.util.Map ; 21 22 import org.apache.avalon.excalibur.pool.Poolable; 23 import org.apache.avalon.framework.parameters.Parameters; 24 import org.apache.avalon.framework.service.ServiceException; 25 import org.apache.cocoon.ProcessingException; 26 import org.apache.cocoon.environment.SourceResolver; 27 import org.apache.cocoon.generation.ServiceableGenerator; 28 import org.apache.cocoon.xml.XMLUtils; 29 import org.xml.sax.SAXException ; 30 31 40 public class Generator extends ServiceableGenerator implements Poolable { 41 42 45 private Date time; 46 47 50 public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) 51 throws ProcessingException, SAXException , IOException { 52 53 Time timeGiver = null; 54 try { 55 timeGiver = (Time) this.manager.lookup(Time.ROLE); 56 this.time = timeGiver.getTime (); 57 } catch (ServiceException ce) { 58 throw new ProcessingException ("Could not obtain current time.", ce); 59 } finally { 60 manager.release(timeGiver); 61 } 62 } 63 64 67 public void generate() 68 throws SAXException , ProcessingException { 69 contentHandler.startDocument(); 70 contentHandler.startElement("", "time", "time", XMLUtils.EMPTY_ATTRIBUTES); 71 72 char[] text = this.time.toString().toCharArray(); 73 contentHandler.characters(text, 0, text.length); 74 75 contentHandler.endElement("", "time", "time"); 76 contentHandler.endDocument(); 77 } 78 79 82 public void recycle () { 83 this.time = null; 84 } 85 } 86 87 88 | Popular Tags |