}
String target = URLDecoder.decode(request.getRequestLine().getUri(), "UTF-8");
if(target.endsWith(".jhtml")) {
if(velocityOK) {
Template template = templateCache.get(target);
if(template == null) {
try {
String vmFileName = target.replace(".jhtml", ".vm").replace("/", "\\").substring(1);
final File file = new File(this.docRoot, target.replace(".jhtml", ".vm"));
if(!file.exists()) {
response.setStatusCode(HttpStatus.SC_NOT_FOUND);
NStringEntity entity = new NStringEntity(
"<html><body><h1>File" + file.getPath() +
" not found</h1></body></html>",
ContentType.create("text/html", "UTF-8"));
response.setEntity(entity);
System.out.println("File " + file.getPath() + " not found");
} else {
template = Velocity.getTemplate(vmFileName, templateEncode);
//
templateCache.putIfAbsent(target, template);
}
} catch (Exception e) {
logger.error("Exception: get template", e);
}
}
// 渲染VM
VelocityContext cxt = new VelocityContext();
monitor.getData(cxt);
Writer writer = new StringWriter();
template.merge(cxt, writer);
response.setStatusCode(HttpStatus.SC_OK);
NStringEntity entity = new NStringEntity(writer.toString(), ContentType.create("text/html", "UTF-8"));
response.setEntity(entity);
} else {
response.setStatusCode(HttpStatus.SC_NOT_FOUND);