summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-04-29 12:52:00 (EDT)
committerSteffen Pingel2013-04-29 13:25:23 (EDT)
commit58243ff3cad073116c0dc140ec580d99ea635344 (patch)
treec64af5364b6658882a016c1d40c1bb50fb50e1d7
parent3f1f632321583806973999648a3928c802acbd34 (diff)
downloadorg.eclipse.mylyn.tasks-58243ff3cad073116c0dc140ec580d99ea635344.zip
org.eclipse.mylyn.tasks-58243ff3cad073116c0dc140ec580d99ea635344.tar.gz
org.eclipse.mylyn.tasks-58243ff3cad073116c0dc140ec580d99ea635344.tar.bz2
406647: use SAXParserFactory instead of XMLReaderFactoryrefs/changes/52/12352/3
* SAXParserFactory does not statically cache discovered classes Change-Id: Ib040ce847a2f17a0f675c296081e62d8df61bf16 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=406647
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java27
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java11
2 files changed, 27 insertions, 11 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java
index 6eb633b..dc94e4b 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java
@@ -23,13 +23,17 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
/**
* @author Rob Elves
@@ -112,7 +116,7 @@ public class TaskRepositoriesExternalizer {
}
SaxRepositoriesContentHandler contentHandler = new SaxRepositoriesContentHandler();
- XMLReader reader = XMLReaderFactory.createXMLReader();
+ XMLReader reader = TaskRepositoriesExternalizer.createXmlReader();
reader.setContentHandler(contentHandler);
reader.parse(new InputSource(inputStream));
return contentHandler.getRepositories();
@@ -132,4 +136,23 @@ public class TaskRepositoriesExternalizer {
}
}
}
+
+ public static XMLReader createXmlReader() throws SAXException {
+ try {
+ // use Xerces to ensure XML 1.1 is handled correctly
+ Class<?> clazz = Class.forName("org.apache.xerces.parsers.SAXParser"); //$NON-NLS-1$
+ return (XMLReader) clazz.newInstance();
+ } catch (Throwable e) {
+ SAXParser saxParser;
+ try {
+ SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+ saxParserFactory.setNamespaceAware(true);
+ saxParser = saxParserFactory.newSAXParser();
+ } catch (ParserConfigurationException e2) {
+ throw new SAXException(e2);
+ }
+ return saxParser.getXMLReader();
+ }
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java
index c73f115..f0d8308 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java
@@ -27,6 +27,7 @@ import javax.xml.transform.stream.StreamResult;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.SafeRunner;
+import org.eclipse.mylyn.internal.tasks.core.TaskRepositoriesExternalizer;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.IRepositoryManager;
import org.eclipse.mylyn.tasks.core.TaskRepository;
@@ -36,7 +37,6 @@ import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
/**
* @author Steffen Pingel
@@ -177,14 +177,7 @@ public class TaskDataExternalizer {
}
public TaskDataState readState(InputStream in) throws IOException, SAXException {
- XMLReader parser;
- try {
- // use Xerces to ensure XML 1.1 is handled correctly
- Class<?> clazz = Class.forName("org.apache.xerces.parsers.SAXParser"); //$NON-NLS-1$
- parser = (XMLReader) clazz.newInstance();
- } catch (Throwable e) {
- parser = XMLReaderFactory.createXMLReader();
- }
+ XMLReader parser = TaskRepositoriesExternalizer.createXmlReader();
TaskDataStateReader handler = new TaskDataStateReader(taskRepositoryManager);
parser.setContentHandler(handler);
parser.parse(new InputSource(in));