Index: lams_central/src/java/org/lamsfoundation/lams/web/tag/CssTag.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/tag/CssTag.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/tag/CssTag.java (revision 8ba43ae6cd465e24431866147a53ae7e43102efd) @@ -0,0 +1,107 @@ +/*************************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * ***********************************************************************/ + +package org.lamsfoundation.lams.web.tag; + +import java.io.IOException; + +import javax.servlet.http.HttpSession; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.tagext.TagSupport; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.themes.CSSThemeVisualElement; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; + +/** + * Output the required css based in the user's details. Will output one or more + * lines. If the user has a theme then exports the default and then the user's + * style sheet. If the user doesn't have a theme then it just exports + * the default. This way, if the user's entry points to a stylesheet that + * doesn't exist, the default one is always available. + * + * @jsp.tag name="css" + * bodycontent="empty" + * display-name="User's chosen stylesheet" + * description="Output stylesheet based on the user preferences." + * + * @author Fiona Malikoff + */ +public class CssTag extends TagSupport { + + private static final Logger log = Logger.getLogger(CssTag.class); + + /** + * + */ + public CssTag() { + super(); + } + + public int doStartTag() throws JspException { + String customStylesheetLink = null; + String serverURL = Configuration.get(ConfigurationKeys.SERVER_URL); + + HttpSession ss = SessionManager.getSession(); + if ( ss != null ) { + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + if ( user != null ) { + CSSThemeVisualElement theme = user.getTheme(); + if ( theme != null && theme.getName() != null ) { + customStylesheetLink = generateLink(theme.getName(),serverURL); + } + } + } + + try { + JspWriter writer = pageContext.getOut(); + if ( customStylesheetLink != null ) { + writer.print(customStylesheetLink); + } + writer.print(generateLink("default",serverURL)); + } catch ( IOException e ) { + log.error("CssTag unable to write out CSS details due to IOException.", e); + // don't throw a JSPException as we want the system to still function. + } + + return SKIP_BODY; + } + + private String generateLink(String stylesheetName, String serverURL) { + if ( serverURL.endsWith("/") ) { + return ""; + } else { + return ""; + } + } + + public int doEndTag() { + return EVAL_PAGE; + } + +} Index: lams_central/src/java/org/lamsfoundation/lams/web/tag/LAMSURLTag.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/tag/LAMSURLTag.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/tag/LAMSURLTag.java (revision 8ba43ae6cd465e24431866147a53ae7e43102efd) @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * ***********************************************************************/ + +package org.lamsfoundation.lams.web.tag; + +import java.io.IOException; + +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.tagext.TagSupport; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; + +/** + * Output the server url from the value stored in the shared session. This + * will be the same value as the server url in the lams.xml configuration file. + * + * @jsp.tag name="LAMSURL" + * bodycontent="empty" + * display-name="LAMS URL" + * description="Output the Server URL as defined in the lams.xml configuration file." + * + * @author Fiona Malikoff + */ +public class LAMSURLTag extends TagSupport { + + private static final long serialVersionUID = -3773379475085729642L; + + private static final Logger log = Logger.getLogger(LAMSURLTag.class); + + /** + * + */ + public LAMSURLTag() { + super(); + } + + public int doStartTag() throws JspException { + String serverURL = Configuration.get(ConfigurationKeys.SERVER_URL); + serverURL = ( serverURL != null ? serverURL.trim() : null); + if ( serverURL != null || serverURL.length()>0 ) { + JspWriter writer = pageContext.getOut(); + try { + writer.print(serverURL); + } catch ( IOException e ) { + log.error("ServerURLTag unable to write out server URL due to IOException. ", e); + throw new JspException(e); + } + } else { + log.warn("ServerURLTag unable to write out server URL as it is missing from the configuration file."); + } + + return SKIP_BODY; + } + + public int doEndTag() { + return EVAL_PAGE; + } + +} Index: lams_central/src/java/org/lamsfoundation/lams/web/tag/UserTag.java =================================================================== diff -u -r21a863a43f70c5031702508737bc34e7323e1d36 -r8ba43ae6cd465e24431866147a53ae7e43102efd --- lams_central/src/java/org/lamsfoundation/lams/web/tag/UserTag.java (.../UserTag.java) (revision 21a863a43f70c5031702508737bc34e7323e1d36) +++ lams_central/src/java/org/lamsfoundation/lams/web/tag/UserTag.java (.../UserTag.java) (revision 8ba43ae6cd465e24431866147a53ae7e43102efd) @@ -38,7 +38,7 @@ /** * Output a property from the userDTO object in the shared session. * - * Has a single paramter "property", which is the name of the property from the UserDTO to be accessed. + * Has a single parameter "property", which is the name of the property from the UserDTO to be accessed. * May be: userID, firstName, lastName, login, email. * * Doesn't support theme yet - to be added when we work out what we want from the theme details. @@ -52,6 +52,8 @@ */ public class UserTag extends TagSupport { + private static final long serialVersionUID = -2801719186682639858L; + private static final Logger log = Logger.getLogger(UserTag.class); /** The property to be output */ Index: lams_central/src/java/org/lamsfoundation/lams/web/tag/WebAppURLTag.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/tag/WebAppURLTag.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/tag/WebAppURLTag.java (revision 8ba43ae6cd465e24431866147a53ae7e43102efd) @@ -0,0 +1,92 @@ +/*************************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * ***********************************************************************/ + +package org.lamsfoundation.lams.web.tag; + +import java.io.IOException; + +import javax.servlet.ServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; +import javax.servlet.jsp.tagext.TagSupport; + +import org.apache.log4j.Logger; + +/** + * Output the base part of the current web app url (e.g. http://server/lams/tool/nb11/) + * based on the current servlet details. + * + * @jsp.tag name="WebAppURL" + * bodycontent="empty" + * display-name="Base URL for the current web app" + * description="Output the basic URL for the current webapp. e.g. http://server/lams/tool/nb11/" + * + * @author Fiona Malikoff + */ +public class WebAppURLTag extends TagSupport { + + private static final long serialVersionUID = -3773379475085729642L; + + private static final Logger log = Logger.getLogger(WebAppURLTag.class); + + /** + * + */ + public WebAppURLTag() { + super(); + } + + public int doStartTag() throws JspException { + ServletRequest sr = pageContext.getRequest(); + if ( HttpServletRequest.class.isInstance(sr) ) { + HttpServletRequest request = (HttpServletRequest) sr; + + String protocol = request.getProtocol(); + if(protocol.startsWith("HTTPS")){ + protocol = "https://"; + }else{ + protocol = "http://"; + } + + String path = protocol+request.getServerName()+":"+request.getServerPort()+request.getContextPath(); + if ( ! path.endsWith("/") ) + path = path + "/"; + + try { + JspWriter writer = pageContext.getOut(); + writer.print(path); + } catch ( IOException e ) { + log.error("ServerURLTag unable to write out server URL due to IOException. ", e); + throw new JspException(e); + } + + } else { + log.warn("ServerURLTag unable to write out server URL as the servlet request is not an HttpServletRequest."); + } + return SKIP_BODY; } + + public int doEndTag() { + return EVAL_PAGE; + } + +} Index: lams_central/web/WEB-INF/lams.tld =================================================================== diff -u -r21a863a43f70c5031702508737bc34e7323e1d36 -r8ba43ae6cd465e24431866147a53ae7e43102efd --- lams_central/web/WEB-INF/lams.tld (.../lams.tld) (revision 21a863a43f70c5031702508737bc34e7323e1d36) +++ lams_central/web/WEB-INF/lams.tld (.../lams.tld) (revision 8ba43ae6cd465e24431866147a53ae7e43102efd) @@ -11,6 +11,13 @@ + LAMSURL + org.lamsfoundation.lams.web.tag.LAMSURLTag + + + + + user org.lamsfoundation.lams.web.tag.UserTag @@ -23,5 +30,19 @@ + + css + org.lamsfoundation.lams.web.tag.CssTag + + + + + + WebAppURL + org.lamsfoundation.lams.web.tag.WebAppURLTag + + + + Index: lams_monitoring/web/WEB-INF/lams.tld =================================================================== diff -u -r4ffb4f1a2bfc99e753289a089a51c92129409397 -r8ba43ae6cd465e24431866147a53ae7e43102efd --- lams_monitoring/web/WEB-INF/lams.tld (.../lams.tld) (revision 4ffb4f1a2bfc99e753289a089a51c92129409397) +++ lams_monitoring/web/WEB-INF/lams.tld (.../lams.tld) (revision 8ba43ae6cd465e24431866147a53ae7e43102efd) @@ -11,6 +11,13 @@ + LAMSURL + org.lamsfoundation.lams.web.tag.LAMSURLTag + + + + + user org.lamsfoundation.lams.web.tag.UserTag @@ -23,5 +30,19 @@ + + css + org.lamsfoundation.lams.web.tag.CssTag + + + + + + WebAppURL + org.lamsfoundation.lams.web.tag.WebAppURLTag + + + +