View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.desktop.impl;
18  
19  import java.util.Locale;
20  import java.util.ResourceBundle;
21  
22  import org.apache.jetspeed.container.url.BasePortalURL;
23  import org.apache.jetspeed.decoration.LayoutDecoration;
24  import org.apache.jetspeed.decoration.Theme;
25  import org.apache.jetspeed.desktop.JetspeedDesktopContext;
26  import org.apache.jetspeed.headerresource.HeaderResource;
27  import org.apache.jetspeed.headerresource.HeaderResourceLib;
28  import org.apache.jetspeed.request.RequestContext;
29  
30  /***
31   * Jetspeed Desktop 
32   *
33   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
34   * @author <a href="mailto:smilek@apache.org">Steve Milek</a>
35   * @version $Id: JetspeedDesktopContextImpl.java $
36   */
37  public class JetspeedDesktopContextImpl implements JetspeedDesktopContext
38  {
39      // Jetspeed Request Context
40      RequestContext context;
41      
42      // base portal url to override default url server info from servlet
43      private BasePortalURL baseUrlAccess = null;
44      
45      private LayoutDecoration layoutDecoration;
46      
47      // default extension for layout templates
48      private String defaultLayoutTemplateExtension;
49      
50      
51      // ... save generated portal urls to avoid duplicate effort
52      private String portalBaseUrl;
53      private String portalUrl;
54      
55      private HeaderResource headerResource;
56      
57      public JetspeedDesktopContextImpl( RequestContext context, BasePortalURL baseUrlAccess, Theme theme, HeaderResource headerResource, String defaultLayoutTemplateExtension )
58      {
59          // String layoutDecorator, String layoutDecoratorRootPath, String resourceName
60          this.context = context;
61          this.baseUrlAccess = baseUrlAccess;
62          this.layoutDecoration = theme.getPageLayoutDecoration();
63          this.headerResource = headerResource;
64          this.defaultLayoutTemplateExtension = defaultLayoutTemplateExtension;
65      }
66      
67      
68      // get portal urls - each of these methods is copied from HeaderResourceImpl.java
69      
70      /***
71       * Portal base url ( e.g. http://localhost:8080/jetspeed )
72       * 
73       * @return portal base url
74       */
75      public String getPortalBaseUrl()
76      {
77          if ( this.portalBaseUrl == null )
78          {
79              this.portalBaseUrl = HeaderResourceLib.getPortalBaseUrl( context, this.baseUrlAccess );
80          }
81          return this.portalBaseUrl;
82      }
83      
84      /***
85       * Portal base url ( e.g. http://localhost:8080/jetspeed )
86       * 
87       * @return portal base url
88       */
89      public String getPortalBaseUrl( boolean encode )
90      {
91          String baseurl = getPortalBaseUrl();
92          if ( ! encode )
93          {
94              return baseurl;
95          }
96          else
97          {
98              return context.getResponse().encodeURL( baseurl );
99          }
100     }
101         
102     /***
103      * Portal base url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/javascript/dojo/ )
104      * 
105      * @return portal base url with relativePath argument appended
106      */
107     public String getPortalResourceUrl( String relativePath )
108     {
109         return getPortalResourceUrl( relativePath, false );
110     }
111     
112     /***
113      * Portal base url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/javascript/dojo/ )
114      * 
115      * @return portal base url with relativePath argument appended
116      */
117     public String getPortalResourceUrl( String relativePath, boolean encode )
118     {
119         return HeaderResourceLib.getPortalResourceUrl( relativePath, getPortalBaseUrl(), encode, context );
120     }
121     
122     /***
123      * Portal base servlet url ( e.g. http://localhost:8080/jetspeed/desktop/ )
124      * 
125      * @return portal base servlet url
126      */
127     public String getPortalUrl()
128     {
129         if ( this.portalUrl == null )
130         {
131             this.portalUrl = HeaderResourceLib.getPortalUrl( getPortalBaseUrl(), context );
132         }
133         return this.portalUrl;
134     }
135     
136     /***
137      * Portal base servlet url ( e.g. http://localhost:8080/jetspeed/desktop/ )
138      * 
139      * @return portal base servlet url
140      */
141     public String getPortalUrl( boolean encode )
142     {
143         return getPortalUrl( null, encode );
144     }
145     
146     /***
147      * Portal base servlet url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/desktop/default-page.psml )
148      * 
149      * @return portal base servlet url with relativePath argument appended
150      */
151     public String getPortalUrl( String relativePath )
152     {
153         return getPortalUrl( relativePath, false );
154     }
155     
156     /***
157      * Portal base servlet url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/desktop/default-page.psml )
158      * 
159      * @return portal base servlet url with relativePath argument appended
160      */
161     public String getPortalUrl( String relativePath, boolean encode )
162     {
163         return HeaderResourceLib.getPortalResourceUrl( relativePath, getPortalUrl(), encode, context );
164     }
165     
166     public String getLayoutDecorationName()
167     {
168         return layoutDecoration.getName();
169     }
170     
171     public String getLayoutTemplatePath()
172     {
173         return getLayoutTemplatePath( null );
174     }
175     public String getLayoutTemplatePath( String layoutTemplateIdPropertyName )
176     {
177         String id = null;
178         if ( layoutTemplateIdPropertyName != null )
179         {
180             id = layoutDecoration.getProperty( layoutTemplateIdPropertyName );
181         }
182         
183         if ( id == null || id.length() == 0 )
184         {
185             id = layoutDecoration.getProperty( LAYOUT_TEMPLATE_ID_PROP );
186         }
187         
188         if ( id == null || id.length() == 0 )
189         {
190             id = LAYOUT_TEMPLATE_ID_DEFAULT;
191         }
192         
193         String ext = layoutDecoration.getProperty( LAYOUT_DESKTOP_TEMPLATE_EXTENSION_PROP );
194         if ( ext == null )
195             ext = layoutDecoration.getProperty( LAYOUT_TEMPLATE_EXTENSION_PROP );
196         if ( ext == null )
197         {
198             ext = this.defaultLayoutTemplateExtension;
199         }
200         return layoutDecoration.getBasePath( id + ext );
201     }
202     
203     public String getLayoutBasePath()
204     {
205         return layoutDecoration.getBasePath();
206     }
207     public String getLayoutBasePath( String relativePath )
208     {
209         return layoutDecoration.getBasePath( relativePath );
210     }
211     
212     public String getLayoutBaseUrl()
213     {
214         return getPortalResourceUrl( getLayoutBasePath(), false );
215     }
216     public String getLayoutBaseUrl( String relativePath )
217     {
218         return getPortalResourceUrl( getLayoutBasePath( relativePath ), false );
219     }
220     
221     public ResourceBundle getLayoutResourceBundle( Locale locale )
222     {
223         return layoutDecoration.getResourceBundle( locale, this.context );
224     }
225     
226     public HeaderResource getHeaderResource()
227     {
228         return this.headerResource;
229     }
230 }