Java Code Examples for javax.mvc.engine.ViewEngineContext#getOutputStream()

The following examples show how to use javax.mvc.engine.ViewEngineContext#getOutputStream() . 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: HandlebarsViewEngine.java    From krazo with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: AsciiDocViewEngine.java    From krazo with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: AsciiDocViewEngine.java    From ozark with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: HandlebarsViewEngine.java    From ozark with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: GroovyViewEngine.java    From ozark with Apache License 2.0 5 votes vote down vote up
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 6
Source File: JadeViewEngine.java    From ozark with Apache License 2.0 4 votes vote down vote up
@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 7
Source File: MustacheViewEngine.java    From ozark with Apache License 2.0 4 votes vote down vote up
@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 8
Source File: JetbrickViewEngine.java    From ozark with Apache License 2.0 4 votes vote down vote up
@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 9
Source File: VelocityViewEngine.java    From ozark with Apache License 2.0 4 votes vote down vote up
@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 10
Source File: FreemarkerViewEngine.java    From ozark with Apache License 2.0 4 votes vote down vote up
@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 11
Source File: PebbleViewEngine.java    From ozark with Apache License 2.0 4 votes vote down vote up
@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 12
Source File: JadeViewEngine.java    From krazo with Apache License 2.0 4 votes vote down vote up
@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 13
Source File: MustacheViewEngine.java    From krazo with Apache License 2.0 4 votes vote down vote up
@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 14
Source File: JetbrickViewEngine.java    From krazo with Apache License 2.0 4 votes vote down vote up
@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 15
Source File: VelocityViewEngine.java    From krazo with Apache License 2.0 4 votes vote down vote up
@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 16
Source File: FreemarkerViewEngine.java    From krazo with Apache License 2.0 4 votes vote down vote up
@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 17
Source File: PebbleViewEngine.java    From krazo with Apache License 2.0 4 votes vote down vote up
@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);
    }
}