1 /***
2 * Copyright (c) 2003 held jointly by the individual authors.
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; with out even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 *
18 * > http://www.gnu.org/copyleft/lesser.html
19 * > http://www.opensource.org/licenses/lgpl-license.php
20 */
21 package net.mlw.vlh.web.tag;
22
23 import java.util.Locale;
24
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.jsp.JspException;
27
28 import net.mlw.vlh.ValueListInfo;
29 import net.mlw.vlh.web.util.DisplayHelper;
30 import net.mlw.vlh.web.util.JspUtils;
31
32 import org.springframework.context.MessageSource;
33 import org.springframework.context.NoSuchMessageException;
34
35 /***
36 * Create focus status table. If info.isFocusEnabled() is false, skip all body
37 * content. <b>Warning </b> info.doFosus is diferent that info.isFocuseEnabled.
38 *
39 * @see net.mlw.vlh.web.ValueListInfo#isFocusEnabled
40 * @see net.mlw.vlh.web.ValueListInfo#doFocus
41 * @author Andrej Zachar
42 * @version $Revision: 1.8 $ $Date: 2005/11/23 15:02:16 $
43 */
44 public class FocusStatusTag extends ConfigurableTag
45 {
46
47 /***
48 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
49 */
50 public int doStartTag() throws JspException
51 {
52 ValueListSpaceTag rootTag = (ValueListSpaceTag) JspUtils.getParent(this, ValueListSpaceTag.class);
53
54 Locale local = rootTag.getConfig().getLocaleResolver().resolveLocale((HttpServletRequest) pageContext.getRequest());
55 MessageSource message = rootTag.getConfig().getMessageSource();
56
57 ValueListInfo info = rootTag.getValueList().getValueListInfo();
58 if (info.isFocusEnabled())
59 {
60 StringBuffer sb = new StringBuffer();
61
62 sb.append("<table ").append(getCellAttributes().getCellAttributesAsString()).append(">");
63 sb.append("\n <tr>");
64 sb.append(generateFocusStatus(info, message, local, rootTag));
65 sb.append("\n </tr>");
66 sb.append("\n <tr>");
67 JspUtils.write(pageContext, sb.toString());
68 pageContext.setAttribute("focusStatus" + rootTag.getTableInfo().getId(), new Integer(info.getFocusStatus()));
69 return EVAL_BODY_INCLUDE;
70 }
71 return SKIP_BODY;
72
73 }
74
75 /***
76 *
77 * @param info
78 * @param message
79 * @param local
80 * @param rootTag
81 * @return
82 * @throws NoSuchMessageException
83 * @throws JspException
84 */
85 private StringBuffer generateFocusStatus(ValueListInfo info, MessageSource message, Locale local, ValueListSpaceTag rootTag)
86 throws NoSuchMessageException, JspException
87 {
88
89 StringBuffer sb = new StringBuffer("");
90
91 if ((!info.isDoFocus()) || (info.getFocusStatus() == ValueListInfo.FOCUS_FOUND))
92 {
93 return sb;
94 }
95
96 DisplayHelper displayHelper = rootTag.getConfig().getDisplayHelper();
97
98 sb.append("\n <td>");
99 if (info.getFocusStatus() == ValueListInfo.FOCUS_NOT_FOUND)
100 {
101 sb.append(displayHelper.help(pageContext, message.getMessage("focusStatus.notFound", new String[]
102 { info.getFocusValue() }, local)));
103 }
104 else
105 {
106 if (info.getFocusStatus() == ValueListInfo.FOCUS_TOO_MANY_ITEMS)
107 {
108 sb.append(displayHelper.help(pageContext, message.getMessage("focusStatus.tooManyItems", null, local)));
109 }
110 }
111 sb.append("</td>");
112 String delim = displayHelper.help(pageContext, message.getMessage("paging.delim", null, "", local));
113 if (delim.length() > 0)
114 {
115 sb.append(delim);
116 }
117 return sb;
118 }
119
120 /***
121 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
122 */
123 public int doEndTag() throws JspException
124 {
125 ValueListSpaceTag rootTag = (ValueListSpaceTag) JspUtils.getParent(this, ValueListSpaceTag.class);
126 ValueListInfo info = rootTag.getValueList().getValueListInfo();
127 if (info.isFocusEnabled())
128 {
129 JspUtils.write(pageContext, "\n </tr>\n</table>");
130 }
131
132 release();
133
134 return EVAL_PAGE;
135 }
136 }