
cat.inspiracio.servlet.http.SetServletContext Maven / Gradle / Ivy
/*
Copyright 2016 Alexander Bunkenburg
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cat.inspiracio.servlet.http;
import java.io.InputStream;
import java.io.StringBufferInputStream;
import java.util.HashMap;
import java.util.Map;
/** A simulation of servlet context with settable resources. */
public class SetServletContext extends InitialServletContext {
// state -------------------------------------------
/** Path to resource */
private Mapresources=new HashMap();
private String contextPath="";
// lifecycle ---------------------------------------
public SetServletContext(){}
// override methods --------------------------------
public SetServletContext setResource(String path, String resource){
resources.put(path, resource);
return this;
}
@Override public InputStream getResourceAsStream(String path){
String r=resources.get(path);
if(r==null)
return null;
InputStream in=new StringBufferInputStream(r);
return in;
}
public SetServletContext setContextPath(String path){contextPath=path;return this;}
@Override public String getContextPath(){return contextPath;}
@Override public void log(String msg){System.out.println(msg);}
@Override public void log(Exception exception, String msg){log(msg + "\n" + exception);}
@Override public void log(String message, Throwable throwable){log(message + "\n" + throwable);}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy