From 138f5bf4960e78277b6dfee12d3f43763c3abb6a Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 14 May 2010 20:01:13 +0000 Subject: [PATCH] Use FreeMarker templates to generate page identity, menu, search, and footer in JSP pages. This will allow theme authors to work just with the ftls rather than having to maintain both jsp and ftl versions of these templates, during the transition from JSP to FreeMarker. --- themes/vivo-basic/jsp/footer.jsp | 112 +++------------------- themes/vivo-basic/jsp/identity.jsp | 144 ++-------------------------- themes/vivo-basic/jsp/menu.jsp | 149 +++-------------------------- 3 files changed, 34 insertions(+), 371 deletions(-) diff --git a/themes/vivo-basic/jsp/footer.jsp b/themes/vivo-basic/jsp/footer.jsp index a0968c80..0c25ccd7 100644 --- a/themes/vivo-basic/jsp/footer.jsp +++ b/themes/vivo-basic/jsp/footer.jsp @@ -1,98 +1,14 @@ -<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> - -<%@ page language="java"%> - -<%@ page import="java.util.Calendar" %> -<%@ page import="org.apache.commons.logging.Log" %> -<%@ page import="org.apache.commons.logging.LogFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.web.*"%> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %><%/* this odd thing points to something in web.xml */ %> - -<%@page import="edu.cornell.mannlib.vitro.webapp.controller.ContactMailServlet"%> -<% - /** - * @version 1.00 - * @author Jon Corson-Rikert - * UPDATES: - * 2006-01-04 bdc removed and tags and moved from to
- * 2005-07-07 JCR included LoginFormBean so can substitute filterbrowse for portalbrowse for authorized users - */ - - final Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.web.themes.vivo-basic.footer.jsp"); - - VitroRequest vreq = new VitroRequest(request); - - Portal portal = vreq.getPortal(); - if (portal==null) { - log.error("portal from vreq.getPortal() null in themes/vivo-basic/footer.jsp"); - } - HttpSession currentSession = request.getSession(); - - boolean authorized = false; - if (loginHandler.getLoginStatus().equals("authenticated")) /* test if session is still valid */ - if (currentSession.getId().equals(loginHandler.getSessionId())) - if (request.getRemoteAddr().equals( - loginHandler.getLoginRemoteAddr())) - authorized = true; - -%> - - - - - /${context}/<%=portal.getThemeDir()%> - - - - - - +<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> + +<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.FreeMarkerHttpServlet" %> +<% + // If the request was for a jsp rather than a servlet, we didn't get these yet. + // This is here as a safety net. We should have gotten the values in identity.jsp, + // since it's the first one we hit. + String footer = (String) request.getAttribute("ftl_footer"); + if (footer == null) { + FreeMarkerHttpServlet.getFreeMarkerComponentsForJsp(request, response); + } +%> + +${ftl_footer} \ No newline at end of file diff --git a/themes/vivo-basic/jsp/identity.jsp b/themes/vivo-basic/jsp/identity.jsp index 0681b25d..37550b2b 100644 --- a/themes/vivo-basic/jsp/identity.jsp +++ b/themes/vivo-basic/jsp/identity.jsp @@ -1,140 +1,12 @@ <%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> -<%@ page language="java" %> -<%@ page errorPage="error.jsp"%> -<%@ page import="org.apache.commons.logging.Log" %> -<%@ page import="org.apache.commons.logging.LogFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.web.TabMenu" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.web.BreadCrumbsUtil" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.Controllers" %> - -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> - - -<%@page import="edu.cornell.mannlib.vitro.webapp.controller.ContactMailServlet"%> - -<% - /** - * - * @version 1.00 - * @author Jon Corson-Rikert, Brian Caruso, and Brian Lowe - * - * UPDATES: - * 2009-04-20 MW542 moved search form to menu.jsp - * 2007-09-27 BJL moved VIVO and CALS-specific markup to VIVO clone - * 2006-01-31 BJL edited to remove deprecated markup - * 2005-11-06 JCR put styling on extra search selection box - * 2005-10-25 JCR changed local ALL CALS RESEARCH constant to appBean.getSharedPortalFlagNumeric() - * 2005-10-11 JCR tweaks to VIVO search label spacing in header - * 2005-09-15 JCR,BDC converted to use revised ApplicationBean and PortalBean - * 2005-08-16 JCR added CALS_IMPACT contant and modified code to use CALS display for that portal - * 2005-08-01 JCR changed ordering of other portals being displayed to displayRank instead of appName (affects SGER, CALS portals) - * 2005-07-05 JCR retrieving ONLY_CURRENT and ONLY_PUBLIC from database and setting in ApplicationBean - * 2005-06-20 JCR enabling a common CALS research portal via ALL CALS RESEARCH - * 2005-06-20 JCR removed MIN_STATUS_ID and minstatus parameter from search -- has been changed to interactive-only maxstatus parameter - * JCR 2005-06-14 : added isInitialized() test for appBean and portalBean - */ - - HttpSession currentSession = request.getSession(); - String currentSessionIdStr = currentSession.getId(); - int securityLevel = -1; - String loginName = null; - if (loginHandler.testSessionLevel(request) > -1) { - securityLevel = Integer.parseInt(loginHandler.getLoginRole()); - loginName = loginHandler.getLoginName(); - } - - final Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.web.menu.jsp"); - - VitroRequest vreq = new VitroRequest(request); - Portal portal = vreq.getPortal(); - - int portalId = -1; - if (portal==null) { - log.error("Attribute 'portalBean' missing or null; portalId defaulted to 1"); - portalId=1; - } else { - portalId=portal.getPortalId(); - } - String fixedTabStr=(fixedTabStr=request.getParameter("fixed"))==null?null:fixedTabStr.equals("")?null:fixedTabStr; - - +<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.FreeMarkerHttpServlet" %> +<% + // If the request was for a jsp rather than a servlet, we didn't get these yet. + String identity = (String) request.getAttribute("ftl_identity"); + if (identity == null) { + FreeMarkerHttpServlet.getFreeMarkerComponentsForJsp(request, response); + } %> - - - /${context}/<%=portal.getThemeDir()%> - - - - - -<% -String homeURL = (portal.getRootBreadCrumbURL()!=null && portal.getRootBreadCrumbURL().length()>0) ? -portal.getRootBreadCrumbURL() : request.getContextPath()+"/"; -%> - - - -
- -

