private String renderTemplate(String template, Context context) { String templatePath = templateDirectory + "/" + template; try { return velocityManager.getEncodedBody(templatePath, "", applicationProperties.getEncoding(), ImmutableMap.<String,Object>of("property", context)); } catch (VelocityException e) { throw new RuntimeException("Error rendering " + templatePath, e); } }
private void toWriterImpl(final Writer writer, boolean attachCartridge) throws IOException { if (source instanceof TemplateSource.File) { final TemplateSource.File template = (TemplateSource.File) source; if (attachCartridge) { context.attachEventCartridge(createDefaultCartridge()); } velocityManager.writeEncodedBody(writer, template.getPath(), "", applicationProperties.getEncoding(), context); } else { if (source instanceof TemplateSource.Fragment) { final TemplateSource.Fragment fragment = (TemplateSource.Fragment) source; if (attachCartridge) { context.attachEventCartridge(createDefaultCartridge()); } velocityManager.writeEncodedBodyForContent(writer, fragment.getContent(), context); } } }
final HashMap<String, Object> params = new HashMap<String, Object>(); params.put("originalBody", originalBody); String newBody = ManagerFactory.getVelocityManager().getEncodedBodyForContent(getTemplateContent(), null, params); final String sender = getSender(message); if (sender == null)
try emailBody = velocityManager.getEncodedBodyForContent(emailBodyTemplate, baseUrl, context);
velocityParams.put("labelUtils", new LabelUtils()); String dashboardHtml = velocityManager.getEncodedBody( "templates/plugins/labels/labels-dashboard-portlet.vm", "",
private void applyDecoratorUsingVelocity(final HttpServletRequest request, final Page page, final HttpServletResponse response) throws IOException { request.setAttribute(STUDIO_ADMIN_SECTION, true); final Map velocityParams = getVelocityParams(request, page, response); final PrintWriter writer = response.getWriter(); try { response.setContentType(new ApplicationPropertiesImpl().getContentType()); final VelocityManager velocityManager = ComponentManager.getInstance().getVelocityManager(); final String body = velocityManager.getEncodedBody("", "/com/atlassian/studio/globaladmin/jirastudioadmin.vm", null, ManagerFactory.getApplicationProperties().getEncoding(), velocityParams); writer.write(body); } catch (final VelocityException e) { writer.write("Exception rendering global admin template"); writer.write("<br><pre>"); e.printStackTrace(writer); writer.write("</pre>"); } request.removeAttribute(RequestConstants.PAGE); }
/** * This method evaluates a velocity tempate and returns the HTML used to * populate the list of labels in the view and colum-view pages. * * @param issue * The issue with the labels. * @param labels * The labels. * @param customField * The labels custom field. * * @throws Exception * Thrown if there's a problem rendering the issue's new labels. * * @return * A HTML view of the issue's new labels. See the tempalte <tt>templates/plugins/labels/label-list.vm</tt>. */ String getVelocityUpdateResponse(Issue issue, Collection<String> labels, CustomField customField) throws Exception { final Map<String, Object> velocityParams = JiraVelocityUtils.getDefaultVelocityParams(EasyMap.build("issueGv", issue != null ? issue.getGenericValue() : null), jiraAuthenticationContext); velocityParams.put("tags", labels); velocityParams.put("issue", issue); velocityParams.put("customField", customField); velocityParams.put("searchService", searchService); velocityParams.put("labelUtils", new LabelUtils()); velocityParams.put("i18n", jiraAuthenticationContext.getI18nHelper()); return velocityManager.getEncodedBody("templates/plugins/labels/label-list.vm", "", applicationProperties.getEncoding(), velocityParams); }
velocityParams.put("labelUtils", new LabelUtils()); String editDialogHtml = velocityManager.getEncodedBody( "templates/plugins/labels/edit-issue-labels.vm", "",
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final LookAndFeelBean lookAndFeelBean = LookAndFeelBean.getInstance(this.applicationProperties); final String eTag = String.valueOf(lookAndFeelBean.getVersion()); // if colors didn't change, return 304 - NOT MODIFIED if (!isResourceModified(request, response, eTag)) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } // get velocity file and render it final String velocityFileName = extractFileName(request.getRequestURI()) + ".vm"; try { final String renderedCSS = velocityManager.getEncodedBody(TEMPLATE_DIRECTORY_PATH, velocityFileName, this.applicationProperties.getEncoding(), EasyMap.build("lookAndFeelBean", lookAndFeelBean)); response.setHeader("ETag", eTag); response.setHeader("Cache-Control", "max-age=300, must-revalidate"); // 5 min response.setContentType("text/css;charset=UTF-8"); HttpUtils.sendTextResponse(response, renderedCSS + additionalCSS, HttpServletResponse.SC_OK, HttpUtils.CONTENT_HTML); } catch (final VelocityException e) { log.warn("Unable to process "+velocityFileName+".", e); HttpUtils.sendTextResponse(response, velocityFileName +", " + e, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, HttpUtils.CONTENT_HTML); } }
return velocityManager.getEncodedBody("com/atlassian/cpji/templates/", "default.html.for.field.vm", getApplicationProperties().getEncoding(), JiraVelocityUtils