[250833] JSP fragment validation can not be disabled
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/validation/JSPBatchValidator.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/validation/JSPBatchValidator.java
index fa75f02..1f77298 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/validation/JSPBatchValidator.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/validation/JSPBatchValidator.java
@@ -509,9 +509,10 @@
}
IWorkspaceRunnable validationRunnable = new IWorkspaceRunnable() {
-
public void run(IProgressMonitor monitor) throws CoreException {
- validateFile((IFile) resource, reporter);
+ if (fragmentCheck((IFile) resource)) {
+ validateFile((IFile) resource, reporter);
+ }
result.setDependsOn((IResource[]) fDependsOn.toArray(new IResource[fDependsOn.size()]));
fDependsOn.clear();
}
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/validation/JSPContentValidator.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/validation/JSPContentValidator.java
index fd9a126..e0c1700 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/validation/JSPContentValidator.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/validation/JSPContentValidator.java
@@ -13,7 +13,9 @@
import java.io.IOException;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jst.jsp.core.internal.Logger;
import org.eclipse.wst.html.core.internal.document.HTMLDocumentTypeConstants;
import org.eclipse.wst.html.core.internal.validate.HTMLValidationAdapterFactory;
@@ -21,16 +23,32 @@
import org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory;
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
import org.eclipse.wst.sse.core.internal.validate.ValidationAdapter;
+import org.eclipse.wst.validation.ValidationResult;
+import org.eclipse.wst.validation.ValidationState;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;
+import org.w3c.dom.Element;
/**
* This validator validates the contents of the content type of the JSP, like
* the HTML regions in a JSP with content type="text/html"
*/
public class JSPContentValidator extends JSPValidator {
+ private static final String HTTP_JAVA_SUN_COM_JSP_PAGE = "http://java.sun.com/JSP/Page"; //$NON-NLS-1$
+ private static final String XMLNS = "xmlns"; //$NON-NLS-1$
+ private static final String XMLNS_JSP = "xmlns:jsp"; //$NON-NLS-1$
+
+
+ /*
+ * Copied from HTMLValidator
+ */
+ private HTMLValidationReporter getReporter(IReporter reporter, IFile file, IDOMModel model) {
+ return new HTMLValidationReporter(this, reporter, file, model);
+ }
+
/*
* Copied from HTMLValidator
*/
@@ -41,11 +59,33 @@
return adapter.hasFeature(HTMLDocumentTypeConstants.HTML);
}
- /*
- * Copied from HTMLValidator
- */
- private HTMLValidationReporter getReporter(IReporter reporter, IFile file, IDOMModel model) {
- return new HTMLValidationReporter(this, reporter, file, model);
+ private boolean isXMLJSP(IDOMDocument document) {
+ Element root = document.getDocumentElement();
+ return root != null && (root.hasAttribute(XMLNS_JSP) || HTTP_JAVA_SUN_COM_JSP_PAGE.equals(root.getAttribute(XMLNS)));
+ }
+
+ private void validate(IFile file, int kind, ValidationState state, IProgressMonitor monitor, IDOMModel model, IReporter reporter) {
+ IDOMDocument document = model.getDocument();
+ if (document == null)
+ return; // error
+
+ boolean isXMLJSP = isXMLJSP(document);
+ boolean hasHTMLFeature = hasHTMLFeature(document);
+
+ if (hasHTMLFeature && !isXMLJSP) {
+ INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance();
+ ValidationAdapter adapter = (ValidationAdapter) factory.adapt(document);
+ if (adapter != null) {
+ HTMLValidationReporter rep = getReporter(reporter, file, model);
+ rep.clear();
+ adapter.setReporter(rep);
+ adapter.validate(document);
+ }
+ }
+ if (!hasHTMLFeature && isXMLJSP) {
+ Validator xmlValidator = new Validator();
+ xmlValidator.validate(file, kind, state, monitor);
+ }
}
/*
@@ -60,7 +100,9 @@
// This validator currently only handles validating HTML content in
// JSP
- if (hasHTMLFeature(document)) {
+ boolean hasXMLFeature = isXMLJSP(document);
+ boolean hasHTMLFeature = hasHTMLFeature(document);
+ if (hasHTMLFeature && !hasXMLFeature) {
INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance();
ValidationAdapter adapter = (ValidationAdapter) factory.adapt(document);
if (adapter == null)
@@ -73,6 +115,35 @@
}
}
+ public ValidationResult validate(final IResource resource, int kind, ValidationState state, IProgressMonitor monitor) {
+ if (resource.getType() != IResource.FILE)
+ return null;
+ ValidationResult result = new ValidationResult();
+ final IReporter reporter = result.getReporter(monitor);
+
+ IStructuredModel model = null;
+ try {
+ model = StructuredModelManager.getModelManager().getModelForRead((IFile) resource);
+ if (!reporter.isCancelled() && model instanceof IDOMModel) {
+ reporter.removeAllMessages(this, resource);
+ validate((IFile) resource, kind, state, monitor, (IDOMModel) model, reporter);
+ }
+ }
+ catch (IOException e) {
+ Logger.logException(e);
+ }
+ catch (CoreException e) {
+ Logger.logException(e);
+ }
+ finally {
+ if (model != null)
+ model.releaseFromRead();
+ }
+
+ return result;
+ }
+
+
protected void validateFile(IFile f, IReporter reporter) {
IStructuredModel model = null;
try {
@@ -93,4 +164,5 @@
model.releaseFromRead();
}
}
+
}