예제 #1
0
  public static boolean call(PageContext pc, Object obj, boolean addNewLine, boolean doErrorStream)
      throws PageException {
    String string;
    if (Decision.isSimpleValue(obj)) string = Caster.toString(obj);
    else {
      try {
        string = Serialize.call(pc, obj);
      } catch (Throwable t) {
        string = obj.toString();
      }
    }
    PrintStream stream = System.out;
    // string+=":"+Thread.currentThread().getId();
    if (doErrorStream) stream = System.err;
    if (string != null) {
      if (StringUtil.indexOfIgnoreCase(string, "<print-stack-trace>") != -1) {
        String st = ExceptionUtil.getStacktrace(new Exception("Stack trace"), false);
        string = StringUtil.replace(string, "<print-stack-trace>", "\n" + st + "\n", true).trim();
      }
      if (StringUtil.indexOfIgnoreCase(string, "<hash-code>") != -1) {
        String st = obj.hashCode() + "";
        string = StringUtil.replace(string, "<hash-code>", st, true).trim();
      }
    }
    if (addNewLine) stream.println(string);
    else stream.print(string);

    return true;
  }
예제 #2
0
 /**
  * translate a binary array to a buffered image
  *
  * @param binary
  * @return
  * @throws IOException
  */
 @Override
 public final BufferedImage toBufferedImage(byte[] bytes, String format) throws IOException {
   try {
     return Sanselan.getBufferedImage(new ByteArrayInputStream(bytes));
   } catch (ImageReadException e) {
     throw ExceptionUtil.toIOException(e);
   }
 }
예제 #3
0
 /**
  * translate a file resource to a buffered image
  *
  * @param res
  * @return
  * @throws IOException
  */
 @Override
 public final BufferedImage toBufferedImage(Resource res, String format) throws IOException {
   InputStream is = null;
   try {
     return Sanselan.getBufferedImage(is = res.getInputStream());
   } catch (ImageReadException e) {
     throw ExceptionUtil.toIOException(e);
   } finally {
     IOUtil.closeEL(is);
   }
 }
예제 #4
0
파일: BIF.java 프로젝트: dajester2013/Lucee
  public BIF(PageContext pc, String name) throws ApplicationException {
    super(Component.ACCESS_PUBLIC);
    ci = (ConfigImpl) pc.getConfig();
    FunctionLib fl = ci.getCombinedFLDs(pc.getCurrentTemplateDialect());
    flf = fl.getFunction(name);

    // BIF not found
    if (flf == null) {
      Key[] keys = CollectionUtil.toKeys(fl.getFunctions().keySet());
      throw new ApplicationException(
          ExceptionUtil.similarKeyMessage(
              keys, name, "build in function", "build in functions", null, false));
    }
    try {
      this.id = Hash.md5(name);
    } catch (NoSuchAlgorithmException e) {
      this.id = name;
    }
  }