Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMazen Faraj2006-01-13 16:44:59 -0500
committerMazen Faraj2006-01-13 16:44:59 -0500
commite9859684805333a516c21e2193e0df7e5807fb84 (patch)
tree56129935d70a92ab2a03d38e504a2ec62259a863 /org.eclipse.help
parent12e416b0c8835c8610b662a1dd76e3a1ac6a4440 (diff)
downloadeclipse.platform.ua-e9859684805333a516c21e2193e0df7e5807fb84.tar.gz
eclipse.platform.ua-e9859684805333a516c21e2193e0df7e5807fb84.tar.xz
eclipse.platform.ua-e9859684805333a516c21e2193e0df7e5807fb84.zip
Final enhancements after M4
Diffstat (limited to 'org.eclipse.help')
-rw-r--r--org.eclipse.help/schema/contentExtension.exsd19
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentFilterProcessor.java86
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentMergeProcessor.java81
3 files changed, 166 insertions, 20 deletions
diff --git a/org.eclipse.help/schema/contentExtension.exsd b/org.eclipse.help/schema/contentExtension.exsd
index 856941790..8a9bef71c 100644
--- a/org.eclipse.help/schema/contentExtension.exsd
+++ b/org.eclipse.help/schema/contentExtension.exsd
@@ -53,6 +53,19 @@
<annotation>
<documentation>
a plugin-relative path to the location of an extension content file. An extension content file is an XML file that specifies the location of content contributions (as XHTML pages/snippets) and the target page where they should be merged into. The content file is parsed at run time by the Help system framework and each content extension is loaded and inserted into the target location specified by the anchor.
+
+This content file should have the following syntax:&lt;br&gt;
+&lt;code&gt;
+&lt;pre&gt;
+ &lt;contentExtension&gt;
+ &lt;topicExtension content=&quot;plugin/relative/path/topicExtensionFile.xhml&quot;
+ path=&quot;plugin_id/path_to_xhtml_file/anchor_id&quot;/&gt;
+ &lt;topicReplace content=&quot;topicReplaceFile.xhml&quot; path=&quot;plugin_id/path_to_xhtml_file/element_id&quot; /&gt;
+ &lt;/contentExtension&gt;
+&lt;/pre&gt;
+&lt;/code&gt;
+ &lt;br&gt;
+&lt;code&gt;topicExtension&lt;/code&gt; is the markup used to insert content at the target anchor location. &lt;code&gt;topicReplace&lt;/code&gt; is the markup used to replace the content of the target element by the specified content. In other words, content can be contributed that either adds to the target location or replaces the content of the target location.
</documentation>
<appInfo>
<meta.attribute kind="resource"/>
@@ -87,8 +100,6 @@
&lt;/p&gt;
&lt;p&gt;The above contribution inserts the content of the XHTML file, &lt;samp&gt;topicA.xhtml&lt;/samp&gt;, into the target Help system page specified by the &lt;samp&gt;path&lt;/samp&gt; attribute. In this case, the content extension will be inserted in the location of an anchor called &lt;samp&gt;topicAnchor&lt;/samp&gt; in page &lt;samp&gt;someHelpPage.xhtml&lt;/samp&gt; in plugin &lt;samp&gt;org.xxx.yyy.somePluginId&lt;/samp&gt;.&lt;/p&gt;
-&lt;/p&gt;
-&lt;/p&gt;
</documentation>
</annotation>
@@ -98,7 +109,7 @@
</appInfo>
<documentation>
No code is required to use this extension point. All that is needed is to supply the appropriate content files mentioned in the plugin.xml file.
-&lt;/p&gt;
+
</documentation>
</annotation>
@@ -108,7 +119,7 @@
</appInfo>
<documentation>
The default implementation of the base help system supplied with the Eclipse platform fully supports this &lt;samp&gt;contentExtension&lt;/samp&gt; extension point.
-&lt;/p&gt;
+
</documentation>
</annotation>
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 294330bd2..326fcfb32 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
@@ -9,7 +9,9 @@
package org.eclipse.help.internal.xhtml;
+import org.eclipse.core.runtime.IProduct;
import org.eclipse.core.runtime.Platform;
+import org.osgi.framework.Bundle;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -35,11 +37,16 @@ public class UAContentFilterProcessor {
}
public void applyFilters(Element element) {
+ boolean filteredIn = false;
if (hasFilterAttribute(element)) {
- boolean filteredIn = false;
filteredIn = processFilterAttribute(element);
if (!filteredIn)
return;
+ } else if (hasFiltersAsChildren(element)) {
+ Element[] filters = DOMUtil.getElementsByTagName(element, "filter");
+ filteredIn = processFilterChildren(element, filters);
+ if (!filteredIn)
+ return;
}
NodeList allChildElements = element.getChildNodes();
@@ -58,6 +65,14 @@ public class UAContentFilterProcessor {
return true;
}
+ private static boolean hasFiltersAsChildren(Element element) {
+ Element[] filters = DOMUtil.getElementsByTagName(element, "filter");
+ if (filters != null && filters.length > 0)
+ return true;
+ return false;
+ }
+
+
/**
* Returns true is filter passes and Element is to be included.
*
@@ -74,9 +89,25 @@ public class UAContentFilterProcessor {
if (!filtered_in)
element.getParentNode().removeChild(element);
- return false;
+ return filtered_in;
+ }
+
+
+ private boolean processFilterChildren(Element parent, Element[] filters) {
+ boolean filtered_in = false;
+ for (int i = 0; i < filters.length; i++) {
+ String filter = filters[i].getAttribute("name");
+ String value = filters[i].getAttribute("value");
+ filtered_in = isFilteredIn(filter, value);
+ if (!filtered_in) {
+ parent.getParentNode().removeChild(parent);
+ break;
+ }
+ }
+ return filtered_in;
}
+
/**
* FIltering capabilities. Can be overiden by subclasses to add more filtering capabilities.
*
@@ -90,6 +121,12 @@ public class UAContentFilterProcessor {
filtered_in = filterByWS(value);
} else if (filter.equals("os")) { //$NON-NLS-1$
filtered_in = filterByOS(value);
+ } else if (filter.equals("arch")) { //$NON-NLS-1$
+ filtered_in = filterByARCH(value);
+ } else if (filter.equals("product")) { //$NON-NLS-1$
+ filtered_in = filterByProduct(value);
+ } else if (filter.equals("plugin")) { //$NON-NLS-1$
+ filtered_in = filterByPlugin(value);
} else
filtered_in = filterBySystemProperty(filter, value);
@@ -116,6 +153,51 @@ public class UAContentFilterProcessor {
return false;
}
+ /**
+ * evaluates ARCH filter.
+ */
+ private static boolean filterByARCH(String arch) {
+ String currentArch = Platform.getOSArch();
+ if (currentArch.equals(arch))
+ return true;
+ return false;
+ }
+
+ /**
+ * evaluates product filter.
+ */
+ private static boolean filterByProduct(String productId) {
+ IProduct product = Platform.getProduct();
+ if (product == null)
+ return false;
+
+ String currentProductId = product.getId();
+ if (currentProductId.equals(productId))
+ return true;
+ return false;
+ }
+
+ /**
+ * evaluates plugin filter.
+ */
+ private static boolean filterByPlugin(String bundleId) {
+ Bundle bundle = Platform.getBundle(bundleId);
+ boolean bundleIsOK = checkBundleState(bundle);
+ if (bundleIsOK)
+ return true;
+
+ return false;
+ }
+
+
+ public static boolean checkBundleState(Bundle bundle) {
+ if (bundle == null || bundle.getState() == Bundle.UNINSTALLED
+ || bundle.getState() == Bundle.INSTALLED)
+ return false;
+
+ return true;
+ }
+
/**
* evaluates system property filter.
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentMergeProcessor.java b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentMergeProcessor.java
index 17e1f8333..0965797bb 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentMergeProcessor.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentMergeProcessor.java
@@ -146,10 +146,16 @@ public class UAContentMergeProcessor {
private void resolveContentExtension(Document contentExtensionDom, IConfigurationElement contentExtElement) {
Bundle bundle = BundleUtil.getBundleFromConfigurationElement(contentExtElement);
Element[] topicExtensions = DOMUtil.getElementsByTagName(contentExtensionDom, "topicExtension"); //$NON-NLS-1$
- if (topicExtensions == null)
- return;
- for (int i = 0; i < topicExtensions.length; i++)
- doResolveContentExtension(topicExtensions[i], bundle);
+ if (topicExtensions != null) {
+ for (int i = 0; i < topicExtensions.length; i++)
+ doResolveContentExtension(topicExtensions[i], bundle);
+ }
+
+ Element[] topicReplaces = DOMUtil.getElementsByTagName(contentExtensionDom, "topicReplace"); //$NON-NLS-1$
+ if (topicReplaces != null) {
+ for (int i = 0; i < topicReplaces.length; i++)
+ doResolveContentReplace(topicReplaces[i], bundle);
+ }
}
private void doResolveContentExtension(Element topicExtension, Bundle bundle) {
@@ -177,8 +183,6 @@ public class UAContentMergeProcessor {
}
-
-
/**
* Insert the topic extension content into the target page if the target page happens to be this
* page.
@@ -195,25 +199,19 @@ public class UAContentMergeProcessor {
else
return false;
}
-
Document topicExtensionDom = topicExtension.getDocument();
if (topicExtensionDom == null)
return false;
-
Element extensionBody = DOMUtil.getBodyElement(topicExtensionDom);
Element[] children = DOMUtil.getElementsByTagName(extensionBody, "*"); //$NON-NLS-1$
for (int i = 0; i < children.length; i++) {
Node targetNode = document.importNode(children[i], true);
anchorElement.getParentNode().insertBefore(targetNode, anchorElement);
}
-
-
return true;
-
}
-
private Element findAnchor(UATopicExtension topicExtension, String locale) {
String path = topicExtension.getPath();
int index = path.indexOf("/"); //$NON-NLS-1$
@@ -234,8 +232,6 @@ public class UAContentMergeProcessor {
}
-
-
protected Document loadContentExtension(IConfigurationElement cfgElement) {
String content = cfgElement.getAttribute("file"); //$NON-NLS-1$
content = BundleUtil.getResourceLocation(content, cfgElement);
@@ -244,5 +240,62 @@ public class UAContentMergeProcessor {
}
+ private void doResolveContentReplace(Element topicReplace, Bundle bundle) {
+ UATopicExtension topicReplaceModel = new UATopicExtension(topicReplace, bundle);
+ boolean isExtensionToCurrentPage = resolveTopicReplace(topicReplaceModel);
+ if (isExtensionToCurrentPage) {
+ if (topicReplace.hasAttribute("failed")) { //$NON-NLS-1$
+ if (!unresolvedConfigExt.containsKey(topicReplace))
+ unresolvedConfigExt.put(topicReplace, bundle);
+ } else {
+ unresolvedConfigExt.remove(topicReplace);
+ // tryResolvingExtensions();
+ }
+ }
+ }
+
+
+
+ private boolean resolveTopicReplace(UATopicExtension topicReplace) {
+
+ Element replaceElement = findReplaceElementById(topicReplace, locale);
+ if (replaceElement == null) {
+ if (topicReplace.getElement().hasAttribute("failed")) //$NON-NLS-1$
+ return true;
+ else
+ return false;
+ }
+ Document topicExtensionDom = topicReplace.getDocument();
+ if (topicExtensionDom == null)
+ return false;
+ Element extensionBody = DOMUtil.getBodyElement(topicExtensionDom);
+ Element[] children = DOMUtil.getElementsByTagName(extensionBody, "*"); //$NON-NLS-1$
+ for (int i = 0; i < children.length; i++) {
+ Node targetNode = document.importNode(children[i], true);
+ replaceElement.getParentNode().insertBefore(targetNode, replaceElement);
+ }
+ return true;
+ }
+
+ private Element findReplaceElementById(UATopicExtension topicReplace, String locale) {
+ String path = topicReplace.getPath();
+ int index = path.indexOf("/"); //$NON-NLS-1$
+ if (index < 0)
+ return null;
+ String pluginID = path.substring(0, index);
+ int lastIndex = path.lastIndexOf("/"); //$NON-NLS-1$
+ String pluginRelativePath = path.substring(index + 1, lastIndex);
+ String element_id = path.substring(lastIndex + 1, path.length());
+
+ if (this.pluginID.equals(pluginID) && this.file.equals(pluginRelativePath)) {
+ Element elementToReplace = DOMUtil.getElementById(document, element_id, "*"); //$NON-NLS-1$
+ if (elementToReplace == null)
+ topicReplace.getElement().setAttribute("failed", "true"); //$NON-NLS-1$ //$NON-NLS-2$
+ return elementToReplace;
+ }
+ return null;
+ }
+
+
}

Back to the top