Пример #1
0
  /**
   * Intialize the Runtime macro. At the init time no implementation so we just save the values to
   * use at the render time.
   *
   * @param rs runtime services
   * @param context InternalContextAdapter
   * @param node node containing the macro call
   */
  public void init(RuntimeServices rs, InternalContextAdapter context, Node node) {
    super.init(rs, context, node);
    rsvc = rs;
    this.node = node;

    /**
     * Apply strictRef setting only if this really looks like a macro, so strict mode doesn't balk
     * at things like #E0E0E0 in a template. compare with ")" is a simple #foo() style macro,
     * comparing to "#end" is a block style macro. We use starts with because the token may end with
     * '\n'
     */
    Token t = node.getLastToken();
    if (t.image.startsWith(")") || t.image.startsWith("#end")) {
      strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);
    }

    // Validate that none of the arguments are plain words, (VELOCITY-614)
    // they should be string literals, references, inline maps, or inline lists
    for (int n = 0; n < node.jjtGetNumChildren(); n++) {
      Node child = node.jjtGetChild(n);
      if (child.getType() == ParserTreeConstants.JJTWORD) {
        badArgsErrorMsg =
            "Invalid arg '"
                + child.getFirstToken().image
                + "' in macro #"
                + macroName
                + " at "
                + Log.formatFileString(child);

        if (strictRef) // If strict, throw now
        {
          /* indicate col/line assuming it starts at 0
           * this will be corrected one call up  */
          throw new TemplateInitException(badArgsErrorMsg, context.getCurrentTemplateName(), 0, 0);
        }
      }
    }
  }
Пример #2
0
  @Override
  public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
      throws TemplateInitException {
    super.init(rs, context, node);

    // 获取缓存提供者
    Object _cache = rs.getProperty(CACHE_PROVIDER);
    if (_cache != null && _cache instanceof Cache) {
      cache = (MemcachedClient) _cache;
    } else {
      throw new TemplateInitException(
          CACHE_PROVIDER
              + " Cannot find the direcitive.cache.provider, or the direcitive.cache.provider object is incorrect.",
          "cache",
          0,
          0);
    }

    // 获取缓存提供者
    Object _time = rs.getProperty(CACHE_TIME);
    if (_time != null) {
      time = Long.valueOf(_time.toString());
    }
  }