@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);
    }
  }
Exemple #2
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();
      }
    }
  }