public static String call(PageContext pc, String strType) throws PageException {
    int type = Util.toType(strType, Config.CACHE_TYPE_NONE);
    if (type == Config.CACHE_TYPE_NONE)
      throw new FunctionException(
          pc,
          "CacheGetDefaultCacheName",
          1,
          "type",
          "invalid type defintion ["
              + strType
              + "], valid types are [object,resource,template,query]");

    ConfigImpl config = (ConfigImpl) pc.getConfig();
    CacheConnection conn = config.getCacheDefaultConnection(type);
    if (conn == null)
      throw new ExpressionException("there is no default cache defined for type [" + strType + "]");

    return conn.getName();
  }
示例#2
0
  public BIF(PageContext pc, String name) throws ApplicationException {
    super(Component.ACCESS_PUBLIC);
    ci = (ConfigImpl) pc.getConfig();
    FunctionLib fl = ci.getCombinedFLDs(pc.getCurrentTemplateDialect());
    flf = fl.getFunction(name);

    // BIF not found
    if (flf == null) {
      Key[] keys = CollectionUtil.toKeys(fl.getFunctions().keySet());
      throw new ApplicationException(
          ExceptionUtil.similarKeyMessage(
              keys, name, "build in function", "build in functions", null, false));
    }
    try {
      this.id = Hash.md5(name);
    } catch (NoSuchAlgorithmException e) {
      this.id = name;
    }
  }
示例#3
0
  private void control(
      CFMLFactoryImpl cfmlFactory, boolean doMinute, boolean doHour, boolean firstRun) {
    try {
      boolean isRunning = cfmlFactory.getUsedPageContextLength() > 0;
      if (isRunning) {
        cfmlFactory.checkTimeout();
      }
      ConfigWeb config = null;

      if (firstRun) {
        config = cfmlFactory.getConfig();
        ThreadLocalConfig.register(config);

        config.reloadTimeServerOffset();
        checkOldClientFile(config);

        // try{checkStorageScopeFile(config,Session.SCOPE_CLIENT);}catch(Throwable t){}
        // try{checkStorageScopeFile(config,Session.SCOPE_SESSION);}catch(Throwable t){}
        try {
          config.reloadTimeServerOffset();
        } catch (Throwable t) {
        }
        try {
          checkTempDirectorySize(config);
        } catch (Throwable t) {
        }
        try {
          checkCacheFileSize(config);
        } catch (Throwable t) {
        }
        try {
          cfmlFactory.getScopeContext().clearUnused();
        } catch (Throwable t) {
        }
      }

      if (config == null) {
        config = cfmlFactory.getConfig();
      }
      ThreadLocalConfig.register(config);

      // every Minute
      if (doMinute) {
        if (config == null) {
          config = cfmlFactory.getConfig();
        }
        ThreadLocalConfig.register(config);

        // double check templates
        try {
          ((ConfigWebImpl) config).getCompiler().checkWatched();
        } catch (Throwable t) {
          t.printStackTrace();
        }

        // deploy extensions, archives ...
        try {
          DeployHandler.deploy(config);
        } catch (Throwable t) {
          t.printStackTrace();
        }

        // clear unused DB Connections
        try {
          ((ConfigImpl) config).getDatasourceConnectionPool().clear(false);
        } catch (Throwable t) {
        }
        // clear all unused scopes
        try {
          cfmlFactory.getScopeContext().clearUnused();
        } catch (Throwable t) {
        }
        // Memory usage
        // clear Query Cache
        /*try{
        	ConfigWebUtil.getCacheHandlerFactories(config).query.clean(null);
        	ConfigWebUtil.getCacheHandlerFactories(config).include.clean(null);
        	ConfigWebUtil.getCacheHandlerFactories(config).function.clean(null);
        	//cfmlFactory.getDefaultQueryCache().clearUnused(null);
        }catch(Throwable t){t.printStackTrace();}*/
        // contract Page Pool
        // try{doClearPagePools((ConfigWebImpl) config);}catch(Throwable t){}
        // try{checkPermGenSpace((ConfigWebImpl) config);}catch(Throwable t){}
        try {
          doCheckMappings(config);
        } catch (Throwable t) {
        }
        try {
          doClearMailConnections();
        } catch (Throwable t) {
        }
        // clean LockManager
        if (cfmlFactory.getUsedPageContextLength() == 0)
          try {
            ((LockManagerImpl) config.getLockManager()).clean();
          } catch (Throwable t) {
          }

        try {
          XMLConfigAdmin.checkForChangesInConfigFile(config);
        } catch (Throwable t) {
        }
      }
      // every hour
      if (doHour) {
        if (config == null) {
          config = cfmlFactory.getConfig();
        }
        ThreadLocalConfig.register(config);

        // time server offset
        try {
          config.reloadTimeServerOffset();
        } catch (Throwable t) {
        }
        // check file based client/session scope
        // try{checkStorageScopeFile(config,Session.SCOPE_CLIENT);}catch(Throwable t){}
        // try{checkStorageScopeFile(config,Session.SCOPE_SESSION);}catch(Throwable t){}
        // check temp directory
        try {
          checkTempDirectorySize(config);
        } catch (Throwable t) {
        }
        // check cache directory
        try {
          checkCacheFileSize(config);
        } catch (Throwable t) {
        }
      }

      try {
        configServer.checkPermGenSpace(true);
      } catch (Throwable t) {
      }
    } catch (Throwable t) {

    } finally {
      ThreadLocalConfig.release();
    }
  }
