KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > theme > impl > ThemeScriptImpl


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

7
8 package org.jboss.portal.core.theme.impl;
9
10 import org.apache.log4j.Logger;
11 import org.jboss.portal.server.theme.PortalTheme;
12 import org.jboss.portal.server.theme.ThemeScript;
13
14 /**
15  * An implementation of a <code>ThemeScript</code>.
16  *
17  * @author Martin Holzner
18  * @version $LastChangedRevision$, $LastChangedDate$
19  * @see ThemeScript
20  */

21 public class ThemeScriptImpl
22    implements ThemeScript
23 {
24    private static final Logger log = Logger.getLogger(ThemeScriptImpl.class);
25    private String JavaDoc m_src;
26    private String JavaDoc m_type;
27    private PortalTheme m_theme;
28
29    /**
30     * Create a theme script.
31     *
32     * @param theme the theme to which this script belongs to
33     * @param src the value of the src attribute
34     * @param type the value of the type attribute
35     */

36    public ThemeScriptImpl(PortalTheme theme, String JavaDoc src, String JavaDoc type)
37    {
38       log.debug("creating theme script with SRC=" + src + " type=" + type);
39       m_theme = theme;
40       m_src = src;
41       m_type = type;
42    }
43
44    /**
45     * @see ThemeScript#getScript
46     */

47    public StringBuffer JavaDoc getScript()
48    {
49       log.debug("get script ...");
50       StringBuffer JavaDoc script = new StringBuffer JavaDoc();
51       script.append("<script ");
52       // adopt the context and inject a theme id param for the theme
53
// servlet to be able to pick up the resource from the correct theme
54
if (m_src != null && !"".equals(m_src))
55       {
56          StringBuffer JavaDoc correctSRC = new StringBuffer JavaDoc();
57          if (m_src.startsWith("/"))
58          {
59             correctSRC.append(m_theme.getContextPath());
60          }
61          correctSRC.append(m_src);
62          script.append(" SRC='").append(correctSRC).append("'");
63       }
64
65       if (m_type != null && !"".equals(m_type))
66       {
67          script.append(" type='").append(m_type).append("'");
68       }
69       script.append(" />");
70
71       log.debug("returning script : " + script);
72
73       return script;
74    }
75
76    /**
77     * @see java.lang.Object#toString()
78     */

79    public String JavaDoc toString()
80    {
81       return getScript().toString();
82    }
83 }
84
Popular Tags