KickJava   Java API By Example, From Geeks To Geeks.

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


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.ThemeLink;
13
14 /**
15  * An implementation of a <code>ThemeLink</code>.
16  *
17  * @author Martin Holzner
18  * @version $LastChangedRevision$, $LastChangedDate$
19  * @see ThemeLink
20  */

21 public class ThemeLinkImpl
22    implements ThemeLink
23 {
24    private static final Logger log = Logger.getLogger(ThemeLinkImpl.class);
25    private String JavaDoc m_rel;
26    private String JavaDoc m_type;
27    private String JavaDoc m_href;
28    private String JavaDoc m_title;
29    private String JavaDoc m_media;
30    private PortalTheme m_theme;
31
32    /**
33     * Create a new ThemeLink
34     *
35     * @param theme the theme this link belongs to
36     * @param rel the rel attributes value
37     * @param type the type attributes value
38     * @param href the href attributes value
39     * @param title the title attributes value
40     * @param media the media attributes value
41     */

42    public ThemeLinkImpl(PortalTheme theme, String JavaDoc rel, String JavaDoc type, String JavaDoc href, String JavaDoc title, String JavaDoc media)
43    {
44       log.debug("create theme link with rel=" + rel + " type=" + type
45          + " HREF=" + href + "title=" + title + " media=" + media);
46       m_theme = theme;
47       m_rel = rel;
48       m_type = type;
49       m_href = href;
50       m_title = title;
51       m_media = media;
52    }
53
54    /**
55     * @see ThemeLink#getLink
56     */

57    public StringBuffer JavaDoc getLink()
58    {
59       log.debug("get link ...");
60       StringBuffer JavaDoc link = new StringBuffer JavaDoc();
61
62       link.append("<link rel='").append(m_rel).append("'");
63
64       if (m_type != null)
65       {
66          link.append(" type='").append(m_type).append("'");
67       }
68
69       if (m_href != null)
70       {
71          // adopt the context and inject a theme id param for the theme
72
// servlet to be able to pick up the resource from the correct theme
73
StringBuffer JavaDoc correctHREF = new StringBuffer JavaDoc();
74          if (m_href.startsWith("/"))
75          {
76             correctHREF.append(m_theme.getContextPath());
77          }
78          correctHREF.append(m_href);
79          link.append(" HREF='").append(correctHREF).append("'");
80       }
81
82       if (m_title != null && !"".equals(m_title))
83       {
84          link.append(" title='").append(m_title).append("'");
85       }
86       if (m_media != null && !"".equals(m_media))
87       {
88          link.append(" media='").append(m_media).append("'");
89       }
90
91       link.append(" />");
92
93       log.debug("returning: " + link);
94
95       return link;
96    }
97
98    /**
99     * @see java.lang.Object#toString
100     */

101    public String JavaDoc toString()
102    {
103       return getLink().toString();
104    }
105 }
106
Popular Tags