Package org.lilystudio.util

Examples of org.lilystudio.util.StringWriter


  public void testBean() throws Exception {
    Context c = new Context();
    Bean bean = new Bean();
    c.putBean(bean);
    Template template = new Template(engine, "{$number}");
    Writer writer = new StringWriter();
    template.merge(c, writer);
    Assert.assertEquals("Bean导入", writer.toString(), "10");

    context.set("bean", bean);
    Assert.assertEquals("Bean导入",
        getResult("{$bean.number}{$bean.number}{$bean.aaa}{$bean.aaa}"),
        "1010nullnull");
View Full Code Here


  }

  private String getResult(String data) throws Exception {
    try {
      Template template = new Template(engine, data);
      Writer writer = new StringWriter();
      template.merge(context, writer);
      return writer.toString();
    } catch (Exception e) {
      return null;
    }
  }
View Full Code Here

    Assert.assertEquals("默认数值转义", "+a", getResult("a-0"));
    Assert.assertEquals("字符串合并", "a+\"a\"+\"b\"", getResult("a+'a'+'b'"));
  }

  private String getResult(String data) throws Exception {
    Writer writer = new StringWriter();
    new JSCompressor().compress(new StringReader(data), writer, false,
        JSCompressor.SEMANTICS);
    return writer.toString();
  }
View Full Code Here

            chain);
      }
    } catch (Throwable e) {
      e.printStackTrace();
      ((HttpServletResponse) response).setCharacterEncoding(encoding);
      StringWriter buf = new StringWriter();
      PrintWriter writer = new PrintWriter(buf);
      e.printStackTrace(writer);
      String text = buf.toString();
      int len = text.length();
      StringBuilder sb = new StringBuilder(512);
      sb.append("<html><head><meta http-equiv='Content-Type' content='text/html;charset=utf-8'></head><body>");
      for (int i = 0; i < len; i++) {
        char c = text.charAt(i);
View Full Code Here

  @Override
  public void execute(Context context, Writer writer, Object[] values)
      throws Exception {
    Object assign = values[1];
    if (assign != null) {
      writer = new StringWriter();
    }

    if (templates.size() > 1024) {
      synchronized (this) {
        templates.clear();
View Full Code Here

  public String parse(Map<String, Object> map) throws Exception {
    Context context = new Context();
    context.putAll(map);
    // 进行临时的输出, 成功才真正的返回得到的结果
    StringWriter out = new StringWriter();
    template.merge(context, out);
    // 回写指定的参数
    if (names != null) {
      for (String name : names) {
        map.put(name, context.get(name));
      }
    }
    return out.toString();
  }
View Full Code Here

  public String parse(Map<String, Object> map) throws Exception {
    VelocityContext context = new VelocityContext(new HashMap<String, Object>(
        map));
    // 进行临时的输出, 成功才真正的返回得到的结果
    StringWriter out = new StringWriter();

    InternalContextAdapterImpl ica = new InternalContextAdapterImpl(context);
    node.init(ica, engine);
    node.render(ica, out);

    // 回写指定的参数
    if (names != null) {
      for (String name : names) {
        map.put(name, context.get(name));
      }
    }
    return out.toString();
  }
View Full Code Here

      this.node = node;
    }

    @Override
    public String getMessage() {
      StringWriter out = new StringWriter();
      try {
        out.write(super.getMessage());
        out.write('\n');
        Transformer transformer = TransformerFactory.newInstance()
            .newTransformer();
        transformer.setOutputProperty(OutputKeys.METHOD, "html");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.transform(new DOMSource(node), new StreamResult(out));
        return out.toString().replaceAll("\\s+\\n", "\n");
      } catch (Exception e) {
        return super.getMessage();
      }
    }
View Full Code Here

  @Override
  public void execute(Context context, Writer writer, Object[] values)
      throws Exception {
    Object assign = values[1];
    if (assign != null) {
      writer = new StringWriter();
    }

    // 加载子模板, 设置子模板的父容器
    Template template = context.getTemplate();
    String name = template.getPath((String) values[0], true);
View Full Code Here

TOP

Related Classes of org.lilystudio.util.StringWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.