KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > webapp > data > LayoutData


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.webapp.data;
12
13 import java.util.ArrayList JavaDoc;
14
15 import javax.servlet.*;
16 import javax.servlet.http.*;
17
18 import org.eclipse.help.internal.HelpPlugin;
19 import org.eclipse.help.internal.base.*;
20
21 public class LayoutData extends RequestData {
22
23     private String JavaDoc query = ""; //$NON-NLS-1$
24
private View[] views;
25
26     public LayoutData(ServletContext context, HttpServletRequest request,
27             HttpServletResponse response) {
28         super(context, request, response);
29
30         // initialize the query string
31
String JavaDoc qs = request.getQueryString();
32         if (qs != null && qs.length() > 0)
33             query = "?" + qs; //$NON-NLS-1$
34
}
35
36     public String JavaDoc getQuery() {
37         return query;
38     }
39
40     public String JavaDoc getBannerURL() {
41         String JavaDoc banner = preferences.getBanner();
42         if (banner == null || banner.trim().length() == 0) {
43             banner = "about:blank"; //$NON-NLS-1$
44
} else if (banner.startsWith("http:/") || banner.startsWith("https:/")) { //$NON-NLS-1$ //$NON-NLS-2$
45
} else if (banner.startsWith("file:/") || banner.startsWith("jar:file:/")) { //$NON-NLS-1$ //$NON-NLS-2$
46
banner = "topic/" + banner; //$NON-NLS-1$
47
} else {
48             banner = "topic" + banner; //$NON-NLS-1$
49
}
50         return banner;
51     }
52
53     public String JavaDoc getBannerHeight() {
54         String JavaDoc height = preferences.getBannerHeight();
55         if (height == null || height.length() == 0) {
56             height = "0"; //$NON-NLS-1$
57
}
58         return height;
59     }
60
61     public String JavaDoc getContentURL() {
62         String JavaDoc topicHref = request.getParameter("topic"); //$NON-NLS-1$
63
if (topicHref == null || topicHref.length() == 0) {
64             return UrlUtil.getHelpURL(preferences.getHelpHome());
65         }
66         else {
67             TocData tocData = new TocData(context, request, response);
68             String JavaDoc topic = tocData.getSelectedTopic();
69             return topic != null ? topic : UrlUtil.getHelpURL(preferences.getHelpHome());
70         }
71     }
72
73     /**
74      * Return array of length 0 if no views
75      */

76     public View[] getViews() {
77         if (views != null)
78             return views;
79
80         View tocview = new View("toc", //$NON-NLS-1$
81
"", //$NON-NLS-1$
82
preferences.getImagesDirectory() + "/contents_view.gif", 'C', !HelpPlugin.getTocManager().isTocLoaded(getLocale())); //$NON-NLS-1$
83
View indexview = null;
84         View searchview = new View("search", //$NON-NLS-1$
85
"", //$NON-NLS-1$
86
preferences.getImagesDirectory() + "/search_results_view.gif", 'R', false); //$NON-NLS-1$
87
View linksview = null;
88         View bookmarksview = null;
89
90         if (preferences.isIndexView())
91             indexview = new View("index", //$NON-NLS-1$
92
"", //$NON-NLS-1$
93
preferences.getImagesDirectory() + "/index_view.gif", 'I', false); //$NON-NLS-1$
94
if (preferences.isLinksView())
95             linksview = new View("links", //$NON-NLS-1$
96
"", //$NON-NLS-1$
97
preferences.getImagesDirectory() + "/links_view.gif", (char)0, false); //$NON-NLS-1$
98
if (preferences.isBookmarksView())
99             bookmarksview = new View("bookmarks", //$NON-NLS-1$
100
"", //$NON-NLS-1$
101
preferences.getImagesDirectory() + "/bookmarks_view.gif", (char)0, false); //$NON-NLS-1$
102

103         ArrayList JavaDoc viewList = new ArrayList JavaDoc();
104         viewList.add(tocview);
105         if (indexview != null) {
106             viewList.add(indexview);
107         }
108         viewList.add(searchview);
109         if (linksview != null) {
110             viewList.add(linksview);
111         }
112         if (bookmarksview !=null) {
113             viewList.add(bookmarksview);
114         }
115         
116         views = (View[]) viewList.toArray(new View[viewList.size()]);
117         return views;
118     }
119
120     public String JavaDoc getVisibleView() {
121         String JavaDoc requestedView = request.getParameter("tab"); //$NON-NLS-1$
122
View[] allViews = getViews();
123         for (int i = 0; i < allViews.length; i++) {
124             if (allViews[i].getName().equals(requestedView)) {
125                 return requestedView;
126             }
127         }
128         return "toc"; //$NON-NLS-1$
129
}
130
131     public View getCurrentView() {
132         String JavaDoc name = request.getParameter("view"); //$NON-NLS-1$
133
views = getViews();
134         for (int i = 0; i < views.length; i++)
135             if (views[i].getName().equals(name))
136                 return views[i];
137         return null;
138     }
139     public String JavaDoc getWindowTitle() {
140         if (preferences.isWindowTitlePrefix()) {
141             return ServletResources.getString("browserTitle", //$NON-NLS-1$
142
BaseHelpSystem.getProductName(), request);
143         }
144         return BaseHelpSystem.getProductName();
145     }
146 }
147
Popular Tags