Skip to content

Commit

Permalink
Refactor XML parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T authored and jukzi committed Jul 26, 2023
1 parent 8f75dca commit 38dd2a8
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.jdt.apt.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Export-Package: com.sun.mirror.apt,
org.eclipse.jdt.apt.core.internal.util;x-friends:="org.eclipse.jdt.apt.pluggable.core,org.eclipse.jdt.apt.tests,org.eclipse.jdt.apt.ui,org.eclipse.jdt.apt.pluggable.tests",
org.eclipse.jdt.apt.core.util
Require-Bundle: org.eclipse.jdt.core;bundle-version="[3.34.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.5.100,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.6.0,4.0.0)",
org.apache.ant;bundle-version="1.6.5"
Bundle-Activator: org.eclipse.jdt.apt.core.internal.AptPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.eclipse.core.internal.runtime.XmlProcessorFactory;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand Down Expand Up @@ -221,8 +222,9 @@ public static Map<FactoryContainer, FactoryPath.Attributes> decodeFactoryPath(fi
Element fpElement = null;

try {
DocumentBuilder parser =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
@SuppressWarnings("restriction")
DocumentBuilder parser = org.eclipse.core.internal.runtime.XmlProcessorFactory
.createDocumentBuilderWithErrorOnDOCTYPE();
fpElement = parser.parse(new InputSource(reader)).getDocumentElement();

}
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.apt.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Require-Bundle: org.eclipse.jdt.apt.core;bundle-version="[3.6.0,4.0.0)",
org.eclipse.jdt.ui;bundle-version="[3.14.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.34.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.ui.forms;bundle-version="[3.2.0,4.0.0)"
Bundle-ActivationPolicy: lazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ public static boolean test() throws Exception {
"</model>\n";

// create "actual" model
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document actualModel = factory.newDocumentBuilder().newDocument();
Document actualModel = org.eclipse.core.internal.runtime.XmlProcessorFactory.createDocumentBuilderWithErrorOnDOCTYPE().newDocument();
Element modelNode = actualModel.createElement(MODEL_TAG);
// primary type
Element typeNode = actualModel.createElement(TYPE_ELEMENT_TAG);
Expand Down Expand Up @@ -204,7 +203,7 @@ public static boolean test() throws Exception {

// load reference model
InputSource source = new InputSource(new StringReader(XML_FRAMEWORK_TEST_MODEL));
Document expectedModel = factory.newDocumentBuilder().parse(source);
Document expectedModel = org.eclipse.core.internal.runtime.XmlProcessorFactory.createDocumentBuilderWithErrorOnDOCTYPE().parse(source);

// compare actual and reference
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static String xmlToString(Document model) {
StringWriter s = new StringWriter();
DOMSource domSource = new DOMSource(model);
StreamResult streamResult = new StreamResult(s);
TransformerFactory tf = TransformerFactory.newInstance();
TransformerFactory tf = org.eclipse.core.internal.runtime.XmlProcessorFactory.createTransformerFactoryWithErrorOnDOCTYPE();
Transformer serializer;
try {
serializer = tf.newTransformer();
Expand Down Expand Up @@ -146,8 +146,7 @@ public static String xmlToCutAndPasteString(Document model, int indent, boolean
* @throws ParserConfigurationException
*/
public static Document convertModel(Iterable<? extends javax.lang.model.element.Element> declarations) throws ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document model = factory.newDocumentBuilder().newDocument();
Document model = org.eclipse.core.internal.runtime.XmlProcessorFactory.createDocumentBuilderWithErrorOnDOCTYPE().newDocument();
org.w3c.dom.Element modelNode = model.createElement(MODEL_TAG);

XMLConverter converter = new XMLConverter(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
import javax.xml.parsers.DocumentBuilderFactory;

import org.eclipse.jdt.compiler.apt.tests.processors.base.XMLComparer;
import org.eclipse.jdt.compiler.apt.tests.processors.base.XMLConverter;
Expand Down Expand Up @@ -844,8 +843,7 @@ private boolean checkModel(List<TypeElement> rootElements, String expected, Stri
Document actualModel = XMLConverter.convertModel(rootElements);

InputSource source = new InputSource(new StringReader(expected));
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document expectedModel = factory.newDocumentBuilder().parse(source);
Document expectedModel = org.eclipse.core.internal.runtime.XmlProcessorFactory.createDocumentBuilderWithErrorOnDOCTYPE().parse(source);

ByteArrayOutputStream out = new ByteArrayOutputStream();
StringBuilder summary = new StringBuilder();
Expand Down
3 changes: 2 additions & 1 deletion org.eclipse.jdt.core.internal.tools/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Bundle-Version: 1.2.0.qualifier
Bundle-Vendor: %providerName
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: META-INF.services
Require-Bundle: org.eclipse.jdt.core.compiler.batch;bundle-version="3.35.0"
Require-Bundle: org.eclipse.jdt.core.compiler.batch;bundle-version="3.35.0",
org.eclipse.core.runtime;bundle-version="3.29.0"
Automatic-Module-Name: org.eclipse.jdt.core.internal.tools

Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ public static String[] buildTables(
List<String> result = new ArrayList<>();
SAXParser saxParser = null;
try {
saxParser = SAXParserFactory.newInstance().newSAXParser();
} catch (ParserConfigurationException e) {
e.printStackTrace();
return null;
} catch (SAXException e) {
@SuppressWarnings("restriction")
SAXParser p = org.eclipse.core.internal.runtime.XmlProcessorFactory.createSAXParserWithErrorOnDOCTYPE();
saxParser =p;
} catch (SAXException | ParserConfigurationException e) {
e.printStackTrace();
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Require-Bundle: org.junit;bundle-version="3.8.1",
org.eclipse.jdt.core;bundle-version="[3.34.0,4.0.0)",
org.eclipse.jdt.core.tests.compiler;bundle-version="[3.4.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.test.performance;bundle-version="[3.1.0,4.0.0)",
org.eclipse.jdt.annotation;bundle-version="[1.1.0,2.0.0)";resolution:=optional,
org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Export-Package: org.eclipse.jdt.core.tests.compiler,
Require-Bundle: org.junit;bundle-version="3.8.1",
org.eclipse.jdt.debug;bundle-version="[3.2.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.34.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.test.performance;bundle-version="[3.10.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.jdt.annotation;bundle-version="[1.1.0,2.0.0)";resolution:=optional,
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Export-Package: org.eclipse.jdt.core.tests,
org.eclipse.jdt.core.tests.rewrite.describing,
org.eclipse.jdt.core.tests.rewrite.modifying
Require-Bundle: org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.34.0,4.0.0)",
org.junit;bundle-version="3.8.1",
org.eclipse.test.performance;bundle-version="[3.1.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.eclipse.core.internal.runtime.XmlProcessorFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
Expand Down Expand Up @@ -63,7 +63,7 @@ public static Map decodeCodeFormatterOptions(String fileName) {

public static Map decodeCodeFormatterOptions(String fileName, String profileName) {
try {
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
SAXParser saxParser = XmlProcessorFactory.createSAXParserWithErrorOnDOCTYPE();
final DecodeCodeFormatterPreferences preferences = new DecodeCodeFormatterPreferences(profileName);
saxParser.parse(new File(fileName), preferences);
return preferences.getEntries();
Expand All @@ -89,7 +89,7 @@ public static Map decodeCodeFormatterOptions(String zipFileName, String zipEntry
return null;
}
inputStream = new BufferedInputStream(zipFile.getInputStream(zipEntry));
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
SAXParser saxParser = XmlProcessorFactory.createSAXParserWithErrorOnDOCTYPE();
final DecodeCodeFormatterPreferences preferences = new DecodeCodeFormatterPreferences(profileName);
saxParser.parse(inputStream, preferences);
return preferences.getEntries();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Bundle-Localization: plugin
Export-Package: org.eclipse.jdt.core.tests.performance,
org.eclipse.jdt.core.tests.performance.util
Require-Bundle: org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.34.0,4.0.0)",
org.eclipse.jdt.core.tests.builder;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jdt.core.tests.compiler;bundle-version="[3.4.0,4.0.0)",
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Export-Package: org.eclipse.jdt.core,
org.eclipse.jdt.internal.formatter.linewrap;x-internal:=true,
org.eclipse.jdt.internal.formatter.old;x-internal:=true
Require-Bundle: org.eclipse.core.resources;bundle-version="[3.18.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.13.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.core.filesystem;bundle-version="[1.7.0,2.0.0)",
org.eclipse.text;bundle-version="[3.6.0,4.0.0)",
org.eclipse.team.core;bundle-version="[3.1.0,4.0.0)";resolution:=optional,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import java.util.zip.ZipFile;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.eclipse.core.resources.IFile;
Expand Down Expand Up @@ -3566,7 +3565,8 @@ public void loadVariablesAndContainers() throws CoreException {
StringReader reader = new StringReader(xmlString);
Element cpElement;
try {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
@SuppressWarnings("restriction")
DocumentBuilder parser = org.eclipse.core.internal.runtime.XmlProcessorFactory.createDocumentBuilderWithErrorOnDOCTYPE();
cpElement = parser.parse(new InputSource(reader)).getDocumentElement();
} catch(SAXException | ParserConfigurationException e){
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.stream.Collectors;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IFile;
Expand Down Expand Up @@ -1317,7 +1316,8 @@ public IClasspathEntry[][] decodeClasspath(String xmlClasspath, Map unknownEleme
StringReader reader = new StringReader(xmlClasspath);
Element cpElement;
try {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
@SuppressWarnings("restriction")
DocumentBuilder parser = org.eclipse.core.internal.runtime.XmlProcessorFactory.createDocumentBuilderWithErrorOnDOCTYPE();
cpElement = parser.parse(new InputSource(reader)).getDocumentElement();
} catch (SAXException | ParserConfigurationException e) {
throw new IOException(Messages.file_badFormat, e);
Expand Down Expand Up @@ -1378,8 +1378,9 @@ public IClasspathEntry decodeClasspathEntry(String encodedEntry) {
Element node;

try {
@SuppressWarnings("restriction")
DocumentBuilder parser =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
org.eclipse.core.internal.runtime.XmlProcessorFactory.createDocumentBuilderWithErrorOnDOCTYPE();
node = parser.parse(new InputSource(reader)).getDocumentElement();
} catch (SAXException | ParserConfigurationException e) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.eclipse.core.runtime.Assert;
Expand Down Expand Up @@ -148,7 +147,8 @@ public static String serialize(IClasspathEntry[] entries, boolean isSystemLibrar
public static UserLibrary createFromString(Reader reader) throws IOException {
Element cpElement;
try {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
@SuppressWarnings("restriction")
DocumentBuilder parser = org.eclipse.core.internal.runtime.XmlProcessorFactory.createDocumentBuilderWithErrorOnDOCTYPE();
cpElement = parser.parse(new InputSource(reader)).getDocumentElement();
} catch (SAXException | ParserConfigurationException e) {
throw new IOException(Messages.file_badFormat, e);
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.tests.latestBREE/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Bundle-Activator: org.eclipse.jdt.tests.latestbree.Activator
Require-Bundle: org.junit;bundle-version="3.8.1",
org.eclipse.jdt.debug;bundle-version="[3.2.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.10.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.test.performance;bundle-version="[3.10.0,4.0.0)",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.jdt.annotation;bundle-version="[1.1.0,2.0.0)";resolution:=optional,
Expand Down

0 comments on commit 38dd2a8

Please sign in to comment.