KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > reading > AbstractReader


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.reading;
17
18 import org.apache.avalon.excalibur.pool.Recyclable;
19 import org.apache.avalon.framework.logger.AbstractLogEnabled;
20 import org.apache.avalon.framework.parameters.Parameters;
21 import org.apache.cocoon.ProcessingException;
22 import org.apache.cocoon.environment.SourceResolver;
23 import org.xml.sax.SAXException JavaDoc;
24
25 import java.io.BufferedOutputStream JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.OutputStream JavaDoc;
28 import java.util.Map JavaDoc;
29
30 /**
31  * A reader can be used to generate binary output for a request. This
32  * abstract class helps in implementing a custom reader.
33  *
34  * @author <a HREF="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
35  * @version CVS $Id: AbstractReader.java 30932 2004-07-29 17:35:38Z vgritsenko $
36  */

37 public abstract class AbstractReader
38   extends AbstractLogEnabled
39   implements Reader, Recyclable {
40
41     /** The current <code>SourceResolver</code>. */
42     protected SourceResolver resolver;
43     /** The current <code>Map</code> of the object model. */
44     protected Map JavaDoc objectModel;
45     /** The current <code>Parameters</code>. */
46     protected Parameters parameters;
47     /** The source URI associated with the request or <b>null</b>. */
48     protected String JavaDoc source;
49     /** The <code>OutputStream</code> to write on. */
50     protected OutputStream JavaDoc out;
51
52     /**
53      * Set the <code>SourceResolver</code> the object model <code>Map</code>,
54      * the source and sitemap <code>Parameters</code> used to process the request.
55      */

56     public void setup(SourceResolver resolver, Map JavaDoc objectModel, String JavaDoc src, Parameters par)
57     throws ProcessingException, SAXException JavaDoc, IOException JavaDoc {
58         this.resolver=resolver;
59         this.objectModel=objectModel;
60         this.source=src;
61         this.parameters=par;
62     }
63
64     /**
65      * Set the <code>OutputStream</code>
66      */

67     public void setOutputStream(OutputStream JavaDoc out) {
68         if ( out instanceof BufferedOutputStream JavaDoc
69              || out instanceof org.apache.cocoon.util.BufferedOutputStream ) {
70             this.out = out;
71         } else {
72             this.out = new BufferedOutputStream JavaDoc(out, 1536);
73         }
74     }
75
76     /**
77      * Get the mime-type of the output of this <code>Reader</code>
78      * This default implementation returns null to indicate that the
79      * mime-type specified in the sitemap is to be used
80      */

81     public String JavaDoc getMimeType() {
82         return null;
83     }
84
85     /**
86      * @return the time the read source was last modified or 0 if it is not
87      * possible to detect
88      */

89     public long getLastModified() {
90         return 0;
91     }
92
93     /**
94      * Recycle the component
95      */

96     public void recycle() {
97         this.out = null;
98         this.resolver = null;
99         this.source = null;
100         this.parameters = null;
101         this.objectModel = null;
102     }
103
104     /**
105      * Test if the component wants to set the content length
106      */

107     public boolean shouldSetContentLength() {
108         return false;
109     }
110
111 }
112
Popular Tags