01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.jsp.tag.uilib.list;
16:
17: import java.io.Writer;
18: import java.util.ListIterator;
19: import org.araneaframework.jsp.tag.BaseIterationTag;
20:
21: /**
22: * List widget rows tag.
23: *
24: * @author Oleg Mürk
25: */
26: public abstract class BaseListRowsTag extends BaseIterationTag {
27: public static final String ROW_REQUEST_ID_KEY = "rowRequestId";
28: public static final String ROW_KEY = "org.araneaframework.jsp.tag.uilib.list.BaseListRowsTag.ROW";
29:
30: protected Object currentRow;
31: protected ListIterator rowIterator;
32:
33: public int doStartTag(Writer out) throws Exception {
34: super .doStartTag(out);
35:
36: // Get list row iterator
37: rowIterator = getIterator();
38:
39: // Get first row & continue if needed
40: if (rowIterator.hasNext()) {
41: currentRow = rowIterator.next();
42:
43: doForEachRow(out);
44:
45: return EVAL_BODY_INCLUDE;
46: } else
47: return SKIP_BODY;
48: }
49:
50: protected void doForEachRow(Writer out) throws Exception {
51: addContextEntry(ROW_KEY, currentRow);
52: addContextEntry(ROW_REQUEST_ID_KEY, Integer
53: .toString(rowIterator.previousIndex()));
54: }
55:
56: protected int afterBody(Writer out) throws Exception {
57: // Get next row & continue if needed
58: if (rowIterator.hasNext()) {
59: currentRow = rowIterator.next();
60:
61: doForEachRow(out);
62:
63: return EVAL_BODY_AGAIN;
64: } else
65: return SKIP_BODY;
66: }
67:
68: protected abstract ListIterator getIterator();
69: }
|