1 16 package org.apache.cocoon.serialization; 17 18 import java.io.IOException ; 19 import java.io.OutputStream ; 20 21 import org.apache.cocoon.components.elementprocessor.ElementProcessor; 22 import org.apache.cocoon.components.elementprocessor.impl.poi.POIFSElementProcessor; 23 24 import org.apache.poi.poifs.filesystem.POIFSFileSystem; 25 import org.xml.sax.SAXException ; 26 27 43 public abstract class POIFSSerializer extends ElementProcessorSerializer 44 { 45 private POIFSFileSystem _filesystem; 46 47 50 51 public POIFSSerializer() { 52 super(); 53 _filesystem = new POIFSFileSystem(); 54 } 55 56 59 65 66 public void endDocument() throws SAXException { 67 doLocalPreEndDocument(); 68 69 OutputStream stream = getOutputStream(); 70 71 if ( stream != null ) { 72 try { 73 _filesystem.writeFilesystem( stream ); 74 } catch ( IOException e ) { 75 throw SAXExceptionFactory( 76 "could not process endDocument event", e ); 77 } 78 } else { 79 throw SAXExceptionFactory( 80 "no outputstream for writing the document!!" ); 81 } 82 doLocalPostEndDocument(); 83 } 84 85 90 91 protected POIFSFileSystem getFilesystem() { 92 return _filesystem; 93 } 94 95 99 100 protected abstract void doLocalPreEndDocument(); 101 102 106 107 protected abstract void doLocalPostEndDocument(); 108 109 115 116 protected void doPreInitialization(ElementProcessor processor) 117 throws SAXException { 118 try { 119 ((POIFSElementProcessor)processor).setFilesystem(_filesystem); 120 } catch (ClassCastException e) { 121 throw SAXExceptionFactory( "could not pre-initialize processor", e ); 122 } 123 } 124 125 128 } 129 | Popular Tags |