Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.help')
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java72
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocBuilder.java29
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/xhtml/DOMUtil.java2
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentFilterProcessor.java3
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentParser.java11
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLContentProducer.java67
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLSupport.java44
7 files changed, 169 insertions, 59 deletions
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 f1cd49c84..2cb7779fa 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/HelpPlugin.java
@@ -1,36 +1,44 @@
-/*******************************************************************************
- * 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
+/***************************************************************************************************
+ * 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
- *******************************************************************************/
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
package org.eclipse.help.internal;
-import java.util.*;
-
-import org.eclipse.core.runtime.*;
-import org.eclipse.help.internal.context.*;
-import org.eclipse.help.internal.toc.*;
-import org.eclipse.help.internal.index.*;
-import org.eclipse.help.internal.util.*;
-import org.osgi.framework.*;
+
+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.index.IndexManager;
+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 implements IRegistryChangeListener, BundleListener {
+
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;
protected static HelpPlugin plugin;
-// private static BundleContext bundleContext;
+ // private static BundleContext bundleContext;
private List tocsChangedListeners = new Vector();
public final static String BASE_TOCS_KEY = "baseTOCS"; //$NON-NLS-1$
@@ -48,16 +56,17 @@ public class HelpPlugin extends Plugin
public static synchronized void logError(String message, Throwable ex) {
if (message == null)
message = ""; //$NON-NLS-1$
- Status errorStatus = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK,
- message, ex);
+ Status errorStatus = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, message, ex);
logStatus(errorStatus);
}
+
/**
* Logs an IStatus
*/
private static void logStatus(IStatus errorStatus) {
HelpPlugin.getDefault().getLog().log(errorStatus);
}
+
/**
* Logs a Warning message with an exception.
*/
@@ -65,8 +74,7 @@ public class HelpPlugin extends Plugin
if (HelpPlugin.DEBUG) {
if (message == null)
message = ""; //$NON-NLS-1$
- Status warningStatus = new Status(IStatus.WARNING, PLUGIN_ID,
- IStatus.OK, message, null);
+ Status warningStatus = new Status(IStatus.WARNING, PLUGIN_ID, IStatus.OK, message, null);
HelpPlugin.getDefault().getLog().log(warningStatus);
}
}
@@ -77,6 +85,7 @@ public class HelpPlugin extends Plugin
public static HelpPlugin getDefault() {
return plugin;
}
+
/*
* (non-Javadoc)
*
@@ -86,7 +95,7 @@ public class HelpPlugin extends Plugin
Platform.getExtensionRegistry().removeRegistryChangeListener(this);
context.removeBundleListener(this);
plugin = null;
-// bundleContext = null;
+ // bundleContext = null;
super.stop(context);
}
@@ -98,10 +107,9 @@ public class HelpPlugin extends Plugin
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
-// bundleContext = context;
+ // bundleContext = context;
context.addBundleListener(this);
- Platform.getExtensionRegistry().addRegistryChangeListener(this,
- HelpPlugin.PLUGIN_ID);
+ Platform.getExtensionRegistry().addRegistryChangeListener(this, HelpPlugin.PLUGIN_ID);
// Setup debugging options
DEBUG = isDebugging();
if (DEBUG) {
@@ -109,6 +117,7 @@ public class HelpPlugin extends Plugin
DEBUG_PROTOCOLS = "true".equalsIgnoreCase(Platform.getDebugOption(PLUGIN_ID + "/debug/protocols")); //$NON-NLS-1$ //$NON-NLS-2$
}
}
+
/**
* Used to obtain Toc Naviagiont Manager
*
@@ -124,6 +133,7 @@ public class HelpPlugin extends Plugin
}
return getDefault().tocManager;
}
+
/**
* Used to obtain Context Manager returns an instance of ContextManager
*/
@@ -132,14 +142,14 @@ public class HelpPlugin extends Plugin
getDefault().contextManager = new ContextManager();
return getDefault().contextManager;
}
+
/*
* (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, TocManager.TOC_XP_NAME);
+ IExtensionDelta[] deltas = event.getExtensionDeltas(HelpPlugin.PLUGIN_ID, TocManager.TOC_XP_NAME);
if (deltas.length > 0) {
tocManager = null;
}
@@ -150,11 +160,13 @@ public class HelpPlugin extends Plugin
}
}
}
+
public void addTocsChangedListener(ITocsChangedListener listener) {
if (!tocsChangedListeners.contains(listener)) {
tocsChangedListeners.add(listener);
}
}
+
public void removeTocsChangedListener(ITocsChangedListener listener) {
tocsChangedListeners.remove(listener);
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocBuilder.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocBuilder.java
index fe4769e18..6bc295ded 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocBuilder.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocBuilder.java
@@ -1,20 +1,22 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
+/***************************************************************************************************
+ * Copyright (c) 2000, 2004 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
- *******************************************************************************/
+ * Contributors: IBM Corporation - initial API and implementation
+ **************************************************************************************************/
package org.eclipse.help.internal.toc;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
-import org.eclipse.help.internal.*;
+import org.eclipse.help.internal.HelpPlugin;
public class TocBuilder {
+
// list of all toc files
protected Collection contributedTocFiles;
@@ -39,8 +41,7 @@ public class TocBuilder {
for (Iterator it = contributedTocFiles.iterator(); it.hasNext();) {
TocFile tocFile = (TocFile) it.next();
Toc toc = tocFile.getToc();
- if (toc != null && toc.getTocFile().isPrimary()
- && !isIntegrated(toc))
+ if (toc != null && toc.getTocFile().isPrimary() && !isIntegrated(toc))
tocCol.add((toc));
}
return tocCol;
@@ -129,8 +130,7 @@ public class TocBuilder {
TocFile tocFile = null;
for (Iterator it = contributedTocFiles.iterator(); it.hasNext();) {
tocFile = (TocFile) it.next();
- if (tocFile.getPluginID().equals(plugin)
- && tocFile.getHref().equals(path))
+ if (tocFile.getPluginID().equals(plugin) && tocFile.getHref().equals(path))
break;
tocFile = null;
}
@@ -148,8 +148,7 @@ public class TocBuilder {
// check if there if there is TOC in ancestor hierarchy (depth first)
for (Iterator it = element.getParents().iterator(); it.hasNext();) {
TocNode parent = (TocNode) it.next();
- if (parent instanceof Toc
- && ((Toc) parent).getTocFile().isPrimary()) {
+ if (parent instanceof Toc && ((Toc) parent).getTocFile().isPrimary()) {
return true;
} else if (isIntegrated(parent)) {
return true;
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/DOMUtil.java b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/DOMUtil.java
index bde650ec9..69f6db777 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/DOMUtil.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/DOMUtil.java
@@ -66,8 +66,6 @@ public class DOMUtil {
}
-
- // <link rel="stylesheet" href="shared.css" type="text/css" />
public static void insertStyle(Document dom, String cssUrl) {
// there should only be one head and one base element dom.
NodeList headList = dom.getElementsByTagName(TAG_HEAD);
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentFilterProcessor.java b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentFilterProcessor.java
index 0efa772d3..809b7c535 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentFilterProcessor.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentFilterProcessor.java
@@ -16,8 +16,7 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
- * Handles content manipulation. Filters filter content in as opposed to filtering out. ie: if a
- * filter passes, content is displayed.
+ * Handles content manipulation. Filters filter content in as opposed to filtering out.
*
*/
public class UAContentFilterProcessor {
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentParser.java b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentParser.java
index 26bef5426..d86e0b48e 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentParser.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentParser.java
@@ -77,16 +77,12 @@ public class UAContentParser {
try {
document = doParse(content);
if (document != null) {
- // xml file is loaded. check that it is XHTML
+
Element rootElement = document.getDocumentElement();
// DocumentType docType = document.getDoctype();
if (rootElement.getTagName().equals(TAG_HTML)) {
- // rely on root element to detect if we have an XHTML file
- // and not on doctype. We need to support xhtml files with
- // no doctype.
hasXHTMLContent = true;
} else
- // not XHTML.
document = null;
}
} catch (Exception e) {
@@ -99,7 +95,6 @@ public class UAContentParser {
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setValidating(false);
- // if this is not set, Document.getElementsByTagNameNS() will fail.
docFactory.setNamespaceAware(true);
docFactory.setExpandEntityReferences(false);
DocumentBuilder parser = docFactory.newDocumentBuilder();
@@ -112,8 +107,6 @@ public class UAContentParser {
if (systemId.equals(XHTML1_TRANSITIONAL) || systemId.equals(XHTML1_STRICT)
|| systemId.equals(XHTML1_FRAMESET)) {
- // be carefull here to support running as a jarred
- // plugin.
URL dtdURL = (URL) dtdMap.get(systemId);
InputSource in = new InputSource(dtdURL.openStream());
in.setSystemId(dtdURL.toExternalForm());
@@ -124,7 +117,6 @@ public class UAContentParser {
});
return parser;
} catch (ParserConfigurationException pce) {
- // Parser with specified options can't be built
HelpPlugin.logError(pce.getMessage(), pce);
}
return null;
@@ -156,7 +148,6 @@ public class UAContentParser {
buffer.append("\n"); //$NON-NLS-1$
buffer.append(spe.getMessage());
- // Use the contained exception.
Exception x = spe;
if (spe.getException() != null)
x = spe.getException();
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLContentProducer.java b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLContentProducer.java
new file mode 100644
index 000000000..e534437cc
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLContentProducer.java
@@ -0,0 +1,67 @@
+/***************************************************************************************************
+ * Copyright (c) 2004, 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.xhtml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Locale;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.help.IHelpContentProducer;
+import org.eclipse.help.internal.util.ResourceLocator;
+import org.osgi.framework.Bundle;
+import org.w3c.dom.Document;
+
+
+public class XHTMLContentProducer implements IHelpContentProducer {
+
+ public InputStream getInputStream(String pluginID, String href, Locale locale) {
+ if (!href.endsWith("xhtml"))
+ return null;
+ return openXHTMLFromPlugin(pluginID, href, locale.toString());
+ }
+
+ /**
+ * Opens an input stream to an xhtml file contained in a plugin. This includes includes OS, WS
+ * and NL lookup.
+ *
+ * @param pluginDesc
+ * the plugin description of the plugin that contains the file you are trying to find
+ * @param file
+ * the relative path of the file to find
+ * @param locale
+ * the locale used as an override or <code>null</code> to use the default locale
+ *
+ * @return an InputStream to the file or <code>null</code> if the file wasn't found
+ */
+ private InputStream openXHTMLFromPlugin(String pluginID, String file, String locale) {
+ ArrayList pathPrefix = ResourceLocator.getPathPrefix(locale);
+
+ Bundle pluginDesc = Platform.getBundle(pluginID);
+
+ URL flatFileURL = ResourceLocator.find(pluginDesc, new Path(file), pathPrefix);
+ if (flatFileURL != null)
+ try {
+ InputStream inputStream = flatFileURL.openStream();
+ UAContentParser parser = new UAContentParser(inputStream);
+ Document dom = parser.getDocument();
+ dom = XHTMLSupport.processDOM(dom, locale);
+ return UATransformManager.getAsInputStream(dom);
+ } catch (IOException e) {
+ return null;
+ }
+ return null;
+ }
+
+
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLSupport.java b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLSupport.java
new file mode 100644
index 000000000..96cef6441
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLSupport.java
@@ -0,0 +1,44 @@
+/***************************************************************************************************
+ * Copyright (c) 2004, 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.xhtml;
+
+import org.w3c.dom.Document;
+
+
+/**
+ * Central class for XHTML support in help.
+ */
+public class XHTMLSupport {
+
+ // singleton for performance.
+ private static UAContentFilterProcessor filterProcessor = new UAContentFilterProcessor();
+ // singleton for performance.
+ private static UAContentMergeProcessor mergeProcessor = new UAContentMergeProcessor();
+
+ public static Document processDOM(Document document, String locale) {
+
+ // resolve filters.
+ filterProcessor.applyFilters(document);
+
+ // resolve includes.
+ mergeProcessor.resolveIncludes(document, locale);
+
+ return document;
+ }
+
+
+ /**
+ * Used by the UI plugin to override base functionality and add more filtering capabilities.
+ */
+ public static void setFilterProcessor(UAContentFilterProcessor filterProcessor) {
+ XHTMLSupport.filterProcessor = filterProcessor;
+ }
+
+}

Back to the top