<%-- $This file is distributed under the terms of the license in /doc/license.txt$ --%> <%@ page errorPage="/error.jsp"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.web.TabWebUtil" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Tab" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.controller.VitroRequest" %> <%@ page import="java.util.Collection" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Portal" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Individual" %> <%@ page import="edu.cornell.mannlib.vitro.webapp.beans.Link" %> <%@ page import="java.net.URLEncoder" %> <%@ page import="org.joda.time.format.DateTimeFormatter" %> <%@ page import="org.joda.time.format.ISODateTimeFormat" %> <%@ page import="org.joda.time.DateTime" %> <% /****************************** Takes tab and populates Atom feed with: requested tab and its description entities associated with this tab immediate children of this tab and their descriptions ******************************/ response.setContentType("application/atom+xml"); Tab leadingTab = (Tab) request.getAttribute("leadingTab"); if (leadingTab == null) { String e = "tabprimary expects that request attribute 'leadingTab' be set to a TabBean object"; throw new JspException(e); } Collection individuals = leadingTab.getRelatedEntities(); Collection tabs = leadingTab.getChildTabs(); Portal portal = (Portal)request.getAttribute("portalBean"); int portalId = -1; if (portal==null) { portalId=1; } else { portalId=portal.getPortalId(); } DateTime dt = new DateTime(); DateTimeFormatter dtf = ISODateTimeFormat.basicDateTimeNoMillis(); String time = dtf.print(dt.getMillis()); time = time.substring(0,4)+"-"+time.substring(4,6)+"-"+time.substring(6,11)+":"+time.substring(11,13)+":"+time.substring(13,15)+"Z"; %> <%! public String forURL(String frag) { String result = null; try { result = URLEncoder.encode(frag, "UTF-8"); } catch (Exception ex) { throw new RuntimeException("UTF-8 not supported", ex); } return result; } public String escapeEntity(String frag) { if(frag.contains("&")) frag = replaceAll(frag, "&", "&"); if(frag.contains("'")) frag = replaceAll(frag, "'", "'"); if(frag.contains("\"")) frag = replaceAll(frag, "\"", """); if(frag.contains(">")) frag = replaceAll(frag, ">", ">"); if(frag.contains("<")) frag = replaceAll(frag, "<", "<"); return frag; } public String replaceAll(String original, String match, String replace) { int index1 = original.indexOf(match); int index2 = original.indexOf(replace); if(index1 == index2 && index1 != -1) { original = original.substring(0, index1+replace.length()+1)+replaceAll(original.substring(index1+replace.length()+1), match, replace); return original; } if(index1 == -1) return original; String before = original.substring(0, index1) + replace; return before + replaceAll(original.substring(index1+1), match, replace); } %> "> <%= escapeEntity(leadingTab.getTitle()) %> <%= leadingTab.getDescription() %> " rel="self" type="application/atom+xml" /> <%= "http://"+request.getServerName()+":"+request.getLocalPort()+request.getContextPath()+escapeEntity("/index.jsp?home="+portalId+"&"+leadingTab.getTabDepthName()+"="+leadingTab.getTabId()) %> <%= time %> Vivo vivo@cornell.edu <% for(Individual i:individuals) { %> <%= escapeEntity(i.getName()) %> <% if (i.getLinksList() == null) { %> <% for(Link l: i.getLinksList()) { %> <% } %> <% } else { %> <% } %> <%= i.getURI() %> <%= time %> <% if (i.getBlurb() != null) { %> <% if (i.getBlurb().matches(".*<.*>.*")) { %>
<%= i.getBlurb() %>
<% } %> <% else { %> <%= i.getBlurb() %> <% } %> <% } %> <% if (i.getDescription() != null) { %>
<%= i.getDescription() %>
<% } %>
<% } %> <% if (tabs != null) { %> <% for(Tab t:tabs) { %> <%= escapeEntity(t.getTitle()) %> <%= "http://"+request.getServerName()+":"+request.getLocalPort()+request.getContextPath()+escapeEntity("/index.jsp?home="+portalId+"&"+t.getTabDepthName()+"="+t.getTabId()) %> <%= time %> <% if (t.getDescription() != null) { %> <% if (t.getDescription().matches(".*<.*>.*")) { %>
<%= t.getDescription() %>
<% } %> <% else { %> <%= t.getDescription() %> <% } %> <% } %> <% if (t.getBody() != null) { %>
<%= t.getBody() %>
<% } %>
<% } %> <% } %>