Exemple #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()]);
  }
Exemple #2
0
  @Override
  public Object callWithNamedValues(PageContext pageContext, Struct values, boolean doIncludePath)
      throws PageException {
    ArrayList<FunctionLibFunctionArg> flfas = flf.getArg();
    Iterator<FunctionLibFunctionArg> it = flfas.iterator();
    FunctionLibFunctionArg arg;
    Object val;

    List<Ref> refs = new ArrayList<Ref>();
    while (it.hasNext()) {
      arg = it.next();

      // match by name
      val = values.get(arg.getName(), null);

      // match by alias
      if (val == null) {
        String alias = arg.getAlias();
        if (!StringUtil.isEmpty(alias, true)) {
          String[] aliases =
              lucee.runtime.type.util.ListUtil.trimItems(
                  lucee.runtime.type.util.ListUtil.listToStringArray(alias, ','));
          for (int x = 0; x < aliases.length; x++) {
            val = values.get(aliases[x], null);
            if (val != null) break;
          }
        }
      }

      if (val == null) {
        if (arg.getRequired()) {
          String[] names = flf.getMemberNames();
          String n = ArrayUtil.isEmpty(names) ? "" : names[0];
          throw new ExpressionException(
              "missing required argument ["
                  + arg.getName()
                  + "] for build in function call ["
                  + n
                  + "]");
        }
      } else {
        refs.add(
            new Casting(
                arg.getTypeAsString(),
                arg.getType(),
                new LFunctionValue(new LString(arg.getName()), val)));
      }
    }

    BIFCall call = new BIFCall(flf, refs.toArray(new Ref[refs.size()]));
    return call.getValue(pageContext);
  }
Exemple #3
0
 /**
  * set the value collection The logical collection name that is the target of the search operation
  * or an external collection with fully qualified path.
  *
  * @param collection value to set
  * @throws PageException
  */
 public void setCollection(String collection) throws PageException {
   String[] collNames =
       ListUtil.toStringArrayTrim(ListUtil.listToArrayRemoveEmpty(collection, ','));
   collections = new SearchCollection[collNames.length];
   SearchEngine se = pageContext.getConfig().getSearchEngine(pageContext);
   try {
     for (int i = 0; i < collections.length; i++) {
       collections[i] = se.getCollectionByName(collNames[i]);
     }
   } catch (SearchException e) {
     collections = null;
     throw Caster.toPageException(e);
   }
 }
Exemple #4
0
  private static boolean invoke(
      PageContext pc,
      StringListData sld,
      UDF udf,
      ExecutorService es,
      List<Future<Data<Object>>> futures)
      throws CasterException, PageException {
    Array arr =
        ListUtil.listToArray(
            sld.list, sld.delimiter, sld.includeEmptyFieldsx, sld.multiCharacterDelimiter);

    Iterator<Entry<Key, Object>> it = arr.entryIterator();
    Entry<Key, Object> e;
    boolean async = es != null;
    Object res;
    while (it.hasNext()) {
      e = it.next();
      res =
          _inv(
              pc,
              udf,
              new Object[] {
                e.getValue(), Caster.toDoubleValue(e.getKey().getString()), sld.list, sld.delimiter
              },
              e.getKey(),
              e.getValue(),
              es,
              futures);
      if (!async && !Caster.toBooleanValue(res)) {
        return false;
      }
    }
    return true;
  }
Exemple #5
0
  @Override
  public Object get(Collection.Key key) throws ExpressionException {
    /*if(NullSupportHelper.full()) {
    	Object o=super.get(key,NullSupportHelper.NULL());
    	if(o!=NullSupportHelper.NULL())return o;

    	o=get(Caster.toIntValue(key.getString(),-1),NullSupportHelper.NULL());
    	if(o!=NullSupportHelper.NULL())return o;
    	throw new ExpressionException("key ["+key.getString()+"] doesn't exist in argument scope. existing keys are ["+
    			lucee.runtime.type.List.arrayToList(CollectionUtil.keys(this),", ")
    			+"]");
    }*/

    // null is supported as returned value with argument scope
    Object o = super.g(key, Null.NULL);
    if (o != Null.NULL) return o;

    o = get(Caster.toIntValue(key.getString(), -1), Null.NULL);
    if (o != Null.NULL) return o;

    throw new ExpressionException(
        "key ["
            + key.getString()
            + "] doesn't exist in argument scope. existing keys are ["
            + lucee.runtime.type.util.ListUtil.arrayToList(CollectionUtil.keys(this), ", ")
            + "]");
  }
 public static double call(
     PageContext pc,
     String list,
     String value,
     String delimter,
     boolean includeEmptyFields,
     boolean multiCharacterDelimiter) {
   return ListUtil.listContainsNoCase(
           list, value, delimter, includeEmptyFields, multiCharacterDelimiter)
       + 1;
 }
