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.example.common.tags.wizard;
16:
17: import java.io.Writer;
18: import org.araneaframework.example.common.framework.context.WizardContext;
19: import org.araneaframework.jsp.tag.BaseTag;
20:
21: /**
22: * This tag includes its body if the wizard's current page index matches specified index.
23: * Page index must fit into following format:
24: * ["not"] (page index value | "first" | "last")
25: *
26: * @author Rein Raudjärv <reinra@ut.ee>
27: *
28: * @jsp.tag
29: * name = "wizardIfPage"
30: * body-content = "JSP"
31: * description = "Includes its body if the wizard's current page index matches specified index."
32: */
33: public class WizardIfPageTag extends BaseTag {
34: public static final String INDEX_FIRST = "first";
35: public static final String INDEX_LAST = "last";
36: public static final String INDEX_NOT_PREFIX = "not";
37: // XXX: wrong. besides, wizardwidget does not have a viewmodel - and widgetcontexttag does not put
38: // widget itself into pagecontext.
39: public static final String WIDGET_CONTEXT_KEY = "org.araneaframework.jsp.ui.context.UiWidgetContextTag.WIDGET";
40:
41: private String index;
42:
43: protected int doStartTag(Writer out) throws Exception {
44:
45: WizardContext wizard = (WizardContext) requireContextEntry(WIDGET_CONTEXT_KEY);
46:
47: int curIndex = wizard.getCurrentPageIndex();
48: int count = wizard.countPages();
49:
50: String ifIndex = (String) evaluate("index", this .index,
51: String.class);
52:
53: boolean not = false;
54:
55: if (ifIndex.startsWith(INDEX_NOT_PREFIX)) {
56: not = true;
57: ifIndex = ifIndex.substring(INDEX_NOT_PREFIX.length());
58: }
59: int index;
60: if (ifIndex.equals(INDEX_FIRST)) {
61: index = 0;
62: } else if (ifIndex.equals(INDEX_LAST)) {
63: index = count - 1;
64: } else {
65: index = Integer.parseInt(ifIndex);
66: }
67:
68: return (!not && index == curIndex || not && index != curIndex) ? EVAL_BODY_INCLUDE
69: : SKIP_BODY;
70: }
71:
72: /**
73: * @jsp.attribute
74: * type = "java.lang.String"
75: * required = "true"
76: * description = "Page index with following format:
77: ["not"] (page index value | "first" | "last")."
78: */
79: public void setIndex(String index) {
80: this.index = index;
81: }
82: }
|