Пример #1
0
 @Override
 public void reset() {
   super.reset();
   factory.resetPageContext();
   tagHandlerPool.reset();
   contextLock = null;
   baseComponentPageCFML = null;
   baseComponentPageLucee = null;
 }
Пример #2
0
  AbstractConfigValue lookupSubst(
      ResolveContext context, SubstitutionExpression subst, int prefixLength)
      throws NotPossibleToResolve {
    context.trace(subst);
    try {
      // First we look up the full path, which means relative to the
      // included file if we were not a root file
      AbstractConfigValue result = findInObject(root, context, subst);

      if (result == null) {
        // Then we want to check relative to the root file. We don't
        // want the prefix we were included at to be used when looking
        // up env variables either.
        SubstitutionExpression unprefixed = subst.changePath(subst.path().subPath(prefixLength));

        // replace the debug trace path
        context.untrace();
        context.trace(unprefixed);

        if (prefixLength > 0) {
          result = findInObject(root, context, unprefixed);
        }

        if (result == null && context.options().getUseSystemEnvironment()) {
          result = findInObject(ConfigImpl.envVariablesAsConfigObject(), context, unprefixed);
        }
      }

      if (result != null) {
        result = context.resolve(result);
      }

      return result;
    } finally {
      context.untrace();
    }
  }
  private static AbstractConfigObject fromPathMap(
      ConfigOrigin origin, Map<Path, Object> pathMap, boolean convertedFromProperties) {
    /*
     * First, build a list of paths that will have values, either string or
     * object values.
     */
    Set<Path> scopePaths = new HashSet<Path>();
    Set<Path> valuePaths = new HashSet<Path>();
    for (Path path : pathMap.keySet()) {
      // add value's path
      valuePaths.add(path);

      // all parent paths are objects
      Path next = path.parent();
      while (next != null) {
        scopePaths.add(next);
        next = next.parent();
      }
    }

    if (convertedFromProperties) {
      /*
       * If any string values are also objects containing other values,
       * drop those string values - objects "win".
       */
      valuePaths.removeAll(scopePaths);
    } else {
      /* If we didn't start out as properties, then this is an error. */
      for (Path path : valuePaths) {
        if (scopePaths.contains(path)) {
          throw new ConfigException.BugOrBroken(
              "In the map, path '"
                  + path.render()
                  + "' occurs as both the parent object of a value and as a value. "
                  + "Because Map has no defined ordering, this is a broken situation.");
        }
      }
    }

    /*
     * Create maps for the object-valued values.
     */
    Map<String, AbstractConfigValue> root = new HashMap<String, AbstractConfigValue>();
    Map<Path, Map<String, AbstractConfigValue>> scopes =
        new HashMap<Path, Map<String, AbstractConfigValue>>();

    for (Path path : scopePaths) {
      Map<String, AbstractConfigValue> scope = new HashMap<String, AbstractConfigValue>();
      scopes.put(path, scope);
    }

    /* Store string values in the associated scope maps */
    for (Path path : valuePaths) {
      Path parentPath = path.parent();
      Map<String, AbstractConfigValue> parent = parentPath != null ? scopes.get(parentPath) : root;

      String last = path.last();
      Object rawValue = pathMap.get(path);
      AbstractConfigValue value;
      if (convertedFromProperties) {
        value = new ConfigString(origin, (String) rawValue);
      } else {
        value = ConfigImpl.fromAnyRef(pathMap.get(path), origin, FromMapMode.KEYS_ARE_PATHS);
      }
      parent.put(last, value);
    }

    /*
     * Make a list of scope paths from longest to shortest, so children go
     * before parents.
     */
    List<Path> sortedScopePaths = new ArrayList<Path>();
    sortedScopePaths.addAll(scopePaths);
    // sort descending by length
    Collections.sort(
        sortedScopePaths,
        new Comparator<Path>() {
          @Override
          public int compare(Path a, Path b) {
            // Path.length() is O(n) so in theory this sucks
            // but in practice we can make Path precompute length
            // if it ever matters.
            return b.length() - a.length();
          }
        });

    /*
     * Create ConfigObject for each scope map, working from children to
     * parents to avoid modifying any already-created ConfigObject. This is
     * where we need the sorted list.
     */
    for (Path scopePath : sortedScopePaths) {
      Map<String, AbstractConfigValue> scope = scopes.get(scopePath);

      Path parentPath = scopePath.parent();
      Map<String, AbstractConfigValue> parent = parentPath != null ? scopes.get(parentPath) : root;

      AbstractConfigObject o =
          new SimpleConfigObject(
              origin, scope, ResolveStatus.RESOLVED, false /* ignoresFallbacks */);
      parent.put(scopePath.last(), o);
    }

    // return root config object
    return new SimpleConfigObject(
        origin, root, ResolveStatus.RESOLVED, false /* ignoresFallbacks */);
  }
Пример #4
0
 public void reset() {
   super.reset();
   getThreadQueue().clear();
 }