예제 #1
1
  /** @return returns a string list of all pathes */
  public static Resource[] getClassPathes() {

    if (classPathes != null) return classPathes;

    ArrayList pathes = new ArrayList();
    String pathSeperator = System.getProperty("path.separator");
    if (pathSeperator == null) pathSeperator = ";";

    // java.ext.dirs
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();

    // pathes from system properties
    String strPathes = System.getProperty("java.class.path");
    if (strPathes != null) {
      Array arr = ListUtil.listToArrayRemoveEmpty(strPathes, pathSeperator);
      int len = arr.size();
      for (int i = 1; i <= len; i++) {
        Resource file = frp.getResource(Caster.toString(arr.get(i, ""), "").trim());
        if (file.exists()) pathes.add(ResourceUtil.getCanonicalResourceEL(file));
      }
    }

    // pathes from url class Loader (dynamic loaded classes)
    ClassLoader cl = new Info().getClass().getClassLoader();
    if (cl instanceof URLClassLoader) getClassPathesFromClassLoader((URLClassLoader) cl, pathes);

    return classPathes = (Resource[]) pathes.toArray(new Resource[pathes.size()]);
  }
예제 #2
0
 @Override
 public Object invoke(PageContext pc, Object[] args) throws PageException {
   if (args.length == 2) return call(pc, Caster.toQuery(args[0]), Caster.toString(args[1]));
   if (args.length == 3)
     return call(pc, Caster.toQuery(args[0]), Caster.toString(args[1]), args[2]);
   return call(pc, Caster.toQuery(args[0]), Caster.toString(args[1]), args[2], args[3]);
 }
예제 #3
0
파일: ListLast.java 프로젝트: denuno/Lucee4
  @Override
  public Object invoke(PageContext pc, Object[] args) throws PageException {
    if (args.length == 1) return call(pc, Caster.toString(args[0]));
    if (args.length == 2) return call(pc, Caster.toString(args[0]), Caster.toString(args[1]));
    if (args.length == 3)
      return call(
          pc, Caster.toString(args[0]), Caster.toString(args[1]), Caster.toBooleanValue(args[2]));

    throw new FunctionException(pc, "ListFirst", 1, 3, args.length);
  }
예제 #4
0
파일: FDUDF.java 프로젝트: denuno/Lucee4
  /**
   * Constructor of the class
   *
   * @param name
   * @param coll
   */
  public FDUDF(IFDStackFrame frame, String name, UDF udf) {
    this.name = name;
    this.udf = udf;

    // meta
    List<FDSimpleVariable> list = new ArrayList<FDSimpleVariable>();
    children.add(new FDSimpleVariable(frame, "Meta Data", "", list));
    list.add(new FDSimpleVariable(frame, "Function Name", udf.getFunctionName(), null));
    if (!StringUtil.isEmpty(udf.getDisplayName()))
      list.add(new FDSimpleVariable(frame, "Display Name", udf.getDisplayName(), null));
    if (!StringUtil.isEmpty(udf.getDescription()))
      list.add(new FDSimpleVariable(frame, "Description", udf.getDescription(), null));
    if (!StringUtil.isEmpty(udf.getHint()))
      list.add(new FDSimpleVariable(frame, "Hint", udf.getHint(), null));
    list.add(new FDSimpleVariable(frame, "Return Type", udf.getReturnTypeAsString(), null));
    list.add(
        new FDSimpleVariable(
            frame, "Return Format", UDFUtil.toReturnFormat(udf.getReturnFormat(), "plain"), null));
    list.add(
        new FDSimpleVariable(
            frame, "Source", Caster.toString(udf.getPageSource().getDisplayPath()), null));
    list.add(
        new FDSimpleVariable(frame, "Secure Json", Caster.toString(udf.getSecureJson(), ""), null));
    list.add(
        new FDSimpleVariable(
            frame, "Verify Client", Caster.toString(udf.getVerifyClient(), ""), null));

    // arguments
    list = new ArrayList();
    List el;
    children.add(new FDSimpleVariable(frame, "Arguments", "", list));
    FunctionArgument[] args = udf.getFunctionArguments();
    for (int i = 0; i < args.length; i++) {
      el = new ArrayList();
      list.add(new FDSimpleVariable(frame, "[" + (i + 1) + "]", "", el));
      el.add(new FDSimpleVariable(frame, "Name", args[i].getName().getString(), null));
      el.add(new FDSimpleVariable(frame, "Type", args[i].getTypeAsString(), null));
      el.add(new FDSimpleVariable(frame, "Required", Caster.toString(args[i].isRequired()), null));

      if (!StringUtil.isEmpty(args[i].getDisplayName()))
        el.add(new FDSimpleVariable(frame, "Display Name", args[i].getDisplayName(), null));
      if (!StringUtil.isEmpty(args[i].getHint()))
        el.add(new FDSimpleVariable(frame, "Hint", args[i].getHint(), null));
    }

    // return
    children.add(new FDSimpleVariable(frame, "return", udf.getReturnTypeAsString(), null));
  }
예제 #5
0
 String callStringRTE(PageContext pc, Component cfc, String methodName, Object[] args) {
   try {
     return Caster.toString(call(pc, cfc, methodName, args));
   } catch (PageException pe) {
     throw new PageRuntimeException(pe);
   }
 }
예제 #6
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;
  }
