示例#1
0
  public void checkAccess(String key, long timeNonce) throws PageException {

    if (previousNonces.containsKey(timeNonce)) {
      long now = System.currentTimeMillis();
      long diff = timeNonce > now ? timeNonce - now : now - timeNonce;
      if (diff > 10)
        throw new ApplicationException("nonce was already used, same nonce can only be used once");
    }
    long now = System.currentTimeMillis() + getTimeServerOffset();
    if (timeNonce > (now + FIVE_SECONDS) || timeNonce < (now - FIVE_SECONDS))
      throw new ApplicationException(
          "nonce is outdated (timserver offset:" + getTimeServerOffset() + ")");
    previousNonces.put(timeNonce, "");

    String[] keys = getAuthenticationKeys();
    // check if one of the keys matching
    String hash;
    for (int i = 0; i < keys.length; i++) {
      try {
        hash =
            Hash.hash(
                keys[i], Caster.toString(timeNonce), Hash.ALGORITHM_SHA_256, Hash.ENCODING_HEX);
        if (hash.equals(key)) return;
      } catch (NoSuchAlgorithmException e) {
        throw Caster.toPageException(e);
      }
    }
    throw new ApplicationException("No access, no matching authentication key found");
  }
示例#2
0
 private Object executeLike(PageContext pc, SQL sql, Query qr, ZExpression expression, int row)
     throws PageException {
   return Caster.toBoolean(
       like(
           sql,
           Caster.toString(executeExp(pc, sql, qr, expression.getOperand(0), row)),
           Caster.toString(executeExp(pc, sql, qr, expression.getOperand(1), row))));
 }
示例#3
0
 private static String createMessage(String format, Object value) {
   if (Decision.isSimpleValue(value))
     return "the value [" + Caster.toString(value, null) + "] is not in  [" + format + "] format";
   return "cannot convert object from type ["
       + Caster.toTypeName(value)
       + "] to a ["
       + format
       + "] format";
 }
示例#4
0
 public void setXmlStandalone(boolean arg0) throws DOMException {
   // dynamic load to support jre 1.4 and 1.5
   try {
     Method m = doc.getClass().getMethod("setXmlStandalone", new Class[] {boolean.class});
     m.invoke(doc, new Object[] {Caster.toBoolean(arg0)});
   } catch (Exception e) {
     throw new PageRuntimeException(Caster.toPageException(e));
   }
 }
示例#5
0
 public void setStrictErrorChecking(boolean arg0) {
   // dynamic load to support jre 1.4 and 1.5
   try {
     Method m = doc.getClass().getMethod("setStrictErrorChecking", new Class[] {boolean.class});
     m.invoke(doc, new Object[] {Caster.toBoolean(arg0)});
   } catch (Exception e) {
     throw new PageRuntimeException(Caster.toPageException(e));
   }
 }
示例#6
0
 public String getXmlVersion() {
   // dynamic load to support jre 1.4 and 1.5
   try {
     Method m = doc.getClass().getMethod("getXmlVersion", new Class[] {});
     return Caster.toString(m.invoke(doc, ArrayUtil.OBJECT_EMPTY));
   } catch (Exception e) {
     throw new PageRuntimeException(Caster.toPageException(e));
   }
 }
示例#7
0
 public boolean getXmlStandalone() {
   // dynamic load to support jre 1.4 and 1.5
   try {
     Method m = doc.getClass().getMethod("getXmlStandalone", new Class[] {});
     return Caster.toBooleanValue(m.invoke(doc, ArrayUtil.OBJECT_EMPTY));
   } catch (Exception e) {
     throw new PageRuntimeException(Caster.toPageException(e));
   }
 }
示例#8
0
 public Node adoptNode(Node arg0) throws DOMException {
   // dynamic load to support jre 1.4 and 1.5
   try {
     Method m = doc.getClass().getMethod("adoptNode", new Class[] {arg0.getClass()});
     return Caster.toNode(m.invoke(doc, new Object[] {arg0}));
   } catch (Exception e) {
     throw new PageRuntimeException(Caster.toPageException(e));
   }
 }
