Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDejan Gloszic2006-02-09 16:12:14 -0500
committerDejan Gloszic2006-02-09 16:12:14 -0500
commit834e3d487a039eabb087a1e601194b6a4c0f2ed4 (patch)
tree0b1982327205f215dc83f6e22a10b5b928d8e424 /org.eclipse.help
parentd6e3d9d22d4cedb6b53ce705f46d41ea5576d466 (diff)
downloadeclipse.platform.ua-834e3d487a039eabb087a1e601194b6a4c0f2ed4.tar.gz
eclipse.platform.ua-834e3d487a039eabb087a1e601194b6a4c0f2ed4.tar.xz
eclipse.platform.ua-834e3d487a039eabb087a1e601194b6a4c0f2ed4.zip
Bug 126267 Insert-at-anchor should insert elements, not just files.
Diffstat (limited to 'org.eclipse.help')
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/xhtml/UAContentMergeProcessor.java20
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/xhtml/UATopicExtension.java77
2 files changed, 66 insertions, 31 deletions
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 d3aff6120..786531559 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
@@ -199,13 +199,9 @@ 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);
+ Element[] elements = topicExtension.getElements();
+ for (int i = 0; i < elements.length; i++) {
+ Node targetNode = document.importNode(elements[i], true);
anchorElement.getParentNode().insertBefore(targetNode, anchorElement);
}
return true;
@@ -265,13 +261,9 @@ public class UAContentMergeProcessor {
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);
+ Element[] elements = topicReplace.getElements();
+ for (int i = 0; i < elements.length; i++) {
+ Node targetNode = document.importNode(elements[i], true);
replaceElement.getParentNode().insertBefore(targetNode, replaceElement);
}
replaceElement.getParentNode().removeChild(replaceElement);
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UATopicExtension.java b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UATopicExtension.java
index b92b8816b..32e6b9b60 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UATopicExtension.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/xhtml/UATopicExtension.java
@@ -9,6 +9,9 @@
package org.eclipse.help.internal.xhtml;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -20,45 +23,85 @@ public class UATopicExtension extends AbstractUAElement {
protected static final String ATT_PATH = "path"; //$NON-NLS-1$
private static final String ATT_CONTENT = "content"; //$NON-NLS-1$
+
+ private static final Element[] EMPTY_ELEMENT_ARRAY = new Element[0];
private String path;
- private String content;
+ private String contentFile;
+ private String contentId;
private Element element;
UATopicExtension(Element element, Bundle bundle) {
super(element, bundle);
path = getAttribute(element, ATT_PATH);
- content = getAttribute(element, ATT_CONTENT);
- content = BundleUtil.getResolvedResourceLocation(content, bundle, false);
+ extractFileAndId(getAttribute(element, ATT_CONTENT), bundle);
+ contentFile = BundleUtil.getResolvedResourceLocation(contentFile, bundle, false);
this.element = element;
}
/**
- * @return Returns the content.
- */
- public String getContent() {
- return content;
- }
-
- /**
* @return Returns the path.
*/
public String getPath() {
return path;
}
-
- public Document getDocument() {
-
- UAContentParser parser = new UAContentParser(content);
+ /**
+ * Returns the elements loaded from the content attribute. This is the content
+ * that should be inserted for the extension. If it is a file, all child elements
+ * of body are returned. If it is a file with an id, only the element with the id
+ * is returned.
+ *
+ * @return the elements to be inserted
+ */
+ public Element[] getElements() {
+ UAContentParser parser = new UAContentParser(contentFile);
Document dom = parser.getDocument();
- return dom;
+ if (dom != null) {
+ if (contentId != null) {
+ // id specified, only get that element
+ return new Element[] { dom.getElementById(contentId) };
+ }
+ else {
+ // no id specified, use the whole body
+ Element extensionBody = DOMUtil.getBodyElement(dom);
+ return DOMUtil.getElementsByTagName(extensionBody, "*"); //$NON-NLS-1$
+ }
+ }
+ return EMPTY_ELEMENT_ARRAY;
}
-
public Element getElement() {
return element;
}
-
+ /**
+ * Extracts the file and id parts of the content attribute. This attribute has two modes -
+ * if you specify a file, it will include the body of that file (minus the body element itself).
+ * If you append an id after the file, only the element with that id will be included. However
+ * we need to know which mode we're in.
+ *
+ * @param content the content attribute value
+ * @param bundle the bundle that contributed this extension
+ */
+ private void extractFileAndId(String content, Bundle bundle) {
+ // look for the file first
+ IPath resourcePath = new Path(content);
+ if (Platform.find(bundle, resourcePath) != null) {
+ // found it, it's a file with no id
+ contentFile = content;
+ }
+ else {
+ // didn't find the file, assume the last segment is an id
+ int lastSlashIndex = content.lastIndexOf('/');
+ if (lastSlashIndex != -1) {
+ contentFile = content.substring(0, lastSlashIndex);
+ contentId = content.substring(lastSlashIndex + 1);
+ }
+ else {
+ // there was no slash, it must be a file
+ contentFile = content;
+ }
+ }
+ }
}

Back to the top