KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > net > taglib > FlashParametersTag


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6 */

7 package org.jboss.net.taglib;
8
9 import java.util.Map JavaDoc;
10 import java.util.Iterator JavaDoc;
11
12 import java.net.URL JavaDoc;
13
14 import javax.servlet.http.HttpServletRequest JavaDoc;
15 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
16 import javax.servlet.jsp.JspTagException JavaDoc;
17 import javax.servlet.jsp.JspWriter JavaDoc;
18
19 import javax.management.MBeanServer JavaDoc;
20 import javax.management.ObjectName JavaDoc;
21
22 import org.jboss.mx.util.MBeanServerLocator;
23
24 /**
25  * JSP Tag class for FlashParameters JSP tag. The purpose is to pass
26  * information to a Flash program embedded in a web page so that needed
27  * initial data is available to it. Two types of information are passed, one
28  * set is the hostUrl and the serviceContext of the SOAP server. The second
29  * is a collection of variable name, value pairs that would also be useful to
30  * the Flash program. When a web page contains a Flash program (.swf) file,
31  * it specifies an <OBJECT> tag. Inside the <OBJECT> tag is a parameter such
32  * as:<br><br>
33  *
34  * <p><code>&lt;PARAM NAME=movie VALUE="HelloWorldForm.swf"&gt;</p></code>
35  *
36  * Using a Macromedia specified technique for passing parameters to Flash, we
37  * place at the end of the VALUE attribute, the FlashParameter tag:<br><br>
38  *
39  * <p><code>...m.swf&lt;flash:flashparms/&gt;"&gt;</p></code>
40  *
41  * The instantiated tag becomes:<br><br>
42  *
43  * <p><code>?hostUrl=http://www.yourhost.com:8080&amprootContext=axis</p></code>
44  *
45  * The tag attribute mbeanName, if not specified, has a default value of
46  * "<code>jboss.net:service=Axis</code>"<br><br>
47  *
48  * As an added feature, by specifying a Bean, using the Tag "parms" attribute
49  * that implements the java.util.Map interface the set of key/value pairs are
50  * added to the Flash movie parameter list.
51  *
52  * @created 30. May 2002
53  * @author <a HREF="mailto:fbrier@multideck.com">Frederick N. Brier</a>
54  * @version $Revision: 1.8 $
55  *
56  * @jsp:tag name="flashparms"
57  * body-content="empty"
58  * display-name="Flash Movie Parameters"
59  * description="Provide support for Flash SOAP and parameter passing"
60  *
61  */

62 public class FlashParametersTag extends TagSupport JavaDoc
63 {
64    final public static String JavaDoc DEFAULT_JBOSSNET_MBEAN_NAME =
65       "jboss.net:service=Axis";
66
67    private String JavaDoc mbeanName = null;
68    private Map JavaDoc parms = null;
69
70    public FlashParametersTag()
71    {
72       super();
73
74    }
75
76    /**
77     * Gets the Flash AxisService MBean name.
78     *
79     * @jsp:attribute required="false" rtexprvalue="false"
80     * type="java.lang.String"
81     * description="MBean Name of the Flash AxisService MBean"
82     */

83    public String JavaDoc getMbeanName()
84    {
85       return this.mbeanName;
86    }
87
88    public void setMbeanName(String JavaDoc mbeanName)
89    {
90       this.mbeanName = mbeanName;
91    }
92
93    /**
94     * Gets additional parameters for Flash Movie.
95     *
96     * @jsp:attribute required="false" rtexprvalue="true"
97     * type="java.util.Map"
98     * description="Map collection of parameters for the Flash Movie"
99     */

100    public Map JavaDoc getParms()
101    {
102       return parms;
103    }
104
105    public void setParms(Map JavaDoc parms)
106    {
107       this.parms = parms;
108    }
109
110    public int doStartTag() throws JspTagException JavaDoc
111    {
112       HttpServletRequest JavaDoc request =
113          (HttpServletRequest JavaDoc) pageContext.getRequest();
114
115       try
116       {
117          JspWriter JavaDoc out = pageContext.getOut();
118          // out.print( "?hostUrl=http://tornado.multideck.dnsq.org:8080&rootContext=/axis/services" );
119

120          if (null == mbeanName)
121          {
122             // Look for MBean using default values.
123
mbeanName = DEFAULT_JBOSSNET_MBEAN_NAME;
124          }
125
126          MBeanServer JavaDoc server = MBeanServerLocator.locateJBoss();
127          ObjectName JavaDoc jbossNetObjName = new ObjectName JavaDoc(mbeanName);
128
129          String JavaDoc rootContext =
130             (String JavaDoc) server.getAttribute(jbossNetObjName, "RootContext");
131
132          // String hostUrl = (String)server.getAttribute( jbossNetObjName, "HostUrl" );
133

134          URL JavaDoc reqUrl = new URL JavaDoc(request.getRequestURL().toString());
135          String JavaDoc hostUrl = reqUrl.getHost() + ":" + reqUrl.getPort();
136
137          out.print("?hostUrl=" + hostUrl + "&rootContext=" + rootContext);
138          if (null != parms)
139          {
140             // Output any remaining parameters
141
Iterator JavaDoc iter = parms.entrySet().iterator();
142             Map.Entry JavaDoc curEntry;
143             while (iter.hasNext())
144             {
145                curEntry = (Map.Entry JavaDoc) iter.next();
146                out.print(
147                   "&"
148                   + curEntry.getKey().toString().trim()
149                   + "="
150                   + curEntry.getValue().toString().trim());
151             }
152          } // if - there are map entries to output as parameters
153

154       }
155       catch (Exception JavaDoc e)
156       {
157          e.printStackTrace();
158          throw new JspTagException JavaDoc(e.toString());
159       }
160
161       return SKIP_BODY;
162    }
163
164 } // of class FlashParametersTag
165
Popular Tags