<%{%>
<%!
private static java.util.regex.Pattern URL_DIR_PATTERN =
java.util.regex.Pattern.compile("(/.*?)(/[^./]++[.]jsp)?+");
private static void includeFile(final javax.servlet.jsp.JspWriter out,
final javax.servlet.http.HttpServletRequest request,
final javax.servlet.ServletContext c,
final String path)
throws Exception{
try{
Class resourcesClass = null;
try{
resourcesClass =
Class.forName("com.mini.jasper.util.Resources");
}
catch(final ClassNotFoundException e){
resourcesClass = null;
}
if(resourcesClass == null){
// doesen't work: in = c.getResourceAsStream(abs + path);
// doesen't work: in = c.getClass().getClassLoader().getResourceAsStream(abs + path);
out.write("<" + "!--#include virtual=\"");
out.write(path);
out.write("\" --" + ">");
return;
}
final String servletPath = request.getServletPath();
final java.util.regex.Matcher matcher =
URL_DIR_PATTERN.matcher(servletPath);
if(!matcher.matches()){
throw new IllegalStateException("Can't determine directory from JSP servlet path " + servletPath);
}
final String absPath = matcher.group(1) + "/" + path;
final java.lang.reflect.Method getResourceAsStream =
resourcesClass.getMethod("getResourceAsStream",
new Class[]{ javax.servlet.ServletContext.class, String.class });
final java.io.InputStream in =
(java.io.InputStream)getResourceAsStream.invoke(null,
new Object[]{c, absPath});
if(in == null){
throw new java.io.IOException("No such resource: "
+ absPath);
}
final java.io.Reader r =
new java.io.InputStreamReader(in, "UTF-8");
try{
/*
* MTU at BMW should be around 1500 bytes. so we can
* fetch around 1kb of data per read. but not 1.5k as
* we leave a little bit for the network protocols.
*/
final char[] buffer = new char[1200];
int len;
while((len = r.read(buffer)) >= 0){
out.write(buffer, 0, len);
}
}
finally{
try{
r.close();
}
catch(final java.io.IOException e){
/*
* maybe the reader was alredy broken before
* the close()
*/
}
}
}
catch(final Throwable t){
throw new RuntimeException("Can't include resource "
+ path, t);
}
}
%>
<%}%>