示例#1
0
  public static lucee.runtime.type.Query toQuery(
      FTPFile[] files, String prefix, String directory, String hostName) throws PageException {

    String[] cols =
        new String[] {
          "name",
          "isdirectory",
          "lastmodified",
          "length",
          "mode",
          "path",
          "url",
          "type",
          "raw",
          "attributes"
        };
    String[] types =
        new String[] {
          "VARCHAR", "BOOLEAN", "DATE", "DOUBLE", "VARCHAR", "VARCHAR", "VARCHAR", "VARCHAR",
          "VARCHAR", "VARCHAR"
        };

    lucee.runtime.type.Query query = new QueryImpl(cols, types, 0, "query");

    // translate directory path for display
    if (directory.length() == 0) directory = "/";
    else if (directory.startsWith("./")) directory = directory.substring(1);
    else if (directory.charAt(0) != '/') directory = '/' + directory;
    if (directory.charAt(directory.length() - 1) != '/') directory = directory + '/';

    int row;
    for (int i = 0; i < files.length; i++) {
      FTPFile file = files[i];
      if (file.getName().equals(".") || file.getName().equals("..")) continue;
      row = query.addRow();
      query.setAt("attributes", row, "");
      query.setAt("isdirectory", row, Caster.toBoolean(file.isDirectory()));
      query.setAt("lastmodified", row, new DateTimeImpl(file.getTimestamp()));
      query.setAt("length", row, Caster.toDouble(file.getSize()));
      query.setAt("mode", row, FTPConstant.getPermissionASInteger(file));
      query.setAt("type", row, FTPConstant.getTypeAsString(file.getType()));
      // query.setAt("permission",row,FTPConstant.getPermissionASInteger(file));
      query.setAt("raw", row, file.getRawListing());
      query.setAt("name", row, file.getName());
      query.setAt("path", row, directory + file.getName());
      query.setAt("url", row, prefix + "://" + hostName + "" + directory + file.getName());
    }
    return query;
  }