예제 #7
0
  @Override
  public ResourceProvider init(String scheme, Map args) {
    this.scheme = scheme;
    this.args = args;

    // CFC Path
    cfcPath = Caster.toString(args.get("cfc"), null);
    if (StringUtil.isEmpty(cfcPath, true)) cfcPath = Caster.toString(args.get("component"), null);
    cfcPath = ConfigWebUtil.fixComponentPath(cfcPath);

    // use Streams for data
    Boolean _useStreams = Caster.toBoolean(args.get("use-streams"), null);
    if (_useStreams == null) _useStreams = Caster.toBoolean(args.get("usestreams"), null);

    if (_useStreams != null) useStreams = _useStreams.booleanValue();

    return this;
  }
예제 #8
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();
 }
예제 #9
0
  @Override
  public Object setE(int intKey, Object value) throws PageException {

    if (intKey > size()) {
      return set(Caster.toString(intKey), value);
    }
    // Iterator it = keyIterator();
    Key[] keys = keys();
    for (int i = 0; i < keys.length; i++) {
      if ((i + 1) == intKey) {
        return super.set(keys[i], value);
      }
    }
    throw new ExpressionException("invalid index [" + intKey + "] for argument scope");
  }
예제 #10
0
  @Override
  public Object setEL(int intKey, Object value) {
    int count = 0;

    if (intKey > size()) {
      return setEL(Caster.toString(intKey), value);
    }
    // Iterator it = keyIterator();
    Key[] keys = keys();
    for (int i = 0; i < keys.length; i++) {
      if ((++count) == intKey) {
        return super.setEL(keys[i], value);
      }
    }
    return value;
  }
  private static SQLItem toSQLItem(Object value) throws PageException {
    if (Decision.isStruct(value)) {
      Struct sct = (Struct) value;
      // name (optional)
      String name = null;
      Object oName = sct.get(KeyConstants._name, null);
      if (oName != null) name = Caster.toString(oName);

      // value (required)
      value = sct.get(KeyConstants._value);

      if (StringUtil.isEmpty(name)) return fill(new SQLItemImpl(value, Types.VARCHAR), sct);

      return fill(new NamedSQLItem(name, value, Types.VARCHAR), sct);
    }
    return new SQLItemImpl(value);
  }
  private static SQLItem fill(SQLItem item, Struct sct) throws DatabaseException, PageException {
    // type (optional)
    Object oType = sct.get(KeyConstants._cfsqltype, null);
    if (oType == null) oType = sct.get(KeyConstants._sqltype, null);
    if (oType == null) oType = sct.get(KeyConstants._type, null);
    if (oType != null) {
      item.setType(SQLCaster.toSQLType(Caster.toString(oType)));
    }

    // nulls (optional)
    Object oNulls = sct.get(KeyConstants._nulls, null);
    if (oNulls != null) {
      item.setNulls(Caster.toBooleanValue(oNulls));
    }

    // scale (optional)
    Object oScale = sct.get(KeyConstants._scale, null);
    if (oScale != null) {
      item.setScale(Caster.toIntValue(oScale));
    }

    /* list
    if(Caster.toBooleanValue(sct.get("list",null),false)) {
    	String separator=Caster.toString(sct.get("separator",null),",");
    	String v = Caster.toString(item.getValue());
       	Array arr=null;
       	if(StringUtil.isEmpty(v)){
       		arr=new ArrayImpl();
       		arr.append("");
       	}
       	else arr=ListUtil.listToArrayRemoveEmpty(v,separator);

    	int len=arr.size();
    	StringBuilder sb=new StringBuilder();
    	for(int i=1;i<=len;i++) {
    	    query.setParam(item.clone(check(arr.getE(i))));
            if(i>1)sb.append(',');
            sb.append('?');
    	}
    	write(sb.toString());
    }*/
    return item;
  }
예제 #13
0
파일: Right.java 프로젝트: denuno/Lucee4
 @Override
 public Object invoke(PageContext pc, Object[] args) throws PageException {
   if (args.length == 2) return call(pc, Caster.toString(args[0]), Caster.toDoubleValue(args[1]));
   throw new FunctionException(pc, "Right", 2, 2, args.length);
 }
예제 #14
0
  @Override
  public Object invoke(PageContext pc, Object[] args) throws PageException {
    if (args.length == 2) return call(pc, Caster.toString(args[0]), Caster.toString(args[1]));
    if (args.length == 3)
      return call(pc, Caster.toString(args[0]), Caster.toString(args[1]), Caster.toString(args[2]));
    if (args.length == 4)
      return call(
          pc,
          Caster.toString(args[0]),
          Caster.toString(args[1]),
          Caster.toString(args[2]),
          Caster.toBooleanValue(args[3]));
    if (args.length == 5)
      return call(
          pc,
          Caster.toString(args[0]),
          Caster.toString(args[1]),
          Caster.toString(args[2]),
          Caster.toBooleanValue(args[3]),
          Caster.toBooleanValue(args[4]));

    throw new FunctionException(pc, "ListContainsNoCase", 2, 5, args.length);
  }
예제 #15
0
 @Override
 public Object append(Object o) throws PageException {
   return set(Caster.toString(size() + 1), o);
 }
예제 #16
0
 @Override
 public Object invoke(PageContext pc, Object[] args) throws PageException {
   if (args.length == 1) return call(pc, Caster.toDatetime(args[0], pc.getTimeZone()));
   return call(pc, Caster.toDatetime(args[0], pc.getTimeZone()), Caster.toString(args[1]));
 }
예제 #17
0
 String callString(PageContext pc, Component cfc, String methodName, Object[] args)
     throws PageException {
   return Caster.toString(call(pc, cfc, methodName, args));
 }
예제 #18
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) {
    }
  }