diff options
author | Chris Goldthorpe | 2011-09-06 16:14:11 +0000 |
---|---|---|
committer | Chris Goldthorpe | 2011-09-06 16:14:11 +0000 |
commit | 5e64f60c82a2553b44b764e7e359d6e903f67822 (patch) | |
tree | 0894f21a1520b75fceeee50c7290b80a77c624a4 /org.eclipse.ua.tests/help/org | |
parent | 33a4df3270f503683d80fb9cc3c70766890b1cf4 (diff) | |
download | eclipse.platform.ua-5e64f60c82a2553b44b764e7e359d6e903f67822.tar.gz eclipse.platform.ua-5e64f60c82a2553b44b764e7e359d6e903f67822.tar.xz eclipse.platform.ua-5e64f60c82a2553b44b764e7e359d6e903f67822.zip |
Bug 330868 - [Webapp] Wrong doc path when a page is referenced twice
Diffstat (limited to 'org.eclipse.ua.tests/help/org')
2 files changed, 44 insertions, 11 deletions
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FragmentServletTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FragmentServletTest.java index d421d3c51..46d7b4de5 100644 --- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FragmentServletTest.java +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FragmentServletTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009 IBM Corporation and others. + * Copyright (c) 2009, 2011 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 @@ -25,7 +25,12 @@ public class FragmentServletTest extends TestCase { public void testFixHrefNormal() { String href = TocFragmentServlet.fixupHref(DOC_HTML, PATH); - assertEquals(DOC_HTML, href); + assertEquals(DOC_HTML + "?cp=1_2", href); + } + + public void testFixHrefWithParameter() { + String href = TocFragmentServlet.fixupHref(DOC_HTML + "?a=b", PATH); + assertEquals(DOC_HTML + "?a=b&cp=1_2", href); } public void testFixHrefNull() { @@ -35,12 +40,12 @@ public class FragmentServletTest extends TestCase { public void testFixHrefWithAnchor() { String href = TocFragmentServlet.fixupHref(DOC_HTML + "#A", PATH); - assertEquals(DOC_HTML + "?path=1_2#A" , href); + assertEquals(DOC_HTML + "?cp=1_2#A" , href); } public void testFixHrefWithAnchorAndParams() { String href = TocFragmentServlet.fixupHref(DOC_HTML + "?a=b#A", PATH); - assertEquals(DOC_HTML + "?a=b&path=1_2#A" , href); + assertEquals(DOC_HTML + "?a=b&cp=1_2#A" , href); } } diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java index 039f8900e..68e7a61c9 100644 --- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java @@ -66,11 +66,11 @@ public class TocFragmentServiceTest extends TestCase { assertEquals(1, UARoot.length); Element[] filterNode = findNodeById(UARoot[0], "2"); assertEquals(1, filterNode.length); - Element[] results = findChildren(filterNode[0], "node", "href", + Element[] results = findHref(filterNode[0], "node", "../topic/org.eclipse.ua.tests/data/help/toc/filteredToc/simple_page.html"); assertEquals(24, results.length); - results = findChildren(filterNode[0], "node", "href", + results = findHref(filterNode[0], "node", "../topic/org.eclipse.ua.tests/data/help/toc/filteredToc/helpInstalled.html"); assertEquals(1, results.length); } @@ -87,10 +87,10 @@ public class TocFragmentServiceTest extends TestCase { assertEquals(1, UARoot.length); Element[] searchNode = findChildren(UARoot[0], "node", "title", "search"); assertEquals(1, searchNode.length); - Element[] topicEn = findChildren(searchNode[0], "node", "href", + Element[] topicEn = findHref(searchNode[0], "node", "../topic/org.eclipse.ua.tests/data/help/search/test_en.html"); assertEquals(1, topicEn.length); - Element[] topicDe = findChildren(searchNode[0], "node", "href", + Element[] topicDe = findHref(searchNode[0], "node", "../topic/org.eclipse.ua.tests/data/help/search/test_de.html"); assertEquals(0, topicDe.length); } @@ -124,10 +124,10 @@ public class TocFragmentServiceTest extends TestCase { "/org.eclipse.ua.tests/data/help/toc/root.xml"); assertEquals(1, UARoot.length); Element[] searchNode = findChildren(UARoot[0], "node", "title", "search"); - Element[] topicEn = findChildren(searchNode[0], "node", "href", + Element[] topicEn = findHref(searchNode[0], "node", "../topic/org.eclipse.ua.tests/data/help/search/test_en.html"); assertEquals(0, topicEn.length); - Element[] topicDe = findChildren(searchNode[0], "node", "href", + Element[] topicDe = findHref(searchNode[0], "node", "../topic/org.eclipse.ua.tests/data/help/search/test_de.html"); assertEquals(1, topicDe.length); BaseHelpSystem.setMode(helpMode); @@ -136,7 +136,7 @@ public class TocFragmentServiceTest extends TestCase { private Element[] findNodeById(Node root, String id) { return findChildren(root, "node", "id", id); } - + private Element[] findChildren(Node parent, String childKind, String attributeName, String attributeValue) { NodeList nodes = parent.getChildNodes(); @@ -154,6 +154,34 @@ public class TocFragmentServiceTest extends TestCase { } return (Element[]) results.toArray(new Element[results.size()]); } + + /* + * Look for a matching href, the query part of the href is not compared + */ + private Element[] findHref(Node parent, String childKind, + String attributeValue) { + NodeList nodes = parent.getChildNodes(); + List<Node> results = new ArrayList<Node>(); + for (int i = 0; i < nodes.getLength(); i++) { + Node next = nodes.item(i); + if (next instanceof Element) { + Element nextElement = (Element)next; + if ( childKind.equals(nextElement.getTagName()) ) { + String href = nextElement.getAttribute("href"); + if (href != null) { + int query = href.indexOf('?'); + if (query >= 0) { + href = href.substring(0, query); + } + if (href.equals (attributeValue)) { + results.add(next); + } + } + } + } + } + return (Element[]) results.toArray(new Element[results.size()]); + } private Node getTreeData(URL url) |