示例#9
0
  /**
   * execute a plus operation
   *
   * @param sql
   * @param qr QueryResult to execute on it
   * @param expression
   * @param row row of resultset to execute
   * @return result
   * @throws PageException
   */
  private Object executePlus(PageContext pc, SQL sql, Query qr, ZExpression expression, int row)
      throws PageException {
    Object left = executeExp(pc, sql, qr, expression.getOperand(0), row);
    Object right = executeExp(pc, sql, qr, expression.getOperand(1), row);

    try {
      return new Double(Caster.toDoubleValue(left) + Caster.toDoubleValue(right));
    } catch (PageException e) {
      return Caster.toString(left) + Caster.toString(right);
    }
  }
示例#10
0
文件: PDF.java 项目: ringgi/railo
  private void doActionSetInfo() throws PageException, IOException, DocumentException {
    required("pdf", "setInfo", "info", info);
    required("pdf", "getInfo", "source", source);

    PDFDocument doc = toPDFDocument(source, password, null);
    PdfReader pr = doc.getPdfReader();
    OutputStream os = null;
    try {
      if (destination == null) {
        if (doc.getResource() == null)
          throw new ApplicationException(
              "source is not based on a resource, destination file is required");
        destination = doc.getResource();
      } else if (destination.exists() && !overwrite)
        throw new ApplicationException("destination file [" + destination + "] already exists");

      PdfStamper stamp = new PdfStamper(pr, os = destination.getOutputStream());
      HashMap moreInfo = new HashMap();

      Key[] keys = info.keys();
      for (int i = 0; i < keys.length; i++) {
        moreInfo.put(
            StringUtil.ucFirst(keys[i].getLowerString()), Caster.toString(info.get(keys[i])));
      }
      // author
      Object value = info.get("author", null);
      if (value != null) moreInfo.put("Author", Caster.toString(value));
      // keywords
      value = info.get("keywords", null);
      if (value != null) moreInfo.put("Keywords", Caster.toString(value));
      // title
      value = info.get("title", null);
      if (value != null) moreInfo.put("Title", Caster.toString(value));
      // subject
      value = info.get("subject", null);
      if (value != null) moreInfo.put("Subject", Caster.toString(value));
      // creator
      value = info.get("creator", null);
      if (value != null) moreInfo.put("Creator", Caster.toString(value));
      // trapped
      value = info.get("Trapped", null);
      if (value != null) moreInfo.put("Trapped", Caster.toString(value));
      // Created
      value = info.get("Created", null);
      if (value != null) moreInfo.put("Created", Caster.toString(value));
      // Language
      value = info.get("Language", null);
      if (value != null) moreInfo.put("Language", Caster.toString(value));

      stamp.setMoreInfo(moreInfo);
      stamp.close();

    } finally {
      IOUtil.closeEL(os);
      pr.close();
    }
  }
示例#11
0
文件: List.java 项目: Fusegrid/railo
 /**
  * cast a Object Array to a String Array
  *
  * @param array
  * @return String Array
  * @throws PageException
  */
 public static String[] toStringArray(Array array) throws PageException {
   String[] arr = new String[array.size()];
   for (int i = 0; i < arr.length; i++) {
     arr[i] = Caster.toString(array.get(i + 1, null));
   }
   return arr;
 }
