KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infohazard > maverick > transform > AbstractTransformStep


1 /*
2  * $Id: AbstractTransformStep.java,v 1.4 2004/06/07 20:37:59 eelco12 Exp $
3  * $Source: /cvsroot/mav/maverick/src/java/org/infohazard/maverick/transform/AbstractTransformStep.java,v $
4  */

5
6 package org.infohazard.maverick.transform;
7
8 import java.io.IOException JavaDoc;
9 import java.io.Writer JavaDoc;
10
11 import javax.servlet.ServletException JavaDoc;
12 import javax.servlet.http.HttpServletResponse JavaDoc;
13
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16 import org.infohazard.maverick.flow.TransformContext;
17 import org.infohazard.maverick.flow.TransformStep;
18 import org.infohazard.maverick.util.FakeHttpServletResponse;
19
20 /**
21  * Helper class for all transform steps. When extending this class,
22  * remember that you are providing the TransformStep interface, so
23  * the getResponse(), etc methods are for a *client* to call. You
24  * should be sending your output to the methods on getNext(), which
25  * is safe to call multiple times.
26  *
27  * Remember, the goal is to take data written to you and send it on
28  * to the next step!
29  */

30 public abstract class AbstractTransformStep implements TransformStep
31 {
32     /**
33      * Logger
34      */

35     private static Log log = LogFactory.getLog(AbstractTransformStep.class);
36
37     /**
38      */

39     private TransformContext transformCtx;
40     
41     /**
42      */

43     private TransformStep next;
44     
45     /**
46      */

47     protected FakeHttpServletResponse fakeResponse;
48     
49     /**
50      */

51     public AbstractTransformStep(TransformContext tctx) throws ServletException JavaDoc
52     {
53         this.transformCtx = tctx;
54     }
55     
56     /**
57      * Always return false from pluggable transform steps.
58      */

59     public boolean isLast()
60     {
61         return false;
62     }
63
64     /**
65      * By default do nothing.
66      */

67     public void setContentType(String JavaDoc contentType)
68     {
69     }
70     
71     /**
72      */

73     protected TransformContext getTransformCtx()
74     {
75         return this.transformCtx;
76     }
77     
78     /**
79      * Allow us to lazily create the next step, much more convenient.
80      */

81     protected TransformStep getNext() throws ServletException JavaDoc
82     {
83         if (this.next == null)
84             this.next = this.getTransformCtx().getNextStep();
85             
86         return this.next;
87     }
88     
89     /**
90      */

91     public HttpServletResponse JavaDoc getResponse() throws IOException JavaDoc, ServletException JavaDoc
92     {
93         log.debug("Getting fake response");
94         
95         // Should be ok to wrap the real mccoy here.
96
if (this.fakeResponse == null)
97             this.fakeResponse = new FakeHttpServletResponse(this.getTransformCtx().getRealResponse());
98
99         return this.fakeResponse;
100     }
101
102     /**
103      */

104     public Writer JavaDoc getWriter() throws IOException JavaDoc, ServletException JavaDoc
105     {
106         return this.getResponse().getWriter();
107     }
108 }
109
Popular Tags