<%out.print(portal.getAppName());%>

- - -
    - - <%-- A user is logged in --%> - <% if (securityLevel > 0) { %> - - - - - - - - - - -
  • - Logged in as <%= loginName %> (Log out) -
  • - -
  • Site Admin
  • - - <%-- A user is not logged in --%> - <% } else { %> - - - - - - -
  • Log in
  • - <% } %> - - - - - - - - - class="last">About - - -
  • Contact Us
  • -
    -
- -
+${ftl_identity} diff --git a/themes/vivo-basic/jsp/menu.jsp b/themes/vivo-basic/jsp/menu.jsp index 55384952..a76ce52c 100644 --- a/themes/vivo-basic/jsp/menu.jsp +++ b/themes/vivo-basic/jsp/menu.jsp @@ -1,146 +1,21 @@ <%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> -<%@ page import="org.apache.commons.logging.Log" %> -<%@ page import="org.apache.commons.logging.LogFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.web.TabMenu" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.web.BreadCrumbsUtil" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.web.TabWebUtil" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory" %> -<%@ page import="edu.cornell.mannlib.vitro.webapp.web.PortalWebUtil" %> -<%@page import="java.util.List"%> -<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> -<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> - - - -<% - /*********************************************** - Make the Tab menu list and search block - - mw542 2009-04-24 moved search from identity.jsp, updated with new code from bdc34 - bdc34 2006-01-03 created - **********************************************/ - final Log log = LogFactory.getLog("edu.cornell.mannlib.vitro.web.menu.jsp"); - - Portal portal = (Portal)request.getAttribute("portalBean"); - int portalId = -1; - if (portal==null) { - portalId=1; - } else { - portalId=portal.getPortalId(); - } - - VitroRequest vreq = new VitroRequest(request); - - List primaryTabs = vreq.getWebappDaoFactory().getTabDao().getPrimaryTabs(portalId); - request.setAttribute("primaryTabs", primaryTabs); - - int tabId = TabWebUtil.getTabIdFromRequest(vreq); - int rootId = TabWebUtil.getRootTabId(vreq); - List tabLevels = vreq.getWebappDaoFactory().getTabDao().getTabHierarcy(tabId,rootId); - request.setAttribute("tabLevels", tabLevels); - - String uri = (String)request.getAttribute("javax.servlet.forward.request_uri"); - if(uri != null){ - request.setAttribute("indexClass", uri.endsWith("browsecontroller") ? "class=\"activeTab\"" : ""); - - if ( uri.indexOf("about") > 0) { - request.setAttribute("aboutClass","class=\"activeTab\""); - } - if ( uri.indexOf("comments") > 0) { - request.setAttribute("commentsClass","class=\"activeTab\""); - } - } - - // application variables not stored in application bean - final String DEFAULT_SEARCH_METHOD = "fulltext"; - final int FILTER_SECURITY_LEVEL = 4; - final int VIVO_SEARCHBOX_SIZE = 20; - - ApplicationBean appBean = vreq.getAppBean(); - PortalWebUtil.populateSearchOptions(portal, appBean, vreq.getWebappDaoFactory().getPortalDao()); - PortalWebUtil.populateNavigationChoices(portal, request, appBean, vreq.getWebappDaoFactory().getPortalDao()); - - HttpSession currentSession = request.getSession(); - String currentSessionIdStr = currentSession.getId(); - int securityLevel = -1; - String loginName = null; - if (loginHandler.testSessionLevel(request) > -1) { - securityLevel = Integer.parseInt(loginHandler.getLoginRole()); - loginName = loginHandler.getLoginName(); - } - +<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.FreeMarkerHttpServlet" %> +<% + // If the request was for a jsp rather than a servlet, we didn't get these yet. + // This is here as a safety net. We should have gotten the values in identity.jsp, + // since it's the first one we hit. + String menu = (String) request.getAttribute("ftl_menu"); + if (menu == null) { + FreeMarkerHttpServlet.getFreeMarkerComponentsForJsp(request, response); + } %> - - - - - - - - - - - - <%------------- Search Form -------------%> -
-
- - <% if (securityLevel>=FILTER_SECURITY_LEVEL && appBean.isFlag1Active()) { %> - - <% } else {%> - - <% } %> - " size="<%=VIVO_SEARCHBOX_SIZE%>" /> - - -
- -<%-- this div is needed for clearing floats --%> -<%--
--%> - -
- - - -