public PageContext getPageContext() { return parentCanvas.getPageContext(); } public String nextId() { return parentCanvas.nextId(); }
/** * @param html * @return a ContextMap to access the parameters of the inbound Http request. */ public static ContextMap getParameters(HtmlCanvas html) { return html.getPageContext().getContextMap(PageContext.REQUEST_PARAMETERS); } /**
/** * Return the full undecoded URL. * @param html * @return */ public static String getRequestURLAndQuery(HtmlCanvas html) { return html.getPageContext().getString(PageContext.REQUEST_URIQ); } }
/** * * @param html * @return a ContextMap to access the Cookies passed in by the inbound Http request. */ public static ContextMap getCookies(HtmlCanvas html) { return html.getPageContext().getContextMap(PageContext.REQUEST_COOKIES); } /**
/** * * @param html * @return the actual path of the inbound Http request. */ public static String getPath(HtmlCanvas html) { return html.getPageContext().getString(PageContext.REQUEST_PATH); } /**
/** * * @param html * @return a ContextMap to access the session associated to the inbound request. */ public static ContextMap getSession(HtmlCanvas html) { return html.getPageContext().getContextMap(PageContext.SESSION); } /**
/** * use RequestUtils.getPathParameters(html) instead. * @return */ @Deprecated public ContextMap getPathParameters() { return this.getPageContext().getContextMap(PageContext.REQUEST_PATH); } /**
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { HtmlCanvas html = HtmlCanvasFactory.createCanvas(request, response, response.getWriter()); HtmlCanvasArgumentResolver.setupPageContext(request, html.getPageContext()); html.getPageContext().attributes.putAll(model); html.render(component); } }
/** * * @param html * @param name * @return aString | null which is the value of a header of the inbound Http request. */ public static String getHeaderValue(HtmlCanvas html, String name) { ContextMap map = html.getPageContext().getContextMap(PageContext.REQUEST_HEADERS); if (null == map) return null; return map.getString(name); } /**
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception { // only accept HtmlCanvas typed parameter if (methodParameter.getParameterType() != HtmlCanvas.class) return UNRESOLVED; HttpServletRequest request = (HttpServletRequest)(webRequest.getNativeRequest()); HttpServletResponse response = (HttpServletResponse)(webRequest.getNativeResponse()); response.setContentType("text/html"); // controllers may override this final HtmlCanvas canvas = HtmlCanvasFactory.createCanvas(request,response,response.getWriter()); setupPageContext(request, canvas.getPageContext()); return canvas; }
public void renderOn(HtmlCanvas html) throws IOException {// @formatter:off // no need to inspect an exception if (target instanceof RenderException) { target.renderOn(html); return; } html .div(class_("rendersnake-inspector")) .write(target.getClass().getName()); html.getPageContext().renderForInpectorOn(this,html); target.renderOn(html); html._div(); } // @formatter:on
/** * Dispatch an incoming request to a Renderable component * by looking for a named component that matches the path. */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uri = request.getPathInfo(); Renderable component = this.dispatchMap.get(uri); if (component == null) { response.sendError(404); } else { HtmlCanvas canvas = HtmlCanvasFactory.createCanvas(request,response,response.getWriter()); PageContext context = canvas.getPageContext(); String q = request.getQueryString(); context.withObject(PageContext.REQUEST_PATH, request.getPathTranslated()); context.withObject(PageContext.REQUEST_URIQ, request.getRequestURI() + (q == null ? "" : "?" + q)); context.withObject(PageContext.SESSION, new SessionAttributesMap(request)); context.withObject(PageContext.REQUEST_PARAMETERS, new RequestParametersMap(request)); context.withObject(PageContext.REQUEST_HEADERS, new RequestHeadersMap(request)); canvas.render(component); } }
/** * Render the receiver on a html to provide debugging information about the exception. */ public void renderOn(HtmlCanvas html) throws IOException { html.div(style("color:red")); if (isEmptyStack) { html.write("[Render Error] unexpected close()"); return; } if (expectedTag != null) { // tag mismatch html.write(String.format("[Render Error] expected [%s] actual [%s]", expectedTag, closingTag)); } if (exception != null) { // general error html.write(String.format("[Render Error] general exception [%s]", exception.getMessage())); } // if debugging, the error component is available Renderable errorComponent = (Renderable)(html.getPageContext().getObject("renderable.error")); if (errorComponent != null) { html.write(" in ").write(errorComponent.getClass().getName()); } else { html.a(href("?inspect")).write(" Inspect details")._a(); this.renderStackTraceOn(html); } html._div(); } /**