示例#12
0
 /**
  * Executes a constant value
  *
  * @param sql
  * @param qr
  * @param constant
  * @param row
  * @return result
  * @throws PageException
  */
 private Object executeConstant(SQL sql, Query qr, ZConstant constant, int row)
     throws PageException {
   switch (constant.getType()) {
     case ZConstant.COLUMNNAME:
       {
         if (constant.getValue().equals(SQLPrettyfier.PLACEHOLDER_QUESTION)) {
           int pos = sql.getPosition();
           sql.setPosition(pos + 1);
           if (sql.getItems().length <= pos)
             throw new DatabaseException("invalid syntax for SQL Statment", null, sql, null);
           return sql.getItems()[pos].getValueForCF();
         }
         return qr.getAt(List.last(constant.getValue(), ".", true), row);
       }
     case ZConstant.NULL:
       return null;
     case ZConstant.NUMBER:
       return Caster.toDouble(constant.getValue());
     case ZConstant.STRING:
       return constant.getValue();
     case ZConstant.UNKNOWN:
     default:
       throw new DatabaseException("invalid constant value", null, sql, null);
   }
 }
示例#13
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;
  }
示例#14
0
  private static Struct checkTableFill(DatabaseMetaData md, String dbName, String tableName)
      throws SQLException, PageException {
    Struct rows = new CastableStruct(tableName, Struct.TYPE_LINKED);
    ResultSet columns = md.getColumns(dbName, null, tableName, null);
    // print.o(new QueryImpl(columns,""));
    try {
      String name;
      Object nullable;
      while (columns.next()) {
        name = columns.getString("COLUMN_NAME");

        nullable = columns.getObject("IS_NULLABLE");
        rows.setEL(
            KeyImpl.init(name),
            new ColumnInfo(
                name,
                columns.getInt("DATA_TYPE"),
                columns.getString("TYPE_NAME"),
                columns.getInt("COLUMN_SIZE"),
                Caster.toBooleanValue(nullable)));
      }
    } finally {
      DBUtil.closeEL(columns);
    } // Table susid defined for cfc susid does not exist.

    return rows;
  }
示例#15
0
 public static String call(PageContext pc, String url, Struct metadata) throws PageException {
   try {
     return _call(pc, url, metadata);
   } catch (IOException e) {
     throw Caster.toPageException(e);
   }
 }
示例#16
0
文件: PDF.java 项目: ringgi/railo
  private PDFDocument toPDFDocument(Object source, String password, Resource directory)
      throws ExpressionException, IOException {

    if (source instanceof PDFDocument) return (PDFDocument) source;
    if (Decision.isBinary(source)) {
      return new PDFDocument(Caster.toBinary(source), password);
    }
    if (source instanceof Resource) {
      return new PDFDocument((Resource) source, password);
    }
    if (source instanceof String) {
      if (directory != null) {
        Resource res = directory.getRealResource((String) source);
        if (!res.isFile()) {
          Resource res2 = ResourceUtil.toResourceNotExisting(pageContext, (String) source);
          if (res2.isFile()) res = res2;
          else throw new ExpressionException("file or directory " + res + " not exist");
        }
        return new PDFDocument(res, password);
      }
      return new PDFDocument(
          ResourceUtil.toResourceExisting(pageContext, (String) source), password);
    }

    throw new CasterException(source, PdfReader.class);
  }
示例#17
0
  public boolean invokeListener(Gateway gateway, String method, Map data) {
    data = GatewayUtil.toCFML(data);

    GatewayEntry entry = getGatewayEntry(gateway);
    String cfcPath = entry.getListenerCfcPath();
    if (!Util.isEmpty(cfcPath, true)) {
      try {
        if (!callOneWay(
            cfcPath, gateway.getId(), method, Caster.toStruct(data, null, false), false))
          log(
              gateway,
              LOGLEVEL_ERROR,
              "function ["
                  + method
                  + "] does not exist in cfc ["
                  + getCFCDirectory()
                  + toRequestURI(cfcPath)
                  + "]");
        else return true;
      } catch (PageException e) {
        e.printStackTrace();
        log(gateway, LOGLEVEL_ERROR, e.getMessage());
      }
    } else log(gateway, LOGLEVEL_ERROR, "there is no listener cfc defined");
    return false;
  }
