diff options
31 files changed, 736 insertions, 74 deletions
diff --git a/org.eclipse.help.base/plugin.xml b/org.eclipse.help.base/plugin.xml index 637239499..7f4752f99 100644 --- a/org.eclipse.help.base/plugin.xml +++ b/org.eclipse.help.base/plugin.xml @@ -163,7 +163,7 @@ <extension point="org.eclipse.help.base.luceneSearchParticipants"> <searchParticipant - extensions="xhtml" + content-type="org.eclipse.help.xhtml" id="org.eclipse.help.base.xhtml" participant="org.eclipse.help.internal.search.XHTMLSearchParticipant" headless="true"/> diff --git a/org.eclipse.help.base/schema/luceneSearchParticipants.exsd b/org.eclipse.help.base/schema/luceneSearchParticipants.exsd index a3393100a..36032cdf3 100644 --- a/org.eclipse.help.base/schema/luceneSearchParticipants.exsd +++ b/org.eclipse.help.base/schema/luceneSearchParticipants.exsd @@ -104,7 +104,20 @@ Search participants are associated with the plug-in the extension appears in. In <attribute name="extensions" type="string"> <annotation> <documentation> - an optional field containing the list of file types handled by the search participant. This is a string containing comma separate file extensions (e.g. "abc, xyz"). This attribute should be used when files are made explicitly known to the help system in the <code>org.eclipse.help.toc</code> extension point. The absence of this attribute is an indication that the participant will index all the documents it is responsible for by itself. + Note: This attribute is deprecated; use the content-types attribute instead. +<p> +an optional field containing the list of file types handled by the search participant. This is a string containing comma separate file extensions (e.g. "abc, xyz"). This attribute should be used when files are made explicitly known to the help system in the <code>org.eclipse.help.toc</code> extension point. The absence of this attribute is an indication that the participant will index all the documents it is responsible for by itself. +<p>Note also that participants that are registered for known documents have plug-in scope. If you want a participant to apply to documents in another plug-in, you must use the <code>binding</code> element to extend the scope. In contrast, participants that do not specify this attribute have global scope. + </documentation> + <appInfo> + <meta.attribute deprecated="true"/> + </appInfo> + </annotation> + </attribute> + <attribute name="content-type" type="string"> + <annotation> + <documentation> + an optional field containing the list of content types handled by the search participant. This is a string containing a comma-separated list of content type identifiers (e.g. "html, xhtml"). This attribute should be used when files are made explicitly known to the help system in the <code>org.eclipse.help.toc</code> extension point. The absence of this attribute and the extensions (deprecated) attribute is an indication that the participant will index all the documents it is responsible for by itself. <p>Note also that participants that are registered for known documents have plug-in scope. If you want a participant to apply to documents in another plug-in, you must use the <code>binding</code> element to extend the scope. In contrast, participants that do not specify this attribute have global scope. </documentation> </annotation> diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java index 1199250a2..aac11fe16 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java @@ -197,7 +197,7 @@ public class SearchIndex implements ISearchIndex { participant = BaseHelpSystem.getSearchManager().getGlobalParticipant(pid); // NEW: check for file extension-based search participant; if (participant == null) - participant = BaseHelpSystem.getSearchManager().getParticipant(pluginId, name); + participant = BaseHelpSystem.getSearchManager().getParticipant(pluginId, name, url); if (participant != null) { IStatus status = participant.addDocument(this, pluginId, name, url, id, doc); if (status.getSeverity() == IStatus.OK) { @@ -1029,7 +1029,7 @@ public class SearchIndex implements ISearchIndex { public IStatus addDocument(String pluginId, String name, URL url, String id, Document doc) { // try a registered participant for the file format LuceneSearchParticipant participant = BaseHelpSystem.getSearchManager() - .getParticipant(pluginId, name); + .getParticipant(pluginId, name, url); if (participant != null) { return participant.addDocument(this, pluginId, name, url, id, doc); } diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchManager.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchManager.java index 6911039c5..e63f0b63d 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchManager.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchManager.java @@ -32,6 +32,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.help.HelpSystem; import org.eclipse.help.IHelpResource; import org.eclipse.help.internal.HelpPlugin; @@ -84,7 +85,31 @@ public class SearchManager implements ITocsChangedListener { return element.getAttribute("id"); //$NON-NLS-1$ } - public boolean matches(String extension) { + public boolean matchesContentType(String fileName) { + return matchesContentType(fileName, null); + } + + public boolean matchesContentType(String fileName, URL url) { + String contentType = element.getAttribute("content-type"); //$NON-NLS-1$ + IContentType type = null; + if (url == null) { + type = Platform.getContentTypeManager().findContentTypeFor(fileName); + } + else { + try { + type = Platform.getContentTypeManager().findContentTypeFor(url.openStream(), fileName); + } + catch (IOException e) { + return false; + } + } + if (type != null) { + return type.getId().equals(contentType); + } + return false; + } + + public boolean matchesExtension(String extension) { String ext = element.getAttribute("extensions"); //$NON-NLS-1$ if (ext == null) return false; @@ -97,6 +122,10 @@ public class SearchManager implements ITocsChangedListener { return false; } + public boolean hasContentType() { + return element.getAttribute("content-type") != null; //$NON-NLS-1$ + } + public boolean hasExtensions() { return element.getAttribute("extensions") != null; //$NON-NLS-1$ } @@ -271,10 +300,20 @@ public class SearchManager implements ITocsChangedListener { return false; int dotLoc = url.lastIndexOf('.'); String ext = url.substring(dotLoc + 1); + String fileName = url.substring(url.lastIndexOf('/') + 1); for (int i = 0; i < list.size(); i++) { ParticipantDescriptor desc = (ParticipantDescriptor) list.get(i); - if (desc.matches(ext)) - return true; + if (desc.hasContentType()) { + if (desc.matchesContentType(fileName)) { + return true; + } + } + // extensions attribute deprecated + else if (desc.hasExtensions()) { + if (desc.matchesExtension(ext)) { + return true; + } + } } return false; } @@ -343,20 +382,37 @@ public class SearchManager implements ITocsChangedListener { * Returns a TOC file participant for the provided plug-in and file name. * * @param pluginId - * @param fileName + * @param path * @return */ - public LuceneSearchParticipant getParticipant(String pluginId, String fileName) { + public LuceneSearchParticipant getParticipant(String pluginId, String path, URL url) { ArrayList list = getParticipantDescriptors(pluginId); if (list == null) return null; - int dotLoc = fileName.lastIndexOf('.'); - String ext = fileName.substring(dotLoc + 1); + int dotLoc = path.lastIndexOf('.'); + int lastSlash = path.lastIndexOf('/'); + String ext = path.substring(dotLoc + 1); + String fileName; + if (lastSlash == -1) { + fileName = path; + } + else { + fileName = path.substring(lastSlash + 1); + } for (int i = 0; i < list.size(); i++) { ParticipantDescriptor desc = (ParticipantDescriptor) list.get(i); - if (desc.matches(ext)) - return desc.getParticipant(); + if (desc.hasContentType()) { + if (desc.matchesContentType(fileName, url)) { + return desc.getParticipant(); + } + } + // extensions attribute deprecated + else if (desc.hasExtensions()) { + if (desc.matchesExtension(ext)) { + return desc.getParticipant(); + } + } } return null; } @@ -434,7 +490,7 @@ public class SearchManager implements ITocsChangedListener { if (!rel.getName().equals("searchParticipant")) //$NON-NLS-1$ continue; // don't allow binding the global participants - if (rel.getAttribute("extensions") == null) //$NON-NLS-1$ + if (rel.getAttribute("content-type") == null && rel.getAttribute("extensions") == null) //$NON-NLS-1$ //$NON-NLS-2$ continue; String id = rel.getAttribute("id"); //$NON-NLS-1$ if (id != null && id.equals(refId)) { diff --git a/org.eclipse.help/plugin.properties b/org.eclipse.help/plugin.properties index 099400c46..22b0e4125 100644 --- a/org.eclipse.help/plugin.properties +++ b/org.eclipse.help/plugin.properties @@ -15,3 +15,5 @@ contexts_extension_point_name = Context Help content_producer_extension_point_name = Help Content Producer index_extension_point_name = Help Index Contributions content_extension_point_name = Help Content Extensions +content_type_html = HTML File +content_type_xhtml = XHTML File diff --git a/org.eclipse.help/plugin.xml b/org.eclipse.help/plugin.xml index a34431554..0cdf96489 100644 --- a/org.eclipse.help/plugin.xml +++ b/org.eclipse.help/plugin.xml @@ -13,5 +13,24 @@ point="org.eclipse.help.contentProducer"> <contentProducer producer="org.eclipse.help.internal.DynamicContentProducer"/> </extension> + + <extension + point="org.eclipse.core.runtime.contentTypes"> + <content-type + base-type="org.eclipse.core.runtime.text" + file-extensions="htm,html" + id="html" + name="%content_type_html" + priority="high"> + </content-type> + <content-type + base-type="org.eclipse.core.runtime.xml" + describer="org.eclipse.help.internal.xhtml.XHTMLContentDescriber" + file-extensions="htm,html,xhtml" + id="xhtml" + name="%content_type_xhtml" + priority="high"> + </content-type> + </extension> </plugin> diff --git a/org.eclipse.help/src/org/eclipse/help/internal/DynamicContentProducer.java b/org.eclipse.help/src/org/eclipse/help/internal/DynamicContentProducer.java index 85acc5d1f..d3210f57b 100644 --- a/org.eclipse.help/src/org/eclipse/help/internal/DynamicContentProducer.java +++ b/org.eclipse.help/src/org/eclipse/help/internal/DynamicContentProducer.java @@ -14,6 +14,7 @@ import java.io.InputStream; import java.util.Locale; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.help.IHelpContentProducer; import org.eclipse.help.internal.util.ResourceLocator; import org.eclipse.help.internal.xhtml.UAContentParser; @@ -32,29 +33,74 @@ public class DynamicContentProducer implements IHelpContentProducer { public InputStream getInputStream(String pluginID, String href, Locale locale) { String file = href; int qloc = href.indexOf('?'); - if (qloc != -1) + if (qloc != -1) { file = href.substring(0, qloc); - int loc = file.lastIndexOf('.'); - if (loc != -1) { - String extension = file.substring(loc + 1).toLowerCase(); - if ("xhtml".equals(extension)) {//$NON-NLS-1$ - /* - * Filtering can be turned off when, for example, - * indexing documents. - */ - boolean filter = true; - if (qloc != -1 && qloc < href.length() - 1) { - String query = href.substring(qloc + 1); - filter = (query.indexOf("filter=false") == -1); //$NON-NLS-1$ - } - return openXHTMLFromPlugin(pluginID, file, locale.toString(), filter); + } + if (isXHTML(pluginID, href, locale)) { + /* + * Filtering can be turned off when, for example, + * indexing documents. + */ + boolean filter = true; + if (qloc != -1 && qloc < href.length() - 1) { + String query = href.substring(qloc + 1); + filter = (query.indexOf("filter=false") == -1); //$NON-NLS-1$ } - // place support for other formats here + return openXHTMLFromPlugin(pluginID, file, locale.toString(), filter); } return null; } /** + * Returns whether or not the given href is pointing to an XHTML + * document (it can be within a .html file). + * + * @param pluginID the id of the plugin containing the document + * @param href the href to the document + * @param locale the document's locale + * @return whether or not the document is XHTML + */ + private static boolean isXHTML(String pluginID, String href, Locale locale) { + String file = href; + int qloc = href.indexOf('?'); + if (qloc != -1) { + file = href.substring(0, qloc); + } + int lastSlash = file.lastIndexOf('/'); + String fileName; + if (lastSlash != -1) { + fileName = file.substring(lastSlash + 1); + } + else { + fileName = file; + } + // first open it to peek inside to see whether it's really XHTML + InputStream contents = openXHTMLFromPluginRaw(pluginID, file, locale.toString()); + IContentType type = null; + try { + type = Platform.getContentTypeManager().findContentTypeFor(contents, fileName); + } + catch (IOException e) { + HelpPlugin.logError("An error occured in DynamicContentProducer while trying to determine the content type", e); //$NON-NLS-1$ + } + finally { + if (contents != null) { + try { + contents.close(); + } + catch (IOException e) { + // nothing we can do + } + } + } + // if it has the right content type it's XHTML + if (type != null) { + return "org.eclipse.help.xhtml".equals(type.getId()); //$NON-NLS-1$ + } + return false; + } + + /** * Opens an input stream to an xhtml file contained in a plugin or in a doc.zip * in the plugin. This includes includes OS, WS and NL lookup. * @@ -69,7 +115,27 @@ public class DynamicContentProducer implements IHelpContentProducer { * * @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, boolean filter) { + private static InputStream openXHTMLFromPlugin(String pluginID, String file, String locale, boolean filter) { + InputStream inputStream = openXHTMLFromPluginRaw(pluginID, file, locale); + if (inputStream != null) { + UAContentParser parser = new UAContentParser(inputStream); + Document dom = parser.getDocument(); + XHTMLSupport support = new XHTMLSupport(pluginID, file, dom, locale); + dom = support.processDOM(filter); + try { + inputStream.close(); + } catch (IOException e) { + } + return UATransformManager.getAsInputStream(dom); + } + return null; + } + + /** + * Same as openXHTMLFromPlugin() but does not do any processing of the document + * (it is opened raw). + */ + private static InputStream openXHTMLFromPluginRaw(String pluginID, String file, String locale) { Bundle bundle = Platform.getBundle(pluginID); if (bundle != null) { // look in the doc.zip and in the plugin to find the xhtml file. @@ -78,17 +144,7 @@ public class DynamicContentProducer implements IHelpContentProducer { if (inputStream == null) { inputStream = ResourceLocator.openFromPlugin(bundle, file, locale); } - if (inputStream != null) { - UAContentParser parser = new UAContentParser(inputStream); - Document dom = parser.getDocument(); - XHTMLSupport support = new XHTMLSupport(pluginID, file, dom, locale); - dom = support.processDOM(filter); - try { - inputStream.close(); - } catch (IOException e) { - } - return UATransformManager.getAsInputStream(dom); - } + return inputStream; } return null; } diff --git a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLContentDescriber.java b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLContentDescriber.java new file mode 100644 index 000000000..b8d16197f --- /dev/null +++ b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/XHTMLContentDescriber.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * 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.xhtml; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Hashtable; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.QualifiedName; +import org.eclipse.core.runtime.content.IContentDescriber; +import org.eclipse.core.runtime.content.IContentDescription; +import org.eclipse.core.runtime.content.XMLRootElementContentDescriber; + +/** + * A content describer for XHTML. + */ +public class XHTMLContentDescriber implements IContentDescriber { + + private static final String PROPERTY_DTD = "dtd"; //$NON-NLS-1$ + + // XHTML has 3 DTDs, so we have to try each one. + private static final String DTD_STRICT = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"; //$NON-NLS-1$ + private static final String DTD_TRANSITIONAL = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"; //$NON-NLS-1$ + private static final String DTD_FRAMESET = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"; //$NON-NLS-1$ + + private static final int BUFFER_SIZE = 8192; + + private XMLRootElementContentDescriber describerStrict = new XMLRootElementContentDescriber(); + private XMLRootElementContentDescriber describerTransitional = new XMLRootElementContentDescriber(); + private XMLRootElementContentDescriber describerFrameset = new XMLRootElementContentDescriber(); + + /** + * Constructs a new XHTMLContentDescriber. Initializes the three + * delegates with their respective DTDs. + */ + public XHTMLContentDescriber() { + try { + describerStrict.setInitializationData(null, null, getParameter(PROPERTY_DTD, DTD_STRICT)); + } + catch (CoreException e) { + // not much we can do here + } + + try { + describerTransitional.setInitializationData(null, null, getParameter(PROPERTY_DTD, DTD_TRANSITIONAL)); + } + catch (CoreException e) { + // not much we can do here + } + + try { + describerFrameset.setInitializationData(null, null, getParameter(PROPERTY_DTD, DTD_FRAMESET)); + } + catch (CoreException e) { + // not much we can do here + } + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.content.IContentDescriber#describe(java.io.InputStream, org.eclipse.core.runtime.content.IContentDescription) + */ + public int describe(InputStream contents, IContentDescription description) throws IOException { + /* + * Load the first BUFFER_SIZE bytes, then pass that to each delegate. + * If any one recognizes their DTD, return VALID. + */ + try { + byte[] buffer = new byte[BUFFER_SIZE]; + contents.read(buffer); + contents.close(); + + ByteArrayInputStream in = new ByteArrayInputStream(buffer); + if (describerTransitional.describe(in, description) == VALID) { + return VALID; + } + in = new ByteArrayInputStream(buffer); + if (describerStrict.describe(in, description) == VALID) { + return VALID; + } + in = new ByteArrayInputStream(buffer); + return describerFrameset.describe(in, description); + } + catch (Exception e) { + return INDETERMINATE; + } + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.content.IContentDescriber#getSupportedOptions() + */ + public QualifiedName[] getSupportedOptions() { + return new QualifiedName[0]; + } + + /** + * Creates a new parameter suitable for passing into the + * XMLRootElementContentDescriber. The parameters have to be + * in the form of a Hashtable. + * + * @param name parameter name + * @param value parameter value + * @return the parameter, in Hashtable form + */ + private static Hashtable getParameter(String name, String value) { + Hashtable hash = new Hashtable(); + hash.put(name, value); + return hash; + } +} diff --git a/org.eclipse.ua.tests/data/help/producer/dynamic2.html b/org.eclipse.ua.tests/data/help/producer/dynamic2.html new file mode 100644 index 000000000..56d16f0f8 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/producer/dynamic2.html @@ -0,0 +1,45 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + Test to make sure the dynamic content producer applies to XHTML inside + a file with extension .html +--> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>dynamic2.html</title> +</head> +<body> + +<h2>dynamic2.html</h2> +<p> +This page contains filtered content. +</p> +<p filter="os=invalid"> +This paragraph, which has filter attribute "os=invalid" should always be filtered out. +</p> +<p filter="os!=invalid"> +This paragraph, which has filter attribute "os!=invalid" should never be filtered out. +</p> +<p filter="plugin=my.invalid.plugin.id.012345"> +This paragraph, which has filter attribute "plugin=my.invalid.plugin.id.012345" should always be filtered out. +</p> +<p filter="plugin!=my.invalid.plugin.id.012345"> +This paragraph, which has filter attribute "plugin!=my.invalid.plugin.id.012345" should never be filtered out. +</p> +<p> + <filter name="plugin" value="my.invalid.plugin.id.012345"/> + This paragraph, which has filter element name="plugin", value="my.invalid.plugin.id.012345", + should always be filtered out. +</p> +<p> + <filter name="plugin" value="!my.invalid.plugin.id.012345"/> + This paragraph, which has filter element name="plugin", value="!my.invalid.plugin.id.012345", + should never be filtered out. +</p> + +<include path="org.eclipse.ua.tests/data/help/producer/include2.html/my.paragraph.id"/> + +</body> +</html> diff --git a/org.eclipse.ua.tests/data/help/producer/dynamic2_expected.txt b/org.eclipse.ua.tests/data/help/producer/dynamic2_expected.txt new file mode 100644 index 000000000..3a390f500 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/producer/dynamic2_expected.txt @@ -0,0 +1,36 @@ +<!-- + Test to make sure the dynamic content producer applies to XHTML inside + a file with extension .html +--><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> + +<title>dynamic2.html</title> +</head> +<body> + +<h2>dynamic2.html</h2> +<p> +This page contains filtered content. +</p> + +<p filter="os!=invalid"> +This paragraph, which has filter attribute "os!=invalid" should never be filtered out. +</p> + +<p filter="plugin!=my.invalid.plugin.id.012345"> +This paragraph, which has filter attribute "plugin!=my.invalid.plugin.id.012345" should never be filtered out. +</p> + +<p> + <filter name="plugin" value="!my.invalid.plugin.id.012345" /> + This paragraph, which has filter element name="plugin", value="!my.invalid.plugin.id.012345", + should never be filtered out. +</p> + +<p id="my.paragraph.id"> + This paragraph comes from <code>include2.html</code>. +</p> + +</body> +</html>
\ No newline at end of file diff --git a/org.eclipse.ua.tests/data/help/producer/include2.html b/org.eclipse.ua.tests/data/help/producer/include2.html new file mode 100644 index 000000000..11dcc7c7e --- /dev/null +++ b/org.eclipse.ua.tests/data/help/producer/include2.html @@ -0,0 +1,20 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + Test to ensure that include works when including XHTML from a file with + .html extension. +--> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>include2.html</title> +</head> +<body> + +<p id="my.paragraph.id"> + This paragraph comes from <code>include2.html</code>. +</p> + +</body> +</html> diff --git a/org.eclipse.ua.tests/data/help/producer/toc.xml b/org.eclipse.ua.tests/data/help/producer/toc.xml index 86a5e0d2b..7d6ce30b3 100644 --- a/org.eclipse.ua.tests/data/help/producer/toc.xml +++ b/org.eclipse.ua.tests/data/help/producer/toc.xml @@ -8,6 +8,7 @@ <toc label="toc.xml"> <topic label="dynamic.xhtml" href="data/help/producer/dynamic.xhtml"/> + <topic label="dynamic2.html" href="data/help/producer/dynamic2.html"/> <!-- This file is in doc.zip in the root of the test plugin --> <topic label="dynamicInZip.xhtml" href="data/help/producer/dynamicInZip.xhtml"/> diff --git a/org.eclipse.ua.tests/data/help/producer/xhtml/invalid/html_doctype.html b/org.eclipse.ua.tests/data/help/producer/xhtml/invalid/html_doctype.html new file mode 100644 index 000000000..2a8198863 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/producer/xhtml/invalid/html_doctype.html @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> + +<!-- + This file is used to test whether or not the dynamic producer will be used + when loading an xhtml document from outside a doc.zip. The paragraph at the + bottom should always be filtered out by the producer. +--> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>test</title> +</head> +<body> + +<h1>test</h1> +<p> +Test +</p> + +</body> +</html> diff --git a/org.eclipse.ua.tests/data/help/producer/xhtml/invalid/missing_doctype.html b/org.eclipse.ua.tests/data/help/producer/xhtml/invalid/missing_doctype.html new file mode 100644 index 000000000..b639180b1 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/producer/xhtml/invalid/missing_doctype.html @@ -0,0 +1,14 @@ +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>test</title> +</head> +<body> + +<h1>test</h1> +<p> +Test +</p> + +</body> +</html> diff --git a/org.eclipse.ua.tests/data/help/producer/xhtml/valid/frameset.html b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/frameset.html new file mode 100644 index 000000000..b30156e06 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/frameset.html @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> + +<!-- + This file is used to test whether or not the dynamic producer will be used + when loading an xhtml document from outside a doc.zip. The paragraph at the + bottom should always be filtered out by the producer. +--> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>test</title> +</head> +<body> + +<h1>test</h1> +<p> +Test +</p> + +</body> +</html> diff --git a/org.eclipse.ua.tests/data/help/producer/xhtml/valid/frameset.xhtml b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/frameset.xhtml new file mode 100644 index 000000000..b30156e06 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/frameset.xhtml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> + +<!-- + This file is used to test whether or not the dynamic producer will be used + when loading an xhtml document from outside a doc.zip. The paragraph at the + bottom should always be filtered out by the producer. +--> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>test</title> +</head> +<body> + +<h1>test</h1> +<p> +Test +</p> + +</body> +</html> diff --git a/org.eclipse.ua.tests/data/help/producer/xhtml/valid/normal.html b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/normal.html new file mode 100644 index 000000000..44165bdc7 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/normal.html @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + This file is used to test whether or not the dynamic producer will be used + when loading an xhtml document from outside a doc.zip. The paragraph at the + bottom should always be filtered out by the producer. +--> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>test</title> +</head> +<body> + +<h1>test</h1> +<p> +Test +</p> + +</body> +</html> diff --git a/org.eclipse.ua.tests/data/help/producer/xhtml/valid/normal.xhtml b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/normal.xhtml new file mode 100644 index 000000000..44165bdc7 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/normal.xhtml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + This file is used to test whether or not the dynamic producer will be used + when loading an xhtml document from outside a doc.zip. The paragraph at the + bottom should always be filtered out by the producer. +--> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>test</title> +</head> +<body> + +<h1>test</h1> +<p> +Test +</p> + +</body> +</html> diff --git a/org.eclipse.ua.tests/data/help/producer/xhtml/valid/strict.html b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/strict.html new file mode 100644 index 000000000..443c3dae5 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/strict.html @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> + +<!-- + This file is used to test whether or not the dynamic producer will be used + when loading an xhtml document from outside a doc.zip. The paragraph at the + bottom should always be filtered out by the producer. +--> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>test</title> +</head> +<body> + +<h1>test</h1> +<p> +Test +</p> + +</body> +</html> diff --git a/org.eclipse.ua.tests/data/help/producer/xhtml/valid/strict.xhtml b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/strict.xhtml new file mode 100644 index 000000000..443c3dae5 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/strict.xhtml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> + +<!-- + This file is used to test whether or not the dynamic producer will be used + when loading an xhtml document from outside a doc.zip. The paragraph at the + bottom should always be filtered out by the producer. +--> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>test</title> +</head> +<body> + +<h1>test</h1> +<p> +Test +</p> + +</body> +</html> diff --git a/org.eclipse.ua.tests/data/help/producer/xhtml/valid/with_xml_decl.xhtml b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/with_xml_decl.xhtml new file mode 100644 index 000000000..44460c399 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/producer/xhtml/valid/with_xml_decl.xhtml @@ -0,0 +1,22 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<!-- + This file is used to test whether or not the dynamic producer will be used + when loading an xhtml document from outside a doc.zip. The paragraph at the + bottom should always be filtered out by the producer. +--> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>test</title> +</head> +<body> + +<h1>test</h1> +<p> +Test +</p> + +</body> +</html> diff --git a/org.eclipse.ua.tests/data/help/search/test7.html b/org.eclipse.ua.tests/data/help/search/test7.html new file mode 100644 index 000000000..b634fb857 --- /dev/null +++ b/org.eclipse.ua.tests/data/help/search/test7.html @@ -0,0 +1,26 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title>test7.html</title> +</head> + +<body> +<p> +This tests whether or not the right search participant will be used for XHTML +content inside a file with extension .html +kejehrgaqm +</p> + +<p filter="os=invalid"> +This paragraph is always filtered out, and is used to ensure that searching does not +flag this document as a hit. Here is a unique word to search for: hugftnhdtg +</p> +<p filter="plugin!=my.invalid.plugin.id.012345"> +This paragraph, which has filter attribute "plugin!=my.invalid.plugin.id.012345" should never be filtered out. +opqmenhfjs +</p> + +</body> +</html> diff --git a/org.eclipse.ua.tests/data/help/search/toc.xml b/org.eclipse.ua.tests/data/help/search/toc.xml index 5e7591950..9faff31af 100644 --- a/org.eclipse.ua.tests/data/help/search/toc.xml +++ b/org.eclipse.ua.tests/data/help/search/toc.xml @@ -8,4 +8,5 @@ <topic label="test4.xhtml" href="data/help/search/test4.xhtml"/> <topic label="test5.xhtml" href="data/help/search/test5.xhtml"/> <topic label="test6.xhtml" href="data/help/search/test6.xhtml"/> + <topic label="test7.html" href="data/help/search/test7.html"/> </toc> diff --git a/org.eclipse.ua.tests/data/help/toc/extraContent/simple_page.html b/org.eclipse.ua.tests/data/help/toc/extraContent/simple_page.html index 5918e900f..290db6534 100644 --- a/org.eclipse.ua.tests/data/help/toc/extraContent/simple_page.html +++ b/org.eclipse.ua.tests/data/help/toc/extraContent/simple_page.html @@ -1,4 +1,5 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><HTML> +<!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"> diff --git a/org.eclipse.ua.tests/data/help/toc/extraContent/toc2.xml b/org.eclipse.ua.tests/data/help/toc/extraContent/toc2.xml index a97999eb7..8e9f82afa 100644 --- a/org.eclipse.ua.tests/data/help/toc/extraContent/toc2.xml +++ b/org.eclipse.ua.tests/data/help/toc/extraContent/toc2.xml @@ -1,35 +1,35 @@ <?xml version="1.0" encoding="utf-8"?> <?NLS TYPE="org.eclipse.help.toc"?> <toc label="Samples" topic="samples.htm"> - <topic label="Bats FOR product: Happy Bats, WAS; version: 9.0,8.0 ; platform: z/OS;AIX" href="bats.htm"> + <topic label="Bats FOR product: Happy Bats, WAS; version: 9.0,8.0 ; platform: z/OS;AIX" href="simple_page.html"> <criteria name="prodname" value="Happy Bats" /> <criteria name="prodname" value="WAS" /> <criteria name="version" value="9.0" /> <criteria name="version" value="8.0" /> <criteria name="platform" value="z/OS" /> <criteria name="platform" value="AIX" /> - <topic label="Caring for your fruit bat FOR Version: 9.0; platform: z/OS; product: WAS" href="batcaring.htm"> + <topic label="Caring for your fruit bat FOR Version: 9.0; platform: z/OS; product: WAS" href="simple_page.html"> <criteria name="version" value="9.0" /> <criteria name="platform" value="z/OS" /> <criteria name="prodname" value="WAS" /> </topic> - <topic label="Cleaning your fruit bat FOR Version: 8.0; platform: AIX; product: Happy Bats" href="batcleaning.htm"> + <topic label="Cleaning your fruit bat FOR Version: 8.0; platform: AIX; product: Happy Bats" href="simple_page.html"> <criteria name="platform" value="AIX" /> <criteria name="version" value="8.0" /> <criteria name="prodname" value="Happy Bats" /> </topic> - <topic label="Feeding your bat" href="batfeeding.htm"/> - <topic label="Bat sonar" href="batsonar.htm"/> - <topic label="Bat guano" href="batguano.htm"/> - <topic label="Bat history" href="bathistory.htm"/> - <topic label="Bat recycling" href="batreuse.htm"/> + <topic label="Feeding your bat" href="simple_page.html"/> + <topic label="Bat sonar" href="simple_page.html"/> + <topic label="Bat guano" href="simple_page.html"/> + <topic label="Bat history" href="simple_page.html"/> + <topic label="Bat recycling" href="simple_page.html"/> </topic> - <topic label="Bats FOR product: Happy Bats" href="bats.htm#none"> + <topic label="Bats FOR product: Happy Bats" href="simple_page.html"> <criteria name="prodname" value="Happy Bats" /> - <topic label="Feeding your bat" href="batfeeding.htm"/> - <topic label="Bat sonar" href="batsonar.htm"/> - <topic label="Bat guano" href="batguano.htm"/> - <topic label="Bat history" href="bathistory.htm"/> - <topic label="Bat recycling" href="batreuse.htm"/> + <topic label="Feeding your bat" href="simple_page.html"/> + <topic label="Bat sonar" href="simple_page.html"/> + <topic label="Bat guano" href="simple_page.html"/> + <topic label="Bat history" href="simple_page.html"/> + <topic label="Bat recycling" href="simple_page.html"/> </topic> </toc>
\ No newline at end of file diff --git a/org.eclipse.ua.tests/data/help/toc/extraContent/toc2_expected.txt b/org.eclipse.ua.tests/data/help/toc/extraContent/toc2_expected.txt index e7b25dca4..fe477d653 100644 --- a/org.eclipse.ua.tests/data/help/toc/extraContent/toc2_expected.txt +++ b/org.eclipse.ua.tests/data/help/toc/extraContent/toc2_expected.txt @@ -4,58 +4,58 @@ href="/org.eclipse.ua.tests/data/help/toc/extraContent/toc2.xml"> <topic label="Bats FOR product: Happy Bats, WAS; version: 9.0,8.0 ; platform: z/OS;AIX" - href="/org.eclipse.ua.tests/bats.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> <topic label="Caring for your fruit bat FOR Version: 9.0; platform: z/OS; product: WAS" - href="/org.eclipse.ua.tests/batcaring.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> </topic> <topic label="Cleaning your fruit bat FOR Version: 8.0; platform: AIX; product: Happy Bats" - href="/org.eclipse.ua.tests/batcleaning.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> </topic> <topic label="Feeding your bat" - href="/org.eclipse.ua.tests/batfeeding.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> </topic> <topic label="Bat sonar" - href="/org.eclipse.ua.tests/batsonar.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> </topic> <topic label="Bat guano" - href="/org.eclipse.ua.tests/batguano.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> </topic> <topic label="Bat history" - href="/org.eclipse.ua.tests/bathistory.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> </topic> <topic label="Bat recycling" - href="/org.eclipse.ua.tests/batreuse.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> </topic> </topic> <topic label="Bats FOR product: Happy Bats" - href="/org.eclipse.ua.tests/bats.htm#none"> + href="/org.eclipse.ua.tests/simple_page.html"> <topic label="Feeding your bat" - href="/org.eclipse.ua.tests/batfeeding.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> </topic> <topic label="Bat sonar" - href="/org.eclipse.ua.tests/batsonar.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> </topic> <topic label="Bat guano" - href="/org.eclipse.ua.tests/batguano.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> </topic> <topic label="Bat history" - href="/org.eclipse.ua.tests/bathistory.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> </topic> <topic label="Bat recycling" - href="/org.eclipse.ua.tests/batreuse.htm"> + href="/org.eclipse.ua.tests/simple_page.html"> </topic> </topic> -</toc> +</toc>
\ No newline at end of file diff --git a/org.eclipse.ua.tests/data/help/toc/extraContent/toc_expected.txt b/org.eclipse.ua.tests/data/help/toc/extraContent/toc_expected.txt index e35bbb632..4c81d6c62 100644 --- a/org.eclipse.ua.tests/data/help/toc/extraContent/toc_expected.txt +++ b/org.eclipse.ua.tests/data/help/toc/extraContent/toc_expected.txt @@ -46,4 +46,4 @@ label="Legal" href="/org.eclipse.ua.tests/data/help/toc/extraContent/simple_page.html"> </topic> -</toc> +</toc>
\ No newline at end of file diff --git a/org.eclipse.ua.tests/data/help/toc/filteredToc/toc_expected.txt b/org.eclipse.ua.tests/data/help/toc/filteredToc/toc_expected.txt index 72cb7236f..45be796f3 100644 --- a/org.eclipse.ua.tests/data/help/toc/filteredToc/toc_expected.txt +++ b/org.eclipse.ua.tests/data/help/toc/filteredToc/toc_expected.txt @@ -66,4 +66,4 @@ href="/org.eclipse.ua.tests/data/help/toc/filteredToc/simple_page.html"> </topic> </topic> -</toc> +</toc>
\ No newline at end of file diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/producer/AllProducerTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/producer/AllProducerTests.java index ed30f03bc..17336eb64 100644 --- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/producer/AllProducerTests.java +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/producer/AllProducerTests.java @@ -30,5 +30,6 @@ public class AllProducerTests extends TestSuite { */ public AllProducerTests() { addTest(DynamicContentTest.suite()); + addTest(XHTMLContentDescriberTest.suite()); } } diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/producer/XHTMLContentDescriberTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/producer/XHTMLContentDescriberTest.java new file mode 100644 index 000000000..78196ea99 --- /dev/null +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/producer/XHTMLContentDescriberTest.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * 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.producer; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +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.core.runtime.content.IContentType; +import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin; +import org.eclipse.ua.tests.util.ResourceFinder; + +public class XHTMLContentDescriberTest extends TestCase { + + /* + * Returns an instance of this Test. + */ + public static Test suite() { + return new TestSuite(XHTMLContentDescriberTest.class); + } + + public void testValidXHTML() throws IOException { + URL[] urls = ResourceFinder.findFiles(UserAssistanceTestPlugin.getDefault(), "data/help/producer/xhtml/valid", "", true); + for (int i=0;i<urls.length;++i) { + InputStream in = urls[i].openStream(); + String url = urls[i].toExternalForm(); + String fileName = url.substring(url.lastIndexOf('/') + 1); + IContentType type = Platform.getContentTypeManager().findContentTypeFor(in, fileName); + Assert.assertEquals("The supplied valid XHTML was mistakenly recognized as invalid XHTML by the type describer: file=" + fileName, "org.eclipse.help.xhtml", type.getId()); + in.close(); + } + } + + public void testInvalidXHTML() throws IOException { + URL[] urls = ResourceFinder.findFiles(UserAssistanceTestPlugin.getDefault(), "data/help/producer/xhtml/invalid", "", true); + for (int i=0;i<urls.length;++i) { + InputStream in = urls[i].openStream(); + String url = urls[i].toExternalForm(); + String fileName = url.substring(url.lastIndexOf('/') + 1); + IContentType type = Platform.getContentTypeManager().findContentTypeFor(in, fileName); + Assert.assertFalse("The supplied invalid XHTML was not properly recognized by the XHTML content type describer: file= " + fileName + " type=" + type.getId(), "org.eclipse.help.xhtml".equals(type.getId())); + in.close(); + } + } +} diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/XHTMLTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/XHTMLTest.java index 32a4bb1b7..2f0c86204 100644 --- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/XHTMLTest.java +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/XHTMLTest.java @@ -71,6 +71,16 @@ public class XHTMLTest extends TestCase { // only exists in paragraph in test6.xhtml that's replaced by another one { "bheufnjefa", /* no hits */ }, + + // sanity test to make sure it finds things in XHTML content in .html file + { "kejehrgaqm", "/org.eclipse.ua.tests/data/help/search/test7.html" }, + + // same as above, but in a section that should never be filtered + { "opqmenhfjs", "/org.eclipse.ua.tests/data/help/search/test7.html" }, + + // only exists in a paragraph in test7.html that should be filtered out + // make sure this works for XHTML content inside .html file + { "hugftnhdtg", /* no hits */ }, }; /* |