1 | /* |
2 | * Copyright 2004 The Apache Software Foundation. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.apache.pluto.driver.tags; |
17 | |
18 | import java.io.IOException; |
19 | |
20 | import javax.servlet.jsp.JspException; |
21 | import javax.servlet.jsp.tagext.TagSupport; |
22 | |
23 | import org.apache.pluto.driver.AttributeKeys; |
24 | |
25 | /** |
26 | * The portlet title tag is used to print the dynamic portlet title to the page. |
27 | * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a> |
28 | * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a> |
29 | * @version 1.0 |
30 | * @since Oct 4, 2004 |
31 | */ |
32 | public class PortletTitleTag extends TagSupport { |
33 | |
34 | // TagSupport Impl --------------------------------------------------------- |
35 | |
36 | /** |
37 | * Method invoked when the start tag is encountered. This method retrieves |
38 | * the portlet title and print it to the page. |
39 | * |
40 | * @see org.apache.pluto.services.PortalCallbackService#setTitle(HttpServletRequest, PortletWindow, String) |
41 | * @see org.apache.pluto.driver.services.container.PortalCallbackServiceImpl#setTitle(HttpServletRequest, PortletWindow, String) |
42 | * |
43 | * @throws JspException |
44 | */ |
45 | public int doStartTag() throws JspException { |
46 | |
47 | // Ensure that the portlet title tag resides within a portlet tag. |
48 | PortletTag parentTag = (PortletTag) TagSupport.findAncestorWithClass( |
49 | this, PortletTag.class); |
50 | if (parentTag == null) { |
51 | throw new JspException("Portlet title tag may only reside " |
52 | + "within a pluto:portlet tag."); |
53 | } |
54 | |
55 | // Print out the portlet title to page. |
56 | try { |
57 | pageContext.getOut().print(pageContext.getRequest().getAttribute( |
58 | AttributeKeys.PORTLET_TITLE)); |
59 | } catch (IOException ex) { |
60 | throw new JspException(ex); |
61 | } |
62 | return SKIP_BODY; |
63 | } |
64 | } |
65 | |