Exemple #7
0
 /**
  * get FTP. ... _FILE_TYPE
  *
  * @param file
  * @return type
  */
 private int getType(Resource file) {
   if (transferMode == FTPConstant.TRANSFER_MODE_BINARY) return AFTPClient.FILE_TYPE_BINARY;
   else if (transferMode == FTPConstant.TRANSFER_MODE_ASCCI) return AFTPClient.FILE_TYPE_TEXT;
   else {
     String ext = ResourceUtil.getExtension(file, null);
     if (ext == null
         || ListUtil.listContainsNoCase(ASCIIExtensionList, ext, ";", true, false) == -1)
       return AFTPClient.FILE_TYPE_BINARY;
     return AFTPClient.FILE_TYPE_TEXT;
   }
 }
Exemple #8
0
 /** @return return System directory */
 public static Resource getSystemDirectory() {
   String pathes = System.getProperty("java.library.path");
   ResourceProvider fr = ResourcesImpl.getFileResourceProvider();
   if (pathes != null) {
     String[] arr = ListUtil.toStringArrayEL(ListUtil.listToArray(pathes, File.pathSeparatorChar));
     for (int i = 0; i < arr.length; i++) {
       if (arr[i].toLowerCase().indexOf("windows\\system") != -1) {
         Resource file = fr.getResource(arr[i]);
         if (file.exists() && file.isDirectory() && file.isWriteable())
           return ResourceUtil.getCanonicalResourceEL(file);
       }
     }
     for (int i = 0; i < arr.length; i++) {
       if (arr[i].toLowerCase().indexOf("windows") != -1) {
         Resource file = fr.getResource(arr[i]);
         if (file.exists() && file.isDirectory() && file.isWriteable())
           return ResourceUtil.getCanonicalResourceEL(file);
       }
     }
     for (int i = 0; i < arr.length; i++) {
       if (arr[i].toLowerCase().indexOf("winnt") != -1) {
         Resource file = fr.getResource(arr[i]);
         if (file.exists() && file.isDirectory() && file.isWriteable())
           return ResourceUtil.getCanonicalResourceEL(file);
       }
     }
     for (int i = 0; i < arr.length; i++) {
       if (arr[i].toLowerCase().indexOf("win") != -1) {
         Resource file = fr.getResource(arr[i]);
         if (file.exists() && file.isDirectory() && file.isWriteable())
           return ResourceUtil.getCanonicalResourceEL(file);
       }
     }
     for (int i = 0; i < arr.length; i++) {
       Resource file = fr.getResource(arr[i]);
       if (file.exists() && file.isDirectory() && file.isWriteable())
         return ResourceUtil.getCanonicalResourceEL(file);
     }
   }
   return null;
 }
Exemple #9
0
  public static String[] splitTypeAndSubType(String mimetype) {
    String[] types = ListUtil.listToStringArray(mimetype, '/');
    String[] rtn = new String[2];

    if (types.length > 0) {
      rtn[0] = types[0].trim();
      if (types.length > 1) {
        rtn[1] = types[1].trim();
      }
    }
    return rtn;
  }
Exemple #10
0
  // MUST create a copy from toURL and rename toURI and rewrite for URI, pherhaps it is possible to
  // merge them somehow
  public static String encode(String relpath) {

    int qIndex = relpath.indexOf('?');

    if (qIndex == -1) return relpath;

    String file = relpath.substring(0, qIndex);
    String query = relpath.substring(qIndex + 1);
    int sIndex = query.indexOf('#');

    String anker = null;
    if (sIndex != -1) {
      // print.o(sIndex);
      anker = query.substring(sIndex + 1);
      query = query.substring(0, sIndex);
    }

    StringBuilder res = new StringBuilder(file);

    // query
    if (!StringUtil.isEmpty(query)) {

      StringList list = ListUtil.toList(query, '&');
      String str;
      int index;
      char del = '?';
      while (list.hasNext()) {
        res.append(del);
        del = '&';
        str = list.next();
        index = str.indexOf('=');
        if (index == -1) res.append(escapeQSValue(str));
        else {
          res.append(escapeQSValue(str.substring(0, index)));
          res.append('=');
          res.append(escapeQSValue(str.substring(index + 1)));
        }
      }
    }

    // anker
    if (anker != null) {
      res.append('#');
      res.append(escapeQSValue(anker));
    }

    return res.toString();
  }
