Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2010-03-04 19:17:30 +0000
committerChris Goldthorpe2010-03-04 19:17:30 +0000
commit41d99263bfe2302f1de5a3fc2173bb412733366d (patch)
tree3d407cd83c423b17f5b151ecc03a3089a156dd95 /org.eclipse.help
parent819b7a83c5b18420ad2b28774d9bce2889f28ae5 (diff)
downloadeclipse.platform.ua-41d99263bfe2302f1de5a3fc2173bb412733366d.tar.gz
eclipse.platform.ua-41d99263bfe2302f1de5a3fc2173bb412733366d.tar.xz
eclipse.platform.ua-41d99263bfe2302f1de5a3fc2173bb412733366d.zip
Bug 302779 – [Help] Allow criteria to be defined independent of TOC filesv20100304
Diffstat (limited to 'org.eclipse.help')
-rw-r--r--org.eclipse.help/plugin.xml1
-rw-r--r--org.eclipse.help/schema/criteriaProvider.exsd110
-rw-r--r--org.eclipse.help/src/org/eclipse/help/AbstractCriteriaProvider.java41
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaProviderRegistry.java129
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocAssembler.java5
5 files changed, 284 insertions, 2 deletions
diff --git a/org.eclipse.help/plugin.xml b/org.eclipse.help/plugin.xml
index 0bb76a8d9..fbbd017ac 100644
--- a/org.eclipse.help/plugin.xml
+++ b/org.eclipse.help/plugin.xml
@@ -18,6 +18,7 @@
<extension-point id="index" name="%index_extension_point_name" schema="schema/index.exsd"/>
<extension-point id="toc" name="%toc_extension_point_name" schema="schema/toc.exsd"/>
<extension-point id="criteriaDefinition" name="%criteriaDefinition_extension_point_name" schema="schema/criteriaDefinition.exsd"/>
+ <extension-point id="criteriaProvider" name="Help Criteria Provider" schema="schema/criteriaProvider.exsd"/>
<extension
point="org.eclipse.help.contentExtension">
<contentExtensionProvider class="org.eclipse.help.internal.extension.ContentExtensionFileProvider"/>
diff --git a/org.eclipse.help/schema/criteriaProvider.exsd b/org.eclipse.help/schema/criteriaProvider.exsd
new file mode 100644
index 000000000..ad26c4388
--- /dev/null
+++ b/org.eclipse.help/schema/criteriaProvider.exsd
@@ -0,0 +1,110 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.help" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.help" id="criteriaProvider" name="Help Criteria Provider"/>
+ </appInfo>
+ <documentation>
+ Support for defining criteria idependent of the table of contents.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="provider"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="provider">
+ <annotation>
+ <documentation>
+ Defines a criteria provider class
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.eclipse.help.AbstractCriteriaProvider:"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 3.5
+ </documentation>
+ </annotation>
+
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ Uses class AbstractCriteriaProvider to allow for criteria to be defined dynamically. Criteria defined using this extension point will be merged with those defined in the table of contents and if multiple criteria providers are defined each will contribute to the criteria of an ITopic or IToc.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2010 IBM Corporation and others.&lt;br&gt;
+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 &lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/org.eclipse.help/src/org/eclipse/help/AbstractCriteriaProvider.java b/org.eclipse.help/src/org/eclipse/help/AbstractCriteriaProvider.java
new file mode 100644
index 000000000..dff4d23a3
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/AbstractCriteriaProvider.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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;
+
+
+/**
+ * <code>AbstractCriteriaProvider</code> is a mechanism for assigning criteria to
+ * <code>ITopic</code> and <code>IToc</code> elements independent of a table of contents
+ * file. The criteria defined by this class are merged with those from the table of contents
+ * or from other criteria providers by creating a union of defined criteria and
+ * defined criteria values.
+ * @since 3.5
+ */
+public abstract class AbstractCriteriaProvider {
+
+ /**
+ * Gets criteria for a topic
+ * @param topic a topic from a table of contents or index
+ * @return an array of criteria which will be added to those already defined in
+ * the table of contents file
+ */
+ public abstract ICriteria[] getCriteria(ITopic topic);
+
+ /**
+ * Gets criteria for a table of contents
+ * @param toc a table of contents
+ * @return an array of criteria which will be added to those already defined in
+ * the table of contents file
+ */
+ public abstract ICriteria[] getCriteria(IToc toc);
+
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaProviderRegistry.java b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaProviderRegistry.java
new file mode 100644
index 000000000..4f85706f8
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/criteria/CriteriaProviderRegistry.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.criteria;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.help.AbstractCriteriaProvider;
+import org.eclipse.help.ICriteria;
+import org.eclipse.help.IToc;
+import org.eclipse.help.IToc2;
+import org.eclipse.help.ITopic;
+import org.eclipse.help.ITopic2;
+import org.eclipse.help.internal.HelpPlugin;
+
+public class CriteriaProviderRegistry {
+
+ public static final String PROVIDER_XP_NAME = "org.eclipse.help.criteriaProvider"; //$NON-NLS-1$
+
+ private static List providers = null;
+
+ private static CriteriaProviderRegistry instance;
+
+ private boolean initialized = false;
+
+ private CriteriaProviderRegistry() {
+ }
+
+ public static CriteriaProviderRegistry getInstance() {
+ if (instance == null) {
+ instance = new CriteriaProviderRegistry();
+ }
+ return instance;
+ }
+
+ synchronized private void readProviders() {
+ if (initialized ) {
+ return;
+ }
+ providers = new ArrayList();
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] elements = registry
+ .getConfigurationElementsFor(PROVIDER_XP_NAME);
+ for (int i = 0; i < elements.length; i++) {
+
+ Object obj = null;
+ try {
+ obj = elements[i].createExecutableExtension("class"); //$NON-NLS-1$
+ } catch (CoreException e) {
+ HelpPlugin.logError("Create extension failed:[" //$NON-NLS-1$
+ + PROVIDER_XP_NAME + "].", e); //$NON-NLS-1$
+ }
+ if (obj instanceof AbstractCriteriaProvider) {
+ providers.add(obj);
+ }
+ }
+ initialized = true;
+ }
+
+ public AbstractCriteriaProvider[] getScopes() {
+ readProviders();
+ return (AbstractCriteriaProvider[]) providers.toArray(new AbstractCriteriaProvider[providers.size()]);
+ }
+
+ public ICriteria[] getAllCriteria(ITopic topic) {
+ readProviders();
+ ICriteria[] criteria;
+ if (topic instanceof ITopic2) {
+ criteria = ((ITopic2) topic).getCriteria();
+ } else {
+ criteria = new ICriteria[0];
+ }
+ for (Iterator iter = providers.iterator(); iter.hasNext();) {
+ AbstractCriteriaProvider provider = (AbstractCriteriaProvider) iter.next();
+ ICriteria[] newCriteria = provider.getCriteria(topic);
+ if (newCriteria.length > 0) {
+ if (criteria.length == 0) {
+ criteria = newCriteria;
+ } else {
+ ICriteria[] union = new ICriteria[criteria.length + newCriteria.length];
+ System.arraycopy(criteria, 0, union, 0, criteria.length);
+ System.arraycopy(newCriteria, 0, union, criteria.length, newCriteria.length);
+ criteria = union;
+ }
+ }
+ }
+ return criteria;
+ }
+
+ public ICriteria[] getAllCriteria(IToc toc) {
+ readProviders();
+ ICriteria[] criteria;
+ if (toc instanceof IToc2) {
+ criteria = ((IToc2) toc).getCriteria();
+ } else {
+ criteria = new ICriteria[0];
+ }
+ for (Iterator iter = providers.iterator(); iter.hasNext();) {
+ AbstractCriteriaProvider provider = (AbstractCriteriaProvider) iter.next();
+ ICriteria[] newCriteria = provider.getCriteria(toc);
+ if (newCriteria.length > 0) {
+ if (criteria.length == 0) {
+ criteria = newCriteria;
+ } else {
+ ICriteria[] union = new ICriteria[criteria.length + newCriteria.length];
+ System.arraycopy(criteria, 0, union, 0, criteria.length);
+ System.arraycopy(newCriteria, 0, union, criteria.length, newCriteria.length);
+ criteria = union;
+ }
+ }
+ }
+ return criteria;
+ }
+
+}
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 ab1966cb2..2e7bcb223 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
@@ -27,6 +27,7 @@ import org.eclipse.help.internal.Anchor;
import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.Topic;
import org.eclipse.help.internal.UAElement;
+import org.eclipse.help.internal.criteria.CriteriaProviderRegistry;
import org.eclipse.help.internal.dynamic.DocumentProcessor;
import org.eclipse.help.internal.dynamic.DocumentReader;
import org.eclipse.help.internal.dynamic.ExtensionHandler;
@@ -475,11 +476,11 @@ public class TocAssembler {
ICriteria[] criteria = new ICriteria[0];
if (element instanceof Topic) {
Topic topic = (Topic) element;
- criteria = topic.getCriteria();
+ criteria = CriteriaProviderRegistry.getInstance().getAllCriteria(topic);
}
else if (element instanceof Toc) {
Toc toc = (Toc) element;
- criteria = toc.getCriteria();
+ criteria = CriteriaProviderRegistry.getInstance().getAllCriteria(toc);
}
HelpPlugin.getCriteriaManager().addCriteriaValues(criteria, locale);

Back to the top