blob: dc9112683c4d25a1b551a1252dc0f8906bb7f670 [file] [log] [blame]
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*******************************************************************************/
package org.ofbiz.webapp.taglib;
import java.io.IOException;
import java.util.Iterator;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;
/**
* IteratorHasNextTag - Conditional Tag.
*/
@SuppressWarnings("serial")
public class IteratorHasNextTag extends BodyTagSupport {
@Override
public int doStartTag() throws JspTagException {
IteratorTag iteratorTag =
(IteratorTag) findAncestorWithClass(this, IteratorTag.class);
if (iteratorTag == null)
throw new JspTagException("IterateNextTag not inside IteratorTag.");
Iterator<?> iterator = iteratorTag.getIterator();
if (iterator == null || !iterator.hasNext())
return SKIP_BODY;
return EVAL_BODY_AGAIN;
}
@Override
public int doAfterBody() {
return SKIP_BODY;
}
@Override
public int doEndTag() {
try {
BodyContent body = getBodyContent();
if (body != null) {
JspWriter out = body.getEnclosingWriter();
String bodyString = body.getString();
body.clearBody();
out.print(bodyString);
}
} catch (IOException e) {
System.out.println("IterateNext Tag error: " + e);
}
return EVAL_PAGE;
}
}