Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-04-26 16:54:58 -0400
committerSteffen Pingel2013-04-30 13:08:53 -0400
commitaf505574701f1e70b64d892666dac6f4cffe9945 (patch)
tree8858a2f7915f54acfc3b15b786127f664982fe70 /org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn
parentefd5db80f0b94f2b9d94df6a153a4e98cfbd9e8b (diff)
downloadorg.eclipse.mylyn.tasks-af505574701f1e70b64d892666dac6f4cffe9945.tar.gz
org.eclipse.mylyn.tasks-af505574701f1e70b64d892666dac6f4cffe9945.tar.xz
org.eclipse.mylyn.tasks-af505574701f1e70b64d892666dac6f4cffe9945.zip
406647: task data gets corrupted when falling back to XML 1.1
Change-Id: I28a69c4aec071ae5ac72aa007285f9ca2acbedb1 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=406647
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/TaskRepositoriesExternalizer.java4
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/XmlReaderUtil.java50
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/TaskDataExternalizer.java4
3 files changed, 54 insertions, 4 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 6eb633bcc..9f0a33137 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
@@ -29,7 +29,6 @@ import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
/**
* @author Rob Elves
@@ -112,7 +111,7 @@ public class TaskRepositoriesExternalizer {
}
SaxRepositoriesContentHandler contentHandler = new SaxRepositoriesContentHandler();
- XMLReader reader = XMLReaderFactory.createXMLReader();
+ XMLReader reader = XmlReaderUtil.createXmlReader();
reader.setContentHandler(contentHandler);
reader.parse(new InputSource(inputStream));
return contentHandler.getRepositories();
@@ -132,4 +131,5 @@ public class TaskRepositoriesExternalizer {
}
}
}
+
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/XmlReaderUtil.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/XmlReaderUtil.java
new file mode 100644
index 000000000..482d017fc
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/XmlReaderUtil.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.core;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+/**
+ * Utility to create {@link XMLReader} instances. Uses Xerces if available to ensure XML 1.1 parsing works correctly.
+ *
+ * @author Steffen Pingel
+ */
+public class XmlReaderUtil {
+
+ 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();
+ }
+ }
+
+ private XmlReaderUtil() {
+ // clients must not instantiate class
+ }
+
+}
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 02c1d353b..477b467c8 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.XmlReaderUtil;
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,7 +177,7 @@ public class TaskDataExternalizer {
}
public TaskDataState readState(InputStream in) throws IOException, SAXException {
- XMLReader parser = XMLReaderFactory.createXMLReader();
+ XMLReader parser = XmlReaderUtil.createXmlReader();
TaskDataStateReader handler = new TaskDataStateReader(taskRepositoryManager);
parser.setContentHandler(handler);
parser.parse(new InputSource(in));

Back to the top