use of org.apache.velocity.context.Context in project maven-plugins by apache.
the class AnnouncementMojo method doGenerate.
protected void doGenerate(List<Release> releases, Release release) throws MojoExecutionException {
try {
ToolManager toolManager = new ToolManager(true);
Context context = toolManager.createContext();
if (getIntroduction() == null || getIntroduction().equals("")) {
setIntroduction(getUrl());
}
context.put("releases", releases);
context.put("groupId", getGroupId());
context.put("artifactId", getArtifactId());
context.put("version", getVersion());
context.put("packaging", getPackaging());
context.put("url", getUrl());
context.put("release", release);
context.put("introduction", getIntroduction());
context.put("developmentTeam", getDevelopmentTeam());
context.put("finalName", getFinalName());
context.put("urlDownload", getUrlDownload());
context.put("project", project);
if (announceParameters == null) {
// empty Map to prevent NPE in velocity execution
context.put("announceParameters", Collections.emptyMap());
} else {
context.put("announceParameters", announceParameters);
}
processTemplate(context, announcementDirectory, template, announcementFile);
} catch (ResourceNotFoundException rnfe) {
throw new MojoExecutionException("Resource not found.", rnfe);
} catch (VelocityException ve) {
throw new MojoExecutionException(ve.toString(), ve);
}
}
use of org.apache.velocity.context.Context in project maven-plugins by apache.
the class DefaultCheckstyleRssGenerator method generateRSS.
@Override
public void generateRSS(CheckstyleResults results, CheckstyleRssGeneratorRequest checkstyleRssGeneratorRequest) throws MavenReportException {
VelocityTemplate vtemplate = new VelocityTemplate(velocityComponent, CheckstyleReport.PLUGIN_RESOURCES);
vtemplate.setLog(checkstyleRssGeneratorRequest.getLog());
Context context = new VelocityContext();
context.put("results", results);
context.put("project", checkstyleRssGeneratorRequest.getMavenProject());
context.put("copyright", checkstyleRssGeneratorRequest.getCopyright());
context.put("levelInfo", SeverityLevel.INFO);
context.put("levelWarning", SeverityLevel.WARNING);
context.put("levelError", SeverityLevel.ERROR);
context.put("stringutils", new StringUtils());
try {
vtemplate.generate(checkstyleRssGeneratorRequest.getOutputDirectory().getPath() + "/checkstyle.rss", "checkstyle-rss.vm", context);
} catch (ResourceNotFoundException e) {
throw new MavenReportException("Unable to find checkstyle-rss.vm resource.", e);
} catch (MojoExecutionException | IOException | VelocityException e) {
throw new MavenReportException("Unable to generate checkstyle.rss.", e);
}
}
use of org.apache.velocity.context.Context in project scoold by Erudika.
the class VelocityView method renderMergedTemplateModel.
/**
* Process the model map by merging it with the Velocity template. Output is directed to the servlet response.
* <p>
* This method can be overridden if custom behavior is needed.
*/
@Override
protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
exposeHelpers(model, request);
Context velocityContext = createVelocityContext(model, request, response);
exposeHelpers(velocityContext, request, response);
exposeToolAttributes(velocityContext, request);
doRender(velocityContext, response);
}
use of org.apache.velocity.context.Context in project openolat by klemens.
the class VelocityTemplateTest method testTemplates.
private void testTemplates(String dir, File file, List<Exception> exs) {
String name = file.getName();
if ("_content".equals(name)) {
File[] templates = file.listFiles();
for (File template : templates) {
String templateName = template.getName();
if (templateName.endsWith(".html")) {
try {
String path = dir + templateName;
StringWriter writer = new StringWriter();
Context context = new VelocityContext();
Template veloTemplate = engine.getTemplate(path);
veloTemplate.merge(context, writer);
count++;
} catch (Exception e) {
exs.add(e);
}
}
}
} else if (file.isDirectory()) {
File[] files = file.listFiles();
for (File child : files) {
String subDir = dir + child.getName() + "/";
testTemplates(subDir, child, exs);
}
}
}
use of org.apache.velocity.context.Context in project openolat by klemens.
the class AssessmentObjectComponentRenderer method renderInteraction.
/**
* Render the interaction or the PositionStageObject
* @param renderer
* @param sb
* @param interaction
* @param assessmentItem
* @param itemSessionState
* @param component
* @param ubu
* @param translator
*/
private void renderInteraction(AssessmentRenderer renderer, StringOutput sb, FlowInteraction interaction, ResolvedAssessmentItem resolvedAssessmentItem, ItemSessionState itemSessionState, AssessmentObjectComponent component, URLBuilder ubu, Translator translator) {
Context ctx = new VelocityContext();
ctx.put("interaction", interaction);
String page = getInteractionTemplate(interaction);
renderVelocity(renderer, sb, interaction, ctx, page, resolvedAssessmentItem, itemSessionState, component, ubu, translator);
}
Aggregations