summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-04-29 08:15:48 (EDT)
committerSteffen Pingel2013-04-30 18:52:50 (EDT)
commit9c42f8f5ab42e17df14f7f56ae3b74b6cf64d1e8 (patch)
tree373668cb2c4ba175466bcd603308f122124696be
parentacc6f6573910885dd42c1666c035e056dd003c04 (diff)
downloadorg.eclipse.mylyn.commons-9c42f8f5ab42e17df14f7f56ae3b74b6cf64d1e8.zip
org.eclipse.mylyn.commons-9c42f8f5ab42e17df14f7f56ae3b74b6cf64d1e8.tar.gz
org.eclipse.mylyn.commons-9c42f8f5ab42e17df14f7f56ae3b74b6cf64d1e8.tar.bz2
406959: use SAXParserFactory instead of XMLReaderFactoryrefs/changes/29/12329/3
Change-Id: Id5686cab7a633fea681d815a589cfe77620f26e6 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=406959
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java33
-rw-r--r--org.eclipse.mylyn.discovery.core/src/org/eclipse/mylyn/internal/discovery/core/model/DirectoryParser.java4
2 files changed, 35 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java
index 0b590fc..a5d94ee 100644
--- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java
@@ -13,8 +13,14 @@ package org.eclipse.mylyn.commons.core;
import java.util.Map;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
/**
* @since 3.0
@@ -42,6 +48,11 @@ public class CoreUtil {
private static final String FRAMEWORK_VERSION = "3.9.0"; //$NON-NLS-1$
+ private static final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
+ static {
+ saxParserFactory.setNamespaceAware(true);
+ }
+
/**
* Returns a string representation of <code>object</code>. If object is a map or array the returned string will
* contains a comma separated list of contained elements.
@@ -304,4 +315,26 @@ public class CoreUtil {
return sb.toString();
}
+ /**
+ * Returns a new {@link XMLReader} instance using default factories.
+ *
+ * @since 3.9
+ */
+ public static SAXParser newSaxParser() throws SAXException {
+ try {
+ return saxParserFactory.newSAXParser();
+ } catch (ParserConfigurationException e) {
+ throw new SAXException(e);
+ }
+ }
+
+ /**
+ * Returns a new {@link XMLReader} instance using default factories.
+ *
+ * @since 3.9
+ */
+ public static XMLReader newXmlReader() throws SAXException {
+ return newSaxParser().getXMLReader();
+ }
+
}
diff --git a/org.eclipse.mylyn.discovery.core/src/org/eclipse/mylyn/internal/discovery/core/model/DirectoryParser.java b/org.eclipse.mylyn.discovery.core/src/org/eclipse/mylyn/internal/discovery/core/model/DirectoryParser.java
index 91343aa..914355f 100644
--- a/org.eclipse.mylyn.discovery.core/src/org/eclipse/mylyn/internal/discovery/core/model/DirectoryParser.java
+++ b/org.eclipse.mylyn.discovery.core/src/org/eclipse/mylyn/internal/discovery/core/model/DirectoryParser.java
@@ -16,6 +16,7 @@ import java.io.Reader;
import java.net.URI;
import java.net.URISyntaxException;
+import org.eclipse.mylyn.commons.core.CoreUtil;
import org.eclipse.mylyn.internal.discovery.core.model.Directory.Entry;
import org.eclipse.mylyn.internal.discovery.core.util.DefaultSaxErrorHandler;
import org.eclipse.mylyn.internal.discovery.core.util.IOWithCauseException;
@@ -26,7 +27,6 @@ import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
/**
* A parser for {@link Directory directories}.
@@ -64,7 +64,7 @@ public class DirectoryParser {
public Directory parse(Reader directoryContents) throws IOException {
XMLReader xmlReader;
try {
- xmlReader = XMLReaderFactory.createXMLReader();
+ xmlReader = CoreUtil.newXmlReader();
} catch (SAXException e) {
throw new IOWithCauseException(e.getMessage(), e);
}