Package freemarker.core

Examples of freemarker.core.Scope


            TemplateModel model)
    throws TemplateException {
        if (!(model instanceof Scope)) {
            throw new TemplateException("Expecting scope on left of ?resolve built-in", env);
        }
        final Scope scope = (Scope) model;
        return new TemplateMethodModel() {
            @Parameters("key")
            public Object exec(List args) throws TemplateModelException {
                return scope.resolveVariable((String) args.get(0));
            }
        };
    }
View Full Code Here


    public int getType() {
      return type;
    }

    public void execute(Environment env) throws TemplateException, IOException {
      Scope scope = null;
      if (namespaceExp != null) {
        try {
          scope = (Scope) namespaceExp.getAsTemplateModel(env);
        } catch (ClassCastException cce) {
                throw new InvalidReferenceException(getStartLocation() + "\nInvalid reference to namespace: " + namespaceExp, env);
        }
      }
      else {
        if (type == AssignmentInstruction.NAMESPACE) {
          scope = env.getCurrentNamespace();
        } else if (type == AssignmentInstruction.LOCAL) {
          scope = env.getCurrentMacroContext();
        } else if (type == AssignmentInstruction.GLOBAL) {
          scope = env.getGlobalNamespace();
        }
      }
      CaptureOutput filter = new CaptureOutput();
        if (nestedBlock != null) {
            env.render(nestedBlock, filter, null);
        }
        String text = filter.capturedText;
      if (scope != null) {
        scope.put(varName, new SimpleScalar(text));
      } else {
        env.unqualifiedSet(varName, new SimpleScalar(text));
      }
    }
View Full Code Here

        else if(commonSize < paramsSize) {
            // More formal args than actual args -- fill in defaults

            // Create a scope that provides live access to the parameter list
            // so we can reference already defined parameters
            Scope scope = new NamedParameterListScope(env.getCurrentScope(),
                    params, result, false);
                fillInDefaults(env, scope, params.subList(args.size(), params.size()));
        }
        return result;
    }
View Full Code Here

            }
        }
        if(unresolvedParamNames != null) {
            // Create a scope that provides live access to the parameter list
            // so we can reference already defined parameters
            final Scope scope = new NamedParameterListScope(
                    env.getCurrentScope(), params, result, false);
            fillInDefaults(env, scope, unresolvedParamNames);
        }
        return result;
    }
View Full Code Here

            result.put(params.get(i), args.getValueAt(i, env));
        }
        if(hasDefaultExpressions() && argsSize < paramsSize) {
            // Create a scope that provides live access to the parameter list
            // so we can reference already defined parameters
            Scope scope = new NamedParameterMapScope(env.getCurrentScope(),
                    result);
            fillInDefaults(env, scope, params.subList(argsSize, paramsSize));
        }
        if(catchall != null) {
            SimpleSequence catchAllVars = new SimpleSequence();
View Full Code Here

            }
        }
        if(unresolvedParamNames != null) {
            // Create a scope that provides live access to the parameter list
            // so we can reference already defined parameters
            Scope scope = new NamedParameterMapScope(env.getCurrentScope(),
                    result);
            fillInDefaults(env, scope, unresolvedParamNames);
        }
        SimpleHash catchAllMap = null;
        if (catchall != null) {
View Full Code Here

    {
        Map<String, TemplateModel> result = new HashMap<String, TemplateModel>();
        if(hasDefaultExpressions()) {
            // Create a scope that provides live access to the parameter list
            // so we can reference already defined parameters
            Scope scope = new NamedParameterMapScope(env.getCurrentScope(),
                    result);
            fillInDefaults(env, scope, defaults.keySet());
        }
        return result;
    }
View Full Code Here

TOP

Related Classes of freemarker.core.Scope

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.