@Override public String render(ModelAndView modelAndView) { Template template = velocityEngine.getTemplate(provider.layout(), "utf-8"); Object model = modelAndView.getModel(); if (model == null) { model = Collections.emptyMap(); } if (model instanceof Map) { VelocityContext context = initialContextProvider.getVelocityContext((Map) model, controller, modelAndView.getViewName()); StringWriter writer = new StringWriter(); template.merge(context, writer); Object meta = context.get("meta"); context.put("meta", GSON.toJson(meta)); return writer.toString(); } else { throw new IllegalArgumentException("modelAndView must be of type java.util.Map"); } } }
/** * Creates a new ModelAndView object with given arguments. * * @param model object. * @param viewName t be rendered. * @return object with model and view set. */ public ModelAndView modelAndView(Object model, String viewName) { return new ModelAndView(model, viewName); }
@Override public final Object handle(Request request, Response response) throws Exception { ModelAndView modelAndView = doHandle(request, response); response.status(200); if (shouldReturnHtml(request)) { response.type("text/html"); return mustacheTemplateEngine.render(modelAndView); } else { response.type("application/json"); return objectMapper.writeValueAsString(modelAndView.getModel()); } }
/** * {@inheritDoc} */ @Override public String render(ModelAndView modelAndView) { try { StringWriter stringWriter = new StringWriter(); Template template = configuration.getTemplate(modelAndView.getViewName()); template.process(modelAndView.getModel(), stringWriter); return stringWriter.toString(); } catch (IOException | TemplateException e) { throw new IllegalArgumentException(e); } }
/** * Constructs a ModelAndView with the provided model and view name * * @param model the model * @param viewName the view name * @return the model and view */ public static ModelAndView modelAndView(Object model, String viewName) { return new ModelAndView(model, viewName); }
@Override public String render(ModelAndView modelAndView) { try { StringWriter stringWriter = new StringWriter(); Template template = configuration.getTemplate(modelAndView.getViewName()); template.process(modelAndView.getModel(), stringWriter); return stringWriter.toString(); } catch (IOException e) { throw new IllegalArgumentException(e); } catch (TemplateException e) { throw new IllegalArgumentException(e); } }
/** * Creates a new ModelAndView object with given arguments. * * @param model object. * @param viewName to be rendered. * @return object with model and view set. */ public ModelAndView modelAndView(Object model, String viewName) { return new ModelAndView(model, viewName); }
/** * {@inheritDoc} */ @Override public String render(ModelAndView modelAndView) { try { StringWriter stringWriter = new StringWriter(); Template template = configuration.getTemplate(modelAndView.getViewName()); template.process(modelAndView.getModel(), stringWriter); return stringWriter.toString(); } catch (IOException | TemplateException e) { throw new IllegalArgumentException(e); } }
public ModelAndView index(Request request, Response response) { HashMap<Object, Object> object = new HashMap<Object, Object>() {{ put("viewTitle", "Elastic Agent Profiles"); }}; return new ModelAndView(object, null); } }
/** * {@inheritDoc} */ @Override public String render(ModelAndView modelAndView) { Template template = velocityEngine.getTemplate(modelAndView.getViewName()); Object model = modelAndView.getModel(); if (model instanceof Map) { Map<?, ?> modelMap = (Map<?, ?>) model; VelocityContext context = new VelocityContext(modelMap); StringWriter writer = new StringWriter(); template.merge(context, writer); return writer.toString(); } else { throw new IllegalArgumentException("modelAndView must be of type java.util.Map"); } }
public ModelAndView index(Request request, Response response) { HashMap<Object, Object> object = new HashMap<Object, Object>() {{ put("viewTitle", "Config Repos"); }}; return new ModelAndView(object, null); } }
@Override public String render(ModelAndView modelAndView) { Object model = modelAndView.getModel(); if (model instanceof Map) { String template = null; try { template = Resources.toString(Resources.getResource(modelAndView.getViewName()), Charsets.UTF_8); } catch (IOException ignored) { } return jinjava.render(template, (Map<String, Object>) model); } else { throw new IllegalArgumentException("modelAndView.getModel() must return a java.util.Map"); } } }
public ModelAndView index(Request request, Response response) { HashMap<Object, Object> object = new HashMap<Object, Object>() {{ put("viewTitle", "Plugins"); }}; return new ModelAndView(object, null); } }
@Override public String render(final ModelAndView modelAndView) { final CompiledTemplate compiledTemplate = loadTemplate(modelAndView.getViewName()); return (String) TemplateRuntime.execute(compiledTemplate, modelAndView.getModel()); }
public ModelAndView index(Request request, Response response) { Map<Object, Object> object = new HashMap<Object, Object>() {{ put("viewTitle", "Server Roles"); }}; return new ModelAndView(object, "roles/index.vm"); } }
@Override @SuppressWarnings("unchecked") public String render(final ModelAndView modelAndView) { final String templateName = modelAndView.getViewName(); if (modelAndView.getModel() instanceof Map) { final Map<String, ?> soyMapData = (Map<String, ?>) modelAndView.getModel(); return soyTofu.newRenderer(templateName).setData(soyMapData).render(); } throw new IllegalArgumentException("Expecting the model to be an instance of Map<String, ?>"); } }
private ModelAndView index(Request request, Response response) { HashMap<Object, Object> object = new HashMap<Object, Object>() {{ put("viewTitle", "Kitchen Sink"); }}; return new ModelAndView(object, null); } }
/** * {@inheritDoc} */ @Override public String render(ModelAndView modelAndView) { String templateEncoding = Optional.ofNullable(this.encoding).orElse(StandardCharsets.UTF_8.name()); Template template = velocityEngine.getTemplate(modelAndView.getViewName(), templateEncoding); Object model = modelAndView.getModel(); if (model instanceof Map) { Map<?, ?> modelMap = (Map<?, ?>) model; VelocityContext context = new VelocityContext(modelMap); StringWriter writer = new StringWriter(); template.merge(context, writer); return writer.toString(); } else { throw new IllegalArgumentException("modelAndView must be of type java.util.Map"); } }
public ModelAndView index(Request request, Response response) { Map<Object, Object> object = new HashMap<Object, Object>() {{ put("viewTitle", "Artifact Stores"); }}; return new ModelAndView(object, "artifact_stores/index.vm"); } }
public String render(ModelAndView modelAndView) { try { JadeTemplate template = this.configuration.getTemplate(modelAndView.getViewName()); return this.configuration.renderTemplate(template, (Map) modelAndView.getModel()); } catch (IOException var3) { throw new IllegalArgumentException(var3); } } }