コード例 #1
0
 public TNode parse(Path path) {
   try {
     final TNode root = parse(Files.readAllBytes(path), TemplateType.fromPath(path));
     root.setUnparsedSize(Files.size(path));
     return root;
   } catch (IOException e) {
     throw new TemplateException(e);
   } catch (TemplateException e) {
     if (e.getCause() != null) {
       throw new TemplateException(
           "Error when parsing " + path + ":" + e.getCause().getMessage(), e.getCause());
     } else {
       throw new TemplateException("Error when parsing " + path + ":" + e.getMessage(), e);
     }
   }
 }
コード例 #2
0
ファイル: ServletFree.java プロジェクト: yixuanwang26/JspExam
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   Map root = new HashMap();
   Connection conn = null;
   conn = ConFact.getInstance().makeConnection();
   String id = req.getParameter("id");
   String sql = "select title,description,language_id from film where film_id=" + id + ";";
   java.sql.PreparedStatement pst;
   try {
     pst = conn.prepareStatement(sql);
     ResultSet rs = pst.executeQuery();
     while (rs.next()) {
       java.sql.PreparedStatement pst1;
       String sql1 = "select name from language where language_id=" + rs.getString(3) + ";";
       pst1 = conn.prepareStatement(sql1);
       ResultSet rs1 = pst1.executeQuery();
       while (rs1.next()) {
         Template t = cfg.getTemplate("test.ftl");
         root.put("title", rs.getString(1));
         root.put("description", rs.getString(2));
         root.put("language", rs1.getString(1));
         resp.setContentType("text/html; charset=" + t.getEncoding());
         Writer out = resp.getWriter();
         t.process(root, out);
       }
       rs1.close();
     }
     rs.close();
     pst.close();
     conn.close();
   } catch (TemplateException e) {
     e.printStackTrace();
   } catch (SQLException e1) {
     e1.printStackTrace();
   }
 }
コード例 #3
0
  /** @param args */
  public static void main(String[] args) {
    ModelParser p = new ModelParser();
    CIISModel m = p.parseModel(cInBase + "BOB_ECIF_逻辑模型模板.xls");
    Template template;
    File afile;
    Writer out;

    CIISObject[] objs = m.getAllObjects();
    Map params = new HashMap();
    params.put("today", new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date()));
    params.put("objects", objs);

    params.put("utils", new Utils());
    try {
      Configuration cfg = new Configuration();
      cfg.setLocalizedLookup(false);
      cfg.setDirectoryForTemplateLoading(new File(cInBase + "javaTemplate"));
      cfg.setObjectWrapper(new DefaultObjectWrapper());

      template = cfg.getTemplate("transBaseErrorCode.ftl");
      afile = new File(cOutJava + "ITransBaseErrorCode.java");
      out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(afile)));
      template.process(params, out);
      out.flush();

      cfg = new Configuration();
      cfg.setLocalizedLookup(false);
      cfg.setDirectoryForTemplateLoading(new File(cInBase + "javaTemplate"));
      cfg.setObjectWrapper(new DefaultObjectWrapper());

      template = cfg.getTemplate("transBaseErrorCode_sql.ftl");
      afile = new File(configOutJava + "transBaseErrorCode.sql");
      out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(afile)));
      template.process(params, out);
      out.flush();

      cfg = new Configuration();
      cfg.setLocalizedLookup(false);
      cfg.setDirectoryForTemplateLoading(new File(cInBase + "javaTemplate"));
      cfg.setObjectWrapper(new DefaultObjectWrapper());

      template = cfg.getTemplate("datamodelConst.ftl");
      afile = new File(cOutJava + "DataModelConst.java");
      out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(afile)));
      template.process(params, out);
      out.flush();

      template = cfg.getTemplate("base.operation.ftl");
      afile = new File(configOutJava + "base.operation.xml");
      out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(afile)));
      template.process(params, out);
      out.flush();

      template = cfg.getTemplate("errorcode.xml.ftl");
      afile = new File(configOutJava + "errorcode.xml");
      out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(afile)));
      template.process(params, out);
      out.flush();

    } catch (TemplateException e) {
      System.out.println("模板出现错误!");
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }