001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.theme.tag;
023:
024: import org.jboss.logging.Logger;
025: import org.jboss.portal.common.NotYetImplemented;
026: import org.jboss.portal.theme.LayoutConstants;
027: import org.jboss.portal.theme.render.renderer.PageRendererContext;
028:
029: import javax.servlet.http.HttpServletRequest;
030: import javax.servlet.jsp.JspException;
031: import javax.servlet.jsp.JspWriter;
032: import javax.servlet.jsp.PageContext;
033: import javax.servlet.jsp.tagext.SimpleTagSupport;
034: import java.io.IOException;
035:
036: /**
037: * Tag handler for the portlet tag. <p>This tag adds the created markup of a Portlet to a page. The portlet tag utilizes
038: * a render set to create the markup around the portlet. The render set takes care of the portlet window, hence it
039: * creates the markup for the title, and the mode and state links. This tag does not initiate the call to the portlet
040: * container, but rather is ment to assist in laying out the rendered markup, after it is generated by the portlet.
041: * (place the already rendered markup of portlet x here....)</p>
042: *
043: * @author <a href="mailto:mholzner@novell.com">Martin Holzner</a>.
044: * @version <tt>$Revision: 8784 $</tt>
045: * @see org.jboss.portal.theme.PortalRenderSet
046: */
047: public class PortletTagHandler extends SimpleTagSupport {
048: private static Logger log = Logger
049: .getLogger(PortletTagHandler.class);
050: private String windowName = null;
051:
052: /**
053: * create the markup of this tag <p>Get a render set from the renderer factory, and call the window renderer to
054: * generate the root container for this Portlet's markup. The window renderer then delegates to the decoration
055: * renderer and the portlet renderer to create the markup for the title and the mode and state links, and to add the
056: * Portlet's markup.</p>
057: *
058: * @throws javax.servlet.jsp.JspException
059: * @throws java.io.IOException
060: * @see org.jboss.portal.theme.PortalRenderSet#getWindowRenderer
061: * @see org.jboss.portal.theme.render.renderer.WindowRenderer#render
062: * @see org.jboss.portal.theme.render.renderer.PortletRenderer#render
063: * @see org.jboss.portal.theme.render.renderer.DecorationRenderer#render
064: */
065: public void doTag() throws JspException, IOException {
066: log.debug("rendering portlet " + windowName);
067:
068: JspWriter out = this .getJspContext().getOut();
069:
070: if (getWindowName() == null) {
071: out.write("<p bgcolor='red'>No Portlet to render!</p>");
072: out
073: .write("<p bgcolor='red'>The Portlet to render must be set in the tag attribute '"
074: + LayoutConstants.ATTR_PORTLET_WINDOW_NAME
075: + "'</p>");
076: out.flush();
077: return;
078: }
079:
080: PageContext app = (PageContext) getJspContext();
081: HttpServletRequest request = (HttpServletRequest) app
082: .getRequest();
083:
084: PageRendererContext page = (PageRendererContext) request
085: .getAttribute(LayoutConstants.ATTR_PAGE);
086: if (page == null) {
087: out.write("<p bgcolor='red'>No page to render!</p>");
088: out
089: .write("<p bgcolor='red'>The page to render (PageResult) must be set in the request attribute '"
090: + LayoutConstants.ATTR_PAGE + "'</p>");
091: out.flush();
092: return;
093: }
094:
095: // String windowID = null;
096: // boolean wIdFound = false;
097: // // we have the windowName (which is the window name), but we need the
098: // // window id
099: // Map portletContexts = page.getWindowContextMap();
100: // for (Iterator i = portletContexts.keySet().iterator(); i.hasNext();) {
101: // windowID = (String) i.next();
102: // WindowContext portletContext = (WindowContext) portletContexts
103: // .get(windowID);
104: // if (windowName.equals(portletContext.getWindowName())) {
105: // wIdFound = true;
106: // if (log.isDebugEnabled()) {
107: // log.debug("found the portlet to render: " + windowName);
108: // }
109: // break;
110: // }
111: // }
112: //
113: // if (!wIdFound) {
114: // log
115: // .warn("can't find the window id of the window name on this page. Page=["
116: // + page.getPageName()
117: // + "] and Window=["
118: // + windowName
119: // + "]. This window won't be shown in page.");
120: // return;
121: // }
122: // if (page.getWindowContext(windowID) == null) {
123: // log.warn("no such window on this page. Page [" + page.getPageName()
124: // + "] Window name [" + windowName + "]" + "] Window Id ["
125: // + windowID + "]");
126: // return;
127: // }
128: //
129: // WindowContext windowContext = page.getWindowContext(windowID);
130: // RenderContext renderContext = (RenderContext)request.getAttribute(LayoutConstants.ATTR_RENDERCONTEXT);
131: //
132: // PageRenderContextImpl prc = new PageRenderContextImpl(page);
133: // String regionName = windowContext.getRegionName();
134: // Region region = page.getRegion(regionName);
135: // RegionRenderContext rrc = new RegionRenderContextImpl(prc, region, null, null);
136: // for (Iterator i = rrc.getWindowRenderContexts().iterator();i.hasNext();)
137: // {
138: // WindowRenderContext wrc = (WindowRenderContext)i.next();
139: // if (wrc.getId().equals(windowContext.getId()))
140: // {
141: // try {
142: // renderContext.render(wrc);
143: // out.write(renderContext.getMarkupFragment().toString());
144: // out.flush();
145: // } catch (RenderException e) {
146: // throw new JspException(e);
147: // }
148: // break;
149: // }
150: // }
151:
152: throw new NotYetImplemented();
153: }
154:
155: public String getWindowName() {
156: return windowName;
157: }
158:
159: public void setWindowName(String portletWindowName) {
160: if (log.isDebugEnabled()) {
161: log.debug("setting window name: " + portletWindowName);
162: }
163: this.windowName = portletWindowName;
164: }
165: }
|