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
  public static String parsePlaceHolder(String path, ServletContext sc) {
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();

    if (path == null) return null;
    if (path.indexOf('{') != -1) {
      if (StringUtil.startsWith(path, '{')) {

        // Web Root
        if (path.startsWith("{web-root")) {
          if (path.startsWith("}", 9))
            path =
                frp.getResource(ReqRspUtil.getRootPath(sc))
                    .getRealResource(path.substring(10))
                    .toString();
          else if (path.startsWith("-dir}", 9))
            path =
                frp.getResource(ReqRspUtil.getRootPath(sc))
                    .getRealResource(path.substring(14))
                    .toString();
          else if (path.startsWith("-directory}", 9))
            path =
                frp.getResource(ReqRspUtil.getRootPath(sc))
                    .getRealResource(path.substring(20))
                    .toString();

        } else path = SystemUtil.parsePlaceHolder(path);
      }

      if ((path.indexOf("{web-context-hash}")) != -1) {
        String id = hash(sc);
        path = StringUtil.replace(path, "{web-context-hash}", id, false);
      }
    }
    return path;
  }
Exemple #3
0
  /**
   * returns the Hoome Directory of the System
   *
   * @return home directory
   */
  public static Resource getHomeDirectory() {
    if (homeFile != null) return homeFile;

    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();

    String homeStr = System.getProperty("user.home");
    if (homeStr != null) {
      homeFile = frp.getResource(homeStr);
      homeFile = ResourceUtil.getCanonicalResourceEL(homeFile);
    }
    return homeFile;
  }
Exemple #4
0
  /**
   * get class pathes from all url ClassLoaders
   *
   * @param ucl URL Class Loader
   * @param pathes Hashmap with allpathes
   */
  private static void getClassPathesFromClassLoader(URLClassLoader ucl, ArrayList pathes) {
    ClassLoader pcl = ucl.getParent();
    // parent first
    if (pcl instanceof URLClassLoader) getClassPathesFromClassLoader((URLClassLoader) pcl, pathes);

    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();
    // get all pathes
    URL[] urls = ucl.getURLs();
    for (int i = 0; i < urls.length; i++) {
      Resource file = frp.getResource(urls[i].getPath());
      if (file.exists()) pathes.add(ResourceUtil.getCanonicalResourceEL(file));
    }
  }
Exemple #5
0
  /** @return return running context root */
  public static Resource getRuningContextRoot() {
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();

    try {
      return frp.getResource(".").getCanonicalResource();
    } catch (IOException e) {
    }
    URL url = new Info().getClass().getClassLoader().getResource(".");
    try {
      return frp.getResource(FileUtil.URLToFile(url).getAbsolutePath());
    } catch (MalformedURLException e) {
      return null;
    }
  }
Exemple #6
0
  /**
   * constructor of the class
   *
   * @param configServer
   * @param config
   * @param configDir
   * @param configFile
   * @param cloneServer
   */
  ConfigWebImpl(
      CFMLFactoryImpl factory,
      ConfigServerImpl configServer,
      ServletConfig config,
      Resource configDir,
      Resource configFile) {
    super(configDir, configFile);
    this.configServer = configServer;
    this.config = config;
    this.factory = factory;
    factory.setConfig(this);
    ResourceProvider frp = ResourcesImpl.getFileResourceProvider();

    this.rootDir = frp.getResource(ReqRspUtil.getRootPath(config.getServletContext()));

    // Fix for tomcat
    if (this.rootDir.getName().equals(".") || this.rootDir.getName().equals(".."))
      this.rootDir = this.rootDir.getParentResource();
  }
Exemple #7
0
 /**
  * returns the Temp Directory of the System
  *
  * @return temp directory
  */
 public static Resource getTempDirectory() {
   if (tempFile != null) return tempFile;
   ResourceProvider fr = ResourcesImpl.getFileResourceProvider();
   String tmpStr = System.getProperty("java.io.tmpdir");
   if (tmpStr != null) {
     tempFile = fr.getResource(tmpStr);
     if (tempFile.exists()) {
       tempFile = ResourceUtil.getCanonicalResourceEL(tempFile);
       return tempFile;
     }
   }
   File tmp = null;
   try {
     tmp = File.createTempFile("a", "a");
     tempFile = fr.getResource(tmp.getParent());
     tempFile = ResourceUtil.getCanonicalResourceEL(tempFile);
   } catch (IOException ioe) {
   } finally {
     if (tmp != null) tmp.delete();
   }
   return tempFile;
 }
  /**
   * read in a single collection element
   *
   * @param config
   * @param el
   * @throws SearchException
   */
  private final void readCollection(Config config, Element el) throws SearchException {
    SearchCollection sc;
    // try {
    // Collection
    DateTime last =
        engine
            .getCastUtil()
            .toDateTime(el.getAttribute("lastUpdate"), engine.getThreadTimeZone(), null);
    if (last == null) last = engine.getCreationUtil().now();
    DateTime cre =
        engine
            .getCastUtil()
            .toDateTime(el.getAttribute("created"), engine.getThreadTimeZone(), null);
    if (cre == null) cre = engine.getCreationUtil().now();
    ResourceProvider frp = engine.getResourceUtil().getFileResourceProvider();
    sc =
        _readCollection(
            el.getAttribute("name"),
            frp.getResource(el.getAttribute("path")),
            el.getAttribute("language"),
            last,
            cre);
    collections.setEL((sc.getName()), sc);

    // Indexes
    NodeList children = el.getChildNodes();
    int len = children.getLength();
    for (int i = 0; i < len; i++) {
      Node n = children.item(i);
      if (n instanceof Element && n.getNodeName().equals("index")) {
        readIndex(sc, (Element) n);
      }
    }
    /*}
    catch (PageException e) {
        throw new SearchException(e);
    }*/
  }
Exemple #9
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;
 }
  public static Struct call(PageContext pc, String scheme) {
    ResourceProvider[] providers = pc.getConfig().getResourceProviders();
    ResourceProvider provider;
    scheme = scheme.trim();
    Struct sct = new StructImpl();
    for (int i = 0; i < providers.length; i++) {
      provider = providers[i];
      if (provider.getScheme().equalsIgnoreCase(scheme)) {
        // MUST sct=provider.getMetaData();
        sct.setEL("Scheme", provider.getScheme());
        sct.setEL("Attributes", provider.isAttributesSupported());
        sct.setEL("CaseSensitive", provider.isCaseSensitive());
        sct.setEL("Mode", provider.isModeSupported());

        sct.setEL("Enabled", Boolean.TRUE);
        return sct;
      }
    }
    sct.setEL("Enabled", Boolean.FALSE);
    return sct;
  }