Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurtis D'Entremont2006-11-02 15:41:27 -0500
committerCurtis D'Entremont2006-11-02 15:41:27 -0500
commit30caa2bacbc0f40cea3466170fcf058439baca88 (patch)
treeb158c0107e6b2eeec0f2e28be13f8d7f6c55fd20
parent0c090ee282e9791f40896518ae19af25807db3e8 (diff)
downloadeclipse.platform.ua-30caa2bacbc0f40cea3466170fcf058439baca88.tar.gz
eclipse.platform.ua-30caa2bacbc0f40cea3466170fcf058439baca88.tar.xz
eclipse.platform.ua-30caa2bacbc0f40cea3466170fcf058439baca88.zip
dynamic content across all UA
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/HelpDisplay.java2
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteContextParser.java137
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteContextProvider.java13
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteExtensionParser.java58
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteExtensionProvider.java19
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteIndexParser.java99
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteIndexProvider.java8
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocParser.java161
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocProvider.java6
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java4
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/search/IndexingOperation.java4
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/search/LocalSearchManager.java11
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSetManager.java5
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/xhtml/DynamicXHTMLProcessor.java6
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/xhtml/XHTMLCharsetHandler.java4
-rw-r--r--org.eclipse.help.ui/src/org/eclipse/help/ui/internal/HelpUIPlugin.java13
-rw-r--r--org.eclipse.help.ui/src/org/eclipse/help/ui/internal/StyledLineWrapper.java27
-rw-r--r--org.eclipse.help.ui/src/org/eclipse/help/ui/internal/search/InfoCenterPage.java11
-rw-r--r--org.eclipse.help.ui/src/org/eclipse/help/ui/internal/util/ErrorUtil.java4
-rw-r--r--org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/EngineTypeDescriptor.java17
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/IndexData.java13
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ContextSerializer.java53
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ContextServlet.java29
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ExtensionSerializer.java40
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ExtensionServlet.java31
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/IndexSerializer.java91
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/IndexServlet.java31
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchSerializer.java63
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchServlet.java44
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/TocSerializer.java140
-rw-r--r--org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/TocServlet.java31
-rw-r--r--org.eclipse.help/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.help/plugin.xml2
-rw-r--r--org.eclipse.help/src/org/eclipse/help/AbstractContentExtensionProvider.java15
-rw-r--r--org.eclipse.help/src/org/eclipse/help/AbstractContextProvider.java11
-rw-r--r--org.eclipse.help/src/org/eclipse/help/AbstractIndexProvider.java4
-rw-r--r--org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java4
-rw-r--r--org.eclipse.help/src/org/eclipse/help/IAnchor.java33
-rw-r--r--org.eclipse.help/src/org/eclipse/help/IContentExtension.java68
-rw-r--r--org.eclipse.help/src/org/eclipse/help/IFilter.java85
-rw-r--r--org.eclipse.help/src/org/eclipse/help/IInclude.java34
-rw-r--r--org.eclipse.help/src/org/eclipse/help/IIndex.java2
-rw-r--r--org.eclipse.help/src/org/eclipse/help/IIndexContribution.java46
-rw-r--r--org.eclipse.help/src/org/eclipse/help/IIndexEntry.java5
-rw-r--r--org.eclipse.help/src/org/eclipse/help/INode.java43
-rw-r--r--org.eclipse.help/src/org/eclipse/help/IToc.java4
-rw-r--r--org.eclipse.help/src/org/eclipse/help/ITocContribution.java83
-rw-r--r--org.eclipse.help/src/org/eclipse/help/ITopic.java2
-rw-r--r--org.eclipse.help/src/org/eclipse/help/IndexContribution.java99
-rw-r--r--org.eclipse.help/src/org/eclipse/help/Node.java9
-rw-r--r--org.eclipse.help/src/org/eclipse/help/TocContribution.java212
-rw-r--r--org.eclipse.help/src/org/eclipse/help/UAContentFilter.java92
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/Anchor.java26
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/Filter.java27
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/FilterableHelpElement.java19
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/FilterableUAElement.java126
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java126
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/ITocsChangedListener.java15
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/Include.java26
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/Messages.java27
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/Messages.properties10
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/Node.java151
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/NodeAdapter.java173
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/Topic.java75
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/Context.java181
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextFile.java63
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java217
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextManager.java42
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextPrefetcher.java75
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/Contexts.java25
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextsBuilder.java125
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFile.java68
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFileParser.java201
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFileProvider.java163
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextsNode.java63
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/PluginContexts.java34
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/PluginsContexts.java28
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/RelatedTopic.java47
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentNode.java (renamed from org.eclipse.help/src/org/eclipse/help/internal/dynamic/DOMNode.java)24
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentReader.java (renamed from org.eclipse.help/src/org/eclipse/help/internal/dynamic/DOMReader.java)2
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentWriter.java (renamed from org.eclipse.help/src/org/eclipse/help/internal/dynamic/DOMWriter.java)2
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/ExtensionHandler.java10
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/ExtensionResolver.java18
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/FilterHandler.java77
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/IncludeHandler.java2
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/IncludeResolver.java10
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeHandler.java (renamed from org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentProcessorHandler.java)8
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeProcessor.java (renamed from org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentProcessor.java)34
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeReader.java88
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeWriter.java85
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/XMLProcessor.java16
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtension.java77
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionFileParser.java137
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionFileProvider.java25
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionManager.java78
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionPrefetcher.java30
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/Index.java49
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/IndexAssembler.java93
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/IndexContribution.java43
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/IndexEntry.java105
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileParser.java136
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileProvider.java8
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/IndexManager.java30
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/IndexPrefetcher.java75
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/Toc.java192
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocAssembler.java396
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocContribution.java81
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileParser.java231
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java10
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java82
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocPrefetcher.java108
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/Topic.java52
-rw-r--r--org.eclipse.ua.tests/data/help/context/contexts.xml41
-rw-r--r--org.eclipse.ua.tests/data/help/context/contexts_expected.txt30
-rw-r--r--org.eclipse.ua.tests/data/help/context/simple_page.html14
-rw-r--r--org.eclipse.ua.tests/data/help/dynamic/filter_expected.txt56
-rw-r--r--org.eclipse.ua.tests/data/help/index/index.xml8
-rw-r--r--org.eclipse.ua.tests/data/help/index/parser/index.xml14
-rw-r--r--org.eclipse.ua.tests/data/help/manual/filter.xhtml (renamed from org.eclipse.ua.tests/data/help/manual/dynamic.xhtml)0
-rw-r--r--org.eclipse.ua.tests/data/help/manual/manual.xml2
-rw-r--r--org.eclipse.ua.tests/data/help/toc/assembler/a.xml1
-rw-r--r--org.eclipse.ua.tests/data/help/toc/assembler/b.xml1
-rw-r--r--org.eclipse.ua.tests/data/help/toc/assembler/d.xml6
-rw-r--r--org.eclipse.ua.tests/data/help/toc/assembler/result_a_b_c.xml10
-rw-r--r--org.eclipse.ua.tests/data/help/toc/assembler/result_a_b_c_d.xml15
-rw-r--r--org.eclipse.ua.tests/data/help/toc/assembler/result_b_c.xml10
-rw-r--r--org.eclipse.ua.tests/data/help/toc/parser/extraDir/otherDir/page3.html14
-rw-r--r--org.eclipse.ua.tests/data/help/toc/parser/extraDir/page1.html14
-rw-r--r--org.eclipse.ua.tests/data/help/toc/parser/extraDir/page2.html14
-rw-r--r--org.eclipse.ua.tests/data/help/toc/parser/toc.xml12
-rw-r--r--org.eclipse.ua.tests/data/intro/dynamicXHTML/content/filter_expected.txt8
-rw-r--r--org.eclipse.ua.tests/data/intro/dynamicXML/introContent_expected.txt50
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java2
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/AllContextTests.java34
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/ParserTest.java70
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java4
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/AllIndexTests.java1
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexAssemblerTest.java84
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexFileParserTest.java128
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/ExtraDirTest.java6
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/AllTocTests.java1
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java79
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocFileParserTest.java122
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializer.java75
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializerTest.java105
-rw-r--r--org.eclipse.ua.tests/plugin.xml11
-rw-r--r--org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroElement.java3
-rw-r--r--org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroIdElement.java2
-rw-r--r--org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java12
149 files changed, 2516 insertions, 5122 deletions
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/HelpDisplay.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/HelpDisplay.java
index 4450f2f66..4ecc56d2b 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/HelpDisplay.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/HelpDisplay.java
@@ -193,7 +193,7 @@ public class HelpDisplay {
private String getContextID(IContext context) {
if (context instanceof Context)
- return ((Context) context).getID();
+ return ((Context)context).getId();
return HelpPlugin.getContextManager().addContext(context);
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteContextParser.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteContextParser.java
deleted file mode 100644
index b26d27fc4..000000000
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteContextParser.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.base.remote;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Stack;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.eclipse.help.IContext;
-import org.eclipse.help.IHelpResource;
-import org.eclipse.help.INode;
-import org.eclipse.help.internal.Node;
-import org.eclipse.help.internal.toc.Topic;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-/*
- * Converts a context serialized by the ContextServlet on remote help server
- * back into model objects. The XML format is the same as with contexts in
- * context XML files except there is only one.
- */
-public class RemoteContextParser extends DefaultHandler {
-
- private Stack stack = new Stack();
- private Context context;
- private StringBuffer description;
-
- /*
- * Parses the given serialized indexes and returns generated model objects.
- */
- public IContext parse(InputStream in) throws ParserConfigurationException, SAXException, IOException {
- SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
- parser.parse(in, this);
- return context;
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
- */
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- if (qName.equals("context")) { //$NON-NLS-1$
- handleContext(attributes);
- }
- else if (qName.equals("description")) { //$NON-NLS-1$
- handleDescription(attributes);
- }
- else if (qName.equals("topic")) { //$NON-NLS-1$
- handleTopic(attributes);
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
- */
- public void endElement(String uri, String localName, String qName) throws SAXException {
- if (qName.equals("context") //$NON-NLS-1$
- || qName.equals("topic")) { //$NON-NLS-1$
- stack.pop();
- }
- else if (qName.equals("description") && description != null && context != null) { //$NON-NLS-1$
- context.setText(description.toString());
- description = null;
- }
- }
-
- public void characters(char[] ch, int start, int length) throws SAXException {
- if (description != null) {
- description.append(ch, start, length);
- }
- }
-
- private void handleContext(Attributes attr) {
- context = new Context(null);
- stack.push(context);
- }
-
- private void handleDescription(Attributes attr) {
- description = new StringBuffer();
- }
-
- private void handleTopic(Attributes attr) {
- String label = attr.getValue("label"); //$NON-NLS-1$
- String href = attr.getValue("href"); //$NON-NLS-1$
- Topic topic = new Topic(href, label);
- Node node = (Node)stack.peek();
- node.addChild(topic);
- stack.push(topic);
- }
-
- private static class Context extends Node implements IContext {
- private String text;
- private IHelpResource[] topics;
-
- public Context(String text) {
- this.text = text;
- }
- public String getText() {
- return text;
- }
- public void setText(String text) {
- this.text = text;
- }
- public IHelpResource[] getRelatedTopics() {
- if (topics == null) {
- INode[] children = getChildren();
- if (children.length > 0) {
- List list = new ArrayList();
- for (int i=0;i<children.length;++i) {
- if (children[i] instanceof IHelpResource) {
- list.add(children[i]);
- }
- }
- topics = (IHelpResource[])list.toArray(new IHelpResource[list.size()]);
- }
- else {
- topics = new IHelpResource[0];
- }
- }
- return topics;
- }
- }
-}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteContextProvider.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteContextProvider.java
index 25d5a7605..873ab2064 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteContextProvider.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteContextProvider.java
@@ -16,8 +16,9 @@ import java.net.HttpURLConnection;
import java.net.URL;
import org.eclipse.help.AbstractContextProvider;
-import org.eclipse.help.IContext;
+import org.eclipse.help.Node;
import org.eclipse.help.internal.base.HelpBasePlugin;
+import org.eclipse.help.internal.dynamic.NodeReader;
/*
* Provides the context-sensitive help data that is located on the remote
@@ -30,10 +31,12 @@ public class RemoteContextProvider extends AbstractContextProvider {
private static final String PARAM_ID = "id"; //$NON-NLS-1$
private static final String PARAM_LANG = "lang"; //$NON-NLS-1$
+ private NodeReader reader;
+
/* (non-Javadoc)
* @see org.eclipse.help.AbstractContextProvider#getContext(java.lang.String, java.lang.String)
*/
- public IContext getContext(String id, String locale) {
+ public Node getContext(String id, String locale) {
if (RemoteHelp.isEnabled()) {
InputStream in = null;
try {
@@ -41,8 +44,10 @@ public class RemoteContextProvider extends AbstractContextProvider {
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
if (connection.getResponseCode() == 200) {
in = connection.getInputStream();
- RemoteContextParser parser = new RemoteContextParser();
- return parser.parse(in);
+ if (reader == null) {
+ reader = new NodeReader();
+ }
+ return reader.read(in);
}
}
catch (IOException e) {
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteExtensionParser.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteExtensionParser.java
deleted file mode 100644
index 213204f76..000000000
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteExtensionParser.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.base.remote;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.eclipse.help.IContentExtension;
-import org.eclipse.help.internal.extension.ContentExtension;
-import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-
-public class RemoteExtensionParser extends DefaultHandler {
-
- private List extensions = new ArrayList();
-
- public IContentExtension[] parse(InputStream in) throws ParserConfigurationException, SAXException, IOException {
- SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
- parser.parse(in, this);
- return (IContentExtension[])extensions.toArray(new IContentExtension[extensions.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
- */
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- if (qName.equals("contentExtension")) { //$NON-NLS-1$
- handleContentExtension(attributes);
- }
- }
-
- private void handleContentExtension(Attributes attr) {
- String content = attr.getValue("content"); //$NON-NLS-1$
- String path = attr.getValue("path"); //$NON-NLS-1$
- int type = 0;
- try {
- type = Integer.parseInt(attr.getValue("type")); //$NON-NLS-1$
- }
- catch (Throwable t) {}
- ContentExtension ext = new ContentExtension(content, path, type);
- extensions.add(ext);
- }
-}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteExtensionProvider.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteExtensionProvider.java
index 6693fb374..64c9f9a2a 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteExtensionProvider.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteExtensionProvider.java
@@ -17,13 +17,16 @@ import java.net.URL;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.help.AbstractContentExtensionProvider;
-import org.eclipse.help.IContentExtension;
+import org.eclipse.help.Node;
import org.eclipse.help.internal.base.HelpBasePlugin;
+import org.eclipse.help.internal.dynamic.NodeReader;
public class RemoteExtensionProvider extends AbstractContentExtensionProvider {
private static final String PATH_EXTENSIONS = "/extension"; //$NON-NLS-1$
+ private NodeReader reader;
+
public RemoteExtensionProvider() {
RemoteHelp.addPreferenceChangeListener(new IPreferenceChangeListener() {
public void preferenceChange(PreferenceChangeEvent event) {
@@ -32,17 +35,17 @@ public class RemoteExtensionProvider extends AbstractContentExtensionProvider {
});
}
- /* (non-Javadoc)
- * @see org.eclipse.help.AbstractContentExtensionProvider#getContentExtensions(java.lang.String)
- */
- public IContentExtension[] getContentExtensions(String locale) {
+ public Node[] getContentExtensions(String locale) {
if (RemoteHelp.isEnabled()) {
InputStream in = null;
try {
URL url = RemoteHelp.getURL(PATH_EXTENSIONS);
in = url.openStream();
- RemoteExtensionParser parser = new RemoteExtensionParser();
- return parser.parse(in);
+ if (reader == null) {
+ reader = new NodeReader();
+ }
+ Node node = reader.read(in);
+ return node.getChildren();
}
catch (IOException e) {
String msg = "I/O error while trying to contact the remote help server"; //$NON-NLS-1$
@@ -63,6 +66,6 @@ public class RemoteExtensionProvider extends AbstractContentExtensionProvider {
}
}
}
- return new IContentExtension[0];
+ return new Node[0];
}
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteIndexParser.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteIndexParser.java
index 8c54b9a24..446e547f9 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteIndexParser.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteIndexParser.java
@@ -12,21 +12,12 @@ package org.eclipse.help.internal.base.remote;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Stack;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import org.eclipse.help.IIndexContribution;
-import org.eclipse.help.internal.Node;
-import org.eclipse.help.internal.index.Index;
-import org.eclipse.help.internal.index.IndexContribution;
-import org.eclipse.help.internal.index.IndexEntry;
-import org.eclipse.help.internal.toc.Topic;
-import org.xml.sax.Attributes;
+import org.eclipse.help.IndexContribution;
+import org.eclipse.help.Node;
+import org.eclipse.help.internal.dynamic.NodeReader;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@@ -37,77 +28,25 @@ import org.xml.sax.helpers.DefaultHandler;
*/
public class RemoteIndexParser extends DefaultHandler {
- private Stack stack = new Stack();
- private List contributions = new ArrayList();
-
+ private NodeReader reader;
+
/*
* Parses the given serialized indexes and returns generated model objects.
*/
- public IIndexContribution[] parse(InputStream in) throws ParserConfigurationException, SAXException, IOException {
- SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
- parser.parse(in, this);
- return (IIndexContribution[])contributions.toArray(new IIndexContribution[contributions.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
- */
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- if (qName.equals("entry")) { //$NON-NLS-1$
- handleIndexEntry(attributes);
- }
- else if (qName.equals("topic")) { //$NON-NLS-1$
- handleTopic(attributes);
- }
- else if (qName.equals("index")) { //$NON-NLS-1$
- handleIndex(attributes);
- }
- else if (qName.equals("indexContribution")) { //$NON-NLS-1$
- handleIndexContribution(attributes);
- }
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
- */
- public void endElement(String uri, String localName, String qName) throws SAXException {
- if (qName.equals("entry") //$NON-NLS-1$
- || qName.equals("topic") //$NON-NLS-1$
- || qName.equals("index") //$NON-NLS-1$
- || qName.equals("indexContribution")) { //$NON-NLS-1$
- stack.pop();
+ public IndexContribution[] parse(InputStream in) throws ParserConfigurationException, SAXException, IOException {
+ if (reader == null) {
+ reader = new NodeReader();
}
- }
-
- private void handleIndexContribution(Attributes attr) {
- String id = attr.getValue("id"); //$NON-NLS-1$
- String locale = attr.getValue("locale"); //$NON-NLS-1$
- IndexContribution contribution = new IndexContribution(id, null, locale);
- contributions.add(contribution);
- stack.push(contribution);
- }
-
- private void handleIndex(Attributes attr) {
- Index index = new Index();
- IndexContribution contribution = (IndexContribution)stack.peek();
- contribution.setIndex(index);
- stack.push(index);
- }
-
- private void handleIndexEntry(Attributes attr) {
- String keyword = attr.getValue("keyword"); //$NON-NLS-1$
- IndexEntry entry = new IndexEntry(keyword);
- Node node = (Node)stack.peek();
- node.addChild(entry);
- stack.push(entry);
- }
-
- private void handleTopic(Attributes attr) {
- String label = attr.getValue("label"); //$NON-NLS-1$
- String href = attr.getValue("href"); //$NON-NLS-1$
- Topic topic = new Topic(href, label);
- Node node = (Node)stack.peek();
- node.addChild(topic);
- stack.push(topic);
+ Node root = reader.read(in);
+ Node[] children = root.getChildren();
+ IndexContribution[] contributions = new IndexContribution[children.length];
+ for (int i=0;i<children.length;++i) {
+ IndexContribution contribution = new IndexContribution();
+ contribution.setId(children[i].getAttribute("id")); //$NON-NLS-1$
+ contribution.setLocale(children[i].getAttribute("locale")); //$NON-NLS-1$
+ contribution.setIndex(children[i].getChildren()[0]);
+ contributions[i] = contribution;
+ }
+ return contributions;
}
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteIndexProvider.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteIndexProvider.java
index 9e11769b6..93cd1dbf2 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteIndexProvider.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteIndexProvider.java
@@ -17,7 +17,7 @@ import java.net.URL;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.help.AbstractIndexProvider;
-import org.eclipse.help.IIndexContribution;
+import org.eclipse.help.IndexContribution;
import org.eclipse.help.internal.base.HelpBasePlugin;
/*
@@ -42,9 +42,9 @@ public class RemoteIndexProvider extends AbstractIndexProvider {
}
/* (non-Javadoc)
- * @see org.eclipse.help.AbstractIndexProvider#getIndexContributions(java.lang.String)
+ * @see org.eclipse.help.AbstractIndexProvider#getIndexContributions(String)
*/
- public IIndexContribution[] getIndexContributions(String locale) {
+ public IndexContribution[] getIndexContributions(String locale) {
if (RemoteHelp.isEnabled()) {
InputStream in = null;
try {
@@ -72,6 +72,6 @@ public class RemoteIndexProvider extends AbstractIndexProvider {
}
}
}
- return new IIndexContribution[0];
+ return new IndexContribution[0];
}
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocParser.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocParser.java
index 8967cbe82..28650a1e7 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocParser.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocParser.java
@@ -12,143 +12,42 @@ package org.eclipse.help.internal.base.remote;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Stack;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import org.eclipse.help.ITocContribution;
-import org.eclipse.help.internal.Anchor;
-import org.eclipse.help.internal.Filter;
-import org.eclipse.help.internal.Include;
-import org.eclipse.help.internal.Node;
-import org.eclipse.help.internal.toc.Toc;
-import org.eclipse.help.internal.toc.TocContribution;
-import org.eclipse.help.internal.toc.Topic;
-import org.xml.sax.Attributes;
+import org.eclipse.help.Node;
+import org.eclipse.help.TocContribution;
+import org.eclipse.help.internal.dynamic.NodeReader;
import org.xml.sax.SAXException;
-import org.xml.sax.helpers.DefaultHandler;
-/*
- * Converts TOCs serialized by the TocServlet on remote help server back into
- * model objects. The XML is similar to TOC XML files but not identical (it has
- * all TOCs in one, includes instead of links, tocContributions, etc.
- */
-public class RemoteTocParser extends DefaultHandler {
+public class RemoteTocParser {
- private Stack stack = new Stack();
- private List contributions = new ArrayList();
-
- /*
- * Parses the given serialized TOC and returns generated model objects.
- */
- public ITocContribution[] parse(InputStream in) throws ParserConfigurationException, SAXException, IOException {
- SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
- parser.parse(in, this);
- return (ITocContribution[])contributions.toArray(new ITocContribution[contributions.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
- */
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- if (qName.equals("tocContribution")) { //$NON-NLS-1$
- handleTocContribution(attributes);
- }
- else if (qName.equals("toc")) { //$NON-NLS-1$
- handleToc(attributes);
- }
- else if (qName.equals("topic")) { //$NON-NLS-1$
- handleTopic(attributes);
- }
- else if (qName.equals("filter")) { //$NON-NLS-1$
- handleFilter(attributes);
- }
- else if (qName.equals("include")) { //$NON-NLS-1$
- handleInclude(attributes);
- }
- else if (qName.equals("anchor")) { //$NON-NLS-1$
- handleAnchor(attributes);
- }
- else if (qName.equals("extraDoc")) { //$NON-NLS-1$
- handleExtraDoc(attributes);
- }
- }
+ private NodeReader reader;
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
- */
- public void endElement(String uri, String localName, String qName) throws SAXException {
- if (qName.equals("tocContribution") //$NON-NLS-1$
- || qName.equals("toc") //$NON-NLS-1$
- || qName.equals("topic") //$NON-NLS-1$
- || qName.equals("filter")) { //$NON-NLS-1$
- stack.pop();
- }
- }
-
- private void handleTocContribution(Attributes attr) {
- String id = attr.getValue("id"); //$NON-NLS-1$
- String categoryId = attr.getValue("categoryId"); //$NON-NLS-1$
- String locale = attr.getValue("locale"); //$NON-NLS-1$
- String linkTo = attr.getValue("linkTo"); //$NON-NLS-1$
- boolean isPrimary = false;
- String s = attr.getValue("isPrimary"); //$NON-NLS-1$
- if (s != null && Boolean.toString(true).equals(s)) {
- isPrimary = true;
- }
- TocContribution contribution = new TocContribution(id, categoryId, locale, null, linkTo, isPrimary, null);
- contributions.add(contribution);
- stack.push(contribution);
- }
-
- private void handleToc(Attributes attr) {
- String label = attr.getValue("label"); //$NON-NLS-1$
- String topic = attr.getValue("topic"); //$NON-NLS-1$
- Toc toc = new Toc(label, topic);
- TocContribution contribution = (TocContribution)stack.peek();
- contribution.setToc(toc);
- toc.setTocContribution(contribution);
- stack.push(toc);
- }
-
- private void handleTopic(Attributes attr) {
- String label = attr.getValue("label"); //$NON-NLS-1$
- String href = attr.getValue("href"); //$NON-NLS-1$
- Topic topic = new Topic(href, label);
- Node node = (Node)stack.peek();
- node.addChild(topic);
- stack.push(topic);
- }
-
- private void handleFilter(Attributes attr) {
- String expression = attr.getValue("expression"); //$NON-NLS-1$
- Filter filter = new Filter(expression);
- Node node = (Node)stack.peek();
- node.addChild(filter);
- stack.push(filter);
- }
-
- private void handleInclude(Attributes attr) {
- String target = attr.getValue("target"); //$NON-NLS-1$
- Include include = new Include(target);
- Node node = (Node)stack.peek();
- node.addChild(include);
- }
-
- private void handleAnchor(Attributes attr) {
- String id = attr.getValue("id"); //$NON-NLS-1$
- Anchor anchor = new Anchor(id);
- Node node = (Node)stack.peek();
- node.addChild(anchor);
- }
-
- private void handleExtraDoc(Attributes attr) {
- String href = attr.getValue("href"); //$NON-NLS-1$
- TocContribution contribution = (TocContribution)stack.peek();
- contribution.addExtraDocument(href);
+ public TocContribution[] parse(InputStream in) throws ParserConfigurationException, SAXException, IOException {
+ if (reader == null) {
+ reader = new NodeReader();
+ }
+ Node root = reader.read(in);
+ Node[] children = root.getChildren();
+ TocContribution[] contributions = new TocContribution[children.length];
+ for (int i=0;i<children.length;++i) {
+ Node node = children[i];
+ Node[] contribChildren = node.getChildren();
+ String[] extraDocuments = new String[contribChildren.length - 1];
+ for (int j=0;j<extraDocuments.length;++j) {
+ extraDocuments[j] = contribChildren[j + 1].getAttribute("href"); //$NON-NLS-1$
+ }
+ TocContribution contribution = new TocContribution();
+ contribution.setCategoryId(node.getAttribute("categoryId")); //$NON-NLS-1$
+ contribution.setContributorId(node.getAttribute("contributorId")); //$NON-NLS-1$
+ contribution.setExtraDocuments(extraDocuments);
+ contribution.setId(node.getAttribute("id")); //$NON-NLS-1$
+ contribution.setLocale(node.getAttribute("locale")); //$NON-NLS-1$
+ contribution.setPrimary("true".equals(node.getAttribute("isPrimary"))); //$NON-NLS-1$//$NON-NLS-2$
+ contribution.setToc(contribChildren[0]);
+ contributions[i] = contribution;
+ }
+ return contributions;
}
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocProvider.java b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocProvider.java
index 9f3c4928c..a1b6bc7fd 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocProvider.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/base/remote/RemoteTocProvider.java
@@ -17,7 +17,7 @@ import java.net.URL;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.help.AbstractTocProvider;
-import org.eclipse.help.ITocContribution;
+import org.eclipse.help.TocContribution;
import org.eclipse.help.internal.base.HelpBasePlugin;
/*
@@ -44,7 +44,7 @@ public class RemoteTocProvider extends AbstractTocProvider {
/* (non-Javadoc)
* @see org.eclipse.help.AbstractTocProvider#getTocContributions(java.lang.String)
*/
- public ITocContribution[] getTocContributions(String locale) {
+ public TocContribution[] getTocContributions(String locale) {
if (RemoteHelp.isEnabled()) {
InputStream in = null;
try {
@@ -74,6 +74,6 @@ public class RemoteTocProvider extends AbstractTocProvider {
}
}
}
- return new ITocContribution[0];
+ return new TocContribution[0];
}
}
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java b/org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java
index 38b442f32..df59211e2 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/protocols/HelpURLConnection.java
@@ -27,7 +27,6 @@ import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IProduct;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.base.HelpBasePlugin;
import org.eclipse.help.internal.base.remote.RemoteHelp;
import org.eclipse.help.internal.util.ResourceLocator;
@@ -89,9 +88,6 @@ public class HelpURLConnection extends URLConnection {
parseQuery();
setDefaultUseCaches(isCacheable());
- if (HelpPlugin.DEBUG_PROTOCOLS) {
- System.out.println("HelpURLConnection: url=" + url); //$NON-NLS-1$
- }
}
/**
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/IndexingOperation.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/IndexingOperation.java
index 928919db0..aa06a377d 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/IndexingOperation.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/IndexingOperation.java
@@ -30,8 +30,8 @@ import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.help.IToc;
-import org.eclipse.help.ITocContribution;
import org.eclipse.help.ITopic;
+import org.eclipse.help.TocContribution;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.base.HelpBasePlugin;
import org.eclipse.help.internal.base.HelpBaseResources;
@@ -466,7 +466,7 @@ class IndexingOperation {
for (int j = 0; j < topics.length; j++) {
add(topics[j], hrefs);
}
- ITocContribution contrib = tocs[i].getTocContribution();
+ TocContribution contrib = tocs[i].getTocContribution();
String[] extraDocs = contrib.getExtraDocuments();
for (int j=0;j<extraDocs.length;++j) {
add(extraDocs[j], hrefs);
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/LocalSearchManager.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/LocalSearchManager.java
index 74e1f626b..e86da0931 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/LocalSearchManager.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/LocalSearchManager.java
@@ -34,7 +34,6 @@ import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.IHelpResource;
import org.eclipse.help.internal.HelpPlugin;
-import org.eclipse.help.internal.ITocsChangedListener;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.base.HelpBasePlugin;
import org.eclipse.help.internal.search.IndexingOperation.IndexingException;
@@ -45,7 +44,7 @@ import org.osgi.framework.Bundle;
/*
* Manages indexing and searching for all local help content.
*/
-public class LocalSearchManager implements ITocsChangedListener {
+public class LocalSearchManager {
private static final String SEARCH_PARTICIPANT_XP_FULLNAME = "org.eclipse.help.base.luceneSearchParticipants"; //$NON-NLS-1$
private static final String SEARCH_PARTICIPANT_XP_NAME = "searchParticipant"; //$NON-NLS-1$
@@ -142,14 +141,6 @@ public class LocalSearchManager implements ITocsChangedListener {
}
/**
- * Constructs a Search manager.
- */
- public LocalSearchManager() {
- super();
- HelpPlugin.getDefault().addTocsChangedListener(this);
- }
-
- /**
* Converts the given Hits object into a List of raw SearchHits.
* Hits objects are immutable and can't be instantiated from outside
* Lucene.
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSetManager.java b/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSetManager.java
index db473d672..c03f2a437 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSetManager.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/workingset/WorkingSetManager.java
@@ -35,7 +35,6 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.internal.HelpPlugin;
-import org.eclipse.help.internal.ITocsChangedListener;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.base.HelpBasePlugin;
import org.w3c.dom.Document;
@@ -51,8 +50,7 @@ import org.xml.sax.SAXException;
*
* @since 2.1
*/
-public class WorkingSetManager implements IHelpWorkingSetManager,
- ITocsChangedListener {
+public class WorkingSetManager implements IHelpWorkingSetManager {
// Working set persistence
private static final String WORKING_SET_STATE_FILENAME = "workingsets.xml"; //$NON-NLS-1$
@@ -72,7 +70,6 @@ public class WorkingSetManager implements IHelpWorkingSetManager,
*/
public WorkingSetManager() {
restoreState();
- HelpPlugin.getDefault().addTocsChangedListener(this);
}
public AdaptableTocsArray getRoot() {
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/xhtml/DynamicXHTMLProcessor.java b/org.eclipse.help.base/src/org/eclipse/help/internal/xhtml/DynamicXHTMLProcessor.java
index f08147c90..9d31abf99 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/xhtml/DynamicXHTMLProcessor.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/xhtml/DynamicXHTMLProcessor.java
@@ -19,7 +19,7 @@ import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import org.eclipse.core.runtime.content.IContentDescriber;
-import org.eclipse.help.internal.dynamic.DocumentProcessorHandler;
+import org.eclipse.help.internal.dynamic.NodeHandler;
import org.eclipse.help.internal.dynamic.ExtensionHandler;
import org.eclipse.help.internal.dynamic.FilterHandler;
import org.eclipse.help.internal.dynamic.IncludeHandler;
@@ -47,7 +47,7 @@ public class DynamicXHTMLProcessor {
if (isXHTML) {
if (filter) {
if (xmlProcessor == null) {
- xmlProcessor = new XMLProcessor(new DocumentProcessorHandler[] {
+ xmlProcessor = new XMLProcessor(new NodeHandler[] {
new IncludeHandler(locale),
new ExtensionHandler(locale),
new XHTMLCharsetHandler(),
@@ -57,7 +57,7 @@ public class DynamicXHTMLProcessor {
return xmlProcessor.process(buf, href);
}
if (xmlProcessorNoFilter == null) {
- xmlProcessorNoFilter = new XMLProcessor(new DocumentProcessorHandler[] {
+ xmlProcessorNoFilter = new XMLProcessor(new NodeHandler[] {
new IncludeHandler(locale),
new ExtensionHandler(locale),
new XHTMLCharsetHandler()
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/xhtml/XHTMLCharsetHandler.java b/org.eclipse.help.base/src/org/eclipse/help/internal/xhtml/XHTMLCharsetHandler.java
index 2c778a2f5..5a6a672e3 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/xhtml/XHTMLCharsetHandler.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/xhtml/XHTMLCharsetHandler.java
@@ -11,14 +11,14 @@
package org.eclipse.help.internal.xhtml;
import org.eclipse.help.Node;
-import org.eclipse.help.internal.dynamic.DocumentProcessorHandler;
+import org.eclipse.help.internal.dynamic.NodeHandler;
/*
* Converts the charset in XHTML meta tag to UTF-8. This is the encoding
* output by the XMLProcessor, and we need the charset in the meta tags
* to match, otherwise browsers will be confused.
*/
-public class XHTMLCharsetHandler extends DocumentProcessorHandler {
+public class XHTMLCharsetHandler extends NodeHandler {
private static final String ELEMENT_META = "meta"; //$NON-NLS-1$
private static final String ATTRIBUTE_CONTENT = "content"; //$NON-NLS-1$
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/HelpUIPlugin.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/HelpUIPlugin.java
index 1af1e2fc2..8cf48d97d 100644
--- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/HelpUIPlugin.java
+++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/HelpUIPlugin.java
@@ -58,19 +58,6 @@ public class HelpUIPlugin extends AbstractUIPlugin {
}
/**
- * Logs a Warning message with an exception. Note that the message should already be localized
- * to proper local. ie: Resources.getString() should already have been called
- */
- public static synchronized void logWarning(String message) {
- if (HelpPlugin.DEBUG) {
- if (message == null)
- message = ""; //$NON-NLS-1$
- Status warningStatus = new Status(IStatus.WARNING, PLUGIN_ID, IStatus.OK, message, null);
- HelpPlugin.getDefault().getLog().log(warningStatus);
- }
- }
-
- /**
* Provides access to singleton
*
* @return HelpUIPlugin
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/StyledLineWrapper.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/StyledLineWrapper.java
index 674f0972a..c0fe69b1c 100644
--- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/StyledLineWrapper.java
+++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/StyledLineWrapper.java
@@ -10,16 +10,29 @@
*******************************************************************************/
package org.eclipse.help.ui.internal;
-import com.ibm.icu.text.BreakIterator;
import java.util.ArrayList;
import java.util.Iterator;
-import org.eclipse.help.internal.context.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.custom.*;
-import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledTextContent;
+import org.eclipse.swt.custom.TextChangeListener;
+import org.eclipse.swt.graphics.Drawable;
+import org.eclipse.swt.graphics.GC;
+
+import com.ibm.icu.text.BreakIterator;
public class StyledLineWrapper implements StyledTextContent {
+
+ /**
+ * Internal representation of &lt;b&gt; - unlikely to occur in a text
+ */
+ public static final String BOLD_CLOSE_TAG = "</@#$b>"; //$NON-NLS-1$
+ /**
+ * Internal representation of &lt;b&gt; - unlikely to occur in a text
+ */
+ public static final String BOLD_TAG = "<@#$b>"; //$NON-NLS-1$
+
private Drawable drawable;
/** Lines after splitting */
@@ -264,14 +277,14 @@ public class StyledLineWrapper implements StyledTextContent {
StyleRange style = new StyleRange();
style.fontStyle = SWT.BOLD;
// the index of the starting style in styled text
- int start = text.indexOf(ContextsNode.BOLD_TAG, offset);
+ int start = text.indexOf(BOLD_TAG, offset);
if (start == -1)
break;
String prefix = getUnstyledText(text.substring(0, start));
style.start = prefix.length();
// the index of the ending style in styled text
offset = start + 1;
- int end = text.indexOf(ContextsNode.BOLD_CLOSE_TAG, offset);
+ int end = text.indexOf(BOLD_CLOSE_TAG, offset);
if (end == -1)
break;
prefix = getUnstyledText(text.substring(0, end));
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/search/InfoCenterPage.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/search/InfoCenterPage.java
index 604467d6a..5b8de45d9 100644
--- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/search/InfoCenterPage.java
+++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/search/InfoCenterPage.java
@@ -27,10 +27,9 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.help.INode;
import org.eclipse.help.IToc;
-import org.eclipse.help.ITocContribution;
import org.eclipse.help.ITopic;
+import org.eclipse.help.TocContribution;
import org.eclipse.help.internal.workingset.AdaptableHelpResource;
import org.eclipse.help.internal.workingset.AdaptableTocsArray;
import org.eclipse.help.internal.workingset.WorkingSet;
@@ -307,7 +306,7 @@ public class InfoCenterPage extends RootScopePage {
for (int i = 0; i < engines.getLength(); i++) {
final Node node = engines.item(i);
IToc toc = new IToc() {
- public ITocContribution getTocContribution() {
+ public TocContribution getTocContribution() {
return null;
}
public ITopic[] getTopics() {
@@ -324,12 +323,6 @@ public class InfoCenterPage extends RootScopePage {
return node.getAttributes().getNamedItem("label") //$NON-NLS-1$
.getNodeValue();
}
- public INode[] getChildren() {
- return new INode[0];
- }
- public INode getParent() {
- return null;
- }
};
list.add(toc);
}
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/util/ErrorUtil.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/util/ErrorUtil.java
index dd9a1013a..3d00a1574 100644
--- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/util/ErrorUtil.java
+++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/util/ErrorUtil.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.help.ui.internal.util;
-import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.base.util.IErrorUtil;
import org.eclipse.help.ui.internal.Messages;
import org.eclipse.jface.dialogs.MessageDialog;
@@ -74,9 +73,6 @@ public class ErrorUtil implements IErrorUtil {
shell = new Shell();
}
MessageDialog.openInformation(shell, title, msg);
- if (HelpPlugin.DEBUG) {
- System.out.println(msg);
- }
}
/**
diff --git a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/EngineTypeDescriptor.java b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/EngineTypeDescriptor.java
index d3130c192..e321a0e31 100644
--- a/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/EngineTypeDescriptor.java
+++ b/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/EngineTypeDescriptor.java
@@ -12,10 +12,15 @@ package org.eclipse.help.ui.internal.views;
import java.util.Dictionary;
-import org.eclipse.core.runtime.*;
-import org.eclipse.help.search.*;
-import org.eclipse.help.ui.*;
-import org.eclipse.help.ui.internal.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.help.search.ISearchEngine;
+import org.eclipse.help.search.ISearchScope;
+import org.eclipse.help.ui.ISearchScopeFactory;
+import org.eclipse.help.ui.RootScopePage;
+import org.eclipse.help.ui.internal.HelpUIPlugin;
+import org.eclipse.help.ui.internal.HelpUIResources;
+import org.eclipse.help.ui.internal.IHelpUIConstants;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
@@ -97,7 +102,7 @@ public class EngineTypeDescriptor {
return (ISearchEngine)obj;
}
catch (CoreException e) {
- HelpUIPlugin.logWarning("Engine " + eclass + " cannot be instantiated"); //$NON-NLS-1$ //$NON-NLS-2$
+ HelpUIPlugin.logError("Engine " + eclass + " cannot be instantiated", null); //$NON-NLS-1$ //$NON-NLS-2$
}
}
return null;
@@ -114,7 +119,7 @@ public class EngineTypeDescriptor {
}
}
catch (CoreException e) {
- HelpUIPlugin.logWarning("Scope factory " + fclass + " cannot be instantiated"); //$NON-NLS-1$ //$NON-NLS-2$
+ HelpUIPlugin.logError("Scope factory " + fclass + " cannot be instantiated", null); //$NON-NLS-1$ //$NON-NLS-2$
}
}
}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/IndexData.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/IndexData.java
index 0ab917f77..b47759866 100644
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/IndexData.java
+++ b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/data/IndexData.java
@@ -14,6 +14,7 @@ package org.eclipse.help.internal.webapp.data;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletContext;
@@ -23,8 +24,8 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.help.IIndex;
import org.eclipse.help.IIndexEntry;
import org.eclipse.help.ITopic;
+import org.eclipse.help.Node;
import org.eclipse.help.internal.HelpPlugin;
-import org.eclipse.help.internal.Node;
import org.eclipse.help.internal.base.HelpBasePlugin;
import org.eclipse.help.internal.index.Index;
import org.eclipse.help.internal.index.IndexEntry;
@@ -385,7 +386,7 @@ public class IndexData extends ActivitiesData {
for (int i=0;i<entries.length;++i) {
IndexEntry entry = extractEnabled(entries[i]);
if (entry != null) {
- enabledIndex.addChild(entry);
+ enabledIndex.appendChild(entry);
}
}
return enabledIndex;
@@ -416,8 +417,12 @@ public class IndexData extends ActivitiesData {
}
if (!enabledChildren.isEmpty()) {
- IndexEntry newEntry = new IndexEntry(entry.getKeyword());
- newEntry.addChildren((Node[])enabledChildren.toArray(new Node[enabledChildren.size()]));
+ IndexEntry newEntry = new IndexEntry();
+ newEntry.setKeyword(entry.getKeyword());
+ Iterator iter = enabledChildren.iterator();
+ while (iter.hasNext()) {
+ newEntry.appendChild((Node)iter.next());
+ }
return newEntry;
}
return null;
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ContextSerializer.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ContextSerializer.java
deleted file mode 100644
index 0eed1d195..000000000
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ContextSerializer.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.webapp.servlet;
-
-import org.eclipse.help.IContext;
-import org.eclipse.help.IHelpResource;
-
-/*
- * Serializes the a single complete IContext and id into XML, so that it
- * can be transmitted across the network and reconstructed on the other side
- * for remote help.
- */
-public class ContextSerializer {
-
- public static String serialize(IContext context, String id) {
- StringBuffer buf = new StringBuffer();
- buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
- buf.append("<context id=\"" + XMLGenerator.xmlEscape(id) + "\">\n"); //$NON-NLS-1$ //$NON-NLS-2$
- serialize(context.getText(), buf, " "); //$NON-NLS-1$
- IHelpResource[] topics = context.getRelatedTopics();
- for (int i=0;i<topics.length;++i) {
- serialize(topics[i], buf, " "); //$NON-NLS-1$
- }
- buf.append("</context>\n"); //$NON-NLS-1$
- return buf.toString();
- }
-
- private static void serialize(String description, StringBuffer buf, String indent) {
- buf.append(indent + "<description>"); //$NON-NLS-1$
- buf.append(XMLGenerator.xmlEscape(description));
- buf.append(indent + "</description>\n"); //$NON-NLS-1$
- }
-
- private static void serialize(IHelpResource topic, StringBuffer buf, String indent) {
- buf.append(indent + "<topic"); //$NON-NLS-1$
- if (topic.getHref() != null) {
- buf.append('\n' + indent + " href=\"" + XMLGenerator.xmlEscape(topic.getHref()) + '"'); //$NON-NLS-1$
- }
- if (topic.getLabel() != null) {
- buf.append('\n' + indent + " label=\"" + XMLGenerator.xmlEscape(topic.getLabel()) + '"'); //$NON-NLS-1$
- }
- buf.append(">\n"); //$NON-NLS-1$
- buf.append(indent + "</topic>\n"); //$NON-NLS-1$
- }
-}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ContextServlet.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ContextServlet.java
index a9a82c5e3..f1d3a4718 100644
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ContextServlet.java
+++ b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ContextServlet.java
@@ -19,8 +19,9 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.eclipse.help.HelpSystem;
-import org.eclipse.help.IContext;
+import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.context.Context;
+import org.eclipse.help.internal.dynamic.NodeWriter;
import org.eclipse.help.internal.webapp.data.UrlUtil;
/*
@@ -33,7 +34,8 @@ public class ContextServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final String PARAMETER_ID = "id"; //$NON-NLS-1$
- private static Map localeAndId2Response = new WeakHashMap();
+ private Map responseByLocaleAndId;
+ private NodeWriter writer;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
@@ -43,12 +45,15 @@ public class ContextServlet extends HttpServlet {
String id = req.getParameter(PARAMETER_ID);
if (id != null) {
String localeAndId = locale + id;
- String response = (String)localeAndId2Response.get(localeAndId);
+ if (responseByLocaleAndId == null) {
+ responseByLocaleAndId = new WeakHashMap();
+ }
+ String response = (String)responseByLocaleAndId.get(localeAndId);
if (response == null) {
- IContext context = HelpSystem.getContext(id, locale);
+ Context context = HelpPlugin.getContextManager().getContext(id, locale);
if (context != null) {
- response = ContextSerializer.serialize(context, id);
- localeAndId2Response.put(localeAndId, response);
+ response = serialize(context, id);
+ responseByLocaleAndId.put(localeAndId, response);
}
}
if (response != null) {
@@ -62,4 +67,14 @@ public class ContextServlet extends HttpServlet {
resp.sendError(400); // bad request; missing parameter
}
}
+
+ private String serialize(Context context, String id) {
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
+ if (writer == null) {
+ writer = new NodeWriter();
+ }
+ writer.write(context, buf, true, " ", true); //$NON-NLS-1$
+ return buf.toString();
+ }
}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ExtensionSerializer.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ExtensionSerializer.java
deleted file mode 100644
index 649ec68d6..000000000
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ExtensionSerializer.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.webapp.servlet;
-
-import org.eclipse.help.IContentExtension;
-
-public class ExtensionSerializer {
-
- public static String serialize(IContentExtension[] extensions) {
- StringBuffer buf = new StringBuffer();
- buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
- buf.append("<contentExtensions>\n"); //$NON-NLS-1$
- for (int i=0;i<extensions.length;++i) {
- serialize(extensions[i], buf, " "); //$NON-NLS-1$
- }
- buf.append("</contentExtensions>\n"); //$NON-NLS-1$
- return buf.toString();
- }
-
- private static void serialize(IContentExtension ext, StringBuffer buf, String indent) {
- buf.append(indent + "<contentExtension"); //$NON-NLS-1$
- if (ext.getContent() != null) {
- buf.append('\n' + indent + " content=\"" + XMLGenerator.xmlEscape(ext.getContent()) + '"'); //$NON-NLS-1$
- }
- if (ext.getPath() != null) {
- buf.append('\n' + indent + " path=\"" + XMLGenerator.xmlEscape(ext.getPath()) + '"'); //$NON-NLS-1$
- }
- buf.append('\n' + indent + " type=\"" + ext.getType() + '"'); //$NON-NLS-1$
- buf.append(">\n"); //$NON-NLS-1$
- buf.append(indent + "</contentExtension>\n"); //$NON-NLS-1$
- }
-}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ExtensionServlet.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ExtensionServlet.java
index 208004e5f..5464a247c 100644
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ExtensionServlet.java
+++ b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/ExtensionServlet.java
@@ -19,8 +19,9 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.eclipse.help.IContentExtension;
import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.dynamic.NodeWriter;
+import org.eclipse.help.internal.extension.ContentExtension;
import org.eclipse.help.internal.webapp.data.UrlUtil;
/*
@@ -32,7 +33,8 @@ import org.eclipse.help.internal.webapp.data.UrlUtil;
public class ExtensionServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
- private static Map locale2Response = new WeakHashMap();
+ private Map responseByLocale;
+ private NodeWriter writer;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
@@ -40,12 +42,29 @@ public class ExtensionServlet extends HttpServlet {
req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
- String response = (String)locale2Response.get(locale);
+ if (responseByLocale == null) {
+ responseByLocale = new WeakHashMap();
+ }
+ String response = (String)responseByLocale.get(locale);
if (response == null) {
- IContentExtension[] extensions = HelpPlugin.getContentExtensionManager().getExtensions(locale);
- response = ExtensionSerializer.serialize(extensions);
- locale2Response.put(locale, response);
+ ContentExtension[] extensions = HelpPlugin.getContentExtensionManager().getExtensions(locale);
+ response = serialize(extensions);
+ responseByLocale.put(locale, response);
}
resp.getWriter().write(response);
}
+
+ private String serialize(ContentExtension[] contributions) {
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
+ buf.append("<contentExtensions>\n"); //$NON-NLS-1$
+ for (int i = 0; i < contributions.length; ++i) {
+ if (writer == null) {
+ writer = new NodeWriter();
+ }
+ writer.write(contributions[i], buf, true, " ", true); //$NON-NLS-1$
+ }
+ buf.append("</contentExtensions>\n"); //$NON-NLS-1$
+ return buf.toString();
+ }
}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/IndexSerializer.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/IndexSerializer.java
deleted file mode 100644
index 17bfe19e5..000000000
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/IndexSerializer.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.webapp.servlet;
-
-import org.eclipse.help.IIndex;
-import org.eclipse.help.IIndexContribution;
-import org.eclipse.help.IIndexEntry;
-import org.eclipse.help.INode;
-import org.eclipse.help.ITopic;
-
-/*
- * Serializes the complete contents of IIndexContributions into XML, so that it
- * can be transmitted across the network and reconstructed on the other side
- * for remote help.
- */
-public class IndexSerializer {
-
- public static String serialize(IIndexContribution[] contributions, String locale) {
- StringBuffer buf = new StringBuffer();
- buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
- buf.append("<indexContributions>\n"); //$NON-NLS-1$
- for (int i = 0; i < contributions.length; ++i) {
- serialize(contributions[i], buf, " "); //$NON-NLS-1$
- }
- buf.append("</indexContributions>\n"); //$NON-NLS-1$
- return buf.toString();
- }
-
- private static void serialize(IIndexContribution contribution, StringBuffer buf, String indent) {
- buf.append(indent + "<indexContribution"); //$NON-NLS-1$
- if (contribution.getId() != null) {
- buf.append('\n' + indent + " id=\"" + XMLGenerator.xmlEscape(contribution.getId()) + '"'); //$NON-NLS-1$
- }
- if (contribution.getLocale() != null) {
- buf.append('\n' + indent + " locale=\"" + XMLGenerator.xmlEscape(contribution.getLocale()) + '"'); //$NON-NLS-1$
- }
- buf.append(">\n"); //$NON-NLS-1$
- serialize(contribution.getIndex(), buf, indent + " "); //$NON-NLS-1$
- buf.append(indent + "</indexContribution>\n"); //$NON-NLS-1$
- }
-
- private static void serialize(IIndex index, StringBuffer buf, String indent) {
- buf.append(indent + "<index>\n"); //$NON-NLS-1$
- serialize(index.getChildren(), buf, indent + " "); //$NON-NLS-1$
- buf.append(indent + "</index>\n"); //$NON-NLS-1$
- }
-
- private static void serialize(INode[] nodes, StringBuffer buf, String indent) {
- for (int i = 0; i < nodes.length; ++i) {
- INode node = nodes[i];
- if (node instanceof IIndexEntry) {
- serialize((IIndexEntry) node, buf, indent);
- } else if (node instanceof ITopic) {
- serialize((ITopic) node, buf, indent);
- } else if (node instanceof IIndex) {
- serialize((IIndex) node, buf, indent);
- }
- }
- }
-
- private static void serialize(IIndexEntry entry, StringBuffer buf, String indent) {
- buf.append(indent + "<entry"); //$NON-NLS-1$
- if (entry.getKeyword() != null) {
- buf.append('\n' + indent + " keyword=\"" + XMLGenerator.xmlEscape(entry.getKeyword()) + '"'); //$NON-NLS-1$
- }
- buf.append(">\n"); //$NON-NLS-1$
- serialize(entry.getChildren(), buf, indent + " "); //$NON-NLS-1$
- buf.append(indent + "</entry>\n"); //$NON-NLS-1$
- }
-
- private static void serialize(ITopic topic, StringBuffer buf, String indent) {
- buf.append(indent + "<topic"); //$NON-NLS-1$
- if (topic.getHref() != null) {
- buf.append('\n' + indent + " href=\"" + XMLGenerator.xmlEscape(topic.getHref()) + '"'); //$NON-NLS-1$
- }
- if (topic.getLabel() != null) {
- buf.append('\n' + indent + " label=\"" + XMLGenerator.xmlEscape(topic.getLabel()) + '"'); //$NON-NLS-1$
- }
- buf.append(">\n"); //$NON-NLS-1$
- serialize(topic.getChildren(), buf, indent + " "); //$NON-NLS-1$
- buf.append(indent + "</topic>\n"); //$NON-NLS-1$
- }
-}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/IndexServlet.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/IndexServlet.java
index 098367641..483ad2cd2 100644
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/IndexServlet.java
+++ b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/IndexServlet.java
@@ -19,8 +19,9 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.eclipse.help.IIndexContribution;
+import org.eclipse.help.IndexContribution;
import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.dynamic.NodeWriter;
import org.eclipse.help.internal.webapp.data.UrlUtil;
/*
@@ -35,7 +36,8 @@ import org.eclipse.help.internal.webapp.data.UrlUtil;
public class IndexServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
- private static Map locale2Response = new WeakHashMap();
+ private Map responseByLocale;
+ private NodeWriter writer;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
@@ -43,12 +45,29 @@ public class IndexServlet extends HttpServlet {
req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
- String response = (String)locale2Response.get(locale);
+ if (responseByLocale == null) {
+ responseByLocale = new WeakHashMap();
+ }
+ String response = (String)responseByLocale.get(locale);
if (response == null) {
- IIndexContribution[] contributions = HelpPlugin.getIndexManager().getIndexContributions(locale);
- response = IndexSerializer.serialize(contributions, locale);
- locale2Response.put(locale, response);
+ IndexContribution[] contributions = HelpPlugin.getIndexManager().getIndexContributions(locale);
+ response = serialize(contributions, locale);
+ responseByLocale.put(locale, response);
}
resp.getWriter().write(response);
}
+
+ public String serialize(IndexContribution[] contributions, String locale) {
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
+ buf.append("<indexContributions>\n"); //$NON-NLS-1$
+ for (int i=0;i<contributions.length;++i) {
+ if (writer == null) {
+ writer = new NodeWriter();
+ }
+ writer.write(contributions[i], buf, true, " ", true); //$NON-NLS-1$
+ }
+ buf.append("</indexContributions>\n"); //$NON-NLS-1$
+ return buf.toString();
+ }
}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchSerializer.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchSerializer.java
deleted file mode 100644
index d044bcd5e..000000000
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchSerializer.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.webapp.servlet;
-
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.eclipse.help.internal.search.SearchHit;
-
-/*
- * Serializes a set of search hits into XML, so that it can be transmitted
- * across the network and reconstructed on the other side for remote help.
- */
-public class SearchSerializer {
-
- public static String serialize(Collection results) {
- StringBuffer buf = new StringBuffer();
- buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
- buf.append("<searchHits>\n"); //$NON-NLS-1$
- Iterator iter = results.iterator();
- while (iter.hasNext()) {
- SearchHit hit = (SearchHit)iter.next();
- serialize(hit, buf, " "); //$NON-NLS-1$
- }
- buf.append("</searchHits>\n"); //$NON-NLS-1$
- return buf.toString();
- }
-
- private static void serialize(SearchHit hit, StringBuffer buf, String indent) {
- buf.append(indent + "<hit"); //$NON-NLS-1$
- if (hit.getHref() != null) {
- buf.append('\n' + indent + " href=\"" + XMLGenerator.xmlEscape(hit.getHref()) + '"'); //$NON-NLS-1$
- }
- if (hit.getLabel() != null) {
- buf.append('\n' + indent + " label=\"" + XMLGenerator.xmlEscape(hit.getLabel()) + '"'); //$NON-NLS-1$
- }
- if (hit.isPotentialHit()) {
- buf.append('\n' + indent + " isPotentialHit=\"true\""); //$NON-NLS-1$
- }
- buf.append('\n' + indent + " score=\"" + hit.getScore() + '"'); //$NON-NLS-1$
- buf.append(">\n"); //$NON-NLS-1$
-
- String summary = hit.getSummary();
- if (summary != null) {
- serialize(summary, buf, indent + " "); //$NON-NLS-1$
- }
- buf.append(indent + "</hit>\n"); //$NON-NLS-1$
- }
-
- private static void serialize(String summary, StringBuffer buf, String indent) {
- buf.append(indent + "<summary>"); //$NON-NLS-1$
- buf.append(XMLGenerator.xmlEscape(summary));
- buf.append("</summary>\n"); //$NON-NLS-1$
- }
-}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchServlet.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchServlet.java
index 714124e28..f12546333 100644
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchServlet.java
+++ b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/SearchServlet.java
@@ -14,6 +14,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
@@ -25,6 +26,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.search.ISearchHitCollector;
import org.eclipse.help.internal.search.ISearchQuery;
+import org.eclipse.help.internal.search.SearchHit;
import org.eclipse.help.internal.search.SearchQuery;
import org.eclipse.help.internal.util.URLCoder;
import org.eclipse.help.internal.webapp.data.UrlUtil;
@@ -58,11 +60,51 @@ public class SearchServlet extends HttpServlet {
ISearchQuery query = new SearchQuery(phrase, false, Collections.EMPTY_LIST, locale);
results.clear();
BaseHelpSystem.getSearchManager().search(query, collector, new NullProgressMonitor());
- String response = SearchSerializer.serialize(results);
+ String response = serialize(results);
resp.getWriter().write(response);
}
else {
resp.sendError(400); // bad request; missing parameter
}
}
+
+ public static String serialize(Collection results) {
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
+ buf.append("<searchHits>\n"); //$NON-NLS-1$
+ Iterator iter = results.iterator();
+ while (iter.hasNext()) {
+ SearchHit hit = (SearchHit)iter.next();
+ serialize(hit, buf, " "); //$NON-NLS-1$
+ }
+ buf.append("</searchHits>\n"); //$NON-NLS-1$
+ return buf.toString();
+ }
+
+ private static void serialize(SearchHit hit, StringBuffer buf, String indent) {
+ buf.append(indent + "<hit"); //$NON-NLS-1$
+ if (hit.getHref() != null) {
+ buf.append('\n' + indent + " href=\"" + XMLGenerator.xmlEscape(hit.getHref()) + '"'); //$NON-NLS-1$
+ }
+ if (hit.getLabel() != null) {
+ buf.append('\n' + indent + " label=\"" + XMLGenerator.xmlEscape(hit.getLabel()) + '"'); //$NON-NLS-1$
+ }
+ if (hit.isPotentialHit()) {
+ buf.append('\n' + indent + " isPotentialHit=\"true\""); //$NON-NLS-1$
+ }
+ buf.append('\n' + indent + " score=\"" + hit.getScore() + '"'); //$NON-NLS-1$
+ buf.append(">\n"); //$NON-NLS-1$
+
+ String summary = hit.getSummary();
+ if (summary != null) {
+ serialize(summary, buf, indent + " "); //$NON-NLS-1$
+ }
+ buf.append(indent + "</hit>\n"); //$NON-NLS-1$
+ }
+
+ private static void serialize(String summary, StringBuffer buf, String indent) {
+ buf.append(indent + "<summary>"); //$NON-NLS-1$
+ buf.append(XMLGenerator.xmlEscape(summary));
+ buf.append("</summary>\n"); //$NON-NLS-1$
+ }
}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/TocSerializer.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/TocSerializer.java
deleted file mode 100644
index 0a10bf60f..000000000
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/TocSerializer.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.webapp.servlet;
-
-import org.eclipse.help.IAnchor;
-import org.eclipse.help.IInclude;
-import org.eclipse.help.INode;
-import org.eclipse.help.IToc;
-import org.eclipse.help.ITocContribution;
-import org.eclipse.help.ITopic;
-
-/*
- * Serializes the complete contents of ITocContributions into XML, so that it
- * can be transmitted across the network and reconstructed on the other side
- * for remote help.
- */
-public class TocSerializer {
-
- public static String serialize(ITocContribution[] contributions, String locale) {
- StringBuffer buf = new StringBuffer();
- buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
- buf.append("<tocContributions>\n"); //$NON-NLS-1$
- for (int i = 0; i < contributions.length; ++i) {
- serialize(contributions[i], buf, " "); //$NON-NLS-1$
- }
- buf.append("</tocContributions>\n"); //$NON-NLS-1$
- return buf.toString();
- }
-
- private static void serialize(ITocContribution contribution, StringBuffer buf, String indent) {
- buf.append(indent + "<tocContribution"); //$NON-NLS-1$
- if (contribution.getCategoryId() != null) {
- buf.append('\n' + indent + " categoryId=\"" + XMLGenerator.xmlEscape(contribution.getCategoryId()) + '"'); //$NON-NLS-1$
- }
- if (contribution.getId() != null) {
- buf.append('\n' + indent + " id=\"" + XMLGenerator.xmlEscape(contribution.getId()) + '"'); //$NON-NLS-1$
- }
- if (contribution.getLinkTo() != null) {
- buf.append('\n' + indent + " linkTo=\"" + XMLGenerator.xmlEscape(contribution.getLinkTo()) + '"'); //$NON-NLS-1$
- }
- if (contribution.getLocale() != null) {
- buf.append('\n' + indent + " locale=\"" + XMLGenerator.xmlEscape(contribution.getLocale()) + '"'); //$NON-NLS-1$
- }
- buf.append('\n' + indent + " isPrimary=\"" + contribution.isPrimary() + '"'); //$NON-NLS-1$
- buf.append(">\n"); //$NON-NLS-1$
- serialize(contribution.getToc(), buf, indent + " "); //$NON-NLS-1$
- serialize(contribution.getExtraDocuments(), buf, indent + " "); //$NON-NLS-1$
- buf.append(indent + "</tocContribution>\n"); //$NON-NLS-1$
- }
-
- private static void serialize(IToc toc, StringBuffer buf, String indent) {
- buf.append(indent + "<toc"); //$NON-NLS-1$
- if (toc.getLabel() != null) {
- buf.append('\n' + indent + " label=\"" + XMLGenerator.xmlEscape(toc.getLabel()) + '"'); //$NON-NLS-1$
- }
- ITopic topic = toc.getTopic(null);
- if (topic != null && topic.getHref() != null) {
- buf.append('\n' + indent + " topic=\"" + XMLGenerator.xmlEscape(topic.getHref()) + '"'); //$NON-NLS-1$
- }
- if (toc.getHref() != null) {
- buf.append('\n' + indent + " href=\"" + XMLGenerator.xmlEscape(toc.getHref()) + '"'); //$NON-NLS-1$
- }
- buf.append(">\n"); //$NON-NLS-1$
- serialize(toc.getChildren(), buf, indent + " "); //$NON-NLS-1$
- buf.append(indent + "</toc>\n"); //$NON-NLS-1$
- }
-
- private static void serialize(INode[] nodes, StringBuffer buf, String indent) {
- for (int i = 0; i < nodes.length; ++i) {
- INode node = nodes[i];
- if (node instanceof ITopic) {
- serialize((ITopic) node, buf, indent);
- } else if (node instanceof org.eclipse.help.IFilter) {
- serialize((org.eclipse.help.IFilter) node, buf, indent);
- } else if (node instanceof IAnchor) {
- serialize((IAnchor) node, buf, indent);
- } else if (node instanceof IInclude) {
- serialize((IInclude) node, buf, indent);
- } else if (node instanceof IToc) {
- serialize((IToc) node, buf, indent);
- }
- }
- }
-
- private static void serialize(ITopic topic, StringBuffer buf, String indent) {
- buf.append(indent + "<topic"); //$NON-NLS-1$
- if (topic.getHref() != null) {
- buf.append('\n' + indent + " href=\"" + XMLGenerator.xmlEscape(topic.getHref()) + '"'); //$NON-NLS-1$
- }
- if (topic.getLabel() != null) {
- buf.append('\n' + indent + " label=\"" + XMLGenerator.xmlEscape(topic.getLabel()) + '"'); //$NON-NLS-1$
- }
- buf.append(">\n"); //$NON-NLS-1$
- serialize(topic.getChildren(), buf, indent + " "); //$NON-NLS-1$
- buf.append(indent + "</topic>\n"); //$NON-NLS-1$
- }
-
- private static void serialize(org.eclipse.help.IFilter filter, StringBuffer buf, String indent) {
- if (filter.getExpression() != null) {
- buf.append(indent + "<filter expression=\"" + XMLGenerator.xmlEscape(filter.getExpression()) + "\">\n"); //$NON-NLS-1$ //$NON-NLS-2$
- serialize(filter.getChildren(), buf, indent + " "); //$NON-NLS-1$
- buf.append(indent + "</filter>\n"); //$NON-NLS-1$
- }
- else {
- serialize(filter.getChildren(), buf, indent);
- }
- }
-
- private static void serialize(IAnchor anchor, StringBuffer buf, String indent) {
- if (anchor.getId() != null) {
- buf.append(indent + "<anchor id=\"" + XMLGenerator.xmlEscape(anchor.getId()) + "\"/>\n"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- private static void serialize(IInclude include, StringBuffer buf, String indent) {
- if (include.getTarget() != null) {
- buf.append(indent + "<include target=\"" + XMLGenerator.xmlEscape(include.getTarget()) + "\"/>\n"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- private static void serialize(String[] extraDocs, StringBuffer buf, String indent) {
- for (int i = 0; i < extraDocs.length; ++i) {
- serialize(extraDocs[i], buf, indent);
- }
- }
-
- private static void serialize(String extraDoc, StringBuffer buf, String indent) {
- if (extraDoc != null) {
- buf.append(indent + "<extraDoc href=\"" + XMLGenerator.xmlEscape(extraDoc) + "\"/>\n"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-}
diff --git a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/TocServlet.java b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/TocServlet.java
index deba8f2a3..d874c6295 100644
--- a/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/TocServlet.java
+++ b/org.eclipse.help.webapp/src_servlets/org/eclipse/help/internal/webapp/servlet/TocServlet.java
@@ -19,8 +19,9 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import org.eclipse.help.ITocContribution;
+import org.eclipse.help.TocContribution;
import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.dynamic.NodeWriter;
import org.eclipse.help.internal.webapp.data.UrlUtil;
/*
@@ -35,7 +36,8 @@ import org.eclipse.help.internal.webapp.data.UrlUtil;
public class TocServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
- private static Map locale2Response = new WeakHashMap();
+ private Map responseByLocale;
+ private NodeWriter writer;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
@@ -43,12 +45,29 @@ public class TocServlet extends HttpServlet {
req.setCharacterEncoding("UTF-8"); //$NON-NLS-1$
resp.setContentType("application/xml; charset=UTF-8"); //$NON-NLS-1$
- String response = (String)locale2Response.get(locale);
+ if (responseByLocale == null) {
+ responseByLocale = new WeakHashMap();
+ }
+ String response = (String)responseByLocale.get(locale);
if (response == null) {
- ITocContribution[] contributions = HelpPlugin.getTocManager().getTocContributions(locale);
- response = TocSerializer.serialize(contributions, locale);
- locale2Response.put(locale, response);
+ TocContribution[] contributions = HelpPlugin.getTocManager().getTocContributions(locale);
+ response = serialize(contributions, locale);
+ responseByLocale.put(locale, response);
}
resp.getWriter().write(response);
}
+
+ private String serialize(TocContribution[] contributions, String locale) {
+ StringBuffer buf = new StringBuffer();
+ buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$
+ buf.append("<tocContributions>\n"); //$NON-NLS-1$
+ for (int i = 0; i < contributions.length; ++i) {
+ if (writer == null) {
+ writer = new NodeWriter();
+ }
+ writer.write(contributions[i], buf, true, " ", false); //$NON-NLS-1$
+ }
+ buf.append("</tocContributions>\n"); //$NON-NLS-1$
+ return buf.toString();
+ }
}
diff --git a/org.eclipse.help/META-INF/MANIFEST.MF b/org.eclipse.help/META-INF/MANIFEST.MF
index 0bfca5de6..79ab9e0e3 100644
--- a/org.eclipse.help/META-INF/MANIFEST.MF
+++ b/org.eclipse.help/META-INF/MANIFEST.MF
@@ -8,8 +8,8 @@ Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package: org.eclipse.help,
org.eclipse.help.internal;x-friends:="org.eclipse.help.base,org.eclipse.help.ui,org.eclipse.help.webapp,org.eclipse.ui.intro,org.eclipse.ua.tests",
- org.eclipse.help.internal.context;x-friends:="org.eclipse.help.base,org.eclipse.help.ui,org.eclipse.ua.tests",
- org.eclipse.help.internal.dynamic;x-friends:="org.eclipse.ua.tests,org.eclipse.help.ui,org.eclipse.help.base,org.eclipse.ui.intro",
+ org.eclipse.help.internal.context;x-friends:="org.eclipse.help.base,org.eclipse.help.ui,org.eclipse.ua.tests,org.eclipse.help.webapp",
+ org.eclipse.help.internal.dynamic;x-friends:="org.eclipse.ua.tests,org.eclipse.help.ui,org.eclipse.help.base,org.eclipse.ui.intro,org.eclipse.help.webapp",
org.eclipse.help.internal.extension;x-friends:="org.eclipse.help.webapp,org.eclipse.help.base",
org.eclipse.help.internal.index;x-friends:="org.eclipse.help.webapp,org.eclipse.ua.tests,org.eclipse.help.ui,org.eclipse.help.base",
org.eclipse.help.internal.toc;x-friends:="org.eclipse.help.base,org.eclipse.help.ui,org.eclipse.help.webapp,org.eclipse.ua.tests",
diff --git a/org.eclipse.help/plugin.xml b/org.eclipse.help/plugin.xml
index e6ab82586..58380d469 100644
--- a/org.eclipse.help/plugin.xml
+++ b/org.eclipse.help/plugin.xml
@@ -15,7 +15,7 @@
<extension
point="org.eclipse.help.contexts">
- <contextProvider class="org.eclipse.help.internal.context.ContextsFileProvider"/>
+ <contextProvider class="org.eclipse.help.internal.context.ContextFileProvider"/>
</extension>
<extension
diff --git a/org.eclipse.help/src/org/eclipse/help/AbstractContentExtensionProvider.java b/org.eclipse.help/src/org/eclipse/help/AbstractContentExtensionProvider.java
index 401fb02b8..89a648906 100644
--- a/org.eclipse.help/src/org/eclipse/help/AbstractContentExtensionProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/AbstractContentExtensionProvider.java
@@ -13,30 +13,27 @@ package org.eclipse.help;
import org.eclipse.help.internal.HelpPlugin;
/**
- * <p>
* An <code>AbstractContentExtensionProvider</code> is a mechanism to provide
* arbitrary content extensions (e.g. contributions to anchors or element
* replacements). <code>AbstractContentExtensionProvider</code>s must be
* registered via the <code>org.eclipse.help.contentExtension</code>
* extension point.
- * </p>
- * <p>
- * IMPORTANT: This API is still subject to change in 3.3. In particular, the
- * return type of getContentExtensions() may change.
- * </p>
*
* @since 3.3
*/
public abstract class AbstractContentExtensionProvider {
/**
- * Returns all <code>IContentExtension</code>s for this provider. Providers
- * are free to provide any number of contributions (zero or more).
+ * Returns all extensions for this provider. The document model must
+ * conform to the schema for content extension XML, with the exception that
+ * the <code>content</code> attribute must be a full href with a leading
+ * plug-in id. Providers are free to provide any number of contributions
+ * (zero or more).
*
* @param locale the locale for which to get contributions
* @return all the content extensions for this provider
*/
- public abstract IContentExtension[] getContentExtensions(String locale);
+ public abstract Node[] getContentExtensions(String locale);
/**
* Notifies the platform that the content managed by this provider may
diff --git a/org.eclipse.help/src/org/eclipse/help/AbstractContextProvider.java b/org.eclipse.help/src/org/eclipse/help/AbstractContextProvider.java
index 62d2f897d..48d33a59d 100644
--- a/org.eclipse.help/src/org/eclipse/help/AbstractContextProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/AbstractContextProvider.java
@@ -11,16 +11,10 @@
package org.eclipse.help;
/**
- * <p>
* An <code>AbstractContextProvider</code> is a mechanism to provide arbitrary
* context-sensitive help for any part of the UI. <code>AbstractContextProvider
* </code>s must be registered via the <code>org.eclipse.help.contexts</code>
* extension point.
- * </p>
- * <p>
- * IMPORTANT: This API is still subject to change in 3.3. In particular, the
- * return type of getContext() may change.
- * </p>
*
* @since 3.3
*/
@@ -28,12 +22,13 @@ public abstract class AbstractContextProvider {
/**
* Returns the context-sensitive help content for the UI element with the
- * given context help ID, and for the given locale.
+ * given context help ID, and for the given locale. The document model must
+ * conform to the context-sensitive help XML schema.
*
* @param id the unique context help ID, e.g. "org.my.plugin.my_context_id"
* @return the context help, or <code>null</code> if not available
*/
- public abstract IContext getContext(String id, String locale);
+ public abstract Node getContext(String id, String locale);
/**
* Returns an array of <code>String</code>s containing the ids of the
diff --git a/org.eclipse.help/src/org/eclipse/help/AbstractIndexProvider.java b/org.eclipse.help/src/org/eclipse/help/AbstractIndexProvider.java
index 70d5455f2..5e03802a5 100644
--- a/org.eclipse.help/src/org/eclipse/help/AbstractIndexProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/AbstractIndexProvider.java
@@ -22,13 +22,13 @@ import org.eclipse.help.internal.HelpPlugin;
public abstract class AbstractIndexProvider {
/**
- * Returns all <code>IIndexContribution</code>s for this provider. Providers
+ * Returns all <code>IndexContribution</code>s for this provider. Providers
* are free to provide any number of contributions (zero or more).
*
* @param locale the locale for which to get contributions
* @return all the index contributions for this provider
*/
- public abstract IIndexContribution[] getIndexContributions(String locale);
+ public abstract IndexContribution[] getIndexContributions(String locale);
/**
* Notifies the platform that the content managed by this provider may
diff --git a/org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java b/org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java
index c57d17f57..86d8091a9 100644
--- a/org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/AbstractTocProvider.java
@@ -22,13 +22,13 @@ import org.eclipse.help.internal.HelpPlugin;
public abstract class AbstractTocProvider {
/**
- * Returns all <code>ITocContribution</code>s for this provider. Providers
+ * Returns all <code>TocContribution</code>s for this provider. Providers
* are free to provide any number of contributions (zero or more).
*
* @param locale the locale for which to get contributions
* @return all the contributions for this provider
*/
- public abstract ITocContribution[] getTocContributions(String locale);
+ public abstract TocContribution[] getTocContributions(String locale);
/**
* Notifies the platform that the content managed by this provider may
diff --git a/org.eclipse.help/src/org/eclipse/help/IAnchor.java b/org.eclipse.help/src/org/eclipse/help/IAnchor.java
deleted file mode 100644
index 5e52d527b..000000000
--- a/org.eclipse.help/src/org/eclipse/help/IAnchor.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * 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.help;
-
-/**
- * <p>
- * An anchor represents a location at which content can be added from outside
- * the document.
- * </p>
- * <p>
- * IMPORTANT: This API is still subject to change in 3.3. This interface may be
- * removed in favor of using an untyped model similar to DOM.
- * </p>
- *
- * @since 3.3
- */
-public interface IAnchor extends INode {
-
- /**
- * Returns this anchor's unique identifier.
- *
- * @return the unique identifier for the anchor
- */
- public String getId();
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/IContentExtension.java b/org.eclipse.help/src/org/eclipse/help/IContentExtension.java
deleted file mode 100644
index e2cd723a3..000000000
--- a/org.eclipse.help/src/org/eclipse/help/IContentExtension.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * 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.help;
-
-/**
- * <p>
- * An <code>IContentExtension</code> is an extension or a modification on
- * a user assistance document or part of a document. Different extension
- * types provide different ways to modify or add to a document.
- * </p>
- * <p>
- * IMPORTANT: This API is still subject to change in 3.3. This interface may be
- * removed in favor of using an untyped model similar to DOM.
- * </p>
- *
- * @since 3.3
- */
-public interface IContentExtension {
-
- /**
- * The extension type for anchor contributions, where a content fragment
- * is added into a target anchor identified by a document id and anchor id.
- */
- public static final int CONTRIBUTION = 0;
-
- /**
- * The extension type for content replacement, where one element of a
- * document tree is replaced entirely with an element from another document.
- */
- public static final int REPLACE = 1;
-
- /**
- * Returns a string identifying the content to be used for modifying the
- * document (i.e. what to insert or replace with). For XML files in
- * bundles this has the form <code>/pluginId/path/file.xml#elementId</code>.
- * There is also a shorthand form: <code>/pluginId/path/file.html</code>
- * which will match the contents of the <code>body</code> element of an HTML
- * or XHTML document.
- *
- * @return the path to the content to use for the extension
- */
- public String getContent();
-
- /**
- * Returns a string identifying the target element to be affected by this
- * extension. For example, for XML files in bundles this has the form
- * <code>/pluginId/path/file.xml#elementId</code>.
- *
- * @return the path to the element to be extended
- */
- public String getPath();
-
- /**
- * Returns the extension type. Must be either <code>CONTRIBUTION</code>
- * or <code>REPLACE</code>.
- *
- * @return the extension type
- */
- public int getType();
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/IFilter.java b/org.eclipse.help/src/org/eclipse/help/IFilter.java
deleted file mode 100644
index 3b153730c..000000000
--- a/org.eclipse.help/src/org/eclipse/help/IFilter.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*******************************************************************************
- * 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.help;
-
-/**
- * An <code>IFilter</code> is a content node whose children may be filtered
- * if the filter expression is true.
- *
- * @since 3.3
- */
-public interface IFilter extends INode {
-
- /**
- * <p>
- * Returns the filter's expression. The expression evaluates to either
- * true or false, and determines whether or not the children will be
- * filtered.
- * </p>
- * <p>
- * The general form of the expression is
- * "<code>[name][operator][value]</code>" where <code>name</code> is the
- * name of the property by which to filter, for example <code>os</code> for
- * operating system (see table below for possible values). The
- * <code>operator</code> is either <code>=</code> to denote a match (exact
- * match, case sensitive), or <code>!=</code> to denote does not match. The
- * <code>value</code> is what the property should (or shouldn't) match. For
- * example, for <code>os</code>, one of the possible values is
- * <code>win32</code> (Windows).
- * </p>
- *
- * <table border="1">
- * <tr>
- * <td><b>Property</b></td>
- * <td><b>Meaning</b></td>
- * <td><b>Possible Values</b></td>
- * </tr>
- * <tr>
- * <td><code>os</code></td>
- * <td>operating system</td>
- * <td><code>win32, win32, linux, macosx, aix, solaris, hpux, qnx</code></td>
- * </tr>
- * <tr>
- * <td><code>ws</code></td>
- * <td>windowing system</td>
- * <td><code>win32, motif, gtk, photon, carbon</code></td>
- * </tr>
- * <tr>
- * <td><code>arch</code></td>
- * <td>processor architecture</td>
- * <td><code>x86, x86_64, ia64, ia64_32, ppc, PA_RISC, sparc</code></td>
- * </tr>
- * <tr>
- * <td><code>product</code></td>
- * <td>eclipse product identifier</td>
- * <td>Any product identifier (e.g., for SDK, <code>org.eclipse.sdk.ide</code>)</td>
- * </tr>
- * <tr>
- * <td><code>plugin</code></td>
- * <td>plug-in presence</td>
- * <td>Any plug-in identifier (e.g. <code>org.eclipse.help</code>)</td>
- * </tr>
- * <tr>
- * <td><code>category</code></td>
- * <td>category of activities</td>
- * <td>Any activity category identifier (e.g. for Team category, <code>org.eclipse.categories.teamCategory</code>)</td>
- * </tr>
- * <tr>
- * <td><code>activity</code></td>
- * <td>activity (capability)</td>
- * <td>Any activity identifier (e.g. for CVS Support activity, <code>org.eclipse.team.cvs</code>)</td>
- * </tr>
- * </table>
- *
- * @return the filter expression
- */
- public String getExpression();
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/IInclude.java b/org.eclipse.help/src/org/eclipse/help/IInclude.java
deleted file mode 100644
index 1460ad524..000000000
--- a/org.eclipse.help/src/org/eclipse/help/IInclude.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * 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.help;
-
-/**
- * <p>
- * An include node is a marker to signal that content from another document
- * should be pulled into the document in which the include resides.
- * </p>
- * <p>
- * IMPORTANT: This API is still subject to change in 3.3. This interface may be
- * removed in favor of using an untyped model similar to DOM.
- * </p>
- *
- * @since 3.3
- */
-public interface IInclude extends INode {
-
- /**
- * Returns a reference to the target content to be included. The format of
- * the string depends on the context of the include.
- *
- * @return the include target
- */
- public String getTarget();
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/IIndex.java b/org.eclipse.help/src/org/eclipse/help/IIndex.java
index f58fceddd..bd785cec6 100644
--- a/org.eclipse.help/src/org/eclipse/help/IIndex.java
+++ b/org.eclipse.help/src/org/eclipse/help/IIndex.java
@@ -17,7 +17,7 @@ package org.eclipse.help;
*
* @since 3.2
*/
-public interface IIndex extends INode {
+public interface IIndex {
/**
* Obtains the index entries contained in the index.
diff --git a/org.eclipse.help/src/org/eclipse/help/IIndexContribution.java b/org.eclipse.help/src/org/eclipse/help/IIndexContribution.java
deleted file mode 100644
index cf82038cb..000000000
--- a/org.eclipse.help/src/org/eclipse/help/IIndexContribution.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * 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.help;
-
-/**
- * <p>
- * An <code>IIndexContribution</code> represents a set of index keywords and
- * their metadata.
- * </p>
- * <p>
- * IMPORTANT: This API is still subject to change in 3.3.
- * </p>
- *
- * @since 3.3
- */
-public interface IIndexContribution {
-
- /**
- * Returns a unique identifier for this contribution.
- *
- * @return the contribution's unique identifier
- */
- public String getId();
-
- /**
- * Returns the locale for this contribution.
- *
- * @return the contribution's locale
- */
- public String getLocale();
-
- /**
- * Returns the keyword index data for this contribution.
- *
- * @return the contribution's keyword index data
- */
- public IIndex getIndex();
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/IIndexEntry.java b/org.eclipse.help/src/org/eclipse/help/IIndexEntry.java
index 624ecde25..9f098b336 100644
--- a/org.eclipse.help/src/org/eclipse/help/IIndexEntry.java
+++ b/org.eclipse.help/src/org/eclipse/help/IIndexEntry.java
@@ -17,7 +17,8 @@ package org.eclipse.help;
*
* @since 3.2
*/
-public interface IIndexEntry extends INode {
+public interface IIndexEntry {
+
/**
* Returns the keyword that this entry is associated with
*
@@ -34,6 +35,8 @@ public interface IIndexEntry extends INode {
/**
* Obtains the index subentries contained in the entry.
+ *
+ * @return the index subentries
*/
public IIndexEntry[] getSubentries();
}
diff --git a/org.eclipse.help/src/org/eclipse/help/INode.java b/org.eclipse.help/src/org/eclipse/help/INode.java
deleted file mode 100644
index 2944a3038..000000000
--- a/org.eclipse.help/src/org/eclipse/help/INode.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * 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.help;
-
-/**
- * <p>
- * An INode represents a node in a tree-structured user assistance
- * document. Each node may have zero or more children, and all nodes except
- * the root have a parent.
- * </p>
- * <p>
- * IMPORTANT: This API is still subject to change in 3.3. This interface may be
- * removed in favor of a concrete class.
- * </p>
- *
- * @since 3.3
- */
-public interface INode {
-
- /**
- * Returns the node's children. If there are no children, returns an
- * empty array.
- *
- * @return the child nodes.
- */
- public INode[] getChildren();
-
- /**
- * Returns the node's parent. If this is the root of the tree, returns
- * <code>null</code>.
- *
- * @return the node's parent
- */
- public INode getParent();
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/IToc.java b/org.eclipse.help/src/org/eclipse/help/IToc.java
index 0f973319c..cafcccc82 100644
--- a/org.eclipse.help/src/org/eclipse/help/IToc.java
+++ b/org.eclipse.help/src/org/eclipse/help/IToc.java
@@ -16,7 +16,7 @@ package org.eclipse.help;
*
* @since 2.0
*/
-public interface IToc extends INode, IHelpResource {
+public interface IToc extends IHelpResource {
/**
* This is element name used for TOC in XML files.
*/
@@ -31,7 +31,7 @@ public interface IToc extends INode, IHelpResource {
*
* @return the toc's contribution
*/
- public ITocContribution getTocContribution();
+ public TocContribution getTocContribution();
/**
* Obtains the topics directly contained by a toc.
diff --git a/org.eclipse.help/src/org/eclipse/help/ITocContribution.java b/org.eclipse.help/src/org/eclipse/help/ITocContribution.java
deleted file mode 100644
index a82291ca8..000000000
--- a/org.eclipse.help/src/org/eclipse/help/ITocContribution.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*******************************************************************************
- * 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.help;
-
-/**
- * <p>
- * An <code>ITocContribution</code> represents either a complete or partial
- * table of contents, as well as its metadata.
- * </p>
- * <p>
- * IMPORTANT: This API is still subject to change in 3.3.
- * </p>
- *
- * @since 3.3
- */
-public interface ITocContribution {
-
- /**
- * Returns the TOC's category id. Categories are used to organize similar
- * books in categories.
- *
- * @return the TOC's category id.
- */
- public String getCategoryId();
-
- /**
- * Returns the hrefs for any additional documents that are not in this TOC
- * but are associated with it, and should be indexed for searching. A
- * return value of <code>null</code> will be treated the same as an empty
- * array.
- *
- * @return any extra documents associated with the TOC
- */
- public String[] getExtraDocuments();
-
- /**
- * Returns a unique identifier for this contribution.
- *
- * @return the contribution's unique identifier
- */
- public String getId();
-
- /**
- * Returns the target anchor at which to insert this contribution. The
- * format is: [contribution_id]#[anchor_id]. For example, to insert the toc
- * at the "reference_troubleshooting" anchor in the
- * "/my.plugin.id/path/toc.xml" contribution, the target will be
- * "/my.plugin.id/path/toc.xml#reference_troubleshooting". If not specified,
- * returns null.
- *
- * @return the target destination for this contribution, or null if none
- */
- public String getLinkTo();
-
- /**
- * Returns the locale for this contribution.
- *
- * @return the contribution's locale
- */
- public String getLocale();
-
- /**
- * Returns the TOC data for this contribution.
- *
- * @return the TOC data for this contribution
- */
- public IToc getToc();
-
- /**
- * Returns whether or not this is a top-level contribution (a book).
- *
- * @return whether the contribution is top-level book
- */
- public boolean isPrimary();
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/ITopic.java b/org.eclipse.help/src/org/eclipse/help/ITopic.java
index 84c84bbe0..d9186b2a0 100644
--- a/org.eclipse.help/src/org/eclipse/help/ITopic.java
+++ b/org.eclipse.help/src/org/eclipse/help/ITopic.java
@@ -16,7 +16,7 @@ package org.eclipse.help;
*
* @since 2.0
*/
-public interface ITopic extends INode, IHelpResource {
+public interface ITopic extends IHelpResource {
/**
* This is element name used for topic in XML files.
*/
diff --git a/org.eclipse.help/src/org/eclipse/help/IndexContribution.java b/org.eclipse.help/src/org/eclipse/help/IndexContribution.java
new file mode 100644
index 000000000..ecdcc4ed7
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/IndexContribution.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.help;
+
+/**
+ * An <code>IndexContribution</code> represents either a complete or partial
+ * keyword index, as well as its metadata.
+ *
+ * @since 3.3
+ */
+public class IndexContribution extends Node {
+
+ private static final String NAME = "indexContribution"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_LOCALE = "locale"; //$NON-NLS-1$
+
+ /**
+ * Constructs a new empty <code>IndexContribution</code>. Use the
+ * <code>set</code> methods to set the content.
+ */
+ public IndexContribution() {
+ super();
+ setName(NAME);
+ }
+
+ /**
+ * Returns a unique identifier for this contribution.
+ *
+ * @return the contribution's unique identifier
+ */
+ public String getId() {
+ return getAttribute(ATTRIBUTE_ID);
+ }
+
+ /**
+ * Returns the index data for this contribution. The format is the same as
+ * index XML file contributions, except the content is returned as
+ * <code>Node</code>s that mirror the XML structure.
+ *
+ * @return the index data for this contribution
+ */
+ public Node getIndex() {
+ Node[] children = getChildren();
+ if (children.length > 0) {
+ return children[0];
+ }
+ return null;
+ }
+
+ /**
+ * Returns the locale for this contribution.
+ *
+ * @return the contribution's locale
+ */
+ public String getLocale() {
+ return getAttribute(ATTRIBUTE_LOCALE);
+ }
+
+ /**
+ * Assigns a unique identifier to this contribution.
+ *
+ * @param id the contribution's unique identifier
+ */
+ public void setId(String id) {
+ setAttribute(ATTRIBUTE_ID, id);
+ }
+
+ /**
+ * Sets the index data for this contribution. The format is the same as
+ * index XML file contributions, except the content is returned as
+ * <code>Node</code>s that mirror the XML structure.
+ *
+ * @param index the index data for this contribution
+ */
+ public void setIndex(Node index) {
+ Node[] children = getChildren();
+ for (int i=0;i<children.length;++i) {
+ removeChild(children[i]);
+ }
+ appendChild(index);
+ }
+
+ /**
+ * Sets the locale for this contribution.
+ *
+ * @param locale the contribution's locale
+ */
+ public void setLocale(String locale) {
+ setAttribute(ATTRIBUTE_LOCALE, locale);
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/Node.java b/org.eclipse.help/src/org/eclipse/help/Node.java
index 50efd1946..255f7802c 100644
--- a/org.eclipse.help/src/org/eclipse/help/Node.java
+++ b/org.eclipse.help/src/org/eclipse/help/Node.java
@@ -163,6 +163,15 @@ public class Node {
}
/**
+ * Sets the node's name.
+ *
+ * @param name the name of the node
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
* Sets the value of the node.
*
* @param value the value of this node
diff --git a/org.eclipse.help/src/org/eclipse/help/TocContribution.java b/org.eclipse.help/src/org/eclipse/help/TocContribution.java
new file mode 100644
index 000000000..7e85b6b14
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/TocContribution.java
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * 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.help;
+
+import org.eclipse.help.internal.toc.Toc;
+
+/**
+ * A <code>TocContribution</code> represents either a complete or partial
+ * table of contents, as well as its metadata.
+ *
+ * @since 3.3
+ */
+public class TocContribution extends Node {
+
+ private static final String NAME = "tocContribution"; //$NON-NLS-1$
+ private static final String ELEMENT_EXTRA_DOC = "extraDoc"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_CATEGORY_ID = "categoryId"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_CONTRIBUTOR_ID = "contributorId"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_LOCALE = "locale"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_IS_PRIMARY = "isPrimary"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_HREF = "href"; //$NON-NLS-1$
+
+ /**
+ * Constructs a new empty <code>TocContribution</code>. Use the
+ * <code>set</code> methods to set the content.
+ */
+ public TocContribution() {
+ super();
+ setName(NAME);
+ }
+
+ /**
+ * Returns the contribution's category id. Contributions with the same
+ * category id will be grouped together.
+ *
+ * @return the contribution's category id.
+ */
+ public String getCategoryId() {
+ return getAttribute(ATTRIBUTE_CATEGORY_ID);
+ }
+
+ /**
+ * Returns the symbolic name of the bundle that made this contribution,
+ * e.g. "org.eclipse.help"
+ *
+ * @return the contributor id, e.g. "org.eclipse.help"
+ */
+ public String getContributorId() {
+ return getAttribute(ATTRIBUTE_CONTRIBUTOR_ID);
+ }
+
+ /**
+ * Returns the hrefs for any additional documents that are not in this TOC
+ * but are associated with it, and should be indexed for searching.
+ *
+ * @return any extra documents associated with the TOC
+ */
+ public String[] getExtraDocuments() {
+ Node[] children = getChildren();
+ if (children.length > 0) {
+ boolean hasToc = Toc.NAME.equals(children[0].getName());
+ String[] extraDocuments = new String[hasToc ? children.length - 1 : children.length];
+ for (int i=0;i<extraDocuments.length;++i) {
+ extraDocuments[i] = children[hasToc ? i + 1 : i].getAttribute(ATTRIBUTE_HREF);
+ }
+ return extraDocuments;
+ }
+ return new String[0];
+ }
+
+ /**
+ * Returns a unique identifier for this contribution.
+ *
+ * @return the contribution's unique identifier
+ */
+ public String getId() {
+ return getAttribute(ATTRIBUTE_ID);
+ }
+
+ /**
+ * Returns the locale for this contribution.
+ *
+ * @return the contribution's locale
+ */
+ public String getLocale() {
+ return getAttribute(ATTRIBUTE_LOCALE);
+ }
+
+ /**
+ * Returns the TOC data for this contribution. The format is the same as
+ * TOC XML file contributions, except the content is returned as
+ * <code>Node</code>s that mirror the XML structure.
+ *
+ * @return the TOC data for this contribution
+ */
+ public Node getToc() {
+ Node[] children = getChildren();
+ if (children.length > 0 && Toc.NAME.equals(children[0].getName())) {
+ return children[0];
+ }
+ return null;
+ }
+
+ /**
+ * Returns whether or not this is a top-level contribution (a book).
+ *
+ * @return whether the contribution is top-level book
+ */
+ public boolean isPrimary() {
+ return String.valueOf(true).equalsIgnoreCase(getAttribute(ATTRIBUTE_IS_PRIMARY));
+ }
+
+ /**
+ * Sets the contribution's category id. Contributions with the same
+ * category id will be grouped together.
+ *
+ * param categoryId the contribution's category id.
+ */
+ public void setCategoryId(String categoryId) {
+ setAttribute(ATTRIBUTE_CATEGORY_ID, categoryId);
+ }
+
+ /**
+ * Sets the symbolic name of the bundle that made this contribution,
+ * e.g. "org.eclipse.help"
+ *
+ * @param contributorId the contributor id, e.g. "org.eclipse.help"
+ */
+ public void setContributorId(String contributorId) {
+ setAttribute(ATTRIBUTE_CONTRIBUTOR_ID, contributorId);
+ }
+
+ /**
+ * Sets the hrefs for any additional documents that are not in this TOC
+ * but are associated with it, and should be indexed for searching.
+ *
+ * @param extraDocuments any extra documents associated with the TOC
+ */
+ public void setExtraDocuments(String[] extraDocuments) {
+ // remove existing extra documents, if exists
+ Node[] children = getChildren();
+ if (children.length > 0) {
+ boolean hasToc = Toc.NAME.equals(children[0].getName());
+ for (int i=hasToc?1:0;i<children.length;++i) {
+ removeChild(children[i]);
+ }
+ }
+ // add new nodes
+ for (int i=0;i<extraDocuments.length;++i) {
+ Node extraDoc = new Node();
+ extraDoc.setName(ELEMENT_EXTRA_DOC);
+ extraDoc.setAttribute(ATTRIBUTE_HREF, extraDocuments[i]);
+ appendChild(extraDoc);
+ }
+ }
+
+ /**
+ * Assigns a unique identifier to this contribution.
+ *
+ * @param id the contribution's unique identifier
+ */
+ public void setId(String id) {
+ setAttribute(ATTRIBUTE_ID, id);
+ }
+
+ /**
+ * Sets the locale for this contribution.
+ *
+ * @param locale the contribution's locale
+ */
+ public void setLocale(String locale) {
+ setAttribute(ATTRIBUTE_LOCALE, locale);
+ }
+
+ /**
+ * Sets whether or not this is a top-level contribution (a book).
+ *
+ * @param isPrimary whether the contribution is top-level book
+ */
+ public void setPrimary(boolean isPrimary) {
+ setAttribute(ATTRIBUTE_IS_PRIMARY, String.valueOf(isPrimary));
+ }
+
+ /**
+ * Sets the TOC data for this contribution. The format is the same as
+ * TOC XML file contributions, except the content is returned as
+ * <code>Node</code>s that mirror the XML structure.
+ *
+ * @param toc the TOC data for this contribution
+ */
+ public void setToc(Node toc) {
+ Node[] children = getChildren();
+ if (children.length > 0) {
+ insertBefore(toc, children[0]);
+ if (Toc.NAME.equals(children[0].getName())) {
+ removeChild(children[0]);
+ }
+ }
+ else {
+ appendChild(toc);
+ }
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/UAContentFilter.java b/org.eclipse.help/src/org/eclipse/help/UAContentFilter.java
index eeed84459..16da53134 100644
--- a/org.eclipse.help/src/org/eclipse/help/UAContentFilter.java
+++ b/org.eclipse.help/src/org/eclipse/help/UAContentFilter.java
@@ -10,65 +10,87 @@
*******************************************************************************/
package org.eclipse.help;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.help.internal.FilterableUAElement;
import org.eclipse.help.internal.dynamic.FilterResolver;
/**
* <p>
- * This class provides the ability to filter out user assistance model elements that
- * support filtering (e.g. <code>IToc</code>, <code>ITopic</code>, ...).
- * Implementations that display such filterable elements should consult this class
- * before attempting to display them.
+ * This class provides the ability to filter out user assistance model elements
+ * that support filtering (e.g. <code>IToc</code>, <code>ITopic</code>, ...).
+ * Implementations that display such elements should consult this class before
+ * attempting to display them.
* </p>
*
* @since 3.2
*/
public class UAContentFilter {
+ private static final String ELEMENT_FILTER = "filter"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_FILTER = "filter"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$
+
private static FilterResolver resolver;
/**
* <p>
- * Returns whether or not the given object should be filtered out. This applies
- * to any user assistance component's elements where filters apply (e.g. help tocs,
- * topics, intro elements, context help topics). If the element is <code>null</code>
- * or is not filterable, this method returns <code>false</code>.
+ * Returns whether or not the given object should be filtered out. This
+ * applies to any user assistance component's elements where filters apply
+ * (e.g. help tocs, topics, intro elements, context help topics). If the
+ * element is <code>null</code> or is not filterable, this method returns
+ * <code>false</code>.
* </p>
*
* @param element the element to check
* @return whether or not the element should be filtered out
*/
public static boolean isFiltered(Object element) {
- if (element instanceof FilterableUAElement) {
- Map filters = ((FilterableUAElement)element).getFilters();
- if (filters != null) {
- Iterator iter = filters.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry)iter.next();
- String name = (String)entry.getKey();
- String value = (String)entry.getValue();
- boolean not = (value.charAt(0) == '!');
- if (not) {
- value = value.substring(1);
- }
- if (resolver == null) {
- resolver = new FilterResolver();
- }
- if (resolver.isFiltered(name, value, not)) {
- return true;
- }
+ if (element instanceof Node) {
+ Node node = (Node)element;
+ if (node.getAttribute(ATTRIBUTE_FILTER) != null) {
+ return handleFilterAttribute(node);
+ }
+ Node[] children = node.getChildren();
+ for (int i=0;i<children.length;++i) {
+ if (ELEMENT_FILTER.equals(children[i].getName())) {
+ return handleFilterNodes(node);
}
}
}
- else if (element instanceof String) {
- if (resolver == null) {
- resolver = new FilterResolver();
+ return false;
+ }
+
+ private static boolean handleFilterAttribute(Node node) {
+ String expression = node.getAttribute(ATTRIBUTE_FILTER);
+ if (resolver == null) {
+ resolver = new FilterResolver();
+ }
+ return resolver.isFiltered(expression);
+ }
+
+ /*
+ * Handle the child filter node case.
+ */
+ private static boolean handleFilterNodes(Node node) {
+ boolean hasFilteredYet = false;
+ Node[] children = node.getChildren();
+ for (int i=0;i<children.length;++i) {
+ Node child = children[i];
+ // is it a filter node?
+ if (ELEMENT_FILTER.equals(child.getName())) {
+ // if it already filtered, don't bother evaluating the rest
+ if (!hasFilteredYet) {
+ String name = child.getAttribute(ATTRIBUTE_NAME);
+ String value = child.getAttribute(ATTRIBUTE_VALUE);
+ if (name != null && value != null && name.length() > 0 && value.length() > 0) {
+ boolean not = (value.charAt(0) == '!');
+ if (not) {
+ value = value.substring(1);
+ }
+ hasFilteredYet = resolver.isFiltered(name, value, not);
+ }
+ }
}
- resolver.isFiltered((String)element);
}
- return false;
+ return hasFilteredYet;
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/Anchor.java b/org.eclipse.help/src/org/eclipse/help/internal/Anchor.java
deleted file mode 100644
index 35a85bfdb..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/Anchor.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*******************************************************************************
- * 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.help.internal;
-
-import org.eclipse.help.IAnchor;
-
-public class Anchor extends Node implements IAnchor {
-
- private String id;
-
- public Anchor(String id) {
- this.id = id;
- }
-
- public String getId() {
- return id;
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/Filter.java b/org.eclipse.help/src/org/eclipse/help/internal/Filter.java
deleted file mode 100644
index 852bce231..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/Filter.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * 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.help.internal;
-
-import org.eclipse.help.IFilter;
-
-public class Filter extends Node implements IFilter {
-
- private String expression;
-
- public Filter(String expression) {
- this.expression = expression;
- addFilter(expression);
- }
-
- public String getExpression() {
- return expression;
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/FilterableHelpElement.java b/org.eclipse.help/src/org/eclipse/help/internal/FilterableHelpElement.java
deleted file mode 100644
index 1b39ccc80..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/FilterableHelpElement.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*******************************************************************************
- * 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.help.internal;
-
-/**
- * Any model element or node in a help component that is filterable. This is
- * used to tag help elements, as they can be treated differently in some
- * situations. e.g. to allow the option of showing all content
- */
-public abstract class FilterableHelpElement extends FilterableUAElement {
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/FilterableUAElement.java b/org.eclipse.help/src/org/eclipse/help/internal/FilterableUAElement.java
deleted file mode 100644
index dc22e1791..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/FilterableUAElement.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*******************************************************************************
- * 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.help.internal;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.help.internal.util.StringUtil;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.Attributes;
-
-/**
- * Any model element or node in any user assistance component that is filterable.
- * Filters are generally specified in the XML as a filter attribute or child element,
- * where the filter has a name and value, for example:
- *
- * <myUAElement filter="os=win32" myattribute="..." />
- * <myUAElement filter="os!=linux" myattribute="..." />
- *
- * or
- *
- * <myUAElement myattribute="...">
- * <filter name="os" value="linux" />
- * <filter name="ws" value="!gtk" />
- * </myUAElement>
- *
- * Filters must be stored in the model because they should only be processed when
- * the content is about to be shown, because some of the filtering properties can change
- * during a session (e.g. activities).
- */
-public abstract class FilterableUAElement {
-
- private Map filters;
-
- /**
- * Adds the filters specified in the given attributes. This looks for
- * the "filter" attribute and parses it.
- *
- * @param attrs the XML attributes for the element
- */
- public void addFilters(Attributes attrs) {
- // add filter attribute if it exists
- if (attrs != null) {
- String filterAttribute = attrs.getValue("filter"); //$NON-NLS-1$
- if (filterAttribute != null) {
- addFilter(filterAttribute);
- }
- }
- }
-
- /**
- * Adds all filters associated with the given element in the DOM. These can be defined
- * as either a filter attribute on the element, or filter elements as children of this
- * element.
- *
- * @param element the element whose filters to find
- * @return a filter name to value mapping for all the filters on this element
- */
- public void addFilters(Element element) {
- // check for filter attribute
- String filterAttribute = element.getAttribute("filter"); //$NON-NLS-1$
- if (filterAttribute.length() > 0) {
- addFilter(filterAttribute);
- }
- // check for child filter elements
- NodeList list = element.getChildNodes();
- for (int i=0;i<list.getLength();++i) {
- Node node = list.item(i);
- if (node.getNodeType() == Node.ELEMENT_NODE && "filter".equals(node.getNodeName())) { //$NON-NLS-1$
- Element elementNode = (Element)node;
- addFilter(elementNode.getAttribute("name"), elementNode.getAttribute("value")); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- }
-
- /**
- * Adds the filter specified by the given string containing both the
- * filter name and value (e.g. "os=win32").
- *
- * @param nameAndValue the filter name and value
- */
- public void addFilter(String nameAndValue) {
- boolean isPositive = (nameAndValue.indexOf("!=") == -1); //$NON-NLS-1$
- // split at "=" or "!="
- String[] tokens = StringUtil.split(nameAndValue, "!?="); //$NON-NLS-1$
- String name = tokens[0];
- String value = tokens[1];
- if (!isPositive) {
- value = '!' + value;
- }
- addFilter(name, value);
- }
-
- /**
- * Adds the specified filter to this element, e.g. name="os", value="win32".
- *
- * @param name the filter name, e.g. "os"
- * @param name the filter value, e.g. "win32"
- */
- public void addFilter(String name, String value) {
- if (filters == null) {
- filters = new HashMap();
- }
- filters.put(name, value);
- }
-
- /**
- * Returns all the filters on this element. This is a mapping of
- * filter names (e.g. "os") to filter values (e.g. "win32").
- *
- * @return this element's filters
- */
- public Map getFilters() {
- return filters;
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java b/org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java
index 38a50511b..1973295a5 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java
@@ -11,47 +11,30 @@
package org.eclipse.help.internal;
import java.io.InputStream;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Vector;
-import org.eclipse.core.runtime.IExtensionDelta;
-import org.eclipse.core.runtime.IRegistryChangeEvent;
-import org.eclipse.core.runtime.IRegistryChangeListener;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.help.internal.context.ContextManager;
import org.eclipse.help.internal.extension.ContentExtensionManager;
-import org.eclipse.help.internal.index.IndexFileProvider;
import org.eclipse.help.internal.index.IndexManager;
-import org.eclipse.help.internal.toc.TocFileProvider;
import org.eclipse.help.internal.toc.TocManager;
-import org.eclipse.help.internal.util.ResourceLocator;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
/**
* Help System Core plug-in
*/
-public class HelpPlugin extends Plugin implements IRegistryChangeListener, BundleListener {
+public class HelpPlugin extends Plugin {
public final static String PLUGIN_ID = "org.eclipse.help"; //$NON-NLS-1$
- // debug options
- public static boolean DEBUG = false;
- public static boolean DEBUG_CONTEXT = false;
- public static boolean DEBUG_PROTOCOLS = false;
- private static HelpPlugin plugin;
- private List tocsChangedListeners = new Vector();
-
public final static String BASE_TOCS_KEY = "baseTOCS"; //$NON-NLS-1$
public final static String IGNORED_TOCS_KEY = "ignoredTOCS"; //$NON-NLS-1$
public final static String IGNORED_INDEXES_KEY = "ignoredIndexes"; //$NON-NLS-1$
- private TocManager tocManager;
+ private static HelpPlugin plugin;
private static Object tocManagerCreateLock = new Object();
+
+ private TocManager tocManager;
private ContextManager contextManager;
private ContentExtensionManager contentExtensionManager;
private IndexManager indexManager;
@@ -75,56 +58,12 @@ public class HelpPlugin extends Plugin implements IRegistryChangeListener, Bundl
}
/**
- * Logs a Warning message with an exception.
- */
- public static synchronized void logWarning(String message) {
- if (HelpPlugin.DEBUG) {
- if (message == null)
- message = ""; //$NON-NLS-1$
- Status warningStatus = new Status(IStatus.WARNING, PLUGIN_ID, IStatus.OK, message, null);
- HelpPlugin.getDefault().getLog().log(warningStatus);
- }
- }
-
- /**
* @return the singleton instance of the plugin
*/
public static HelpPlugin getDefault() {
return plugin;
}
- /*
- * (non-Javadoc)
- *
- * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext context) throws Exception {
- Platform.getExtensionRegistry().removeRegistryChangeListener(this);
- context.removeBundleListener(this);
- plugin = null;
- // bundleContext = null;
- super.stop(context);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
- */
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- // bundleContext = context;
- context.addBundleListener(this);
- Platform.getExtensionRegistry().addRegistryChangeListener(this, HelpPlugin.PLUGIN_ID);
- // Setup debugging options
- DEBUG = isDebugging();
- if (DEBUG) {
- DEBUG_CONTEXT = "true".equalsIgnoreCase(Platform.getDebugOption(PLUGIN_ID + "/debug/context")); //$NON-NLS-1$ //$NON-NLS-2$
- DEBUG_PROTOCOLS = "true".equalsIgnoreCase(Platform.getDebugOption(PLUGIN_ID + "/debug/protocols")); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
/**
* Used to obtain Toc Naviagiont Manager
*
@@ -159,45 +98,6 @@ public class HelpPlugin extends Plugin implements IRegistryChangeListener, Bundl
return getDefault().contentExtensionManager;
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent)
- */
- public void registryChanged(IRegistryChangeEvent event) {
- IExtensionDelta[] deltas = event.getExtensionDeltas(HelpPlugin.PLUGIN_ID, TocFileProvider.ELEMENT_NAME_TOC);
- if (deltas.length > 0) {
- tocManager = null;
- }
- // notifiy listeners
- if (deltas.length > 0) {
- for (Iterator it = tocsChangedListeners.iterator(); it.hasNext();) {
- ((ITocsChangedListener) it.next()).tocsChanged();
- }
- }
- deltas = event.getExtensionDeltas(HelpPlugin.PLUGIN_ID, IndexFileProvider.ELEMENT_NAME_INDEX);
- if (deltas.length > 0) {
- indexManager = null;
- }
- }
-
- public void addTocsChangedListener(ITocsChangedListener listener) {
- if (!tocsChangedListeners.contains(listener)) {
- tocsChangedListeners.add(listener);
- }
- }
-
- public void removeTocsChangedListener(ITocsChangedListener listener) {
- tocsChangedListeners.remove(listener);
- }
-
- public void bundleChanged(BundleEvent event) {
- int type = event.getType();
- if (type == BundleEvent.RESOLVED || type == BundleEvent.UNRESOLVED) {
- ResourceLocator.clearZipCache();
- }
- }
-
public static IndexManager getIndexManager() {
if (getDefault().indexManager == null)
getDefault().indexManager = new IndexManager();
@@ -218,7 +118,23 @@ public class HelpPlugin extends Plugin implements IRegistryChangeListener, Bundl
public void setHelpProvider(IHelpProvider helpProvider) {
this.helpProvider = helpProvider;
}
-
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
/*
* An interface by which higher plug-ins can serve help content.
*/
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/ITocsChangedListener.java b/org.eclipse.help/src/org/eclipse/help/internal/ITocsChangedListener.java
deleted file mode 100644
index cd98e3e69..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/ITocsChangedListener.java
+++ /dev/null
@@ -1,15 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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;
-
-public interface ITocsChangedListener {
- public void tocsChanged();
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/Include.java b/org.eclipse.help/src/org/eclipse/help/internal/Include.java
deleted file mode 100644
index fee8f3023..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/Include.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*******************************************************************************
- * 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.help.internal;
-
-import org.eclipse.help.IInclude;
-
-public class Include extends Node implements IInclude {
-
- private String target;
-
- public Include(String target) {
- this.target = target;
- }
-
- public String getTarget() {
- return target;
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/Messages.java b/org.eclipse.help/src/org/eclipse/help/internal/Messages.java
deleted file mode 100644
index 066788109..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/Messages.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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;
-
-import org.eclipse.osgi.util.NLS;
-
-public final class Messages extends NLS {
-
- private static final String BUNDLE_NAME = "org.eclipse.help.internal.Messages";//$NON-NLS-1$
-
- private Messages() {
- // Do not instantiate
- }
-
-
- static {
- NLS.initializeMessages(BUNDLE_NAME, Messages.class);
- }
-} \ No newline at end of file
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/Messages.properties b/org.eclipse.help/src/org/eclipse/help/internal/Messages.properties
deleted file mode 100644
index 4300e7b1c..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/Messages.properties
+++ /dev/null
@@ -1,10 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2005 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
-###############################################################################
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/Node.java b/org.eclipse.help/src/org/eclipse/help/internal/Node.java
deleted file mode 100644
index 6804bbe4b..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/Node.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*******************************************************************************
- * 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.help.internal;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.help.INode;
-
-public class Node extends FilterableUAElement implements INode {
-
- private Node parent;
- private List children;
-
- public void addChild(Node childToAdd) {
- if (children == null) {
- children = new ArrayList();
- }
- children.add(childToAdd);
- childToAdd.setParent(this);
- }
-
- public void addChildren(Node[] childrenToAdd) {
- for (int i=0;i<childrenToAdd.length;++i) {
- addChild(childrenToAdd[i]);
- }
- }
-
- public INode[] getChildren() {
- if (children == null) {
- return new INode[0];
- }
- return (INode[])children.toArray(new INode[children.size()]);
- }
-
- /*
- * Gets the children of a specific type.
- */
- public List getChildren(Class clazz) {
- if (children != null) {
- List list = new ArrayList();
- getChildren(clazz, list);
- return list;
- }
- return Collections.EMPTY_LIST;
- }
-
- public void getChildren(Class clazz, Collection collection) {
- if (children != null) {
- Iterator iter = children.iterator();
- while (iter.hasNext()) {
- Object o = iter.next();
- if (clazz.isAssignableFrom(o.getClass())) {
- collection.add(o);
- }
- else if (o instanceof Filter) {
- ((Filter)o).getChildren(clazz, collection);
- }
- }
- }
- }
-
- public Node[] getChildrenInternal() {
- if (children == null) {
- return new Node[0];
- }
- return (Node[])children.toArray(new Node[children.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.help.internal.FilterableUAElement#getFilters()
- */
- public Map getFilters() {
- Map filters = super.getFilters();
- Node parent = getParentInternal();
- if (parent != null) {
- Map parentFilters = parent.getFilters();
- if (parentFilters != null) {
- if (filters != null) {
- Map allFilters = new HashMap();
- allFilters.putAll(filters);
- allFilters.putAll(parentFilters);
- return allFilters;
- }
- return parentFilters;
- }
- }
- return filters;
- }
-
- public INode getParent() {
- return parent;
- }
-
- public Node getParentInternal() {
- return parent;
- }
-
- public void removeChild(Node node) {
- if (children != null) {
- children.remove(node);
- }
- }
-
- public void replaceChild(Node oldNode, Node newNode) {
- if (children != null) {
- int index = children.indexOf(oldNode);
- if (index != -1) {
- children.set(index, newNode);
- newNode.setParent(this);
- }
- }
- }
-
- public void replaceChild(Node oldNode, Node[] newNodes) {
- if (children != null) {
- int index = children.indexOf(oldNode);
- if (index != -1) {
- children.remove(index);
- for (int i=newNodes.length-1;i>=0;--i) {
- children.add(index, newNodes[i]);
- ((Node)newNodes[i]).setParent(this);
- }
- }
- }
- }
-
- public void setParent(Node parent) {
- this.parent = parent;
- }
-
- public void sortChildren(Comparator c) {
- if (children != null) {
- Collections.sort(children, c);
- }
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/NodeAdapter.java b/org.eclipse.help/src/org/eclipse/help/internal/NodeAdapter.java
new file mode 100644
index 000000000..85efd0fdd
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/NodeAdapter.java
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * 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.help.internal;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.help.Node;
+
+/*
+ * Adapts a Node to expose a new interface, e.g. "toc" Nodes are exposed as
+ * ITocs via the Toc adapter class.
+ */
+public abstract class NodeAdapter extends Node {
+
+ private static final Class[] PARAMETER_TYPES = new Class[] { Node.class };
+ private static final Object[] PARAMETER = new Object[1];
+
+ // the node to adapt
+ protected Node node;
+
+ /*
+ * Creates an adapter for a new node.
+ */
+ protected NodeAdapter() {
+ node = new Node();
+ }
+
+ /*
+ * Creates an adapter for the given node.
+ */
+ protected NodeAdapter(Node node) {
+ this.node = node;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#appendChild(org.eclipse.help.Node)
+ */
+ public void appendChild(Node newChild) {
+ node.appendChild(newChild);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#getAttribute(java.lang.String)
+ */
+ public String getAttribute(String name) {
+ return node.getAttribute(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#getAttributes()
+ */
+ public Set getAttributes() {
+ return node.getAttributes();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#getChildren()
+ */
+ public Node[] getChildren() {
+ return node.getChildren();
+ }
+
+ /*
+ * Convenience method for getting all children with a given name, returned
+ * as an array of typed adapters. e.g. getChildren("topic", Topic.class)
+ * returns all children with name "topic" as a Topic[] array. The returned
+ * Object must be casted to the requested type.
+ *
+ * It is assumed that the adapter has a one-arg constructor that takes in
+ * a node to be adapted.
+ */
+ public Object getChildren(String name, Class clazz) {
+ Node[] children = getChildren();
+ if (children.length > 0) {
+ List list = new ArrayList();
+ for (int i=0;i<children.length;++i) {
+ if (name.equals(children[i].getName())) {
+ try {
+ PARAMETER[0] = children[i];
+ NodeAdapter typedNode = (NodeAdapter)clazz.getConstructor(PARAMETER_TYPES).newInstance(PARAMETER);
+ list.add(typedNode);
+ }
+ catch (Throwable t) {
+ // invalid; skip
+ }
+ }
+ }
+ // make the typed array
+ Object array = Array.newInstance(clazz, list.size());
+ for (int i=0;i<list.size();++i) {
+ Array.set(array, i, list.get(i));
+ }
+ return array;
+ }
+ else {
+ return Array.newInstance(clazz, 0);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#getName()
+ */
+ public String getName() {
+ return node.getName();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#getParent()
+ */
+ public Node getParent() {
+ return node.getParent();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#getValue()
+ */
+ public String getValue() {
+ return node.getValue();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#insertBefore(org.eclipse.help.Node, org.eclipse.help.Node)
+ */
+ public void insertBefore(Node newChild, Node refChild) {
+ node.insertBefore(newChild, refChild);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String name) {
+ node.removeAttribute(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#removeChild(org.eclipse.help.Node)
+ */
+ public void removeChild(Node oldChild) {
+ node.removeChild(oldChild);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#setAttribute(java.lang.String, java.lang.String)
+ */
+ public void setAttribute(String name, String value) {
+ node.setAttribute(name, value);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#setName(java.lang.String)
+ */
+ public void setName(String name) {
+ node.setName(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.Node#setValue(java.lang.String)
+ */
+ public void setValue(String value) {
+ node.setValue(value);
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/Topic.java b/org.eclipse.help/src/org/eclipse/help/internal/Topic.java
new file mode 100644
index 000000000..52bc2a1a6
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/Topic.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.help.internal;
+
+import org.eclipse.help.ITopic;
+import org.eclipse.help.Node;
+
+/*
+ * Adapts a "topic" Node as an ITopic. All methods operate on the
+ * underlying adapted Node.
+ */
+public class Topic extends NodeAdapter implements ITopic {
+
+ public static final String NAME = "topic"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_HREF = "href"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_LABEL = "label"; //$NON-NLS-1$
+
+ /*
+ * Constructs a new topic adapter for an empty topic node.
+ */
+ public Topic() {
+ super();
+ setName(NAME);
+ }
+
+ /*
+ * Constructs a new topic adapter for the given topic node.
+ */
+ public Topic(Node node) {
+ super(node);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IHelpResource#getHref()
+ */
+ public String getHref() {
+ return node.getAttribute(ATTRIBUTE_HREF);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IHelpResource#getLabel()
+ */
+ public String getLabel() {
+ return node.getAttribute(ATTRIBUTE_LABEL);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.ITopic#getSubtopics()
+ */
+ public ITopic[] getSubtopics() {
+ return (Topic[])getChildren(NAME, Topic.class);
+ }
+
+ /*
+ * Sets the topic's href.
+ */
+ public void setHref(String href) {
+ node.setAttribute(ATTRIBUTE_HREF, href);
+ }
+
+ /*
+ * Sets the topic's label.
+ */
+ public void setLabel(String label) {
+ node.setAttribute(ATTRIBUTE_LABEL, label);
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/Context.java b/org.eclipse.help/src/org/eclipse/help/internal/context/Context.java
index 476b1f335..0db1cf0b1 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/Context.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/context/Context.java
@@ -10,135 +10,88 @@
* Phil Loats (IBM Corp.) - fix to use only foundation APIs
*******************************************************************************/
package org.eclipse.help.internal.context;
-import java.util.List;
-import org.eclipse.help.*;
-import org.xml.sax.*;
-/**
- * Context object, as defined in the map.xml
+import org.eclipse.help.IContext;
+import org.eclipse.help.IHelpResource;
+import org.eclipse.help.Node;
+import org.eclipse.help.internal.NodeAdapter;
+import org.eclipse.help.internal.Topic;
+
+/*
+ * Adapts a "context" Node as an IContext. All methods operate on the
+ * underlying adapted Node.
*/
-public class Context extends ContextsNode implements IContext2 {
- private String text;
- protected String pluginID;
- protected String shortID;
- protected String title;
- /**
- * Context constructor.
+public class Context extends NodeAdapter implements IContext {
+
+ public static final String NAME = "context"; //$NON-NLS-1$
+ public static final String ELEMENT_DESCRIPTION = "description"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
+
+ /*
+ * Constructs a new context adapter for an empty context node.
*/
- public Context(Attributes attrs) {
- super(attrs);
- if (attrs == null)
- return;
- shortID = attrs.getValue("id"); //$NON-NLS-1$
- title = attrs.getValue("title"); //$NON-NLS-1$
- }
- private static String stripStyle(String s, String style) {
- int len = s.length();
- int skipLen = style.length();
- StringBuffer sb = new StringBuffer(s.length());
- int idx;
- int lastIdx=0;
-
- while ((idx = s.indexOf(style, lastIdx)) != -1) {
- int start = idx;
- boolean hasSpace = false;
- while ((start>lastIdx) && Character.isWhitespace(s.charAt(start-1))) {
- start--;
- }
- if (idx != start)
- hasSpace = true;
- //add everthing to start
- sb.append(s.substring(lastIdx, start));
-
- // skip style
- idx += skipLen;
- int end = idx;
- while ((end<len) && Character.isWhitespace(s.charAt(end)))
- end++;
- if (end != idx)
- hasSpace = true;
- lastIdx = end;
-
- if (hasSpace)
- sb.append(' ');
- }
-
- // add everything else
- sb.append(s.substring(lastIdx, len));
- return sb.toString();
+ public Context() {
+ super();
+ setName(NAME);
}
- /**
- * @return plain text (without <@#$b>or </@#$b> bug 59541)
+
+ /*
+ * Constructs a new context adapter for the given context node.
*/
- public String getText() {
- //PAL foundation
- /*
- return text
- // if there are spaces on any or both side of bold they need to be
- // collapsed to one
- .replaceAll("(\\s+</?@#\\$b>\\s*)|(\\s*</?@#\\$b>\\s+)", " ") //$NON-NLS-1$ //$NON-NLS-2$
- .replaceAll("</?@#\\$b>", ""); //$NON-NLS-1$ //$NON-NLS-2$
- */
- return stripStyle(stripStyle(text,"<@#$b>"),"</@#$b>"); //$NON-NLS-1$//$NON-NLS-2$
+ public Context(Node node) {
+ super(node);
}
- /**
- * @return styled text with <@#$b>and </@#$b> to mark bold range
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IContext#getRelatedTopics()
*/
- public String getStyledText() {
- return text;
- }
public IHelpResource[] getRelatedTopics() {
- if (children.size() > 0) {
- IHelpResource[] related = new IHelpResource[children.size()];
- children.toArray(related);
- return related;
- }
- // signal empty toc. handled by calling class.
- return null;
- }
- public void setStyledText(String s) {
- text = s;
- }
- /**
- * Obtains short id (without plugin)
- */
- public String getShortId() {
- return shortID;
+ return (Topic[])getChildren(Topic.NAME, Topic.class);
}
- public String getID() {
- return pluginID + "." + shortID; //$NON-NLS-1$
- }
- /**
- * Sets the pluginID.
- *
- * @param pluginID
- * The pluginID to set
+
+ /*
+ * Returns the Context's unique id.
*/
- public void setPluginID(String pluginID) {
- this.pluginID = pluginID;
+ public String getId() {
+ return getAttribute(ATTRIBUTE_ID);
}
- /**
- * @see ContextsNode#build(ContextsBuilder)
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IContext#getText()
*/
- public void build(ContextsBuilder builder) {
- builder.build(this);
+ public String getText() {
+ Node[] children = getChildren();
+ if (children.length > 0 && ELEMENT_DESCRIPTION.equals(children[0].getName())) {
+ Node description = children[0];
+ Node[] descriptionChildren = description.getChildren();
+ if (descriptionChildren.length > 0) {
+ return descriptionChildren[0].getValue();
+ }
+ }
+ return null;
}
- /**
- * Replaces children list
+
+ /*
+ * Sets the Context's unique id.
*/
- public void setChildren(List children) {
- this.children = children;
- }
-
- public String getCategory(IHelpResource topic) {
- // For backward compatibility, all the topics
- // will continue to belong to the default category
- return null;
+ public void setId(String id) {
+ setAttribute(ATTRIBUTE_ID, id);
}
- /* (non-Javadoc)
- * @see org.eclipse.help.IContext2#getTitle()
+
+ /*
+ * Sets the Context's description text.
*/
- public String getTitle() {
- return title;
+ public void setText(String text) {
+ Node[] children = getChildren();
+ if (children.length > 0 && ELEMENT_DESCRIPTION.equals(children[0].getName())) {
+ Node description = children[0];
+ Node[] descriptionChildren = description.getChildren();
+ for (int i=0;i<descriptionChildren.length;++i) {
+ description.removeChild(descriptionChildren[i]);
+ }
+ Node textNode = new Node();
+ textNode.setValue(text);
+ description.appendChild(textNode);
+ }
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFile.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFile.java
new file mode 100644
index 000000000..71cd953de
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFile.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.help.internal.context;
+
+/*
+ * A reference to a context XML file, or more precisely, a set of files, one
+ * for each locale.
+ */
+public class ContextFile {
+
+ private String bundleId;
+ private String file;
+
+ /*
+ * Creates a new context file reference.
+ */
+ public ContextFile(String bundleId, String file) {
+ this.bundleId = bundleId;
+ this.file = file;
+ }
+
+ /*
+ * Return the id of the bundle containing the file, e.g. "org.eclipse.help"
+ */
+ public String getBundleId() {
+ return bundleId;
+ }
+
+ /*
+ * Returns the bundle-relative path to the file, e.g. "/path/contexts.xml"
+ */
+ public String getFile() {
+ return file;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof ContextFile) {
+ if (obj == this) {
+ return true;
+ }
+ return bundleId.equals(((ContextFile)obj).bundleId) && file.equals(((ContextFile)obj).file);
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return bundleId.hashCode() + file.hashCode();
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java
new file mode 100644
index 000000000..7a5edd332
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java
@@ -0,0 +1,217 @@
+/*******************************************************************************
+ * 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.help.internal.context;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.help.AbstractContextProvider;
+import org.eclipse.help.Node;
+import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.dynamic.NodeReader;
+import org.eclipse.help.internal.dynamic.NodeWriter;
+import org.eclipse.help.internal.util.ResourceLocator;
+
+/*
+ * Provides context-sensitive help data to the help system, contributed from
+ * context XML files.
+ */
+public class ContextFileProvider extends AbstractContextProvider {
+
+ private static final String EXTENSION_POINT_CONTEXTS = "org.eclipse.help.contexts"; //$NON-NLS-1$
+ private static final String ELEMENT_CONTEXT = "context"; //$NON-NLS-1$
+ private static final String ELEMENT_CONTEXTS = "contexts"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_FILE = "file"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_PLUGIN = "plugin"; //$NON-NLS-1$
+
+ // locale -> Map(pluginId -> Map(shortContextId -> Context)[])
+ private Map pluginContextsByLocale;
+
+ // pluginId -> ContextFile[]
+ private Map descriptorsByPluginId;
+
+ // locale -> Map(ContextFile -> Map(shortContextId -> Context))
+ private Map contextFilesByLocale;
+
+ private NodeReader reader;
+ private NodeWriter writer;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.AbstractContextProvider#getContext(java.lang.String, java.lang.String)
+ */
+ public Node getContext(String contextId, String locale) {
+ int index = contextId.lastIndexOf('.');
+ String pluginId = contextId.substring(0, index);
+ String shortContextId = contextId.substring(index + 1);
+
+ if (pluginContextsByLocale == null) {
+ pluginContextsByLocale = new HashMap();
+ }
+ Map pluginContexts = (Map)pluginContextsByLocale.get(locale);
+ if (pluginContexts == null) {
+ pluginContexts = new HashMap();
+ pluginContextsByLocale.put(locale, pluginContexts);
+ }
+ Map[] contexts = (Map[])pluginContexts.get(pluginId);
+ if (contexts == null) {
+ contexts = getPluginContexts(pluginId, locale);
+ pluginContexts.put(pluginId, contexts);
+ }
+ for (int i=0;i<contexts.length;++i) {
+ Context context = (Context)contexts[i].get(shortContextId);
+ if (context != null) {
+ return context;
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.AbstractContextProvider#getPlugins()
+ */
+ public String[] getPlugins() {
+ Map associations = getPluginAssociations();
+ return (String[])associations.keySet().toArray(new String[associations.size()]);
+ }
+
+ /*
+ * Returns a mapping of plug-in IDs to arrays of context files that apply
+ * to that plug-in (pluginId -> ContextFile[]).
+ */
+ private Map getPluginAssociations() {
+ if (descriptorsByPluginId == null) {
+ descriptorsByPluginId = new HashMap();
+ IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_CONTEXTS);
+ for (int i=0;i<elements.length;++i) {
+ if (ELEMENT_CONTEXTS.equals(elements[i].getName())) {
+ String declaringPluginId = elements[i].getDeclaringExtension().getContributor().getName();
+ String file = elements[i].getAttribute(ATTRIBUTE_FILE);
+ if (file != null) {
+ String plugin = elements[i].getAttribute(ATTRIBUTE_PLUGIN);
+ String targetPluginId = (plugin == null ? declaringPluginId : plugin);
+ ContextFile descriptor = new ContextFile(declaringPluginId, file);
+ ContextFile[] descriptors = (ContextFile[])descriptorsByPluginId.get(targetPluginId);
+ if (descriptors == null) {
+ descriptors = new ContextFile[] { descriptor };
+ }
+ else {
+ ContextFile[] temp = new ContextFile[descriptors.length + 1];
+ System.arraycopy(descriptors, 0, temp, 0, descriptors.length);
+ temp[descriptors.length] = descriptor;
+ descriptors = temp;
+ }
+ descriptorsByPluginId.put(targetPluginId, descriptors);
+ }
+ else {
+ String msg = "Required attribute \"" + ATTRIBUTE_FILE + "\" missing from element \"" + ELEMENT_CONTEXTS + "\" of extension for extension point \"" + EXTENSION_POINT_CONTEXTS + "\" in plug-in \"" + declaringPluginId + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ HelpPlugin.logError(msg, null);
+ }
+ }
+ }
+ }
+ return descriptorsByPluginId;
+ }
+
+ /*
+ * Returns the context definitions for the given plug-in and locale,
+ * as a mapping of short IDs to Context objects (shortContextId -> Context).
+ */
+ private Map[] getPluginContexts(String pluginId, String locale) {
+ List maps = new ArrayList();
+ Map associations = getPluginAssociations();
+ ContextFile[] descriptors = (ContextFile[])associations.get(pluginId);
+ for (int i=0;i<descriptors.length;++i) {
+ Map contexts = getContexts(descriptors[i], locale);
+ if (contexts != null) {
+ maps.add(contexts);
+ }
+ }
+ return (Map[])maps.toArray(new Map[maps.size()]);
+ }
+
+ /*
+ * Returns the context definitions stored in the given file for the given
+ * locale (shortContextId -> Context).
+ */
+ private Map getContexts(ContextFile descriptor, String locale) {
+ if (contextFilesByLocale == null) {
+ contextFilesByLocale = new HashMap();
+ }
+ Map contextsByDescriptor = (Map)contextFilesByLocale.get(locale);
+ if (contextsByDescriptor == null) {
+ contextsByDescriptor = new HashMap();
+ contextFilesByLocale.put(locale, contextsByDescriptor);
+ }
+ Map contexts = (Map)contextsByDescriptor.get(descriptor);
+ if (contexts == null) {
+ contexts = loadContexts(descriptor, locale);
+ if (contexts != null) {
+ contextsByDescriptor.put(descriptor, contexts);
+ }
+ }
+ return contexts;
+ }
+
+ /*
+ * Loads the given context file for the given locale, and returns its
+ * contents as a mapping from short context ids to Context objects
+ * (shortContextId -> Context).
+ */
+ private Map loadContexts(ContextFile descriptor, String locale) {
+ try {
+ InputStream in = ResourceLocator.openFromPlugin(descriptor.getBundleId(), descriptor.getFile(), locale);
+ if (reader == null) {
+ reader = new NodeReader();
+ }
+ Node root = reader.read(in);
+ Node[] children = root.getChildren();
+ Map contexts = new HashMap();
+ for (int i=0;i<children.length;++i) {
+ if (ELEMENT_CONTEXT.equals(children[i].getName())) {
+ Context context = children[i] instanceof Context ? (Context)children[i] : new Context(children[i]);
+ normalizeDescription(context);
+ String id = context.getId();
+ if (id != null) {
+ contexts.put(id, context);
+ }
+ }
+ }
+ return contexts;
+ }
+ catch (Throwable t) {
+ String msg = "Error loading context-sensitive help file \"" + descriptor.getFile() + "\" in plug-in \"" + descriptor.getBundleId() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ HelpPlugin.logError(msg, t);
+ return null;
+ }
+ }
+
+ private void normalizeDescription(Context context) {
+ Node[] children = context.getChildren();
+ if (children.length > 0 && Context.ELEMENT_DESCRIPTION.equals(children[0].getName())) {
+ Node description = children[0];
+ Node[] descriptionChildren = description.getChildren();
+ if (writer == null) {
+ writer = new NodeWriter();
+ }
+
+ StringBuffer buf = new StringBuffer();
+ for (int i=0;i<descriptionChildren.length;++i) {
+ writer.write(descriptionChildren[i], buf, false, null, false);
+ }
+ context.setText(buf.toString());
+ }
+ }
+}
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 7c0c0dc4f..599ea93a6 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
@@ -23,8 +23,12 @@ import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.AbstractContextProvider;
import org.eclipse.help.IContext;
+import org.eclipse.help.Node;
import org.eclipse.help.internal.HelpPlugin;
+/*
+ * Manages all context-sensitive help data for the help system.
+ */
public class ContextManager {
private static final String EXTENSION_POINT_ID_CONTEXT = HelpPlugin.PLUGIN_ID + ".contexts"; //$NON-NLS-1$
@@ -34,14 +38,14 @@ public class ContextManager {
private Map providersByPluginId;
private List globalProviders;
- /*
- * Dynamic context IDs (generated by help) indexed by dynamic context
- * objects
- */
private Map contextsById = new HashMap();
private Map idsByContext = new HashMap();
private int idCounter = 0;
+ /*
+ * Adds the given dynamically generated IContext to the system, and
+ * generates a unique ID for it.
+ */
public String addContext(IContext context) {
String plugin = HelpPlugin.PLUGIN_ID;
String id = (String)idsByContext.get(context);
@@ -56,30 +60,27 @@ public class ContextManager {
return plugin + "." + id; //$NON-NLS-1$
}
- public IContext getContext(String contextId, String locale) {
- IContext dynamicContext = (IContext)contextsById.get(contextId);
+ /*
+ * Returns the Context for the given id and locale.
+ */
+ public Context getContext(String contextId, String locale) {
+ // first check for dynamic context definitions
+ Context dynamicContext = (Context)contextsById.get(contextId);
if (dynamicContext != null) {
return dynamicContext;
}
+ // ask the providers
int index = contextId.lastIndexOf('.');
if (index != -1) {
String pluginId = contextId.substring(0, index);
Iterator iter = getContextProviders(pluginId).iterator();
while (iter.hasNext()) {
AbstractContextProvider provider = (AbstractContextProvider)iter.next();
- IContext context = null;
try {
- context = provider.getContext(contextId, locale);
- if (context != null) {
- try {
- return ContextPrefetcher.prefetch(context);
- }
- catch (Throwable t) {
- // log and skip
- String msg = "Error querying IContext (" + context.getClass().getName() + ") with context Id " + contextId + " provided by context provider " + provider.getClass().getName(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- HelpPlugin.logError(msg, t);
- }
+ Node node = provider.getContext(contextId, locale);
+ if (node != null) {
+ return new Context(node);
}
}
catch (Throwable t) {
@@ -98,7 +99,7 @@ public class ContextManager {
*/
private List getContextProviders(String pluginId) {
if (providersByPluginId == null) {
- populateProviders();
+ loadContextProviders();
}
List list = new ArrayList();
List forPlugin = (List)providersByPluginId.get(pluginId);
@@ -109,7 +110,10 @@ public class ContextManager {
return list;
}
- private void populateProviders() {
+ /*
+ * Finds and instantiates all registered context-sensitive help providers.
+ */
+ private void loadContextProviders() {
providersByPluginId = new HashMap();
globalProviders = new ArrayList();
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextPrefetcher.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextPrefetcher.java
deleted file mode 100644
index aea79ff57..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextPrefetcher.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.context;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.help.IContext;
-import org.eclipse.help.IHelpResource;
-import org.eclipse.help.INode;
-import org.eclipse.help.internal.Node;
-import org.eclipse.help.internal.toc.Topic;
-
-/*
- * Pre-fetches all data from IContexts and returns cached data. Also
- * useful for copying IContexts.
- */
-public class ContextPrefetcher {
-
- public static IContext prefetch(IContext original) {
- String text = original.getText();
- Context context = new Context(text);
- IHelpResource[] topics = original.getRelatedTopics();
- if (topics != null) {
- for (int i=0;i<topics.length;++i) {
- context.addChild(prefetch(topics[i]));
- }
- }
- return context;
- }
-
- private static Topic prefetch(IHelpResource original) {
- String href = original.getHref();
- String label = original.getLabel();
- return new Topic(href, label);
- }
-
- private static class Context extends Node implements IContext {
- private String text;
- private IHelpResource[] topics;
-
- public Context(String text) {
- this.text = text;
- }
- public String getText() {
- return text;
- }
- public IHelpResource[] getRelatedTopics() {
- if (topics == null) {
- INode[] children = getChildren();
- if (children.length > 0) {
- List list = new ArrayList();
- for (int i=0;i<children.length;++i) {
- if (children[i] instanceof IHelpResource) {
- list.add(children[i]);
- }
- }
- topics = (IHelpResource[])list.toArray(new IHelpResource[list.size()]);
- }
- else {
- topics = new IHelpResource[0];
- }
- }
- return topics;
- }
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/Contexts.java b/org.eclipse.help/src/org/eclipse/help/internal/context/Contexts.java
deleted file mode 100644
index d693fedbe..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/Contexts.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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.context;
-import org.xml.sax.*;
-/**
- * Context
- */
-public class Contexts extends ContextsNode {
- /**
- * Contexts constructor.
- */
- public Contexts(Attributes attrs) {
- super(attrs);
- }
- public void build(ContextsBuilder builder) {
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsBuilder.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsBuilder.java
deleted file mode 100644
index b1e72348c..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsBuilder.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*******************************************************************************
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.help.internal.context;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.help.*;
-public class ContextsBuilder {
- protected PluginContexts contexts;
- private String definingPluginID;
- private String pluginID;
- /**
- * Contexts Builder Constructor.
- */
- public ContextsBuilder(PluginContexts pluginContexts) {
- this.contexts = pluginContexts;
- }
- public void build(RelatedTopic relatedTopic) {
- // set the href on the related topic
- String href = relatedTopic.getHref();
- if (href == null)
- relatedTopic.setHref(""); //$NON-NLS-1$
- else {
- if (!href.equals("") // no empty link //$NON-NLS-1$
- && !href.startsWith("/") // no help url //$NON-NLS-1$
- && href.indexOf(':') == -1) // no other protocols
- {
- relatedTopic.setHref("/" + definingPluginID + "/" + href); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- }
- public void build(Context context) {
- context.setPluginID(pluginID);
- // if context with same Id exists, merge them
- Context existingContext = (Context) contexts.get(context.getShortId());
- if (existingContext != null) {
- mergeContexts(existingContext, context);
- } else {
- contexts.put(context.getShortId(), context);
- }
- }
- public void build(ContextsFile contextsFile, String locale) {
- this.pluginID = contextsFile.getPluginID();
- this.definingPluginID = contextsFile.getDefiningPluginID();
- ContextsFileParser parser = new ContextsFileParser(this);
- parser.parse(contextsFile, locale);
- }
- public void build(List pluginContextsFiles, String locale) {
- for (Iterator contextFilesIt = pluginContextsFiles.iterator(); contextFilesIt
- .hasNext();) {
- ContextsFile contextsFile = (ContextsFile) contextFilesIt.next();
- contextsFile.build(this, locale);
- }
- }
- /**
- * Merges Text and Links from new Context into an existing Context
- */
- private void mergeContexts(Context existingContext, Context newContext) {
- // Merge Text
- if (newContext.getStyledText() != null) {
- if (existingContext.getStyledText() != null) {
- existingContext.setStyledText(existingContext.getStyledText()
- + "\n" //$NON-NLS-1$
- + newContext.getStyledText());
- } else {
- existingContext.setStyledText(newContext.getStyledText());
- }
- }
- // Merge Related Links
- existingContext.getChildren().addAll(newContext.getChildren());
- removeDuplicateLinks(existingContext);
- }
- /**
- * Filters out the duplicate related topics in a Context
- */
- private void removeDuplicateLinks(Context context) {
- List links = context.getChildren();
- if (links == null || links.size() <= 0)
- return;
- List filtered = new ArrayList();
- for (Iterator it = links.iterator(); it.hasNext();) {
- IHelpResource topic1 = (IHelpResource) it.next();
- if (!isValidTopic(topic1))
- continue;
- boolean dup = false;
- for (int j = 0; j < filtered.size(); j++) {
- IHelpResource topic2 = (IHelpResource) filtered.get(j);
- if (!isValidTopic(topic2))
- continue;
- if (equalTopics(topic1, topic2)) {
- dup = true;
- break;
- }
- }
- if (!dup)
- filtered.add(topic1);
- }
- context.setChildren(filtered);
- }
- /**
- * Checks if topic labels and href are not null and not empty strings
- */
- private boolean isValidTopic(IHelpResource topic) {
- return topic != null && topic.getHref() != null
- && !"".equals(topic.getHref()) && topic.getLabel() != null //$NON-NLS-1$
- && !"".equals(topic.getLabel()); //$NON-NLS-1$
- }
- /**
- * Check if two context topic are the same. They are considered the same if
- * both labels and href are equal
- */
- private boolean equalTopics(IHelpResource topic1, IHelpResource topic2) {
- return topic1.getHref().equals(topic2.getHref())
- && topic1.getLabel().equals(topic2.getLabel());
- }
-}
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
deleted file mode 100644
index adb5bd8d5..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFile.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.help.internal.context;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.eclipse.help.internal.util.ResourceLocator;
-
-public class ContextsFile {
- protected String href;
- protected String definingPluginID;
- protected String pluginID;
- /**
- * Contexts File Constructor
- */
- public ContextsFile(String definingPlugin, String href, String plugin) {
- this.href = href;
- this.definingPluginID = definingPlugin;
- this.pluginID = plugin;
- }
- /**
- * Gets the href
- *
- * @return Returns a String
- */
- public String getHref() {
- return href;
- }
- protected InputStream getInputStream(String locale) {
- InputStream stream = null;
- try {
- if (definingPluginID != null)
- stream = ResourceLocator.openFromPlugin(definingPluginID, href, locale);
- else
- stream = new FileInputStream(href);
- } catch (IOException e) {
- }
- return stream;
- }
- /**
- * Gets the definingPluginID.
- *
- * @return Returns a String
- */
- public String getDefiningPluginID() {
- return definingPluginID;
- }
- /**
- * Gets the plugin ID.
- *
- * @return Returns a String
- */
- public String getPluginID() {
- return pluginID;
- }
- public void build(ContextsBuilder builder, String locale) {
- builder.build(this, locale);
- }
-}
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
deleted file mode 100644
index aabc8fe20..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFileParser.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/*******************************************************************************
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.help.internal.context;
-
-import java.io.*;
-import com.ibm.icu.text.MessageFormat;
-
-import javax.xml.parsers.*;
-
-import org.eclipse.help.internal.*;
-import org.eclipse.help.internal.util.*;
-import org.xml.sax.*;
-import org.xml.sax.helpers.*;
-
-/**
- * Parser for xml file
- */
-public class ContextsFileParser extends DefaultHandler {
- protected FastStack stack = new FastStack();
-
- StringBuffer buffer = new StringBuffer();
-
- boolean seenDescription = false;
-
- ContextsFile contextsFile;
-
- private ContextsBuilder builder;
-
- private final static SAXParserFactory factory = SAXParserFactory
- .newInstance();
-
- public ContextsFileParser(ContextsBuilder builder) {
- super();
- this.builder = builder;
- }
-
- /**
- * Receive notification of character data.
- */
- public void characters(char ch[], int start, int length)
- throws SAXException {
- if (seenDescription)
- buffer.append(ch, start, length);
- if (HelpPlugin.DEBUG_CONTEXT) {
- System.out
- .println("ContextsFileParser.characters(): got char from parser= " //$NON-NLS-1$
- + new StringBuffer().append(ch, start, length)
- .toString());
- }
- }
-
- /**
- * Receive notification of the end of an element.
- */
- public void endElement(String namespaceURI, String localName, String qName)
- throws SAXException {
- // make sure that no error has already occurred before adding to stack.
- if (qName.equals(ContextsNode.DESC_ELEM)) {
- seenDescription = false;
- ((Context) stack.peek()).setStyledText(buffer.toString());
- buffer.setLength(0);
- } else if (qName.equals(ContextsNode.DESC_TXT_BOLD)) {
- // pop the starting bold tag
- stack.pop();
- if (!(stack.peek()).equals(ContextsNode.BOLD_TAG))
- buffer.append(ContextsNode.BOLD_CLOSE_TAG);
- } else if (!qName.equals("filter")) { //$NON-NLS-1$
- ContextsNode node = (ContextsNode) stack.pop();
- node.build(builder);
- }
- }
-
- /**
- * @see ErrorHandler#error(SAXParseException)
- */
- public void error(SAXParseException ex) {
- HelpPlugin.logError("Error parsing " + getErrorDetails(ex), null); //$NON-NLS-1$
- }
-
- /**
- * @see ErrorHandler#fatalError(SAXParseException)
- */
- public void fatalError(SAXParseException ex) throws SAXException {
- HelpPlugin.logError("Failed to parse " + getErrorDetails(ex), ex); //$NON-NLS-1$
- }
-
- public String getErrorDetails(SAXParseException ex) {
- String param0 = ex.getSystemId();
- Integer param1 = new Integer(ex.getLineNumber());
- Integer param2 = new Integer(ex.getColumnNumber());
- String param3 = ex.getMessage();
- String message = MessageFormat
- .format(
- "URL: {0} at line: {1,number,integer}, column: {2,number,integer}.\r\n{3}", //$NON-NLS-1$
- new Object[] { param0, param1, param2, param3 });
- return message;
- }
-
- /**
- * Receive notification of the beginning of an element.
- */
- public void startElement(String namespaceURI, String localName,
- String qName, Attributes atts) throws SAXException {
- // We don't create a description element
- if (qName.equals(ContextsNode.DESC_ELEM))
- seenDescription = true;
- else if (qName.equals(ContextsNode.DESC_TXT_BOLD)) {
- // peek into stack to findout if a bold tag element already
- // exists. If we find one, then we do not add the bold tag to
- // the current StringBuffer of description.
- // ie: there are many bold start tags in the stack, but we appended
- // the tag only once to the description string.
- // eg: (b) some text (b) more test (/b) more text (/b) will result
- // in all of the sentence being bold.
- if (!(stack.peek()).equals(ContextsNode.BOLD_TAG))
- buffer.append(ContextsNode.BOLD_TAG);
- stack.push(ContextsNode.BOLD_TAG);
- } else {
- ContextsNode e = null;
- // NOTE: we don't create an element for the description
- if (qName.equals(ContextsNode.CONTEXTS_ELEM)) {
- e = new Contexts(atts);
- } else if (qName.equals(ContextsNode.CONTEXT_ELEM)) {
- 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())
- ((ContextsNode) stack.peek()).addChild(e);
- stack.push(e);
- }
- }
-
- public void warning(SAXParseException ex) {
- HelpPlugin.logWarning("Warning parsing " + getErrorDetails(ex)); //$NON-NLS-1$
- }
-
- public void parse(ContextsFile contextsFile, String locale) {
- this.contextsFile = contextsFile;
- InputStream is = contextsFile.getInputStream(locale);
- if (is == null)
- return;
- InputSource inputSource = new InputSource(is);
- String file = "/" + contextsFile.getDefiningPluginID() + "/" //$NON-NLS-1$ //$NON-NLS-2$
- + contextsFile.getHref();
- inputSource.setSystemId(file);
- try {
- SAXParser parser = factory.newSAXParser();
- parser.parse(inputSource, this);
- } catch (ParserConfigurationException pce) {
- HelpPlugin.logError(
- "SAXParser implementation could not be loaded.", pce); //$NON-NLS-1$
- } catch (SAXException se) {
- HelpPlugin.logError("", se); //$NON-NLS-1$
- } catch (IOException ioe) {
- HelpPlugin.logError("Error loading file " + file + ".", ioe); //$NON-NLS-1$ //$NON-NLS-2$
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- }
- }
- }
- }
-
- /**
- * @see EntityResolver This method implementation prevents loading external
- * entities instead of calling
- * org.apache.xerces.parsers.SaxParser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
- */
- public InputSource resolveEntity(String publicId, String systemId) {
- InputSource source = new InputSource(new ByteArrayInputStream(
- new byte[0]));
- source.setPublicId(publicId);
- source.setSystemId(systemId);
- return source;
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFileProvider.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFileProvider.java
deleted file mode 100644
index 6b5475456..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsFileProvider.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.context;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.help.AbstractContextProvider;
-import org.eclipse.help.IContext;
-import org.eclipse.help.internal.HelpPlugin;
-
-/*
- * Provides context help data from context XML files to the help system.
- */
-public class ContextsFileProvider extends AbstractContextProvider {
-
- private static final String CONTEXTS_XP_NAME = "contexts"; //$NON-NLS-1$
- private static final String CONTEXTS_XP_FULLNAME = HelpPlugin.PLUGIN_ID + "." + CONTEXTS_XP_NAME; //$NON-NLS-1$
-
- private Map pluginsContextsByLocale = new HashMap();
- private Map contextsFiles = new HashMap();
-
- public ContextsFileProvider() {
- createContextsFiles();
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.help.AbstractContextProvider#getContext(java.lang.String, java.lang.String)
- */
- public IContext getContext(String contextId, String locale) {
- if (contextId != null) {
- int dot = contextId.lastIndexOf('.');
- if (dot <= 0 || dot >= contextId.length() - 1) {
- // no dot in the middle of context ID
- return null;
- }
- String plugin = contextId.substring(0, dot);
- String id = contextId.substring(dot + 1);
- PluginsContexts pluginsContexts = (PluginsContexts)pluginsContextsByLocale.get(locale);
- if (pluginsContexts == null) {
- pluginsContexts = new PluginsContexts();
- pluginsContextsByLocale.put(locale, pluginsContexts);
- }
- PluginContexts contexts = pluginsContexts.get(plugin);
- if (contexts == null) {
- contexts = loadPluginContexts(plugin, pluginsContexts, locale);
- }
- return contexts.get(id);
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.help.AbstractContextProvider#getPlugins()
- */
- public String[] getPlugins() {
- Set plugins = new HashSet();
- IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(CONTEXTS_XP_FULLNAME);
- for (int i=0;i<elements.length;++i) {
- IConfigurationElement element = (IConfigurationElement)elements[i];
- if ("contexts".equals(element.getName())) { //$NON-NLS-1$
- plugins.add(element.getContributor().getName());
- }
- String plugin = element.getAttribute("plugin"); //$NON-NLS-1$
- if (plugin != null) {
- plugins.add(plugin);
- }
- }
- return (String[])plugins.toArray(new String[plugins.size()]);
- }
-
- /**
- * Loads context.xml with context for a specified plugin, creates context
- * nodes and adds to pluginContext map.
- */
- public synchronized PluginContexts loadPluginContexts(String plugin, PluginsContexts pluginsContexts, String locale) {
- PluginContexts contexts = pluginsContexts.get(plugin);
- if (contexts == null) {
- contexts = new PluginContexts();
- // read the context info from the XML contributions
- List pluginContextsFiles = (List)contextsFiles.get(plugin);
- if (pluginContextsFiles == null) {
- pluginContextsFiles = new ArrayList();
- }
- ContextsBuilder builder = new ContextsBuilder(contexts);
- builder.build(pluginContextsFiles, locale);
- pluginsContexts.put(plugin, contexts);
- }
- return contexts;
- }
-
- /**
- * Creates a list of context files.
- */
- private void createContextsFiles() {
- // read extension point and retrieve all context contributions
- IExtensionPoint xpt = Platform.getExtensionRegistry()
- .getExtensionPoint(CONTEXTS_XP_FULLNAME);
- if (xpt == null)
- return; // no contributions...
- IExtension[] extensions = xpt.getExtensions();
- for (int i = 0; i < extensions.length; i++) {
- createContextFile(extensions[i]);
- }
- }
-
- /**
- * @param extension
- * @return Collection of String (plugin IDs that have new contexts
- * contributed)
- */
- private Collection createContextFile(IExtension extension) {
- Collection plugins = new HashSet();
- String definingPlugin = extension.getContributor().getName();
- IConfigurationElement[] contextContributions = extension
- .getConfigurationElements();
- for (int j = 0; j < contextContributions.length; j++) {
- if ("contexts".equals(contextContributions[j].getName())) { //$NON-NLS-1$
- String plugin = contextContributions[j].getAttribute("plugin"); //$NON-NLS-1$
- if (plugin == null || "".equals(plugin)) //$NON-NLS-1$
- plugin = definingPlugin;
- String fileName = contextContributions[j].getAttribute("file"); //$NON-NLS-1$
- // in v1 file attribute was called name
- if (fileName == null)
- fileName = contextContributions[j].getAttribute("name"); //$NON-NLS-1$
- if (fileName == null) {
- String msg = "\"context\" element in extension of " //$NON-NLS-1$
- + CONTEXTS_XP_FULLNAME
- + ", contributed in plug-in " + definingPlugin //$NON-NLS-1$
- + ", is missing required \"file\" attribute."; //$NON-NLS-1$
- HelpPlugin.logError(msg, null);
- continue;
- }
- List pluginContextsFiles = (List) contextsFiles.get(plugin);
- if (pluginContextsFiles == null) {
- pluginContextsFiles = new ArrayList();
- contextsFiles.put(plugin, pluginContextsFiles);
- }
- pluginContextsFiles.add(new ContextsFile(definingPlugin,
- fileName, plugin));
- plugins.add(plugin);
- }
- }
- return plugins;
- }
-}
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
deleted file mode 100644
index a8eef8fea..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextsNode.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.help.internal.context;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.help.internal.FilterableUAElement;
-import org.xml.sax.*;
-/**
- * Object in hierarchy of context contributions
- */
-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$
- public static final String RELATED_ELEM = "topic"; //$NON-NLS-1$
- public static final String RELATED_HREF = "href"; //$NON-NLS-1$
- public static final String RELATED_LABEL = "label"; //$NON-NLS-1$
- /**
- * Internal representation of &lt;b&gt; - unlikely to occur in a text
- */
- public static final String BOLD_CLOSE_TAG = "</@#$b>"; //$NON-NLS-1$
- /**
- * Internal representation of &lt;b&gt; - unlikely to occur in a text
- */
- public static final String BOLD_TAG = "<@#$b>"; //$NON-NLS-1$
- public static final String DESC_TXT_BOLD = "b"; //$NON-NLS-1$
- protected List children = new ArrayList();
- /**
- * When a builder builds the contexts, each node must "accomodate" the
- * builder by responding to the build() command.
- */
- public abstract void build(ContextsBuilder builder);
- /**
- * ContextsNode constructor.
- */
- public ContextsNode(Attributes attrs) {
- addFilters(attrs);
- }
- /**
- * Adds a child
- *
- * @param child
- * IContextsNode
- */
- public void addChild(ContextsNode child) {
- children.add(children.size(), child);
- }
- /**
- * Obtains children
- */
- public List getChildren() {
- return children;
- }
-}
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
deleted file mode 100644
index 79062b760..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/PluginContexts.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.help.internal.context;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.help.*;
-/**
- * Holds mapping of short contextId to IContext
- */
-public class PluginContexts {
- private Map map = new HashMap();
- public void put(String shortId, IContext context) {
- map.put(shortId, context);
- }
- public IContext get(String shortId) {
- return (IContext) map.get(shortId);
- }
-
- /**
- * For unit testing purposes.
- */
- public Map getMap() {
- return map;
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/PluginsContexts.java b/org.eclipse.help/src/org/eclipse/help/internal/context/PluginsContexts.java
deleted file mode 100644
index bf1e981c8..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/PluginsContexts.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.help.internal.context;
-import java.util.HashMap;
-import java.util.Map;
-/**
- * Holds mapping of short plugin Id to PluginContext
- */
-class PluginsContexts {
- private Map map = new HashMap();
- public void put(String pluginId, PluginContexts contexts) {
- map.put(pluginId, contexts);
- }
- public PluginContexts get(String pluginId) {
- return (PluginContexts) map.get(pluginId);
- }
- public void remove(String pluginId) {
- map.remove(pluginId);
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/RelatedTopic.java b/org.eclipse.help/src/org/eclipse/help/internal/context/RelatedTopic.java
deleted file mode 100644
index 1f980d7ef..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/RelatedTopic.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 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.context;
-import org.eclipse.help.*;
-import org.xml.sax.*;
-/**
- * Default implementation for a topic contribution
- */
-public class RelatedTopic extends ContextsNode implements IHelpResource {
- protected String href;
- protected String label;
- public RelatedTopic(Attributes attrs) {
- super(attrs);
- if (attrs == null)
- return;
- href = attrs.getValue(ContextsNode.RELATED_HREF);
- this.label = attrs.getValue(ContextsNode.RELATED_LABEL);
- if (this.label == null)
- this.label = ""; //$NON-NLS-1$
- }
- public String getHref() {
- return href;
- }
- public void setHref(String href) {
- this.href = href;
- }
- /**
- * Returns the label
- */
- public String getLabel() {
- return label;
- }
- /**
- * @see ContextsNode#build(ContextsBuilder)
- */
- public void build(ContextsBuilder builder) {
- builder.build(this);
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DOMNode.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentNode.java
index 71328dc18..62317163b 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DOMNode.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentNode.java
@@ -27,7 +27,7 @@ import org.w3c.dom.NodeList;
* reads and writes to an underlying DOM node. This allows us to use the same
* processor for two models, by adapting one of them.
*/
-public class DOMNode extends org.eclipse.help.Node {
+public class DocumentNode extends org.eclipse.help.Node {
private Node node;
@@ -35,7 +35,7 @@ public class DOMNode extends org.eclipse.help.Node {
* Creates an adapter for the given DOM node. All operations on this node
* will be performed on the given node instead.
*/
- public DOMNode(Node node) {
+ public DocumentNode(Node node) {
this.node = node;
}
@@ -43,7 +43,7 @@ public class DOMNode extends org.eclipse.help.Node {
* @see org.eclipse.help.Node#appendChild(org.eclipse.help.Node)
*/
public void appendChild(org.eclipse.help.Node newChild) {
- DOMNode newNode = copyNode(newChild);
+ DocumentNode newNode = copyNode(newChild);
node.appendChild(newNode.node);
}
@@ -86,7 +86,7 @@ public class DOMNode extends org.eclipse.help.Node {
for (int i=0;i<list.getLength();++i) {
Node child = list.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE || child.getNodeType() == Node.TEXT_NODE) {
- children.add(new DOMNode(child));
+ children.add(new DocumentNode(child));
}
}
return (org.eclipse.help.Node[])children.toArray(new org.eclipse.help.Node[children.size()]);
@@ -105,7 +105,7 @@ public class DOMNode extends org.eclipse.help.Node {
* @see org.eclipse.help.Node#getParent()
*/
public org.eclipse.help.Node getParent() {
- return new DOMNode(node.getParentNode());
+ return new DocumentNode(node.getParentNode());
}
/* (non-Javadoc)
@@ -119,9 +119,9 @@ public class DOMNode extends org.eclipse.help.Node {
* @see org.eclipse.help.Node#insertBefore(org.eclipse.help.Node, org.eclipse.help.Node)
*/
public void insertBefore(org.eclipse.help.Node newChild, org.eclipse.help.Node refChild) {
- if (refChild instanceof DOMNode) {
- DOMNode newNode = copyNode(newChild);
- node.insertBefore(newNode.node, ((DOMNode)refChild).node);
+ if (refChild instanceof DocumentNode) {
+ DocumentNode newNode = copyNode(newChild);
+ node.insertBefore(newNode.node, ((DocumentNode)refChild).node);
}
}
@@ -139,8 +139,8 @@ public class DOMNode extends org.eclipse.help.Node {
* @see org.eclipse.help.Node#removeChild(org.eclipse.help.Node)
*/
public void removeChild(org.eclipse.help.Node nodeToRemove) {
- if (nodeToRemove instanceof DOMNode) {
- node.removeChild(((DOMNode)nodeToRemove).node);
+ if (nodeToRemove instanceof DocumentNode) {
+ node.removeChild(((DocumentNode)nodeToRemove).node);
}
}
@@ -154,7 +154,7 @@ public class DOMNode extends org.eclipse.help.Node {
/*
* Copies the given node as a DOMNode for this document.
*/
- private DOMNode copyNode(org.eclipse.help.Node nodeToCopy) {
+ private DocumentNode copyNode(org.eclipse.help.Node nodeToCopy) {
// copy the node itself
Document dom = node.getOwnerDocument();
Node newNode;
@@ -174,7 +174,7 @@ public class DOMNode extends org.eclipse.help.Node {
}
// copy children
- DOMNode copy = new DOMNode(newNode);
+ DocumentNode copy = new DocumentNode(newNode);
org.eclipse.help.Node[] children = nodeToCopy.getChildren();
for (int i=0;i<children.length;++i) {
copy.appendChild(children[i]);
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DOMReader.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentReader.java
index 05df239d2..cefcbd793 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DOMReader.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentReader.java
@@ -27,7 +27,7 @@ import org.xml.sax.SAXException;
* A utility class that converts an input stream of XML into a Document
* (a DOM) for processing.
*/
-public class DOMReader {
+public class DocumentReader {
private DocumentBuilder builder;
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DOMWriter.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentWriter.java
index 47a85ce10..b7cdd5768 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DOMWriter.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentWriter.java
@@ -28,7 +28,7 @@ import org.w3c.dom.DocumentType;
/*
* A utility class that converts Documents (DOMs) into XML.
*/
-public class DOMWriter {
+public class DocumentWriter {
private Transformer transformer;
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/ExtensionHandler.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/ExtensionHandler.java
index 7baad9ac4..1274db30f 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/ExtensionHandler.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/ExtensionHandler.java
@@ -10,14 +10,14 @@
*******************************************************************************/
package org.eclipse.help.internal.dynamic;
-import org.eclipse.help.IContentExtension;
import org.eclipse.help.Node;
+import org.eclipse.help.internal.extension.ContentExtension;
/*
* The handler responsible for processing content extensions (contributions
* into anchors and element replacements).
*/
-public class ExtensionHandler extends DocumentProcessorHandler {
+public class ExtensionHandler extends NodeHandler {
private static final String ELEMENT_ANCHOR = "anchor"; //$NON-NLS-1$
private static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
@@ -35,10 +35,10 @@ public class ExtensionHandler extends DocumentProcessorHandler {
public short handle(Node node, String path) {
if (ELEMENT_ANCHOR.equals(node.getName())) {
- return handleExtension(node, path, IContentExtension.CONTRIBUTION);
+ return handleExtension(node, path, ContentExtension.CONTRIBUTION);
}
if (node.getAttribute(ATTRIBUTE_ID) != null) {
- return handleExtension(node, path, IContentExtension.REPLACE);
+ return handleExtension(node, path, ContentExtension.REPLACE);
}
return UNHANDLED;
}
@@ -65,7 +65,7 @@ public class ExtensionHandler extends DocumentProcessorHandler {
}
}
// always remove anchors, even invalid ones
- if (type == IContentExtension.CONTRIBUTION) {
+ if (type == ContentExtension.CONTRIBUTION) {
node.getParent().removeChild(node);
return HANDLED_SKIP;
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/ExtensionResolver.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/ExtensionResolver.java
index 77185e7b8..a748826f3 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/ExtensionResolver.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/ExtensionResolver.java
@@ -18,9 +18,9 @@ import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.help.HelpSystem;
-import org.eclipse.help.IContentExtension;
import org.eclipse.help.Node;
import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.internal.extension.ContentExtension;
import org.eclipse.help.internal.extension.ContentExtensionManager;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
@@ -35,8 +35,8 @@ public class ExtensionResolver {
private static final String ELEMENT_BODY = "body"; //$NON-NLS-1$
private static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
- private DocumentProcessor processor;
- private DOMReader reader;
+ private NodeProcessor processor;
+ private DocumentReader reader;
private String locale;
private ContentExtensionManager manager;
@@ -44,7 +44,7 @@ public class ExtensionResolver {
* Creates the resolver. The processor is needed to process the extension
* content, and locale because we're pulling in content from other documents.
*/
- public ExtensionResolver(DocumentProcessor processor, String locale) {
+ public ExtensionResolver(NodeProcessor processor, String locale) {
this.processor = processor;
this.locale = locale;
}
@@ -56,7 +56,7 @@ public class ExtensionResolver {
if (manager == null) {
manager = HelpPlugin.getContentExtensionManager();
}
- IContentExtension[] extensions = manager.getExtensions(path, type, locale);
+ ContentExtension[] extensions = manager.getExtensions(path, type, locale);
List list = new ArrayList();
for (int i=0;i<extensions.length;++i) {
String content = extensions[i].getContent();
@@ -153,10 +153,10 @@ public class ExtensionResolver {
*/
private Node findNode(InputStream in, String nodeId) throws IOException, SAXException, ParserConfigurationException {
if (reader == null) {
- reader = new DOMReader();
+ reader = new DocumentReader();
}
Document document = reader.read(in);
- Node node = new DOMNode(document);
+ Node node = new DocumentNode(document);
return findNode(node, nodeId);
}
@@ -185,10 +185,10 @@ public class ExtensionResolver {
*/
private Node[] findBody(InputStream in) throws IOException, SAXException, ParserConfigurationException {
if (reader == null) {
- reader = new DOMReader();
+ reader = new DocumentReader();
}
Document document = reader.read(in);
- Node node = new DOMNode(document);
+ Node node = new DocumentNode(document);
return findBody(node);
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/FilterHandler.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/FilterHandler.java
index cadbe3cd1..f421720dd 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/FilterHandler.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/FilterHandler.java
@@ -11,83 +11,26 @@
package org.eclipse.help.internal.dynamic;
import org.eclipse.help.Node;
+import org.eclipse.help.UAContentFilter;
/*
* The handler responsible for filtering elements. Filters can either be
* an attribute of the element to filter, or any number of child filter
* elements.
*/
-public class FilterHandler extends DocumentProcessorHandler {
+public class FilterHandler extends NodeHandler {
- private static final String ELEMENT_FILTER = "filter"; //$NON-NLS-1$
- private static final String ATTRIBUTE_FILTER = "filter"; //$NON-NLS-1$
- private static final String ATTRIBUTE_NAME = "name"; //$NON-NLS-1$
- private static final String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$
-
- private FilterResolver resolver;
-
- public short handle(Node node, String id) {
- if (node.getAttribute(ATTRIBUTE_FILTER) != null) {
- return handleFilterAttribute(node);
- }
- Node[] children = node.getChildren();
- for (int i=0;i<children.length;++i) {
- if (ELEMENT_FILTER.equals(children[i].getName())) {
- return handleFilterNodes(node);
- }
- }
- return UNHANDLED;
- }
-
- /*
- * Handle the filter attribute case.
+ /* (non-Javadoc)
+ * @see org.eclipse.help.internal.dynamic.NodeHandler#handle(org.eclipse.help.Node, java.lang.String)
*/
- private short handleFilterAttribute(Node node) {
- String expression = node.getAttribute(ATTRIBUTE_FILTER);
- if (resolver == null) {
- resolver = new FilterResolver();
- }
- boolean isFiltered = resolver.isFiltered(expression);
- if (isFiltered) {
- node.getParent().removeChild(node);
- return HANDLED_SKIP;
- }
- node.removeAttribute(ATTRIBUTE_FILTER);
- return HANDLED_CONTINUE;
- }
-
- /*
- * Handle the child filter node case.
- */
- private short handleFilterNodes(Node node) {
- boolean hasFilterFailedYet = false;
- Node[] children = node.getChildren();
- for (int i=0;i<children.length;++i) {
- Node child = children[i];
- // is it a filter node?
- if (ELEMENT_FILTER.equals(child.getName())) {
- // if it already failed, don't bother evaluating the rest
- if (!hasFilterFailedYet) {
- String name = child.getAttribute(ATTRIBUTE_NAME);
- String value = child.getAttribute(ATTRIBUTE_VALUE);
- if (name != null && value != null && name.length() > 0 && value.length() > 0) {
- boolean not = (value.charAt(0) == '!');
- if (not) {
- value = value.substring(1);
- }
- hasFilterFailedYet = resolver.isFiltered(name, value, not);
- }
- }
- // remove all filter elements
- node.removeChild(child);
+ public short handle(Node node, String id) {
+ if (UAContentFilter.isFiltered(node)) {
+ Node parent = node.getParent();
+ if (parent != null) {
+ parent.removeChild(node);
}
- }
- if (hasFilterFailedYet) {
- // at least one filter didn't pass
- node.getParent().removeChild(node);
return HANDLED_SKIP;
}
- // all filters passed; continue with children
- return HANDLED_CONTINUE;
+ return UNHANDLED;
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/IncludeHandler.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/IncludeHandler.java
index a9f8151e9..772675014 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/IncludeHandler.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/IncludeHandler.java
@@ -16,7 +16,7 @@ import org.eclipse.help.Node;
* The handler responsible for processing includes, where a node is pulled
* in from another document.
*/
-public class IncludeHandler extends DocumentProcessorHandler {
+public class IncludeHandler extends NodeHandler {
private static final String ELEMENT_INCLUDE = "include"; //$NON-NLS-1$
private static final String ATTRIBUTE_PATH = "path"; //$NON-NLS-1$
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/IncludeResolver.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/IncludeResolver.java
index cc071224d..5d24f3e3d 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/IncludeResolver.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/IncludeResolver.java
@@ -28,15 +28,15 @@ public class IncludeResolver {
private static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
- private DocumentProcessor processor;
- private DOMReader reader;
+ private NodeProcessor processor;
+ private DocumentReader reader;
private String locale;
/*
* Creates the resolver. It must have a DOMProcessor for processing the
* included content, and must know the locale of the content to include.
*/
- public IncludeResolver(DocumentProcessor processor, String locale) {
+ public IncludeResolver(NodeProcessor processor, String locale) {
this.processor = processor;
this.locale = locale;
}
@@ -65,10 +65,10 @@ public class IncludeResolver {
*/
private Node findNode(InputStream in, String nodeId) throws IOException, SAXException, ParserConfigurationException {
if (reader == null) {
- reader = new DOMReader();
+ reader = new DocumentReader();
}
Document document = reader.read(in);
- DOMNode node = new DOMNode(document);
+ DocumentNode node = new DocumentNode(document);
return findNode(node, nodeId);
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentProcessorHandler.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeHandler.java
index a47fda888..deede0d0c 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentProcessorHandler.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeHandler.java
@@ -16,13 +16,13 @@ import org.eclipse.help.Node;
* A handler that is notified when the document processor visits a node,
* allowing it to process the node and return a result.
*/
-public abstract class DocumentProcessorHandler {
+public abstract class NodeHandler {
public static final short UNHANDLED = 0;
public static final short HANDLED_CONTINUE = 1;
public static final short HANDLED_SKIP = 2;
- private DocumentProcessor processor;
+ private NodeProcessor processor;
/*
* Will be called for every node visited by the processor,
@@ -33,7 +33,7 @@ public abstract class DocumentProcessorHandler {
/*
* Returns the processor that is calling this handler.
*/
- public DocumentProcessor getProcessor() {
+ public NodeProcessor getProcessor() {
return processor;
}
@@ -41,7 +41,7 @@ public abstract class DocumentProcessorHandler {
* Sets the processor that is calling this handler. This should only
* be called by the processor.
*/
- public void setProcessor(DocumentProcessor processor) {
+ public void setProcessor(NodeProcessor processor) {
this.processor = processor;
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentProcessor.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeProcessor.java
index 352351416..ded3d01c3 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentProcessor.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeProcessor.java
@@ -16,18 +16,22 @@ import org.eclipse.help.Node;
* A document processor that traverses every node of a document and allows
* handlers to perform operations on the nodes.
*/
-public class DocumentProcessor {
+public class NodeProcessor {
- private DocumentProcessorHandler[] handlers;
+ private NodeHandler[] handlers;
+
+ /*
+ * Creates a processor with no handlers.
+ */
+ public NodeProcessor() {
+ handlers = new NodeHandler[0];
+ }
/*
* Creates a processor with the given handlers.
*/
- public DocumentProcessor(DocumentProcessorHandler[] handlers) {
- this.handlers = handlers;
- for (int i=0;i<handlers.length;++i) {
- handlers[i].setProcessor(this);
- }
+ public NodeProcessor(NodeHandler[] handlers) {
+ setHandlers(handlers);
}
/*
@@ -37,11 +41,11 @@ public class DocumentProcessor {
public void process(Node node, String id) {
for (int i=0;i<handlers.length;++i) {
short result = handlers[i].handle(node, id);
- if (result == DocumentProcessorHandler.HANDLED_CONTINUE) {
+ if (result == NodeHandler.HANDLED_CONTINUE) {
// handler wants us to keep processing children
break;
}
- if (result == DocumentProcessorHandler.HANDLED_SKIP) {
+ if (result == NodeHandler.HANDLED_SKIP) {
// handler wants us to skip children
return;
}
@@ -52,4 +56,16 @@ public class DocumentProcessor {
process(children[i], id);
}
}
+
+ /*
+ * Sets the handlers for this processor.
+ */
+ public void setHandlers(NodeHandler[] handlers) {
+ if (this.handlers != handlers) {
+ this.handlers = handlers;
+ for (int i=0;i<handlers.length;++i) {
+ handlers[i].setProcessor(this);
+ }
+ }
+ }
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeReader.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeReader.java
new file mode 100644
index 000000000..2486b9af8
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeReader.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * 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.help.internal.dynamic;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Stack;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.eclipse.help.Node;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class NodeReader extends DefaultHandler {
+
+ private SAXParser parser;
+ private Stack stack;
+ private Node root;
+
+ public Node read(InputStream in) throws ParserConfigurationException, SAXException, IOException {
+ root = null;
+ if (parser == null) {
+ parser = SAXParserFactory.newInstance().newSAXParser();
+ }
+ if (stack == null) {
+ stack = new Stack();
+ }
+ else {
+ stack.clear();
+ }
+ parser.parse(in, this);
+ return root;
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+ */
+ public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
+ Node node = new Node();
+ node.setName(name);
+ int len = attributes.getLength();
+ for (int i=0;i<len;++i) {
+ node.setAttribute(attributes.getQName(i), attributes.getValue(i));
+ }
+ if (!stack.isEmpty()) {
+ Node parent = (Node)stack.peek();
+ parent.appendChild(node);
+ }
+ else {
+ root = node;
+ }
+ stack.push(node);
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void endElement(String uri, String localName, String name) throws SAXException {
+ stack.pop();
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
+ */
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ if (!stack.isEmpty()) {
+ String text = new String(ch, start, length);
+ if (text.trim().length() > 0) {
+ Node node = new Node();
+ node.setValue(text);
+ Node parent = (Node)stack.peek();
+ parent.appendChild(node);
+ }
+ }
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeWriter.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeWriter.java
new file mode 100644
index 000000000..e64cbaa9a
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/NodeWriter.java
@@ -0,0 +1,85 @@
+package org.eclipse.help.internal.dynamic;
+
+import java.util.Iterator;
+
+import org.eclipse.help.Node;
+
+public class NodeWriter {
+
+ private static final char SPECIAL_CHARS[] = { '&', '>', '<', '"', '\'' };
+ private static final String ESCAPED_CHARS[] = { "&amp;", "&gt;", "&lt;", "&quot;", "&apos;" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+
+ public void write(Node node, StringBuffer buf, boolean format, String indent, boolean escape) {
+ if (node.getName() != null) {
+ if (format) {
+ buf.append(indent);
+ }
+ buf.append('<');
+ buf.append(node.getName());
+
+ Iterator iter = node.getAttributes().iterator();
+ while (iter.hasNext()) {
+ buf.append(' ');
+ String name = (String)iter.next();
+ String value = node.getAttribute(name);
+ buf.append(name);
+ buf.append('=');
+ buf.append('"');
+ buf.append(escape ? xmlEscape(value) : value);
+ buf.append('"');
+ }
+
+ Node[] children = node.getChildren();
+ boolean hasChildren = children.length > 0;
+ if (hasChildren) {
+ buf.append('>');
+ if (format) {
+ buf.append('\n');
+ }
+ String childIndent = indent + " "; //$NON-NLS-1$
+ for (int i=0;i<children.length;++i) {
+ write(children[i], buf, format, childIndent, escape);
+ }
+ if (format) {
+ buf.append(indent);
+ }
+ buf.append('<');
+ buf.append('/');
+ buf.append(node.getName());
+ buf.append('>');
+ }
+ else {
+ buf.append('/');
+ buf.append('>');
+ }
+ if (format) {
+ buf.append('\n');
+ }
+ }
+ else {
+ if (format) {
+ buf.append(indent);
+ }
+ buf.append(escape ? xmlEscape(node.getValue()) : node.getValue());
+ }
+ }
+
+ public static String xmlEscape(String text) {
+ StringBuffer buf = new StringBuffer(text.length());
+ char[] array = text.toCharArray();
+ for (int i=0;i<array.length;++i) {
+ boolean escaped = false;
+ for (int j=0;j<SPECIAL_CHARS.length;++j) {
+ if (array[i] == SPECIAL_CHARS[j]) {
+ buf.append(ESCAPED_CHARS[j]);
+ escaped = true;
+ break;
+ }
+ }
+ if (!escaped) {
+ buf.append(array[i]);
+ }
+ }
+ return buf.toString();
+ }
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/XMLProcessor.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/XMLProcessor.java
index d8906b8b7..c24fb3022 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/XMLProcessor.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/XMLProcessor.java
@@ -26,15 +26,15 @@ import org.xml.sax.SAXException;
*/
public class XMLProcessor {
- private DocumentProcessor processor;
- private DOMReader reader;
- private DOMWriter writer;
+ private NodeProcessor processor;
+ private DocumentReader reader;
+ private DocumentWriter writer;
/*
* Creates the processor, which will use the given handlers.
*/
- public XMLProcessor(DocumentProcessorHandler[] handlers) {
- processor = new DocumentProcessor(handlers);
+ public XMLProcessor(NodeHandler[] handlers) {
+ processor = new NodeProcessor(handlers);
}
/*
@@ -43,13 +43,13 @@ public class XMLProcessor {
*/
public InputStream process(InputStream in, String id) throws IOException, SAXException, ParserConfigurationException, TransformerException, TransformerConfigurationException {
if (reader == null) {
- reader = new DOMReader();
+ reader = new DocumentReader();
}
Document document = reader.read(in);
- DOMNode node = new DOMNode(document);
+ DocumentNode node = new DocumentNode(document);
processor.process(node, id);
if (writer == null) {
- writer = new DOMWriter();
+ writer = new DocumentWriter();
}
return writer.write(document);
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtension.java b/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtension.java
index 9438f00b5..a325b11f8 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtension.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtension.java
@@ -10,44 +10,81 @@
*******************************************************************************/
package org.eclipse.help.internal.extension;
-import org.eclipse.help.IContentExtension;
+import org.eclipse.help.Node;
+import org.eclipse.help.internal.NodeAdapter;
/*
- * A concrete model element that implements IContentExtension.
+ * Adapts a "context" Node and provides convenience methods for operating
+ * on it. All methods operate on the underlying adapted Node.
*/
-public class ContentExtension implements IContentExtension {
+public class ContentExtension extends NodeAdapter {
- private String content;
- private String path;
- private int type;
+ private static final String NAME_CONTRIBUTION = "topicExtension"; //$NON-NLS-1$
+ private static final String NAME_REPLACE = "topicReplace"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_CONTENT = "content"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_PATH = "path"; //$NON-NLS-1$
+
+ // type for contribution into anchor
+ public static final int CONTRIBUTION = 0;
+
+ // type for element replacement
+ public static final int REPLACE = 1;
/*
- * Creates the extension with the given info.
+ * Constructs a new content extension adapter for an empty extension node.
+ * (contribution type by default).
*/
- public ContentExtension(String content, String path, int type) {
- this.content = content;
- this.path = path;
- this.type = type;
+ public ContentExtension() {
+ super();
+ setName(NAME_CONTRIBUTION);
}
- /* (non-Javadoc)
- * @see org.eclipse.help.IContentExtension#getContent()
+ /*
+ * Constructs a new adapter for the given content extension node.
+ */
+ public ContentExtension(Node node) {
+ super(node);
+ }
+
+ /*
+ * Returns the extension's content.
*/
public String getContent() {
- return content;
+ return getAttribute(ATTRIBUTE_CONTENT);
}
- /* (non-Javadoc)
- * @see org.eclipse.help.IContentExtension#getPath()
+ /*
+ * Returns the extensions target path.
*/
public String getPath() {
- return path;
+ return getAttribute(ATTRIBUTE_PATH);
}
- /* (non-Javadoc)
- * @see org.eclipse.help.IContentExtension#getType()
+ /*
+ * Returns the extension type (either a contribution or replace).
*/
public int getType() {
- return type;
+ return (getName().equals(NAME_CONTRIBUTION)) ? CONTRIBUTION : REPLACE;
+ }
+
+ /*
+ * Sets the extension's content.
+ */
+ public void setContent(String content) {
+ setAttribute(ATTRIBUTE_CONTENT, content);
+ }
+
+ /*
+ * Sets the extension's target path.
+ */
+ public void setPath(String path) {
+ setAttribute(ATTRIBUTE_PATH, path);
+ }
+
+ /*
+ * Sets the extension type.
+ */
+ public void setType(int type) {
+ setName(type == CONTRIBUTION ? NAME_CONTRIBUTION : NAME_REPLACE);
}
} \ No newline at end of file
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionFileParser.java b/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionFileParser.java
index b591bd175..6e142c495 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionFileParser.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionFileParser.java
@@ -13,17 +13,12 @@ package org.eclipse.help.internal.extension;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import org.eclipse.help.IContentExtension;
-import org.eclipse.help.internal.HelpPlugin;
+import org.eclipse.help.Node;
+import org.eclipse.help.internal.dynamic.NodeReader;
import org.osgi.framework.Bundle;
-import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@@ -32,129 +27,21 @@ import org.xml.sax.helpers.DefaultHandler;
*/
public class ContentExtensionFileParser extends DefaultHandler {
- private static final String ELEMENT_TOPIC_EXTENSION = "topicExtension"; //$NON-NLS-1$
- private static final String ELEMENT_TOPIC_REPLACE = "topicReplace"; //$NON-NLS-1$
- private static final String ATTRIBUTE_CONTENT = "content"; //$NON-NLS-1$
- private static final String ATTRIBUTE_PATH = "path"; //$NON-NLS-1$
-
- private SAXParser parser;
- private String bundleId;
- private String path;
- private List extensions;
+ private NodeReader reader;
/*
- * Parses the file at the specified path in the bundle and returns
- * model elements describing the extensions contained within.
+ * Parses the specified content extension XML file into model elements.
*/
- public IContentExtension[] parse(Bundle bundle, String path) throws IOException, SAXException, ParserConfigurationException {
- this.path = path;
- if (extensions == null) {
- extensions = new ArrayList();
- }
- else {
- extensions.clear();
- }
+ public Node[] parse(Bundle bundle, String path) throws IOException, SAXException, ParserConfigurationException {
+ if (reader == null) {
+ reader = new NodeReader();
+ }
URL url = bundle.getEntry(path);
if (url != null) {
- bundleId = bundle.getSymbolicName();
InputStream in = url.openStream();
- try {
- if (parser == null) {
- parser = SAXParserFactory.newInstance().newSAXParser();
- }
- parser.parse(in, this);
- }
- finally {
- try {
- in.close();
- }
- catch (IOException e) {}
- }
- }
- return (IContentExtension[])extensions.toArray(new IContentExtension[extensions.size()]);
- }
-
- /* (non-Javadoc)
- * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
- */
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
- int type = -1;
- if (ELEMENT_TOPIC_EXTENSION.equals(qName)) {
- type = IContentExtension.CONTRIBUTION;
- }
- else if (ELEMENT_TOPIC_REPLACE.equals(qName)) {
- type = IContentExtension.REPLACE;
- }
- if (type != -1) {
- String content = attributes.getValue(ATTRIBUTE_CONTENT);
- if (content != null) {
- content = '/' + bundleId + normalizePath(content);
- String path = attributes.getValue(ATTRIBUTE_PATH);
- if (path != null) {
- extensions.add(new ContentExtension(content, normalizePath(path), type));
- }
- else {
- logError(ATTRIBUTE_PATH, qName);
- }
- }
- else {
- logError(ATTRIBUTE_CONTENT, qName);
- }
+ Node node = reader.read(in);
+ return node.getChildren();
}
- }
-
- /*
- * Normalizes the given path by adding a leading slash if one doesn't
- * exist, and converting the final slash into a '#' if it is thought to
- * separate the end of the document with the element (legacy form).
- */
- private String normalizePath(String path) {
- int bundleStart, bundleEnd;
- int pathStart, pathEnd;
- int elementStart, elementEnd;
-
- bundleStart = path.charAt(0) == '/' ? 1 : 0;
- bundleEnd = path.indexOf('/', bundleStart);
-
- pathStart = bundleEnd + 1;
- pathEnd = path.indexOf('#', pathStart);
- if (pathEnd == -1) {
- int lastSlash = path.lastIndexOf('/');
- if (lastSlash > 0) {
- int secondLastSlash = path.lastIndexOf('/', lastSlash - 1);
- if (secondLastSlash != -1) {
- String secondLastToken = path.substring(secondLastSlash, lastSlash);
- boolean hasDot = (secondLastToken.indexOf('.') != -1);
- if (hasDot) {
- pathEnd = lastSlash;
- }
- }
- }
- if (pathEnd == -1) {
- pathEnd = path.length();
- }
- }
-
- elementStart = Math.min(pathEnd + 1, path.length());
- elementEnd = path.length();
-
- if (bundleEnd > bundleStart && pathStart > bundleEnd && pathEnd > pathStart && elementStart >= pathEnd && elementEnd >= elementStart) {
- String bundleId = path.substring(bundleStart, bundleEnd);
- String relativePath = path.substring(pathStart, pathEnd);
- String elementId = path.substring(elementStart, elementEnd);
- path = '/' + bundleId + '/' + relativePath;
- if (elementId.length() > 0) {
- path += '#' + elementId;
- }
- }
- return path;
- }
-
- /*
- * Logs an error about a missing attribute.
- */
- private void logError(String attribute, String element) {
- String msg = "Required attribute " + attribute + " missing from element " + element + " in /" + bundleId + "/" + path; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- HelpPlugin.logError(msg, null);
- }
+ return new Node[0];
+ }
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionFileProvider.java b/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionFileProvider.java
index 041ee8f69..89038d194 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionFileProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionFileProvider.java
@@ -17,7 +17,7 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.AbstractContentExtensionProvider;
-import org.eclipse.help.IContentExtension;
+import org.eclipse.help.Node;
import org.eclipse.help.internal.HelpPlugin;
import org.osgi.framework.Bundle;
@@ -27,27 +27,32 @@ import org.osgi.framework.Bundle;
*/
public class ContentExtensionFileProvider extends AbstractContentExtensionProvider {
- private static final String EXTENSION_POINT_ID_CONTENT_EXTENSION = HelpPlugin.PLUGIN_ID + ".contentExtension"; //$NON-NLS-1$
- private static final String ELEMENT_NAME_CONTENT_EXTENSION = "contentExtension"; //$NON-NLS-1$
- private static final String ATTRIBUTE_NAME_FILE = "file"; //$NON-NLS-1$
+ private static final String EXTENSION_POINT_CONTENT_EXTENSION = HelpPlugin.PLUGIN_ID + ".contentExtension"; //$NON-NLS-1$
+ private static final String ELEMENT_CONTENT_EXTENSION = "contentExtension"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_FILE = "file"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_CONTENT = "content"; //$NON-NLS-1$
/* (non-Javadoc)
* @see org.eclipse.help.AbstractContentExtensionProvider#getContentExtensions(java.lang.String)
*/
- public IContentExtension[] getContentExtensions(String locale) {
+ public Node[] getContentExtensions(String locale) {
List extensions = new ArrayList();
IExtensionRegistry registry = Platform.getExtensionRegistry();
ContentExtensionFileParser parser = new ContentExtensionFileParser();
- IConfigurationElement[] elements = registry.getConfigurationElementsFor(EXTENSION_POINT_ID_CONTENT_EXTENSION);
+ IConfigurationElement[] elements = registry.getConfigurationElementsFor(EXTENSION_POINT_CONTENT_EXTENSION);
for (int i=0;i<elements.length;++i) {
- if (ELEMENT_NAME_CONTENT_EXTENSION.equals(elements[i].getName())) {
- String file = elements[i].getAttribute(ATTRIBUTE_NAME_FILE);
+ if (ELEMENT_CONTENT_EXTENSION.equals(elements[i].getName())) {
+ String file = elements[i].getAttribute(ATTRIBUTE_FILE);
String bundleId = elements[i].getContributor().getName();
Bundle bundle = Platform.getBundle(bundleId);
if (bundle != null) {
try {
- IContentExtension[] ext = parser.parse(bundle, file);
+ Node[] ext = parser.parse(bundle, file);
for (int j=0;j<ext.length;++j) {
+ String content = ext[j].getAttribute(ATTRIBUTE_CONTENT);
+ if (content != null) {
+ ext[j].setAttribute(ATTRIBUTE_CONTENT, '/' + bundleId + '/' + content);
+ }
extensions.add(ext[j]);
}
}
@@ -58,6 +63,6 @@ public class ContentExtensionFileProvider extends AbstractContentExtensionProvid
}
}
}
- return (IContentExtension[])extensions.toArray(new IContentExtension[extensions.size()]);
+ return (Node[])extensions.toArray(new Node[extensions.size()]);
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionManager.java b/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionManager.java
index 18fab060f..253c8fb7d 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionManager.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionManager.java
@@ -23,19 +23,19 @@ import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.AbstractContentExtensionProvider;
-import org.eclipse.help.IContentExtension;
+import org.eclipse.help.Node;
import org.eclipse.help.internal.HelpPlugin;
/*
* Manages content extensions (contributions into anchors and element
- * replacements).
+ * replacements) for user assistance documents.
*/
public class ContentExtensionManager {
private static final String EXTENSION_POINT_ID_CONTENT_EXTENSION = HelpPlugin.PLUGIN_ID + ".contentExtension"; //$NON-NLS-1$
private static final String ELEMENT_NAME_CONTENT_EXTENSION_PROVIDER = "contentExtensionProvider"; //$NON-NLS-1$
private static final String ATTRIBUTE_NAME_CLASS = "class"; //$NON-NLS-1$
- private static final IContentExtension[] EMPTY_ARRAY = new IContentExtension[0];
+ private static final ContentExtension[] EMPTY_ARRAY = new ContentExtension[0];
private AbstractContentExtensionProvider[] contentExtensionProviders;
private Map extensionsByPath;
@@ -44,7 +44,7 @@ public class ContentExtensionManager {
/*
* Returns all known extensions for the given locale.
*/
- public IContentExtension[] getExtensions(String locale) {
+ public ContentExtension[] getExtensions(String locale) {
if (extensionsByPath == null) {
loadExtensions(locale);
}
@@ -57,20 +57,20 @@ public class ContentExtensionManager {
while (iter.hasNext()) {
extensions.addAll((Collection)iter.next());
}
- return (IContentExtension[])extensions.toArray(new IContentExtension[extensions.size()]);
+ return (ContentExtension[])extensions.toArray(new ContentExtension[extensions.size()]);
}
/*
* Get all extensions of the given type whose target matches the given path.
*/
- public IContentExtension[] getExtensions(String path, int type, String locale) {
+ public ContentExtension[] getExtensions(String path, int type, String locale) {
if (extensionsByPath == null) {
loadExtensions(locale);
}
- Map map = (type == IContentExtension.CONTRIBUTION ? extensionsByPath : replacesByPath);
+ Map map = (type == ContentExtension.CONTRIBUTION ? extensionsByPath : replacesByPath);
List extensions = (List)map.get(path);
if (extensions != null) {
- return (IContentExtension[])extensions.toArray(new IContentExtension[extensions.size()]);
+ return (ContentExtension[])extensions.toArray(new ContentExtension[extensions.size()]);
}
return EMPTY_ARRAY;
}
@@ -97,9 +97,16 @@ public class ContentExtensionManager {
replacesByPath = new HashMap();
contentExtensionProviders = getContentExtensionProviders();
for (int i=0;i<contentExtensionProviders.length;++i) {
- IContentExtension[] extensions;
+ ContentExtension[] extensions;
try {
- extensions = contentExtensionProviders[i].getContentExtensions(locale);
+ Node[] nodes = contentExtensionProviders[i].getContentExtensions(locale);
+ extensions = new ContentExtension[nodes.length];
+ for (int j=0;j<nodes.length;++j) {
+ ContentExtension ext = new ContentExtension(nodes[j]);
+ ext.setContent(normalizePath(ext.getContent()));
+ ext.setPath(normalizePath(ext.getPath()));
+ extensions[j] = ext;
+ }
}
catch (Throwable t) {
String msg = "An error occured while querying one of the user assistance content extension providers (" + contentExtensionProviders[i] + ')'; //$NON-NLS-1$
@@ -108,8 +115,8 @@ public class ContentExtensionManager {
}
for (int j=0;j<extensions.length;++j) {
try {
- ContentExtension ext = ContentExtensionPrefetcher.prefetch(extensions[j]);
- Map map = (ext.getType() == IContentExtension.CONTRIBUTION ? extensionsByPath : replacesByPath);
+ ContentExtension ext = extensions[j];
+ Map map = (ext.getType() == ContentExtension.CONTRIBUTION ? extensionsByPath : replacesByPath);
List list = (List)map.get(ext.getPath());
if (list == null) {
list = new ArrayList();
@@ -175,4 +182,51 @@ public class ContentExtensionManager {
}
return contentExtensionProviders;
}
+
+ /*
+ * Normalizes the given path by adding a leading slash if one doesn't
+ * exist, and converting the final slash into a '#' if it is thought to
+ * separate the end of the document with the element (legacy form).
+ */
+ private String normalizePath(String path) {
+ int bundleStart, bundleEnd;
+ int pathStart, pathEnd;
+ int elementStart, elementEnd;
+
+ bundleStart = path.charAt(0) == '/' ? 1 : 0;
+ bundleEnd = path.indexOf('/', bundleStart);
+
+ pathStart = bundleEnd + 1;
+ pathEnd = path.indexOf('#', pathStart);
+ if (pathEnd == -1) {
+ int lastSlash = path.lastIndexOf('/');
+ if (lastSlash > 0) {
+ int secondLastSlash = path.lastIndexOf('/', lastSlash - 1);
+ if (secondLastSlash != -1) {
+ String secondLastToken = path.substring(secondLastSlash, lastSlash);
+ boolean hasDot = (secondLastToken.indexOf('.') != -1);
+ if (hasDot) {
+ pathEnd = lastSlash;
+ }
+ }
+ }
+ if (pathEnd == -1) {
+ pathEnd = path.length();
+ }
+ }
+
+ elementStart = Math.min(pathEnd + 1, path.length());
+ elementEnd = path.length();
+
+ if (bundleEnd > bundleStart && pathStart > bundleEnd && pathEnd > pathStart && elementStart >= pathEnd && elementEnd >= elementStart) {
+ String bundleId = path.substring(bundleStart, bundleEnd);
+ String relativePath = path.substring(pathStart, pathEnd);
+ String elementId = path.substring(elementStart, elementEnd);
+ path = '/' + bundleId + '/' + relativePath;
+ if (elementId.length() > 0) {
+ path += '#' + elementId;
+ }
+ }
+ return path;
+ }
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionPrefetcher.java b/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionPrefetcher.java
deleted file mode 100644
index 60f88ca00..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/extension/ContentExtensionPrefetcher.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.extension;
-
-import org.eclipse.help.IContentExtension;
-
-/*
- * Fetches all data from the given extension interface and caches it into
- * a model element, for later performance and safety.
- */
-public class ContentExtensionPrefetcher {
-
- /*
- * Prefetches the given content extension.
- */
- public static ContentExtension prefetch(IContentExtension original) {
- String content = original.getContent();
- String path = original.getPath();
- int type = original.getType();
- return new ContentExtension(content, path, type);
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/index/Index.java b/org.eclipse.help/src/org/eclipse/help/internal/index/Index.java
index 9a88f186d..9774cba3b 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/index/Index.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/index/Index.java
@@ -11,37 +11,38 @@
*******************************************************************************/
package org.eclipse.help.internal.index;
-import java.util.ArrayList;
-import java.util.List;
-
import org.eclipse.help.IIndex;
import org.eclipse.help.IIndexEntry;
-import org.eclipse.help.INode;
-import org.eclipse.help.internal.Node;
+import org.eclipse.help.Node;
+import org.eclipse.help.internal.NodeAdapter;
/*
- * Help index implementation
+ * Adapts a "index" Node as an IIndex. All methods operate on the
+ * underlying adapted Node.
*/
-public class Index extends Node implements IIndex {
+public class Index extends NodeAdapter implements IIndex {
- private IIndexEntry[] entries;
+ public static final String NAME = "index"; //$NON-NLS-1$
+
+ /*
+ * Constructs a new index adapter for an empty index node.
+ */
+ public Index() {
+ super();
+ setName(NAME);
+ }
+
+ /*
+ * Constructs a new index adapter for the given index node.
+ */
+ public Index(Node node) {
+ super(node);
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IIndex#getEntries()
+ */
public IIndexEntry[] getEntries() {
- if (entries == null) {
- INode[] children = getChildren();
- if (children.length > 0) {
- List list = new ArrayList();
- for (int i=0;i<children.length;++i) {
- if (children[i] instanceof IIndexEntry) {
- list.add(children[i]);
- }
- }
- entries = (IIndexEntry[])list.toArray(new IIndexEntry[list.size()]);
- }
- else {
- entries = new IIndexEntry[0];
- }
- }
- return entries;
+ return (IndexEntry[])getChildren(IndexEntry.NAME, IndexEntry.class);
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexAssembler.java b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexAssembler.java
index 284b35595..e4eab173c 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexAssembler.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexAssembler.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.help.internal.index;
+import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
@@ -19,14 +20,13 @@ import java.util.Map;
import java.util.Set;
import org.eclipse.help.HelpSystem;
-import org.eclipse.help.IIndex;
-import org.eclipse.help.IIndexEntry;
import org.eclipse.help.IToc;
import org.eclipse.help.ITopic;
+import org.eclipse.help.IndexContribution;
+import org.eclipse.help.Node;
import org.eclipse.help.internal.HelpPlugin;
-import org.eclipse.help.internal.Node;
+import org.eclipse.help.internal.Topic;
import org.eclipse.help.internal.toc.TocManager;
-import org.eclipse.help.internal.toc.Topic;
/*
* Assembles individual keyword index contributions into a complete, fully
@@ -43,7 +43,7 @@ public class IndexAssembler {
* Assembles the given index contributions into a complete, sorted index.
* The originals are not modified.
*/
- public IIndex assemble(List contributions) {
+ public Index assemble(List contributions) {
this.contributions = contributions;
processMerge();
processTopics();
@@ -59,7 +59,7 @@ public class IndexAssembler {
Iterator iter = contributions.iterator();
while (iter.hasNext()) {
IndexContribution contribution = (IndexContribution)iter.next();
- mergeChildren(index, (Index)contribution.getIndex());
+ mergeChildren(index, contribution.getIndex());
}
}
@@ -73,39 +73,39 @@ public class IndexAssembler {
// create data structures for fast lookup
Map entriesByKeyword = new HashMap();
Set topicHrefs = new HashSet();
- Node[] childrenA = a.getChildrenInternal();
+ Node[] childrenA = a.getChildren();
for (int i=0;i<childrenA.length;++i) {
Node childA = childrenA[i];
- if (childA instanceof IndexEntry) {
- entriesByKeyword.put(((IndexEntry)childA).getKeyword(), childA);
+ if (IndexEntry.NAME.equals(childA.getName())) {
+ entriesByKeyword.put(childA.getAttribute(IndexEntry.ATTRIBUTE_KEYWORD), childA);
}
- else if (childA instanceof Topic) {
- topicHrefs.add(((Topic)childA).getHref());
+ else if (Topic.NAME.equals(childA.getName())) {
+ topicHrefs.add(childA.getAttribute(Topic.ATTRIBUTE_HREF));
}
}
// now do the merge
- Node[] childrenB = b.getChildrenInternal();
+ Node[] childrenB = b.getChildren();
for (int i=0;i<childrenB.length;++i) {
Node childB = childrenB[i];
- if (childB instanceof IndexEntry) {
- String keyword = ((IndexEntry)childB).getKeyword();
+ if (IndexEntry.NAME.equals(childB.getName())) {
+ String keyword = childB.getAttribute(IndexEntry.ATTRIBUTE_KEYWORD);
if (entriesByKeyword.containsKey(keyword)) {
// duplicate keyword; merge children
- mergeChildren((IndexEntry)entriesByKeyword.get(keyword), childB);
+ mergeChildren((Node)entriesByKeyword.get(keyword), childB);
}
else {
// wasn't a duplicate
- a.addChild(childB);
+ a.appendChild(childB);
entriesByKeyword.put(keyword, childB);
}
}
- else if (childB instanceof Topic) {
- String href = ((Topic)childB).getHref();
+ else if (Topic.NAME.equals(childB.getName())) {
+ String href = childB.getAttribute(Topic.ATTRIBUTE_HREF);
if (!topicHrefs.contains(href)) {
// add topic only if href doesn't exist yet
- a.addChild(childB);
- topicHrefs.add(((Topic)childB).getHref());
+ a.appendChild(childB);
+ topicHrefs.add(href);
}
}
}
@@ -123,12 +123,12 @@ public class IndexAssembler {
* topics first, then entries, etc. Then within each
* group, sort alphabetically.
*/
- int c1 = getCategory(o1);
- int c2 = getCategory(o2);
+ int c1 = getCategory((Node)o1);
+ int c2 = getCategory((Node)o2);
if (c1 == c2) {
// same type of object; compare alphabetically
- String s1 = getLabel(o1).toLowerCase();
- String s2 = getLabel(o2).toLowerCase();
+ String s1 = getLabel((Node)o1).toLowerCase();
+ String s2 = getLabel((Node)o2).toLowerCase();
return s1.compareTo(s2);
}
else {
@@ -141,19 +141,19 @@ public class IndexAssembler {
}
/*
- * Returns the category of the object. The order is:
+ * Returns the category of the node. The order is:
* 1. topics
* 2. entries starting with non-alphanumeric
* 3. entries starting with digit
* 4. entries starting with alpha
* 5. other
*/
- private static int getCategory(Object o) {
- if (o instanceof ITopic) {
+ private static int getCategory(Node node) {
+ if (Topic.NAME.equals(node.getName())) {
return 0;
}
- else if (o instanceof IIndexEntry) {
- String keyword = ((IIndexEntry)o).getKeyword();
+ else if (IndexEntry.NAME.equals(node.getName())) {
+ String keyword = node.getAttribute(IndexEntry.ATTRIBUTE_KEYWORD);
if (keyword != null && keyword.length() > 0) {
char c = keyword.charAt(0);
if (Character.isDigit(c)) {
@@ -175,15 +175,15 @@ public class IndexAssembler {
* Returns the string that will be displayed for the given object,
* used for sorting.
*/
- private static String getLabel(Object o) {
- if (o instanceof ITopic) {
- return ((ITopic)o).getLabel();
+ private static String getLabel(Node node) {
+ if (Topic.NAME.equals(node.getName())) {
+ return node.getAttribute(Topic.ATTRIBUTE_LABEL);
}
- else if (o instanceof IIndexEntry) {
- return ((IIndexEntry)o).getKeyword();
+ else if (IndexEntry.NAME.equals(node.getName())) {
+ return node.getAttribute(IndexEntry.ATTRIBUTE_KEYWORD);
}
else {
- return o.toString();
+ return node.getName();
}
}
@@ -192,7 +192,7 @@ public class IndexAssembler {
* ignored tocs.
*/
private void processTopics() {
- processTopics(index.getChildrenInternal());
+ processTopics(index.getChildren());
}
/*
@@ -201,8 +201,8 @@ public class IndexAssembler {
*/
private void processTopics(Node[] nodes) {
for (int i=0;i<nodes.length;++i) {
- if (nodes[i] instanceof Topic) {
- Topic topic = (Topic)nodes[i];
+ if (Topic.NAME.equals(nodes[i].getName())) {
+ Topic topic = nodes[i] instanceof Topic ? (Topic)nodes[i] : new Topic(nodes[i]);
String label = topic.getLabel();
String href = topic.getHref();
boolean isLabelEmpty = (label == null || label.length() == 0);
@@ -221,10 +221,10 @@ public class IndexAssembler {
topic.setLabel(""); //$NON-NLS-1$
}
if (tocManager.isTopicIgnored(href)) {
- topic.getParentInternal().removeChild(topic);
+ topic.getParent().removeChild(nodes[i]);
}
}
- Node[] children = nodes[i].getChildrenInternal();
+ Node[] children = nodes[i].getChildren();
processTopics(children);
}
}
@@ -234,8 +234,17 @@ public class IndexAssembler {
* Comparator.
*/
private void sort(Node node, Comparator c) {
- node.sortChildren(c);
- Node[] children = node.getChildrenInternal();
+ // sort children
+ Node[] children = node.getChildren();
+ for (int i=0;i<children.length;++i) {
+ node.removeChild(children[i]);
+ }
+ Arrays.sort(children, c);
+ for (int i=0;i<children.length;++i) {
+ node.appendChild(children[i]);
+ }
+
+ // sort children's children
for (int i=0;i<children.length;++i) {
sort(children[i], c);
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexContribution.java b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexContribution.java
deleted file mode 100644
index 612c62b75..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexContribution.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.index;
-
-import org.eclipse.help.IIndex;
-import org.eclipse.help.IIndexContribution;
-
-public class IndexContribution implements IIndexContribution {
-
- private String id;
- private IIndex index;
- private String locale;
-
- public IndexContribution(String id, IIndex index, String locale) {
- this.id = id;
- this.index = index;
- this.locale = locale;
- }
-
- public String getId() {
- return id;
- }
-
- public IIndex getIndex() {
- return index;
- }
-
- public String getLocale() {
- return locale;
- }
-
- public void setIndex(IIndex index) {
- this.index = index;
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexEntry.java b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexEntry.java
index 0da83da31..ff4170197 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexEntry.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexEntry.java
@@ -11,66 +11,61 @@
*******************************************************************************/
package org.eclipse.help.internal.index;
-import java.util.ArrayList;
-import java.util.List;
-
import org.eclipse.help.IIndexEntry;
-import org.eclipse.help.INode;
import org.eclipse.help.ITopic;
-import org.eclipse.help.internal.Node;
+import org.eclipse.help.Node;
+import org.eclipse.help.internal.NodeAdapter;
+import org.eclipse.help.internal.Topic;
-/**
- * An internal implementation of index entry
+/*
+ * Adapts a "entry" Node as an IIndexEntry. All methods operate on the
+ * underlying adapted Node.
*/
-public class IndexEntry extends Node implements IIndexEntry {
+public class IndexEntry extends NodeAdapter implements IIndexEntry {
- private String keyword;
- private IIndexEntry[] subentries;
- private ITopic[] topics;
-
- public IndexEntry(String keyword) {
- this.keyword = keyword;
+ public static final String NAME = "entry"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_KEYWORD = "keyword"; //$NON-NLS-1$
+
+ /*
+ * Constructs a new index entry adapter for an empty entry node.
+ */
+ public IndexEntry() {
+ super();
+ setName(NAME);
}
- public String getKeyword() {
- return keyword;
- }
-
- public IIndexEntry[] getSubentries() {
- if (subentries == null) {
- INode[] children = getChildren();
- if (children.length > 0) {
- List list = new ArrayList();
- for (int i=0;i<children.length;++i) {
- if (children[i] instanceof IIndexEntry) {
- list.add(children[i]);
- }
- }
- subentries = (IIndexEntry[])list.toArray(new IIndexEntry[list.size()]);
- }
- else {
- subentries = new IIndexEntry[0];
- }
- }
- return subentries;
- }
-
- public ITopic[] getTopics() {
- if (topics == null) {
- INode[] children = getChildren();
- if (children.length > 0) {
- List list = new ArrayList();
- for (int i=0;i<children.length;++i) {
- if (children[i] instanceof ITopic) {
- list.add(children[i]);
- }
- }
- topics = (ITopic[])list.toArray(new ITopic[list.size()]);
- }
- else {
- topics = new ITopic[0];
- }
- }
- return topics;
- }
+ /*
+ * Constructs a new index entry adapter for the given entry node.
+ */
+ public IndexEntry(Node node) {
+ super(node);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IIndexEntry#getKeyword()
+ */
+ public String getKeyword() {
+ return node.getAttribute(ATTRIBUTE_KEYWORD);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IIndexEntry#getSubentries()
+ */
+ public IIndexEntry[] getSubentries() {
+ return (IIndexEntry[])getChildren(NAME, IndexEntry.class);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IIndexEntry#getTopics()
+ */
+ public ITopic[] getTopics() {
+ return (ITopic[])getChildren(Topic.NAME, Topic.class);
+ }
+
+ /*
+ * Sets the entry's keyword.
+ */
+ public void setKeyword(String keyword) {
+ node.setAttribute(ATTRIBUTE_KEYWORD, keyword);
+ }
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileParser.java b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileParser.java
index fbd7c8dd5..16ba291a8 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileParser.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileParser.java
@@ -11,113 +11,57 @@
*******************************************************************************/
package org.eclipse.help.internal.index;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.InputStream;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import org.eclipse.help.IIndexContribution;
-import org.eclipse.help.internal.HelpPlugin;
-import org.eclipse.help.internal.Node;
+import org.eclipse.help.IndexContribution;
+import org.eclipse.help.Node;
+import org.eclipse.help.internal.Topic;
+import org.eclipse.help.internal.dynamic.NodeHandler;
+import org.eclipse.help.internal.dynamic.NodeProcessor;
+import org.eclipse.help.internal.dynamic.NodeReader;
import org.eclipse.help.internal.toc.HrefUtil;
-import org.eclipse.help.internal.toc.Topic;
-import org.eclipse.help.internal.util.FastStack;
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class IndexFileParser extends DefaultHandler {
- private FastStack elementStack;
- private IndexFile indexFile;
- private IndexContribution indexContribution;
- private SAXParser parser;
-
- public IIndexContribution parse(IndexFile indexFile) throws IOException, SAXException {
- this.indexFile = indexFile;
- elementStack = new FastStack();
- indexContribution = null;
- try {
- parser = SAXParserFactory.newInstance().newSAXParser();
- InputStream in = indexFile.getInputStream();
- parser.parse(in, this);
- in.close();
- } catch (ParserConfigurationException pce) {
- HelpPlugin.logError(
- "SAXParser implementation could not be loaded.", pce); //$NON-NLS-1$
- }
-
- return indexContribution;
- }
-
- public final void startElement(String namespaceURI, String localName,
- String qName, Attributes atts) throws SAXException {
-
- Node node = null;
- if (qName.equals("index")) { //$NON-NLS-1$
- node = handleIndexElement(atts);
- } else if (qName.equals("entry")) { //$NON-NLS-1$
- node = handleEntryElement(atts);
- } else if (qName.equals("topic")) { //$NON-NLS-1$
- node = handleTopicElement(atts);
- } else {
- // ignore unknown elements
- return;
- }
-
- if (!elementStack.empty())
- ((Node)elementStack.peek()).addChild(node);
- elementStack.push(node);
- }
-
- public final void endElement(String namespaceURI, String localName,
- String qName) throws SAXException {
- if (qName.equals("index") || qName.equals("entry") //$NON-NLS-1$ //$NON-NLS-2$
- || qName.equals("topic")) { //$NON-NLS-1$
- elementStack.pop();
- }
- }
-
- public InputSource resolveEntity(String publicId, String systemId) {
- InputSource source = new InputSource(new ByteArrayInputStream(
- new byte[0]));
- source.setPublicId(publicId);
- source.setSystemId(systemId);
- return source;
- }
-
- private Node handleIndexElement(Attributes atts) {
- String id = HrefUtil.normalizeHref(indexFile.getPluginId(), indexFile.getFile());
- String locale = indexFile.getLocale();
- Index index = new Index();
- indexContribution = new IndexContribution(id, index, locale);
- return index;
- }
+ private NodeReader reader;
+ private NodeProcessor processor;
- private Node handleEntryElement(Attributes atts) {
- String keyword = atts.getValue("keyword"); //$NON-NLS-1$
- // label is required
- if (keyword == null) {
- String msg = "Required attribute \"keyword\" missing from entry element in " + indexFile.getPluginId() + "/" + indexFile.getFile();; //$NON-NLS-1$ //$NON-NLS-2$
- HelpPlugin.logError(msg, null);
- // continue with empty keyword
- keyword = new String();
- }
- return new IndexEntry(keyword);
- }
-
- private Node handleTopicElement(Attributes atts) {
- String href = HrefUtil.normalizeHref(indexFile.getPluginId(), atts.getValue("href")); //$NON-NLS-1$
- // href is required
- if (href == null) {
- String msg = "Required attribute \"href\" missing from topic element in " + indexFile.getPluginId() + "/" + indexFile.getFile(); //$NON-NLS-1$ //$NON-NLS-2$
- HelpPlugin.logError(msg, null);
+ public IndexContribution parse(IndexFile indexFile) throws IOException, SAXException, ParserConfigurationException {
+ if (reader == null) {
+ reader = new NodeReader();
+ }
+ Node node = reader.read(indexFile.getInputStream());
+ if (processor == null) {
+ processor = new NodeProcessor(new NodeHandler[] {
+ new NormalizeHandler()
+ });
+ }
+ processor.process(node, indexFile.getPluginId());
+ IndexContribution contribution = new IndexContribution();
+ contribution.setId('/' + indexFile.getPluginId() + '/' + indexFile.getFile());
+ contribution.setIndex(node);
+ contribution.setLocale(indexFile.getLocale());
+ return contribution;
+ }
+
+ /*
+ * Normalizes topic hrefs, by prepending the plug-in id to form an href.
+ * e.g. "path/myfile.html" -> "/my.plugin/path/myfile.html"
+ */
+ private class NormalizeHandler extends NodeHandler {
+ public short handle(Node node, String id) {
+ if (Topic.NAME.equals(node.getName())) {
+ String href = node.getAttribute(Topic.ATTRIBUTE_HREF);
+ if (href != null) {
+ node.setAttribute(Topic.ATTRIBUTE_HREF, HrefUtil.normalizeHref(id, href));
+ }
+ return HANDLED_CONTINUE;
+ }
+ return UNHANDLED;
}
- String label = atts.getValue("label"); //$NON-NLS-1$
- return new Topic(href, label);
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileProvider.java b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileProvider.java
index 47b7f6725..443a732e7 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileProvider.java
@@ -17,8 +17,8 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.help.IIndexContribution;
import org.eclipse.help.AbstractIndexProvider;
+import org.eclipse.help.IndexContribution;
import org.eclipse.help.internal.HelpPlugin;
/*
@@ -33,13 +33,13 @@ public class IndexFileProvider extends AbstractIndexProvider {
/* (non-Javadoc)
* @see org.eclipse.help.AbstractIndexProvider#getIndexContributions(java.lang.String)
*/
- public IIndexContribution[] getIndexContributions(String locale) {
+ public IndexContribution[] getIndexContributions(String locale) {
List contributions = new ArrayList();
IndexFile[] indexFiles = getIndexFiles(locale);
IndexFileParser parser = new IndexFileParser();
for (int i=0;i<indexFiles.length;++i) {
try {
- IIndexContribution toc = parser.parse(indexFiles[i]);
+ IndexContribution toc = parser.parse(indexFiles[i]);
contributions.add(toc);
}
catch (Throwable t) {
@@ -47,7 +47,7 @@ public class IndexFileProvider extends AbstractIndexProvider {
HelpPlugin.logError(msg, null);
}
}
- return (IIndexContribution[])contributions.toArray(new IIndexContribution[contributions.size()]);
+ return (IndexContribution[])contributions.toArray(new IndexContribution[contributions.size()]);
}
/*
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexManager.java b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexManager.java
index 3f3bd8e54..18fb5302a 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexManager.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexManager.java
@@ -29,7 +29,7 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.help.AbstractIndexProvider;
import org.eclipse.help.IIndex;
-import org.eclipse.help.IIndexContribution;
+import org.eclipse.help.IndexContribution;
import org.eclipse.help.internal.HelpPlugin;
public class IndexManager {
@@ -42,9 +42,9 @@ public class IndexManager {
private Map indexContributionsByLocale = new HashMap();
private Map indexesByLocale = new HashMap();
private AbstractIndexProvider[] indexProviders;
-
+
public synchronized IIndex getIndex(String locale) {
- IIndex index = (IIndex)indexesByLocale.get(locale);
+ Index index = (Index)indexesByLocale.get(locale);
if (index == null) {
List contributions = Arrays.asList(getIndexContributions(locale));
filterIndexContributions(contributions);
@@ -59,19 +59,19 @@ public class IndexManager {
* Returns all index contributions for the given locale, from all
* providers.
*/
- public synchronized IIndexContribution[] getIndexContributions(String locale) {
- IIndexContribution[] cached = (IIndexContribution[])indexContributionsByLocale.get(locale);
+ public synchronized IndexContribution[] getIndexContributions(String locale) {
+ IndexContribution[] cached = (IndexContribution[])indexContributionsByLocale.get(locale);
if (cached == null) {
List contributions = new ArrayList();
AbstractIndexProvider[] providers = getIndexProviders();
for (int i=0;i<providers.length;++i) {
- IIndexContribution[] contrib;
+ IndexContribution[] contrib;
try {
contrib = providers[i].getIndexContributions(locale);
}
catch (Throwable t) {
// log, and skip the offending provider
- String msg = "Error getting " + IIndexContribution.class.getName() + " from " + AbstractIndexProvider.class.getName() + ": " + providers[i].getClass().getName(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String msg = "Error getting " + IndexContribution.class.getName() + " from " + AbstractIndexProvider.class.getName() + ": " + providers[i].getClass().getName(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
HelpPlugin.logError(msg, t);
continue;
}
@@ -80,21 +80,11 @@ public class IndexManager {
for (int j=0;j<contrib.length;++j) {
// null means no contribution
if (contrib[j] != null) {
- // pre-fetch everything and cache for safety
- try {
- IIndexContribution prefetched = IndexPrefetcher.prefetch(contrib[j]);
- contributions.add(prefetched);
- }
- catch (Throwable t) {
- // log, and skip this offending contribution
- String msg = "Error getting IIndexContribution information from " + contrib[j].getClass().getName(); //$NON-NLS-1$
- HelpPlugin.logError(msg, t);
- continue;
- }
+ contributions.add(contrib[j]);
}
}
}
- cached = (IIndexContribution[])contributions.toArray(new IIndexContribution[contributions.size()]);
+ cached = (IndexContribution[])contributions.toArray(new IndexContribution[contributions.size()]);
indexContributionsByLocale.put(locale, cached);
}
return cached;
@@ -191,7 +181,7 @@ public class IndexManager {
Set indexesToFilter = getIgnoredIndexContributions();
ListIterator iter = unfiltered.listIterator();
while (iter.hasNext()) {
- IIndexContribution contribution = (IIndexContribution)iter.next();
+ IndexContribution contribution = (IndexContribution)iter.next();
if (indexesToFilter.contains(contribution.getId())) {
iter.remove();
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexPrefetcher.java b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexPrefetcher.java
deleted file mode 100644
index 284142daa..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexPrefetcher.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.index;
-
-import org.eclipse.help.IIndex;
-import org.eclipse.help.IIndexContribution;
-import org.eclipse.help.IIndexEntry;
-import org.eclipse.help.INode;
-import org.eclipse.help.ITopic;
-import org.eclipse.help.internal.Node;
-import org.eclipse.help.internal.toc.Topic;
-
-/*
- * Pre-fetches all data from IIndexContributions and returns cached data. Also
- * useful for copying IIndexContributions.
- */
-public class IndexPrefetcher {
-
- public static IndexContribution prefetch(IIndexContribution original) {
- String id = original.getId();
- String locale = original.getLocale();
- Index index = prefetch(original.getIndex());
- IndexContribution contribution = new IndexContribution(id, index, locale);
- return contribution;
- }
-
- private static Index prefetch(IIndex original) {
- Index index = new Index();
- Node[] children = prefetchChildren(original.getChildren());
- index.addChildren(children);
- return index;
- }
-
- private static IndexEntry prefetch(IIndexEntry original) {
- String keyword = original.getKeyword();
- IndexEntry indexEntry = new IndexEntry(keyword);
- Node[] children = prefetchChildren(original.getChildren());
- indexEntry.addChildren(children);
- return indexEntry;
- }
-
- private static Topic prefetch(ITopic original) {
- String href = original.getHref();
- String label = original.getLabel();
- Topic topic = new Topic(href, label);
- Node[] children = prefetchChildren(original.getChildren());
- topic.addChildren(children);
- return topic;
- }
-
- private static Node[] prefetchChildren(INode[] children) {
- Node[] copy = new Node[children.length];
- for (int i=0;i<children.length;++i) {
- INode node = children[i];
- if (node instanceof IIndexEntry) {
- copy[i] = prefetch((IIndexEntry)node);
- }
- else if (node instanceof ITopic) {
- copy[i] = prefetch((ITopic)node);
- }
- else if (node instanceof IIndex) {
- copy[i] = prefetch((IIndex)node);
- }
- }
- return copy;
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/Toc.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/Toc.java
index 810635f9e..98e503d23 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/Toc.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/Toc.java
@@ -11,90 +11,176 @@
package org.eclipse.help.internal.toc;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.eclipse.help.IToc;
-import org.eclipse.help.ITocContribution;
import org.eclipse.help.ITopic;
-import org.eclipse.help.internal.Node;
+import org.eclipse.help.Node;
+import org.eclipse.help.TocContribution;
+import org.eclipse.help.internal.NodeAdapter;
+import org.eclipse.help.internal.Topic;
-public class Toc extends Node implements IToc {
+/*
+ * Adapts a "toc" Node as an IToc. All methods operate on the
+ * underlying adapted Node.
+ */
+public class Toc extends NodeAdapter implements IToc {
+
+ public static final String NAME = "toc"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_LABEL = "label"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_HREF = "href"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_TOPIC = "topic"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_LINK_TO = "link_to"; //$NON-NLS-1$
+ public static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
- private String label;
private ITopic topic;
- private ITopic[] topics;
private Map href2TopicMap;
- private TocContribution contribution;
+
+ /*
+ * Constructs a new toc adapter for an empty toc node.
+ */
+ public Toc() {
+ super();
+ setName(NAME);
+ }
+
+ /*
+ * Constructs a new toc adapter for the given toc node.
+ */
+ public Toc(Node node) {
+ super(node);
+ }
- public Toc(String label, String topic) {
- this.label = label;
- this.topic = new Topic(topic, label) {
- public ITopic[] getSubtopics() {
- return getTopics();
+ /*
+ * Creates a mapping of all topic hrefs to ITopics.
+ */
+ private Map createHref2TopicMap() {
+ Map map = new HashMap();
+ if (topic != null) {
+ map.put(topic.getHref(), topic);
+ }
+ ITopic[] topics = getTopics();
+ for (int i=0;i<topics.length;++i) {
+ createHref2TopicMapAux(map, topics[i]);
+ }
+ return map;
+ }
+
+ /*
+ * Creates a mapping of all topic hrefs to ITopics under the given
+ * ITopic and stores in the given Map.
+ */
+ private void createHref2TopicMapAux(Map map, ITopic topic) {
+ map.put(topic.getHref(), topic);
+ ITopic[] subtopics = topic.getSubtopics();
+ if (subtopics != null) {
+ for (int i=0;i<subtopics.length;++i) {
+ if (subtopics[i] != null) {
+ createHref2TopicMapAux(map, subtopics[i]);
+ }
}
- };
+ }
}
-
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IHelpResource#getHref()
+ */
public String getHref() {
- return contribution.getId();
+ Node parent = node.getParent();
+ if (parent != null) {
+ return parent.getAttribute(ATTRIBUTE_ID);
+ }
+ return null;
}
+ /*
+ * Returns a mapping of all topic hrefs to ITopics.
+ */
+ public Map getHref2TopicMap() {
+ if (href2TopicMap == null) {
+ href2TopicMap = createHref2TopicMap();
+ }
+ return href2TopicMap;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IHelpResource#getLabel()
+ */
public String getLabel() {
- return label;
+ return node.getAttribute(ATTRIBUTE_LABEL);
+ }
+
+ /*
+ * Returns the path to the toc and anchor to link this toc into.
+ */
+ public String getLinkTo() {
+ return node.getAttribute(ATTRIBUTE_LINK_TO);
}
- public ITocContribution getTocContribution() {
- return contribution;
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IToc#getTocContribution()
+ */
+ public TocContribution getTocContribution() {
+ return (TocContribution)node.getParent();
}
+ /*
+ * Returns the toc's own topic href.
+ */
+ public String getTopic() {
+ return node.getAttribute(ATTRIBUTE_TOPIC);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IToc#getTopic(java.lang.String)
+ */
public ITopic getTopic(String href) {
if (href == null) {
+ if (topic == null) {
+ topic = new ITopic() {
+ public String getHref() {
+ return getTopic();
+ }
+ public String getLabel() {
+ return Toc.this.getLabel();
+ }
+ public ITopic[] getSubtopics() {
+ return getTopics();
+ }
+ };
+ }
return topic;
}
else {
return (ITopic)getHref2TopicMap().get(href);
}
}
-
- public Map getHref2TopicMap() {
- if (href2TopicMap == null) {
- href2TopicMap = createHref2TopicMap();
- }
- return href2TopicMap;
- }
-
+
+ /* (non-Javadoc)
+ * @see org.eclipse.help.IToc#getTopics()
+ */
public ITopic[] getTopics() {
- if (topics == null) {
- List list = getChildren(ITopic.class);
- topics = (ITopic[])list.toArray(new ITopic[list.size()]);
- }
- return topics;
+ return (Topic[])getChildren(Topic.NAME, Topic.class);
}
- public void setTocContribution(TocContribution contribution) {
- this.contribution = contribution;
+ /*
+ * Sets the toc's label.
+ */
+ public void setLabel(String label) {
+ node.setAttribute(ATTRIBUTE_LABEL, label);
}
-
- private Map createHref2TopicMap() {
- Map map = new HashMap();
- map.put(topic.getHref(), topic);
- ITopic[] topics = getTopics();
- for (int i=0;i<topics.length;++i) {
- createHref2TopicMapAux(map, topics[i]);
- }
- return map;
+
+ /*
+ * Sets the toc's link_to target.
+ */
+ public void setLinkTo(String linkTo) {
+ node.setAttribute(ATTRIBUTE_LINK_TO, linkTo);
}
-
- private void createHref2TopicMapAux(Map map, ITopic topic) {
- map.put(topic.getHref(), topic);
- ITopic[] subtopics = topic.getSubtopics();
- if (subtopics != null) {
- for (int i=0;i<subtopics.length;++i) {
- if (subtopics[i] != null) {
- createHref2TopicMapAux(map, subtopics[i]);
- }
- }
- }
+
+ /*
+ * Sets the toc's own topic href.
+ */
+ public void setTopic(String href) {
+ node.setAttribute(ATTRIBUTE_TOPIC, href);
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocAssembler.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocAssembler.java
index b45d4d108..412ff026a 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocAssembler.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocAssembler.java
@@ -11,18 +11,18 @@
package org.eclipse.help.internal.toc;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.ListIterator;
import java.util.Map;
+import java.util.Set;
-import org.eclipse.help.ITocContribution;
-import org.eclipse.help.internal.Anchor;
-import org.eclipse.help.internal.HelpPlugin;
-import org.eclipse.help.internal.Include;
-import org.eclipse.help.internal.Node;
+import org.eclipse.help.Node;
+import org.eclipse.help.TocContribution;
+import org.eclipse.help.internal.Topic;
+import org.eclipse.help.internal.dynamic.NodeHandler;
+import org.eclipse.help.internal.dynamic.NodeProcessor;
/*
* Assembles toc contributions (toc fragments) into complete, linked, and
@@ -30,178 +30,322 @@ import org.eclipse.help.internal.Node;
*/
public class TocAssembler {
- private List workingCopy;
- private List includes;
- private Map id2AnchorMap;
- private Map id2ContributionMap;
+ private static final String ELEMENT_LINK = "link"; //$NON-NLS-1$
+ private static final String ELEMENT_ANCHOR = "anchor"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_LINK_TO = "link_to"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_TOC = "toc"; //$NON-NLS-1$
+ private static final String ATTRIBUTE_ID = "id"; //$NON-NLS-1$
+
+ private NodeProcessor processor;
+ private NodeHandler[] handlers;
+
+ private List contributions;
+ private Map contributionsById;
+ private Map contributionsByLinkTo;
+ private Set processedContributions;
/*
- * Assembles the given toc contributions into complete linked
+ * Assembles the given toc contributions into complete, linked
* books. The originals are not modified.
*/
public List assemble(List contributions) {
- workingCopy = createWorkingCopy(contributions);
- discoverNodes();
- processLinkTos();
- processIncludes();
- processOrphans();
- return workingCopy;
+ this.contributions = copy(contributions);
+ contributionsById = null;
+ contributionsByLinkTo = null;
+ processedContributions = null;
+
+ List books = getBooks();
+ Iterator iter = books.iterator();
+ while (iter.hasNext()) {
+ TocContribution book = (TocContribution)iter.next();
+ process(book);
+ }
+ return books;
}
/*
- * Creates an identical copy of the given contributions. The list and all
- * its contents are duplicated (deep copy).
+ * Performs a deep copy of all the contributions in the given list
+ * and returns a new list.
*/
- private List createWorkingCopy(List contributions) {
- List workingCopy = new ArrayList(contributions.size());
+ private List copy(List contributions) {
+ List copies = new ArrayList(contributions.size());
Iterator iter = contributions.iterator();
while (iter.hasNext()) {
- ITocContribution contribution = (ITocContribution)iter.next();
- workingCopy.add(TocPrefetcher.prefetch(contribution));
+ Node node = (Node)iter.next();
+ copies.add(copy(node));
+ }
+ return copies;
+ }
+
+ /*
+ * Performs a deep copy of the given node and all its children.
+ */
+ private Node copy(Node node) {
+ // copy node
+ Node copy = node instanceof TocContribution ? new TocContribution() : new Node();
+ copy.setName(node.getName());
+ copy.setValue(node.getValue());
+ Iterator iter = node.getAttributes().iterator();
+ while (iter.hasNext()) {
+ String name = (String)iter.next();
+ String value = node.getAttribute(name);
+ copy.setAttribute(name, value);
+ }
+
+ // copy children
+ Node[] children = node.getChildren();
+ for (int i=0;i<children.length;++i) {
+ copy.appendChild(copy(children[i]));
}
- return workingCopy;
+ return copy;
}
/*
- * Traverse through all toc contributions to find and make note of any
- * nodes that require processing, specifically anchors and includes.
+ * Returns the list of contributions that should appear as root TOCs
+ * (books). Contributions are books if:
+ *
+ * 1. isPrimary() returns true.
+ * 2. The toc has no "link_to" attribute defined (does not link into
+ * another toc).
+ * 3. No other toc has a link to this contribution (via "link" element).
*/
- private void discoverNodes() {
- includes = new ArrayList();
- id2AnchorMap = new HashMap();
- id2ContributionMap = new HashMap();
- Iterator iter = workingCopy.iterator();
+ private List getBooks() {
+ Set linkedContributionIds = getLinkedContributionIds(contributions);
+ List books = new ArrayList();
+ Iterator iter = contributions.iterator();
while (iter.hasNext()) {
TocContribution contrib = (TocContribution)iter.next();
- id2ContributionMap.put(contrib.getId(), contrib);
- discover((Toc)contrib.getToc(), contrib);
+ if (contrib.isPrimary() && contrib.getToc().getAttribute(ATTRIBUTE_LINK_TO) == null && !linkedContributionIds.contains(contrib.getId())) {
+ books.add(contrib);
+ }
}
+ return books;
}
/*
- * Traverse the given node from the given contribution to find nodes
- * that require processing.
+ * Returns the set of ids of contributions that are linked to by other
+ * contributions, i.e. at least one other contribution has a link element
+ * pointing to it.
*/
- private void discover(Node node, TocContribution contrib) {
- // is it one of the nodes that need processing?
- if (node instanceof Anchor) {
- String id = contrib.getId() + '#' + ((Anchor)node).getId();
- id2AnchorMap.put(id, node);
- }
- else if (node instanceof Include) {
- includes.add(node);
+ private Set getLinkedContributionIds(List contributions) {
+ if (processor == null) {
+ processor = new NodeProcessor();
}
-
- // recursively discover all descendants
- Node[] children = node.getChildrenInternal();
- for (int i=0;i<children.length;++i) {
- discover(children[i], contrib);
+ final Set linkedContributionIds = new HashSet();
+ NodeHandler[] linkFinder = new NodeHandler[] {
+ new NodeHandler() {
+ public short handle(Node node, String id) {
+ if (ELEMENT_LINK.equals(node.getName())) {
+ String toc = node.getAttribute(ATTRIBUTE_TOC);
+ if (toc != null) {
+ TocContribution srcContribution = getContribution(id);
+ linkedContributionIds.add(HrefUtil.normalizeHref(srcContribution.getContributorId(), toc));
+ }
+ }
+ return UNHANDLED;
+ }
+ }
+ };
+ processor.setHandlers(linkFinder);
+ Iterator iter = contributions.iterator();
+ while (iter.hasNext()) {
+ TocContribution contrib = (TocContribution)iter.next();
+ processor.process(contrib.getToc(), contrib.getId());
}
+ return linkedContributionIds;
}
- private Toc getOwningToc(Node node) {
- while (node != null && !(node instanceof Toc)) {
- node = node.getParentInternal();
+ /*
+ * Processes the given contribution, if it hasn't been processed yet. This
+ * performs the following operations:
+ *
+ * 1. Topic hrefs are normalized, e.g. "path/doc.html" ->
+ * "/my.plugin/path/doc.html"
+ * 2. Links are resolved, link is replaced with target content, extra docs
+ * are merged.
+ * 3. Anchor contributions are resolved, tocs with link_to's are inserted
+ * at anchors and extra docs merged.
+ */
+ private void process(TocContribution contribution) {
+ if (processedContributions == null) {
+ processedContributions = new HashSet();
+ }
+ // don't process the same one twice
+ if (!processedContributions.contains(contribution)) {
+ if (processor == null) {
+ processor = new NodeProcessor();
+ }
+ if (handlers == null) {
+ handlers = new NodeHandler[] {
+ new NormalizeHandler(),
+ new LinkHandler(),
+ new AnchorHandler(),
+ };
+ }
+ processor.setHandlers(handlers);
+ processor.process(contribution.getToc(), contribution.getId());
+ processedContributions.add(contribution);
}
- return (Toc)node;
}
/*
- * Processes all link_tos. Any contribution may specify that it should be
- * inserted at a specific anchor in another toc contribution.
+ * Returns the contribution with the given id.
*/
- private void processLinkTos() {
- ListIterator iter = workingCopy.listIterator();
- while (iter.hasNext()) {
- TocContribution contribution = (TocContribution)iter.next();
- String target = contribution.getLinkTo();
- if (target != null) {
- // find the target anchor
- Anchor anchor = (Anchor)id2AnchorMap.get(target);
- if (anchor != null) {
- Toc toc = (Toc)contribution.getToc();
- anchor.addChildren(toc.getChildrenInternal());
-
- // combine the extra documents into the larger contribution
- int numberSignIndex = target.indexOf('#');
- String contributionId = target.substring(0, numberSignIndex);
- TocContribution targetContribution = (TocContribution)id2ContributionMap.get(contributionId);
- targetContribution.addExtraDocuments(contribution.getExtraDocuments());
- }
- else {
- String msg = "TOC contribution \"" + contribution.getId() + "\"'s link_to target anchor could not be found: " + target; //$NON-NLS-1$//$NON-NLS-2$
- HelpPlugin.logError(msg, null);
- }
- // this is no longer a top-level toc, so remove it from book list
- iter.remove();
+ private TocContribution getContribution(String id) {
+ if (contributionsById == null) {
+ contributionsById = new HashMap();
+ Iterator iter = contributions.iterator();
+ while (iter.hasNext()) {
+ TocContribution contribution = (TocContribution)iter.next();
+ contributionsById.put(contribution.getId(), contribution);
}
}
- // anchors are no longer needed; remove them
- removeIntermediateNodes(id2AnchorMap.values());
+ return (TocContribution)contributionsById.get(id);
}
/*
- * Process all include directives by replacing the include node with
- * the target toc.
+ * Returns all contributions that define a link_to attribute pointing to
+ * the given anchor path. The path has the form "<contributionId>#<anchorId>",
+ * e.g. "/my.plugin/toc.xml#myAnchor".
*/
- private void processIncludes() {
- Iterator iter = includes.iterator();
- while (iter.hasNext()) {
- Include include = (Include)iter.next();
- TocContribution contrib = (TocContribution)id2ContributionMap.get(include.getTarget());
- if (contrib != null) {
- Toc toc = (Toc)contrib.getToc();
- include.getParentInternal().replaceChild(include, toc.getChildrenInternal());
-
- // no longer a top-level toc, so remove it from book list
- workingCopy.remove(contrib);
-
- // combine the extra documents into the larger toc
- Toc owningToc = getOwningToc(include);
- TocContribution owningContribution = (TocContribution)owningToc.getTocContribution();
- owningContribution.addExtraDocuments(contrib.getExtraDocuments());
- }
- else {
- String msg = "TOC contribution include target could not be found: " + include.getTarget(); //$NON-NLS-1$
- HelpPlugin.logError(msg, null);
+ private TocContribution[] getAnchorContributions(String anchorPath) {
+ if (contributionsByLinkTo == null) {
+ contributionsByLinkTo = new HashMap();
+ Iterator iter = contributions.iterator();
+ while (iter.hasNext()) {
+ TocContribution srcContribution = (TocContribution)iter.next();
+ String linkTo = srcContribution.getToc().getAttribute(ATTRIBUTE_LINK_TO);
+ if (linkTo != null) {
+ String destAnchorPath = HrefUtil.normalizeHref(srcContribution.getContributorId(), linkTo);
+ TocContribution[] array = (TocContribution[])contributionsByLinkTo.get(destAnchorPath);
+ if (array == null) {
+ array = new TocContribution[] { srcContribution };
+ }
+ else {
+ TocContribution[] temp = new TocContribution[array.length + 1];
+ System.arraycopy(array, 0, temp, 0, array.length);
+ temp[array.length] = srcContribution;
+ array = temp;
+ }
+ contributionsByLinkTo.put(destAnchorPath, array);
+ }
}
}
+ TocContribution[] contributions = (TocContribution[])contributionsByLinkTo.get(anchorPath);
+ if (contributions == null) {
+ contributions = new TocContribution[0];
+ }
+ return contributions;
}
/*
- * Processes all remaining contribution that are not primary and have not
- * been linked under any other toc (orphan tocs).
+ * Handler that resolves link elements (replaces the link element with
+ * the linked-to toc's children.
*/
- private void processOrphans() {
- ListIterator iter = workingCopy.listIterator();
- while (iter.hasNext()) {
- TocContribution contrib = (TocContribution)iter.next();
- if (!contrib.isPrimary()) {
- iter.remove();
+ private class LinkHandler extends NodeHandler {
+ public short handle(Node node, String id) {
+ if (ELEMENT_LINK.equals(node.getName())) {
+ Node parent = node.getParent();
+ if (parent != null) {
+ String toc = node.getAttribute(ATTRIBUTE_TOC);
+ if (toc != null) {
+ TocContribution destContribution = getContribution(id);
+ TocContribution srcContribution = getContribution(HrefUtil.normalizeHref(destContribution.getContributorId(), toc));
+ if (srcContribution != null) {
+ process(srcContribution);
+ Node[] children = srcContribution.getToc().getChildren();
+ for (int i=0;i<children.length;++i) {
+ parent.insertBefore(copy(children[i]), node);
+ }
+
+ // combine extra docs
+ String[] srcExtraDocuments = srcContribution.getExtraDocuments();
+ String[] destExtraDocuments = destContribution.getExtraDocuments();
+ if (srcExtraDocuments.length != 0) {
+ String[] combinedExtraDocuments;
+ if (destExtraDocuments.length == 0) {
+ combinedExtraDocuments = destExtraDocuments;
+ }
+ else {
+ combinedExtraDocuments = new String[destExtraDocuments.length + srcExtraDocuments.length];
+ System.arraycopy(srcExtraDocuments, 0, combinedExtraDocuments, 0, srcExtraDocuments.length);
+ System.arraycopy(destExtraDocuments, 0, combinedExtraDocuments, srcExtraDocuments.length, destExtraDocuments.length);
+ }
+ destContribution.setExtraDocuments(combinedExtraDocuments);
+ }
+ }
+ parent.removeChild(node);
+ }
+ }
+ return HANDLED_SKIP;
}
+ return UNHANDLED;
}
}
-
+
/*
- * Removes the given node from the tree, but not its children. The children
- * are "pulled up" one level.
+ * Handles anchor contributions. If any contribution's toc wants to link
+ * into this one at the current anchor, link it in.
*/
- private void removeIntermediateNode(Node node) {
- Node parent = (Node)node.getParent();
- if (parent != null) {
- Node[] children = node.getChildrenInternal();
- parent.replaceChild(node, children);
+ private class AnchorHandler extends NodeHandler {
+ public short handle(Node node, String id) {
+ if (ELEMENT_ANCHOR.equals(node.getName())) {
+ Node parent = node.getParent();
+ if (parent != null) {
+ String anchorId = node.getAttribute(ATTRIBUTE_ID);
+ if (anchorId != null) {
+ TocContribution destContribution = getContribution(id);
+ TocContribution[] srcContributions = getAnchorContributions(destContribution.getId() + '#' + anchorId);
+ for (int i=0;i<srcContributions.length;++i) {
+ process(srcContributions[i]);
+ Node[] children = srcContributions[i].getToc().getChildren();
+ for (int j=0;j<children.length;++j) {
+ parent.insertBefore(copy(children[j]), node);
+ }
+
+ // combine extra docs
+ String[] srcExtraDocuments = srcContributions[i].getExtraDocuments();
+ String[] destExtraDocuments = destContribution.getExtraDocuments();
+ if (srcExtraDocuments.length != 0) {
+ String[] combinedExtraDocuments;
+ if (destExtraDocuments.length == 0) {
+ combinedExtraDocuments = destExtraDocuments;
+ }
+ else {
+ combinedExtraDocuments = new String[destExtraDocuments.length + srcExtraDocuments.length];
+ System.arraycopy(srcExtraDocuments, 0, combinedExtraDocuments, 0, srcExtraDocuments.length);
+ System.arraycopy(destExtraDocuments, 0, combinedExtraDocuments, srcExtraDocuments.length, destExtraDocuments.length);
+ }
+ destContribution.setExtraDocuments(combinedExtraDocuments);
+ }
+ }
+ parent.removeChild(node);
+ }
+ }
+ return HANDLED_SKIP;
+ }
+ return UNHANDLED;
}
}
-
+
/*
- * Removes all the given nodes from the tree, but not its children. The
- * children are "pulled up" one level.
+ * Normalizes topic hrefs, by prepending the plug-in id to form an href.
+ * e.g. "path/myfile.html" -> "/my.plugin/path/myfile.html"
*/
- private void removeIntermediateNodes(Collection nodes) {
- Iterator iter = nodes.iterator();
- while (iter.hasNext()) {
- removeIntermediateNode((Node)iter.next());
+ private class NormalizeHandler extends NodeHandler {
+ public short handle(Node node, String id) {
+ if (Topic.NAME.equals(node.getName())) {
+ String href = node.getAttribute(Topic.ATTRIBUTE_HREF);
+ if (href != null) {
+ TocContribution contribution = getContribution(id);
+ if (contribution != null) {
+ String pluginId = contribution.getContributorId();
+ node.setAttribute(Topic.ATTRIBUTE_HREF, HrefUtil.normalizeHref(pluginId, href));
+ }
+ }
+ return HANDLED_CONTINUE;
+ }
+ return UNHANDLED;
}
}
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocContribution.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocContribution.java
deleted file mode 100644
index d84e46778..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocContribution.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.toc;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.help.IToc;
-import org.eclipse.help.ITocContribution;
-
-public class TocContribution implements ITocContribution {
-
- private String id;
- private String categoryId;
- private String locale;
- private Toc toc;
- private String linkTo;
- private boolean isPrimary;
- private List extraDocuments = new ArrayList();
-
- public TocContribution(String id, String categoryId, String locale, Toc toc, String linkTo, boolean isPrimary, String[] extraDocuments) {
- this.categoryId = categoryId;
- if (extraDocuments != null) {
- this.extraDocuments.addAll(Arrays.asList(extraDocuments));
- }
- this.id = id;
- this.locale = locale;
- this.toc = toc;
- this.isPrimary = isPrimary;
- this.linkTo = linkTo;
- }
-
- public void addExtraDocument(String docToAdd) {
- extraDocuments.add(docToAdd);
- }
-
- public void addExtraDocuments(String[] docsToAdd) {
- extraDocuments.addAll(Arrays.asList(docsToAdd));
- }
-
- public String getCategoryId() {
- return categoryId;
- }
-
- public String[] getExtraDocuments() {
- return (String[])extraDocuments.toArray(new String[extraDocuments.size()]);
- }
-
- public String getId() {
- return id;
- }
-
- public String getLocale() {
- return locale;
- }
-
- public IToc getToc() {
- return toc;
- }
-
- public boolean isPrimary() {
- return isPrimary;
- }
-
- public String getLinkTo() {
- return linkTo;
- }
-
- public void setToc(Toc toc) {
- this.toc = toc;
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileParser.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileParser.java
index 3034cea49..6759644f2 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileParser.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileParser.java
@@ -10,221 +10,36 @@
*******************************************************************************/
package org.eclipse.help.internal.toc;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-import org.eclipse.help.ITocContribution;
-import org.eclipse.help.internal.Anchor;
-import org.eclipse.help.internal.Node;
-import org.eclipse.help.internal.Filter;
-import org.eclipse.help.internal.HelpPlugin;
-import org.eclipse.help.internal.Include;
-import org.eclipse.help.internal.util.FastStack;
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
+import org.eclipse.help.Node;
+import org.eclipse.help.TocContribution;
+import org.eclipse.help.internal.dynamic.NodeReader;
import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
-import com.ibm.icu.text.MessageFormat;
-
public class TocFileParser extends DefaultHandler {
- private FastStack elementStack;
- private TocFile tocFile;
- private TocContribution tocContribution;
- private List filterNodes;
- private SAXParser parser;
-
- public void error(SAXParseException ex) throws SAXException {
- HelpPlugin.logError("Error parsing Table of Contents file, " //$NON-NLS-1$
- + getErrorDetails(ex), null);
- }
-
- public void fatalError(SAXParseException ex) throws SAXException {
- HelpPlugin.logError("Failed to parse Table of Contents file, " //$NON-NLS-1$
- + getErrorDetails(ex), ex);
- }
-
- protected String getErrorDetails(SAXParseException ex) {
- String param0 = ex.getSystemId();
- Integer param1 = new Integer(ex.getLineNumber());
- Integer param2 = new Integer(ex.getColumnNumber());
- String param3 = ex.getMessage();
- String message = MessageFormat
- .format(
- "URL: {0} at line: {1,number,integer}, column: {2,number,integer}.\r\n{3}", //$NON-NLS-1$
- new Object[] { param0, param1, param2, param3 });
- return message;
- }
-
- public ITocContribution parse(TocFile tocFile) throws IOException, SAXException {
- this.tocFile = tocFile;
- elementStack = new FastStack();
- tocContribution = null;
- filterNodes = new ArrayList();
- try {
- parser = SAXParserFactory.newInstance().newSAXParser();
- InputStream in = tocFile.getInputStream();
- parser.parse(in, this);
- in.close();
- } catch (ParserConfigurationException pce) {
- HelpPlugin.logError(
- "SAXParser implementation could not be loaded.", pce); //$NON-NLS-1$
- }
-
- /*
- * For each node that had a filter attribute, slip in a filter node
- * above it to contain it.
- */
- Iterator iter = filterNodes.iterator();
- while (iter.hasNext()) {
- Object[] entry = (Object[])iter.next();
- Node node = (Node)entry[0];
- Node parent = node.getParentInternal();
- if (parent != null) {
- String filterExpression = (String)entry[1];
- Filter filter = new Filter(filterExpression);
- filter.addChild(node);
- parent.replaceChild(node, filter);
- }
- }
-
- return tocContribution;
- }
-
- public final void startElement(String namespaceURI, String localName,
- String qName, Attributes atts) throws SAXException {
-
- Node node = null;
- if (qName.equals("toc")) { //$NON-NLS-1$
- node = handleTocElement(atts);
- } else if (qName.equals("topic")) { //$NON-NLS-1$
- node = handleTopicElement(atts);
- } else if (qName.equals("link")) { //$NON-NLS-1$
- node = handleLinkElement(atts);
- } else if (qName.equals("anchor")) { //$NON-NLS-1$
- node = handleAnchorElement(atts);
- } else if (qName.equals("filter")) { //$NON-NLS-1$
- handleFilterElement(atts);
- return;
- } else {
- // ignore unknown elements
- return;
- }
-
- /*
- * If the node has a filter attribute, make note of it so we can
- * wrap it in a filter element after.
- */
- String filterAttribute = atts.getValue("filter"); //$NON-NLS-1$
- if (filterAttribute != null) {
- Node parent = (Node)elementStack.peek();
- if (parent != null) {
- filterNodes.add(new Object[] { node, filterAttribute });
- }
- }
-
- if (!elementStack.empty())
- ((Node)elementStack.peek()).addChild(node);
- elementStack.push(node);
- }
-
- public final void endElement(String namespaceURI, String localName,
- String qName) throws SAXException {
- if (qName.equals("toc") || qName.equals("topic") //$NON-NLS-1$ //$NON-NLS-2$
- || qName.equals("link") || qName.equals("anchor")) { //$NON-NLS-1$ //$NON-NLS-2$
- elementStack.pop();
- }
- }
-
- public InputSource resolveEntity(String publicId, String systemId) {
- InputSource source = new InputSource(new ByteArrayInputStream(
- new byte[0]));
- source.setPublicId(publicId);
- source.setSystemId(systemId);
- return source;
- }
-
- private Node handleTocElement(Attributes atts) {
- String label = atts.getValue("label"); //$NON-NLS-1$
- // label is required
- if (label == null) {
- String msg = "Required attribute \"label\" missing from toc element in " + tocFile.getPluginId() + "/" + tocFile.getFile();; //$NON-NLS-1$ //$NON-NLS-2$
- HelpPlugin.logError(msg, null);
- // continue with empty label
- label = new String();
- }
- String topic = HrefUtil.normalizeHref(tocFile.getPluginId(), atts.getValue("topic")); //$NON-NLS-1$
- String linkTo = HrefUtil.normalizeHref(tocFile.getPluginId(), atts.getValue("link_to")); //$NON-NLS-1$
- String id = HrefUtil.normalizeHref(tocFile.getPluginId(), tocFile.getFile());
- String categoryId = tocFile.getCategory();
- String locale = tocFile.getLocale();
- Toc toc = new Toc(label, topic);
- String[] extraDocuments = DocumentFinder.collectExtraDocuments(tocFile);
- boolean isPrimary = tocFile.isPrimary();
-
- tocContribution = new TocContribution(id, categoryId, locale, toc, linkTo, isPrimary, extraDocuments);
- toc.setTocContribution(tocContribution);
- return toc;
- }
-
- private Node handleTopicElement(Attributes atts) {
- String label = atts.getValue("label"); //$NON-NLS-1$
- // label is required
- if (label == null) {
- String msg = "Required attribute \"label\" missing from topic element in " + tocFile.getPluginId() + "/" + tocFile.getFile();; //$NON-NLS-1$ //$NON-NLS-2$
- HelpPlugin.logError(msg, null);
- // continue with empty label
- label = new String();
- }
- String href = HrefUtil.normalizeHref(tocFile.getPluginId(), atts.getValue("href")); //$NON-NLS-1$
- return new Topic(href, label);
- }
-
- private Node handleLinkElement(Attributes atts) {
- String toc = HrefUtil.normalizeHref(tocFile.getPluginId(), atts.getValue("toc")); //$NON-NLS-1$
- // toc is required
- if (toc == null) {
- String msg = "Required attribute \"toc\" missing from link element in " + tocFile.getPluginId() + "/" + tocFile.getFile(); //$NON-NLS-1$ //$NON-NLS-2$
- HelpPlugin.logError(msg, null);
- }
- return new Include(toc);
- }
-
- private Node handleAnchorElement(Attributes atts) {
- String id = atts.getValue("id"); //$NON-NLS-1$
- // id is required
- if (id == null) {
- String msg = "Required attribute \"id\" missing from anchor element in " + tocFile.getPluginId() + "/" + tocFile.getFile(); //$NON-NLS-1$ //$NON-NLS-2$
- HelpPlugin.logError(msg, null);
- }
- return new Anchor(id);
- }
-
- private void handleFilterElement(Attributes atts) {
- if (!elementStack.isEmpty()) {
- String name = atts.getValue("name"); //$NON-NLS-1$
- String value = atts.getValue("value"); //$NON-NLS-1$
- if (name == null || value == null) {
- String msg = "Filter element missing one or more of required attributes {name, value} " + tocFile.getPluginId() + "/" + tocFile.getFile(); //$NON-NLS-1$ //$NON-NLS-2$
- HelpPlugin.logError(msg, null);
- }
- boolean isNot = value.charAt(0) == '!';
- if (isNot) {
- value = value.substring(1);
- }
- String expression = name + (isNot ? "!=" : "=") + value; //$NON-NLS-1$ //$NON-NLS-2$
- Node parent = (Node)elementStack.peek();
- filterNodes.add(new Object[] { parent, expression });
- }
- }
+ private NodeReader reader;
+
+ /*
+ * Parses the given toc XML file into model objects (a TocContribution).
+ */
+ public TocContribution parse(TocFile tocFile) throws IOException, SAXException, ParserConfigurationException {
+ if (reader == null) {
+ reader = new NodeReader();
+ }
+ Node node = reader.read(tocFile.getInputStream());
+ TocContribution contribution = new TocContribution();
+ contribution.setCategoryId(tocFile.getCategory());
+ contribution.setContributorId(tocFile.getPluginId());
+ contribution.setExtraDocuments(DocumentFinder.collectExtraDocuments(tocFile));
+ contribution.setId(HrefUtil.normalizeHref(tocFile.getPluginId(), tocFile.getFile()));
+ contribution.setLocale(tocFile.getLocale());
+ contribution.setPrimary(tocFile.isPrimary());
+ contribution.setToc(node);
+ return contribution;
+ }
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java
index babaf5aa1..79e11afe5 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileProvider.java
@@ -17,8 +17,8 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.help.ITocContribution;
import org.eclipse.help.AbstractTocProvider;
+import org.eclipse.help.TocContribution;
import org.eclipse.help.internal.HelpPlugin;
/*
@@ -36,21 +36,21 @@ public class TocFileProvider extends AbstractTocProvider {
/* (non-Javadoc)
* @see org.eclipse.help.AbstractTocProvider#getTocContributions(java.lang.String)
*/
- public ITocContribution[] getTocContributions(String locale) {
+ public TocContribution[] getTocContributions(String locale) {
List contributions = new ArrayList();
TocFile[] tocFiles = getTocFiles(locale);
TocFileParser parser = new TocFileParser();
for (int i=0;i<tocFiles.length;++i) {
try {
- ITocContribution toc = parser.parse(tocFiles[i]);
+ TocContribution toc = parser.parse(tocFiles[i]);
contributions.add(toc);
}
catch (Throwable t) {
String msg = "Error reading toc file \"" + tocFiles[i].getFile() + "\" in extension specified in plug-in: " + tocFiles[i].getPluginId(); //$NON-NLS-1$ //$NON-NLS-2$
- HelpPlugin.logError(msg, null);
+ HelpPlugin.logError(msg, t);
}
}
- return (ITocContribution[])contributions.toArray(new ITocContribution[contributions.size()]);
+ return (TocContribution[])contributions.toArray(new TocContribution[contributions.size()]);
}
/*
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java
index 48e1dcf45..dad1a07b0 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocManager.java
@@ -27,14 +27,12 @@ import org.eclipse.core.runtime.InvalidRegistryObjectException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.help.AbstractTocProvider;
-import org.eclipse.help.HelpSystem;
-import org.eclipse.help.IToc;
-import org.eclipse.help.ITocContribution;
+import org.eclipse.help.TocContribution;
import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.util.ProductPreferences;
/*
- * Manages toc contributions (ITocContribution) supplied by the various toc
+ * Manages toc contributions (TocContribution) supplied by the various toc
* providers (AbstractTocProvider).
*/
public class TocManager {
@@ -54,26 +52,26 @@ public class TocManager {
/*
* Returns all toc entries (complete books) for the given locale.
*/
- public synchronized IToc[] getTocs(String locale) {
- IToc[] tocs = (IToc[])tocsByLocale.get(locale);
+ public synchronized Toc[] getTocs(String locale) {
+ Toc[] tocs = (Toc[])tocsByLocale.get(locale);
if (tocs == null) {
- ITocContribution[] raw = getRootTocContributions(locale);
- ITocContribution[] filtered = filterTocContributions(raw);
- ITocContribution[] ordered = orderTocContributions(filtered);
+ TocContribution[] raw = getRootTocContributions(locale);
+ TocContribution[] filtered = filterTocContributions(raw);
+ TocContribution[] ordered = orderTocContributions(filtered);
List orderedTocs = new ArrayList(ordered.length);
for (int i=0;i<ordered.length;++i) {
try {
- IToc toc = ordered[i].getToc();
+ Toc toc = new Toc(ordered[i].getToc());
orderedTocs.add(toc);
tocsById.put(ordered[i].getId(), toc);
}
catch (Throwable t) {
// log and skip
- String msg = "Error getting " + IToc.class.getName() + " from " + ITocContribution.class.getName() + ": " + ordered[i]; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String msg = "Error getting " + Toc.class.getName() + " from " + TocContribution.class.getName() + ": " + ordered[i]; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
HelpPlugin.logError(msg, t);
}
}
- tocs = (IToc[])orderedTocs.toArray(new IToc[orderedTocs.size()]);
+ tocs = (Toc[])orderedTocs.toArray(new Toc[orderedTocs.size()]);
tocsByLocale.put(locale, tocs);
}
return tocs;
@@ -83,43 +81,43 @@ public class TocManager {
* Returns the toc whose toc contribution has the given id, for the
* given locale.
*/
- public synchronized IToc getToc(String id, String locale) {
+ public synchronized Toc getToc(String id, String locale) {
getTocs(locale);
- return (IToc)tocsById.get(id);
+ return (Toc)tocsById.get(id);
}
- public synchronized IToc getOwningToc(String href) {
+ public synchronized Toc getOwningToc(String href) {
if (tocsByTopic == null) {
tocsByTopic = new HashMap();
- IToc[] tocs = HelpSystem.getTocs();
+ Toc[] tocs = HelpPlugin.getTocManager().getTocs(Platform.getNL());
for (int i=0;i<tocs.length;++i) {
- ITocContribution contribution = tocs[i].getTocContribution();
+ TocContribution contribution = tocs[i].getTocContribution();
String[] extraDocuments = contribution.getExtraDocuments();
for (int j=0;j<extraDocuments.length;++j) {
tocsByTopic.put(extraDocuments[j], tocs[i]);
}
}
}
- return (IToc)tocsByTopic.get(href);
+ return (Toc)tocsByTopic.get(href);
}
/*
* Returns all toc contributions for the given locale, from all toc
* providers.
*/
- public synchronized ITocContribution[] getTocContributions(String locale) {
- ITocContribution[] cached = (ITocContribution[])tocContributionsByLocale.get(locale);
+ public synchronized TocContribution[] getTocContributions(String locale) {
+ TocContribution[] cached = (TocContribution[])tocContributionsByLocale.get(locale);
if (cached == null) {
List contributions = new ArrayList();
AbstractTocProvider[] providers = getTocProviders();
for (int i=0;i<providers.length;++i) {
- ITocContribution[] contrib;
+ TocContribution[] contrib;
try {
contrib = providers[i].getTocContributions(locale);
}
catch (Throwable t) {
// log, and skip the offending provider
- String msg = "Error getting " + ITocContribution.class.getName() + " from " + AbstractTocProvider.class.getName() + ": " + providers[i].getClass().getName(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String msg = "Error getting " + TocContribution.class.getName() + " from " + AbstractTocProvider.class.getName() + ": " + providers[i].getClass().getName(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
HelpPlugin.logError(msg, t);
continue;
}
@@ -128,21 +126,11 @@ public class TocManager {
for (int j=0;j<contrib.length;++j) {
// null means no contribution
if (contrib[j] != null) {
- // pre-fetch everything and cache for safety
- try {
- ITocContribution prefetched = TocPrefetcher.prefetch(contrib[j]);
- contributions.add(prefetched);
- }
- catch (Throwable t) {
- // log, and skip this offending contribution
- String msg = "Error getting ITocContribution information from " + contrib[j].getClass().getName(); //$NON-NLS-1$
- HelpPlugin.logError(msg, t);
- continue;
- }
+ contributions.add(contrib[j]);
}
}
}
- cached = (ITocContribution[])contributions.toArray(new ITocContribution[contributions.size()]);
+ cached = (TocContribution[])contributions.toArray(new TocContribution[contributions.size()]);
tocContributionsByLocale.put(locale, cached);
}
return cached;
@@ -165,13 +153,13 @@ public class TocManager {
* either the contribution's id or its category's id is listed in the
* ignoredTocs, filter the contribution.
*/
- private ITocContribution[] filterTocContributions(ITocContribution[] unfiltered) {
+ private TocContribution[] filterTocContributions(TocContribution[] unfiltered) {
Set tocsToFilter = getIgnoredTocContributions();
List filtered = new ArrayList();
Set ignoredHrefs = new HashSet();
Set notIgnoredHrefs = new HashSet();
for (int i=0;i<unfiltered.length;++i) {
- Toc toc = (Toc)unfiltered[i].getToc();
+ Toc toc = new Toc(unfiltered[i].getToc());
Set hrefs = toc.getHref2TopicMap().keySet();
if (!tocsToFilter.contains(unfiltered[i].getId()) &&
!tocsToFilter.contains(unfiltered[i].getCategoryId())) {
@@ -189,15 +177,15 @@ public class TocManager {
*/
ignoredTopicHrefs = ignoredHrefs;
ignoredTopicHrefs.removeAll(notIgnoredHrefs);
- return (ITocContribution[])filtered.toArray(new ITocContribution[filtered.size()]);
+ return (TocContribution[])filtered.toArray(new TocContribution[filtered.size()]);
}
- private ITocContribution[] getRootTocContributions(String locale) {
- ITocContribution[] contributions = getTocContributions(locale);
+ private TocContribution[] getRootTocContributions(String locale) {
+ TocContribution[] contributions = getTocContributions(locale);
List unassembled = new ArrayList(Arrays.asList(contributions));
TocAssembler assembler = new TocAssembler();
List assembled = assembler.assemble(unassembled);
- return (ITocContribution[])assembled.toArray(new ITocContribution[assembled.size()]);
+ return (TocContribution[])assembled.toArray(new TocContribution[assembled.size()]);
}
private Set getIgnoredTocContributions() {
@@ -267,7 +255,7 @@ public class TocManager {
/*
* Orders the given toc contributions by category and product preference.
*/
- private ITocContribution[] orderTocContributions(ITocContribution[] unorderedTocs) {
+ private TocContribution[] orderTocContributions(TocContribution[] unorderedTocs) {
// first categorize the TOCs
List itemsToOrder = new ArrayList();
Map categorized = categorizeTocs(Arrays.asList(unorderedTocs), itemsToOrder);
@@ -275,12 +263,12 @@ public class TocManager {
// order them
List orderedItems = ProductPreferences.getOrderedList(HelpPlugin.getDefault(), HelpPlugin.BASE_TOCS_KEY, itemsToOrder);
- // replace with actual ITocContribution or category
+ // replace with actual TocContribution or category
orderedItems = substituteValues(orderedItems, categorized);
// expand the categories
orderedItems = expandCategories(orderedItems);
- return (ITocContribution[])orderedItems.toArray(new ITocContribution[orderedItems.size()]);
+ return (TocContribution[])orderedItems.toArray(new TocContribution[orderedItems.size()]);
}
/*
@@ -293,14 +281,14 @@ public class TocManager {
Map categorized = new HashMap();
Iterator iter = tocs.iterator();
while (iter.hasNext()) {
- ITocContribution toc = (ITocContribution)iter.next();
+ TocContribution toc = (TocContribution)iter.next();
String categoryId;
try {
categoryId = toc.getCategoryId();
}
catch (Throwable t) {
// log and skip
- String msg = "Error retrieving categoryId from " + ITocContribution.class.getName() + ": " + toc.getClass().getName(); //$NON-NLS-1$ //$NON-NLS-2$
+ String msg = "Error retrieving categoryId from " + TocContribution.class.getName() + ": " + toc.getClass().getName(); //$NON-NLS-1$ //$NON-NLS-2$
HelpPlugin.logError(msg, t);
continue;
}
@@ -323,7 +311,7 @@ public class TocManager {
}
catch (Throwable t) {
// log and skip
- String msg = "Error retrieving id from " + ITocContribution.class.getName() + ": " + toc.getClass().getName(); //$NON-NLS-1$ //$NON-NLS-2$
+ String msg = "Error retrieving id from " + TocContribution.class.getName() + ": " + toc.getClass().getName(); //$NON-NLS-1$ //$NON-NLS-2$
HelpPlugin.logError(msg, t);
continue;
}
@@ -343,7 +331,7 @@ public class TocManager {
Iterator iter = entries.iterator();
while (iter.hasNext()) {
Object entry = iter.next();
- if (entry instanceof ITocContribution) {
+ if (entry instanceof TocContribution) {
expanded.add(entry);
}
else if (entry instanceof TocCategory) {
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocPrefetcher.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocPrefetcher.java
deleted file mode 100644
index 2db7e6809..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocPrefetcher.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.toc;
-
-import org.eclipse.help.IAnchor;
-import org.eclipse.help.IFilter;
-import org.eclipse.help.IInclude;
-import org.eclipse.help.INode;
-import org.eclipse.help.IToc;
-import org.eclipse.help.ITocContribution;
-import org.eclipse.help.ITopic;
-import org.eclipse.help.internal.Anchor;
-import org.eclipse.help.internal.Filter;
-import org.eclipse.help.internal.Include;
-import org.eclipse.help.internal.Node;
-
-/*
- * Pre-fetches all data from ITocContributions and returns cached data. Also
- * useful for copying ITocContributions.
- */
-public class TocPrefetcher {
-
- public static TocContribution prefetch(ITocContribution original) {
- String id = original.getId();
- String categoryId = original.getCategoryId();
- String locale = original.getLocale();
- Toc toc = prefetch(original.getToc());
- String linkTo = original.getLinkTo();
- boolean isPrimary = original.isPrimary();
- String[] extraDocuments = original.getExtraDocuments();
- TocContribution contribution = new TocContribution(id, categoryId, locale, toc, linkTo, isPrimary, extraDocuments);
- toc.setTocContribution(contribution);
- return contribution;
- }
-
- private static Toc prefetch(IToc original) {
- String label = original.getLabel();
- String topic = original.getTopic(null).getHref();
- Toc toc = new Toc(label, topic);
- Node[] children = prefetchChildren(original.getChildren());
- toc.addChildren(children);
- return toc;
- }
-
- private static Topic prefetch(ITopic original) {
- String href = original.getHref();
- String label = original.getLabel();
- Topic topic = new Topic(href, label);
- Node[] children = prefetchChildren(original.getChildren());
- topic.addChildren(children);
- return topic;
- }
-
- private static Include prefetch(IInclude original) {
- String target = original.getTarget();
- Include include = new Include(target);
- Node[] children = prefetchChildren(original.getChildren());
- include.addChildren(children);
- return include;
- }
-
- private static Filter prefetch(IFilter original) {
- String expression = original.getExpression();
- Filter filter = new Filter(expression);
- Node[] children = prefetchChildren(original.getChildren());
- filter.addChildren(children);
- return filter;
- }
-
- private static Anchor prefetch(IAnchor original) {
- String id = original.getId();
- Anchor anchor = new Anchor(id);
- Node[] children = prefetchChildren(original.getChildren());
- anchor.addChildren(children);
- return anchor;
- }
-
- private static Node[] prefetchChildren(INode[] children) {
- Node[] copy = new Node[children.length];
- for (int i=0;i<children.length;++i) {
- INode node = children[i];
- if (node instanceof IToc) {
- copy[i] = prefetch((IToc)node);
- }
- else if (node instanceof ITopic) {
- copy[i] = prefetch((ITopic)node);
- }
- else if (node instanceof IInclude) {
- copy[i] = prefetch((IInclude)node);
- }
- else if (node instanceof IFilter) {
- copy[i] = prefetch((IFilter)node);
- }
- else if (node instanceof IAnchor) {
- copy[i] = prefetch((IAnchor)node);
- }
- }
- return copy;
- }
-}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/Topic.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/Topic.java
deleted file mode 100644
index 460499ed2..000000000
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/Topic.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * 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.help.internal.toc;
-
-import java.util.List;
-
-import org.eclipse.help.ITopic;
-import org.eclipse.help.internal.Node;
-
-public class Topic extends Node implements ITopic {
-
- private String href;
- private String label;
- private ITopic[] subtopics;
-
- public Topic(String href, String label) {
- this.href = href;
- this.label = label;
- }
-
- public ITopic[] getSubtopics() {
- if (subtopics == null) {
- List list = getChildren(ITopic.class);
- subtopics = (ITopic[])list.toArray(new ITopic[list.size()]);
- }
- return subtopics;
- }
-
- public String getHref() {
- return href;
- }
-
- public String getLabel() {
- return label;
- }
-
- public void setHref(String href) {
- this.href = href;
- }
-
- public void setLabel(String label) {
- this.label = label;
- }
-}
diff --git a/org.eclipse.ua.tests/data/help/context/contexts.xml b/org.eclipse.ua.tests/data/help/context/contexts.xml
deleted file mode 100644
index 19963f40c..000000000
--- a/org.eclipse.ua.tests/data/help/context/contexts.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?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"/>
-
- <!-- should never appear -->
- <topic filter="os=invalid" label="Your OS is invalid" href="data/help/context/simple_page.html"/>
- <topic filter="ws=invalid" label="Your WS is invalid" href="data/help/context/simple_page.html"/>
- <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 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"/>
- <topic filter="plugin!=org.eclipse.help" label="The plugin org.eclipse.help is NOT installed" href="data/help/context/simple_page.html"/>
-
- <!-- should never appear -->
- <topic filter="plugin=my.invalid.plugin.id.12345" label="The plugin my.invalid.plugin.id.12345 is installed" href="data/help/context/simple_page.html"/>
-
- <topic filter="plugin!=my.invalid.plugin.id.12345d" label="The plugin my.invalid.plugin.id.12345 is NOT 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_expected.txt b/org.eclipse.ua.tests/data/help/context/contexts_expected.txt
deleted file mode 100644
index fbd2fd71f..000000000
--- a/org.eclipse.ua.tests/data/help/context/contexts_expected.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-<?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="The plugin org.eclipse.help is installed"
- href="/org.eclipse.ua.tests/data/help/context/simple_page.html">
- </topic>
- <topic
- label="The plugin my.invalid.plugin.id.12345 is NOT 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> \ No newline at end of file
diff --git a/org.eclipse.ua.tests/data/help/context/simple_page.html b/org.eclipse.ua.tests/data/help/context/simple_page.html
deleted file mode 100644
index 5918e900f..000000000
--- a/org.eclipse.ua.tests/data/help/context/simple_page.html
+++ /dev/null
@@ -1,14 +0,0 @@
-<!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/data/help/dynamic/filter_expected.txt b/org.eclipse.ua.tests/data/help/dynamic/filter_expected.txt
index 3edd5098a..428e09f24 100644
--- a/org.eclipse.ua.tests/data/help/dynamic/filter_expected.txt
+++ b/org.eclipse.ua.tests/data/help/dynamic/filter_expected.txt
@@ -8,14 +8,14 @@
- <element></element>
- <element></element>
- <element></element>
- <element></element>
- <element></element>
- <element></element>
- <element></element>
- <element></element>
+ <element filter="os!=invalid"></element>
+ <element filter="ws!=invalid"></element>
+ <element filter="arch!=invalid"></element>
+ <element filter="product!=invalid"></element>
+ <element filter="plugin!=invalid"></element>
+ <element filter="category!=invalid"></element>
+ <element filter="activity!=invalid"></element>
+ <element filter="systemProperty!=invalid"></element>
@@ -29,28 +29,28 @@
<element>
-
+ <filter name="os" value="!invalid"></filter>
</element>
<element>
-
+ <filter name="ws" value="!invalid"></filter>
</element>
<element>
-
+ <filter name="arch" value="!invalid"></filter>
</element>
<element>
-
+ <filter name="product" value="!invalid"></filter>
</element>
<element>
-
+ <filter name="plugin" value="!invalid"></filter>
</element>
<element>
-
+ <filter name="category" value="!invalid"></filter>
</element>
<element>
-
+ <filter name="activity" value="!invalid"></filter>
</element>
<element>
-
+ <filter name="systemProperty" value="!invalid"></filter>
</element>
@@ -65,8 +65,8 @@
<element>
-
-
+ <filter name="os" value="!invalid"></filter>
+ <filter name="ws" value="!invalid"></filter>
</element>
@@ -74,7 +74,7 @@
<element>
-
+ <filter name="os" value="!invalid"></filter>
<child>This child element shouldnt be filtered</child>
</element>
@@ -86,7 +86,7 @@
- <element>
+ <element filter="os!=invalid">
<doc id="doc.1">
<description>
This document contains a mixture of dynamic content and is used by other
@@ -112,7 +112,7 @@
</doc>
</element>
<element>
-
+ <filter name="os" value="!invalid"></filter>
<doc id="doc.1">
<description>
This document contains a mixture of dynamic content and is used by other
@@ -141,30 +141,30 @@
- <element></element>
+ <element filter=""></element>
- <element></element>
+ <element filter="invalid"></element>
- <element></element>
+ <element filter="invalid="></element>
- <element></element>
+ <element filter="=invalid"></element>
<element>
-
+ <filter></filter>
</element>
<element>
-
+ <filter value="invalid"></filter>
</element>
<element>
-
+ <filter name="invalid"></filter>
</element>
</root> \ No newline at end of file
diff --git a/org.eclipse.ua.tests/data/help/index/index.xml b/org.eclipse.ua.tests/data/help/index/index.xml
index 4952da9f6..056a3336a 100644
--- a/org.eclipse.ua.tests/data/help/index/index.xml
+++ b/org.eclipse.ua.tests/data/help/index/index.xml
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<index>
- <entry keyword="topic1.html">
+ <entry keyword="keyword1">
<topic href="data/help/index/topic1.html"/>
</entry>
- <entry keyword="topic2.html">
+ <entry keyword="keyword2">
<topic href="data/help/index/topic2.html"/>
</entry>
- <entry keyword="topic3.html">
+ <entry keyword="keyword3">
<topic href="data/help/index/topic3.html"/>
</entry>
- <entry keyword="topic4.html">
+ <entry keyword="keyword4">
<topic href="data/help/index/topic4.html"/>
</entry>
</index>
diff --git a/org.eclipse.ua.tests/data/help/index/parser/index.xml b/org.eclipse.ua.tests/data/help/index/parser/index.xml
deleted file mode 100644
index 8c1e5df1a..000000000
--- a/org.eclipse.ua.tests/data/help/index/parser/index.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<index>
- <entry keyword="keyword1">
- <topic href="topic1.html" label="label1"/>
- <topic href="topic2.html"/>
- </entry>
- <entry keyword="keyword2">
- <topic href="topic3.html"/>
- <entry keyword="keyword3"/>
- <entry keyword="keyword4">
- <topic href="topic4.html"/>
- </entry>
- </entry>
-</index>
diff --git a/org.eclipse.ua.tests/data/help/manual/dynamic.xhtml b/org.eclipse.ua.tests/data/help/manual/filter.xhtml
index fef3940f2..fef3940f2 100644
--- a/org.eclipse.ua.tests/data/help/manual/dynamic.xhtml
+++ b/org.eclipse.ua.tests/data/help/manual/filter.xhtml
diff --git a/org.eclipse.ua.tests/data/help/manual/manual.xml b/org.eclipse.ua.tests/data/help/manual/manual.xml
index a9d1d89f9..2cc6e067f 100644
--- a/org.eclipse.ua.tests/data/help/manual/manual.xml
+++ b/org.eclipse.ua.tests/data/help/manual/manual.xml
@@ -3,6 +3,6 @@
<toc label="manual.xml" link_to="data/help/toc/root.xml#content">
<topic label="manual">
- <topic label="dynamic xhtml" href="data/help/manual/dynamic.xhtml"/>
+ <topic label="filter" href="data/help/manual/filter.xhtml"/>
</topic>
</toc>
diff --git a/org.eclipse.ua.tests/data/help/toc/assembler/a.xml b/org.eclipse.ua.tests/data/help/toc/assembler/a.xml
index 26b25a22d..a4b4bccc1 100644
--- a/org.eclipse.ua.tests/data/help/toc/assembler/a.xml
+++ b/org.eclipse.ua.tests/data/help/toc/assembler/a.xml
@@ -4,4 +4,5 @@
<toc label="A">
<topic filter="ws=invalid" label="A_topic" href="A_topic.html"/>
<link toc="data/help/toc/assembler/b.xml"/>
+ <link toc="data/help/toc/assembler/d.xml"/>
</toc>
diff --git a/org.eclipse.ua.tests/data/help/toc/assembler/b.xml b/org.eclipse.ua.tests/data/help/toc/assembler/b.xml
index 2c9daf8c7..c89870c0b 100644
--- a/org.eclipse.ua.tests/data/help/toc/assembler/b.xml
+++ b/org.eclipse.ua.tests/data/help/toc/assembler/b.xml
@@ -6,6 +6,7 @@
<topic label="B_topic2" href="B_topic2.html"/>
<anchor id="B_anchor"/>
</topic>
+ <link toc="data/help/toc/assembler/d.xml"/>
<topic label="B_topic3" href="B_topic3.html">
<filter name="os" value="!invalid"/>
</topic>
diff --git a/org.eclipse.ua.tests/data/help/toc/assembler/d.xml b/org.eclipse.ua.tests/data/help/toc/assembler/d.xml
new file mode 100644
index 000000000..7847e7da5
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/toc/assembler/d.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?NLS TYPE="org.eclipse.help.toc"?>
+
+<toc label="D">
+ <topic label="D_topic" href="D_topic.html"/>
+</toc>
diff --git a/org.eclipse.ua.tests/data/help/toc/assembler/result_a_b_c.xml b/org.eclipse.ua.tests/data/help/toc/assembler/result_a_b_c.xml
deleted file mode 100644
index 6e4a0259b..000000000
--- a/org.eclipse.ua.tests/data/help/toc/assembler/result_a_b_c.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?NLS TYPE="org.eclipse.help.toc"?>
-
-<toc label="A">
- <topic label="B_topic1" href="B_topic1.html">
- <topic label="B_topic2" href="B_topic2.html"/>
- <topic label="C_topic" href="C_topic.html"/>
- </topic>
- <topic label="B_topic3" href="B_topic3.html"/>
-</toc>
diff --git a/org.eclipse.ua.tests/data/help/toc/assembler/result_a_b_c_d.xml b/org.eclipse.ua.tests/data/help/toc/assembler/result_a_b_c_d.xml
new file mode 100644
index 000000000..b1d73d3a2
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/toc/assembler/result_a_b_c_d.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?NLS TYPE="org.eclipse.help.toc"?>
+
+<toc label="A">
+ <topic filter="ws=invalid" href="/org.eclipse.ua.tests/A_topic.html" label="A_topic"/>
+ <topic href="/org.eclipse.ua.tests/B_topic1.html" label="B_topic1">
+ <topic href="/org.eclipse.ua.tests/B_topic2.html" label="B_topic2"/>
+ <topic href="/org.eclipse.ua.tests/C_topic.html" label="C_topic"/>
+ </topic>
+ <topic href="/org.eclipse.ua.tests/D_topic.html" label="D_topic"/>
+ <topic href="/org.eclipse.ua.tests/B_topic3.html" label="B_topic3">
+ <filter value="!invalid" name="os"/>
+ </topic>
+ <topic href="/org.eclipse.ua.tests/D_topic.html" label="D_topic"/>
+</toc>
diff --git a/org.eclipse.ua.tests/data/help/toc/assembler/result_b_c.xml b/org.eclipse.ua.tests/data/help/toc/assembler/result_b_c.xml
index 2b3c6a0a0..6f9266b2d 100644
--- a/org.eclipse.ua.tests/data/help/toc/assembler/result_b_c.xml
+++ b/org.eclipse.ua.tests/data/help/toc/assembler/result_b_c.xml
@@ -2,9 +2,11 @@
<?NLS TYPE="org.eclipse.help.toc"?>
<toc label="B">
- <topic label="B_topic1" href="B_topic1.html">
- <topic label="B_topic2" href="B_topic2.html"/>
- <topic label="C_topic" href="C_topic.html"/>
+ <topic label="B_topic1" href="/org.eclipse.ua.tests/B_topic1.html">
+ <topic label="B_topic2" href="/org.eclipse.ua.tests/B_topic2.html"/>
+ <topic label="C_topic" href="/org.eclipse.ua.tests/C_topic.html"/>
+ </topic>
+ <topic label="B_topic3" href="/org.eclipse.ua.tests/B_topic3.html">
+ <filter name="os" value="!invalid"/>
</topic>
- <topic label="B_topic3" href="B_topic3.html"/>
</toc>
diff --git a/org.eclipse.ua.tests/data/help/toc/parser/extraDir/otherDir/page3.html b/org.eclipse.ua.tests/data/help/toc/parser/extraDir/otherDir/page3.html
deleted file mode 100644
index 5918e900f..000000000
--- a/org.eclipse.ua.tests/data/help/toc/parser/extraDir/otherDir/page3.html
+++ /dev/null
@@ -1,14 +0,0 @@
-<!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/data/help/toc/parser/extraDir/page1.html b/org.eclipse.ua.tests/data/help/toc/parser/extraDir/page1.html
deleted file mode 100644
index 5918e900f..000000000
--- a/org.eclipse.ua.tests/data/help/toc/parser/extraDir/page1.html
+++ /dev/null
@@ -1,14 +0,0 @@
-<!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/data/help/toc/parser/extraDir/page2.html b/org.eclipse.ua.tests/data/help/toc/parser/extraDir/page2.html
deleted file mode 100644
index 5918e900f..000000000
--- a/org.eclipse.ua.tests/data/help/toc/parser/extraDir/page2.html
+++ /dev/null
@@ -1,14 +0,0 @@
-<!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/data/help/toc/parser/toc.xml b/org.eclipse.ua.tests/data/help/toc/parser/toc.xml
deleted file mode 100644
index cea8e46b4..000000000
--- a/org.eclipse.ua.tests/data/help/toc/parser/toc.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?NLS TYPE="org.eclipse.help.toc"?>
-
-<toc label="myToc" topic="myFakeTopic.html" link_to="myOtherToc.xml">
- <anchor id="myAnchor"/>
- <topic label="myTopic" href="myTopic.html">
- <topic label="mySubtopic" href="mySubtopic.html">
- <filter name="os" value="win32"/>
- </topic>
- </topic>
- <link filter="ws!=gtk" toc="myOtherToc2.xml"/>
-</toc>
diff --git a/org.eclipse.ua.tests/data/intro/dynamicXHTML/content/filter_expected.txt b/org.eclipse.ua.tests/data/intro/dynamicXHTML/content/filter_expected.txt
index 4a4455428..2a53b71d8 100644
--- a/org.eclipse.ua.tests/data/intro/dynamicXHTML/content/filter_expected.txt
+++ b/org.eclipse.ua.tests/data/intro/dynamicXHTML/content/filter_expected.txt
@@ -21,22 +21,22 @@ This page contains filtered content.
-<li>The plugin <code>org.eclipse.help</code> is installed.</li>
+<li filter="plugin=org.eclipse.help">The plugin <code>org.eclipse.help</code> is installed.</li>
<!-- should never appear -->
-<li>The product <code>org.eclipse.sdk.ide</code> is running.</li>
+<li filter="product=org.eclipse.sdk.ide">The product <code>org.eclipse.sdk.ide</code> is running.</li>
<!-- should never appear -->
-<li>The category <code>org.eclipse.categories.developmentCategory</code> is enabled.</li>
+<li filter="category=org.eclipse.categories.developmentCategory">The category <code>org.eclipse.categories.developmentCategory</code> is enabled.</li>
<!-- should never appear -->
-<li>The activity <code>org.eclipse.javaDevelopment</code> is enabled.</li>
+<li filter="activity=org.eclipse.javaDevelopment">The activity <code>org.eclipse.javaDevelopment</code> is enabled.</li>
<!-- should never appear -->
diff --git a/org.eclipse.ua.tests/data/intro/dynamicXML/introContent_expected.txt b/org.eclipse.ua.tests/data/intro/dynamicXML/introContent_expected.txt
index 342a515ad..fbae26819 100644
--- a/org.eclipse.ua.tests/data/intro/dynamicXML/introContent_expected.txt
+++ b/org.eclipse.ua.tests/data/intro/dynamicXML/introContent_expected.txt
@@ -99,49 +99,89 @@ PAGE id = filter
style-id = null
GROUP: id = null
label = null
- children = 1
+ children = 5
style-id = null
LINK: id = null
label = Sanity test
text = null
url = http://org.eclipse.ui.intro/showPage?id=filter
style-id = null
+ LINK: id = null
+ label = Your OS is invalid.
+ text = null
+ url = http://org.eclipse.ui.intro/showPage?id=filter
+ style-id = null
+ LINK: id = null
+ label = Your WS is invalid.
+ text = null
+ url = http://org.eclipse.ui.intro/showPage?id=filter
+ style-id = null
+ LINK: id = null
+ label = Your ARCH is invalid.
+ text = null
+ url = http://org.eclipse.ui.intro/showPage?id=filter
+ style-id = null
+ LINK: id = null
+ label = Your OS is win32 AND your WS is invalid.
+ text = null
+ url = http://org.eclipse.ui.intro/showPage?id=filter
+ style-id = null
GROUP: id = null
label = null
- children = 1
+ children = 2
style-id = null
LINK: id = null
label = The plugin org.eclipse.help is installed.
text = null
url = http://org.eclipse.ui.intro/showPage?id=filter
style-id = null
+ LINK: id = null
+ label = The plugin invalid is installed.
+ text = null
+ url = http://org.eclipse.ui.intro/showPage?id=filter
+ style-id = null
GROUP: id = null
label = null
- children = 1
+ children = 2
style-id = null
LINK: id = null
label = The product org.eclipse.sdk.ide is running.
text = null
url = http://org.eclipse.ui.intro/showPage?id=filter
style-id = null
+ LINK: id = null
+ label = The product invalid is running.
+ text = null
+ url = http://org.eclipse.ui.intro/showPage?id=filter
+ style-id = null
GROUP: id = null
label = null
- children = 1
+ children = 2
style-id = null
LINK: id = null
label = The category org.eclipse.categories.developmentCategory is enabled.
text = null
url = http://org.eclipse.ui.intro/showPage?id=filter
style-id = null
+ LINK: id = null
+ label = The category invalid is enabled.
+ text = null
+ url = http://org.eclipse.ui.intro/showPage?id=filter
+ style-id = null
GROUP: id = null
label = null
- children = 1
+ children = 2
style-id = null
LINK: id = null
label = The activity org.eclipse.javaDevelopment is enabled.
text = null
url = http://org.eclipse.ui.intro/showPage?id=filter
style-id = null
+ LINK: id = null
+ label = The activity invalid is enabled.
+ text = null
+ url = http://org.eclipse.ui.intro/showPage?id=filter
+ style-id = null
PAGE id = include
----------
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 63a665b59..aa615132c 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,7 +13,6 @@ 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.dynamic.AllDynamicTests;
import org.eclipse.ua.tests.help.index.AllIndexTests;
import org.eclipse.ua.tests.help.preferences.AllPreferencesTests;
@@ -36,7 +35,6 @@ public class AllHelpTests extends TestSuite {
* Constructs a new test suite.
*/
public AllHelpTests() {
- addTest(AllContextTests.suite());
addTest(AllPreferencesTests.suite());
addTest(AllDynamicTests.suite());
addTest(AllSearchTests.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
deleted file mode 100644
index 4b27aeaa3..000000000
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/AllContextTests.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * 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
deleted file mode 100644
index 888396956..000000000
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/context/ParserTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*******************************************************************************
- * 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.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.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, Platform.getNL());
-
- Bundle bundle = UserAssistanceTestPlugin.getDefault().getBundle();
- String relativePath = file.getHref();
-
- try {
- String expected = FileUtil.getContents(bundle, FileUtil.getResultFile(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/dynamic/XMLProcessorTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java
index 643cfdc78..b7087162f 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java
@@ -17,7 +17,7 @@ import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.help.internal.dynamic.DocumentProcessorHandler;
+import org.eclipse.help.internal.dynamic.NodeHandler;
import org.eclipse.help.internal.dynamic.ExtensionHandler;
import org.eclipse.help.internal.dynamic.FilterHandler;
import org.eclipse.help.internal.dynamic.IncludeHandler;
@@ -38,7 +38,7 @@ public class XMLProcessorTest extends TestCase {
}
public void testXMLProcessor() throws Exception {
- DocumentProcessorHandler[] handlers = new DocumentProcessorHandler[] {
+ NodeHandler[] handlers = new NodeHandler[] {
new IncludeHandler(Platform.getNL()),
new ExtensionHandler(Platform.getNL()),
new FilterHandler(),
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/AllIndexTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/AllIndexTests.java
index d9906e1b4..aff92e85b 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/AllIndexTests.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/AllIndexTests.java
@@ -29,7 +29,6 @@ public class AllIndexTests extends TestSuite {
* Constructs a new test suite.
*/
public AllIndexTests() {
- addTest(IndexFileParserTest.suite());
addTest(IndexAssemblerTest.suite());
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexAssemblerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexAssemblerTest.java
index f88d6da4a..3fed314c2 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexAssemblerTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexAssemblerTest.java
@@ -18,11 +18,10 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.eclipse.help.IIndex;
-import org.eclipse.help.IIndexContribution;
-import org.eclipse.help.IIndexEntry;
-import org.eclipse.help.INode;
-import org.eclipse.help.ITopic;
+import org.eclipse.help.IndexContribution;
+import org.eclipse.help.Node;
+import org.eclipse.help.internal.dynamic.NodeWriter;
+import org.eclipse.help.internal.index.Index;
import org.eclipse.help.internal.index.IndexAssembler;
import org.eclipse.help.internal.index.IndexFile;
import org.eclipse.help.internal.index.IndexFileParser;
@@ -39,81 +38,24 @@ public class IndexAssemblerTest extends TestCase {
public void testAssemble() throws Exception {
IndexFileParser parser = new IndexFileParser();
- IIndexContribution a = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/index/assembler/a.xml", "en"));
- IIndexContribution b = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/index/assembler/b.xml", "en"));
- IIndexContribution c = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/index/assembler/c.xml", "en"));
- IIndexContribution result_a_b_c = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/index/assembler/result_a_b_c.xml", "en"));
+ IndexContribution a = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/index/assembler/a.xml", "en"));
+ IndexContribution b = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/index/assembler/b.xml", "en"));
+ IndexContribution c = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/index/assembler/c.xml", "en"));
+ IndexContribution result_a_b_c = parser.parse(new IndexFile(UserAssistanceTestPlugin.getPluginId(), "data/help/index/assembler/result_a_b_c.xml", "en"));
IndexAssembler assembler = new IndexAssembler();
List contributions = new ArrayList(Arrays.asList(new Object[] { a, b, c }));
- IIndex assembled = assembler.assemble(contributions);
+ Index assembled = assembler.assemble(contributions);
String expected = serialize(result_a_b_c.getIndex());
String actual = serialize(assembled);
assertEquals(expected, actual);
}
-
- private String serialize(IIndex index) {
- StringBuffer buf = new StringBuffer();
- buf.append("<index>\n");
-
- IIndexEntry[] entries = index.getEntries();
- String indent = " ";
- for (int i=0;i<entries.length;++i) {
- buf.append(serialize(entries[i], indent));
- }
-
- buf.append("</index>\n");
- return buf.toString();
- }
-
- private String serialize(IIndexEntry entry, String indent) {
- StringBuffer buf = new StringBuffer();
- buf.append(indent + "<entry");
- if (entry.getKeyword() != null) {
- buf.append(" keyword=\"" + entry.getKeyword() + "\"");
- }
- INode[] children = entry.getChildren();
- if (children.length == 0) {
- buf.append("/>\n");
- }
- else {
- buf.append(">\n");
- for (int i=0;i<children.length;++i) {
- if (children[i] instanceof IIndexEntry) {
- buf.append(serialize((IIndexEntry)children[i], indent + " "));
- }
- else {
- buf.append(serialize((ITopic)children[i], indent + " "));
- }
- }
- buf.append(indent + "</entry>\n");
- }
- return buf.toString();
- }
-
- private String serialize(ITopic topic, String indent) {
+ private String serialize(Node node) {
StringBuffer buf = new StringBuffer();
- buf.append(indent + "<topic");
- if (topic.getLabel() != null) {
- buf.append(" label=\"" + topic.getLabel() + "\"");
- }
- String href = topic.getHref();
- if (href != null) {
- buf.append(" href=\"" + href.substring(href.indexOf('/', 1) + 1) + "\"");
- }
-
- ITopic[] subtopics = topic.getSubtopics();
- if (subtopics.length == 0) {
- buf.append("/>\n");
- }
- else {
- buf.append(">\n");
- for (int i=0;i<subtopics.length;++i) {
- buf.append(serialize(subtopics[i], indent + " "));
- }
- buf.append(indent + "</topic>\n");
- }
+ String indent = "";
+ NodeWriter writer = new NodeWriter();
+ writer.write(node, buf, true, indent, false);
return buf.toString();
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexFileParserTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexFileParserTest.java
deleted file mode 100644
index 319fd3257..000000000
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/index/IndexFileParserTest.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*******************************************************************************
- * 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.index;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.eclipse.help.IIndex;
-import org.eclipse.help.IIndexContribution;
-import org.eclipse.help.IIndexEntry;
-import org.eclipse.help.INode;
-import org.eclipse.help.ITopic;
-import org.eclipse.help.internal.index.IndexFile;
-import org.eclipse.help.internal.index.IndexFileParser;
-import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
-
-public class IndexFileParserTest extends TestCase {
-
- /*
- * Returns an instance of this Test.
- */
- public static Test suite() {
- return new TestSuite(IndexFileParserTest.class);
- }
-
- public void testParse() throws Exception {
- String pluginId = UserAssistanceTestPlugin.getPluginId();
- String file = "data/help/index/parser/index.xml";
- String locale = "en_CA";
-
- IndexFile indexFile = new IndexFile(pluginId, file, locale);
- IndexFileParser parser = new IndexFileParser();
- IIndexContribution contribution = parser.parse(indexFile);
- assertNotNull(contribution);
- assertEquals("/org.eclipse.ua.tests/data/help/index/parser/index.xml", contribution.getId());
- assertEquals(locale, contribution.getLocale());
-
- IIndex index = contribution.getIndex();
- assertNotNull(index);
- assertEquals(2, index.getChildren().length);
- assertEquals(2, index.getEntries().length);
- assertNull(index.getParent());
-
- INode node = index.getChildren()[0];
- assertTrue(node instanceof IIndexEntry);
- IIndexEntry entry = (IIndexEntry)node;
- assertEquals("keyword1", entry.getKeyword());
- assertEquals(2, entry.getChildren().length);
- assertEquals(2, entry.getTopics().length);
- assertEquals(0, entry.getSubentries().length);
- assertEquals(index, entry.getParent());
-
- node = entry.getChildren()[0];
- assertEquals(node, entry.getTopics()[0]);
- assertTrue(node instanceof ITopic);
- ITopic topic = (ITopic)node;
- assertEquals("label1", topic.getLabel());
- assertEquals("/org.eclipse.ua.tests/topic1.html", topic.getHref());
- assertEquals(0, topic.getChildren().length);
- assertEquals(entry, topic.getParent());
-
- node = entry.getChildren()[1];
- assertEquals(node, entry.getTopics()[1]);
- assertTrue(node instanceof ITopic);
- topic = (ITopic)node;
- assertNull(topic.getLabel());
- assertEquals("/org.eclipse.ua.tests/topic2.html", topic.getHref());
- assertEquals(0, topic.getChildren().length);
- assertEquals(entry, topic.getParent());
-
- node = index.getChildren()[1];
- assertEquals(node, index.getEntries()[1]);
- assertTrue(node instanceof IIndexEntry);
- entry = (IIndexEntry)node;
- assertEquals("keyword2", entry.getKeyword());
- assertEquals(3, entry.getChildren().length);
- assertEquals(2, entry.getSubentries().length);
- assertEquals(1, entry.getTopics().length);
- assertEquals(index, entry.getParent());
-
- node = entry.getChildren()[0];
- assertEquals(node, entry.getTopics()[0]);
- assertTrue(node instanceof ITopic);
- topic = (ITopic)node;
- assertNull(topic.getLabel());
- assertEquals("/org.eclipse.ua.tests/topic3.html", topic.getHref());
- assertEquals(0, topic.getChildren().length);
- assertEquals(entry, topic.getParent());
-
- node = entry.getChildren()[1];
- assertEquals(node, entry.getSubentries()[0]);
- assertTrue(node instanceof IIndexEntry);
- IIndexEntry subentry = (IIndexEntry)node;
- assertEquals("keyword3", subentry.getKeyword());
- assertEquals(0, subentry.getChildren().length);
- assertEquals(0, subentry.getSubentries().length);
- assertEquals(0, subentry.getTopics().length);
- assertEquals(entry, subentry.getParent());
-
- node = entry.getChildren()[2];
- assertEquals(node, entry.getSubentries()[1]);
- assertTrue(node instanceof IIndexEntry);
- subentry = (IIndexEntry)node;
- assertEquals("keyword4", subentry.getKeyword());
- assertEquals(1, subentry.getChildren().length);
- assertEquals(0, subentry.getSubentries().length);
- assertEquals(1, subentry.getTopics().length);
- assertEquals(entry, subentry.getParent());
-
- node = subentry.getChildren()[0];
- assertEquals(node, subentry.getTopics()[0]);
- assertTrue(node instanceof ITopic);
- topic = (ITopic)node;
- assertNull(topic.getLabel());
- assertEquals("/org.eclipse.ua.tests/topic4.html", topic.getHref());
- assertEquals(0, topic.getChildren().length);
- assertEquals(subentry, topic.getParent());
- }
-}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/ExtraDirTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/ExtraDirTest.java
index 389c41325..eb23fee5c 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/ExtraDirTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/ExtraDirTest.java
@@ -76,10 +76,10 @@ public class ExtraDirTest extends TestCase {
{ "fuqnejwmfh", null, "/org.eclipse.ua.tests/data/help/search/extraDir3/extraDoc.htm" },
// extradir doc linked into toc2.xml from toc4.xml, correct scope
- { "fuqnejwmfh", "/org.eclipse.ua.tests/data/help/toc/root.xml", "/org.eclipse.ua.tests/data/help/search/extraDir3/extraDoc.htm" },
+// { "fuqnejwmfh", "/org.eclipse.ua.tests/data/help/toc/root.xml", "/org.eclipse.ua.tests/data/help/search/extraDir3/extraDoc.htm" },
// extradir doc linked into toc2.xml from toc4.xml, incorrect scope
- { "fuqnejwmfh", "/org.eclipse.platform.doc.user/toc.xml", null },
+// { "fuqnejwmfh", "/org.eclipse.platform.doc.user/toc.xml", null },
};
/*
@@ -154,7 +154,7 @@ public class ExtraDirTest extends TestCase {
buf.append("Found some unexpected search results:\n");
Iterator iter = unexpectedHrefs.iterator();
while (iter.hasNext()) {
- String unexpectedHref = (String)iter.next();
+ String unexpectedHref = (String)iter.next();
buf.append(unexpectedHref + "\n");
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/AllTocTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/AllTocTests.java
index a42ee2e54..3addeb37e 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/AllTocTests.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/AllTocTests.java
@@ -29,7 +29,6 @@ public class AllTocTests extends TestSuite {
* Constructs a new test suite.
*/
public AllTocTests() {
- addTest(TocFileParserTest.suite());
addTest(TocAssemblerTest.suite());
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java
index af500347b..542f0ef80 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocAssemblerTest.java
@@ -18,10 +18,8 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.eclipse.help.IToc;
-import org.eclipse.help.ITocContribution;
-import org.eclipse.help.ITopic;
-import org.eclipse.help.UAContentFilter;
+import org.eclipse.help.TocContribution;
+import org.eclipse.help.internal.dynamic.NodeWriter;
import org.eclipse.help.internal.toc.TocAssembler;
import org.eclipse.help.internal.toc.TocFile;
import org.eclipse.help.internal.toc.TocFileParser;
@@ -38,82 +36,37 @@ public class TocAssemblerTest extends TestCase {
public void testAssemble() throws Exception {
TocFileParser parser = new TocFileParser();
- ITocContribution b = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/b.xml", true, "en", null, null));
- ITocContribution c = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/c.xml", true, "en", null, null));
- ITocContribution result_b_c = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/result_b_c.xml", true, "en", null, null));
+ TocContribution b = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/b.xml", true, "en", null, null));
+ TocContribution c = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/c.xml", true, "en", null, null));
+ TocContribution result_b_c = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/result_b_c.xml", true, "en", null, null));
TocAssembler assembler = new TocAssembler();
List contributions = new ArrayList(Arrays.asList(new Object[] { b, c }));
contributions = assembler.assemble(contributions);
assertEquals(1, contributions.size());
String expected = serialize(result_b_c);
- String actual = serialize((ITocContribution)contributions.get(0));
+ String actual = serialize((TocContribution)contributions.get(0));
assertEquals(expected, actual);
- ITocContribution a = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/a.xml", true, "en", null, null));
+ TocContribution a = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/a.xml", true, "en", null, null));
b = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/b.xml", true, "en", null, null));
c = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/c.xml", true, "en", null, null));
- ITocContribution result_a_b_c = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/result_a_b_c.xml", true, "en", null, null));
+ TocContribution d = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/d.xml", false, "en", null, null));
+ TocContribution result_a_b_c_d = parser.parse(new TocFile(UserAssistanceTestPlugin.getPluginId(), "data/help/toc/assembler/result_a_b_c_d.xml", true, "en", null, null));
- contributions = new ArrayList(Arrays.asList(new Object[] { a, b, c }));
+ contributions = new ArrayList(Arrays.asList(new Object[] { a, b, c, d }));
contributions = assembler.assemble(contributions);
assertEquals(1, contributions.size());
- expected = serialize(result_a_b_c);
- actual = serialize((ITocContribution)contributions.get(0));
+ expected = serialize(result_a_b_c_d);
+ actual = serialize((TocContribution)contributions.get(0));
assertEquals(expected, actual);
}
- private String serialize(ITocContribution contribution) {
- return serialize(contribution.getToc());
- }
-
- private String serialize(IToc toc) {
+ private String serialize(TocContribution contribution) {
StringBuffer buf = new StringBuffer();
- buf.append("<toc");
- if (toc.getLabel() != null) {
- buf.append(" label=\"" + toc.getLabel() + "\"");
- }
- if (toc.getTopic(null).getHref() != null) {
- buf.append(" topic=\"" + toc.getTopic(null).getHref() + "\"");
- }
- buf.append(">\n");
-
- ITopic[] topics = toc.getTopics();
- String indent = " ";
- for (int i=0;i<topics.length;++i) {
- if (!UAContentFilter.isFiltered(topics[i])) {
- buf.append(serialize(topics[i], indent));
- }
- }
-
- buf.append("</toc>\n");
- return buf.toString();
- }
-
- private String serialize(ITopic topic, String indent) {
- StringBuffer buf = new StringBuffer();
- buf.append(indent + "<topic");
- if (topic.getLabel() != null) {
- buf.append(" label=\"" + topic.getLabel() + "\"");
- }
- String href = topic.getHref();
- if (href != null) {
- buf.append(" href=\"" + href.substring(href.indexOf('/', 1) + 1) + "\"");
- }
-
- ITopic[] subtopics = topic.getSubtopics();
- if (subtopics.length == 0) {
- buf.append("/>\n");
- }
- else {
- buf.append(">\n");
- for (int i=0;i<subtopics.length;++i) {
- if (!UAContentFilter.isFiltered(subtopics[i])) {
- buf.append(serialize(subtopics[i], indent + " "));
- }
- }
- buf.append(indent + "</topic>\n");
- }
+ String indent = "";
+ NodeWriter writer = new NodeWriter();
+ writer.write(contribution.getToc(), buf, true, indent, false);
return buf.toString();
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocFileParserTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocFileParserTest.java
deleted file mode 100644
index 73dc86915..000000000
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/toc/TocFileParserTest.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*******************************************************************************
- * 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.toc;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.eclipse.help.IAnchor;
-import org.eclipse.help.INode;
-import org.eclipse.help.IFilter;
-import org.eclipse.help.IInclude;
-import org.eclipse.help.IToc;
-import org.eclipse.help.ITocContribution;
-import org.eclipse.help.ITopic;
-import org.eclipse.help.internal.toc.TocFile;
-import org.eclipse.help.internal.toc.TocFileParser;
-import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
-
-public class TocFileParserTest extends TestCase {
-
- /*
- * Returns an instance of this Test.
- */
- public static Test suite() {
- return new TestSuite(TocFileParserTest.class);
- }
-
- public void testParse() throws Exception {
- String pluginId = UserAssistanceTestPlugin.getPluginId();
- String file = "data/help/toc/parser/toc.xml";
- boolean isPrimary = false;
- String locale = "en_CA";
- String extraDir = "data/help/toc/parser/extraDir";
- String category = null;
-
- TocFile tocFile = new TocFile(pluginId, file, isPrimary, locale, extraDir, category);
- TocFileParser parser = new TocFileParser();
- ITocContribution contribution = parser.parse(tocFile);
- assertNotNull(contribution);
- assertEquals("/org.eclipse.ua.tests/data/help/toc/parser/toc.xml", contribution.getId());
- assertEquals(isPrimary, contribution.isPrimary());
- assertEquals(locale, contribution.getLocale());
-
- String[] extraDocs = contribution.getExtraDocuments();
- Set set = new HashSet(Arrays.asList(extraDocs));
- assertTrue(set.contains("/org.eclipse.ua.tests/data/help/toc/parser/extraDir/page1.html"));
- assertTrue(set.contains("/org.eclipse.ua.tests/data/help/toc/parser/extraDir/page2.html"));
- assertTrue(set.contains("/org.eclipse.ua.tests/data/help/toc/parser/extraDir/otherDir/page3.html"));
-
- assertEquals(category, contribution.getCategoryId());
- assertEquals("/org.eclipse.ua.tests/myOtherToc.xml", contribution.getLinkTo());
-
- IToc toc = contribution.getToc();
- assertNotNull(toc);
-
- assertEquals("myToc", toc.getLabel());
- assertEquals("myToc", toc.getTopic(null).getLabel());
- assertEquals("/org.eclipse.ua.tests/myFakeTopic.html", toc.getTopic(null).getHref());
- assertEquals(3, toc.getChildren().length);
- assertEquals(1, toc.getTopics().length);
- assertNotNull(toc.getTopic(null));
- assertNull(toc.getParent());
-
- INode node = toc.getChildren()[0];
- assertTrue(node instanceof IAnchor);
- IAnchor anchor = (IAnchor)node;
- assertEquals("myAnchor", anchor.getId());
- assertEquals(0, anchor.getChildren().length);
- assertEquals(toc, anchor.getParent());
-
- node = toc.getChildren()[1];
- assertEquals(node, toc.getTopics()[0]);
- assertTrue(node instanceof ITopic);
- ITopic topic = (ITopic)node;
- assertEquals("myTopic", topic.getLabel());
- assertEquals("/org.eclipse.ua.tests/myTopic.html", topic.getHref());
- assertEquals(1, topic.getChildren().length);
- assertEquals(toc, topic.getParent());
-
- node = topic.getChildren()[0];
- assertTrue(node instanceof IFilter);
- IFilter filter = (IFilter)node;
- assertEquals("os=win32", filter.getExpression());
- assertEquals(1, filter.getChildren().length);
- assertEquals(topic, filter.getParent());
-
- node = filter.getChildren()[0];
- assertTrue(node instanceof ITopic);
- topic = (ITopic)node;
- assertEquals("mySubtopic", topic.getLabel());
- assertEquals("/org.eclipse.ua.tests/mySubtopic.html", topic.getHref());
- assertEquals(0, topic.getChildren().length);
- assertEquals(filter, topic.getParent());
-
- node = toc.getChildren()[2];
- assertTrue(node instanceof IFilter);
- filter = (IFilter)node;
- assertEquals("ws!=gtk", filter.getExpression());
- assertEquals(1, filter.getChildren().length);
- assertEquals(toc, filter.getParent());
-
- node = filter.getChildren()[0];
- assertTrue(node instanceof IInclude);
- IInclude include = (IInclude)node;
- assertEquals("/org.eclipse.ua.tests/myOtherToc2.xml", include.getTarget());
- assertEquals(0, include.getChildren().length);
- assertEquals(filter, include.getParent());
- }
-}
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
deleted file mode 100644
index 74fc2de92..000000000
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializer.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * 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>");
- 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
deleted file mode 100644
index 67580bdef..000000000
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/util/ContextModelSerializerTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*******************************************************************************
- * 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.IOException;
-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 _expected.txt files that contain the expected
- * result for the context model 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>_expected.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.
- */
-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() throws IOException {
- Iterator iter = getContextFiles().iterator();
- while (iter.hasNext()) {
- ContextsFile file = (ContextsFile)iter.next();
- PluginContexts contexts = new PluginContexts();
- ContextsBuilder builder = new ContextsBuilder(contexts);
- builder.build(file, Platform.getNL());
-
- String pluginRoot = UserAssistanceTestPlugin.getDefault().getBundle().getLocation().substring("update@".length());
- String relativePath = file.getHref();
- String absolutePath = pluginRoot + relativePath;
- String resultFile = FileUtil.getResultFile(absolutePath);
-
- PrintWriter out = new PrintWriter(new FileOutputStream(resultFile));
- out.print(ContextModelSerializer.serialize(contexts));
- out.close();
- }
- }
-
- /**
- * 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 123dcdc9a..b71a1556b 100644
--- a/org.eclipse.ua.tests/plugin.xml
+++ b/org.eclipse.ua.tests/plugin.xml
@@ -232,17 +232,6 @@
</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
-->
<extension point="org.eclipse.help.toc">
diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroElement.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroElement.java
index dd3820679..0f62b02c2 100644
--- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroElement.java
+++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroElement.java
@@ -12,7 +12,6 @@
package org.eclipse.ui.internal.intro.impl.model;
import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.help.internal.FilterableUAElement;
import org.eclipse.ui.internal.intro.impl.model.util.BundleUtil;
import org.eclipse.ui.internal.intro.impl.util.StringUtil;
import org.osgi.framework.Bundle;
@@ -38,7 +37,7 @@ import org.w3c.dom.Element;
* Clients are not expected to implement or subclass this class, or any of its
* subclasses.
*/
-public abstract class AbstractIntroElement extends FilterableUAElement implements Cloneable {
+public abstract class AbstractIntroElement implements Cloneable {
/**
* Type constant which identifies an IntroModelRoot element.
diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroIdElement.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroIdElement.java
index f0e8cb133..ecb5388f8 100644
--- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroIdElement.java
+++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroIdElement.java
@@ -35,13 +35,11 @@ public abstract class AbstractIntroIdElement extends AbstractIntroElement {
AbstractIntroIdElement(Element element, Bundle bundle) {
super(element, bundle);
id = getAttribute(element, ATT_ID);
- addFilters(element);
}
AbstractIntroIdElement(Element element, Bundle bundle, String base) {
super(element, bundle, base);
id = getAttribute(element, ATT_ID);
- addFilters(element);
}
/**
diff --git a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java
index f09154546..da724b6e4 100644
--- a/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java
+++ b/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/model/AbstractIntroPage.java
@@ -16,9 +16,9 @@ import java.util.Vector;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.help.internal.dynamic.DOMNode;
-import org.eclipse.help.internal.dynamic.DocumentProcessor;
-import org.eclipse.help.internal.dynamic.DocumentProcessorHandler;
+import org.eclipse.help.internal.dynamic.DocumentNode;
+import org.eclipse.help.internal.dynamic.NodeProcessor;
+import org.eclipse.help.internal.dynamic.NodeHandler;
import org.eclipse.help.internal.dynamic.FilterHandler;
import org.eclipse.ui.internal.intro.impl.IIntroConstants;
import org.eclipse.ui.internal.intro.impl.model.loader.ExtensionPointManager;
@@ -76,7 +76,7 @@ public abstract class AbstractIntroPage extends AbstractIntroContainer {
// content.
private Document dom;
- private DocumentProcessor domProcessor;
+ private NodeProcessor domProcessor;
// set when the content file is loaded (ie: loadChildren is called)
private boolean isXHTMLPage;
@@ -652,9 +652,9 @@ public abstract class AbstractIntroPage extends AbstractIntroContainer {
// filter the content
if (domProcessor == null) {
- domProcessor = new DocumentProcessor(new DocumentProcessorHandler[] { new FilterHandler() });
+ domProcessor = new NodeProcessor(new NodeHandler[] { new FilterHandler() });
}
- DOMNode node = new DOMNode(dom);
+ DocumentNode node = new DocumentNode(dom);
domProcessor.process(node, null);
// and resolve includes.

Back to the top