1 package org.seasar.cubby.tags; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 import java.io.StringWriter; 6 7 import javax.servlet.jsp.JspWriter; 8 9 public class MockJspWriter extends JspWriter { 10 11 StringWriter writer = new StringWriter(); 12 PrintWriter printWriter = new PrintWriter(writer); 13 14 public MockJspWriter() { 15 this(0, true); 16 } 17 18 protected MockJspWriter(int bufferSize, boolean autoFlush) { 19 super(bufferSize, autoFlush); 20 } 21 22 public String getResult() { 23 return writer.toString(); 24 } 25 26 @Override 27 public void clear() throws IOException { 28 writer = new StringWriter(); 29 printWriter = new PrintWriter(writer); 30 } 31 32 @Override 33 public void clearBuffer() throws IOException { 34 writer = new StringWriter(); 35 printWriter = new PrintWriter(writer); 36 } 37 38 @Override 39 public void close() throws IOException { 40 writer.close(); 41 } 42 43 @Override 44 public void flush() throws IOException { 45 writer.flush(); 46 } 47 48 @Override 49 public int getRemaining() { 50 return 0; 51 } 52 53 @Override 54 public void newLine() throws IOException { 55 printWriter.println(); 56 } 57 58 @Override 59 public void print(boolean b) throws IOException { 60 printWriter.print(b); 61 } 62 63 @Override 64 public void print(char c) throws IOException { 65 printWriter.print(c); 66 } 67 68 @Override 69 public void print(int i) throws IOException { 70 printWriter.print(i); 71 } 72 73 @Override 74 public void print(long l) throws IOException { 75 printWriter.print(l); 76 } 77 78 @Override 79 public void print(float f) throws IOException { 80 printWriter.print(f); 81 } 82 83 @Override 84 public void print(double d) throws IOException { 85 printWriter.print(d); 86 } 87 88 @Override 89 public void print(char[] s) throws IOException { 90 printWriter.print(s); 91 } 92 93 @Override 94 public void print(String s) throws IOException { 95 printWriter.print(s); 96 } 97 98 @Override 99 public void print(Object obj) throws IOException { 100 printWriter.print(obj); 101 } 102 103 @Override 104 public void println() throws IOException { 105 printWriter.println(); 106 } 107 108 @Override 109 public void println(boolean x) throws IOException { 110 printWriter.println(x); 111 } 112 113 @Override 114 public void println(char x) throws IOException { 115 printWriter.println(x); 116 } 117 118 @Override 119 public void println(int x) throws IOException { 120 printWriter.println(x); 121 } 122 123 @Override 124 public void println(long x) throws IOException { 125 printWriter.println(x); 126 } 127 128 @Override 129 public void println(float x) throws IOException { 130 printWriter.println(x); 131 } 132 133 @Override 134 public void println(double x) throws IOException { 135 printWriter.println(x); 136 } 137 138 @Override 139 public void println(char[] x) throws IOException { 140 printWriter.println(x); 141 } 142 143 @Override 144 public void println(String x) throws IOException { 145 printWriter.println(x); 146 } 147 148 @Override 149 public void println(Object x) throws IOException { 150 printWriter.println(x); 151 } 152 153 @Override 154 public void write(char[] cbuf, int off, int len) throws IOException { 155 printWriter.write(cbuf, off, len); 156 } 157 158 }