1 21 22 package org.opensubsystems.core.www; 23 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 import java.util.Iterator ; 27 import java.util.Map ; 28 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.jsp.JspException ; 31 32 import org.opensubsystems.core.error.OSSException; 33 34 43 public class WebModuleTag extends BlockElementTag 44 { 45 47 50 private static final long serialVersionUID = 1L; 51 52 56 protected String m_strActiveModule; 57 58 60 63 public WebModuleTag() 64 { 65 super("", BlockElementTag.DIV_BLOCK_ELEMENT); 66 67 m_strActiveModule = null; 68 } 69 70 72 75 public int doStartTag( 76 ) throws JspException 77 { 78 Map mpDefinitions = null; String contextpath; 82 StringBuffer sbHtml = new StringBuffer (); 83 84 contextpath = ((HttpServletRequest )pageContext.getRequest()).getContextPath(); 85 86 try 87 { 88 mpDefinitions = WebModuleDefinitionManager.getInstance() 90 .getWebModuleDefinitions(); 91 } 92 catch (OSSException osseExc) 93 { 94 throw new JspException ("An unexpected exception has occured.", osseExc); 95 } 96 97 if ((mpDefinitions != null) && (!mpDefinitions.isEmpty())) 98 { 99 Iterator itDefinitions; 100 WebModule moduleDefinition; 101 int iIndex = 1; 102 103 StringBuffer sbIconFilePath = new StringBuffer (); 104 URL fileURL = null; 105 106 120 121 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 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 eURLExc) 163 { 164 fileURL = null; 166 } 167 168 if (fileURL != null) 169 { 170 sbHtml.append("<img SRC=\""); 173 sbHtml.append(sbIconFilePath); 174 sbHtml.append("\" align=\"middle\" border=\"0\"> "); 175 } 176 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 193 public int doEndTag( 194 ) throws JspException 195 { 196 return super.doEndTag(); 198 } 199 200 205 public String getActiveModule( 206 ) 207 { 208 return m_strActiveModule; 209 } 210 211 216 public void setActivemodule( 217 String strActiveModule 218 ) 219 { 220 m_strActiveModule = strActiveModule; 221 } 222 } 223 | Popular Tags |