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