Beispiel #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;
  }
Beispiel #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);
   }
 }
Beispiel #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);
   }
 }
Beispiel #4
0
  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;
    }
  }