|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2006, 2009 IBM Corporation and others. |
2 |
* Copyright (c) 2006, 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 22-32
Link Here
|
| 22 |
|
22 |
|
| 23 |
import org.eclipse.help.IToc; |
23 |
import org.eclipse.help.IToc; |
| 24 |
import org.eclipse.help.ITopic; |
24 |
import org.eclipse.help.ITopic; |
|
|
25 |
import org.eclipse.help.base.AbstractHelpScope; |
| 25 |
import org.eclipse.help.internal.Topic; |
26 |
import org.eclipse.help.internal.Topic; |
|
|
27 |
import org.eclipse.help.internal.base.scope.ScopeUtils; |
| 26 |
import org.eclipse.help.internal.toc.Toc; |
28 |
import org.eclipse.help.internal.toc.Toc; |
| 27 |
import org.eclipse.help.internal.webapp.WebappResources; |
29 |
import org.eclipse.help.internal.webapp.WebappResources; |
| 28 |
import org.eclipse.help.internal.webapp.data.EnabledTopicUtils; |
|
|
| 29 |
import org.eclipse.help.internal.webapp.data.IconFinder; |
30 |
import org.eclipse.help.internal.webapp.data.IconFinder; |
|
|
31 |
import org.eclipse.help.internal.webapp.data.RequestScope; |
| 30 |
import org.eclipse.help.internal.webapp.data.TocData; |
32 |
import org.eclipse.help.internal.webapp.data.TocData; |
| 31 |
import org.eclipse.help.internal.webapp.data.UrlUtil; |
33 |
import org.eclipse.help.internal.webapp.data.UrlUtil; |
| 32 |
|
34 |
|
|
Lines 54-60
Link Here
|
| 54 |
|
56 |
|
| 55 |
readParameters(req); |
57 |
readParameters(req); |
| 56 |
|
58 |
|
| 57 |
Serializer serializer = new Serializer(data, req.getLocale()); |
59 |
AbstractHelpScope scope = RequestScope.getScopeFromRequest(req, resp); |
|
|
60 |
Serializer serializer = new Serializer(data, req.getLocale(), scope); |
| 58 |
String response = serializer.generateTreeXml(); |
61 |
String response = serializer.generateTreeXml(); |
| 59 |
locale2Response.put(locale, response); |
62 |
locale2Response.put(locale, response); |
| 60 |
resp.getWriter().write(response); |
63 |
resp.getWriter().write(response); |
|
Lines 74-88
Link Here
|
| 74 |
private StringBuffer buf; |
77 |
private StringBuffer buf; |
| 75 |
private int requestKind; |
78 |
private int requestKind; |
| 76 |
private Locale locale; |
79 |
private Locale locale; |
|
|
80 |
private AbstractHelpScope scope; |
| 77 |
private static final int REQUEST_SHOW_IN_TOC = 1; // Get the path to an element an element based on its href |
81 |
private static final int REQUEST_SHOW_IN_TOC = 1; // Get the path to an element an element based on its href |
| 78 |
private static final int REQUEST_SHOW_TOCS = 2; // Show all the tocs but not their children |
82 |
private static final int REQUEST_SHOW_TOCS = 2; // Show all the tocs but not their children |
| 79 |
private static final int REQUEST_SHOW_CHILDREN = 3; // Show the children of a node |
83 |
private static final int REQUEST_SHOW_CHILDREN = 3; // Show the children of a node |
| 80 |
private static final int REQUEST_EXPAND_PATH = 4; // Get all the nodes requires to expand a path in the tree |
84 |
private static final int REQUEST_EXPAND_PATH = 4; // Get all the nodes requires to expand a path in the tree |
| 81 |
|
85 |
|
| 82 |
public Serializer(TocData data, Locale locale) { |
86 |
public Serializer(TocData data, Locale locale, AbstractHelpScope scope) { |
| 83 |
tocData = data; |
87 |
tocData = data; |
| 84 |
buf = new StringBuffer(); |
88 |
buf = new StringBuffer(); |
| 85 |
this.locale = locale; |
89 |
this.locale = locale; |
|
|
90 |
this.scope = scope; |
| 86 |
if (tocData.isExpandPath()) { |
91 |
if (tocData.isExpandPath()) { |
| 87 |
requestKind = REQUEST_EXPAND_PATH; |
92 |
requestKind = REQUEST_EXPAND_PATH; |
| 88 |
} else if (tocData.getTopicHref() != null) { |
93 |
} else if (tocData.getTopicHref() != null) { |
|
Lines 119-125
Link Here
|
| 119 |
// Count the number of enabled tocs |
124 |
// Count the number of enabled tocs |
| 120 |
int enabled = 0; |
125 |
int enabled = 0; |
| 121 |
for (int i = 0; i <= selectedToc; i++) { |
126 |
for (int i = 0; i <= selectedToc; i++) { |
| 122 |
if (EnabledTopicUtils.isEnabled(tocData.getTocs()[i])) { |
127 |
if (ScopeUtils.showInTree(tocData.getTocs()[i], scope)) { |
| 123 |
enabled++; |
128 |
enabled++; |
| 124 |
} |
129 |
} |
| 125 |
} |
130 |
} |
|
Lines 165-172
Link Here
|
| 165 |
|
170 |
|
| 166 |
private void serializeToc(IToc toc, int tocIndex, ITopic[] topicPath, boolean isSelected) { |
171 |
private void serializeToc(IToc toc, int tocIndex, ITopic[] topicPath, boolean isSelected) { |
| 167 |
|
172 |
|
| 168 |
if (!EnabledTopicUtils.isEnabled(toc)) { |
173 |
if (!ScopeUtils.showInTree(toc, scope)) { |
| 169 |
// do not generate toc when there are no leaf topics |
174 |
// do not generate toc when there are no leaf topics or if it is filtered out |
| 170 |
return; |
175 |
return; |
| 171 |
} |
176 |
} |
| 172 |
ITopic[] topics = toc.getTopics(); |
177 |
ITopic[] topics = toc.getTopics(); |
|
Lines 205-211
Link Here
|
| 205 |
|
210 |
|
| 206 |
private void serializeTopic(ITopic topic, ITopic[] topicPath, boolean isSelected, String parentPath) { |
211 |
private void serializeTopic(ITopic topic, ITopic[] topicPath, boolean isSelected, String parentPath) { |
| 207 |
ITopic[] subtopics = topic.getSubtopics(); |
212 |
ITopic[] subtopics = topic.getSubtopics(); |
| 208 |
boolean isLeaf = !EnabledTopicUtils.hasEnabledSubtopic(topic); |
213 |
boolean isLeaf = !ScopeUtils.hasInScopeDescendent(topic, scope); |
| 209 |
buf.append("<node"); //$NON-NLS-1$ |
214 |
buf.append("<node"); //$NON-NLS-1$ |
| 210 |
if (topic.getLabel() != null) { |
215 |
if (topic.getLabel() != null) { |
| 211 |
buf.append('\n' + " title=\"" + XMLGenerator.xmlEscape(topic.getLabel()) + '"'); //$NON-NLS-1$ |
216 |
buf.append('\n' + " title=\"" + XMLGenerator.xmlEscape(topic.getLabel()) + '"'); //$NON-NLS-1$ |
|
Lines 293-306
Link Here
|
| 293 |
// Show the children of this node |
298 |
// Show the children of this node |
| 294 |
for (int subtopic = 0; subtopic < childTopics.length; subtopic++) { |
299 |
for (int subtopic = 0; subtopic < childTopics.length; subtopic++) { |
| 295 |
ITopic childTopic = childTopics[subtopic]; |
300 |
ITopic childTopic = childTopics[subtopic]; |
| 296 |
if (EnabledTopicUtils.isEnabled(childTopic)) { |
301 |
if (ScopeUtils.showInTree(childTopic, scope)) { |
| 297 |
serializeTopic(childTopic, null, false, addSuffix(parentPath, subtopic)); |
302 |
serializeTopic(childTopic, null, false, addSuffix(parentPath, subtopic)); |
| 298 |
} |
303 |
} |
| 299 |
} |
304 |
} |
| 300 |
} else if (topicPath != null) { |
305 |
} else if (topicPath != null) { |
| 301 |
for (int subtopic = 0; subtopic < childTopics.length; subtopic++) { |
306 |
for (int subtopic = 0; subtopic < childTopics.length; subtopic++) { |
| 302 |
ITopic childTopic = childTopics[subtopic]; |
307 |
ITopic childTopic = childTopics[subtopic]; |
| 303 |
if (EnabledTopicUtils.isEnabled(childTopic)) { |
308 |
if (ScopeUtils.showInTree(childTopic, scope)) { |
| 304 |
if (topicPath[0].getLabel().equals(childTopic.getLabel())) { |
309 |
if (topicPath[0].getLabel().equals(childTopic.getLabel())) { |
| 305 |
ITopic[] newPath = null; |
310 |
ITopic[] newPath = null; |
| 306 |
if (topicPath.length > 1) { |
311 |
if (topicPath.length > 1) { |