예제 #1
0
  // Velocity init
  public static void initVelocity() {
    if (velocityCatch == null) {
      System.out.println("init VM");
      velocityCatch = new Object();

      Properties props = new Properties();
      props.setProperty("input.encoding", "UTF-8");
      props.setProperty("output.encoding", "UTF-8");

      if (getConfig().getChild("vmtemplatepath") != null) {
        props.setProperty("file.resource.loader.path", getConfig().getChildText("vmtemplatepath"));
      }
      if (System.getProperty("vmtemplatepath") != null) {
        props.setProperty("file.resource.loader.path", System.getProperty("vmtemplatepath"));
        // Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,
        // System.getProperty("vmtemplatepath"));//oder new FIle()?
      }
      System.out.println("vmtemplatepath=" + props.getProperty("vmtemplatepath"));
      try {
        Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, VeloLog.getInstance());
        Velocity.init(props);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
  public String createEmailTemplate(MemberDocumentTempInfo membershipInfo) throws Exception {

    String html = "";

    // configure velocity engine
    Properties p = new Properties();
    p.setProperty("file.resource.loader.path", IMUtil.TEMP_DIR);
    p.setProperty("file.resource.loader.path", IMUtil.TEMP_DIR);
    Velocity.init(p);

    // create temp file
    tempFile = new File(IMUtil.TEMP_DIR + File.separator + TEMPLATE_FILE_NAME);
    FileCopyUtils.copy(contentFields.getBytes(), tempFile);

    // create template and fill it
    VelocityContext context = new VelocityContext();
    context.put("membershipInfo", membershipInfo);
    context.put("user", receiver);

    String language = "fa";
    if (language == "fa") context.put("language", "fa");
    else context.put("language", "en");
    Template template = null;
    template = Velocity.getTemplate(tempFile.getName(), "UTF-8");
    StringWriter sw = new StringWriter();
    template.merge(context, sw);
    html = sw.toString();
    return html;
  }
예제 #3
0
  /**
   * Creates the REST API documentation in HTML form, using the controllers' data and the velocity
   * template.
   *
   * @param controllers .
   * @return string that contains the documentation in HTML form.
   * @throws Exception .
   */
  public String generateHtmlDocumentation(final List<DocController> controllers) throws Exception {

    logger.log(
        Level.INFO,
        "Generate velocity using template: "
            + velocityTemplatePath
            + (isUserDefineTemplatePath
                ? File.separator + velocityTemplateFileName + " (got template path from user)"
                : "(default template path)"));

    Properties p = new Properties();
    p.setProperty("directive.set.null.allowed", "true");
    if (isUserDefineTemplatePath) {
      p.setProperty("file.resource.loader.path", velocityTemplatePath);
    } else {
      p.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
      p.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
    }

    Velocity.init(p);

    VelocityContext ctx = new VelocityContext();

    ctx.put("controllers", controllers);
    ctx.put("version", version);
    ctx.put("docCssPath", docCssPath);

    Writer writer = new StringWriter();

    Template template = Velocity.getTemplate(velocityTemplateFileName);
    template.merge(ctx, writer);

    return writer.toString();
  }
예제 #4
0
  /**
   * @param va
   * @param fw
   * @throws Exception
   * @throws IOException
   */
  public void generate(VelocityAction va, Writer fw) throws Exception, IOException {
    Assert.isNotNull(va.getContext(), "velocity context must be given");
    Assert.isNotNull(va.getTemplatePath(), "velocity template must be given");

    // get Template
    VelocityContext context = va.getContext();
    String templatePath = va.getTemplatePath();
    InputStream template = null;
    File templateFile = new File(templatePath);
    if (templateFile.exists()) {
      // the template is located on File System
      template = new FileInputStream(templateFile);
    } else {
      // resource may be acceded in classPath
      template = getClass().getResourceAsStream(templatePath);
    }

    Assert.isNotNull(template, "velocity template resource can't be loaded");
    // execute
    Velocity.init();
    String s = IOUtils.toString(template);
    Velocity.evaluate(context, fw, "log", s);

    // close streams
    template.close();
    fw.flush();
    fw.close();
  }
예제 #5
0
 /** Instantiates a new exporter velocity. */
 public ExporterVelocity() {
   Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, new VelocityLogger());
   try {
     Velocity.init();
   } catch (final Exception e) {
   }
   velocityContext = new VelocityContext();
 }
예제 #6
0
파일: ApBase.java 프로젝트: sorako/kotemaru
 /**
  * 初期化処理。 <br>
  * - 環境を貰い、Velocityを初期化する。 <br>
  * - 注意事項:Eclipse の注釈処理のバグで jar を差し替えるとVelocityが jar 内の リソースを参照出来なくなる。=> Eclipse再起動が必要。
  */
 @Override
 public void init(ProcessingEnvironment env) {
   super.init(env);
   this.environment = env;
   Velocity.setProperty("runtime.log.logsystem.class", "");
   Velocity.setProperty("resource.loader", "class");
   Velocity.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
   Velocity.init();
 }
예제 #7
0
  {
    try {
      if (Velocity.getProperty(Velocity.FILE_RESOURCE_LOADER_PATH) != null) {
        logger.debug(
            String.format(
                "Resource Loader Path: %s",
                Velocity.getProperty(Velocity.FILE_RESOURCE_LOADER_PATH).toString()));
        shibbolethTemplate = Velocity.getTemplate("shibboleth/interface.vm");
      }
      JsonSimpleConfig config = new JsonSimpleConfig();

      SHIB_ATTRIBUTE_DELIMITER = config.getString(";", SHIBBOLETH_PLUGIN_ID, SHIBBOLETH_DELIMITER);

      SHIB_SESSION_ID =
          config.getString("Shib-Session-ID", SHIBBOLETH_PLUGIN_ID, SHIBBOLETH_SESSION_ATTR);
      SHIB_ATTRIBUTES.add(SHIB_SESSION_ID);
      SHIB_IDP =
          config.getString("Shib-Identity-Provide", SHIBBOLETH_PLUGIN_ID, SHIBBOLETH_IDP_ATTRIBUTE);
      SHIB_ATTRIBUTES.add(SHIB_IDP);
      SHIB_COMMON_NAME = config.getString("cn", SHIBBOLETH_PLUGIN_ID, SHIBBOLETH_CN_ATTRIBUTE);
      SHIB_ATTRIBUTES.add(SHIB_COMMON_NAME);
      SHIB_USER_NAME =
          config.getString("eppn", SHIBBOLETH_PLUGIN_ID, SHIBBOLETH_USERNAME_ATTRIBUTE);
      SHIB_ATTRIBUTES.add(SHIB_USER_NAME);

      List attrs = config.getArray(SHIBBOLETH_PLUGIN_ID, SHIBBOLETH_ATTRIBUTES);
      SHIB_ATTRIBUTES.addAll(attrs);

      SHIB_USE_HEADERS =
          config.getBoolean(SHIB_USE_HEADERS, SHIBBOLETH_PLUGIN_ID, SHIBBOLETH_USE_HEADERS);

      logger.debug(String.format("Session ID Attribute: %s", SHIB_SESSION_ID));
      logger.debug(String.format("Shib Identity Provider Attribute: %s", SHIB_IDP));
      logger.debug(String.format("Shib Common Name Attribute: %s", SHIB_COMMON_NAME));
      logger.debug(String.format("Shib Username Attribute: %s", SHIB_USER_NAME));
      logger.debug(String.format("Shib Attributes: %s", attrs));
      logger.debug(String.format("Shib Attribute split: %s", SHIB_ATTRIBUTE_DELIMITER));

      ServiceLoader<ShibbolethRoleManager> providers =
          ServiceLoader.load(ShibbolethRoleManager.class);
      List plugins = config.getArray(SHIBBOLETH_PLUGIN_ID, "rolePlugins");
      for (Object plugin : plugins) {
        for (ShibbolethRoleManager provider : providers) {
          if (provider.getId().equals(plugin.toString())) {
            logger.debug(String.format("Added Role Manager: %s", provider.getId()));
            roleManagers.add(provider);
          }
        }
      }

      serverUrlBase = config.getString(null, "urlBase");
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
    }
  }
예제 #8
0
파일: VMDemo.java 프로젝트: rampage/erlide
  public static void main(String[] args) throws Exception {
    Velocity.init();
    Template t = Velocity.getTemplate("./templates/poc.vm");

    VelocityContext ctx = new VelocityContext();

    Writer writer = new StringWriter();
    t.merge(ctx, writer);

    System.out.println(writer);
  }
  /**
   * This method will be used for remote registration. Registered patient information will be placed
   * into an xml file for the FormEntry processor.
   *
   * @param paramPatient
   * @param paramString1
   * @param paramString2
   * @throws APIException
   */
  public void registerPatient(Patient paramPatient, String paramString1, String paramString2)
      throws APIException {
    File localFile1 = OpenmrsUtil.getDirectoryInApplicationDataDirectory("amrsregistration");
    File localFile2 = new File(localFile1, "registrationTemplate.xml");
    try {
      String str1 = OpenmrsUtil.getFileAsString(localFile2);

      Properties localProperties = new Properties();
      localProperties.setProperty("resource.loader", "class");
      localProperties.setProperty(
          "class.resource.loader.description", "VelocityClasspathResourceLoader");
      localProperties.setProperty(
          "class.resource.loader.class",
          "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
      localProperties.setProperty(
          "runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");

      Velocity.init(localProperties);
      VelocityContext localVelocityContext = new VelocityContext();
      localVelocityContext.put("locale", Context.getLocale());
      localVelocityContext.put(
          "patient", Context.getPatientService().getPatient(paramPatient.getPatientId()));
      localVelocityContext.put("user", Context.getAuthenticatedUser());
      localVelocityContext.put("fn", new DataExportFunctions());
      localVelocityContext.put("dateEntered", new Date());
      localVelocityContext.put("sid", paramString1);
      localVelocityContext.put("uid", paramString2);
      StringWriter localStringWriter = new StringWriter();
      Velocity.evaluate(localVelocityContext, localStringWriter, super.getClass().getName(), str1);

      String str2 =
          Context.getAdministrationService().getGlobalProperty("remoteformentry.pending_queue_dir");
      File localFile3 = OpenmrsUtil.getDirectoryInApplicationDataDirectory(str2);
      Date localDate = new Date();
      String str3 = "amrsregistration_" + localDate.toString();
      File localFile4 = new File(localFile3, str3);
      try {
        FileWriter localFileWriter = new FileWriter(localFile4);
        localFileWriter.write(localStringWriter.toString());
        localFileWriter.flush();
        localFileWriter.close();
      } catch (IOException localIOException) {
        log.error("Unable to write amrsregistration output file.", localIOException);
      }
    } catch (Exception localException) {
      log.error("Unable to create amrsregistration output file", localException);
      throw new APIException(localException);
    }
  }
예제 #10
0
 public static synchronized MonitorManager getInstance() {
   if (instance == null) {
     instance = new MonitorManager();
   }
   if (!instance.isInitialized) {
     try {
       MonitorManager localMonitorManager = instance;
       PluginController localPluginController =
           (PluginController)
               WebUtils.getServletContextManager().getActor("nds.io.plugincontroller");
       localMonitorManager.oaLmanager =
           new PluginManager(ObjectActionListener.class, localPluginController.getPluginScanner());
       localMonitorManager.oaLmanager.init();
       if (localMonitorManager.oaLmanager.findPlugin("default") != null) {
         localPluginController.getPluginScanner().addDeploymentListener(new a());
         localMonitorManager.reloadObjectActionListeners();
         logger.info("Monitor plugin found.");
         localMonitorManager.isMonitorPluginInstalled = true;
       } else {
         localMonitorManager.isMonitorPluginInstalled = false;
         logger.warning("Monitor plugin not installed.");
       }
       localMonitorManager.isInitialized = true;
       Velocity.init();
     } catch (Exception localException) {
       throw new NDSRuntimeException(localException.getMessage(), localException);
     }
   }
   return instance;
 }
예제 #11
0
  public static void evalToStream(String sTemplate, VelocityContext vc, OutputStream out) {
    ClydeVelocityResourceLoader.setCurrentTemplate(sTemplate);
    try {
      Template template = null;

      try {
        template = Velocity.getTemplate(".");
      } catch (ResourceNotFoundException e) {
        throw new RuntimeException(e);
      } catch (ParseErrorException e) {
        throw new RuntimeException(e);
      } catch (MethodInvocationException e) {
        throw new RuntimeException(e);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }

      Writer w = new OutputStreamWriter(out);
      template.merge(vc, w);
      w.flush();
      w.close();
    } catch (ResourceNotFoundException ex) {
      throw new RuntimeException(ex);
    } catch (ParseErrorException ex) {
      throw new RuntimeException(ex);
    } catch (MethodInvocationException ex) {
      throw new RuntimeException(ex);
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }
  }
예제 #12
0
  public static String evalToString(String sTemplate, VelocityContext vc) {
    ClydeVelocityResourceLoader.setCurrentTemplate(sTemplate);
    try {
      Template template = null;

      try {
        template = Velocity.getTemplate(".");
      } catch (ResourceNotFoundException e) {
        throw new RuntimeException(e);
      } catch (ParseErrorException e) {
        throw new RuntimeException(e);
      } catch (MethodInvocationException e) {
        throw new RuntimeException(e);
      } catch (Exception e) {
        throw new RuntimeException(e);
      }

      StringWriter sw = new StringWriter();

      template.merge(vc, sw);
      String result = sw.toString();
      return result;
    } catch (ResourceNotFoundException ex) {
      throw new RuntimeException(ex);
    } catch (ParseErrorException ex) {
      throw new RuntimeException(ex);
    } catch (MethodInvocationException ex) {
      throw new RuntimeException(ex);
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }
  }
예제 #13
0
  @Override
  public void sendNotification(Check check, Subscription subscription, List<Alert> alerts) {

    try {
      VelocityContext context = createVelocityContext(check, subscription, alerts);

      StringWriter w = new StringWriter();
      Velocity.evaluate(context, w, "EmailNotificationService", getTemplateAsString());

      Email email =
          new Email()
              .withTo(subscription.getTarget())
              .withFrom(seyrenConfig.getFromEmail())
              .withSubject(createSubject(check))
              .withMessage(w.getBuffer().toString());

      mailSender.send(createMimeMessage(email));

    } catch (Exception e) {
      throw new NotificationFailedException(
          "Failed to send notification to "
              + subscription.getTarget()
              + " from "
              + seyrenConfig.getFromEmail(),
          e);
    }
  }
  /** Default constructor. */
  AbsoluteFileResourceLoaderTestCase() {
    super("AbsoluteFileResourceLoaderTest");

    try {
      assureResultsDirectoryExists(RESULTS_DIR);

      // signify we want to use an absolute path
      Velocity.addProperty(Velocity.FILE_RESOURCE_LOADER_PATH, "");

      Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, TestLogChute.class.getName());

      Velocity.init();
    } catch (Exception e) {
      fail("Cannot setup AbsoluteFileResourceLoaderTest!");
    }
  }
  static {
    Properties properties = new Properties();
    properties.setProperty("resource.loader", "class");
    properties.setProperty(
        "class.resource.loader.class",
        "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

    Velocity.init(properties);
  }
예제 #16
0
  /**
   * 送信するメールの内容を作成する.
   *
   * @return
   */
  public static String createTaskMemberMsg(
      RunData rundata, String addr, EipTProjectTask task, EipTProject project) {
    VelocityContext context = new VelocityContext();
    boolean enableAsp = JetspeedResources.getBoolean("aipo.asp", false);
    String CR = ALMailUtils.CR;

    context.put("user_email", addr);

    // (さんの申請は承認されました。など)
    StringBuffer message = new StringBuffer("");
    message.append(CR);
    message
        .append(getl10nFormat("PROJECT_MAIL_TEXT", project.getProjectName(), task.getTaskName()))
        .append(CR);
    context.put("message", message);

    // サービス
    context.put("serviceAlias", ALOrgUtilsService.getAlias());
    // サービス(Aipo)へのアクセス
    context.put("enableAsp", enableAsp);
    context.put("globalurl", ALMailUtils.getGlobalurl());
    context.put("localurl", ALMailUtils.getLocalurl());
    CustomLocalizationService locService =
        (CustomLocalizationService) ServiceUtil.getServiceByName(LocalizationService.SERVICE_NAME);
    String lang = locService.getLocale(rundata).getLanguage();
    StringWriter writer = new StringWriter();
    try {
      if (lang != null && lang.equals("ja")) {
        Template template =
            Velocity.getTemplate(
                "portlets/mail/" + lang + "/project-notification-mail.vm", "utf-8");
        template.merge(context, writer);
      } else {
        Template template =
            Velocity.getTemplate("portlets/mail/project-notification-mail.vm", "utf-8");
        template.merge(context, writer);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    writer.flush();
    String ret = writer.getBuffer().toString();
    return ret;
  }
예제 #17
0
파일: Generate.java 프로젝트: ycads/Cloud
 /**
  * 生成模板文件
  *
  * @param vm
  * @param list
  * @param map
  */
 public String generate(String vm, Map<String, Object> map) throws Exception {
   StringWriter writer = new StringWriter();
   for (Entry<String, Object> e : map.entrySet()) {
     context.put(e.getKey(), e.getValue());
   }
   context.put("generatetime", new Timestamp(System.currentTimeMillis()));
   context.put("modeldesc", Config.getInstance().getModeldesc());
   Velocity.mergeTemplate(vm, "UTF-8", context, writer);
   return writer.toString();
 }
  public static String merge(Map<String, String> map)
      throws ResourceNotFoundException, ParseErrorException, Exception {

    VelocityContext context = new VelocityContext(map);
    StringWriter sw = new StringWriter();
    Template temp = Velocity.getTemplate("/test/template.vm");
    temp.merge(context, sw);
    sw.flush();
    return sw.toString();
  }
예제 #19
0
 public String format(Weather weather) throws Exception {
   log.info("Formatting Weather Data");
   Reader reader =
       new InputStreamReader(getClass().getClassLoader().getResourceAsStream("output.vm"));
   VelocityContext context = new VelocityContext();
   context.put("weather", weather);
   StringWriter writer = new StringWriter();
   Velocity.evaluate(context, writer, "", reader);
   return writer.toString();
 }
예제 #20
0
  @Override
  public void init() throws ServletException {
    super.init();

    Properties _Properties = new Properties();

    _Properties.setProperty("resource.loader", "webapp");
    _Properties.setProperty(
        "webapp.resource.loader.class", "org.apache.velocity.tools.view.WebappResourceLoader");
    _Properties.setProperty("webapp.resource.loader.path", VELOCITY_TEMPLATES_PREFIX);

    ServletContext _ServletContext = getServletContext();
    Velocity.setApplicationAttribute("javax.servlet.ServletContext", _ServletContext);
    try {
      Velocity.init(_Properties);
    } catch (Exception ex) {
      Logger.getLogger(PAD_IJBC.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
 @Override
 public void writeTo(Appendable output) throws IOException {
   Map<String, ?> mutableContext = new HashMap<String, Object>(context);
   Context velocityContext = new VelocityContext(mutableContext);
   try {
     Velocity.evaluate(velocityContext, asWriter(output), "LOG", new StringReader(templateCode));
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
예제 #22
0
  public void writeFile(String filePath, Map input) {
    Velocity.init();
    VelocityContext context = new VelocityContext();

    // Weather variable.
    BucketEntry weather = MapUtil.getBucket(input, "weather").get(0);
    context.put("wst_insi", MapUtil.getValueOr(weather.getValues(), "wst_insi", "?"));

    // Soil metadata
    context.put("classification", MapUtil.getValueOr(weather.getValues(), "classification", "?"));
    context.put("soil_site", MapUtil.getValueOr(weather.getValues(), "soil_site", "?"));
    context.put("soil_name", MapUtil.getValueOr(weather.getValues(), "soil_name", "?"));
    context.put("sl_source", MapUtil.getValueOr(weather.getValues(), "sl_source", "?"));
    context.put("soil_lat", MapUtil.getValueOr(weather.getValues(), "soil_lat", "?"));
    context.put("soil_long", MapUtil.getValueOr(weather.getValues(), "soil_long", "?"));

    // Setup the soil layers.
    SoilLayer[] layers;
    BucketEntry soil = MapUtil.getBucket(input, "soil").get(0);
    ArrayList data = soil.getDataList();
    layers = new SoilLayer[data.size()];
    double cumThickness = 0.0;
    for (int i = 0; i < data.size(); i++) {
      layers[i] = new SoilLayer();
      layers[i].ReadFrom((Map) data.get(i));
      cumThickness = layers[i].calcThickness(cumThickness);
    }
    context.put("layers", layers);

    // Write template.
    Template template = Velocity.getTemplate("src\\main\\resources\\AgMIPTemplate.apsim");
    FileWriter F;
    try {

      F = new FileWriter("Test.apsim");
      template.merge(context, F);
      F.close();

    } catch (IOException ex) {
      Logger.getLogger(ApsimOutput.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
예제 #23
0
파일: ApBase.java 프로젝트: sorako/kotemaru
 /**
  * Velocityテンプレート取得。
  *
  * @param templ テンプレート名。(リソースのパス名)
  * @return
  */
 protected Template getVelocityTemplate(String templ) {
   try {
     return Velocity.getTemplate("/" + templ);
   } catch (Exception e) {
     // - 注意事項:Eclipse の注釈処理のバグで jar を差し替えるとVelocityが jar 内の
     //   リソースを参照出来なくなる。=> Eclipse再起動が必要。
     // ここに来る。
     error(e);
     throw new RuntimeException("Template " + templ + " not found. " + e.toString());
   }
 }
예제 #24
0
  @Override
  protected void writePlans(String dir) {
    Properties p = new Properties();
    p.setProperty("resource.loader", "class");
    p.setProperty(
        "class.resource.loader.class",
        "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");

    Velocity.init(p);
    Context context = new VelocityContext();
    context.put("plans", plans);

    Template template = Velocity.getTemplate("pl/poznan/put/transims/demand/matsim/plans.xml.vm");
    File planFile = new File(dir + "\\plans.xml");

    try (Writer writer = new BufferedWriter(new FileWriter(planFile))) {
      template.merge(context, writer);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
 @Override
 public void init(ServletConfig config) {
   Properties properties = new Properties();
   String basePath =
       System.getProperty("user.dir") + config.getServletContext().getContextPath() + PRE_FIX;
   properties.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, basePath);
   try {
     Velocity.init(properties);
   } catch (Exception e) {
     throw new VelocityException(e);
   }
 }
예제 #26
0
  private String doTemplateMerge(PostLogic post, String templatePath) throws Exception {
    Template template = Velocity.getTemplate(templatePath);
    VelocityContext ctx = new VelocityContext();
    ctx.put("post", post);
    ctx.put("helpers", new Helpers());

    StringWriter writer = new StringWriter();
    template.merge(ctx, writer);

    String toString = writer.toString();

    return toString;
  }
  /*
   * A propriedade "file.resource.loader.path" do Velocity foi
   * inicializada para apontar para [JOAO_DE_BARRO_WORKDIR]
   * em AbstractGeneratorCoordinator.
   */
  public Template getTemplate() throws ResourceNotFoundException {
    String methodName = "getTemplate";
    Template template = null;

    try {
      template = Velocity.getTemplate("./resources/vm/" + getTemplateName());
    } catch (ResourceNotFoundException e) {
      System.err.println("teste");
      error(methodName, e);
      throw e;
    }

    return template;
  }
예제 #28
0
 public PerformSubmitPage() throws PageLoadException {
   super("student_submitted", AccessLevel.USER);
   try {
     emailTemplate = Velocity.getTemplate("email_submission.vm.txt");
   } catch (ResourceNotFoundException e) {
     throw new PageLoadException(500, "Email template resource not found", e);
   } catch (ParseErrorException e) {
     throw new PageLoadException(500, "Email template could not be parsed", e);
   } catch (MethodInvocationException e) {
     throw new PageLoadException(500, "Email template-induced exception caught", e);
   } catch (Exception e) {
     throw new PageLoadException(500, "Misc. email template exception", e);
   }
 }
예제 #29
0
  public static void setup() throws Exception {
    workSpaceDir = Jazmin.environment.getString("deploy.workspace", "./workspace/");
    deployHostname = Jazmin.environment.getString("deploy.hostname", "localhost");
    repoPath = Jazmin.environment.getString("deploy.repo.dir", "./repo");
    antPath = Jazmin.environment.getString("deploy.ant", "ant");
    antCommonLibPath = Jazmin.environment.getString("deploy.ant.lib", "./lib");

    WebServer ws = Jazmin.getServer(WebServer.class);
    if (ws != null) {
      deployHostport = ws.getPort();
    }
    checkWorkspace();
    Velocity.init();
  }
  @Command(
      value = "create-from",
      help = "Create a new entity service class with CRUD methods for an existing entity bean.")
  public void createFrom(
      @Option(name = "entity", required = true, type = PromptType.JAVA_CLASS) JavaResource entity,
      final PipeOut out)
      throws FileNotFoundException {

    JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);

    JavaSource<?> entitySource = entity.getJavaSource();

    VelocityContext context = new VelocityContext();
    context.put("package", java.getBasePackage() + ".service");
    context.put("entityImport", entitySource.getQualifiedName());
    context.put("entityName", entitySource.getName());
    context.put("cdiName", entitySource.getName().toLowerCase());

    // Service class
    StringWriter writer = new StringWriter();
    Velocity.mergeTemplate("TemplateService.vtl", "UTF-8", context, writer);

    JavaClass serviceClass = JavaParser.parse(JavaClass.class, writer.toString());
    java.saveJavaSource(serviceClass);

    pickup.fire(new PickupResource(java.getJavaResource(serviceClass)));

    // ServiceTest class
    StringWriter writerTest = new StringWriter();
    Velocity.mergeTemplate("TemplateServiceTest.vtl", "UTF-8", context, writerTest);

    JavaClass serviceTestClass = JavaParser.parse(JavaClass.class, writerTest.toString());
    java.saveTestJavaSource(serviceTestClass);

    pickup.fire(new PickupResource(java.getTestJavaResource(serviceTestClass)));
  }