示例#18
0
  /**
   * @param title
   * @param key
   * @param content
   * @param custom1
   * @param custom2
   * @param custom3
   * @param custom4
   * @return Document
   */
  public static Document getDocument(
      String title,
      String key,
      String content,
      String urlpath,
      String custom1,
      String custom2,
      String custom3,
      String custom4) {

    // make a new, empty document
    Document doc = new Document();
    doc.add(FieldUtil.UnIndexed("size", Caster.toString(content.length())));

    doc.add(FieldUtil.Text("key", key));
    FieldUtil.setMimeType(doc, "text/plain");
    FieldUtil.setRaw(doc, content);
    FieldUtil.setContent(doc, content);
    FieldUtil.setSummary(doc, StringUtil.max(content, SUMMERY_SIZE), false);

    FieldUtil.setTitle(doc, title);
    FieldUtil.setURL(doc, urlpath);
    FieldUtil.setCustom(doc, custom1, 1);
    FieldUtil.setCustom(doc, custom2, 2);
    FieldUtil.setCustom(doc, custom3, 3);
    FieldUtil.setCustom(doc, custom4, 4);
    return doc;
  }
示例#19
0
 /** @see railo.runtime.type.Collection#_setEL(java.lang.String, java.lang.Object) */
 public Object setEL(Collection.Key key, Object value) {
   try {
     return setEL(Caster.toIntValue(key.getString()), value);
   } catch (ExpressionException e) {
     return null;
   }
 }
示例#20
0
 /** @see railo.runtime.type.Collection#setEL(java.lang.String, java.lang.Object) */
 public Object setEL(String key, Object value) {
   try {
     return setEL(Caster.toIntValue(key), value);
   } catch (ExpressionException e) {
     return null;
   }
 }
示例#21
0
    public boolean accept(Resource res) {

      if (res.isDirectory()) return allowDir;

      // load content
      String str = null;
      try {
        str = IOUtil.toString(res, "UTF-8");
      } catch (IOException e) {
        return false;
      }

      int index = str.indexOf(':');
      if (index != -1) {
        long expires = Caster.toLongValue(str.substring(0, index), -1L);
        // check is for backward compatibility, old files have no expires date inside. they do ot
        // expire
        if (expires != -1) {
          if (expires < System.currentTimeMillis()) {
            return true;
          }
          str = str.substring(index + 1);
          return false;
        }
      }
      // old files not having a timestamp inside
      else if (res.lastModified() <= time) {
        return true;
      }
      return false;
    }
  protected void _init(PageContext pc, Map<String, String> arguments) {
    this.pc = pc;

    // header
    HttpServletRequest req = pc.getHttpServletRequest();

    header = new StringBuffer();
    createHeader(header, "context-path", req.getContextPath());
    createHeader(header, "remote-user", req.getRemoteUser());
    createHeader(header, "remote-addr", req.getRemoteAddr());
    createHeader(header, "remote-host", req.getRemoteHost());
    createHeader(
        header,
        "script-name",
        StringUtil.emptyIfNull(req.getContextPath())
            + StringUtil.emptyIfNull(req.getServletPath()));
    createHeader(header, "server-name", req.getServerName());
    createHeader(header, "protocol", req.getProtocol());
    createHeader(header, "server-port", Caster.toString(req.getServerPort()));
    createHeader(
        header,
        "path-info",
        StringUtil.replace(
            StringUtil.emptyIfNull(req.getRequestURI()),
            StringUtil.emptyIfNull(req.getServletPath()),
            "",
            true));
    // createHeader(header,"path-translated",pc.getBasePageSource().getDisplayPath());
    createHeader(header, "query-string", req.getQueryString());
    createHeader(header, "unit", unitShortToString(unit));
    createHeader(header, "min-time-nano", min + "");

    content = new StringBuffer();

    // directory
    String strDirectory = arguments.get("directory");
    if (dir == null) {
      if (StringUtil.isEmpty(strDirectory)) {
        dir = getTemp(pc);
      } else {
        try {
          dir = ResourceUtil.toResourceNotExisting(pc, strDirectory, false);
          if (!dir.exists()) {
            dir.createDirectory(true);
          } else if (dir.isFile()) {
            err(
                pc,
                "can not create directory [" + dir + "], there is already a file with same name.");
          }
        } catch (Throwable t) {
          err(pc, t);
          dir = getTemp(pc);
        }
      }
    }
    file = dir.getRealResource((pc.getId()) + "-" + CreateUUID.call(pc) + ".exl");
    file.createNewFile();
    start = System.currentTimeMillis();
  }
