Esempio n. 1
0
 public static double call(
     PageContext pc, Query query, String string, Object datatype, Object array)
     throws PageException {
   if (datatype == null) return call(pc, query, string, array);
   query.addColumn(
       KeyImpl.init(string),
       Caster.toArray(array),
       SQLCaster.toSQLType(Caster.toString(datatype)));
   return query.size();
 }
Esempio n. 2
0
 @Override
 public Object getValue(Query qr, int row, Object defaultValue) {
   if (col == null) {
     col = qr.getColumn(getColumn(), null);
     if (col == null) return defaultValue;
   }
   return col.get(row, defaultValue);
 }
Esempio n. 3
0
 private static boolean invoke(
     PageContext pc, Query qry, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures)
     throws CasterException, PageException {
   final int pid = pc.getId();
   ForEachQueryIterator it = new ForEachQueryIterator(qry, pid);
   boolean async = es != null;
   double r;
   Object res, row;
   try {
     while (it.hasNext()) {
       row = it.next();
       r = Caster.toDoubleValue(qry.getCurrentrow(pid));
       res = _inv(pc, udf, new Object[] {row, r, qry}, r, row, es, futures);
       if (!async && !Caster.toBooleanValue(res)) {
         return false;
       }
     }
   } finally {
     it.reset();
   }
   return true;
 }
Esempio n. 4
0
  public static Query getMemoryUsageAsQuery(int type) throws DatabaseException {

    java.util.List<MemoryPoolMXBean> manager = ManagementFactory.getMemoryPoolMXBeans();
    Iterator<MemoryPoolMXBean> it = manager.iterator();
    Query qry =
        new QueryImpl(
            new Collection.Key[] {
              KeyConstants._name,
              KeyConstants._type,
              KeyConstants._used,
              KeyConstants._max,
              KeyConstants._init
            },
            0,
            "memory");

    int row = 0;
    MemoryPoolMXBean bean;
    MemoryUsage usage;
    MemoryType _type;
    while (it.hasNext()) {
      bean = it.next();
      usage = bean.getUsage();
      _type = bean.getType();
      if (type == MEMORY_TYPE_HEAP && _type != MemoryType.HEAP) continue;
      if (type == MEMORY_TYPE_NON_HEAP && _type != MemoryType.NON_HEAP) continue;

      row++;
      qry.addRow();
      qry.setAtEL(KeyConstants._name, row, bean.getName());
      qry.setAtEL(KeyConstants._type, row, _type.name());
      qry.setAtEL(KeyConstants._max, row, Caster.toDouble(usage.getMax()));
      qry.setAtEL(KeyConstants._used, row, Caster.toDouble(usage.getUsed()));
      qry.setAtEL(KeyConstants._init, row, Caster.toDouble(usage.getInit()));
    }
    return qry;
  }
Esempio n. 5
0
 // MUST hanle null correctly
 @Override
 public Object getValue(Query qr, int row) throws PageException {
   if (col == null) col = qr.getColumn(getColumn());
   return QueryUtil.getValue(col, row);
 }
  @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;
  }
Esempio n. 7
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;
  }
Esempio n. 8
0
  @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;
  }
Esempio n. 9
0
 public static double call(PageContext pc, Query query, String string, Object array)
     throws PageException {
   query.addColumn(KeyImpl.init(string), Caster.toArray(array));
   return query.size();
 }
Esempio n. 10
0
  /** @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) {
    }
  }