Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2008-04-18 19:07:40 -0400
committerChris Goldthorpe2008-04-18 19:07:40 -0400
commit4303a01acb1402c2e4f711b4414c363d71ef9e8b (patch)
treeea3d966f1cdef73b6c0af66adc673b77f34bc16b /org.eclipse.help
parent30429f1ff9905330d8288c29188452cdbd5254ed (diff)
downloadeclipse.platform.ua-4303a01acb1402c2e4f711b4414c363d71ef9e8b.tar.gz
eclipse.platform.ua-4303a01acb1402c2e4f711b4414c363d71ef9e8b.tar.xz
eclipse.platform.ua-4303a01acb1402c2e4f711b4414c363d71ef9e8b.zip
Bug 205092 – [Help] Java Heap Space issues with Eclipse Help IC
Diffstat (limited to 'org.eclipse.help')
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/UAElement.java6
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentReader.java7
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/IndexAssembler.java5
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/IndexDocumentReader.java56
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileParser.java5
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/IndexManager.java76
6 files changed, 112 insertions, 43 deletions
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/UAElement.java b/org.eclipse.help/src/org/eclipse/help/internal/UAElement.java
index cbeb879d4..884df9f0e 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/UAElement.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/UAElement.java
@@ -155,8 +155,8 @@ public class UAElement implements IUAElement {
public IUAElement[] getChildren() {
if (children == null) {
- children = new ArrayList();
if (element.hasChildNodes()) {
+ children = new ArrayList(4);
Node node = element.getFirstChild();
while (node != null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
@@ -168,6 +168,8 @@ public class UAElement implements IUAElement {
}
node = node.getNextSibling();
}
+ } else {
+ return new UAElement[0];
}
}
return (UAElement[])children.toArray(new UAElement[children.size()]);
@@ -217,7 +219,7 @@ public class UAElement implements IUAElement {
importElement(newChild);
element.insertBefore(newChild.element, refChild.element);
newChild.parent = this;
-
+ getChildren();
if (children != null) {
int index = children.indexOf(refChild);
if (index < 0) {
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentReader.java b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentReader.java
index 412717969..165b46667 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentReader.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/dynamic/DocumentReader.java
@@ -55,8 +55,15 @@ public class DocumentReader {
}
Document document = managedBuilder.builder.parse(input);
managedBuilder.inUse = false;
+ prepareDocument(document);
return UAElementFactory.newElement(document.getDocumentElement());
}
+
+ /**
+ * Allows subclasses to process the DOM before creating a UA element
+ */
+ protected void prepareDocument(Document document) {
+ }
private synchronized ManagedBuilder getManagedBuilder() throws FactoryConfigurationError, ParserConfigurationException {
if (cachedBuilder == null || cachedBuilder.inUse) {
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexAssembler.java b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexAssembler.java
index 233ddf944..dff337140 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexAssembler.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexAssembler.java
@@ -62,6 +62,7 @@ public class IndexAssembler {
while (iter.hasNext()) {
IndexContribution contribution = (IndexContribution)iter.next();
mergeChildren(index, (Index)contribution.getIndex());
+ contribution.setIndex(null);
}
return index;
}
@@ -178,10 +179,6 @@ public class IndexAssembler {
topic.setHref(HrefUtil.normalizeHref(pluginId, href));
}
}
- String title = element.getAttribute("title"); //$NON-NLS-1$
- if (title != null) {
- topic.setLabel(title);
- }
}
return UNHANDLED;
}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexDocumentReader.java b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexDocumentReader.java
new file mode 100644
index 000000000..3f5220076
--- /dev/null
+++ b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexDocumentReader.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.index;
+
+import org.eclipse.help.internal.dynamic.DocumentReader;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class IndexDocumentReader extends DocumentReader {
+
+ protected void prepareDocument(Document document) {
+ prune(document.getDocumentElement());
+ }
+
+ private void prune(Node element) {
+ NodeList nodes = element.getChildNodes();
+ Node node = nodes.item(0);
+ while (node != null) {
+ short nodeType = node.getNodeType();
+ if (nodeType == Node.TEXT_NODE || nodeType == Node.COMMENT_NODE) {
+ Node nodeToDelete = node;
+ node = node.getNextSibling();
+ element.removeChild(nodeToDelete);
+ } else if (nodeType == Node.ELEMENT_NODE) {
+ String kind = node.getNodeName();
+ if ("topic".equalsIgnoreCase(kind)) { //$NON-NLS-1$
+ fixTopicAttributes((Element)node);
+ }
+ prune(node);
+ node = node.getNextSibling();
+ } else {
+ node = node.getNextSibling();
+ }
+ }
+ }
+
+ private void fixTopicAttributes(Element topic) {
+ String title = topic.getAttribute("name"); //$NON-NLS-1$
+ if (title != null && title.length() > 0) {
+ topic.setAttribute("label", title); //$NON-NLS-1$
+ topic.removeAttribute("name"); //$NON-NLS-1$
+ }
+ }
+
+}
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileParser.java b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileParser.java
index 4aebbbcfa..3baeaac6f 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileParser.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 Intel Corporation and others.
+ * Copyright (c) 2005, 2008 Intel 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
@@ -8,6 +8,7 @@
* Contributors:
* Intel Corporation - initial API and implementation
* IBM Corporation - 122967 [Help] Remote help system
+ * IBM Corporation - Use IndexDocumentReader
*******************************************************************************/
package org.eclipse.help.internal.index;
@@ -26,7 +27,7 @@ public class IndexFileParser {
public IndexContribution parse(IndexFile indexFile) throws IOException, SAXException, ParserConfigurationException {
if (reader == null) {
- reader = new DocumentReader();
+ reader = new IndexDocumentReader();
}
InputStream in = indexFile.getInputStream();
if (in != null) {
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexManager.java b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexManager.java
index c2fbeb16f..4616dcda0 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/index/IndexManager.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/index/IndexManager.java
@@ -53,7 +53,7 @@ public class IndexManager {
if (HelpPlugin.DEBUG_INDEX) {
System.out.println("Start to update keyword index for locale " + locale); //$NON-NLS-1$
}
- List contributions = new ArrayList(Arrays.asList(getIndexContributions(locale)));
+ List contributions = new ArrayList(Arrays.asList(readIndexContributions(locale)));
filterIndexContributions(contributions);
IndexAssembler assembler = new IndexAssembler();
index = assembler.assemble(contributions, locale);
@@ -71,45 +71,51 @@ public class IndexManager {
* providers.
*/
public synchronized IndexContribution[] getIndexContributions(String locale) {
- IndexContribution[] cached = (IndexContribution[])indexContributionsByLocale.get(locale);
- if (cached == null) {
- List contributions = new ArrayList();
- AbstractIndexProvider[] providers = getIndexProviders();
- for (int i=0;i<providers.length;++i) {
- IIndexContribution[] contrib;
- try {
- contrib = providers[i].getIndexContributions(locale);
+ IndexContribution[] contributions = (IndexContribution[])indexContributionsByLocale.get(locale);
+ if (contributions == null) {
+ contributions = readIndexContributions(locale);
+ indexContributionsByLocale.put(locale, contributions);
+ }
+ return contributions;
+ }
+
+ private IndexContribution[] readIndexContributions(String locale) {
+ IndexContribution[] cached;
+ List contributions = new ArrayList();
+ AbstractIndexProvider[] providers = getIndexProviders();
+ for (int i=0;i<providers.length;++i) {
+ IIndexContribution[] contrib;
+ try {
+ contrib = providers[i].getIndexContributions(locale);
+ }
+ catch (Throwable t) {
+ // log, and skip the offending provider
+ String msg = "Error getting help keyword index data from provider: " + providers[i].getClass().getName() + " (skipping provider)"; //$NON-NLS-1$ //$NON-NLS-2$
+ HelpPlugin.logError(msg, t);
+ continue;
+ }
+
+ // check for nulls and root element
+ for (int j=0;j<contrib.length;++j) {
+ if (contrib[j] == null) {
+ String msg = "Help keyword index provider \"" + providers[i].getClass().getName() + "\" returned a null contribution (skipping)"; //$NON-NLS-1$ //$NON-NLS-2$
+ HelpPlugin.logError(msg);
}
- catch (Throwable t) {
- // log, and skip the offending provider
- String msg = "Error getting help keyword index data from provider: " + providers[i].getClass().getName() + " (skipping provider)"; //$NON-NLS-1$ //$NON-NLS-2$
- HelpPlugin.logError(msg, t);
- continue;
+ else if (contrib[j].getIndex() == null) {
+ String msg = "Help keyword index provider \"" + providers[i].getClass().getName() + "\" returned a contribution with a null root element (expected a \"" + Index.NAME + "\" element; skipping)"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ HelpPlugin.logError(msg);
}
-
- // check for nulls and root element
- for (int j=0;j<contrib.length;++j) {
- if (contrib[j] == null) {
- String msg = "Help keyword index provider \"" + providers[i].getClass().getName() + "\" returned a null contribution (skipping)"; //$NON-NLS-1$ //$NON-NLS-2$
- HelpPlugin.logError(msg);
- }
- else if (contrib[j].getIndex() == null) {
- String msg = "Help keyword index provider \"" + providers[i].getClass().getName() + "\" returned a contribution with a null root element (expected a \"" + Index.NAME + "\" element; skipping)"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- HelpPlugin.logError(msg);
- }
- else {
- IndexContribution contribution = new IndexContribution();
- contribution.setId(contrib[j].getId());
- contribution.setLocale(contrib[j].getLocale());
- IIndex index = contrib[j].getIndex();
- contribution.setIndex(index instanceof Index ? (Index)index : (Index)UAElementFactory.newElement(index));
- contributions.add(contribution);
- }
+ else {
+ IndexContribution contribution = new IndexContribution();
+ contribution.setId(contrib[j].getId());
+ contribution.setLocale(contrib[j].getLocale());
+ IIndex index = contrib[j].getIndex();
+ contribution.setIndex(index instanceof Index ? (Index)index : (Index)UAElementFactory.newElement(index));
+ contributions.add(contribution);
}
}
- cached = (IndexContribution[])contributions.toArray(new IndexContribution[contributions.size()]);
- indexContributionsByLocale.put(locale, cached);
}
+ cached = (IndexContribution[])contributions.toArray(new IndexContribution[contributions.size()]);
return cached;
}

Back to the top