01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.environment.mock;
18:
19: import java.net.MalformedURLException;
20: import java.net.URL;
21: import java.util.Enumeration;
22: import java.util.Hashtable;
23: import java.io.InputStream;
24:
25: import org.apache.cocoon.environment.Context;
26:
27: public class MockContext implements Context {
28:
29: private Hashtable attributes = new Hashtable();
30: private Hashtable resources = new Hashtable();
31: private Hashtable mappings = new Hashtable();
32: private Hashtable initparameters = new Hashtable();
33:
34: public Object getAttribute(String name) {
35: return attributes.get(name);
36: }
37:
38: public void setAttribute(String name, Object value) {
39: attributes.put(name, value);
40: }
41:
42: public void removeAttribute(String name) {
43: attributes.remove(name);
44: }
45:
46: public Enumeration getAttributeNames() {
47: return attributes.keys();
48: }
49:
50: public void setResource(String path, URL url) {
51: resources.put(path, url);
52: }
53:
54: public URL getResource(String path) throws MalformedURLException {
55: return (URL) resources.get(path);
56: }
57:
58: public String getRealPath(String path) {
59: return path;
60: }
61:
62: public String getMimeType(String file) {
63: return (String) mappings.get(file.substring(file
64: .lastIndexOf(".") + 1));
65: }
66:
67: public void setInitParameter(String name, String value) {
68: initparameters.put(name, value);
69: }
70:
71: public String getInitParameter(String name) {
72: return (String) initparameters.get(name);
73: }
74:
75: public InputStream getResourceAsStream(String path) {
76: return null;
77: }
78:
79: public void reset() {
80: attributes.clear();
81: resources.clear();
82: mappings.clear();
83: initparameters.clear();
84: }
85: }
|