示例#23
0
文件: List.java 项目: Fusegrid/railo
 public static String[] listToStringArray(String list, char delimeter) {
   Array array = List.listToArrayRemoveEmpty(list, delimeter);
   String[] arr = new String[array.size()];
   for (int i = 0; i < arr.length; i++) {
     arr[i] = Caster.toString(array.get(i + 1, ""), "");
   }
   return arr;
 }
示例#24
0
文件: PDF.java 项目: ringgi/railo
 /**
  * @param opacity the opacity to set
  * @throws ApplicationException
  */
 public void setOpacity(double opacity) throws ApplicationException {
   if (opacity < 0 || opacity > 10)
     throw new ApplicationException(
         "invalid opacity definition ["
             + Caster.toString(opacity)
             + "], value should be in range from 0 to 10");
   this.opacity = (float) (opacity / 10);
 }
示例#25
0
 public static Array call(PageContext pc, QueryColumn column) throws PageException {
   Array arr = new ArrayImpl();
   int size = column.size();
   for (int i = 1; i <= size; i++) {
     arr.append(Caster.toString(column.get(i, null)));
   }
   return arr;
 }
示例#26
0
文件: List.java 项目: Fusegrid/railo
  /**
   * cast a Object Array to a String Array
   *
   * @param array
   * @return String Array
   */
  public static String[] toStringArrayEL(Array array) {
    String[] arr = new String[array.size()];
    for (int i = 0; i < arr.length; i++) {
      arr[i] = Caster.toString(array.get(i + 1, null), null);
    }

    return arr;
  }
示例#27
0
  public static String call(PageContext pc, Object name, Object image, double x, double y)
      throws PageException {
    if (name instanceof String) name = pc.getVariable(Caster.toString(name));
    Image img = Image.toImage(name);

    img.drawImage(Image.createImage(pc, image, true, false, true), (int) x, (int) y);
    return null;
  }
示例#28
0
文件: List.java 项目: Fusegrid/railo
  /**
   * trim every single item of the array
   *
   * @param arr
   * @return
   * @throws PageException
   */
  public static Array trimItems(Array arr) throws PageException {
    Key[] keys = arr.keys();

    for (int i = 0; i < keys.length; i++) {
      arr.setEL(keys[i], Caster.toString(arr.get(keys[i], null)).trim());
    }
    return arr;
  }
示例#29
0
文件: List.java 项目: Fusegrid/railo
  /**
   * cast a Object Array to a String Array
   *
   * @param array
   * @param defaultValue
   * @return String Array
   */
  public static String[] toStringArray(Array array, String defaultValue) {
    String[] arr = new String[array.size()];
    for (int i = 0; i < arr.length; i++) {
      arr[i] = Caster.toString(array.get(i + 1, defaultValue), defaultValue);
    }

    return arr;
  }
示例#30
0
文件: IsIPv6.java 项目: ringgi/railo
 public static boolean call(PageContext pc) throws PageException {
   try {
     InetAddress ia = InetAddress.getLocalHost();
     InetAddress[] ias = InetAddress.getAllByName(ia.getHostName());
     return _call(ias);
   } catch (UnknownHostException e) {
     throw Caster.toPageException(e);
   }
 }