001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.desktop.impl;
018:
019: import java.util.Locale;
020: import java.util.ResourceBundle;
021:
022: import org.apache.jetspeed.container.url.BasePortalURL;
023: import org.apache.jetspeed.decoration.LayoutDecoration;
024: import org.apache.jetspeed.decoration.Theme;
025: import org.apache.jetspeed.desktop.JetspeedDesktopContext;
026: import org.apache.jetspeed.headerresource.HeaderResource;
027: import org.apache.jetspeed.headerresource.HeaderResourceLib;
028: import org.apache.jetspeed.request.RequestContext;
029:
030: /**
031: * Jetspeed Desktop
032: *
033: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
034: * @author <a href="mailto:smilek@apache.org">Steve Milek</a>
035: * @version $Id: JetspeedDesktopContextImpl.java $
036: */
037: public class JetspeedDesktopContextImpl implements
038: JetspeedDesktopContext {
039: // Jetspeed Request Context
040: RequestContext context;
041:
042: // base portal url to override default url server info from servlet
043: private BasePortalURL baseUrlAccess = null;
044:
045: private LayoutDecoration layoutDecoration;
046:
047: // default extension for layout templates
048: private String defaultLayoutTemplateExtension;
049:
050: // ... save generated portal urls to avoid duplicate effort
051: private String portalBaseUrl;
052: private String portalUrl;
053:
054: private HeaderResource headerResource;
055:
056: public JetspeedDesktopContextImpl(RequestContext context,
057: BasePortalURL baseUrlAccess, Theme theme,
058: HeaderResource headerResource,
059: String defaultLayoutTemplateExtension) {
060: // String layoutDecorator, String layoutDecoratorRootPath, String resourceName
061: this .context = context;
062: this .baseUrlAccess = baseUrlAccess;
063: this .layoutDecoration = theme.getPageLayoutDecoration();
064: this .headerResource = headerResource;
065: this .defaultLayoutTemplateExtension = defaultLayoutTemplateExtension;
066: }
067:
068: // get portal urls - each of these methods is copied from HeaderResourceImpl.java
069:
070: /**
071: * Portal base url ( e.g. http://localhost:8080/jetspeed )
072: *
073: * @return portal base url
074: */
075: public String getPortalBaseUrl() {
076: if (this .portalBaseUrl == null) {
077: this .portalBaseUrl = HeaderResourceLib.getPortalBaseUrl(
078: context, this .baseUrlAccess);
079: }
080: return this .portalBaseUrl;
081: }
082:
083: /**
084: * Portal base url ( e.g. http://localhost:8080/jetspeed )
085: *
086: * @return portal base url
087: */
088: public String getPortalBaseUrl(boolean encode) {
089: String baseurl = getPortalBaseUrl();
090: if (!encode) {
091: return baseurl;
092: } else {
093: return context.getResponse().encodeURL(baseurl);
094: }
095: }
096:
097: /**
098: * Portal base url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/javascript/dojo/ )
099: *
100: * @return portal base url with relativePath argument appended
101: */
102: public String getPortalResourceUrl(String relativePath) {
103: return getPortalResourceUrl(relativePath, false);
104: }
105:
106: /**
107: * Portal base url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/javascript/dojo/ )
108: *
109: * @return portal base url with relativePath argument appended
110: */
111: public String getPortalResourceUrl(String relativePath,
112: boolean encode) {
113: return HeaderResourceLib.getPortalResourceUrl(relativePath,
114: getPortalBaseUrl(), encode, context);
115: }
116:
117: /**
118: * Portal base servlet url ( e.g. http://localhost:8080/jetspeed/desktop/ )
119: *
120: * @return portal base servlet url
121: */
122: public String getPortalUrl() {
123: if (this .portalUrl == null) {
124: this .portalUrl = HeaderResourceLib.getPortalUrl(
125: getPortalBaseUrl(), context);
126: }
127: return this .portalUrl;
128: }
129:
130: /**
131: * Portal base servlet url ( e.g. http://localhost:8080/jetspeed/desktop/ )
132: *
133: * @return portal base servlet url
134: */
135: public String getPortalUrl(boolean encode) {
136: return getPortalUrl(null, encode);
137: }
138:
139: /**
140: * Portal base servlet url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/desktop/default-page.psml )
141: *
142: * @return portal base servlet url with relativePath argument appended
143: */
144: public String getPortalUrl(String relativePath) {
145: return getPortalUrl(relativePath, false);
146: }
147:
148: /**
149: * Portal base servlet url with relativePath argument appended ( e.g. http://localhost:8080/jetspeed/desktop/default-page.psml )
150: *
151: * @return portal base servlet url with relativePath argument appended
152: */
153: public String getPortalUrl(String relativePath, boolean encode) {
154: return HeaderResourceLib.getPortalResourceUrl(relativePath,
155: getPortalUrl(), encode, context);
156: }
157:
158: public String getLayoutDecorationName() {
159: return layoutDecoration.getName();
160: }
161:
162: public String getLayoutTemplatePath() {
163: return getLayoutTemplatePath(null);
164: }
165:
166: public String getLayoutTemplatePath(
167: String layoutTemplateIdPropertyName) {
168: String id = null;
169: if (layoutTemplateIdPropertyName != null) {
170: id = layoutDecoration
171: .getProperty(layoutTemplateIdPropertyName);
172: }
173:
174: if (id == null || id.length() == 0) {
175: id = layoutDecoration.getProperty(LAYOUT_TEMPLATE_ID_PROP);
176: }
177:
178: if (id == null || id.length() == 0) {
179: id = LAYOUT_TEMPLATE_ID_DEFAULT;
180: }
181:
182: String ext = layoutDecoration
183: .getProperty(LAYOUT_DESKTOP_TEMPLATE_EXTENSION_PROP);
184: if (ext == null)
185: ext = layoutDecoration
186: .getProperty(LAYOUT_TEMPLATE_EXTENSION_PROP);
187: if (ext == null) {
188: ext = this .defaultLayoutTemplateExtension;
189: }
190: return layoutDecoration.getBasePath(id + ext);
191: }
192:
193: public String getLayoutBasePath() {
194: return layoutDecoration.getBasePath();
195: }
196:
197: public String getLayoutBasePath(String relativePath) {
198: return layoutDecoration.getBasePath(relativePath);
199: }
200:
201: public String getLayoutBaseUrl() {
202: return getPortalResourceUrl(getLayoutBasePath(), false);
203: }
204:
205: public String getLayoutBaseUrl(String relativePath) {
206: return getPortalResourceUrl(getLayoutBasePath(relativePath),
207: false);
208: }
209:
210: public ResourceBundle getLayoutResourceBundle(Locale locale) {
211: return layoutDecoration.getResourceBundle(locale, this .context);
212: }
213:
214: public HeaderResource getHeaderResource() {
215: return this.headerResource;
216: }
217: }
|