/** Process the tag. */
  public int doStartTag() throws JspException {
    try {
      _iterator = null;
      _index = 0;
      _count = 0;

      PageContextImpl pageContext = (PageContextImpl) this.pageContext;
      ELContext env = pageContext.getELContext();

      if (_beginExpr != null) _begin = (int) _beginExpr.evalLong(env);
      else _begin = -1;

      if (_endExpr != null) _end = (int) _endExpr.evalLong(env);
      else _end = Integer.MAX_VALUE;

      if (_stepExpr != null) _step = (int) _stepExpr.evalLong(env);
      else _step = 0;

      Object items = null;

      if (_itemsExpr != null) {
        items = _itemsExpr.evalObject(env);

        _iterator = getIterator(items);

        while (_index < _begin && _iterator.hasNext()) {
          _index++;
          _iterator.next();
        }
      } else if (_beginExpr == null)
        throw new JspException(L.l("c:forEach must specify `items' or `begin'"));
      else if (_endExpr == null)
        throw new JspException(L.l("c:forEach must specify `items' or `begin'"));
      else {
        _iterator = new RangeIterator(_begin, _end);
        _end = -1;
      }

      if (_varStatus != null) pageContext.setAttribute(_varStatus, this);

      if (_var != null) _initialVar = pageContext.getAttribute(_var);

      return doAfterBody();
    } catch (Exception e) {
      throw new JspException(e);
    }
  }
  /** Process the tag. */
  public int doEndTag() throws JspException {
    Object[] args = null;

    if (_params != null) {
      args = _params.toArray(new Object[_params.size()]);
      _params = null;
    }

    try {
      PageContextImpl pageContext = (PageContextImpl) this.pageContext;
      ELContext env = pageContext.getELContext();

      JspWriter out = pageContext.getOut();

      String key;

      if (_keyExpr != null) key = _keyExpr.evalString(env);
      else key = getBodyContent().getString().trim();

      String msg;

      if (_bundleExpr != null) {
        Object bundleObject = _bundleExpr.evalObject(env);

        msg = pageContext.getLocalizedMessage(bundleObject, key, args, null);
      } else {
        LocalizationContext lc;
        lc = (LocalizationContext) pageContext.getAttribute("caucho.bundle");

        if (lc == null) msg = pageContext.getLocalizedMessage(key, args, null);
        else msg = pageContext.getLocalizedMessage(lc, key, args, null);
      }

      if (_var != null) CoreSetTag.setValue(pageContext, _var, _scope, msg);
      else out.print(msg);
    } catch (Exception e) {
      throw new JspException(e);
    }

    return EVAL_PAGE;
  }