javax.mvc.engine.ViewEngineException Java Examples
The following examples show how to use
javax.mvc.engine.ViewEngineException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ViewEngineJspImpl.java From portals-pluto with Apache License 2.0 | 6 votes |
@Override public void processView(ViewEngineContext viewEngineContext) throws ViewEngineException { String view = viewEngineContext.getView(); String viewFolder = (String) configuration.getProperty(ViewEngine.VIEW_FOLDER); if (viewFolder == null) { viewFolder = ViewEngine.DEFAULT_VIEW_FOLDER; } String viewPath = viewFolder.concat(view); PortletRequestDispatcher requestDispatcher = portletContext.getRequestDispatcher(viewPath); try { requestDispatcher.include(viewEngineContext.getRequest(PortletRequest.class), viewEngineContext.getResponse(PortletResponse.class)); } catch (Exception e) { throw new ViewEngineException(e); } }
Example #2
Source File: HandlebarsViewEngine.java From krazo with Apache License 2.0 | 6 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { handlebars.with(new ServletContextTemplateLoader(servletContext, getViewFolder(context))); Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset); InputStream resourceAsStream = servletContext.getResourceAsStream(resolveView(context)); InputStreamReader in = new InputStreamReader(resourceAsStream, "UTF-8"); BufferedReader bufferedReader = new BufferedReader(in);) { String viewContent = bufferedReader.lines().collect(Collectors.joining()); Template template = handlebars.compileInline(viewContent); template.apply(model, writer); } catch (IOException e) { throw new ViewEngineException(e); } }
Example #3
Source File: ThymeleafViewEngine.java From ozark with Apache License 2.0 | 6 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { try { HttpServletRequest request = context.getRequest(HttpServletRequest.class); HttpServletResponse response = context.getResponse(HttpServletResponse.class); CDIWebContext ctx = new CDIWebContext(beanManager, request, response, servletContext, context.getLocale()); Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", request); ctx.setVariables(model); try { engine.process(resolveView(context), ctx, response.getWriter()); response.flushBuffer(); } finally { ctx.close(); } } catch (IOException e) { throw new ViewEngineException(e); } }
Example #4
Source File: AsciiDocViewEngine.java From ozark with Apache License 2.0 | 6 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset); InputStream is = servletContext.getResourceAsStream(resolveView(context)); InputStreamReader isr = new InputStreamReader(is, "UTF-8"); BufferedReader reader = new BufferedReader(isr)) { Options options = new Options(); options.setAttributes(new HashMap<>(context.getModels().asMap())); asciidoctor.convert(reader, writer, options); } catch (IOException e) { throw new ViewEngineException(e); } }
Example #5
Source File: AsciiDocViewEngine.java From krazo with Apache License 2.0 | 6 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset); InputStream is = servletContext.getResourceAsStream(resolveView(context)); InputStreamReader isr = new InputStreamReader(is, "UTF-8"); BufferedReader reader = new BufferedReader(isr)) { Options options = new Options(); options.setAttributes(new HashMap<>(context.getModels().asMap())); asciidoctor.convert(reader, writer, options); } catch (IOException e) { throw new ViewEngineException(e); } }
Example #6
Source File: HandlebarsViewEngine.java From ozark with Apache License 2.0 | 6 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset); InputStream resourceAsStream = servletContext.getResourceAsStream(resolveView(context)); InputStreamReader in = new InputStreamReader(resourceAsStream, "UTF-8"); BufferedReader bufferedReader = new BufferedReader(in);) { String viewContent = bufferedReader.lines().collect(Collectors.joining()); Template template = handlebars.compileInline(viewContent); template.apply(model, writer); } catch (IOException e) { throw new ViewEngineException(e); } }
Example #7
Source File: ThymeleafViewEngine.java From krazo with Apache License 2.0 | 6 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { try { HttpServletRequest request = context.getRequest(HttpServletRequest.class); HttpServletResponse response = context.getResponse(HttpServletResponse.class); CDIWebContext ctx = new CDIWebContext(beanManager, request, response, servletContext, context.getLocale()); Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", request); ctx.setVariables(model); try { engine.process(resolveView(context), ctx, response.getWriter()); response.flushBuffer(); } finally { ctx.close(); } } catch (IOException e) { throw new ViewEngineException(e); } }
Example #8
Source File: TrimouViewEngine.java From trimou with Apache License 2.0 | 5 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { try { Models models = context.getModels(); models.put("request", context.getRequest()); models.put("locale", context.getRequest().getLocale()); Writer writer = context.getResponse().getWriter(); engine.getMustache(context.getView()).render(writer, models); writer.flush(); } catch (IOException e) { throw new ViewEngineException(e); } }
Example #9
Source File: ThymeleafViewEngine.java From generator-jvm with MIT License | 5 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Try.run(() -> { final HttpServletRequest request = context.getRequest(); final HttpServletResponse response = context.getResponse(); final WebContext webContext = new WebContext(request, response, servletContext, request.getLocale()); webContext.setVariables(context.getModels()); request.setAttribute("view", context.getView()); engine.process(/*layout*/ "default", webContext, response.getWriter()); }).getOrElseThrow(ViewEngineException::new); }
Example #10
Source File: ViewEngineProducer.java From portals-pluto with Apache License 2.0 | 5 votes |
@Bean @Scope(proxyMode = ScopedProxyMode.INTERFACES, value = "portletRequest") public ViewEngine getViewEngine(TemplateEngineSupplier templateEngineSupplier, IWebContext webContext) { return new ThymeleafViewEngine(templateEngineSupplier.get(), webContext, viewEngineContext -> { MimeResponse mimeResponse = viewEngineContext.getResponse(MimeResponse.class); try { return mimeResponse.getWriter(); } catch (IOException e) { throw new ViewEngineException(e); } }); }
Example #11
Source File: ViewEngineProducer.java From portals-pluto with Apache License 2.0 | 5 votes |
@PortletRequestScoped @Produces public ViewEngine getTimeleafViewEngine(TemplateEngineSupplier templateEngineSupplier, IWebContext webContext) { return new ThymeleafViewEngine(templateEngineSupplier.get(), webContext, viewEngineContext -> { MimeResponse mimeResponse = viewEngineContext.getResponse(MimeResponse.class); try { return mimeResponse.getWriter(); } catch (IOException e) { throw new ViewEngineException(e); } }); }
Example #12
Source File: GroovyViewEngine.java From ozark with Apache License 2.0 | 5 votes |
public void processView(ViewEngineContext context) throws ViewEngineException { Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset); InputStream resourceAsStream = servletContext.getResourceAsStream(resolveView(context)); InputStreamReader in = new InputStreamReader(resourceAsStream, "UTF-8");) { Template template = markupTemplateEngine.createTemplate(in); Writable output = template.make(model); output.writeTo(writer); } catch (IOException | CompilationFailedException | ClassNotFoundException e) { throw new ViewEngineException(e); } }
Example #13
Source File: FaceletsViewEngine.java From ozark with Apache License 2.0 | 5 votes |
/** * Forwards request to servlet container. * * @param context view engine context. * @throws ViewEngineException if any error occurs. */ @Override public void processView(ViewEngineContext context) throws ViewEngineException { try { forwardRequest(context, "*.xhtml"); } catch (ServletException | IOException e) { throw new ViewEngineException(e); } }
Example #14
Source File: JspViewEngine.java From ozark with Apache License 2.0 | 5 votes |
/** * Forwards request to servlet container. * * @param context view engine context. * @throws ViewEngineException if any error occurs. */ @Override public void processView(ViewEngineContext context) throws ViewEngineException { try { forwardRequest(context, "*.jsp", "*.jspx"); } catch (ServletException | IOException e) { throw new ViewEngineException(e); } }
Example #15
Source File: JspViewEngine.java From krazo with Apache License 2.0 | 5 votes |
/** * Forwards request to servlet container. * * @param context view engine context. * @throws ViewEngineException if any error occurs. */ @Override public void processView(ViewEngineContext context) throws ViewEngineException { try { forwardRequest(context, "*.jsp", "*.jspx"); } catch (ServletException | IOException e) { throw new ViewEngineException(e); } }
Example #16
Source File: FaceletsViewEngine.java From krazo with Apache License 2.0 | 5 votes |
/** * Forwards request to servlet container. * * @param context view engine context. * @throws ViewEngineException if any error occurs. */ @Override public void processView(ViewEngineContext context) throws ViewEngineException { try { forwardRequest(context, "*.xhtml"); } catch (ServletException | IOException e) { throw new ViewEngineException(e); } }
Example #17
Source File: PebbleViewEngine.java From krazo with Apache License 2.0 | 4 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset)) { PebbleTemplate template = pebbleEngine.getTemplate(resolveView(context)); Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); template.evaluate(writer, model); } catch (PebbleException | IOException ex) { throw new ViewEngineException(String.format("Could not process view %s.", context.getView()), ex); } }
Example #18
Source File: ViewRendererMvcImpl.java From portals-pluto with Apache License 2.0 | 4 votes |
@Override public void render(PortletRequest portletRequest, MimeResponse mimeResponse, PortletConfig portletConfig) throws PortletException { Map<String, Object> modelMap = models.asMap(); for (Map.Entry<String, Object> entry : modelMap.entrySet()) { portletRequest.setAttribute(entry.getKey(), entry.getValue()); } String viewName = (String) portletRequest.getAttribute(VIEW_NAME); if (viewName != null) { if (!viewName.contains(".")) { String defaultViewExtension = (String) configuration.getProperty( ConfigurationImpl.DEFAULT_VIEW_EXTENSION); viewName = viewName.concat(".").concat(defaultViewExtension); } ViewEngine supportingViewEngine = null; for (ViewEngine viewEngine : viewEngines) { if (viewEngine.supports(viewName)) { supportingViewEngine = viewEngine; break; } } if (supportingViewEngine == null) { throw new PortletException(new ViewEngineException("No ViewEngine found that supports " + viewName)); } try { beanManager.fireEvent(new BeforeProcessViewEventImpl(viewName, supportingViewEngine.getClass())); supportingViewEngine.processView(new ViewEngineContextImpl(configuration, portletRequest, mimeResponse, models, portletRequest.getLocale())); beanManager.fireEvent(new AfterProcessViewEventImpl(viewName, supportingViewEngine.getClass())); } catch (ViewEngineException vee) { throw new PortletException(vee); } } if ((mutableBindingResult != null) && !mutableBindingResult.isConsulted()) { Set<ParamError> allErrors = mutableBindingResult.getAllErrors(); for (ParamError paramError : allErrors) { if (LOG.isWarnEnabled()) { LOG.warn("BindingResult error not processed for " + paramError.getParamName() + ": " + paramError.getMessage()); } } } }
Example #19
Source File: ThymeleafViewEngine.java From portals-pluto with Apache License 2.0 | 4 votes |
@Override public void processView(ViewEngineContext viewEngineContext) throws ViewEngineException { templateEngine.process(viewEngineContext.getView(), webContext, writerSupplier.get(viewEngineContext)); }
Example #20
Source File: ViewableWriter.java From krazo with Apache License 2.0 | 4 votes |
/** * Searches for a suitable {@link javax.mvc.engine.ViewEngine} to process the view. If no engine * is found, is forwards the request back to the servlet container. */ @Override public void writeTo(Viewable viewable, Class<?> aClass, Type type, Annotation[] annotations, MediaType resolvedMediaType, MultivaluedMap<String, Object> headers, OutputStream out) throws IOException, WebApplicationException { // Find engine for this Viewable final ViewEngine engine = engineFinder.find(viewable); if (engine == null) { throw new ServerErrorException(messages.get("NoViewEngine", viewable), INTERNAL_SERVER_ERROR); } // build the full media type (including the charset) and make sure the response header is set correctly MediaType mediaType = buildMediaTypeWithCharset(resolvedMediaType); headers.putSingle(HttpHeaders.CONTENT_TYPE, mediaType); HttpServletRequest request = unwrapOriginalRequest(injectedRequest); HttpServletResponse response = unwrapOriginalResponse(injectedResponse); // Create wrapper for response final ServletOutputStream responseStream = new DelegatingServletOutputStream(out); final HttpServletResponse responseWrapper = new MvcHttpServletResponse(response, responseStream, mediaType, headers); // Pass request to view engine try { // If no models in viewable, inject via CDI Models models = viewable.getModels(); if (models == null) { models = modelsInstance.get(); } // Bind EL 'mvc' object in models models.put("mvc", mvc); // Execute the view engine eventDispatcher.fireBeforeProcessViewEvent(engine, viewable); try { // Process view using selected engine engine.processView(new ViewEngineContextImpl(viewable.getView(), models, request, responseWrapper, headers, responseStream, mediaType, uriInfo, resourceInfo, config, mvc.getLocale())); } finally { eventDispatcher.fireAfterProcessViewEvent(engine, viewable); } } catch (ViewEngineException e) { throw new ServerErrorException(INTERNAL_SERVER_ERROR, e); } finally { responseWrapper.getWriter().flush(); } }
Example #21
Source File: JadeViewEngine.java From ozark with Apache License 2.0 | 4 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset)) { JadeTemplate template = jade.getTemplate(resolveView(context)); Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); jade.renderTemplate(template, model, writer); } catch (JadeException | IOException ex) { throw new ViewEngineException(String.format("Could not process view %s.", context.getView()), ex); } }
Example #22
Source File: MustacheViewEngine.java From ozark with Apache License 2.0 | 4 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset)) { Mustache mustache = factory.compile(resolveView(context)); Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); mustache.execute(writer, model).flush(); } catch (IOException e) { throw new ViewEngineException(e); } }
Example #23
Source File: JetbrickViewEngine.java From ozark with Apache License 2.0 | 4 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset)) { JetTemplate template = jetEngine.getTemplate(resolveView(context)); Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); template.render(model, writer); } catch (TemplateException | IOException e) { throw new ViewEngineException(e); } }
Example #24
Source File: JadeViewEngine.java From krazo with Apache License 2.0 | 4 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset)) { JadeTemplate template = jade.getTemplate(resolveView(context)); Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); jade.renderTemplate(template, model, writer); } catch (JadeException | IOException ex) { throw new ViewEngineException(String.format("Could not process view %s.", context.getView()), ex); } }
Example #25
Source File: VelocityViewEngine.java From ozark with Apache License 2.0 | 4 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset)) { Template template = velocityEngine.getTemplate(resolveView(context)); Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); VelocityContext velocityContext = new VelocityContext(model); template.merge(velocityContext, writer); } catch (IOException e) { throw new ViewEngineException(e); } }
Example #26
Source File: JtwigViewEngine.java From krazo with Apache License 2.0 | 4 votes |
public void processView(ViewEngineContext context) throws ViewEngineException { try { Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); HttpServletRequest request = context.getRequest(HttpServletRequest.class); HttpServletResponse response = context.getResponse(HttpServletResponse.class); jtwigRenderer.dispatcherFor(resolveView(context)).with(model).render(request,response); } catch (ServletException | IOException e) { throw new ViewEngineException(e); } }
Example #27
Source File: FreemarkerViewEngine.java From krazo with Apache License 2.0 | 4 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset)) { Template template = configuration.getTemplate(resolveView(context)); Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); template.process(model, writer); } catch (TemplateException | IOException e) { throw new ViewEngineException(e); } }
Example #28
Source File: FreemarkerViewEngine.java From ozark with Apache License 2.0 | 4 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Charset charset = resolveCharsetAndSetContentType(context); try (Writer writer = new OutputStreamWriter(context.getOutputStream(), charset)) { Template template = configuration.getTemplate(resolveView(context)); Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); template.process(model, writer); } catch (TemplateException | IOException e) { throw new ViewEngineException(e); } }
Example #29
Source File: JtwigViewEngine.java From ozark with Apache License 2.0 | 4 votes |
public void processView(ViewEngineContext context) throws ViewEngineException { try { Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); HttpServletRequest request = context.getRequest(HttpServletRequest.class); HttpServletResponse response = context.getResponse(HttpServletResponse.class); jtwigRenderer.dispatcherFor(resolveView(context)).with(model).render(request,response); } catch (ServletException | IOException e) { throw new ViewEngineException(e); } }
Example #30
Source File: PebbleViewEngine.java From ozark with Apache License 2.0 | 4 votes |
@Override public void processView(ViewEngineContext context) throws ViewEngineException { Charset charset = resolveCharsetAndSetContentType(context); try(Writer writer = new OutputStreamWriter(context.getOutputStream(), charset)) { PebbleTemplate template = pebbleEngine.getTemplate(resolveView(context)); Map<String, Object> model = new HashMap<>(context.getModels().asMap()); model.put("request", context.getRequest(HttpServletRequest.class)); template.evaluate(writer, model); } catch (PebbleException | IOException ex) { throw new ViewEngineException(String.format("Could not process view %s.", context.getView()), ex); } }