コード例 #1
0
 public CCodeGenerator() throws TemplateModelException {
   config.setDefaultEncoding("UTF-8");
   config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
   config.setClassForTemplateLoading(CCodeGenerator.class, "/templates");
   config.setSharedVariable("cTypeHelper", C_TypeHelper.getInstance());
   config.setSharedVariable("enumHelper", EnumHelper.getInstance());
   config.setSharedVariable("requestHelper", RequestHelper.getInstance());
   config.setSharedVariable("helper", Helper.getInstance());
   config.setSharedVariable("structHelper", StructHelper.getInstance());
   config.setSharedVariable("structMemberHelper", StructMemberHelper.getInstance());
   config.setSharedVariable("parameterHelper", ParameterHelper.getInstance());
 }
コード例 #2
0
  public void processTemplate(
      final Object obj, final String templateName, final OutputStream outputStream)
      throws IOException {
    final Template template = config.getTemplate(templateName);

    final Writer writer = new OutputStreamWriter(outputStream);
    try {
      template.process(obj, writer);
    } catch (final NullPointerException | TemplateException e) {
      LOG.error("Unable to process template " + templateName, e);
    }
  }