-
- ToadletContext toadletContext = request.getToadletContext();
- PageMaker pageMaker = toadletContext.getPageMaker();
- PageNode pageNode = pageMaker.getPageNode(l10n.getString(pageTitleKey), toadletContext);
- for (String styleSheet : getStyleSheets()) {
- pageNode.addCustomStyleSheet(styleSheet);
- }
-
- processTemplate(request, template);
- StringWriter stringWriter = new StringWriter();
- template.render(stringWriter);
- pageNode.content.addChild("%", stringWriter.toString());
-
- return new Response(200, "OK", "text/html", pageNode.outer.generate());
- }
-
- /**
- * Can be overridden to return a custom set of style sheets that are to be
- * included in the page’s header.
- *
- * @return Additional style sheets to load
- */
- protected Collection<String> getStyleSheets() {
- return Collections.emptySet();
- }
-
- /**
- * Can be overridden when extending classes need to set variables in the
- * template before it is rendered.
- *
- * @param request
- * The request that is rendered
- * @param template
- * The template to set variables in
- */
- protected void processTemplate(Request request, Template template) {
- /* do nothing. */
- }
-
- /**
- * Can be overridden to redirect the user to a different page, in case a log
- * in is required, or something else is wrong.
- *
- * @param request
- * The request that is processed
- * @return The URL to redirect to, or {@code null} to not redirect
- */
- protected String getRedirectTarget(Page.Request request) {
- return null;
+ ByteArrayInputStream responseInputStream = new ByteArrayInputStream(responseOutputStream.toByteArray());
+ /* no need to close a ByteArrayInputStream. */
+ return new Response(200, "OK", contentType, null, responseInputStream);