[367856] [validation] Track javascript dependencies for validation in HTML
diff --git a/bundles/org.eclipse.wst.html.core/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.html.core/META-INF/MANIFEST.MF
index 287cb52..26a2dc1 100644
--- a/bundles/org.eclipse.wst.html.core/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.html.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.wst.html.core; singleton:=true
-Bundle-Version: 1.1.406.qualifier
+Bundle-Version: 1.1.407.qualifier
 Bundle-Activator: org.eclipse.wst.html.core.internal.HTMLCorePlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/preferences/HTMLCorePreferenceInitializer.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/preferences/HTMLCorePreferenceInitializer.java
index 3130e16..666db90 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/preferences/HTMLCorePreferenceInitializer.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/preferences/HTMLCorePreferenceInitializer.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2010 IBM Corporation and others.
+ * Copyright (c) 2005, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -81,7 +81,7 @@
 		node.putInt(HTMLCorePreferenceNames.ATTRIBUTE_DUPLICATE, ValidationMessage.WARNING);
 		node.putInt(HTMLCorePreferenceNames.ATTRIBUTE_VALUE_MISMATCH, ValidationMessage.ERROR);
 		node.putInt(HTMLCorePreferenceNames.ATTRIBUTE_VALUE_UNCLOSED, ValidationMessage.WARNING);
-		node.putInt(HTMLCorePreferenceNames.ATTRIBUTE_VALUE_RESOURCE_NOT_FOUND, ValidationMessage.IGNORE);
+		node.putInt(HTMLCorePreferenceNames.ATTRIBUTE_VALUE_RESOURCE_NOT_FOUND, ValidationMessage.WARNING);
 		node.putInt(HTMLCorePreferenceNames.ATTRIBUTE_OBSOLETE_NAME, ValidationMessage.WARNING);
 		
 		
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLAttributeValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLAttributeValidator.java
index 76e9d2f..7c34a29 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLAttributeValidator.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLAttributeValidator.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004, 2011 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -10,6 +10,7 @@
  *******************************************************************************/
 package org.eclipse.wst.html.core.internal.validate;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Locale;
 