Exemple #11
0
 public static Map<String, String> parseParameterList(
     String _str, boolean decode, String charset) {
   // return lucee.commons.net.HTTPUtil.toURI(strUrl,port);
   Map<String, String> data = new HashMap<String, String>();
   StringList list = ListUtil.toList(_str, '&');
   String str;
   int index;
   while (list.hasNext()) {
     str = list.next();
     index = str.indexOf('=');
     if (index == -1) {
       data.put(decode(str, decode), "");
     } else {
       data.put(decode(str.substring(0, index), decode), decode(str.substring(index + 1), decode));
     }
   }
   return data;
 }
Exemple #12
0
  private static String decodeQuery(String query, char startDelimiter) {
    if (!StringUtil.isEmpty(query)) {
      StringBuilder res = new StringBuilder();

      StringList list = ListUtil.toList(query, '&');
      String str;
      int index;
      char del = startDelimiter;
      while (list.hasNext()) {
        res.append(del);
        del = '&';
        str = list.next();
        index = str.indexOf('=');
        if (index == -1) res.append(escapeQSValue(str));
        else {
          res.append(escapeQSValue(str.substring(0, index)));
          res.append('=');
          res.append(escapeQSValue(str.substring(index + 1)));
        }
      }
      query = res.toString();
    } else query = "";
    return query;
  }
Exemple #13
0
 public static String call(
     PageContext pc, String list, String delimiter, boolean includeEmptyFields) {
   return ListUtil.last(list, delimiter, !includeEmptyFields);
 }
Exemple #14
0
 public static String call(PageContext pc, String list, String delimiter) {
   return ListUtil.last(list, delimiter, true);
 }
Exemple #15
0
 public static String call(PageContext pc, String list) {
   return ListUtil.last(list, ",", true);
 }
 public static double call(
     PageContext pc, String list, String value, String delimter, boolean includeEmptyFields) {
   if (includeEmptyFields) return ListUtil.listFindNoCase(list, value, delimter) + 1;
   return ListUtil.listFindNoCaseIgnoreEmpty(list, value, delimter) + 1;
 }
Exemple #17
0
 /**
  * @param category the category to set
  * @throws ApplicationException
  */
 public void setCategory(String listCategories) {
   if (StringUtil.isEmpty(listCategories)) return;
   this.category = ListUtil.trimItems(ListUtil.listToStringArray(listCategories, ','));
 }
Exemple #18
0
  public static URI toURI(String strUrl, int port) throws URISyntaxException {

    // print.o((strUrl));
    URI uri = new URI(strUrl);

    String host = uri.getHost();
    String fragment = uri.getRawFragment();
    String path = uri.getRawPath();
    String query = uri.getRawQuery();

    String scheme = uri.getScheme();
    String userInfo = uri.getRawUserInfo();
    if (port <= 0) port = uri.getPort();

    // decode path
    if (!StringUtil.isEmpty(path)) {

      int sqIndex = path.indexOf(';');
      String q = null;
      if (sqIndex != -1) {
        q = path.substring(sqIndex + 1);
        path = path.substring(0, sqIndex);
      }

      StringBuilder res = new StringBuilder();

      StringList list = ListUtil.toListTrim(path, '/');
      String str;

      while (list.hasNext()) {
        str = list.next();
        // str=URLDecoder.decode(str);

        if (StringUtil.isEmpty(str)) continue;
        res.append("/");
        res.append(escapeQSValue(str));
      }
      if (StringUtil.endsWith(path, '/')) res.append('/');
      path = res.toString();

      if (sqIndex != -1) {
        path += decodeQuery(q, ';');
      }
    }

    // decode query
    query = decodeQuery(query, '?');

    // decode ref/anchor
    if (!StringUtil.isEmpty(fragment)) {
      fragment = escapeQSValue(fragment);
    }

    // user/pasword
    if (!StringUtil.isEmpty(userInfo)) {
      int index = userInfo.indexOf(':');
      if (index != -1) {
        userInfo =
            escapeQSValue(userInfo.substring(0, index))
                + ":"
                + escapeQSValue(userInfo.substring(index + 1));
      } else userInfo = escapeQSValue(userInfo);
    }

    /*print.o("- fragment:"+fragment);
    print.o("- host:"+host);
    print.o("- path:"+path);
    print.o("- query:"+query);
    print.o("- scheme:"+scheme);
    print.o("- userInfo:"+userInfo);
    print.o("- port:"+port);
    print.o("- absolute:"+uri.isAbsolute());
    print.o("- opaque:"+uri.isOpaque());*/

    StringBuilder rtn = new StringBuilder();
    if (scheme != null) {
      rtn.append(scheme);
      rtn.append("://");
    }
    if (userInfo != null) {
      rtn.append(userInfo);
      rtn.append("@");
    }
    if (host != null) {
      rtn.append(host);
    }
    if (port > 0) {
      rtn.append(":");
      rtn.append(port);
    }
    if (path != null) {
      rtn.append(path);
    }
    if (query != null) {
      // rtn.append("?");
      rtn.append(query);
    }
    if (fragment != null) {
      rtn.append("#");
      rtn.append(fragment);
    }

    return new URI(rtn.toString());
  }
