Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2010-11-05 19:28:46 +0000
committerChris Goldthorpe2010-11-05 19:28:46 +0000
commit3a4080d428bea007180b0379d9f661f1ae229539 (patch)
treeb05c5964a23c070414369c5e0927393414e1f4ca
parenteb1bded5e44be4b86da60f6c02f6d79d75682515 (diff)
downloadeclipse.platform.ua-3a4080d428bea007180b0379d9f661f1ae229539.tar.gz
eclipse.platform.ua-3a4080d428bea007180b0379d9f661f1ae229539.tar.xz
eclipse.platform.ua-3a4080d428bea007180b0379d9f661f1ae229539.zip
Bug 329466 - [Webapp] Wrong topic was selected in the TOC tree
-rw-r--r--org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/TopicFinder.java58
-rw-r--r--org.eclipse.ua.tests/data/help/toc/extraContent/toc2.xml3
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TopicFinderTest.java34
3 files changed, 87 insertions, 8 deletions
diff --git a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/TopicFinder.java b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/TopicFinder.java
index 1774a3e58..1651fcc06 100644
--- a/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/TopicFinder.java
+++ b/org.eclipse.help.webapp/src/org/eclipse/help/internal/webapp/data/TopicFinder.java
@@ -40,10 +40,16 @@ public class TopicFinder {
int index = -1;
do {
selectedToc = findTocContainingTopic(topicHref);
-
- ITopic topic = findTopic(UrlUtil.getHelpURL(topicHref));
- if (topic != null && selectedToc >= 0) {
- foundTopicPath = getTopicPathInToc(topic, tocs[selectedToc]);
+ index = topicHref.indexOf("/nav/"); //$NON-NLS-1$
+ if (index != -1) {
+ foundTopicPath = getTopicPathFromNav(topicHref.substring(index + 5));
+
+ } else {
+ ITopic topic = findTopic(UrlUtil.getHelpURL(topicHref));
+ if (topic != null && selectedToc >= 0) {
+ foundTopicPath = getTopicPathInToc(topic,
+ tocs[selectedToc]);
+ }
}
// if no match has been found, check if there is an anchor
if (foundTopicPath == null && topicHref != null) {
@@ -58,6 +64,28 @@ public class TopicFinder {
foundTopicPath = null;
}
}
+
+ public ITopic[] getTopicPathFromNav(String nav) {
+ StringTokenizer tok = new StringTokenizer(nav, "_"); //$NON-NLS-1$
+ try {
+ int segments = tok.countTokens();
+ ITopic[] path = new ITopic[segments - 1];
+ // first number is toc index
+ int index = Integer.parseInt(tok.nextToken());
+ IToc toc = tocs[index];
+ ITopic current = toc.getTopic(null);
+ for (int i = 0; tok.hasMoreTokens(); i++) {
+ index = Integer.parseInt(tok.nextToken());
+ appendFilteredIndex(index, current.getSubtopics());
+ current = current.getSubtopics()[index];
+ path[i] = current;
+ }
+ return path;
+ } catch (Exception e) {
+ numericPath = null;
+ return null;
+ }
+ }
public ITopic[] getTopicPath() {
return foundTopicPath;
@@ -85,7 +113,7 @@ public class TopicFinder {
// returns path in reverse order
List reversePath = getTopicPathInTopic(topicToFind, topics[i]);
if (reversePath != null) {
- appendFilteredIndex(i, topics);
+ prependFilteredIndex(i, topics);
return invertPath(reversePath);
}
}
@@ -131,7 +159,7 @@ public class TopicFinder {
// it was in a subtopic.. add to the path and return
path.add(topic);
// Add to the numeric path counting only enabled topics
- appendFilteredIndex(i, subtopics);
+ prependFilteredIndex(i, subtopics);
return path;
}
}
@@ -153,6 +181,24 @@ public class TopicFinder {
if (numericPath == null) {
numericPath = "" + indexInFilteredList; //$NON-NLS-1$
} else {
+ numericPath = numericPath + '_' + indexInFilteredList;
+ }
+ }
+
+ // Prepend an entry to the numeric path representing the position in the list
+ // of filtered topics. Note that we need to convert the index in the unfiltered
+ // list to an index in a filtered list of topics
+ private void prependFilteredIndex(int indexInUnfilteredList, ITopic[] unfiltered) {
+ int indexInFilteredList = 0;
+ for (int i = 0; i < indexInUnfilteredList; i++) {
+ if (ScopeUtils.showInTree(unfiltered[i], scope)) {
+ indexInFilteredList++;
+ }
+ }
+
+ if (numericPath == null) {
+ numericPath = "" + indexInFilteredList; //$NON-NLS-1$
+ } else {
numericPath = "" + indexInFilteredList + '_' + numericPath; //$NON-NLS-1$
}
diff --git a/org.eclipse.ua.tests/data/help/toc/extraContent/toc2.xml b/org.eclipse.ua.tests/data/help/toc/extraContent/toc2.xml
index e8a507d19..ab4d86c8e 100644
--- a/org.eclipse.ua.tests/data/help/toc/extraContent/toc2.xml
+++ b/org.eclipse.ua.tests/data/help/toc/extraContent/toc2.xml
@@ -12,6 +12,9 @@
<toc label="extraContent2" topic="data/help/toc/extraContent/simple_page.html" link_to="data/help/toc/root.xml#content">
<topic label="extraContent2">
+ <topic label="Getting started" unknownAttribute2="value2">
+ <topic label="Tips and tricks" href="data/help/toc/extraContent/simple_page.html"/>
+ </topic>
<topic label="Tests FOR product: Unit Tests, WAS; version: 9.0,8.0 ; platform: z/OS;AIX" href="data/help/toc/extraContent/simple_page.html">
<criteria name="prodname" value="Happy Tests" />
<criteria name="prodname" value="WAS" />
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TopicFinderTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TopicFinderTest.java
index dcee387f3..7c969bfda 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TopicFinderTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TopicFinderTest.java
@@ -108,8 +108,8 @@ public class TopicFinderTest extends TestCase{
assertEquals("The plugin org.eclipse.help is installed", topics[1].getLabel());
assertEquals("/org.eclipse.ua.tests/data/help/toc/filteredToc/helpInstalled.html", topics[1].getHref());
}
-
- public void testNavURL() {
+
+ public void testTocNavURL() {
String topic = "http://localhost:8082/help/topic/org.eclipse.ua.tests/data/help/toc/filteredToc/helpInstalled.html";
IToc[] tocs = getTocs();
TopicFinder finder = new TopicFinder(topic, tocs, new UniversalScope());
@@ -119,5 +119,35 @@ public class TopicFinderTest extends TestCase{
assertEquals(selectedToc, finder2.getSelectedToc());
assertEquals(0, finder2.getTopicPath().length);
}
+
+ public void testTopic_0_0NavURL() {
+ checkNavTopic(0, 0);
+ }
+
+ public void testTopic_0_1NavURL() {
+ checkNavTopic(0, 1);
+ }
+
+ public void testTopic_1_0NavURL() {
+ checkNavTopic(1, 0);
+ }
+
+ private void checkNavTopic(int index1, int index2) {
+ String topic = "http://localhost:8082/help/topic/org.eclipse.ua.tests/data/help/toc/filteredToc/helpInstalled.html";
+ IToc[] tocs = getTocs();
+ TopicFinder finder = new TopicFinder(topic, tocs, new UniversalScope());
+ int selectedToc = finder.getSelectedToc();
+ String navPath = "http://127.0.0.1:1936/help/nav/" + selectedToc +
+ '_' + index1 + '_' + index2;
+ TopicFinder finder2 = new TopicFinder(navPath, tocs, new UniversalScope());
+ assertEquals(selectedToc, finder2.getSelectedToc());
+ ITopic[] topicPath = finder2.getTopicPath();
+ assertEquals(2, topicPath.length);
+ ITopic[] topLevelTopics = tocs[selectedToc].getTopics();
+ assertEquals(topLevelTopics[index1], topicPath[0]);
+ ITopic[] secondLevelTopics = topLevelTopics[index1].getSubtopics();
+ assertEquals(secondLevelTopics[index2], topicPath[1]);
+ assertEquals("" + index1 + '_' + index2, finder2.getNumericPath());
+ }
}

Back to the top