KickJava   Java API By Example, From Geeks To Geeks.

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


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.common.MediaType;
12 import org.jboss.portal.server.ServerRegistrationID;
13 import org.jboss.portal.server.deployment.PortalWebApp;
14 import org.jboss.portal.server.metadata.LayoutRegistrationMetaData;
15 import org.jboss.portal.server.theme.PortalLayout;
16 import org.jboss.portal.server.theme.PortalRenderSet;
17 import org.jboss.portal.server.theme.strategy.LayoutStrategy;
18
19 import javax.servlet.ServletContext JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * Implementation of a <code>PortalLayout</code>.
26  * <p>An instance of this class represents the meta data of a portal layout.</p>
27  *
28  * @author <a HREF="mailto:mholzner@novell.com">Martin Holzner</a>.
29  * @version <tt>$Revision: 1.10 $</tt>
30  * @see org.jboss.portal.server.LayoutServer
31  */

32 public class PortalLayoutImpl extends LayoutRegistrationMetaData
33    implements PortalLayout
34 {
35    private final String JavaDoc name;
36    private final String JavaDoc uri;
37    private final String JavaDoc appName;
38    private final Map JavaDoc stateURIs;
39    // a list of PortalRenderSet
40
private final List JavaDoc renderSets;
41    private final Map JavaDoc strategies;
42    private final PortalWebApp pwa;
43    private static Logger log = Logger.getLogger(PortalLayoutImpl.class);
44
45    /**
46     * Create the layout.
47     *
48     * @param id the unique identifier of this layout
49     * @param pwa the portal pweb application the layout is contained in
50     * @param appName the name of the portal web application that this layout is contained in
51     * @param name the name of the layout
52     * @param uri the uri of the layout (the Servlet or JSP), relative to the context root of the portal web application
53     * @param stateURIs a <code>java.util.Map</code> of state and uri values. the layout can use a differnt resource (URI)
54     * for a particular state (example: use maximized.jsp if the state is maximized)
55     * @param renderSets a <code>java.util.List</code> of render sets that is defined for this layout (see portal-layouts.xml)
56     * @param strategies a <code>java.util.Map</code> of media type and strategy values. A layout can specify a different
57     * strategy for a particular <code>MediaType</code> (see portal-layouts.xml)
58     * @see ServerRegistrationID
59     * @see MediaType
60     */

61    public PortalLayoutImpl(ServerRegistrationID id, PortalWebApp pwa, String JavaDoc appName, String JavaDoc name,
62                            String JavaDoc uri, Map JavaDoc stateURIs, List JavaDoc renderSets, Map JavaDoc strategies)
63    {
64       super(id);
65
66       if (appName == null || "".equals(appName))
67       {
68          throw new IllegalArgumentException JavaDoc("appName cannot be null");
69       }
70       if (name == null || "".equals(name))
71       {
72          throw new IllegalArgumentException JavaDoc("name cannot be null");
73       }
74       if (pwa == null)
75       {
76          throw new IllegalArgumentException JavaDoc("Portal WebApp cannot be null");
77       }
78       if (uri == null || "".equals(uri))
79       {
80          throw new IllegalArgumentException JavaDoc("uri cannot be null");
81       }
82       if (renderSets == null)
83       {
84          throw new IllegalArgumentException JavaDoc("render set list cannot be null");
85       }
86       if (strategies == null)
87       {
88          throw new IllegalArgumentException JavaDoc("strategies map cannot be null");
89       }
90
91       log.debug("creating new layout " + name + " + in " + appName);
92       this.pwa = pwa;
93       this.renderSets = renderSets;
94       this.name = name;
95       this.uri = uri;
96       this.appName = appName;
97       this.stateURIs = stateURIs;
98       this.strategies = strategies;
99    }
100
101    /**
102     * Get the name of the portal web application that contains this layout.
103     *
104     * @return the name of the portal web application that contains this layout
105     */

106    public String JavaDoc getAppName()
107    {
108       return appName;
109    }
110
111    /**
112     * Get the name of this layout.
113     *
114     * @return the name of the layout
115     */

116    public String JavaDoc getName()
117    {
118       return this.name;
119    }
120
121    /**
122     * Get the servlet context that contains this layout.
123     *
124     * @return the serlvet context of this layout
125     */

126    public ServletContext JavaDoc getServletContext()
127    {
128       return pwa.getServletContext();
129    }
130
131    /**
132     * Get the generic URI for this layout.
133     * <p>The URI is the location of the layout resource inside the Servlet context that contains it.
134     * The generic URI is the one that does not depend on a state. It is the most common URI for this layout.</p>
135     *
136     * @return the URI for this layout
137     * @see #getServletContext()
138     * @see #getURI(String)
139     */

140    public String JavaDoc getURI()
141    {
142       return uri;
143    }
144
145    /**
146     * Get the uri, the location of the layout, relative to its context.
147     *
148     * @param state an optional key to further separate URIs (for example for maximized window state).
149     * If a layout uri was defined for the provided state, that uri will be returned, otherwise the generic
150     * URI for this layout will be returned. If null is provided, the result is the same as calling getURI()
151     * @return the uri of the layout relative to its context
152     * @see #getServletContext()
153     * @see #getURI
154     */

155    public String JavaDoc getURI(String JavaDoc state)
156    {
157       if (state == null)
158       {
159          return getURI();
160       }
161       if (stateURIs != null)
162       {
163          return (String JavaDoc)stateURIs.get(state);
164       }
165       return null;
166    }
167
168    /**
169     * Get the context path for the servlet context (portal web application) that contains this layout.
170     *
171     * @return the context path of this layout
172     */

173    public String JavaDoc getContextPath()
174    {
175       return pwa.getContextPath();
176    }
177
178    /**
179     * Out of the render sets defined for this layout (in portal-layouts.xml), get the one that matches the
180     * requested content type.
181     *
182     * @param mediaType the media type of the current request
183     * @return a PortalRenderSet for this layout and provided media/content type
184     * @see MediaType
185     * @see PortalRenderSet
186     */

187    public PortalRenderSet getRenderSet(MediaType mediaType)
188    {
189       for (Iterator JavaDoc i = renderSets.iterator(); i.hasNext();)
190       {
191          PortalRenderSet renderSet = (PortalRenderSet)i.next();
192          if (renderSet.getMediaType().equals(mediaType))
193          {
194             return renderSet;
195          }
196       }
197       return null;
198    }
199
200    /**
201     * Get the class loader for this layout, the loader of the portal web application.
202     *
203     * @return the class loader of the portal web application
204     */

205    public ClassLoader JavaDoc getLoader()
206    {
207       return pwa.getClassLoader();
208    }
209
210    /**
211     * Out of the portal strategies defined for this layout (if any), get the one that was defined for the
212     * provided media type. (see also portal-layouts.xml)
213     *
214     * @param mediaType the media type (content type) for which to get the strategy for
215     * @return the strategy that was defined for this layout and media type, or null if no strategy was defined for the
216     * provided criteria.
217     */

218    public LayoutStrategy getStrategy(MediaType mediaType)
219    {
220       return (LayoutStrategy)strategies.get(mediaType);
221    }
222 }
223
Popular Tags