示例#1
0
    public boolean accept(Resource res) {

      if (res.isDirectory()) return allowDir;

      // load content
      String str = null;
      try {
        str = IOUtil.toString(res, "UTF-8");
      } catch (IOException e) {
        return false;
      }

      int index = str.indexOf(':');
      if (index != -1) {
        long expires = Caster.toLongValue(str.substring(0, index), -1L);
        // check is for backward compatibility, old files have no expires date inside. they do ot
        // expire
        if (expires != -1) {
          if (expires < System.currentTimeMillis()) {
            return true;
          }
          str = str.substring(index + 1);
          return false;
        }
      }
      // old files not having a timestamp inside
      else if (res.lastModified() <= time) {
        return true;
      }
      return false;
    }
示例#2
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;
 }