1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.shale.test.mock; |
19 | |
|
20 | |
import java.io.IOException; |
21 | |
import java.io.OutputStream; |
22 | |
import java.io.Writer; |
23 | |
import java.util.HashMap; |
24 | |
import java.util.Map; |
25 | |
|
26 | |
import javax.faces.context.ResponseStream; |
27 | |
import javax.faces.context.ResponseWriter; |
28 | |
import javax.faces.render.RenderKit; |
29 | |
import javax.faces.render.Renderer; |
30 | |
import javax.faces.render.ResponseStateManager; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class MockRenderKit extends RenderKit { |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | 18 | public MockRenderKit() { |
48 | 18 | } |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | 18 | private Map renderers = new HashMap(); |
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
public void addRenderer(String family, String rendererType, |
68 | |
Renderer renderer) { |
69 | |
|
70 | 26 | if ((family == null) || (rendererType == null) || (renderer == null)) { |
71 | |
throw new NullPointerException(); |
72 | |
} |
73 | 26 | renderers.put(family + "|" + rendererType, renderer); |
74 | |
|
75 | 26 | } |
76 | |
|
77 | |
|
78 | |
|
79 | |
public Renderer getRenderer(String family, String rendererType) { |
80 | |
|
81 | 2 | if ((family == null) || (rendererType == null)) { |
82 | |
throw new NullPointerException(); |
83 | |
} |
84 | 2 | return (Renderer) renderers.get(family + "|" + rendererType); |
85 | |
|
86 | |
} |
87 | |
|
88 | |
|
89 | |
|
90 | |
public ResponseWriter createResponseWriter(Writer writer, |
91 | |
String contentTypeList, |
92 | |
String characterEncoding) { |
93 | |
|
94 | |
return new MockResponseWriter(writer, contentTypeList, characterEncoding); |
95 | |
|
96 | |
} |
97 | |
|
98 | |
|
99 | |
|
100 | |
public ResponseStream createResponseStream(OutputStream out) { |
101 | |
|
102 | |
final OutputStream stream = out; |
103 | |
return new ResponseStream() { |
104 | |
|
105 | |
public void close() throws IOException { |
106 | |
stream.close(); |
107 | |
} |
108 | |
|
109 | |
public void flush() throws IOException { |
110 | |
stream.flush(); |
111 | |
} |
112 | |
|
113 | |
public void write(byte[] b) throws IOException { |
114 | |
stream.write(b); |
115 | |
} |
116 | |
|
117 | |
public void write(byte[] b, int off, int len) throws IOException { |
118 | |
stream.write(b, off, len); |
119 | |
} |
120 | |
|
121 | |
public void write(int b) throws IOException { |
122 | |
stream.write(b); |
123 | |
} |
124 | |
|
125 | |
}; |
126 | |
|
127 | |
|
128 | |
} |
129 | |
|
130 | |
|
131 | |
|
132 | |
public ResponseStateManager getResponseStateManager() { |
133 | |
|
134 | |
throw new UnsupportedOperationException(); |
135 | |
|
136 | |
} |
137 | |
|
138 | |
|
139 | |
} |