KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > io > PipeTag


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
17 package org.apache.taglibs.io;
18
19 import java.io.IOException JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.InputStreamReader JavaDoc;
22 import java.io.OutputStream JavaDoc;
23 import java.io.Reader JavaDoc;
24 import java.io.Writer JavaDoc;
25
26 import javax.servlet.ServletContext JavaDoc;
27 import javax.servlet.jsp.JspException JavaDoc;
28 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
29 import javax.servlet.jsp.tagext.Tag JavaDoc;
30
31 /** A pipe tag can be given some input and it pipes to either its standard output
32   * or it can pipe to a parent PipeConsumer
33   *
34   * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
35   * @version $Revision: 1.2 $
36   */

37 public class PipeTag extends TransformerTagSupport {
38
39     public PipeTag() {
40     }
41     
42     /** Pipe the input to the output unless my parent is a consumer
43       * in which case I'll pass my input into my parent PipeConsumer
44       */

45     protected void transform(
46         Reader JavaDoc reader,
47         Writer JavaDoc writer
48     ) throws IOException JavaDoc, JspException JavaDoc {
49         Tag JavaDoc parent = getParent();
50         if ( parent instanceof PipeConsumer ) {
51             PipeConsumer consumer = (PipeConsumer) parent;
52             consumer.setReader( reader );
53         }
54         else {
55             PipeHelper.pipe( reader, writer );
56         }
57     }
58 }
59
Popular Tags