Exemple #19
0
 private static String getSupportedLocalesAsString() {
   // TODO chnge from ArryObject to string
   String[] arr = locales.keySet().toArray(new String[locales.size()]);
   Arrays.sort(arr);
   return ListUtil.arrayToList(arr, ",");
 }
Exemple #20
0
  public static byte[] createPojo(
      String className, ASMProperty[] properties, Class parent, Class[] interfaces, String srcName)
      throws PageException {
    className = className.replace('.', '/');
    className = className.replace('\\', '/');
    className = ListUtil.trim(className, "/");
    String[] inter = null;
    if (interfaces != null) {
      inter = new String[interfaces.length];
      for (int i = 0; i < inter.length; i++) {
        inter[i] = interfaces[i].getName().replace('.', '/');
      }
    }
    // CREATE CLASS
    ClassWriter cw = ASMUtil.getClassWriter();
    cw.visit(
        Opcodes.V1_6,
        Opcodes.ACC_PUBLIC,
        className,
        null,
        parent.getName().replace('.', '/'),
        inter);
    String md5;
    try {
      md5 = createMD5(properties);
    } catch (Throwable t) {
      md5 = "";
      t.printStackTrace();
    }

    FieldVisitor fv =
        cw.visitField(
            Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC,
            "_md5_",
            "Ljava/lang/String;",
            null,
            md5);
    fv.visitEnd();

    // Constructor
    GeneratorAdapter adapter =
        new GeneratorAdapter(Opcodes.ACC_PUBLIC, CONSTRUCTOR_OBJECT, null, null, cw);
    adapter.loadThis();
    adapter.invokeConstructor(toType(parent, true), CONSTRUCTOR_OBJECT);
    adapter.returnValue();
    adapter.endMethod();

    // properties
    for (int i = 0; i < properties.length; i++) {
      createProperty(cw, className, properties[i]);
    }

    // complexType src
    if (!StringUtil.isEmpty(srcName)) {
      GeneratorAdapter _adapter =
          new GeneratorAdapter(
              Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC,
              _SRC_NAME,
              null,
              null,
              cw);
      _adapter.push(srcName);
      _adapter.returnValue();
      _adapter.endMethod();
    }

    cw.visitEnd();
    return cw.toByteArray();
  }
Exemple #21
0
  public static URL encodeURL(URL url, int port) throws MalformedURLException {

    // file
    String path = url.getPath();
    // String file=url.getFile();
    String query = url.getQuery();
    String ref = url.getRef();
    String user = url.getUserInfo();
    if (port <= 0) port = url.getPort();

    // decode path
    if (!StringUtil.isEmpty(path)) {
      int sqIndex = path.indexOf(';');
      String q = null;
      if (sqIndex != -1) {
        q = path.substring(sqIndex + 1);
        path = path.substring(0, sqIndex);
      }

      StringBuilder res = new StringBuilder();

      StringList list = ListUtil.toListTrim(path, '/');
      String str;

      while (list.hasNext()) {
        str = list.next();
        // str=URLDecoder.decode(str);

        if (StringUtil.isEmpty(str)) continue;
        res.append("/");
        res.append(escapeQSValue(str));
      }
      if (StringUtil.endsWith(path, '/')) res.append('/');
      path = res.toString();

      if (sqIndex != -1) {
        path += decodeQuery(q, ';');
      }
    }

    // decode query
    query = decodeQuery(query, '?');

    String file = path + query;

    // decode ref/anchor
    if (ref != null) {
      file += "#" + escapeQSValue(ref);
    }

    // user/pasword
    if (!StringUtil.isEmpty(user)) {
      int index = user.indexOf(':');
      if (index != -1) {
        user =
            escapeQSValue(user.substring(0, index))
                + ":"
                + escapeQSValue(user.substring(index + 1));
      } else user = escapeQSValue(user);

      String strUrl = getProtocol(url) + "://" + user + "@" + url.getHost();
      if (port > 0) strUrl += ":" + port;
      strUrl += file;
      return new URL(strUrl);
    }

    // port
    if (port <= 0) return new URL(url.getProtocol(), url.getHost(), file);
    return new URL(url.getProtocol(), url.getHost(), port, file);
  }
 public static double call(PageContext pc, String list, String value, String delimter) {
   return ListUtil.listFindNoCaseIgnoreEmpty(list, value, delimter) + 1;
 }