示例#4
0
  private static Object _search(
      PageContext pc,
      PageSource loadingLocation,
      String rawPath,
      Boolean searchLocal,
      Boolean searchRoot,
      boolean executeConstr,
      short returnType,
      Page currP,
      int dialect,
      boolean isExtendedComponent)
      throws PageException {
    ConfigImpl config = (ConfigImpl) pc.getConfig();
    boolean doCache = config.useComponentPathCache();
    String sub = null;
    if (returnType != RETURN_TYPE_PAGE && rawPath.indexOf(':') != -1) {
      int d = rawPath.indexOf(':');
      int s = rawPath.indexOf('.');
      if (d > s) {
        sub = rawPath.substring(d + 1);
        rawPath = rawPath.substring(0, d);
      }
    }

    // app-String appName=pc.getApplicationContext().getName();
    rawPath = rawPath.trim().replace('\\', '/');
    String path = (rawPath.indexOf("./") == -1) ? rawPath.replace('.', '/') : rawPath;

    boolean isRealPath = !StringUtil.startsWith(path, '/');
    // PageSource currPS = pc.getCurrentPageSource();
    // Page currP=currPS.loadPage(pc,false);
    PageSource ps = null;
    CIPage page = null;

    // MUSTMUST improve to handle different extensions
    String pathWithCFC =
        path.concat(
            "."
                + (dialect == CFMLEngine.DIALECT_CFML
                    ? Constants.getCFMLComponentExtension()
                    : Constants.getLuceeComponentExtension()));

    // no cache for per application pathes
    Mapping[] acm = pc.getApplicationContext().getComponentMappings();
    if (!ArrayUtil.isEmpty(acm)) {
      Mapping m;
      for (int y = 0; y < acm.length; y++) {
        m = acm[y];
        ps = m.getPageSource(pathWithCFC);
        page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
        if (page != null) {

          return returnType == RETURN_TYPE_PAGE
              ? page
              : load(
                  pc,
                  page,
                  trim(path.replace('/', '.')),
                  sub,
                  isRealPath,
                  returnType,
                  isExtendedComponent,
                  executeConstr);
        }
      }
    }

    if (searchLocal == null)
      searchLocal =
          Caster.toBoolean(rawPath.indexOf('.') == -1 ? true : config.getComponentLocalSearch());
    if (searchRoot == null) searchRoot = Caster.toBoolean(config.getComponentRootSearch());

    // CACHE
    // check local in cache
    String localCacheName = null;
    if (searchLocal && isRealPath) {
      localCacheName = currP.getPageSource().getDisplayPath().replace('\\', '/');
      localCacheName =
          localCacheName.substring(0, localCacheName.lastIndexOf('/') + 1).concat(pathWithCFC);
      if (doCache) {
        page = config.getCachedPage(pc, localCacheName);
        if (page != null)
          return returnType == RETURN_TYPE_PAGE
              ? page
              : load(
                  pc,
                  page,
                  trim(path.replace('/', '.')),
                  sub,
                  isRealPath,
                  returnType,
                  isExtendedComponent,
                  executeConstr);
      }
    }

    // check import cache
    if (doCache && isRealPath) {
      ImportDefintion impDef = config.getComponentDefaultImport();
      ImportDefintion[] impDefs =
          currP == null ? new ImportDefintion[0] : currP.getImportDefintions();
      int i = -1;
      do {

        if (impDef.isWildcard() || impDef.getName().equalsIgnoreCase(path)) {
          page = config.getCachedPage(pc, "import:" + impDef.getPackageAsPath() + pathWithCFC);
          if (page != null)
            return returnType == RETURN_TYPE_PAGE
                ? page
                : load(
                    pc,
                    page,
                    trim(path.replace('/', '.')),
                    sub,
                    isRealPath,
                    returnType,
                    isExtendedComponent,
                    executeConstr);
        }
        impDef = ++i < impDefs.length ? impDefs[i] : null;
      } while (impDef != null);
    }

    if (doCache) {
      // check global in cache
      page = config.getCachedPage(pc, pathWithCFC);
      if (page != null)
        return returnType == RETURN_TYPE_PAGE
            ? page
            : load(
                pc,
                page,
                trim(path.replace('/', '.')),
                sub,
                isRealPath,
                returnType,
                isExtendedComponent,
                executeConstr);
    }

    // SEARCH
    // search from local
    if (searchLocal && isRealPath) {
      // check realpath
      PageSource[] arr = ((PageContextImpl) pc).getRelativePageSources(pathWithCFC);
      page = toCIPage(PageSourceImpl.loadPage(pc, arr, null));
      if (page != null) {
        if (doCache) config.putCachedPageSource(localCacheName, page.getPageSource());
        return returnType == RETURN_TYPE_PAGE
            ? page
            : load(
                pc,
                page,
                trim(path.replace('/', '.')),
                sub,
                isRealPath,
                returnType,
                isExtendedComponent,
                executeConstr);
      }
    }

    // search with imports
    Mapping[] cMappings = config.getComponentMappings();

    if (isRealPath) {

      ImportDefintion impDef = config.getComponentDefaultImport();
      ImportDefintion[] impDefs =
          currP == null ? new ImportDefintion[0] : currP.getImportDefintions();
      PageSource[] arr;

      int i = -1;
      do {
        if (impDef.isWildcard() || impDef.getName().equalsIgnoreCase(path)) {

          // search from local first
          if (searchLocal) {
            arr =
                ((PageContextImpl) pc)
                    .getRelativePageSources(impDef.getPackageAsPath() + pathWithCFC);
            page = toCIPage(PageSourceImpl.loadPage(pc, arr, null));
            if (page != null) {
              if (doCache)
                config.putCachedPageSource(
                    "import:" + impDef.getPackageAsPath() + pathWithCFC, page.getPageSource());
              return returnType == RETURN_TYPE_PAGE
                  ? page
                  : load(
                      pc,
                      page,
                      trim(path.replace('/', '.')),
                      sub,
                      isRealPath,
                      returnType,
                      isExtendedComponent,
                      executeConstr);
            }
          }

          // search mappings and webroot
          page =
              toCIPage(
                  PageSourceImpl.loadPage(
                      pc,
                      ((PageContextImpl) pc)
                          .getPageSources("/" + impDef.getPackageAsPath() + pathWithCFC),
                      null));
          if (page != null) {
            String key = impDef.getPackageAsPath() + pathWithCFC;
            if (doCache && !((MappingImpl) page.getPageSource().getMapping()).isAppMapping())
              config.putCachedPageSource("import:" + key, page.getPageSource());
            return returnType == RETURN_TYPE_PAGE
                ? page
                : load(
                    pc,
                    page,
                    trim(path.replace('/', '.')),
                    sub,
                    isRealPath,
                    returnType,
                    isExtendedComponent,
                    executeConstr);
          }

          // search component mappings
          Mapping m;
          for (int y = 0; y < cMappings.length; y++) {
            m = cMappings[y];
            ps = m.getPageSource(impDef.getPackageAsPath() + pathWithCFC);
            page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
            if (page != null) {
              if (doCache)
                config.putCachedPageSource(
                    "import:" + impDef.getPackageAsPath() + pathWithCFC, page.getPageSource());
              return returnType == RETURN_TYPE_PAGE
                  ? page
                  : load(
                      pc,
                      page,
                      trim(path.replace('/', '.')),
                      sub,
                      isRealPath,
                      returnType,
                      isExtendedComponent,
                      executeConstr);
            }
          }
        }
        impDef = ++i < impDefs.length ? impDefs[i] : null;
      } while (impDef != null);
    }

    String p;
    if (isRealPath) p = '/' + pathWithCFC;
    else p = pathWithCFC;

    // search mappings and webroot
    page = toCIPage(PageSourceImpl.loadPage(pc, ((PageContextImpl) pc).getPageSources(p), null));
    if (page != null) {
      String key = pathWithCFC;
      if (doCache && !((MappingImpl) page.getPageSource().getMapping()).isAppMapping())
        config.putCachedPageSource(key, page.getPageSource());
      return returnType == RETURN_TYPE_PAGE
          ? page
          : load(
              pc,
              page,
              trim(path.replace('/', '.')),
              sub,
              isRealPath,
              returnType,
              isExtendedComponent,
              executeConstr);
    }

    // search component mappings
    Mapping m;
    for (int i = 0; i < cMappings.length; i++) {
      m = cMappings[i];
      ps = m.getPageSource(p);
      page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));

      // recursive search
      if (page == null && config.doComponentDeepSearch() && path.indexOf('/') == -1) {
        ps = MappingUtil.searchMappingRecursive(m, pathWithCFC, true);
        if (ps != null) {
          page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
          if (page != null) doCache = false; // do not cache this, it could be ambigous
        }
      }

      if (page != null) {
        if (doCache) config.putCachedPageSource(pathWithCFC, page.getPageSource());
        return returnType == RETURN_TYPE_PAGE
            ? page
            : load(
                pc,
                page,
                trim(path.replace('/', '.')),
                sub,
                isRealPath,
                returnType,
                isExtendedComponent,
                executeConstr);
      }
    }

    // search relative to active component (this get not cached because the cache get ambigous if we
    // do)
    if (searchLocal && isRealPath) {
      if (loadingLocation == null) {
        Component c = pc.getActiveComponent();
        if (c != null) loadingLocation = c.getPageSource();
      }

      if (loadingLocation != null) {
        ps = loadingLocation.getRealPage(pathWithCFC);
        if (ps != null) {
          page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));

          if (page != null) {
            return returnType == RETURN_TYPE_PAGE
                ? page
                : load(
                    pc,
                    page,
                    trim(path.replace('/', '.')),
                    sub,
                    isRealPath,
                    returnType,
                    isExtendedComponent,
                    executeConstr);
          }
        }
      }
    }
    // translate cfide. to org.lucee.cfml
    if (StringUtil.startsWithIgnoreCase(rawPath, "cfide.")) {
      String rpm = Constants.DEFAULT_PACKAGE + "." + rawPath.substring(6);
      try {
        return _search(
            pc,
            loadingLocation,
            rpm,
            searchLocal,
            searchRoot,
            executeConstr,
            returnType,
            currP,
            dialect,
            false);
      } catch (ExpressionException ee) {
        return null;
        // throw new ExpressionException("invalid "+toStringType(returnType)+" definition, can't
        // find "+rawPath+" or "+rpm);
      }
    }
    return null;
    // throw new ExpressionException("invalid "+toStringType(returnType)+" definition, can't find
    // "+toStringType(returnType)+" ["+rawPath+"]");
  }