    1   /*
    2    * Copyright 2004-2009 the Seasar Foundation and the Others.
    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,
    13   * either express or implied. See the License for the specific language
    14   * governing permissions and limitations under the License.
    15   */
    16  package org.seasar.cubby.tags;
    17
    18  import java.io.IOException;
    19  import java.io.PrintWriter;
    20  import java.io.StringWriter;
    21
    22  import javax.servlet.jsp.JspWriter;
    23
    24  public class MockJspWriter extends JspWriter {
    25
    26  	private StringWriter writer = new StringWriter();
    27
    28  	private PrintWriter printWriter = new PrintWriter(writer);
    29
    30  	public MockJspWriter() {
    31  		this(0, true);
    32  	}
    33
    34  	protected MockJspWriter(int bufferSize, boolean autoFlush) {
    35  		super(bufferSize, autoFlush);
    36  	}
    37
    38  	public String getResult() {
    39  		return writer.toString();
    40  	}
    41
    42  	@Override
    43  	public void clear() throws IOException {
    44  		writer = new StringWriter();
    45  		printWriter = new PrintWriter(writer);
    46  	}
    47
    48  	@Override
    49  	public void clearBuffer() throws IOException {
    50  		writer = new StringWriter();
    51  		printWriter = new PrintWriter(writer);
    52  	}
    53
    54  	@Override
    55  	public void close() throws IOException {
    56  		writer.close();
    57  	}
    58
    59  	@Override
    60  	public void flush() throws IOException {
    61  		writer.flush();
    62  	}
    63
    64  	@Override
    65  	public int getRemaining() {
    66  		return 0;
    67  	}
    68
    69  	@Override
    70  	public void newLine() throws IOException {
    71  		printWriter.println();
    72  	}
    73
    74  	@Override
    75  	public void print(boolean b) throws IOException {
    76  		printWriter.print(b);
    77  	}
    78
    79  	@Override
    80  	public void print(char c) throws IOException {
    81  		printWriter.print(c);
    82  	}
    83
    84  	@Override
    85  	public void print(int i) throws IOException {
    86  		printWriter.print(i);
    87  	}
    88
    89  	@Override
    90  	public void print(long l) throws IOException {
    91  		printWriter.print(l);
    92  	}
    93
    94  	@Override
    95  	public void print(float f) throws IOException {
    96  		printWriter.print(f);
    97  	}
    98
    99  	@Override
    100 	public void print(double d) throws IOException {
    101 		printWriter.print(d);
    102 	}
    103
    104 	@Override
    105 	public void print(char[] s) throws IOException {
    106 		printWriter.print(s);
    107 	}
    108
    109 	@Override
    110 	public void print(String s) throws IOException {
    111 		printWriter.print(s);
    112 	}
    113
    114 	@Override
    115 	public void print(Object obj) throws IOException {
    116 		printWriter.print(obj);
    117 	}
    118
    119 	@Override
    120 	public void println() throws IOException {
    121 		printWriter.println();
    122 	}
    123
    124 	@Override
    125 	public void println(boolean x) throws IOException {
    126 		printWriter.println(x);
    127 	}
    128
    129 	@Override
    130 	public void println(char x) throws IOException {
    131 		printWriter.println(x);
    132 	}
    133
    134 	@Override
    135 	public void println(int x) throws IOException {
    136 		printWriter.println(x);
    137 	}
    138
    139 	@Override
    140 	public void println(long x) throws IOException {
    141 		printWriter.println(x);
    142 	}
    143
    144 	@Override
    145 	public void println(float x) throws IOException {
    146 		printWriter.println(x);
    147 	}
    148
    149 	@Override
    150 	public void println(double x) throws IOException {
    151 		printWriter.println(x);
    152 	}
    153
    154 	@Override
    155 	public void println(char[] x) throws IOException {
    156 		printWriter.println(x);
    157 	}
    158
    159 	@Override
    160 	public void println(String x) throws IOException {
    161 		printWriter.println(x);
    162 	}
    163
    164 	@Override
    165 	public void println(Object x) throws IOException {
    166 		printWriter.println(x);
    167 	}
    168
    169 	@Override
    170 	public void write(char[] cbuf, int off, int len) throws IOException {
    171 		printWriter.write(cbuf, off, len);
    172 	}
    173
    174 	@Override
    175 	public String toString() {
    176 		return writer.toString();
    177 	}
    178 }