KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > serialization > POIFSSerializer


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.serialization;
17
18 import java.io.IOException JavaDoc;
19 import java.io.OutputStream JavaDoc;
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 JavaDoc;
26
27 /**
28  * An extension of ElementProcessorSerializer with extensions for dealing with
29  * the POIFS filesystem This is an abstract class. Concrete extensions need to
30  * implement the following methods:
31  * <ul>
32  * <li> String getMimeType()</li>
33  * <li> void doLocalPreEndDocument()</li>
34  * <li> void doLocalPostEndDocument()</li>
35  * <li> ElementProcessorFactory getElementProcessorFactory()</li>
36  * </li>
37  * </ul>
38  *
39  * @author Marc Johnson (marc_johnson27591@hotmail.com)
40  * @author Nicola Ken Barozzi (nicolaken@apache.org)
41  * @version CVS $Id: POIFSSerializer.java 30932 2004-07-29 17:35:38Z vgritsenko $
42  */

43 public abstract class POIFSSerializer extends ElementProcessorSerializer
44 {
45   private POIFSFileSystem _filesystem;
46
47   /**
48    * Constructor
49    */

50
51   public POIFSSerializer() {
52     super();
53     _filesystem = new POIFSFileSystem();
54   }
55
56   /*
57    * ********** START implementation of ContentHandler **********
58    */

59   /**
60    * Receive notification of the end of a document.
61    *
62    *@exception SAXException if there is an error writing the document to the
63    * output stream
64    */

65
66   public void endDocument() throws SAXException JavaDoc {
67     doLocalPreEndDocument();
68
69     OutputStream JavaDoc stream = getOutputStream();
70
71     if ( stream != null ) {
72       try {
73         _filesystem.writeFilesystem( stream );
74       } catch ( IOException JavaDoc 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   /**
86    * Provide access to the filesystem for extending classes
87    *
88    *@return the filesystem
89    */

90
91   protected POIFSFileSystem getFilesystem() {
92     return _filesystem;
93   }
94
95   /**
96    * Extending classes should do whatever they need to do prior to writing the
97    * filesystem out
98    */

99
100   protected abstract void doLocalPreEndDocument();
101
102   /**
103    * Extending classes should do whatever they need to do after writing the
104    * filesystem out
105    */

106
107   protected abstract void doLocalPostEndDocument();
108
109   /**
110    * perform pre-initialization on an element processor
111    *
112    *@param processor the element processor to be iniitialized
113    *@exception SAXException on errors
114    */

115
116   protected void doPreInitialization(ElementProcessor processor)
117       throws SAXException JavaDoc {
118     try {
119       ((POIFSElementProcessor)processor).setFilesystem(_filesystem);
120     } catch (ClassCastException JavaDoc e) {
121       throw SAXExceptionFactory( "could not pre-initialize processor", e );
122     }
123   }
124
125   /*
126    * ********** END implementation of ContentHandler **********
127    */

128 }
129 // end public abstract class POIFSSerializer
130
Popular Tags