KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > portlet > taglib > NamespaceTag


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.portlet.taglib;
10
11 import java.io.IOException JavaDoc;
12
13 import javax.servlet.jsp.JspException JavaDoc;
14
15 import org.jboss.portal.server.Instance;
16 import org.jboss.portal.server.Window;
17 import org.jboss.portal.server.invocation.AttachmentKey;
18 import org.jboss.portal.server.invocation.Invocation;
19
20 /**
21  * The namespace tag for the JSR 168 Portlet specification.
22  *
23  * This tag produces a unique value for the current portlet.
24  *
25  * This tag should be used for named elements in the portlet output
26  * (such as Javascript functions and variables). The namespacing
27  * ensures that the given name is uniquely associated with this
28  * portlet and avoids name conflicts with other elements on the portal
29  * page or with other portlets on the page.
30  *
31  * @author <a HREF="mailto:sgwood@ix.netcom.com">Sherman Wood</a>
32  * @version $Revision: 1.2 $
33  *
34  * @jsp.tag name="namespace"
35  * body-content="empty"
36  *
37  */

38 public class NamespaceTag extends PortletTag
39 {
40
41    public int doStartTag() throws JspException JavaDoc
42    {
43       return SKIP_BODY;
44    }
45
46    public int doEndTag() throws JspException JavaDoc
47    {
48       Invocation invocation = getInvocation();
49
50       Window window = (Window)invocation.getAttachment(AttachmentKey.WINDOW);
51       Instance instance = (Instance)window.getInstance();
52       try
53       {
54          // This is org.jboss.portal...fullyQualifiedClassName@instanceId
55
String JavaDoc baseString = instance.toString();
56          int atPos = baseString.indexOf("@");
57          int lastDotPos = baseString.lastIndexOf(".");
58
59          String JavaDoc instanceId = baseString.substring(atPos + 1);
60          String JavaDoc className = baseString.substring(lastDotPos + 1, atPos);
61
62          // Want to spit out "_className_instanceId" as the namespace
63

64          pageContext.getOut().print("_" + className + "_" + instanceId);
65       }
66       catch (IOException JavaDoc e)
67       {
68          e.printStackTrace();
69       }
70       return EVAL_PAGE;
71    }
72 }
73
Popular Tags