Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java86
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/index/IndexFileParser.java19
-rw-r--r--org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileParser.java26
3 files changed, 75 insertions, 56 deletions
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java
index 10b60fead..3897b71d1 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/context/ContextFileProvider.java
@@ -196,44 +196,10 @@ public class ContextFileProvider extends AbstractContextProvider {
// load the file
InputStream in = ResourceLocator.openFromPlugin(descriptor.getBundleId(), descriptor.getFile(), locale);
if (in != null) {
- if (reader == null) {
- reader = new DocumentReader();
- }
- UAElement root = reader.read(in);
- if ("contexts".equals(root.getElementName())) { //$NON-NLS-1$
- // process dynamic content
- if (processor == null) {
- processor = new DocumentProcessor(new ProcessorHandler[] {
- new ValidationHandler(getRequiredAttributes()),
- new NormalizeHandler(),
- new IncludeHandler(reader, locale),
- new ExtensionHandler(reader, locale)
- });
- }
- processor.process(root, '/' + descriptor.getBundleId() + '/' + descriptor.getFile());
-
- // build map
- IUAElement[] children = root.getChildren();
- Map contexts = new HashMap();
- for (int i=0;i<children.length;++i) {
- if (children[i] instanceof Context) {
- Context context = (Context)children[i];
- String id = context.getId();
- if (id != null) {
- Object existingContext = contexts.get(id);
- if (existingContext != null) {
- ((Context)existingContext).mergeContext(context);
- } else {
- contexts.put(id, context);
- }
- }
- }
- }
- return contexts;
- }
- else {
- String msg = "Required root element \"contexts\" missing from context-sensitive help file \"/" + getErrorPath(descriptor, locale) + "\" (skipping)"; //$NON-NLS-1$ //$NON-NLS-2$
- HelpPlugin.logError(msg);
+ try {
+ return loadContextsFromInputStream(descriptor, locale, in);
+ } finally {
+ in.close();
}
}
else {
@@ -246,6 +212,50 @@ public class ContextFileProvider extends AbstractContextProvider {
}
return null;
}
+
+ private Map loadContextsFromInputStream(ContextFile descriptor, String locale, InputStream in)
+ throws Exception {
+ if (reader == null) {
+ reader = new DocumentReader();
+ }
+ UAElement root = reader.read(in);
+ if ("contexts".equals(root.getElementName())) { //$NON-NLS-1$
+ // process dynamic content
+ if (processor == null) {
+ processor = new DocumentProcessor(new ProcessorHandler[] {
+ new ValidationHandler(getRequiredAttributes()),
+ new NormalizeHandler(),
+ new IncludeHandler(reader, locale),
+ new ExtensionHandler(reader, locale)
+ });
+ }
+ processor.process(root, '/' + descriptor.getBundleId() + '/' + descriptor.getFile());
+
+ // build map
+ IUAElement[] children = root.getChildren();
+ Map contexts = new HashMap();
+ for (int i=0;i<children.length;++i) {
+ if (children[i] instanceof Context) {
+ Context context = (Context)children[i];
+ String id = context.getId();
+ if (id != null) {
+ Object existingContext = contexts.get(id);
+ if (existingContext != null) {
+ ((Context)existingContext).mergeContext(context);
+ } else {
+ contexts.put(id, context);
+ }
+ }
+ }
+ }
+ return contexts;
+ }
+ else {
+ String msg = "Required root element \"contexts\" missing from context-sensitive help file \"/" + getErrorPath(descriptor, locale) + "\" (skipping)"; //$NON-NLS-1$ //$NON-NLS-2$
+ HelpPlugin.logError(msg);
+ }
+ return null;
+ }
private String getErrorPath(ContextFile descriptor, String locale) {
return ResourceLocator.getErrorPath(descriptor.getBundleId(), descriptor.getFile(), locale);
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 3baeaac6f..d1a2d8022 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, 2008 Intel Corporation and others.
+ * Copyright (c) 2005, 2009 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
@@ -9,6 +9,7 @@
* Intel Corporation - initial API and implementation
* IBM Corporation - 122967 [Help] Remote help system
* IBM Corporation - Use IndexDocumentReader
+ * IBM Corporation - [Bug 297921
*******************************************************************************/
package org.eclipse.help.internal.index;
@@ -31,12 +32,16 @@ public class IndexFileParser {
}
InputStream in = indexFile.getInputStream();
if (in != null) {
- Index index = (Index)reader.read(in);
- IndexContribution contrib = new IndexContribution();
- contrib.setId('/' + indexFile.getPluginId() + '/' + indexFile.getFile());
- contrib.setIndex(index);
- contrib.setLocale(indexFile.getLocale());
- return contrib;
+ try {
+ Index index = (Index)reader.read(in);
+ IndexContribution contrib = new IndexContribution();
+ contrib.setId('/' + indexFile.getPluginId() + '/' + indexFile.getFile());
+ contrib.setIndex(index);
+ contrib.setLocale(indexFile.getLocale());
+ return contrib;
+ } finally {
+ in.close();
+ }
}
else {
throw new FileNotFoundException();
diff --git a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileParser.java b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileParser.java
index 2d3759230..1242c01b4 100644
--- a/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileParser.java
+++ b/org.eclipse.help/src/org/eclipse/help/internal/toc/TocFileParser.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2009 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
@@ -30,16 +30,20 @@ public class TocFileParser extends DefaultHandler {
}
InputStream in = tocFile.getInputStream();
if (in != null) {
- Toc toc = (Toc)reader.read(in);
- TocContribution contribution = new TocContribution();
- contribution.setCategoryId(tocFile.getCategory());
- contribution.setContributorId(tocFile.getPluginId());
- contribution.setExtraDocuments(DocumentFinder.collectExtraDocuments(tocFile));
- contribution.setId(HrefUtil.normalizeHref(tocFile.getPluginId(), tocFile.getFile()));
- contribution.setLocale(tocFile.getLocale());
- contribution.setToc(toc);
- contribution.setPrimary(tocFile.isPrimary());
- return contribution;
+ try {
+ Toc toc = (Toc) reader.read(in);
+ TocContribution contribution = new TocContribution();
+ contribution.setCategoryId(tocFile.getCategory());
+ contribution.setContributorId(tocFile.getPluginId());
+ contribution.setExtraDocuments(DocumentFinder.collectExtraDocuments(tocFile));
+ contribution.setId(HrefUtil.normalizeHref(tocFile.getPluginId(), tocFile.getFile()));
+ contribution.setLocale(tocFile.getLocale());
+ contribution.setToc(toc);
+ contribution.setPrimary(tocFile.isPrimary());
+ return contribution;
+ } finally {
+ in.close();
+ }
}
else {
throw new FileNotFoundException();

Back to the top