Examples of VelocityContext


Examples of org.apache.velocity.VelocityContext

                "performing " + methodName + " with templateFile '" + templateFile + "' and templateObjects '" +
                templateObjects + "'");
        }
        ExceptionUtils.checkEmpty("templateFile", templateFile);
        ExceptionUtils.checkNull("output", output);
        this.velocityContext = new VelocityContext();
        this.loadVelocityContext(templateObjects);

        Template template = (Template)this.discoveredTemplates.get(templateFile);
        if (template == null)
        {
View Full Code Here

Examples of org.apache.velocity.VelocityContext

        String evaluatedExpression = null;
        if (StringUtils.isNotEmpty(expression) && templateObjects != null && !templateObjects.isEmpty())
        {
            if (this.velocityContext == null)
            {
                this.velocityContext = new VelocityContext();
                this.loadVelocityContext(templateObjects);
            }
            try
            {
                final StringWriter writer = new StringWriter();
View Full Code Here

Examples of org.apache.velocity.VelocityContext

        } 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);
        try {
            tmpl.merge(ctx, writer);
View Full Code Here

Examples of org.apache.velocity.VelocityContext

    /**
     * @inheritDoc
     */
    public void prepareRender() {
       this.velocityContext = new VelocityContext();       
    }
View Full Code Here

Examples of org.apache.velocity.VelocityContext

      try
      {
         // simple case - single descriptor package (e.g. xxx-service.xml)
         if (vmTemplate != null )
         {
            VelocityContext ctx = createTemplateContext(ci, properties);

            BufferedWriter out = new BufferedWriter(new FileWriter(outputModule));

            try {
               boolean success = ve.mergeTemplate(template + '/' + vmTemplate, ctx, out);

               if (success == true)
               {
                  String errorMsg = (String)ctx.get(TEMPLATE_ERROR_PARAM);

                  if (errorMsg.length() > 0)
                     throw new Exception("Template error: " + errorMsg);
                  else
                     log.debug("created module '" + outputModule.getName() + "' based on template '" + template + "'");
               }
               else
                  throw new Exception("Failed to create module '" + outputModule.getName());
            }
            finally
            {
               out.close();
            }
         }
         else
         {
            // complex case - many descriptors and possibly files to copy
            // now output will be a directory instead of a plain descriptor (e.g. xxx.sar)
            VelocityContext ctx = createTemplateContext(ci, properties);

            // deep copy files if copydir specified
            String copydir = ci.getCopydir();

            File sourceDir = new File(this.templateDir, template + '/' + copydir);

            deepCopy(sourceDir, outputModule);

            // go through all declared templates
            List templateList = ci.getTemplateInfoList();

            for (Iterator i = templateList.iterator(); i.hasNext(); )
            {
               TemplateInfo ti = (TemplateInfo)i.next();

               File outputFile = new File(outputModule, ti.getOutput());
               File outputPath  = outputFile.getParentFile();

               if (!outputPath.exists())
                  if (!outputPath.mkdirs())
                     throw new IOException("cannot create directory: " + outputPath);

               BufferedWriter out = new BufferedWriter(new FileWriter(outputFile));

               try {
                  boolean success = ve.mergeTemplate(template + '/' + ti.getInput(), ctx, out);

                  if (success == true)
                  {
                     String errorMsg = (String)ctx.get(TEMPLATE_ERROR_PARAM);

                     if (errorMsg.length() > 0)
                        throw new Exception("Template error: " + errorMsg);
                     else
                        log.debug("created module '" + outputModule.getName() + "' based on template '" + template + "'");
View Full Code Here

Examples of org.apache.velocity.VelocityContext

    * @throws Exception
    */
   private VelocityContext createTemplateContext(ConfigInfo ci, HashMap map)
      throws Exception
   {
      VelocityContext vc;

      List propertyList = ci.getPropertyInfoList();

      if (propertyList.size() > 0)
      {
         vc = new VelocityContext();

         for (Iterator i = propertyList.iterator(); i.hasNext(); ) {
            PropertyInfo pi = (PropertyInfo)i.next();

            String name = pi.getName();
            String type = pi.getType();
            boolean optional = pi.isOptional();
            Object defaultValue = pi.getDefaultValue();

            if (name == null || name.length() == 0 || type == null || type.length() == 0)
               throw new Exception("Null or empty name/type property metadata for template: " + ci.getName());

            Object sentValue = map.get(name);

            // a value was sent - pass it over after checking its type
            if (sentValue != null)
            {
               if (!type.equals(sentValue.getClass().getName()))
                  throw new Exception("Expected type '" + type + "' for property '" + name +
                                      "', got '" + sentValue.getClass().getName());

               vc.put(name, sentValue);
            }
            else if (optional == false) {
               // a value was not sent - property is required
               // so use the default value (if exists) or throw an exception
               if (defaultValue != null) {
                  vc.put(name, defaultValue);
               }
               else {
                  throw new Exception("Required property missing: '" + name + "' of type '" + type + "'");
               }
            }
            // property is optional and value was not sent
            // do nothing even if a default is set
         }
      }
      else
      {
         // property list empty, allow everything
         // just embed the Hashmap
         vc = new VelocityContext(map);
      }
      // add a parameter to allow the templates to report errors
      vc.put(TEMPLATE_ERROR_PARAM, "");
      // add a context helper
      vc.put(CONTEXT_HELPER, new ContextHelper());

      return vc;
   }
View Full Code Here

Examples of org.apache.velocity.VelocityContext

      String vmTemplate = ci.getTemplate();

      // Generate the XSLT based on the properties and the template:
      StringWriter sw = new StringWriter();
      PrintWriter xslt = new PrintWriter(sw);
      VelocityContext ctx = createTemplateContext(ci, map);
      String tp = template + File.separator + vmTemplate;
      ve.mergeTemplate(tp, ctx, xslt);
      StringBuffer buf = sw.getBuffer();
      xslt.close();
View Full Code Here

Examples of org.apache.velocity.VelocityContext

   */
  public MailTemplate(String subjectTemplate, String bodyTemplate, File[] attachments) {
    this.subjectTemplate = subjectTemplate;
    this.bodyTemplate = bodyTemplate;
    this.attachments = attachments;
    this.context = new VelocityContext();
    this.cpfrom = true;
  }
View Full Code Here

Examples of org.apache.velocity.VelocityContext

   */
  public String[] previewSubjectAndBody(Identity recipientTO, List<Identity> recipientsCC, List<Identity> recipientsBCC, MailTemplate template,
      Identity sender){
    MailerResult result = new MailerResult();

    VelocityContext context = new VelocityContext();   
    template.putVariablesInMailContext(context, recipientTO);
   
    MimeMessage msg = createWithContext(context, recipientTO, recipientsCC, recipientsBCC, template, sender, result);
    String subject=null;
    String body=null;
View Full Code Here

Examples of org.apache.velocity.VelocityContext

    }
    boolean isMailSendToRecipient = false;
    if (recipientsTO != null) {
      for (Identity recipient : recipientsTO) {
        // populate velocity context with variables
        VelocityContext context = new VelocityContext();
        template.putVariablesInMailContext(context, recipient);
        sendWithContext(context, recipient, null, null, template, sender, result);
        if (!result.getFailedIdentites().contains(recipient)) {
          isMailSendToRecipient = true;
        }
      }
    }
    if (recipientsCC != null) {
      for (Identity recipient : recipientsCC) {
        // populate velocity context with variables
        VelocityContext context = new VelocityContext();
        template.putVariablesInMailContext(context, recipient);
        sendWithContext(context, recipient, null, null, template, sender, result);
        if (!result.getFailedIdentites().contains(recipient)) {
          isMailSendToRecipient = true;
        }
      }
    }
    if (recipientsBCC != null) {
      for (Identity recipient : recipientsBCC) {
        // populate velocity context with variables
        VelocityContext context = new VelocityContext();
        template.putVariablesInMailContext(context, recipient);
        sendWithContext(context, recipient, null, null, template, sender, result);
        if (!result.getFailedIdentites().contains(recipient)) {
          isMailSendToRecipient = true;
        }
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.