@@ -41,6 +42,7 @@
 
 public class HTMLAttributeValidator extends PrimeValidator {
 
+	private static final String JAVASCRIPT_PREFIX = "javascript:"; //$NON-NLS-1$
 	private static final int REGION_NAME = 1;
 	private static final int REGION_VALUE = 2;
 	// <<D210422
@@ -200,17 +202,24 @@
 						}
 					}
 					else if (CMDataType.URI.equals(attrType.getDataTypeName())) {
-						// TODO: URI validation?
-						if (false && actualValue.indexOf('#') < 0 && actualValue.indexOf(":/") == -1 && CMUtil.isHTML(edec)) { //$NON-NLS-1$ //$NON-NLS-2$
+						if (actualValue.indexOf('#') < 0 && actualValue.indexOf(":/") < 0 && !actualValue.toLowerCase(Locale.ENGLISH).startsWith(JAVASCRIPT_PREFIX) && CMUtil.isHTML(edec)) { //$NON-NLS-1$ //$NON-NLS-2$
 							IStructuredDocumentRegion start = ((IDOMNode) node).getStartStructuredDocumentRegion();
+							// roundabout start tag check
 							if (start != null && start.getFirstRegion().getTextLength() == 1) {
-								IPath basePath = new Path(((IDOMNode) node).getModel().getBaseLocation());
-								if (basePath.segmentCount() > 1) {
-									IPath path = ModuleCoreSupport.resolve(basePath, actualValue);
-									IResource found = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
-									if (found == null || !found.isAccessible()) {
-										rgnType = REGION_VALUE;
-										state = ErrorState.RESOURCE_NOT_FOUND;
+								// only check when we have a way to set dependencies
+								Collection dependencies = (Collection) ((IDOMNode) ((IDOMNode) node).getOwnerDocument()).getUserData(HTMLValidationAdapterFactory.DEPENDENCIES);
+								if (dependencies != null) {
+									IPath basePath = new Path(((IDOMNode) node).getModel().getBaseLocation());
+									if (basePath.segmentCount() > 1) {
+										IPath path = ModuleCoreSupport.resolve(basePath, actualValue);
+										IResource found = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+										if (found == null) {
+											rgnType = REGION_VALUE;
+											state = ErrorState.RESOURCE_NOT_FOUND;
+										}
+										else {
+											dependencies.add(found);
+										}
 									}
 								}
 							}
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLValidationAdapterFactory.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLValidationAdapterFactory.java
index 1010e04..061574d 100644
--- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLValidationAdapterFactory.java
+++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/HTMLValidationAdapterFactory.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004, 2005 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -23,6 +23,8 @@
 
 	private static HTMLValidationAdapterFactory instance = null;
 
+	public static final String DEPENDENCIES = "org.eclipse.wst.html.validator.dependencies"; //$NON-NLS-1$
+
 	/**
 	 * HTMLValidationAdapterFactory constructor comment.
 	 */
diff --git a/bundles/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF
index 40d2506..a9a93a7 100644
--- a/bundles/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.wst.html.ui; singleton:=true
-Bundle-Version: 1.0.505.qualifier
+Bundle-Version: 1.0.506.qualifier
 Bundle-Activator: org.eclipse.wst.html.ui.internal.HTMLUIPlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/bundles/org.eclipse.wst.html.ui/src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java b/bundles/org.eclipse.wst.html.ui/src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java
index 2efc77b..28a6457 100644
--- a/bundles/org.eclipse.wst.html.ui/src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java
+++ b/bundles/org.eclipse.wst.html.ui/src-html-validation/org/eclipse/wst/html/internal/validation/HTMLValidator.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2001, 2007 IBM Corporation and others.
+ * Copyright (c) 2001, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -13,6 +13,8 @@
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
 
 import org.eclipse.core.filebuffers.ITextFileBuffer;
@@ -66,6 +68,7 @@
 import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
 import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob;
 import org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter;
+import org.eclipse.wst.xml.core.internal.document.NodeImpl;
 import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
 import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
 import org.w3c.dom.Text;
@@ -448,7 +451,7 @@
 				if (resource instanceof IFile) {
 					Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, resource.getFullPath().toString().substring(1));
 					reporter.displaySubtask(this, message);
-					validateFile(helper, reporter, (IFile) resource);
+					validateFile(helper, reporter, (IFile) resource, null);
 				}
 				else if (resource instanceof IContainer) {
 					validateContainer(helper, reporter, (IContainer) resource);
@@ -476,13 +479,13 @@
 			IResource resource = getResource(delta);
 			if (resource == null || !(resource instanceof IFile))
 				continue;
-			validateFile(helper, reporter, (IFile) resource);
+			validateFile(helper, reporter, (IFile) resource, null);
 		}
 	}
 
 	/**
 	 */
-	private void validateFile(IValidationContext helper, IReporter reporter, IFile file) {
+	private void validateFile(IValidationContext helper, IReporter reporter, IFile file, ValidationResult result) {
 		if ((reporter != null) && (reporter.isCancelled() == true)) {
 			throw new OperationCanceledException();
 		}
@@ -494,7 +497,20 @@
 			return;
 
 		try {
+			Collection dependencies = null;
+			NodeImpl document = null;
+			if (model.getDocument() instanceof NodeImpl) {
+				document = (NodeImpl) model.getDocument();
+			}
+			if (result != null && document != null) {
+				dependencies = new HashSet();
+				document.setUserData(HTMLValidationAdapterFactory.DEPENDENCIES, dependencies, null);
+			}
 			validate(reporter, file, model);
+			if (result != null && document != null) {
+				document.setUserData(HTMLValidationAdapterFactory.DEPENDENCIES, null, null);
+				result.setDependsOn((IResource[]) dependencies.toArray(new IResource[dependencies.size()]));
+			}
 		}
 		finally {
 			releaseModel(model);
@@ -557,7 +573,7 @@
 			return null;
 		ValidationResult result = new ValidationResult();
 		IReporter reporter = result.getReporter(monitor);
-		validateFile(null, reporter, (IFile) resource);
+		validateFile(null, reporter, (IFile) resource, result);
 		return result;
 	}
 }
\ No newline at end of file
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLValidationPreferencePage.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLValidationPreferencePage.java
index 1a1f612..0375c38 100644
--- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLValidationPreferencePage.java
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLValidationPreferencePage.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2008 IBM Corporation and others.
+ * Copyright (c) 2008, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -166,8 +166,7 @@
 		addComboBox(inner, label, HTMLCorePreferenceNames.ATTRIBUTE_VALUE_UNCLOSED, SEVERITIES, errorWarningIgnoreLabel, 0);
 		
 		label = HTMLUIMessages.HTMLValidationPreferencePage_35;
-		// TODO: validate resources?
-		// addComboBox(inner, label, HTMLCorePreferenceNames.ATTRIBUTE_VALUE_RESOURCE_NOT_FOUND, SEVERITIES, errorWarningIgnoreLabel, 0);
+		addComboBox(inner, label, HTMLCorePreferenceNames.ATTRIBUTE_VALUE_RESOURCE_NOT_FOUND, SEVERITIES, errorWarningIgnoreLabel, 0);
 
 		// End Attribute section