Exemplo n.º 1
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);
    }
  }
Exemplo n.º 2
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);
    }
  }