diff options
author | Dejan Gloszic | 2006-02-09 23:19:41 +0000 |
---|---|---|
committer | Dejan Gloszic | 2006-02-09 23:19:41 +0000 |
commit | 045f60cde766d1b467d923ea03db0ecf31c18723 (patch) | |
tree | e9298b22706b6cad4cf893ef3263618a42d15cbb | |
parent | 58eb0b1860f4e1a18a276ffbe39120026e02cb27 (diff) | |
download | eclipse.platform.ua-045f60cde766d1b467d923ea03db0ecf31c18723.tar.gz eclipse.platform.ua-045f60cde766d1b467d923ea03db0ecf31c18723.tar.xz eclipse.platform.ua-045f60cde766d1b467d923ea03db0ecf31c18723.zip |
127104[Help] Ability to filter out context help topics
19 files changed, 618 insertions, 44 deletions
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/ContextHelpDialog.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/ContextHelpDialog.java index f55165c2d..7c5cf1b19 100644 --- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/ContextHelpDialog.java +++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/ContextHelpDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2006 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 @@ -303,7 +303,9 @@ public class ContextHelpDialog { label.setLayoutData(data); // Create related links for (int i = 0; i < relatedTopics.length; i++) { - createLink(composite, relatedTopics[i]); + if (!UAContentFilter.isFiltered(relatedTopics[i])) { + createLink(composite, relatedTopics[i]); + } } // create dynamic help link if current context allows dynamic help diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/ContextHelpPart.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/ContextHelpPart.java index 3807bfd2a..fd9c3b639 100644 --- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/ContextHelpPart.java +++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/ContextHelpPart.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. + * Copyright (c) 2000, 2006 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 @@ -11,10 +11,20 @@ package org.eclipse.help.ui.internal.views; import org.eclipse.core.runtime.Platform; -import org.eclipse.help.*; +import org.eclipse.help.HelpSystem; +import org.eclipse.help.IContext; +import org.eclipse.help.IContext2; +import org.eclipse.help.IContextProvider; +import org.eclipse.help.IHelpResource; +import org.eclipse.help.IToc; +import org.eclipse.help.ITopic; +import org.eclipse.help.UAContentFilter; import org.eclipse.help.internal.HelpPlugin; -import org.eclipse.help.ui.internal.*; -import org.eclipse.jface.action.*; +import org.eclipse.help.ui.internal.HelpUIResources; +import org.eclipse.help.ui.internal.IHelpUIConstants; +import org.eclipse.help.ui.internal.Messages; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.dialogs.IDialogPage; import org.eclipse.jface.dialogs.IPageChangeProvider; import org.eclipse.jface.resource.JFaceResources; @@ -25,13 +35,29 @@ import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; -import org.eclipse.swt.widgets.*; -import org.eclipse.ui.*; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.IPerspectiveDescriptor; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.forms.*; -import org.eclipse.ui.forms.events.*; +import org.eclipse.ui.forms.FormColors; +import org.eclipse.ui.forms.SectionPart; +import org.eclipse.ui.forms.events.ExpansionAdapter; +import org.eclipse.ui.forms.events.ExpansionEvent; +import org.eclipse.ui.forms.events.HyperlinkEvent; import org.eclipse.ui.forms.events.IHyperlinkListener; -import org.eclipse.ui.forms.widgets.*; +import org.eclipse.ui.forms.widgets.FormText; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.Section; +import org.eclipse.ui.forms.widgets.TableWrapData; +import org.eclipse.ui.forms.widgets.TableWrapLayout; public class ContextHelpPart extends SectionPart implements IHelpPart { private ReusableHelpPart parent; @@ -415,29 +441,31 @@ public class ContextHelpPart extends SectionPart implements IHelpPart { addCategory(sbuf, null); for (int i = 0; i < links.length; i++) { IHelpResource link = links[i]; - if (context2 != null) { - String cat = context2.getCategory(link); - if (cat == null && category != null || cat != null - && category == null || cat != null - && category != null && !cat.equals(category)) { - addCategory(sbuf, cat); + if (!UAContentFilter.isFiltered(link)) { + if (context2 != null) { + String cat = context2.getCategory(link); + if (cat == null && category != null || cat != null + && category == null || cat != null + && category != null && !cat.equals(category)) { + addCategory(sbuf, cat); + } + category = cat; } - category = cat; - } - sbuf.append("<li style=\"image\" value=\""); //$NON-NLS-1$ - sbuf.append(IHelpUIConstants.IMAGE_FILE_F1TOPIC); - sbuf.append("\" indent=\"21\">"); //$NON-NLS-1$ - sbuf.append("<a href=\""); //$NON-NLS-1$ - sbuf.append(link.getHref()); - String tcat = getTopicCategory(link.getHref(), locale); - if (tcat != null && !Platform.getWS().equals(Platform.WS_GTK)) { - sbuf.append("\" alt=\""); //$NON-NLS-1$ - sbuf.append(tcat); + sbuf.append("<li style=\"image\" value=\""); //$NON-NLS-1$ + sbuf.append(IHelpUIConstants.IMAGE_FILE_F1TOPIC); + sbuf.append("\" indent=\"21\">"); //$NON-NLS-1$ + sbuf.append("<a href=\""); //$NON-NLS-1$ + sbuf.append(link.getHref()); + String tcat = getTopicCategory(link.getHref(), locale); + if (tcat != null && !Platform.getWS().equals(Platform.WS_GTK)) { + sbuf.append("\" alt=\""); //$NON-NLS-1$ + sbuf.append(tcat); + } + sbuf.append("\">"); //$NON-NLS-1$ + sbuf.append(parent.escapeSpecialChars(link.getLabel())); + sbuf.append("</a>"); //$NON-NLS-1$ + sbuf.append("</li>"); //$NON-NLS-1$ } - sbuf.append("\">"); //$NON-NLS-1$ - sbuf.append(parent.escapeSpecialChars(link.getLabel())); - sbuf.append("</a>"); //$NON-NLS-1$ - sbuf.append("</li>"); //$NON-NLS-1$ } } sbuf.append("</form>"); //$NON-NLS-1$ diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextManager.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextManager.java index b51d81064..62001413b 100644 --- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextManager.java +++ b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. + * Copyright (c) 2000, 2006 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 @@ -71,7 +71,7 @@ public class ContextManager implements IRegistryChangeListener { * Loads context.xml with context for a specified plugin, creates context * nodes and adds to pluginContext map. */ - private synchronized PluginContexts loadPluginContexts(String plugin) { + public synchronized PluginContexts loadPluginContexts(String plugin) { PluginContexts contexts = pluginsContexts.get(plugin); if (contexts == null) { contexts = new PluginContexts(); diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFile.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFile.java index dd157b78e..3858b0f4f 100644 --- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFile.java +++ b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. + * Copyright (c) 2000, 2006 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 @@ -21,7 +21,7 @@ public class ContextsFile { /** * Contexts File Constructor */ - protected ContextsFile(String definingPlugin, String href, String plugin) { + public ContextsFile(String definingPlugin, String href, String plugin) { this.href = href; this.definingPluginID = definingPlugin; this.pluginID = plugin; @@ -31,7 +31,7 @@ public class ContextsFile { * * @return Returns a String */ - protected String getHref() { + public String getHref() { return href; } protected InputStream getInputStream() { diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFileParser.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFileParser.java index 65cf75414..593589b9c 100644 --- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFileParser.java +++ b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFileParser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. + * Copyright (c) 2000, 2006 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 @@ -72,7 +72,7 @@ public class ContextsFileParser extends DefaultHandler { stack.pop(); if (!(stack.peek()).equals(ContextsNode.BOLD_TAG)) buffer.append(ContextsNode.BOLD_CLOSE_TAG); - } else { + } else if (!qName.equals("filter")) { //$NON-NLS-1$ ContextsNode node = (ContextsNode) stack.pop(); node.build(builder); } @@ -132,6 +132,19 @@ public class ContextsFileParser extends DefaultHandler { e = new Context(atts); } else if (qName.equals(ContextsNode.RELATED_ELEM)) { e = new RelatedTopic(atts); + } else if (qName.equals("filter")) { //$NON-NLS-1$ + if (!stack.empty()) { + Object parent = stack.peek(); + if (parent instanceof FilterableUAElement && atts != null) { + FilterableUAElement filterableNode = (FilterableUAElement)parent; + String name = atts.getValue("name"); //$NON-NLS-1$ + String value = atts.getValue("value"); //$NON-NLS-1$ + if (name != null && value != null) { + filterableNode.addFilter(name, value); + } + } + } + return; } else return; if (!stack.empty()) diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsNode.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsNode.java index 53ec72905..1667fd9ca 100644 --- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsNode.java +++ b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. + * Copyright (c) 2000, 2006 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 @@ -11,11 +11,12 @@ package org.eclipse.help.internal.context; import java.util.*; +import org.eclipse.help.internal.FilterableUAElement; import org.xml.sax.*; /** * Object in hierarchy of context contributions */ -public abstract class ContextsNode { +public abstract class ContextsNode extends FilterableUAElement { public static final String CONTEXTS_ELEM = "contexts"; //$NON-NLS-1$ public static final String CONTEXT_ELEM = "context"; //$NON-NLS-1$ public static final String DESC_ELEM = "description"; //$NON-NLS-1$ @@ -41,6 +42,7 @@ public abstract class ContextsNode { * ContextsNode constructor. */ public ContextsNode(Attributes attrs) { + addFilters(attrs); } /** * Adds a child diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/PluginContexts.java b/org.eclipse.help/src/org/eclipse/help/internal/context/PluginContexts.java index 2698c29e8..108959061 100644 --- a/org.eclipse.help/src/org/eclipse/help/internal/context/PluginContexts.java +++ b/org.eclipse.help/src/org/eclipse/help/internal/context/PluginContexts.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2004 IBM Corporation and others. + * Copyright (c) 2000, 2006 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 @@ -15,7 +15,7 @@ import org.eclipse.help.*; /** * Holds mapping of short contextId to IContext */ -class PluginContexts { +public class PluginContexts { private Map map = new HashMap(); public void put(String shortId, IContext context) { map.put(shortId, context); @@ -23,4 +23,11 @@ class PluginContexts { public IContext get(String shortId) { return (IContext) map.get(shortId); } + + /** + * For unit testing purposes. + */ + public Map getMap() { + return map; + } } diff --git a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java index 23dfc7433..00d67c292 100644 --- a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java +++ b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/FileUtil.java @@ -14,6 +14,7 @@ import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import org.eclipse.core.runtime.Platform; import org.osgi.framework.Bundle; @@ -28,7 +29,11 @@ public class FileUtil { * as a String (file must be encoded as UTF-8). */ public static String getContents(Bundle bundle, String relativePath) throws IOException { - return readString(bundle.getEntry(relativePath).openStream()); + URL url = bundle.getEntry(relativePath); + if (url != null) { + return readString(url.openStream()); + } + return null; } /** diff --git a/org.eclipse.ua.tests/data/help/context/contexts.xml b/org.eclipse.ua.tests/data/help/context/contexts.xml new file mode 100644 index 000000000..ed1c0fe00 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/context/contexts.xml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?NLS TYPE="org.eclipse.help.contexts"?> + +<contexts> + <context id="test.id" > + <description>This is a test context.</description> + <topic label="This topic should always appear" href="data/help/context/simple_page.html"/> + <topic filter="os=win32" label="Your OS is win32" href="data/help/context/simple_page.html"/> + <topic filter="os=linux" label="Your OS is linux" href="data/help/context/simple_page.html"/> + <topic filter="os=macosx" label="Your OS is macosx" href="data/help/context/simple_page.html"/> + + <!-- should never appear --> + <topic filter="os=invalid" label="Your OS is invalid" href="data/help/context/simple_page.html"/> + + <topic filter="ws=win32" label="Your WS is win32" href="data/help/context/simple_page.html"/> + <topic filter="ws=gtk" label="Your WS is gtk" href="data/help/context/simple_page.html"/> + <topic filter="ws=carbon" label="Your WS is carbon" href="data/help/context/simple_page.html"/> + + <!-- should never appear --> + <topic filter="ws=invalid" label="Your WS is invalid" href="data/help/context/simple_page.html"/> + + <topic filter="arch=x86" label="Your ARCH is x86" href="data/help/context/simple_page.html"/> + <topic filter="arch=ppc" label="Your ARCH is ppc" href="data/help/context/simple_page.html"/> + + <!-- should never appear --> + <topic filter="arch=invalid" label="Your ARCH is invalid" href="data/help/context/simple_page.html"/> + + <topic label="Your OS is win32 AND your WS is win32" href="data/help/context/simple_page.html"> + <filter name="os" value="win32"/> + <filter name="ws" value="win32"/> + </topic> + + <topic label="Your OS is linux AND your WS is gtk" href="data/help/context/simple_page.html"> + <filter name="os" value="linux"/> + <filter name="ws" value="gtk"/> + </topic> + + <topic label="Your OS is macosx AND your WS is carbon" href="data/help/context/simple_page.html"> + <filter name="os" value="macosx"/> + <filter name="ws" value="carbon"/> + </topic> + + <!-- should never appear --> + <topic label="Your OS is win32 AND your WS is invalid" href="data/help/context/simple_page.html"> + <filter name="os" value="win32"/> + <filter name="ws" value="invalid"/> + </topic> + + <topic filter="plugin=org.eclipse.help" label="The plugin org.eclipse.help is installed" href="data/help/context/simple_page.html"/> + + <!-- should never appear --> + <topic filter="plugin=invalid" label="The plugin invalid is installed" href="data/help/context/simple_page.html"/> + + <topic filter="product=org.eclipse.sdk.ide" label="The product org.eclipse.sdk.ide is running" href="data/help/context/simple_page.html"/> + + <!-- should never appear --> + <topic filter="product=invalid" label="The product invalid is running" href="data/help/context/simple_page.html"/> + + <topic filter="category=org.eclipse.categories.developmentCategory" label="The category org.eclipse.categories.developmentCategory is enabled" href="data/help/context/simple_page.html"/> + + <!-- should never appear --> + <topic filter="category=invalid" label="The category invalid is enabled" href="data/help/context/simple_page.html"/> + + <topic filter="activity=org.eclipse.javaDevelopment" label="The activity org.eclipse.javaDevelopment is enabled" href="data/help/context/simple_page.html"/> + + <!-- should never appear --> + <topic filter="activity=invalid" label="The activity invalid is enabled" href="data/help/context/simple_page.html"/> + + </context> +</contexts> diff --git a/org.eclipse.ua.tests/data/help/context/contexts_serialized_linux_gtk_x86.txt b/org.eclipse.ua.tests/data/help/context/contexts_serialized_linux_gtk_x86.txt new file mode 100644 index 000000000..1d86c68e4 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/context/contexts_serialized_linux_gtk_x86.txt @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<contexts> + <context id="test.id"> + <description>This is a test context.<description> + <topic + label="This topic should always appear" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="Your OS is linux" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="Your WS is gtk" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="Your ARCH is x86" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="Your OS is linux AND your WS is gtk" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="The plugin org.eclipse.help is installed" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="The product org.eclipse.sdk.ide is running" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="The category org.eclipse.categories.developmentCategory is enabled" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="The activity org.eclipse.javaDevelopment is enabled" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + </context> +</contexts> diff --git a/org.eclipse.ua.tests/data/help/context/contexts_serialized_macosx_carbon_ppc.txt b/org.eclipse.ua.tests/data/help/context/contexts_serialized_macosx_carbon_ppc.txt new file mode 100644 index 000000000..76f03d888 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/context/contexts_serialized_macosx_carbon_ppc.txt @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<contexts> + <context id="test.id"> + <description>This is a test context.<description> + <topic + label="This topic should always appear" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="Your OS is macosx" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="Your WS is carbon" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="Your ARCH is ppc" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="Your OS is macosx AND your WS is carbon" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="The plugin org.eclipse.help is installed" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="The product org.eclipse.sdk.ide is running" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="The category org.eclipse.categories.developmentCategory is enabled" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="The activity org.eclipse.javaDevelopment is enabled" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + </context> +</contexts> diff --git a/org.eclipse.ua.tests/data/help/context/contexts_serialized_win32_win32_x86.txt b/org.eclipse.ua.tests/data/help/context/contexts_serialized_win32_win32_x86.txt new file mode 100644 index 000000000..c61019fe6 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/context/contexts_serialized_win32_win32_x86.txt @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<contexts> + <context id="test.id"> + <description>This is a test context.<description> + <topic + label="This topic should always appear" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="Your OS is win32" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="Your WS is win32" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="Your ARCH is x86" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="Your OS is win32 AND your WS is win32" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="The plugin org.eclipse.help is installed" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="The product org.eclipse.sdk.ide is running" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="The category org.eclipse.categories.developmentCategory is enabled" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + <topic + label="The activity org.eclipse.javaDevelopment is enabled" + href="/org.eclipse.ua.tests/data/help/context/simple_page.html"> + </topic> + </context> +</contexts> diff --git a/org.eclipse.ua.tests/data/help/context/simple_page.html b/org.eclipse.ua.tests/data/help/context/simple_page.html new file mode 100644 index 000000000..5918e900f --- /dev/null +++ b/org.eclipse.ua.tests/data/help/context/simple_page.html @@ -0,0 +1,14 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><HTML> +<HEAD> +<meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." > +<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1"> +<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"> +<TITLE>Test</TITLE> +</HEAD> + +<p> +Test +</p> + +</BODY> +</HTML> diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java index 41880fdd2..8a044eae6 100644 --- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java @@ -13,6 +13,7 @@ package org.eclipse.ua.tests.help; import junit.framework.Test; import junit.framework.TestSuite; +import org.eclipse.ua.tests.help.context.AllContextTests; import org.eclipse.ua.tests.help.toc.AllTocTests; /* @@ -31,6 +32,7 @@ public class AllHelpTests extends TestSuite { * Constructs a new test suite. */ public AllHelpTests() { + addTest(AllContextTests.suite()); addTest(AllTocTests.suite()); } } diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/AllContextTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/AllContextTests.java new file mode 100644 index 000000000..4b27aeaa3 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/AllContextTests.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2006 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.ua.tests.help.context; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/* + * Tests help functionality (automated). + */ +public class AllContextTests extends TestSuite { + + /* + * Returns the entire test suite. + */ + public static Test suite() { + return new AllContextTests(); + } + + /* + * Constructs a new test suite. + */ + public AllContextTests() { + addTest(ParserTest.suite()); + } +} diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/ParserTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/ParserTest.java new file mode 100644 index 000000000..f6c769f38 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/ParserTest.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2006 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.ua.tests.help.context; + +import java.io.IOException; +import java.util.Iterator; + +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.help.internal.context.ContextsBuilder; +import org.eclipse.help.internal.context.ContextsFile; +import org.eclipse.help.internal.context.PluginContexts; +import org.eclipse.help.ui.internal.HelpUIPlugin; +import org.eclipse.ua.tests.help.util.ContextModelSerializer; +import org.eclipse.ua.tests.help.util.ContextModelSerializerTest; +import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin; +import org.eclipse.ua.tests.util.FileUtil; +import org.osgi.framework.Bundle; + +public class ParserTest extends TestCase { + + /* + * Returns an instance of this Test. + */ + public static Test suite() { + return new TestSuite(ParserTest.class); + } + + /* + * Ensure that org.eclipse.help.ui is started. It contributes extra content + * filtering that is used by this test. See UIContentFilterProcessor. + */ + protected void setUp() throws Exception { + HelpUIPlugin.getDefault(); + } + + public void testParser() { + Iterator iter = ContextModelSerializerTest.getContextFiles().iterator(); + while (iter.hasNext()) { + ContextsFile file = (ContextsFile)iter.next(); + PluginContexts contexts = new PluginContexts(); + ContextsBuilder builder = new ContextsBuilder(contexts); + builder.build(file); + + Bundle bundle = UserAssistanceTestPlugin.getDefault().getBundle(); + String relativePath = file.getHref(); + + try { + String expected = FileUtil.getResultFileContents(bundle, relativePath); + String actual = ContextModelSerializer.serialize(contexts); + Assert.assertEquals("Serialized context help model for " + relativePath + " did not match the expected result", expected, actual); + } + catch(IOException e) { + Assert.fail("An error occured while loading expected result file for context help at: " + relativePath + ": " + e); + } + } + } +} diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializer.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializer.java new file mode 100644 index 000000000..4832afe55 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializer.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2006 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.ua.tests.help.util; + +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.help.IContext; +import org.eclipse.help.IHelpResource; +import org.eclipse.help.UAContentFilter; +import org.eclipse.help.internal.context.PluginContexts; + +public class ContextModelSerializer { + + private static final String EMPTY_STRING = ""; + + public static String serialize(PluginContexts contexts) { + StringBuffer buf = new StringBuffer(); + buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); + buf.append(serializeAux(contexts, "")); + return buf.toString(); + } + + private static String serializeAux(PluginContexts contexts, String indent) { + StringBuffer buf = new StringBuffer(); + buf.append(indent + "<contexts>\n"); + + Iterator iter = contexts.getMap().entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = (Map.Entry)iter.next(); + buf.append(serializeAux(entry, indent + " ")); + } + + buf.append(indent + "</contexts>\n"); + return buf.toString(); + } + + private static String serializeAux(Map.Entry entry, String indent) { + String id = (String)entry.getKey(); + IContext context = (IContext)entry.getValue(); + StringBuffer buf = new StringBuffer(); + buf.append(indent + "<context id=\"" + id + "\">\n"); + buf.append(indent + " <description>"); + buf.append(context.getText()); + buf.append("<description>\n"); + + IHelpResource[] topics = context.getRelatedTopics(); + for (int i=0;i<topics.length;++i) { + buf.append(serializeAux(topics[i], indent + " ")); + } + + buf.append(indent + "</context>\n"); + return buf.toString(); + } + + private static String serializeAux(IHelpResource topic, String indent) { + if (!UAContentFilter.isFiltered(topic)) { + StringBuffer buf = new StringBuffer(); + buf.append(indent + "<topic\n"); + buf.append(indent + " label=\"" + topic.getLabel() + "\"\n"); + buf.append(indent + " href=\"" + topic.getHref() + "\">\n"); + buf.append(indent + "</topic>\n"); + return buf.toString(); + } + return EMPTY_STRING; + } +} diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializerTest.java new file mode 100644 index 000000000..429af6c4f --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializerTest.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2006 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.ua.tests.help.util; + +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.Platform; +import org.eclipse.help.internal.context.ContextsBuilder; +import org.eclipse.help.internal.context.ContextsFile; +import org.eclipse.help.internal.context.PluginContexts; +import org.eclipse.help.ui.internal.HelpUIPlugin; +import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin; +import org.eclipse.ua.tests.util.FileUtil; + +/* + * A utility for regenerating the _serialized.txt files that contain the expected + * output for the context content when serialized. This reads all the context content + * from the plugin manifest (for this test plugin only), constructs the model, then + * serializes the model to a text file, which is stored in the same directory as the + * intro xml file, as <original_name>_serialized.txt. + * + * These files are used by the JUnit tests to compare the result with the expected + * result. + * + * Usage: + * + * 1. Run this test as a JUnit plug-in test. + * 2. Right-click in "Package Explorer -> Refresh". + * + * The new files should appear. + * + * Note: Some of the files have os, ws, and arch appended, for example + * <original_name>_serialized_linux_gtk_x86.txt. These are filtering tests that have + * filters by os/ws/arch so the result is different on each combination. This test will + * only generate the _serialized file and will be the one for the current platform. You + * need to make one copy for each combination and edit the files manually to have the + * correct content (or generate on each platform). + */ +public class ContextModelSerializerTest extends TestCase { + + /* + * Returns an instance of this Test. + */ + public static Test suite() { + return new TestSuite(ContextModelSerializerTest.class); + } + + /* + * Ensure that org.eclipse.help.ui is started. It contributes extra content + * filtering that is used by this test. See UIContentFilterProcessor. + */ + protected void setUp() throws Exception { + HelpUIPlugin.getDefault(); + } + + public void testRunSerializer() { + Iterator iter = getContextFiles().iterator(); + while (iter.hasNext()) { + ContextsFile file = (ContextsFile)iter.next(); + PluginContexts contexts = new PluginContexts(); + ContextsBuilder builder = new ContextsBuilder(contexts); + builder.build(file); + + String pluginRoot = UserAssistanceTestPlugin.getDefault().getBundle().getLocation().substring("update@".length()); + String relativePath = file.getHref(); + String absolutePath = pluginRoot + relativePath; + String resultFile = FileUtil.getResultFile(absolutePath); + + try { + PrintWriter out = new PrintWriter(new FileOutputStream(resultFile)); + out.print(ContextModelSerializer.serialize(contexts)); + out.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + + /** + * Gets all context files from the extension with id "tests.context". We only want + * to consider these for our tests. + * + * @return all ContextsFile objects contributed for tests + */ + public static Collection getContextFiles() { + Collection contextFiles = new ArrayList(); + IExtension extension = Platform.getExtensionRegistry().getExtension(UserAssistanceTestPlugin.getPluginId() + ".contextTest"); + IConfigurationElement[] configElements = extension.getConfigurationElements(); + for (int j=0;j<configElements.length;j++) { + if (configElements[j].getName().equals("contexts")) { + String href = configElements[j].getAttribute("file"); //$NON-NLS-1$ + contextFiles.add(new ContextsFile(UserAssistanceTestPlugin.getPluginId(), href, null)); + } + } + return contextFiles; + } +} diff --git a/org.eclipse.ua.tests/plugin.xml b/org.eclipse.ua.tests/plugin.xml index 68d8d046f..9a04e75d7 100644 --- a/org.eclipse.ua.tests/plugin.xml +++ b/org.eclipse.ua.tests/plugin.xml @@ -216,6 +216,17 @@ configId="org.eclipse.ua.tests.intro.config.dynamicXML"> </configExtension> </extension> + + <!-- + Context help test content + --> + <extension + point="org.eclipse.help.contexts" + id="contextTest"> + <contexts + file="data/help/context/contexts.xml"> + </contexts> + </extension> <!-- TOC test content |