コード例 #1
0
ファイル: Ftp.java プロジェクト: dajester2013/Lucee
  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;
  }
コード例 #2
0
  @Override
  public final Query getCollectionsAsQuery() {
    final String v = "VARCHAR";
    Query query = null;
    String[] cols =
        new String[] {
          "external",
          "language",
          "mapped",
          "name",
          "online",
          "path",
          "registered",
          "lastmodified",
          "categories",
          "charset",
          "created",
          "size",
          "doccount"
        };
    String[] types =
        new String[] {
          "BOOLEAN", v, "BOOLEAN", v, "BOOLEAN", v, v, "DATE", "BOOLEAN", v, "OBJECT", "DOUBLE",
          "DOUBLE"
        };
    try {
      query = engine.getCreationUtil().createQuery(cols, types, collections.size(), "query");
    } catch (PageException e) {
      query = engine.getCreationUtil().createQuery(cols, collections.size(), "query");
    }

    // Collection.Key[] keys = collections.keys();
    Iterator<Object> it = collections.valueIterator();
    int i = -1;
    while (it.hasNext()) {
      i++;
      try {
        SearchCollection coll = (SearchCollection) it.next();
        query.setAt("external", i + 1, Boolean.FALSE);
        query.setAt("charset", i + 1, "UTF-8");
        query.setAt("created", i + 1, coll.created());

        query.setAt("categories", i + 1, Boolean.TRUE);
        query.setAt("language", i + 1, coll.getLanguage());
        query.setAt("mapped", i + 1, Boolean.FALSE);
        query.setAt("name", i + 1, coll.getName());
        query.setAt("online", i + 1, Boolean.TRUE);
        query.setAt("path", i + 1, coll.getPath().getAbsolutePath());
        query.setAt("registered", i + 1, "CF");
        query.setAt("lastmodified", i + 1, coll.getLastUpdate());
        query.setAt("size", i + 1, new Double(coll.getSize()));
        query.setAt("doccount", i + 1, new Double(coll.getDocumentCount()));
      } catch (PageException pe) {
      }
    }
    return query;
  }
コード例 #3
0
ファイル: Search.java プロジェクト: dajester2013/Lucee
  @Override
  public int doStartTag() throws PageException {
    // SerialNumber sn = pageContext.getConfig().getSerialNumber();
    // if(sn.getVersion()==SerialNumber.VERSION_COMMUNITY)
    //    throw new SecurityException("no access to this functionality with the
    // "+sn.getStringVersion()+" version of Lucee");
    final String v = "VARCHAR", d = "DOUBLE";
    String[] cols =
        new String[] {
          "title",
          "url",
          "summary",
          "score",
          "recordssearched",
          "key",
          "custom1",
          "custom2",
          "custom3",
          "custom4",
          "categoryTree",
          "category",
          "context",
          "size",
          "rank",
          "author",
          "type",
          "collection"
        };

    // TODO support context
    String[] types = new String[] {v, v, v, d, d, v, v, v, v, v, v, v, v, d, d, v, v, v};
    SearchData data =
        pageContext.getConfig().getSearchEngine(pageContext).createSearchData(suggestions);
    SuggestionItem item =
        null; // this is already here to make sure the classloader load this sinstance

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

    SearchCollection collection;
    long time = System.currentTimeMillis();
    AddionalAttrs.setAddionalAttrs(
        contextBytes, contextPassages, contextHighlightBegin, contextHighlightEnd);
    try {
      for (int i = 0; i < collections.length; i++) {
        collection = collections[i];
        startrow =
            collection.search(
                data,
                qry,
                criteria,
                collection.getLanguage(),
                type,
                startrow,
                maxrows,
                categoryTree,
                category);

        if (maxrows >= 0 && qry.getRecordcount() >= maxrows) break;
      }
      pageContext.setVariable(name, qry);
    } catch (SearchException se) {
      throw Caster.toPageException(se);
    } finally {
      AddionalAttrs.removeAddionalAttrs();
    }

    time = System.currentTimeMillis() - time;
    Double recSearched = new Double(data.getRecordsSearched());
    int len = qry.getRecordcount();
    for (int i = 1; i <= len; i++) {
      qry.setAt("recordssearched", i, recSearched);
    }

    // status
    if (status != null) {
      Struct sct = new StructImpl();
      pageContext.setVariable(status, sct);
      sct.set(FOUND, new Double(qry.getRecordcount()));
      sct.set(SEARCHED, recSearched);
      sct.set(KeyConstants._time, new Double(time));

      // TODO impl this values

      Map s = data.getSuggestion();
      if (s.size() > 0) {
        String key;

        Iterator it = s.keySet().iterator();
        Struct keywords = new StructImpl();
        Struct keywordScore = new StructImpl();
        sct.set(KEYWORDS, keywords);
        sct.set(KEYWORD_SCORE, keywordScore);
        Object obj;

        while (it.hasNext()) {
          key = (String) it.next();

          // the problem is a conflict between the SuggestionItem version from core and extension
          obj = s.get(key);
          if (obj instanceof SuggestionItem) {
            item = (SuggestionItem) obj;
            keywords.set(key, item.getKeywords());
            keywordScore.set(key, item.getKeywordScore());
          } else {
            Class clazz = obj.getClass();
            try {
              keywords.set(
                  key, clazz.getMethod("getKeywords", new Class[0]).invoke(obj, new Object[0]));
              keywordScore.set(
                  key, clazz.getMethod("getKeywordScore", new Class[0]).invoke(obj, new Object[0]));
            } catch (Exception e) {
            }
          }
        }

        String query = data.getSuggestionQuery();
        if (query != null) {
          String html = StringUtil.replace(query, "<suggestion>", "<b>", false);
          html = StringUtil.replace(html, "</suggestion>", "</b>", false);
          sct.set("suggestedQueryHTML", html);

          String plain = StringUtil.replace(query, "<suggestion>", "", false);
          plain = StringUtil.replace(plain, "</suggestion>", "", false);
          sct.set("suggestedQuery", plain);
        }
      }

      // if(suggestions!=SUGGESTIONS_NEVER)sct.set("suggestedQuery", "");
      // sct.set("keywords", "");
      // sct.set("keywordScore", "");

    }

    return SKIP_BODY;
  }
