1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/*******************************************************************************
* Copyright (c) 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.help.internal.webapp.data;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.internal.webapp.HelpWebappPlugin;
import org.eclipse.help.webapp.AbstractFrame;
public class FrameData extends RequestData {
private static final String FRAME_EXTENSION_POINT = "org.eclipse.help.webapp.frame"; //$NON-NLS-1$
private List allFrames;
public FrameData(ServletContext context, HttpServletRequest request,
HttpServletResponse response) {
super(context, request, response);
}
public AbstractFrame[] getFrames(int location) {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] elements = registry
.getConfigurationElementsFor(FRAME_EXTENSION_POINT);
if (allFrames == null) {
allFrames = new ArrayList();
for (int i = 0; i < elements.length; i++) {
Object obj = null;
try {
obj = elements[i].createExecutableExtension("class"); //$NON-NLS-1$
} catch (CoreException e) {
HelpWebappPlugin.logError("Create extension failed:[" //$NON-NLS-1$
+ FRAME_EXTENSION_POINT + "].", e); //$NON-NLS-1$
}
if (obj instanceof AbstractFrame) {
allFrames.add(obj);
}
}
Collections.sort(allFrames);
}
List frameList = new ArrayList();
for (Iterator iter = allFrames.iterator(); iter.hasNext();) {
AbstractFrame frame = (AbstractFrame) iter.next();
if (frame.isVisible() && frame.getLocation() == location) {
frameList.add(frame);
}
}
AbstractFrame[] frames = (AbstractFrame[]) frameList.toArray(new AbstractFrame[frameList.size()]);
return frames;
}
public String getUrl(AbstractFrame frame) {
return request.getContextPath() + frame.getURL();
}
public String getContentAreaFrameSizes() {
String size = "24,*"; //$NON-NLS-1$
AbstractFrame[] frames = getFrames(AbstractFrame.BELOW_CONTENT);
for (int f = 0; f < frames.length; f++) {
size += ',';
size += frames[f].getSize();
}
return size;
}
/**
* Get the additional frame added to the Main Help Toolbar
* Considering of the layout and space of Main Help Toolbar, only one extra frame is supported
*
* @return AbstractFrame or null if not found
*/
public AbstractFrame getHelpToolbarFrame() {
AbstractFrame[] frames = getFrames(AbstractFrame.HELP_TOOLBAR);
if(frames.length > 0) {
if(frames.length > 1){
HelpWebappPlugin.logWarning("Only one extra frame is supported to be added to Help Toolbar. The first reterived element will be used."); //$NON-NLS-1$
}
return frames[0];
}else {
return null;
}
}
/**
* Get layout(frame sizes) of Main Help Toolbar
*/
public String getHelpToolbarFrameSizes() {
String size = "*"; //$NON-NLS-1$
AbstractFrame frame = getHelpToolbarFrame();
if(null != frame) {
boolean isRTL = UrlUtil.isRTL(request, response);
if(isRTL) {
size = frame.getSize() + ", " + size; //$NON-NLS-1$
}else {
size = size + ", " + frame.getSize(); //$NON-NLS-1$
}
}
return size;
}
}
|