home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / Generator.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-07-12  |  2.7 KB  |  46 lines

  1. package org.apache.cocoon.samples.parentcm;
  2.  
  3. import java.io.IOException;
  4. import java.util.Date;
  5. import java.util.Map;
  6. import org.apache.avalon.excalibur.pool.Poolable;
  7. import org.apache.avalon.framework.component.ComponentException;
  8. import org.apache.avalon.framework.parameters.Parameters;
  9. import org.apache.cocoon.ProcessingException;
  10. import org.apache.cocoon.environment.SourceResolver;
  11. import org.apache.cocoon.generation.ComposerGenerator;
  12. import org.xml.sax.SAXException;
  13. import org.xml.sax.helpers.AttributesImpl;
  14.  
  15. public class Generator extends ComposerGenerator implements Poolable {
  16.    private Date time;
  17.  
  18.    public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException {
  19.       Time timeGiver = null;
  20.  
  21.       try {
  22.          timeGiver = (Time)this.manager.lookup(Time.ROLE);
  23.          this.time = timeGiver.getTime();
  24.       } catch (ComponentException ce) {
  25.          throw new ProcessingException("Could not obtain current time.", ce);
  26.       } finally {
  27.          this.manager.release(timeGiver);
  28.       }
  29.  
  30.    }
  31.  
  32.    public void generate() throws SAXException, ProcessingException {
  33.       AttributesImpl emptyAttributes = new AttributesImpl();
  34.       this.contentHandler.startDocument();
  35.       this.contentHandler.startElement("", "time", "time", emptyAttributes);
  36.       char[] text = this.time.toString().toCharArray();
  37.       this.contentHandler.characters(text, 0, text.length);
  38.       this.contentHandler.endElement("", "time", "time");
  39.       this.contentHandler.endDocument();
  40.    }
  41.  
  42.    public void recycle() {
  43.       this.time = null;
  44.    }
  45. }
  46.