コード例 #4
0
ファイル: Schedule.java プロジェクト: dajester2013/Lucee
  /** @throws PageException */
  private void doList() throws PageException {
    // if(tr ue) throw new PageRuntimeException("qqq");
    ScheduleTask[] tasks = scheduler.getAllScheduleTasks();
    final String v = "VARCHAR";
    String[] cols =
        new String[] {
          "task",
          "path",
          "file",
          "startdate",
          "starttime",
          "enddate",
          "endtime",
          "url",
          "port",
          "interval",
          "timeout",
          "username",
          "password",
          "proxyserver",
          "proxyport",
          "proxyuser",
          "proxypassword",
          "resolveurl",
          "publish",
          "valid",
          "paused",
          "autoDelete"
        };
    String[] types =
        new String[] {
          v, v, v, "DATE", "OTHER", "DATE", "OTHER", v, v, v, v, v, v, v, v, v, v, v, "BOOLEAN", v,
          "BOOLEAN", "BOOLEAN"
        };
    lucee.runtime.type.Query query = new QueryImpl(cols, types, tasks.length, "query");
    try {
      for (int i = 0; i < tasks.length; i++) {
        int row = i + 1;
        ScheduleTask task = tasks[i];
        query.setAt(KeyConstants._task, row, task.getTask());
        if (task.getResource() != null) {
          query.setAt(KeyConstants._path, row, task.getResource().getParent());
          query.setAt(KeyConstants._file, row, task.getResource().getName());
        }
        query.setAt("publish", row, Caster.toBoolean(task.isPublish()));
        query.setAt("startdate", row, task.getStartDate());
        query.setAt("starttime", row, task.getStartTime());
        query.setAt("enddate", row, task.getEndDate());
        query.setAt("endtime", row, task.getEndTime());
        query.setAt(KeyConstants._url, row, printUrl(task.getUrl()));
        query.setAt(KeyConstants._port, row, Caster.toString(HTTPUtil.getPort(task.getUrl())));
        query.setAt("interval", row, task.getStringInterval());
        query.setAt("timeout", row, Caster.toString(task.getTimeout() / 1000));
        query.setAt("valid", row, Caster.toString(task.isValid()));
        if (task.hasCredentials()) {
          query.setAt("username", row, task.getCredentials().getUsername());
          query.setAt("password", row, task.getCredentials().getPassword());
        }
        ProxyData pd = task.getProxyData();
        if (ProxyDataImpl.isValid(pd)) {
          query.setAt("proxyserver", row, pd.getServer());
          if (pd.getPort() > 0) query.setAt("proxyport", row, Caster.toString(pd.getPort()));
          if (ProxyDataImpl.hasCredentials(pd)) {
            query.setAt("proxyuser", row, pd.getUsername());
            query.setAt("proxypassword", row, pd.getPassword());
          }
        }
        query.setAt("resolveurl", row, Caster.toString(task.isResolveURL()));

        query.setAt("paused", row, Caster.toBoolean(task.isPaused()));
        query.setAt("autoDelete", row, Caster.toBoolean(((ScheduleTaskImpl) task).isAutoDelete()));
      }
      pageContext.setVariable(returnvariable, query);
    } catch (DatabaseException e) {
    }
  }