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.

This commit is contained in:
rjy7 2010-05-14 20:01:13 +00:00
parent f5fe62039e
commit 138f5bf496
3 changed files with 34 additions and 371 deletions

View file

@ -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"%><jsp:useBean id="loginHandler" class="edu.cornell.mannlib.vedit.beans.LoginFormBean" scope="session" />
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.FreeMarkerHttpServlet" %>
<%
/**
* @version 1.00
* @author Jon Corson-Rikert
* UPDATES:
* 2006-01-04 bdc removed <head> and <body> tags and moved from <table> to <div>
* 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");
// 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);
}
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;
%>
<c:set var="currentYear" value="<%= Calendar.getInstance().get(Calendar.YEAR) %>" />
<c:set var='context' value="<%=vreq.getContextPath()%>" />
<c:set var='themePath'>
<c:if test="${!empty context && context != ''}">/${context}</c:if>/<%=portal.getThemeDir()%>
</c:set>
<c:set var='themeDir'><c:out value='${themePath}' default='/themes/vivo-basic/' /></c:set>
<c:set var="currentPortal" value="<%=portal.getPortalId()%>"/>
<c:set var="contactMailSetup" value="<%= ContactMailServlet.getSmtpHostFromProperties() != null %>"/>
<div id='footer'>
<% if (!(portal.getBannerImage() == null || portal.getBannerImage().equals("")))
{ %>
<img class="footerLogo" src="${themeDir}site_icons/<%=portal.getBannerImage()%>" alt="<%=portal.getShortHand()%>"/>
<% } %>
<div class='footerLinks'>
<ul class="otherNav">
<c:url var="aboutHref" value="<%= Controllers.ABOUT %>">
<c:param name="home" value="${currentPortal}"/>
</c:url>
<c:set var="aboutHref">
<c:out value="${aboutHref}" escapeXml="true"/>
</c:set>
<li<c:if test="${!contactMailSetup}"> class="last"</c:if>><a href="${aboutHref}" title="more about this web site">About</a></li>
<c:url var="contactHref" value="/comments">
<c:param name="home" value="${currentPortal}"/>
</c:url>
<c:set var="contactHref">
<c:out value="${contactHref}" escapeXml="true"/>
</c:set>
<c:if test="${contactMailSetup}">
<li class="last"><a href="${contactHref}" title="feedback form">Contact Us</a></li>
</c:if>
</ul>
</div>
<% if (portal.getCopyrightAnchor() != null && portal.getCopyrightAnchor().length()>0) { %>
<div class='copyright'>
&copy;${currentYear}&nbsp;
<% if (portal.getCopyrightURL() != null && portal.getCopyrightURL().length()>0) { %>
<a href="<%=portal.getCopyrightURL()%>">
<% } %>
<%=portal.getCopyrightAnchor()%>
<% if (portal.getCopyrightURL() != null && portal.getCopyrightURL().length()>0) { %>
</a>
<% } %>
</div>
<div class='copyright'>
All Rights Reserved. <a href="termsOfUse?home=<%=portal.getPortalId()%>">Terms of Use</a>
</div>
<% } %>
</div>
${ftl_footer}

View file

@ -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"%><jsp:useBean id="loginHandler" class="edu.cornell.mannlib.vedit.beans.LoginFormBean" scope="session" />
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.FreeMarkerHttpServlet" %>
<%
/**
*
* @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();
// 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);
}
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;
%>
<c:set var='context' value="<%=vreq.getContextPath()%>" />
<c:set var='themePath'>
<c:if test="${!empty context && context != ''}">/${context}</c:if>/<%=portal.getThemeDir()%>
</c:set>
<c:set var='themeDir'><c:out value='${themePath}' default='/themes/vivo-basic/' /></c:set>
<c:set var="currentPortal" value="<%=portal.getPortalId()%>"/>
<c:set var="contactMailSetup" value="<%= ContactMailServlet.getSmtpHostFromProperties() != null %>"/>
<%
String homeURL = (portal.getRootBreadCrumbURL()!=null && portal.getRootBreadCrumbURL().length()>0) ?
portal.getRootBreadCrumbURL() : request.getContextPath()+"/";
%>
<!-- uncomment this div to place your institutional branding/identity at the top of every page
<div id="institution">
</div>
-->
<div id="identity">
<h1><a title="Home" href="<%=homeURL%>"><%out.print(portal.getAppName());%></a></h1>
<!--
<% if (portal.getShortHand() != null) { %>
<em><%out.print(portal.getShortHand());%></em>
<% } %>
-->
<ul id="otherMenu">
<%-- A user is logged in --%>
<% if (securityLevel > 0) { %>
<c:url var="logoutHref" value="<%= Controllers.LOGOUT_JSP %>">
<c:param name="home" value="${currentPortal}" />
<c:param name="loginSubmitMode" value="Log Out" />
</c:url>
<c:url var="siteAdminHref" value="<%= Controllers.SITE_ADMIN %>">
<c:param name="home" value="${currentPortal}" />
</c:url>
<li>
Logged in as <strong><%= loginName %></strong> (<a href="${logoutHref}">Log out</a>)
</li>
<li><a href="${siteAdminHref}" >Site Admin</a></li>
<%-- A user is not logged in --%>
<% } else { %>
<c:url var="loginHref" value="<%= Controllers.LOGIN %>">
<c:param name="home" value="${currentPortal}"/>
<c:param name="login" value="block"/>
</c:url>
<li><a title="log in to manage this site" href="${loginHref}">Log in</a></li>
<% } %>
<c:url var="aboutHref" value="<%= Controllers.ABOUT %>">
<c:param name="home" value="${currentPortal}"/>
</c:url>
<c:set var="aboutHref">
<c:out value="${aboutHref}" escapeXml="true"/>
</c:set>
<li<c:if test="${!contactMailSetup}"> class="last"</c:if>><a href="${aboutHref}" title="more about this web site">About</a></li>
<c:if test="${contactMailSetup}" >
<li class="last"><a href='<c:url value="/comments"><c:param name="home" value="${currentPortal}"/></c:url>'>Contact Us</a></li>
</c:if>
</ul>
</div><!-- end identity -->
${ftl_identity}

View file

@ -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" %>
<jsp:useBean id="loginHandler" class="edu.cornell.mannlib.vedit.beans.LoginFormBean" scope="session" />
<%@ page import="edu.cornell.mannlib.vitro.webapp.controller.FreeMarkerHttpServlet" %>
<%
/***********************************************
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();
// 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);
}
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();
}
%>
<c:set var="themeDir">
<c:out value="<%=portal.getThemeDir()%>" default="themes/vivo-basic" />
</c:set>
<c:url var="themePath" value="/${themeDir}" />
<c:url var="searchURL" value="/search"/>
<c:set var="currentPortal" value="<%=portal.getPortalId()%>"/>
<c:set var="rootTab" value="<%=rootId%>"/>
<!-- ************** START menu.jsp ************** -->
<div id="navAndSearch" class="block">
<div id="primaryAndOther">
<ul id="primary">
<c:forEach items="${primaryTabs}" var="tab">
<li>
<c:remove var="activeClass"/>
<c:if test="${param.primary==tab.tabId}">
<c:set var="activeClass"> class="activeTab" </c:set>
</c:if>
<c:forEach items="${tabLevels}" var="subTab">
<c:if test="${subTab==tab.tabId && subTab != rootTab}">
<c:set var="activeClass"> class="activeTab" </c:set>
</c:if>
</c:forEach>
${ftl_menu}
${ftl_search}
</div> <!-- end navAndSearch -->
<c:url var="tabHref" value="/index.jsp"><c:param name="primary" value="${tab.tabId}"/></c:url>
<a ${activeClass} href="${tabHref}">
<c:out value="${tab.title}"/></a>
</li>
</c:forEach>
<li>
<a ${indexClass} href="<c:url value="/browsecontroller"/>"
title="list all contents by type">
Index</a>
</li>
</ul>
</div><!--END 'primaryAndOther'-->
<%-- TabMenu.getSecondaryTabMenu(vreq) --%>
<%------------- Search Form -------------%>
<div id="searchBlock">
<form id="searchForm" action="${searchURL}" >
<label for="search">Search </label>
<% if (securityLevel>=FILTER_SECURITY_LEVEL && appBean.isFlag1Active()) { %>
<select id="search-form-modifier" name="flag1" class="form-item" >
<option value="nofiltering" selected="selected">entire database (<%=loginName%>)</option>
<option value="${currentPortal}"><%=portal.getShortHand()%></option>
</select>
<% } else {%>
<input type="hidden" name="flag1" value="${currentPortal}" />
<% } %>
<input type="text" name="querytext" id="search" class="search-form-item" value="<c:out value="${requestScope.querytext}"/>" size="<%=VIVO_SEARCHBOX_SIZE%>" />
<input class="search-form-submit" name="submit" type="submit" value="Search" />
</form>
</div>
<%-- this div is needed for clearing floats --%>
<%-- <div class="clear"></div> --%>
</div><!-- END 'navigation' -->
<div id="breadcrumbs" class="small"><%=BreadCrumbsUtil.getBreadCrumbsDiv(request)%></div>
<!-- ************************ END menu.jsp ************************ -->