01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.theme.tag;
23:
24: import org.jboss.portal.theme.LayoutConstants;
25: import org.jboss.portal.theme.page.PageResult;
26: import org.jboss.portal.theme.page.WindowContext;
27: import org.jboss.portal.theme.page.WindowResult;
28:
29: import javax.servlet.http.HttpServletRequest;
30: import javax.servlet.jsp.JspException;
31: import javax.servlet.jsp.JspWriter;
32: import javax.servlet.jsp.PageContext;
33: import javax.servlet.jsp.tagext.SimpleTagSupport;
34: import java.io.IOException;
35: import java.util.Iterator;
36: import java.util.Map;
37:
38: /**
39: * JSP tag to write the header content set as portlet response property. <p>Portlets can set a response property to
40: * signal to the portal that the provided value should be injected into the head of the response document. This tag is
41: * the means to inject that content.</p>
42: *
43: * @author <a href="mailto:mholzner@novell.com>Martin Holzner</a>
44: * @version $LastChangedRevision: 8784 $, $LastChangedDate: 2007-10-27 19:01:46 -0400 (Sat, 27 Oct 2007) $
45: * @see
46: */
47: public class HeaderContentTagHandler extends SimpleTagSupport {
48: public void doTag() throws JspException, IOException {
49: // Get page and region
50: PageContext app = (PageContext) getJspContext();
51: HttpServletRequest request = (HttpServletRequest) app
52: .getRequest();
53:
54: //
55: PageResult page = (PageResult) request
56: .getAttribute(LayoutConstants.ATTR_PAGE);
57: JspWriter out = this .getJspContext().getOut();
58: if (page == null) {
59: out.write("<p bgcolor='red'>No page to render!</p>");
60: out
61: .write("<p bgcolor='red'>The page to render (PageResult) must be set in the request attribute '"
62: + LayoutConstants.ATTR_PAGE + "'</p>");
63: out.flush();
64: return;
65: }
66:
67: //
68: Map results = page.getWindowContextMap();
69: for (Iterator i = results.values().iterator(); i.hasNext();) {
70: WindowContext wc = (WindowContext) i.next();
71: WindowResult result = wc.getResult();
72: if (result.getHeaderContent() != null) {
73: out.println(result.getHeaderContent());
74: }
75: }
76: out.flush();
77: }
78: }
|