1 16 package org.apache.cocoon.environment.mock; 17 18 import java.io.ByteArrayOutputStream ; 19 import java.io.IOException ; 20 import java.io.OutputStream ; 21 import java.net.MalformedURLException ; 22 import java.util.Enumeration ; 23 import java.util.HashMap ; 24 import java.util.Hashtable ; 25 import java.util.Map ; 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 ; 34 import org.xml.sax.SAXException ; 35 36 public class MockEnvironment implements Environment { 37 38 private SourceResolver resolver; 39 40 private String uri; 41 private String uriprefix; 42 private String rootcontext; 43 private String context; 44 private String view; 45 private String action; 46 private String contenttype; 47 private int contentlength; 48 private int status; 49 private ByteArrayOutputStream outputstream; 50 private HashMap objectmodel; 51 private Hashtable attributes = new Hashtable (); 52 53 public MockEnvironment(SourceResolver resolver) { 54 this.resolver = resolver; 55 } 56 57 public String getURI() { 58 return uri; 59 } 60 61 public String getURIPrefix() { 62 return uriprefix; 63 } 64 65 public String getRootContext() { 66 return rootcontext; 67 } 68 69 public String getContext() { 70 return context; 71 } 72 73 public String getView() { 74 return view; 75 } 76 77 public String getAction() { 78 return action; 79 } 80 81 public void setContext(String prefix, String uri, String context) { 82 throw new AssertionFailedError("Not implemented"); 83 } 84 85 public void changeContext(String uriprefix, String context) throws Exception { 86 throw new AssertionFailedError("Not implemented"); 87 } 88 89 public void redirect(boolean sessionmode, String url) throws IOException { 90 throw new AssertionFailedError("Use Redirector.redirect instead!"); 91 } 92 93 public void setContentType(String contenttype) { 94 this.contenttype = contenttype; 95 } 96 97 public String 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 getOutputStream() throws IOException { 118 outputstream = new ByteArrayOutputStream (); 119 return outputstream; 120 } 121 122 public OutputStream getOutputStream(int bufferSize) throws IOException { 123 outputstream = new ByteArrayOutputStream (); 124 return outputstream; 125 } 126 127 public byte[] getOutput() { 128 return outputstream.toByteArray(); 129 } 130 131 public Map 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 name, Object value) { 144 attributes.put(name, value); 145 } 146 147 public Object getAttribute(String name) { 148 return attributes.get(name); 149 } 150 151 public void removeAttribute(String name) { 152 attributes.remove(name); 153 } 154 155 public Enumeration getAttributeNames() { 156 return attributes.keys(); 157 } 158 159 public boolean tryResetResponse() throws IOException { 160 throw new AssertionFailedError("Not implemented"); 161 } 162 163 public void commitResponse() throws IOException { 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 systemID) 177 throws ProcessingException, SAXException , IOException { 178 179 throw new AssertionFailedError("Not not use deprecated methods!"); 180 } 181 182 public void toSAX(org.apache.excalibur.source.Source source, 183 ContentHandler handler) 184 throws SAXException , IOException , 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 mimeTypeHint, 191 ContentHandler handler) 192 throws SAXException , IOException , ProcessingException { 193 194 throw new AssertionFailedError("Not not use deprecated methods!"); 195 } 196 197 public org.apache.excalibur.source.Source resolveURI(String location) 198 throws MalformedURLException , IOException , org.apache.excalibur.source.SourceException { 199 200 return resolver.resolveURI(location); 201 } 202 203 public org.apache.excalibur.source.Source resolveURI(String location, 204 String base, 205 Map parameters) 206 throws MalformedURLException , IOException , org.apache.excalibur.source.SourceException { 207 208 return resolver.resolveURI(location, base, parameters); 209 } 210 211 214 public void release(org.apache.excalibur.source.Source source) { 215 resolver.release(source); 216 } 217 218 221 public boolean isExternal() { 222 return true; 223 } 224 225 228 public boolean isInternalRedirect() { 229 return false; 230 } 231 } 232 233 | Popular Tags |