home *** CD-ROM | disk | FTP | other *** search
- package org.apache.cocoon.samples.parentcm;
-
- import java.io.IOException;
- import java.util.Date;
- import java.util.Map;
- import org.apache.avalon.excalibur.pool.Poolable;
- import org.apache.avalon.framework.component.ComponentException;
- import org.apache.avalon.framework.parameters.Parameters;
- import org.apache.cocoon.ProcessingException;
- import org.apache.cocoon.environment.SourceResolver;
- import org.apache.cocoon.generation.ComposerGenerator;
- import org.xml.sax.SAXException;
- import org.xml.sax.helpers.AttributesImpl;
-
- public class Generator extends ComposerGenerator implements Poolable {
- private Date time;
-
- public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException {
- Time timeGiver = null;
-
- try {
- timeGiver = (Time)this.manager.lookup(Time.ROLE);
- this.time = timeGiver.getTime();
- } catch (ComponentException ce) {
- throw new ProcessingException("Could not obtain current time.", ce);
- } finally {
- this.manager.release(timeGiver);
- }
-
- }
-
- public void generate() throws SAXException, ProcessingException {
- AttributesImpl emptyAttributes = new AttributesImpl();
- this.contentHandler.startDocument();
- this.contentHandler.startElement("", "time", "time", emptyAttributes);
- char[] text = this.time.toString().toCharArray();
- this.contentHandler.characters(text, 0, text.length);
- this.contentHandler.endElement("", "time", "time");
- this.contentHandler.endDocument();
- }
-
- public void recycle() {
- this.time = null;
- }
- }
-