KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > www > WebModuleTag


1 /*
2  * Copyright (c) 2006 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: WebModuleTag.java,v 1.10 2007/01/07 06:14:09 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.core.www;
23
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.jsp.JspException JavaDoc;
31
32 import org.opensubsystems.core.error.OSSException;
33
34 /**
35  * Custom tag to render visual representation of a web module in the page. The
36  * default visual representation of a web module is a tab on a toolbar.
37  *
38  * @version $Id: WebModuleTag.java,v 1.10 2007/01/07 06:14:09 bastafidli Exp $
39  * @author Julian Legeny
40  * @code.reviewer Miro Halas
41  * @code.reviewed 1.7 2006/04/29 00:25:48 jlegeny
42  */

43 public class WebModuleTag extends BlockElementTag
44 {
45    // Attributes ///////////////////////////////////////////////////////////////
46

47    /**
48     * Generated serial version id for this class.
49     */

50    private static final long serialVersionUID = 1L;
51
52    /**
53     * Name of the active module. If the currently rendered module matches this
54     * name it will be rendered as an active module.
55     */

56    protected String JavaDoc m_strActiveModule;
57
58    // Constructors /////////////////////////////////////////////////////////////
59

60    /**
61     * Constructor for custom tag.
62     */

63    public WebModuleTag()
64    {
65       super("", BlockElementTag.DIV_BLOCK_ELEMENT);
66       
67       m_strActiveModule = null;
68    }
69
70    // Business logic ///////////////////////////////////////////////////////////
71

72    /**
73     * {@inheritDoc}
74     */

75    public int doStartTag(
76    ) throws JspException JavaDoc
77    {
78       // Figure out which web modules are present and will be displayed
79
// as module toolbar tabs
80
Map JavaDoc mpDefinitions = null; // key is module name, value is ModuleDefinition
81
String JavaDoc contextpath;
82       StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
83
84       contextpath = ((HttpServletRequest JavaDoc)pageContext.getRequest()).getContextPath();
85
86       try
87       {
88          // Get all the web module definitions
89
mpDefinitions = WebModuleDefinitionManager.getInstance()
90                                       .getWebModuleDefinitions();
91       }
92       catch (OSSException osseExc)
93       {
94          throw new JspException JavaDoc("An unexpected exception has occured.", osseExc);
95       }
96       
97       if ((mpDefinitions != null) && (!mpDefinitions.isEmpty()))
98       {
99          Iterator JavaDoc itDefinitions;
100          WebModule moduleDefinition;
101          int iIndex = 1;
102          
103          StringBuffer JavaDoc sbIconFilePath = new StringBuffer JavaDoc();
104          URL JavaDoc fileURL = null;
105
106          /*
107             <logic:equal name="activemodule" value="security">
108                <div id="securitytab"
109                     class="clsToolbarButtonActive"><a HREF="<%=contextpath%>/osssecurity"
110                     title="Security"><img SRC="../../../../../security/images/securityicon.gif"
111                     align="middle" border="0"> Security</a></div>
112             </logic:equal>
113             <logic:notEqual name="activemodule" value="security">
114                <div id="securitytab"
115                     class="clsToolbarButton"><a HREF="<%=contextpath%>/ossportal"
116                     title="Security"><img SRC="../../../../../security/images/securityicon.gif"
117                     align="middle" border="0"> Security</a></div>
118             </logic:notEqual>
119           */

120
121          // Go through all definitions and generate particular tabs
122
for (itDefinitions = mpDefinitions.values().iterator();
123              itDefinitions.hasNext();)
124          {
125             moduleDefinition = (WebModule)itDefinitions.next();
126             
127             
128             sbHtml.append("<");
129             sbHtml.append(m_strType);
130             sbHtml.append(" id=\"module");
131             sbHtml.append(iIndex++);
132             sbHtml.append("\" class=\"clsToolbarButton");
133             if ((m_strActiveModule != null)
134                  && (m_strActiveModule.equals(moduleDefinition.getName())))
135             {
136                sbHtml.append("Active");
137             }
138             sbHtml.append("\"><a HREF=\"");
139             sbHtml.append(contextpath);
140             sbHtml.append(WebCommonConstants.URL_SEPARATOR_CHAR);
141             sbHtml.append(moduleDefinition.getURL());
142             sbHtml.append("\" title=\"");
143             sbHtml.append(moduleDefinition.getTooltip());
144             sbHtml.append("\">");
145             
146             // construct full path for icon file that will be shown
147
// within the module tab before tab label
148
// if icon file does not exist, no icon will be shown
149
sbIconFilePath.append(WebCommonConstants.URL_SEPARATOR_CHAR);
150             sbIconFilePath.append(moduleDefinition.getName());
151             sbIconFilePath.append(WebCommonConstants.URL_SEPARATOR_CHAR);
152             sbIconFilePath.append("images");
153             sbIconFilePath.append(WebCommonConstants.URL_SEPARATOR_CHAR);
154             sbIconFilePath.append(moduleDefinition.getName());
155             sbIconFilePath.append("icon.gif");
156
157             try
158             {
159                fileURL = pageContext.getServletContext().getResource(
160                             sbIconFilePath.toString());
161             }
162             catch (MalformedURLException JavaDoc eURLExc)
163             {
164                // do not throw exception, just consider that file doesn't exist
165
fileURL = null;
166             }
167             
168             if (fileURL != null)
169             {
170                // generate code for showing image only if particular image file
171
// exists on specified path
172
sbHtml.append("<img SRC=\"");
173                sbHtml.append(sbIconFilePath);
174                sbHtml.append("\" align=\"middle\" border=\"0\"> ");
175             }
176             // clear string buffer for next usage
177
sbIconFilePath.delete(0, sbIconFilePath.length());
178             
179             sbHtml.append(moduleDefinition.getTabName());
180             sbHtml.append("</a></");
181             sbHtml.append(m_strType);
182             sbHtml.append(">");
183          }
184          TagUtils.write(pageContext, sbHtml.toString());
185       }
186
187       return super.doStartTag();
188    }
189
190    /**
191     * {@inheritDoc}
192     */

193    public int doEndTag(
194    ) throws JspException JavaDoc
195    {
196       // And now generate the default end of the element
197
return super.doEndTag();
198    }
199    
200    /**
201     * @return String - name of the active module. If the currently rendered
202     * module matches this name it will be rendered as an
203     * active module.
204     */

205    public String JavaDoc getActiveModule(
206    )
207    {
208       return m_strActiveModule;
209    }
210
211    /**
212     * @param strActiveModule - name of the active module. If the currently
213     * rendered module matches this name it will be
214     * rendered as an active module.
215     */

216    public void setActivemodule(
217       String JavaDoc strActiveModule
218    )
219    {
220       m_strActiveModule = strActiveModule;
221    }
222 }
223
Popular Tags