001: /*
002: * $Id: StrutsMockJspWriter.java 471756 2006-11-06 15:01:43Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp;
022:
023: import java.io.IOException;
024: import java.io.StringWriter;
025:
026: import javax.servlet.jsp.JspWriter;
027:
028: /**
029: * Unforunately, the MockJspWriter throws a NotImplementedException when any of the Writer methods are invoked and
030: * as you might guess, Velocity uses the Writer methods. I'velocityEngine subclassed the MockJspWriter for the time being so
031: * that we can do testing on the results until MockJspWriter gets fully implemented.
032: * <p/>
033: * todo replace this once MockJspWriter implements Writer correctly (i.e. doesn't throw NotImplementException)
034: */
035: public class StrutsMockJspWriter extends JspWriter {
036: StringWriter writer;
037:
038: public StrutsMockJspWriter(StringWriter writer) {
039: super (1024, true);
040: this .writer = writer;
041: }
042:
043: public void newLine() throws IOException {
044: writer.write("\n");
045: }
046:
047: public void print(boolean b) throws IOException {
048: writer.write(String.valueOf(b));
049: }
050:
051: public void print(char c) throws IOException {
052: writer.write(String.valueOf(c));
053: }
054:
055: public void print(int i) throws IOException {
056: writer.write(i);
057: }
058:
059: public void print(long l) throws IOException {
060: writer.write(String.valueOf(l));
061: }
062:
063: public void print(float v) throws IOException {
064: writer.write(String.valueOf(v));
065: }
066:
067: public void print(double v) throws IOException {
068: writer.write(String.valueOf(v));
069: }
070:
071: public void print(char[] chars) throws IOException {
072: writer.write(chars);
073: }
074:
075: public void print(String s) throws IOException {
076: writer.write(s);
077: }
078:
079: public void print(Object o) throws IOException {
080: writer.write(o.toString());
081: }
082:
083: public void println() throws IOException {
084: writer.write("\n");
085: }
086:
087: public void println(boolean b) throws IOException {
088: print(b);
089: println();
090: }
091:
092: public void println(char c) throws IOException {
093: print(c);
094: println();
095: }
096:
097: public void println(int i) throws IOException {
098: print(i);
099: println();
100: }
101:
102: public void println(long l) throws IOException {
103: print(l);
104: println();
105: }
106:
107: public void println(float v) throws IOException {
108: print(v);
109: println();
110: }
111:
112: public void println(double v) throws IOException {
113: print(v);
114: println();
115: }
116:
117: public void println(char[] chars) throws IOException {
118: print(chars);
119: println();
120: }
121:
122: public void println(String s) throws IOException {
123: print(s);
124: println();
125: }
126:
127: public void println(Object o) throws IOException {
128: print(o);
129: println();
130: }
131:
132: public void clear() throws IOException {
133: }
134:
135: public void clearBuffer() throws IOException {
136: }
137:
138: public void close() throws IOException {
139: writer.close();
140: }
141:
142: public int getRemaining() {
143: return 0;
144: }
145:
146: public void write(char cbuf[], int off, int len) throws IOException {
147: writer.write(cbuf, off, len);
148: }
149:
150: public void write(String str) throws IOException {
151: writer.write(str);
152: }
153:
154: public void write(int c) throws IOException {
155: writer.write(c);
156: }
157:
158: public void write(char[] cbuf) throws IOException {
159: writer.write(cbuf);
160: }
161:
162: public void write(String str, int off, int len) throws IOException {
163: writer.write(str, off, len);
164: }
165:
166: public void flush() {
167: writer.flush();
168: }
169: }
|