Search in sources :

Example 11 with Context

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);
    }
}
Also used : Context(org.apache.velocity.context.Context) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) VelocityException(org.apache.velocity.exception.VelocityException) ToolManager(org.apache.velocity.tools.ToolManager) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException)

Example 12 with Context

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);
    }
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) Context(org.apache.velocity.context.Context) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) VelocityContext(org.apache.velocity.VelocityContext) StringUtils(org.codehaus.plexus.util.StringUtils) VelocityException(org.apache.velocity.exception.VelocityException) IOException(java.io.IOException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 13 with Context

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);
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) Context(org.apache.velocity.context.Context)

Example 14 with Context

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);
        }
    }
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) Context(org.apache.velocity.context.Context) StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) File(java.io.File) Template(org.apache.velocity.Template)

Example 15 with Context

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);
}
Also used : Context(org.apache.velocity.context.Context) VelocityContext(org.apache.velocity.VelocityContext) VelocityContext(org.apache.velocity.VelocityContext) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)

Aggregations

Context (org.apache.velocity.context.Context)41 VelocityContext (org.apache.velocity.VelocityContext)33 StringWriter (java.io.StringWriter)9 IOException (java.io.IOException)8 Identity (org.olat.core.id.Identity)8 File (java.io.File)6 ArrayList (java.util.ArrayList)6 AssessmentRenderFunctions.contentAsString (org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)6 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 StringReader (java.io.StringReader)4 Locale (java.util.Locale)4 Map (java.util.Map)4 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)4 ValidationError (org.olat.core.gui.components.form.ValidationError)4 MailContext (org.olat.core.util.mail.MailContext)4 I18nManagerWrapper (com.agiletec.aps.system.services.i18n.I18nManagerWrapper)3 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)3 Renderer (org.olat.core.gui.render.Renderer)3