001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.reading;
018:
019: import org.apache.avalon.excalibur.pool.Recyclable;
020: import org.apache.avalon.framework.logger.AbstractLogEnabled;
021: import org.apache.avalon.framework.parameters.Parameters;
022: import org.apache.cocoon.ProcessingException;
023: import org.apache.cocoon.environment.SourceResolver;
024: import org.xml.sax.SAXException;
025:
026: import java.io.BufferedOutputStream;
027: import java.io.IOException;
028: import java.io.OutputStream;
029: import java.util.Map;
030:
031: /**
032: * A reader can be used to generate binary output for a request. This
033: * abstract class helps in implementing a custom reader.
034: *
035: * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
036: * @version CVS $Id: AbstractReader.java 452130 2006-10-02 17:17:06Z vgritsenko $
037: */
038: public abstract class AbstractReader extends AbstractLogEnabled
039: implements Reader, Recyclable {
040:
041: /** The current <code>SourceResolver</code>. */
042: protected SourceResolver resolver;
043: /** The current <code>Map</code> of the object model. */
044: protected Map objectModel;
045: /** The current <code>Parameters</code>. */
046: protected Parameters parameters;
047: /** The source URI associated with the request or <b>null</b>. */
048: protected String source;
049: /** The <code>OutputStream</code> to write on. */
050: protected OutputStream out;
051:
052: /**
053: * Set the <code>SourceResolver</code> the object model <code>Map</code>,
054: * the source and sitemap <code>Parameters</code> used to process the request.
055: */
056: public void setup(SourceResolver resolver, Map objectModel,
057: String src, Parameters par) throws ProcessingException,
058: SAXException, IOException {
059: this .resolver = resolver;
060: this .objectModel = objectModel;
061: this .source = src;
062: this .parameters = par;
063: }
064:
065: /**
066: * Set the <code>OutputStream</code>
067: */
068: public void setOutputStream(OutputStream out) {
069: if (out instanceof BufferedOutputStream
070: || out instanceof org.apache.cocoon.util.BufferedOutputStream) {
071: this .out = out;
072: } else {
073: this .out = new BufferedOutputStream(out, 1536);
074: }
075: }
076:
077: /**
078: * Get the mime-type of the output of this <code>Reader</code>
079: */
080: public String getMimeType() {
081: return null;
082: }
083:
084: /**
085: * @return the time the read source was last modified or 0 if it is not
086: * possible to detect
087: */
088: public long getLastModified() {
089: return 0;
090: }
091:
092: /**
093: * Recycle the component
094: */
095: public void recycle() {
096: this .out = null;
097: this .resolver = null;
098: this .source = null;
099: this .parameters = null;
100: this .objectModel = null;
101: }
102:
103: /**
104: * Test if the component wants to set the content length
105: */
106: public boolean shouldSetContentLength() {
107: return false;
108: }
109:
110: }
|