Package org.apache.velocity

Examples of org.apache.velocity.Template


    {
        // then get a context
        Context context = getContext(request, response);

        // get the template
        Template template = getTemplate(request, response);

        // merge the template and context into the response
        merge(template, context, response.getWriter());

        return context;
View Full Code Here


    {
        // then get a context
        Context context = getContext(request);

        // get the template
        Template template = getTemplate(request);

        // merge the template and context into the writer
        merge(template, context, out);

        return context;
View Full Code Here

        Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new NullLogChute());
        Velocity.setProperty(Velocity.RESOURCE_LOADER, "class");
        Velocity.setProperty("class.resource.loader.description", "Velocity Classpath Resource Loader");
        Velocity.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
        Velocity.init();
        Template template = Velocity.getTemplate("/org/apache/tomee/configs/" + filename);
        VelocityContext context = new VelocityContext();
        context.put("tomcatHttpPort", Integer.toString(configuration.getHttpPort()));
        context.put("tomcatShutdownPort", Integer.toString(configuration.getStopPort()));
        Writer writer = new FileWriter(new File(targetDir, filename));
        template.merge(context, writer);
        writer.flush();
        writer.close();
    }
View Full Code Here

    private void processPlan(VelocityEngine velocity, File plan) throws Exception {
        // Get the plan name, which is basically plan.getAbsolutePath() - sourceDir.getAbsolutePath()
        String planName = extractPlanName(sourceDir, plan);

        // load the template
        Template template = velocity.getTemplate(planName);

        // determine the output file
        File outputFile = new File(targetDir, planName);

        // create the output directory
        File outputDir = outputFile.getParentFile();
        if (!outputDir.exists()) {
            if (!outputDir.mkdirs()) {
                throw new IllegalArgumentException("Could not create outputDir: " + outputDir.getAbsolutePath());
            }
        }
        if (!outputDir.isDirectory()) {
            throw new IllegalArgumentException("outputDir is not a directory: " + outputDir.getAbsolutePath());
        }

        if (force || outputFile.lastModified() < plan.lastModified()) {
            System.out.println("    Preprocessing " + planName);

            // process the plan
            PrintStream out = null;
            FileReader templateReader = null;
            try {
                out = new PrintStream(new FileOutputStream(outputFile));

                PrintWriter writer = new PrintWriter(out);
                template.merge(context, writer);
                writer.flush();
            } finally {
                close(out);
                close(templateReader);
            }
View Full Code Here

            File sourceD = new File(sourceDir);
            VelocityEngine velocity = new VelocityEngine();
            velocity.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, sourceD.getAbsolutePath());
            velocity.init();
            Template template = velocity.getTemplate(planFile);
            StringWriter writer = new StringWriter();
            template.merge(context, writer);

            String plan = writer.toString();

            LinkedHashSet dependencies = toDependencies();
            org.apache.geronimo.kernel.repository.Artifact configId = new org.apache.geronimo.kernel.repository.Artifact(groupId, artifactId, version, "car");
View Full Code Here

            /*
             *  make a writer, and merge the template 'against' the context
             */
            Template template = Velocity.getTemplate(templateFile);

            Writer writer = new BufferedWriter(new OutputStreamWriter(System.out));
            template.merge( context , writer);

            writer.flush();
            writer.close();
        }
        catch( Exception e )
View Full Code Here

        Vector linkList = getExtraLinks();

        ctx.put("theList", linkList);
        ctx.put("ast","[*]");

        Template outty = null;
       
        try
        {
            outty =  getTemplate("sample.vm");
        }
View Full Code Here

        // Don't spit out any logs
        velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.NullLogSystem");
        velocity.init();

        Template template = velocity.getTemplate(planFileName);
        StringWriter writer = new StringWriter();
        template.merge(context, writer);

        String plan = writer.toString();

        XmlObject doc = XmlObject.Factory.parse(plan);
        XmlCursor xmlCursor = doc.newCursor();
View Full Code Here

        ve.setProperty(RuntimeConstants.RUNTIME_LOG, logFile);
      }

      ve.init();
      Template t = ve.getTemplate(template);

      if (clusterMode == null) {
        clusterMode = new String("");
      }
      if (hadoopVersion == null) {
        hadoopVersion = "";
      }

      // For each of the qFiles generate the test
      VelocityContext ctx = new VelocityContext();
      ctx.put("className", className);
      ctx.put("qfiles", qFiles);
      ctx.put("resultsDir", resultsDir);
      ctx.put("logDir", logDir);
      ctx.put("clusterMode", clusterMode);
      ctx.put("hadoopVersion", hadoopVersion);

      File outFile = new File(outDir, className + ".java");
      FileWriter writer = new FileWriter(outFile);
      t.merge(ctx, writer);
      writer.close();

      System.out.println("Generated " + outFile.getCanonicalPath() + " from template " + template);
    } catch(BuildException e) {
      throw e;
View Full Code Here

            throw new ToolException(msg, e);
        }
    }

    public void doWrite(String templateName, Writer outputs) throws ToolException {
        Template tmpl = null;
        try {
            tmpl = Velocity.getTemplate(templateName);
        } catch (Exception e) {
            Message msg = new Message("TEMPLATE_MISSING", LOG, templateName);
            throw new ToolException(msg, e);
        }

        VelocityContext ctx = new VelocityContext();

        for (Iterator iter = attributes.keySet().iterator(); iter.hasNext();) {
            String key = (String)iter.next();
            ctx.put(key, attributes.get(key));
        }

        VelocityWriter writer = new VelocityWriter(outputs);
        ctx.put("out", writer);
        try {
            tmpl.merge(ctx, writer);
            writer.close();
        } catch (Exception e) {
            Message msg = new Message("VELOCITY_ENGINE_WRITE_ERRORS", LOG);
            throw new ToolException(msg, e);
        }
View Full Code Here

TOP

Related Classes of org.apache.velocity.Template

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.