Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,10 @@ private void doScanZippedNetBeansOrgSources() throws IOException {

private String parseCNB(final ZipEntry projectXML) throws IOException {
Document doc;
InputStream is = nbSrcZip.getInputStream(projectXML);
try {
doc = XMLUtil.parse(new InputSource(is), false, true, null, null);
try (InputStream is = nbSrcZip.getInputStream(projectXML)) {
doc = XMLUtil.parse(new InputSource(is), false, true, true, null, null);
} catch (SAXException e) {
throw (IOException) new IOException(projectXML + ": " + e.toString()).initCause(e); // NOI18N
} finally {
is.close();
throw new IOException(projectXML + ": " + e.toString(), e); // NOI18N
}
Element docel = doc.getDocumentElement();
Element type = XMLUtil.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); // NOI18N
Expand Down
2 changes: 1 addition & 1 deletion ergonomics/ide.ergonomics/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
javac.source=1.8
javac.release=21
javac.compilerargs=-Xlint -Xlint:-serial

javadoc.arch=${basedir}/arch.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -38,7 +39,6 @@
import javax.swing.Icon;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.xml.parsers.DocumentBuilder;
import org.netbeans.api.autoupdate.UpdateElement;
import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.project.Project;
Expand All @@ -63,15 +63,15 @@
import org.openide.util.lookup.ProxyLookup;
import org.openide.util.lookup.ServiceProvider;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.netbeans.api.project.ui.OpenProjects;
import org.netbeans.spi.project.ui.LogicalViewProvider;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataFolder;
import org.openide.nodes.FilterNode;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor.Task;
import org.openide.xml.XMLUtil;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
Expand Down Expand Up @@ -116,20 +116,15 @@ Document dom(String relative) {
}
File f = FileUtil.toFile(fo);
try {
DocumentBuilder b = DocumentBuilderFactory.newInstance().newDocumentBuilder();
if (f != null) {
doc = b.parse(f);
} else {
InputStream is = fo.getInputStream();
doc = b.parse(is);
InputStream is = f != null ? new FileInputStream(f) : fo.getInputStream();
try (is) {
doc = XMLUtil.parse(new InputSource(is), false, false, true, null, null);
}
if (doms == null) {
doms = new HashMap<String,Document>();
}
doms.put(relative, doc);
return doc;
} catch (ParserConfigurationException parserConfigurationException) {
LOG.log(Level.WARNING, "Cannot configure XML parser", parserConfigurationException); // NOI18N
} catch (SAXException sAXException) {
LOG.log(Level.INFO, "XML broken in " + f, sAXException); // NOI18N
} catch (Exception any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public ProjectProblemsProvider getProblemProvider() {

private Document loadConfig(FileObject config) throws IOException, SAXException {
synchronized (configIOLock) {
return XMLUtil.parse(new InputSource(config.toURL().toString()), false, true, null, null);
return XMLUtil.parse(new InputSource(config.toURL().toString()), false, true, true, null, null);
}
}

Expand Down Expand Up @@ -281,7 +281,7 @@ public void run() {
if (str != null) {
Document doc;
try {
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, null, null);
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, true, null, null);
return XMLUtil.findElement(doc.getDocumentElement(), elementName, namespace);
} catch (SAXException ex) {
LOG.log(Level.FINE, "cannot parse", ex);
Expand Down Expand Up @@ -327,7 +327,7 @@ private void lazyAttachListener() {
String str = (String) projectDirectory.getAttribute(AUX_CONFIG);
if (str != null) {
try {
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, null, null);
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, true, null, null);
} catch (SAXException ex) {
LOG.log(Level.FINE, "cannot parse", ex);
} catch (IOException ex) {
Expand Down Expand Up @@ -396,7 +396,7 @@ private void lazyAttachListener() {
String str = (String) projectDirectory.getAttribute(AUX_CONFIG);
if (str != null) {
try {
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, null, null);
doc = XMLUtil.parse(new InputSource(new StringReader(str)), false, true, true, null, null);
} catch (SAXException | IOException ex) {
Exceptions.printStackTrace(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ private byte[] applyBuildExtensions(byte[] resultData, AntBuildExtender ext) {
ByteArrayInputStream in2 = new ByteArrayInputStream(resultData);
InputSource is = new InputSource(in2);

Document doc = XMLUtil.parse(is, false, true, null, null);
Document doc = XMLUtil.parse(is, false, true, true, null, null);
Element el = doc.getDocumentElement();
Node firstSubnode = el.getFirstChild();
//TODO check if first one is text and use it as indentation..
Expand Down Expand Up @@ -495,11 +495,7 @@ private byte[] applyBuildExtensions(byte[] resultData, AntBuildExtender ext) {
XMLUtil.write(doc, out, "UTF-8"); //NOI18N
return out.toByteArray();
}
catch (IOException ex) {
Exceptions.printStackTrace(ex);
return resultData;
}
catch (SAXException ex) {
catch (IOException | SAXException ex) {
Exceptions.printStackTrace(ex);
return resultData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.netbeans.modules.xml.retriever.catalog.Utilities;
import org.netbeans.modules.xml.xam.dom.DocumentModel;
import org.netbeans.modules.xml.retriever.catalog.CatalogAttribute;
import org.netbeans.modules.xml.retriever.catalog.CatalogElement;
import org.netbeans.modules.xml.retriever.catalog.CatalogEntry;
import org.netbeans.modules.xml.retriever.impl.Util;
import org.openide.cookies.EditorCookie;
import org.openide.cookies.SaveCookie;
import org.openide.filesystems.FileLock;
Expand Down Expand Up @@ -377,10 +377,10 @@ private HashMap<String,String> getOtherAttributes(Element elm, String[] strArry)

public synchronized void sync() throws IOException {
logger.finer("ENTER");
DocumentBuilderFactory dBuilderFact = DocumentBuilderFactory.newInstance();
//dBuilderFact.setValidating(true);
DocumentBuilder dBuilder = null;
try {
DocumentBuilderFactory dBuilderFact = Util.createEntityIgnoringDBF();
//dBuilderFact.setValidating(true);
dBuilder = dBuilderFact.newDocumentBuilder();
} catch (ParserConfigurationException ex) {
assignStateAndFirePropChangeEvent(DocumentModel.State.NOT_WELL_FORMED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ public LSInput resolveResource(String type, String namespaceURI, String publicId
//create LSInput object
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
domImpl = Util.createEntityIgnoringDBF().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException ex) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import java.net.URISyntaxException;
import javax.swing.text.BadLocationException;
import javax.swing.text.StyledDocument;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.netbeans.modules.xml.retriever.catalog.CatalogWriteModelFactory;
import org.netbeans.modules.xml.retriever.impl.Util;
import org.netbeans.modules.xml.xam.locator.CatalogModelException;
import org.netbeans.modules.xml.xam.locator.CatalogModel;
import org.netbeans.modules.xml.xam.ModelSource;
Expand Down Expand Up @@ -110,8 +110,7 @@ public LSInput resolveResource(String type, String namespaceURI, String publicId
//create LSInput object
DOMImplementation domImpl = null;
try {

domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
domImpl = Util.createEntityIgnoringDBF().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException ex) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.netbeans.modules.xml.retriever.*;
import org.netbeans.modules.xml.retriever.DocumentTypeParser;
import org.netbeans.modules.xml.retriever.impl.IConstants;
import org.netbeans.modules.xml.retriever.catalog.Utilities.DocumentTypesEnum;
import org.netbeans.modules.xml.retriever.catalog.Utilities.HashNamespaceResolver;
import org.openide.filesystems.FileObject;
Expand All @@ -49,6 +47,7 @@ public class DocumentTypeSchemaWsdlParser implements DocumentTypeParser{
public DocumentTypeSchemaWsdlParser() {
}

@Override
public boolean accept(String mimeType) {
if(mimeType != null && mimeType.equalsIgnoreCase(DocumentTypesEnum.schema.toString())) //noi18n
return true;
Expand All @@ -58,6 +57,7 @@ public boolean accept(String mimeType) {
}


@Override
public List<String> getAllLocationOfReferencedEntities(FileObject fob) throws Exception{
return getAllLocationOfReferencedEntities(FileUtil.toFile(fob));
}
Expand All @@ -79,8 +79,8 @@ private void initXpath() throws Exception{
}
}

private Map<String, String> namespaces = new HashMap<String,String>();
private Map<String, String> prefixes = new HashMap<String,String>();
private final Map<String, String> namespaces = new HashMap<>();
private final Map<String, String> prefixes = new HashMap<>();

private NamespaceContext getNamespaceContext() {
namespaces.put("xsd","http://www.w3.org/2001/XMLSchema"); //NOI18N
Expand All @@ -91,16 +91,17 @@ private NamespaceContext getNamespaceContext() {
}

private Node getDOMTree(File parsedFile) throws Exception{
DocumentBuilderFactory dbfact = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory dbfact = Util.createEntityIgnoringDBF();
dbfact.setNamespaceAware(true);

FileObject parsedFileObject = FileUtil.toFileObject(FileUtil.normalizeFile(parsedFile));
Node node = dbfact.newDocumentBuilder().parse(parsedFileObject.getInputStream());
return node;
}


@Override
public List<String> getAllLocationOfReferencedEntities(File parsedFile) throws Exception{
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
initXpath();
Node documentNode = getDOMTree(parsedFile);

Expand Down Expand Up @@ -150,7 +151,6 @@ public List<String> getAllLocationOfReferencedEntities(File parsedFile) throws E


public String getFileExtensionByParsing(File parsedFile) throws Exception{
String result = null;
initXpath();
Node documentNode = getDOMTree(parsedFile);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.modules.xml.retriever.Retriever;
Expand All @@ -37,7 +38,6 @@
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.modules.Places;
import org.openide.util.Exceptions;

/**
*
Expand Down Expand Up @@ -299,6 +299,14 @@ public static FileObject getProjectCatalogFileObject(Project prj, boolean create
}
return result;
}


public static DocumentBuilderFactory createEntityIgnoringDBF() throws ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); //NOI18N
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); //NOI18N
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); //NOI18N
return dbf;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
import java.util.concurrent.Callable;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.annotations.common.NullAllowed;
import org.netbeans.api.java.classpath.ClassPath;
Expand Down Expand Up @@ -579,23 +576,6 @@ public Project getOwningProject() {

}

private static final DocumentBuilder db;
static {
try {
db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new AssertionError(e);
}
}
// private static Document createNewDocument() {
// // #50198: for thread safety, use a separate document.
// // Using XMLUtil.createDocument is much too slow.
// synchronized (db) {
// return db.newDocument();
// }
// }
//
//
@NonNull
private Runnable newStartMainUpdaterAction() {
return () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.netbeans.modules.maven.grammar;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.annotations.common.StaticResource;
Expand All @@ -42,7 +41,6 @@
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.MIMEResolver;
import org.openide.loaders.DataObjectExistsException;
import org.openide.loaders.MultiDataObject;
import org.openide.loaders.MultiFileLoader;
Expand Down Expand Up @@ -187,7 +185,7 @@ static String annotateWithProjectName(FileObject primaryFile) { // #154508
if (primaryFile.getNameExt().equals("pom.xml")) { // NOI18N
try {
//TODO faster and less memory intensive to have just FileObject().asText()-> regexp?
Element artifactId = XMLUtil.findElement(XMLUtil.parse(new InputSource(primaryFile.toURL().toString()), false, false, XMLUtil.defaultErrorHandler(), null).getDocumentElement(), "artifactId", null); // NOI18N
Element artifactId = XMLUtil.findElement(XMLUtil.parse(new InputSource(primaryFile.toURL().toString()), false, false, true, XMLUtil.defaultErrorHandler(), null).getDocumentElement(), "artifactId", null); // NOI18N
if (artifactId != null) {
String text = XMLUtil.findText(artifactId);
if (text != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public static Map<String,List<String>> getLifecyclePlugins(String packaging, @Nu
return Collections.emptyMap();
}
private static Map<String,List<String>> parsePhases(String u, String packaging) throws Exception {
Document doc = XMLUtil.parse(new InputSource(u), false, false, XMLUtil.defaultErrorHandler(), null);
Document doc = XMLUtil.parse(new InputSource(u), false, false, true, XMLUtil.defaultErrorHandler(), null);
for (Element componentsEl : XMLUtil.findSubElements(doc.getDocumentElement())) {
for (Element componentEl : XMLUtil.findSubElements(componentsEl)) {
if (XMLUtil.findText(XMLUtil.findElement(componentEl, "role", null)).trim().equals("org.apache.maven.lifecycle.mapping.LifecycleMapping")
Expand Down Expand Up @@ -379,8 +379,8 @@ private static Map<String,List<String>> parsePhases(String u, String packaging)
return null;
}
LOG.log(Level.FINER, "parsing plugin.xml from {0}", jar);
try {
return XMLUtil.parse(new InputSource("jar:" + BaseUtilities.toURI(jar) + "!/META-INF/maven/plugin.xml"), false, false, XMLUtil.defaultErrorHandler(), null);
try {
return XMLUtil.parse(new InputSource("jar:" + BaseUtilities.toURI(jar) + "!/META-INF/maven/plugin.xml"), false, false, true, XMLUtil.defaultErrorHandler(), null);
} catch (Exception x) {
LOG.log(Level.FINE, "could not parse " + jar, x.toString());
return null;
Expand Down
Loading
Loading