KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > mock > MockEnvironment


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.environment.mock;
17
18 import java.io.ByteArrayOutputStream JavaDoc;
19 import java.io.IOException JavaDoc;
20 import java.io.OutputStream JavaDoc;
21 import java.net.MalformedURLException JavaDoc;
22 import java.util.Enumeration JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Hashtable JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import junit.framework.AssertionFailedError;
28
29 import org.apache.cocoon.ProcessingException;
30 import org.apache.cocoon.environment.Environment;
31 import org.apache.cocoon.environment.Source;
32 import org.apache.excalibur.source.SourceResolver;
33 import org.xml.sax.ContentHandler JavaDoc;
34 import org.xml.sax.SAXException JavaDoc;
35
36 public class MockEnvironment implements Environment {
37
38     private SourceResolver resolver;
39
40     private String JavaDoc uri;
41     private String JavaDoc uriprefix;
42     private String JavaDoc rootcontext;
43     private String JavaDoc context;
44     private String JavaDoc view;
45     private String JavaDoc action;
46     private String JavaDoc contenttype;
47     private int contentlength;
48     private int status;
49     private ByteArrayOutputStream JavaDoc outputstream;
50     private HashMap JavaDoc objectmodel;
51     private Hashtable JavaDoc attributes = new Hashtable JavaDoc();
52
53     public MockEnvironment(SourceResolver resolver) {
54         this.resolver = resolver;
55     }
56
57     public String JavaDoc getURI() {
58         return uri;
59     }
60
61     public String JavaDoc getURIPrefix() {
62         return uriprefix;
63     }
64
65     public String JavaDoc getRootContext() {
66         return rootcontext;
67     }
68
69     public String JavaDoc getContext() {
70         return context;
71     }
72
73     public String JavaDoc getView() {
74         return view;
75     }
76
77     public String JavaDoc getAction() {
78         return action;
79     }
80
81     public void setContext(String JavaDoc prefix, String JavaDoc uri, String JavaDoc context) {
82         throw new AssertionFailedError("Not implemented");
83     }
84
85     public void changeContext(String JavaDoc uriprefix, String JavaDoc context) throws Exception JavaDoc {
86         throw new AssertionFailedError("Not implemented");
87     }
88
89     public void redirect(boolean sessionmode, String JavaDoc url) throws IOException JavaDoc {
90         throw new AssertionFailedError("Use Redirector.redirect instead!");
91     }
92
93     public void setContentType(String JavaDoc contenttype) {
94         this.contenttype = contenttype;
95     }
96
97     public String JavaDoc getContentType() {
98         return contenttype;
99     }
100
101     public void setContentLength(int length) {
102         this.contentlength = length;
103     }
104
105     public int getContentLength() {
106         return contentlength;
107     }
108
109     public void setStatus(int statusCode) {
110         this.status = statusCode;
111     }
112
113     public int getStatus() {
114         return status;
115     }
116
117     public OutputStream JavaDoc getOutputStream() throws IOException JavaDoc {
118         outputstream = new ByteArrayOutputStream JavaDoc();
119         return outputstream;
120     }
121
122     public OutputStream JavaDoc getOutputStream(int bufferSize) throws IOException JavaDoc {
123         outputstream = new ByteArrayOutputStream JavaDoc();
124         return outputstream;
125     }
126
127     public byte[] getOutput() {
128         return outputstream.toByteArray();
129     }
130
131     public Map JavaDoc getObjectModel() {
132         return objectmodel;
133     }
134
135     public boolean isResponseModified(long lastModified) {
136         throw new AssertionFailedError("Not implemented");
137     }
138
139     public void setResponseIsNotModified() {
140         throw new AssertionFailedError("Not implemented");
141     }
142
143     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
144         attributes.put(name, value);
145     }
146
147     public Object JavaDoc getAttribute(String JavaDoc name) {
148         return attributes.get(name);
149     }
150
151     public void removeAttribute(String JavaDoc name) {
152         attributes.remove(name);
153     }
154
155     public Enumeration JavaDoc getAttributeNames() {
156         return attributes.keys();
157     }
158
159     public boolean tryResetResponse() throws IOException JavaDoc {
160         throw new AssertionFailedError("Not implemented");
161     }
162
163     public void commitResponse() throws IOException JavaDoc {
164         throw new AssertionFailedError("Not implemented");
165     }
166     
167     public void startingProcessing() {
168         throw new AssertionFailedError("Not implemented");
169     }
170     
171     public void finishingProcessing() {
172         throw new AssertionFailedError("Not implemented");
173     }
174
175
176     public Source resolve(String JavaDoc systemID)
177       throws ProcessingException, SAXException JavaDoc, IOException JavaDoc {
178   
179         throw new AssertionFailedError("Not not use deprecated methods!");
180     }
181
182     public void toSAX(org.apache.excalibur.source.Source source,
183                 ContentHandler JavaDoc handler)
184       throws SAXException JavaDoc, IOException JavaDoc, ProcessingException {
185
186         throw new AssertionFailedError("Not not use deprecated methods!");
187     }
188
189     public void toSAX(org.apache.excalibur.source.Source source,
190                String JavaDoc mimeTypeHint,
191                ContentHandler JavaDoc handler)
192       throws SAXException JavaDoc, IOException JavaDoc, ProcessingException {
193
194         throw new AssertionFailedError("Not not use deprecated methods!");
195     }
196
197     public org.apache.excalibur.source.Source resolveURI(String JavaDoc location)
198         throws MalformedURLException JavaDoc, IOException JavaDoc, org.apache.excalibur.source.SourceException {
199
200         return resolver.resolveURI(location);
201     }
202
203     public org.apache.excalibur.source.Source resolveURI(String JavaDoc location,
204                                                          String JavaDoc base,
205                                                          Map JavaDoc parameters)
206         throws MalformedURLException JavaDoc, IOException JavaDoc, org.apache.excalibur.source.SourceException {
207
208         return resolver.resolveURI(location, base, parameters);
209     }
210
211     /**
212      * Releases a resolved resource
213      */

214     public void release(org.apache.excalibur.source.Source source) {
215         resolver.release(source);
216     }
217     
218     /**
219      * Always return <code>true</code>.
220      */

221     public boolean isExternal() {
222         return true;
223     }
224
225     /* (non-Javadoc)
226      * @see org.apache.cocoon.environment.Environment#isInternRedirect()
227      */

228     public boolean isInternalRedirect() {
229         return false;
230     }
231 }
232
233
Popular Tags