KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.MalformedURLException JavaDoc;
19 import java.net.URL JavaDoc;
20 import java.util.Enumeration JavaDoc;
21 import java.util.Hashtable JavaDoc;
22 import java.io.InputStream JavaDoc;
23
24 import org.apache.cocoon.environment.Context;
25
26 public class MockContext implements Context {
27
28     private Hashtable JavaDoc attributes = new Hashtable JavaDoc();
29     private Hashtable JavaDoc resources = new Hashtable JavaDoc();
30     private Hashtable JavaDoc mappings = new Hashtable JavaDoc();
31     private Hashtable JavaDoc initparameters = new Hashtable JavaDoc();
32
33     public Object JavaDoc getAttribute(String JavaDoc name) {
34         return attributes.get(name);
35     }
36
37     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
38         attributes.put(name, value);
39     }
40
41     public void removeAttribute(String JavaDoc name) {
42         attributes.remove(name);
43     }
44
45     public Enumeration JavaDoc getAttributeNames() {
46         return attributes.keys();
47     }
48
49     public void setResource(String JavaDoc path, URL JavaDoc url) {
50         resources.put(path, url);
51     }
52
53     public URL JavaDoc getResource(String JavaDoc path) throws MalformedURLException JavaDoc {
54         return (URL JavaDoc)resources.get(path);
55     }
56
57     public String JavaDoc getRealPath(String JavaDoc path) {
58       return path;
59     }
60
61     public String JavaDoc getMimeType(String JavaDoc file) {
62         return (String JavaDoc)mappings.get(file.substring(file.lastIndexOf(".")+1));
63     }
64
65     public void setInitParameter(String JavaDoc name, String JavaDoc value) {
66         initparameters.put(name, value);
67     }
68
69     public String JavaDoc getInitParameter(String JavaDoc name) {
70         return (String JavaDoc)initparameters.get(name);
71     }
72
73     public InputStream JavaDoc getResourceAsStream(String JavaDoc path) {
74         return null;
75     }
76
77     public void reset() {
78         attributes.clear();
79         resources.clear();
80         mappings.clear();
81         initparameters.clear();
82     }
83 }
84
Popular Tags