public void render(JetContext context, JetWriter writer) { render(new JetPageContext(this, context, writer)); }
@Override protected JetTemplate doGetValue(String name) { Resource resource = JetEngine.this.getResource(name); return new JetTemplate(JetEngine.this, resource); } }
/** * 根据一个绝对路径,获取一个模板对象. * * @throws ResourceNotFoundException */ public JetTemplate getTemplate(String name) throws ResourceNotFoundException { name = PathUtils.getStandardizedName(name); JetTemplate template = templateCache.get(name); template.checkLastModified(); return template; }
case precompile: case always: compileAndLoadClass(); break; case auto: if (lastCompiledTimestamp > resource.lastModified()) { try { loadClassFile(); } catch (Throwable e) { compileAndLoadClass(); compileAndLoadClass(); if (resource instanceof SourceCodeResource) { compileAndLoadClass(); } else if (resource instanceof CompiledClassResource) { try { loadClassFile(); } catch (Exception e) { throw ExceptionUtils.uncheck(e);
protected void checkLastModified() { if (reloadable && lastCompiledTimestamp < resource.lastModified()) { synchronized (this) { // double check if (lastCompiledTimestamp < resource.lastModified()) { compileAndLoadClass(); } } } }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding(charsetEncoding); if (response.getContentType() == null) { response.setContentType("text/html; charset=" + charsetEncoding); } String path = RequestUtils.getPathInfo(request); try { JetTemplate template = engine.getTemplate(path); JetWebContext context = new JetWebContext(request, response); template.render(context, response.getOutputStream()); } catch (ResourceNotFoundException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Template not found: " + path); } } }
/** * 直接从源代码中创建一个新的模板对象. * * <p>返回的对象内部没有缓存,每次都会重新进行解析和编译,如果需要缓存,请在外面直接实现。</p> * * @since 1.1.0 */ public JetTemplate createTemplate(String source) { Resource resource = new SourceCodeResource(source); return new JetTemplate(this, resource); }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding(charsetEncoding); if (response.getContentType() == null) { response.setContentType("text/html; charset=" + charsetEncoding); } String path = RequestUtils.getPathInfo(request); try { JetTemplate template = engine.getTemplate(path); JetWebContext context = new JetWebContext(request, response); template.render(context, response.getOutputStream()); } catch (ResourceNotFoundException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Template not found: " + path); } } }
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) resp; response.setCharacterEncoding(charsetEncoding); if (response.getContentType() == null) { response.setContentType("text/html; charset=" + charsetEncoding); } String path = RequestUtils.getPathInfo(request); try { JetTemplate template = engine.getTemplate(path); JetWebContext context = new JetWebContext(request, response); template.render(context, response.getOutputStream()); } catch (ResourceNotFoundException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Template not found: " + path); } }
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) resp; response.setCharacterEncoding(charsetEncoding); if (response.getContentType() == null) { response.setContentType("text/html; charset=" + charsetEncoding); } String path = RequestUtils.getPathInfo(request); try { JetTemplate template = engine.getTemplate(path); JetWebContext context = new JetWebContext(request, response); template.render(context, response.getOutputStream()); } catch (ResourceNotFoundException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Template not found: " + path); } }
@Override protected void doRender(RequestContext ctx, String viewPathName) throws IOException { HttpServletResponse response = ctx.getResponse(); response.setContentType("text/html; charset=" + response.getCharacterEncoding()); JetWebContext context = new JetWebContext(ctx.getRequest(), response, ctx.getModel()); OutputStream out = response.getOutputStream(); JetTemplate template = engine.getTemplate(viewPathName); template.render(context, out); out.flush(); } }
@Override public void render() { JetEngine engine = JetWebEngine.getEngine(); String charsetEncoding = engine.getConfig().getOutputEncoding().name(); response.setCharacterEncoding(charsetEncoding); if (response.getContentType() == null) { response.setContentType("text/html; charset=" + charsetEncoding); } try { JetTemplate template = engine.getTemplate(view); JetWebContext context = new JetWebContext(request, response); template.render(context, response.getOutputStream()); } catch (IOException e) { throw new IllegalStateException(e); } } }
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JetEngine engine = JetWebEngineLoader.getJetEngine(); String charsetEncoding = engine.getConfig().getOutputEncoding(); if (response.getContentType() == null) { response.setContentType("text/html; charset=" + charsetEncoding); } response.setCharacterEncoding(charsetEncoding); String uri = request.getServletPath(); String pathInfo = request.getPathInfo(); if (pathInfo != null && pathInfo.length() > 0) { uri = uri + pathInfo; } try { JetTemplate template = engine.getTemplate(uri); JetContext context = new JetWebContext(request, response); template.render(context, response.getOutputStream()); } catch (ResourceNotFoundException e) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Template not found: " + uri); } } }
@Override public String render(ModelAndView modelAndView) { JetTemplate template = jetEngine.getTemplate(modelAndView.getViewName()); Object model = modelAndView.getModel(); if (model instanceof Map) { Map<String, Object> modelMap = (Map<String, Object>) model; JetContext context = new JetContext(modelMap.size()); context.putAll(modelMap); StringWriter writer = new StringWriter(); template.render(context, writer); return writer.toString(); } else { throw new IllegalArgumentException("modelAndView.getModel() must return a java.util.Map"); } }
@Override protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { JetWebContext context = new JetWebContext(request, response, model); JetTemplate template = JetWebEngine.getEngine().getTemplate(getUrl()); template.render(context, response.getOutputStream()); }
@Override protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { JetWebContext context = new JetWebContext(request, response, model); JetTemplate template = JetWebEngine.getEngine().getTemplate(getUrl()); template.render(context, response.getOutputStream()); }
public void render(Map<String, Object> context, Writer out) { JetContext ctx = new JetContext(context); JetWriter writer = JetWriter.create(out, encoding); render(new JetPageContext(this, ctx, writer)); }
public void render(Map<String, Object> context, OutputStream out) { JetContext ctx = new JetContext(context); JetWriter writer = JetWriter.create(out, encoding); render(new JetPageContext(this, ctx, writer)); }
@Override protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { JetContext context = new JetWebContext(request, response, model); JetTemplate template = JetWebEngineLoader.getJetEngine().getTemplate(getUrl()); template.render(context, response.getOutputStream()); }
@Override protected void renderView(ActionRequest actionRequest, String path) throws Exception { final HttpServletRequest request = actionRequest.getHttpServletRequest(); final HttpServletResponse response = actionRequest.getHttpServletResponse(); JetEngine engine = JetWebEngine.getEngine(); response.setCharacterEncoding(engine.getConfig().getOutputEncoding().name()); if (contentType != null) { response.setContentType(contentType); } JetTemplate template = engine.getTemplate(path); JetWebContext context = new JetWebContext(request, response); template.render(context, response.getOutputStream()); } }