001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.environment.mock;
018:
019: import java.io.ByteArrayOutputStream;
020: import java.io.IOException;
021: import java.io.OutputStream;
022: import java.net.MalformedURLException;
023: import java.util.Enumeration;
024: import java.util.HashMap;
025: import java.util.Hashtable;
026: import java.util.Map;
027:
028: import junit.framework.AssertionFailedError;
029:
030: import org.apache.cocoon.ProcessingException;
031: import org.apache.cocoon.environment.Environment;
032: import org.apache.cocoon.environment.Source;
033: import org.apache.excalibur.source.SourceResolver;
034: import org.xml.sax.ContentHandler;
035: import org.xml.sax.SAXException;
036:
037: /* @version $Id: MockEnvironment.java 433543 2006-08-22 06:22:54Z crossley $ */
038: public class MockEnvironment implements Environment {
039:
040: private SourceResolver resolver;
041:
042: private String uri;
043: private String uriprefix;
044: private String rootcontext;
045: private String context;
046: private String view;
047: private String action;
048: private String contenttype;
049: private int contentlength;
050: private int status;
051: private ByteArrayOutputStream outputstream;
052: private HashMap objectmodel;
053: private Hashtable attributes = new Hashtable();
054:
055: public MockEnvironment(SourceResolver resolver) {
056: this .resolver = resolver;
057: }
058:
059: public String getURI() {
060: return uri;
061: }
062:
063: public String getURIPrefix() {
064: return uriprefix;
065: }
066:
067: public String getRootContext() {
068: return rootcontext;
069: }
070:
071: public String getContext() {
072: return context;
073: }
074:
075: public String getView() {
076: return view;
077: }
078:
079: public String getAction() {
080: return action;
081: }
082:
083: public void setContext(String prefix, String uri, String context) {
084: throw new AssertionFailedError("Not implemented");
085: }
086:
087: public void changeContext(String uriprefix, String context)
088: throws Exception {
089: throw new AssertionFailedError("Not implemented");
090: }
091:
092: public void redirect(boolean sessionmode, String url)
093: throws IOException {
094: throw new AssertionFailedError(
095: "Use Redirector.redirect instead!");
096: }
097:
098: public void setContentType(String contenttype) {
099: this .contenttype = contenttype;
100: }
101:
102: public String getContentType() {
103: return contenttype;
104: }
105:
106: public void setContentLength(int length) {
107: this .contentlength = length;
108: }
109:
110: public int getContentLength() {
111: return contentlength;
112: }
113:
114: public void setStatus(int statusCode) {
115: this .status = statusCode;
116: }
117:
118: public int getStatus() {
119: return status;
120: }
121:
122: /**
123: * Get the output stream where to write the generated resource.
124: * @deprecated Use {@link #getOutputStream(int)} instead.
125: */
126: public OutputStream getOutputStream() throws IOException {
127: return getOutputStream(-1);
128: }
129:
130: public OutputStream getOutputStream(int bufferSize)
131: throws IOException {
132: outputstream = new ByteArrayOutputStream();
133: return outputstream;
134: }
135:
136: public byte[] getOutput() {
137: return outputstream.toByteArray();
138: }
139:
140: public Map getObjectModel() {
141: return objectmodel;
142: }
143:
144: public boolean isResponseModified(long lastModified) {
145: throw new AssertionFailedError("Not implemented");
146: }
147:
148: public void setResponseIsNotModified() {
149: throw new AssertionFailedError("Not implemented");
150: }
151:
152: public void setAttribute(String name, Object value) {
153: attributes.put(name, value);
154: }
155:
156: public Object getAttribute(String name) {
157: return attributes.get(name);
158: }
159:
160: public void removeAttribute(String name) {
161: attributes.remove(name);
162: }
163:
164: public Enumeration getAttributeNames() {
165: return attributes.keys();
166: }
167:
168: public boolean tryResetResponse() throws IOException {
169: throw new AssertionFailedError("Not implemented");
170: }
171:
172: public void commitResponse() throws IOException {
173: throw new AssertionFailedError("Not implemented");
174: }
175:
176: public void startingProcessing() {
177: throw new AssertionFailedError("Not implemented");
178: }
179:
180: public void finishingProcessing() {
181: throw new AssertionFailedError("Not implemented");
182: }
183:
184: public Source resolve(String systemID) throws ProcessingException,
185: SAXException, IOException {
186:
187: throw new AssertionFailedError(
188: "Not not use deprecated methods!");
189: }
190:
191: public void toSAX(org.apache.excalibur.source.Source source,
192: ContentHandler handler) throws SAXException, IOException,
193: ProcessingException {
194:
195: throw new AssertionFailedError(
196: "Not not use deprecated methods!");
197: }
198:
199: public void toSAX(org.apache.excalibur.source.Source source,
200: String mimeTypeHint, ContentHandler handler)
201: throws SAXException, IOException, ProcessingException {
202:
203: throw new AssertionFailedError(
204: "Not not use deprecated methods!");
205: }
206:
207: public org.apache.excalibur.source.Source resolveURI(String location)
208: throws MalformedURLException, IOException,
209: org.apache.excalibur.source.SourceException {
210:
211: return resolver.resolveURI(location);
212: }
213:
214: public org.apache.excalibur.source.Source resolveURI(
215: String location, String base, Map parameters)
216: throws MalformedURLException, IOException,
217: org.apache.excalibur.source.SourceException {
218:
219: return resolver.resolveURI(location, base, parameters);
220: }
221:
222: /**
223: * Releases a resolved resource
224: */
225: public void release(org.apache.excalibur.source.Source source) {
226: resolver.release(source);
227: }
228:
229: /**
230: * Always return <code>true</code>.
231: */
232: public boolean isExternal() {
233: return true;
234: }
235:
236: /* (non-Javadoc)
237: * @see org.apache.cocoon.environment.Environment#isInternRedirect()
238: */
239: public boolean isInternalRedirect() {
240: return false;
241: }
242: }
|