Package org.apache.velocity

Examples of org.apache.velocity.Template.merge()


        File mydir = new File(directory, "mydir");
        expect(generator.getFilename(mydir , packageName, suite, clazz, parameters, runtimeClass, requestClass)).andReturn("myfile.txt");
        String sampleVmPath = "/sample.vm";
        expect(generator.getTemplatePath(mydir, packageName, suite, clazz, parameters, runtimeClass, requestClass)).andReturn(sampleVmPath);
        expect(velocityEngine.getTemplate("/sample.vm")).andReturn(template);
        template.merge(isA(VelocityContext.class), isA(FileWriter.class));
        expectLastCall().andThrow(new IOException());

        replay(velocityEngine, generator, suite, clazz, template, parameters);
        generator.generate(directory, packageName, suite, clazz, parameters, runtimeClass, requestClass);
        verify(velocityEngine, generator, suite, clazz, template, parameters);
View Full Code Here


        File mydir = new File(directory, "mydir");
        expect(generator.getFilename(mydir , packageName, suite, clazz, parameters, runtimeClass, requestClass)).andReturn("myfile.txt");
        String sampleVmPath = "/sample.vm";
        expect(generator.getTemplatePath(mydir, packageName, suite, clazz, parameters, runtimeClass, requestClass)).andReturn(sampleVmPath);
        expect(velocityEngine.getTemplate("/sample.vm")).andReturn(template);
        template.merge(isA(VelocityContext.class), isA(FileWriter.class));
        expectLastCall().andThrow(new ClassParseException());

        replay(velocityEngine, generator, suite, clazz, template, parameters);
        generator.generate(directory, packageName, suite, clazz, parameters, runtimeClass, requestClass);
        verify(velocityEngine, generator, suite, clazz, template, parameters);
View Full Code Here

        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

    Writer writer = null;
    try {
      log.info("Writing " + file);
      Template velocityTemplate = engine.getTemplate(templatePath);
      writer = new FileWriter(file);
      velocityTemplate.merge(context, writer);
    } catch (IOException e) {
      log.error(e.getMessage(), e);
    } catch (ResourceNotFoundException e) {
      log.error(e.getMessage(), e);
    } catch (ParseErrorException e) {
View Full Code Here

        Template template = Velocity.getTemplate("/org/apache/openejb/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();
    }

    private void copyFileTo(File targetDir, String filename) throws IOException {
View Full Code Here

    boolean wrap_response = (layout_template != null) || (json_wrapper != null);

    // create output, optionally wrap it into a json object
    if (wrap_response) {
      StringWriter stringWriter = new StringWriter();
      template.merge(context, stringWriter);

      if (layout_template != null) {
        context.put("content", stringWriter.toString());
        stringWriter = new StringWriter();
        try {
View Full Code Here

        writer.write(')');
      } else // using a layout, but not JSON wrapping
        writer.write(stringWriter.toString());
      }
    } else {
      template.merge(context, writer);
    }
  }

  private VelocityEngine getEngine(SolrQueryRequest request) {
    VelocityEngine engine = new VelocityEngine();
View Full Code Here

                vw.recycle(new OutputStreamWriter(out, encoding));

            if (vw == null)
                Debug.logWarning("[VelocityViewHandler.eval] : VelocityWriter is NULL", module);

            template.merge(context, vw);
        } catch (Exception e) {
            throw new ViewHandlerException(e.getMessage(), e);
        } finally {
            try {
                if (vw != null) {
View Full Code Here

 
  public String mergeData(String vmName) throws ResourceNotFoundException, ParseErrorException, Exception{
    Template template = engine.getTemplate(vmName);
    VelocityContext context = getDefaultContext();
    StringWriter writer = new StringWriter();
    template.merge(context, writer);
    return writer.toString();
  }
 
  public String mergeData(String vmName, String variableName, Object info) throws ResourceNotFoundException, ParseErrorException, Exception {
    Template template = engine.getTemplate(vmName);
View Full Code Here

    Template template = engine.getTemplate(vmName);
    VelocityContext context = getDefaultContext();
    context.put("template", this);
    context.put(variableName, info);
    StringWriter writer = new StringWriter();
    template.merge(context, writer);
    return writer.toString();
  }
 
  public EmptyTemplateInfo getEmptyTemplateInfo() throws ResourceNotFoundException, ParseErrorException, Exception {
    return getEmptyTemplateInfo("template.vm");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.