View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.springframework.extensions.surf.util;
20  
21  import java.io.IOException;
22  import java.io.PrintWriter;
23  import java.io.Writer;
24  
25  import javax.servlet.jsp.JspWriter;
26  
27  /**
28   * akeJspWriter.
29   */
30  public class FakeJspWriter extends JspWriter
31  {
32      /** The root writer. */
33      private Writer rootWriter = null;
34      
35      /** A print writer that wraps the root writer */
36      private PrintWriter printWriter = null;
37  
38      /**
39       * Instantiates a new fake jsp writer.
40       */
41      public FakeJspWriter() {
42          super(0, false);
43          
44          rootWriter = new StringBuilderWriter(512);
45          printWriter = new PrintWriter(rootWriter);
46      }
47  
48      /**
49       * Instantiates a new fake jsp writer.
50       * 
51       * @param myWriter
52       *            the my writer
53       */
54      public FakeJspWriter(Writer myWriter) {
55          super(0, false);
56  
57          this.rootWriter = myWriter;
58          printWriter = new PrintWriter(myWriter);
59      }
60      
61      /**
62       * Instantiates a new fake jsp writer.
63       * 
64       * @param arg0
65       *            the arg0
66       * @param arg1
67       *            the arg1
68       */
69      public FakeJspWriter(int arg0, boolean arg1) {
70          super(arg0, arg1);
71  
72          rootWriter = new StringBuilderWriter(512);
73          printWriter = new PrintWriter(rootWriter);        
74      }
75  
76      /**
77       * Gets the print writer.
78       * 
79       * @return the print writer
80       */
81      public PrintWriter getPrintWriter() {
82          return printWriter;
83      }
84  
85      /**
86       * Gets the root writer.
87       * 
88       * @return the root writer
89       */
90      public Writer getRootWriter() {
91          return rootWriter;
92      }
93  
94      /* (non-Javadoc)
95       * @see javax.servlet.jsp.JspWriter#newLine()
96       */
97      @Override
98      public void newLine() throws IOException {
99          printWriter.println();
100     }
101 
102     /* (non-Javadoc)
103      * @see javax.servlet.jsp.JspWriter#print(boolean)
104      */
105     @Override
106     public void print(boolean arg0) throws IOException {
107         printWriter.print(arg0);
108     }
109 
110     /* (non-Javadoc)
111      * @see javax.servlet.jsp.JspWriter#print(char)
112      */
113     @Override
114     public void print(char arg0) throws IOException {
115         printWriter.print(arg0);
116     }
117 
118     /* (non-Javadoc)
119      * @see javax.servlet.jsp.JspWriter#print(int)
120      */
121     @Override
122     public void print(int arg0) throws IOException {
123         printWriter.print(arg0);
124     }
125 
126     /* (non-Javadoc)
127      * @see javax.servlet.jsp.JspWriter#print(long)
128      */
129     @Override
130     public void print(long arg0) throws IOException {
131         printWriter.print(arg0);
132     }
133 
134     /* (non-Javadoc)
135      * @see javax.servlet.jsp.JspWriter#print(float)
136      */
137     @Override
138     public void print(float arg0) throws IOException {
139         printWriter.print(arg0);
140     }
141 
142     /* (non-Javadoc)
143      * @see javax.servlet.jsp.JspWriter#print(double)
144      */
145     @Override
146     public void print(double arg0) throws IOException {
147         printWriter.print(arg0);
148     }
149 
150     /* (non-Javadoc)
151      * @see javax.servlet.jsp.JspWriter#print(char[])
152      */
153     @Override
154     public void print(char[] arg0) throws IOException {
155         printWriter.print(arg0);
156     }
157 
158     /* (non-Javadoc)
159      * @see javax.servlet.jsp.JspWriter#print(java.lang.String)
160      */
161     @Override
162     public void print(String arg0) throws IOException {
163         printWriter.print(arg0);
164     }
165 
166     /* (non-Javadoc)
167      * @see javax.servlet.jsp.JspWriter#print(java.lang.Object)
168      */
169     @Override
170     public void print(Object arg0) throws IOException {
171         printWriter.print(arg0);
172     }
173 
174     /* (non-Javadoc)
175      * @see javax.servlet.jsp.JspWriter#println()
176      */
177     @Override
178     public void println() throws IOException {
179         printWriter.println();
180     }
181 
182     /* (non-Javadoc)
183      * @see javax.servlet.jsp.JspWriter#println(boolean)
184      */
185     @Override
186     public void println(boolean arg0) throws IOException {
187         printWriter.println(arg0);
188     }
189 
190     /* (non-Javadoc)
191      * @see javax.servlet.jsp.JspWriter#println(char)
192      */
193     @Override
194     public void println(char arg0) throws IOException {
195         printWriter.println(arg0);
196     }
197 
198     /* (non-Javadoc)
199      * @see javax.servlet.jsp.JspWriter#println(int)
200      */
201     @Override
202     public void println(int arg0) throws IOException {
203         printWriter.println(arg0);
204     }
205 
206     /* (non-Javadoc)
207      * @see javax.servlet.jsp.JspWriter#println(long)
208      */
209     @Override
210     public void println(long arg0) throws IOException {
211         printWriter.println(arg0);
212     }
213 
214     /* (non-Javadoc)
215      * @see javax.servlet.jsp.JspWriter#println(float)
216      */
217     @Override
218     public void println(float arg0) throws IOException {
219         printWriter.println(arg0);
220     }
221 
222     /* (non-Javadoc)
223      * @see javax.servlet.jsp.JspWriter#println(double)
224      */
225     @Override
226     public void println(double arg0) throws IOException {
227         printWriter.println(arg0);
228     }
229 
230     /* (non-Javadoc)
231      * @see javax.servlet.jsp.JspWriter#println(char[])
232      */
233     @Override
234     public void println(char[] arg0) throws IOException {
235         printWriter.println(arg0);
236     }
237 
238     /* (non-Javadoc)
239      * @see javax.servlet.jsp.JspWriter#println(java.lang.String)
240      */
241     @Override
242     public void println(String arg0) throws IOException {
243         printWriter.println(arg0);
244     }
245 
246     /* (non-Javadoc)
247      * @see javax.servlet.jsp.JspWriter#println(java.lang.Object)
248      */
249     @Override
250     public void println(Object arg0) throws IOException {
251         printWriter.println(arg0);
252     }
253 
254     /* (non-Javadoc)
255      * @see javax.servlet.jsp.JspWriter#clear()
256      */
257     @Override
258     public void clear() throws IOException {
259     }
260 
261     /* (non-Javadoc)
262      * @see javax.servlet.jsp.JspWriter#clearBuffer()
263      */
264     @Override
265     public void clearBuffer() throws IOException {
266     }
267 
268     /* (non-Javadoc)
269      * @see javax.servlet.jsp.JspWriter#flush()
270      */
271     @Override
272     public void flush() throws IOException {
273         printWriter.flush();
274     }
275 
276     /* (non-Javadoc)
277      * @see javax.servlet.jsp.JspWriter#close()
278      */
279     @Override
280     public void close() throws IOException {
281         printWriter.close();
282     }
283 
284     /* (non-Javadoc)
285      * @see javax.servlet.jsp.JspWriter#getRemaining()
286      */
287     @Override
288     public int getRemaining() {
289         return 0;
290     }
291 
292     /* (non-Javadoc)
293      * @see java.io.Writer#write(char[], int, int)
294      */
295     @Override
296     public void write(char[] cbuf, int off, int len) throws IOException {
297         printWriter.write(cbuf, off, len);
298     }
299 
300 }