[121991] Exception in log when saving incorrect web.xml
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/DocumentProvider.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/DocumentProvider.java
index c5a0789..49aa95b 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/DocumentProvider.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/util/DocumentProvider.java
@@ -130,8 +130,12 @@
* @return Document
*/
public Document getDocument() {
+ return getDocument(true);
+ }
+
+ public Document getDocument(boolean createEmptyOnFailure) {
if (document == null)
- load();
+ load(createEmptyOnFailure);
return document;
}
@@ -165,7 +169,7 @@
public Element getElement(String name) {
Element result = null;
if (document == null)
- load();
+ load(false);
if (document != null) {
result = (Element) getNode(getRootElement(), name);
}
@@ -180,6 +184,9 @@
if (resolver == null) {
resolver = new EntityResolver() {
public InputSource resolveEntity(String publicID, String systemID) throws SAXException, IOException {
+ if (!isValidating())
+ return null;
+
InputSource result = null;
if (getBaseReference() != null) {
try {
@@ -380,7 +387,7 @@
return fValidating;
}
- public void load() {
+ void load(boolean createEmptyOnFailure) {
// rootElementName and fileName are expected to be defined at this
// point
document = getParsedDocument();
@@ -392,18 +399,20 @@
}
if (document == null || rootElement == null) {
- document = getNewDocument();
- if (document != null) {
- NodeList children = document.getChildNodes();
- for (int i = 0; i < children.getLength(); i++) {
- if (children.item(i).getNodeType() == Node.ELEMENT_NODE && children.item(i).getNodeName().equals(getRootElementName()))
- rootElement = children.item(i);
- }
- if (rootElement == null) {
+ if (createEmptyOnFailure) {
+ document = getNewDocument();
+ if (document != null) {
+ NodeList children = document.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
- if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
+ if (children.item(i).getNodeType() == Node.ELEMENT_NODE && children.item(i).getNodeName().equals(getRootElementName()))
rootElement = children.item(i);
- break;
+ }
+ if (rootElement == null) {
+ for (int i = 0; i < children.getLength(); i++) {
+ if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
+ rootElement = children.item(i);
+ break;
+ }
}
}
}
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/taglib/ProjectDescription.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/taglib/ProjectDescription.java
index 4500d62..6e311f1 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/taglib/ProjectDescription.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/taglib/ProjectDescription.java
@@ -1068,8 +1068,9 @@
DocumentProvider provider = new DocumentProvider();
provider.setInputStream(webxmlContents);
provider.setValidating(false);
+ provider.setRootElementName("web-app"); //$NON-NLS-1$
provider.setBaseReference(webxml.getParent().getLocation().toString());
- document = provider.getDocument();
+ document = provider.getDocument(false);
}
catch (CoreException e) {
Logger.logException(e);