📄 layouttag.java
字号:
/* * LayoutTag.java * * Version: $Revision: 1.17 $ * * Date: $Date: 2005/10/31 19:46:36 $ * * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts * Institute of Technology. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of the Hewlett-Packard Company nor the name of the * Massachusetts Institute of Technology nor the names of their * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */package org.dspace.app.webui.jsptag;import java.io.IOException;import java.util.ArrayList;import java.util.List;import javax.servlet.RequestDispatcher;import javax.servlet.ServletConfig;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletResponse;import javax.servlet.jsp.JspException;import javax.servlet.jsp.jstl.fmt.LocaleSupport;import javax.servlet.jsp.tagext.TagSupport;import org.apache.log4j.Logger;import org.dspace.content.Collection;import org.dspace.content.Community;import org.dspace.core.ConfigurationManager;/** * Tag for HTML page layout ("skin"). * <P> * This tag <em>sets</em> request attributes that should be used by the header * and footer to render the page appropriately: * <P> * <ul> * <li><code>dspace.layout.title</code>- title of page</li> * <li><code>dspace.layout.locbar</code>- value will Boolean true or false * </li> * <li><code>dspace.layout.parenttitles</code>- a <code>List</code> of * <code>String</code> s corresponding with titles to put in the location bar. * Only set if <code>dspace.layout.locbar</code> is true</li> * <li><code>dspace.layout.parentlinks</code>- a <code>List</code> of * <code>String</code> s corresponding with links to put in the location bar. * Empty strings mean no link. Will only be set if * <code>dspace.layout.locbar</code> is true.</li> * <li><code>dspace.layout.navbar</code>- value will be "off", or the * navigation bar to include, e.g. "/layout/navbar_default.jsp"</li> * <li><code>dspace.layout.sidebar</code>- contents of the sidebar</li> * <li><code>dspace.current.user</code>- the EPerson currently logged in, or * <code>null</code> if anonymous access</li> * </ul> * <p> * Furthermore it sets the content type of the response to text/html using UTF-8 * to ensure this will be returned in the HTTP header. * </p> * * @author Robert Tansley * @version $Revision: 1.17 $ */public class LayoutTag extends TagSupport{ /** log4j logger */ private static Logger log = Logger.getLogger(LayoutTag.class); /** layout style name */ private String style; /** title */ private String title; /** title key (from message dictionary) */ private String titleKey; /** Navigation bar type, null means none */ private String navbar; /** Location bar type */ private String locbar; /** Name of "parent" page */ private String parentTitle; /** Name of "parent" page key (from message dictionary) */ private String parentTitleKey; /** Link to "parent" page */ private String parentLink; /** Contents of side bar */ private String sidebar; /** Whether to add headers to prevent browsers caching the page */ private String noCache; /** Syndication feed "autodiscovery" link data */ private String feedData; public LayoutTag() { super(); } public int doStartTag() throws JspException { ServletRequest request = pageContext.getRequest(); // header file String header = "/layout/header-default.jsp"; // Choose default style unless one is specified if (style != null) { header = "/layout/header-" + style.toLowerCase() + ".jsp"; } // Sort out location bar if (locbar == null) { locbar = "auto"; } // These lists will contain titles and links to put in the location // bar List parents = new ArrayList(); List parentLinks = new ArrayList(); if (locbar.equalsIgnoreCase("off")) { // No location bar request.setAttribute("dspace.layout.locbar", new Boolean(false)); } else { // We'll always add "DSpace Home" to the a location bar parents.add(ConfigurationManager.getProperty("dspace.name")); if (locbar.equalsIgnoreCase("nolink")) { parentLinks.add(""); } else { parentLinks.add("/"); } // Add other relevant components to the location bar if (locbar.equalsIgnoreCase("link")) { // "link" mode - next thing in location bar is taken from // parameters of tag, with a link if (parentTitle != null) { parents.add(parentTitle); parentLinks.add(parentLink); } else if (parentTitleKey != null) { parents.add(LocaleSupport.getLocalizedMessage(pageContext, parentTitleKey)); parentLinks.add(parentLink); } } else if (locbar.equalsIgnoreCase("commLink")) { // "commLink" mode - show all parent communities Community[] comms = (Community[]) request .getAttribute("dspace.communities"); if (comms != null) { for (int i = 0; i < comms.length; i++) { parents.add(comms[i].getMetadata("name")); parentLinks.add("/handle/" + comms[i].getHandle()); } } } else if (locbar.equalsIgnoreCase("nolink")) { // "nolink" mode - next thing in location bar is taken from // parameters of tag, with no link if (parentTitle != null) { parents.add(parentTitle); parentLinks.add(""); } } else { // Grab parents from the URL - these should have been picked up // by the HandleServlet Collection col = (Collection) request .getAttribute("dspace.collection"); Community[] comms = (Community[]) request .getAttribute("dspace.communities"); if (comms != null) { for (int i = 0; i < comms.length; i++) { parents.add(comms[i].getMetadata("name")); parentLinks.add("/handle/" + comms[i].getHandle()); } if (col != null) { parents.add(col.getMetadata("name")); parentLinks.add("/handle/" + col.getHandle()); } } } request.setAttribute("dspace.layout.locbar", new Boolean(true)); } request.setAttribute("dspace.layout.parenttitles", parents); request.setAttribute("dspace.layout.parentlinks", parentLinks); // Navigation bar: "default" is default :) if (navbar == null) { navbar = "default"; } if (navbar.equals("off")) { request.setAttribute("dspace.layout.navbar", "off"); } else { request.setAttribute("dspace.layout.navbar", "/layout/navbar-" + navbar + ".jsp"); } // Set title if (title != null) { request.setAttribute("dspace.layout.title", title); } else if (titleKey != null) { request.setAttribute("dspace.layout.title", LocaleSupport .getLocalizedMessage(pageContext, titleKey)); } else { request.setAttribute("dspace.layout.title", "NO TITLE"); } // Set feedData if present if (feedData != null && ! "NONE".equals(feedData)) { // set the links' reference - community or collection boolean commLinks = feedData.startsWith("comm:"); if ( commLinks ) { Community com = (Community)request.getAttribute("dspace.community"); request.setAttribute("dspace.layout.feedref", com.getHandle()); } else { Collection col = (Collection)request.getAttribute("dspace.collection"); request.setAttribute("dspace.layout.feedref", col.getHandle()); } // build a list of link attributes for each link format String[] formats = feedData.substring(feedData.indexOf(":")+1).split(","); List linkParts = new ArrayList(); // each link has a mime-type, title, and format (used in href URL) for (int i = 0; i < formats.length; i++) { if("rss_1.0".equals(formats[i])) { linkParts.add("rdf+xml"); } else { linkParts.add("rss+xml"); } if (commLinks) { linkParts.add("Items in Community"); } else { linkParts.add("Items in Collection"); } linkParts.add(formats[i]); } request.setAttribute("dspace.layout.linkparts", linkParts); } else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -