[298304] [validation] Generated EL problems severity should have user preference
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java
index f6ea3da..ec996ff 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/ELGeneratorVisitor.java
@@ -22,26 +22,40 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ProjectScope;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.core.runtime.preferences.InstanceScope;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jface.text.Position;
 import org.eclipse.jst.jsp.core.internal.JSPCoreMessages;
+import org.eclipse.jst.jsp.core.internal.JSPCorePlugin;
 import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController;
 import org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentImpl;
 import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
 import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TaglibTracker;
 import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDFunction;
+import org.eclipse.jst.jsp.core.internal.preferences.JSPCorePreferenceNames;
 import org.eclipse.jst.jsp.core.jspel.ELProblem;
 import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.sse.core.internal.FileBufferModelManager;
 import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
 import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
 import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection;
+import org.eclipse.wst.sse.core.internal.validate.ValidationMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
 
 public class ELGeneratorVisitor implements JSPELParserVisitor {
 	
+	private static final String PREFERENCE_NODE_QUALIFIER = JSPCorePlugin.getDefault().getBundle().getSymbolicName();
 	private static final String ENDL = "\n"; //$NON-NLS-1$
 	
 	private static final String fExpressionHeader1 = "public String _elExpression"; //$NON-NLS-1$
@@ -113,6 +127,7 @@
 	private boolean fUseParameterizedTypes;
 
 	private List fELProblems;
+	private IScopeContext[] fScopeContexts = null;
 
 	/**
 	 * Tranlsation of XML-style operators to java
@@ -150,6 +165,7 @@
 		fGeneratedFunctionStart = -1; //set when generating function definition
 		fUseParameterizedTypes = compilerSupportsParameterizedTypes();
 		fELProblems = new ArrayList();
+		fScopeContexts = getScopeContexts();
 	}
 
 	/**
@@ -552,12 +568,15 @@
 			append(")"); //$NON-NLS-1$
 		}
 		else {
-			//column offsets are 1 based not 0 based, thus subtract one
-			final int problemOffset = fContentStart + node.getFirstToken().beginColumn - 1;
-			final int problemLength = node.getLastToken().endColumn - 1;
-
-			//could not find function translation so report error
-			fELProblems.add(new ELProblem(new Position(problemOffset, problemLength), NLS.bind(JSPCoreMessages.JSPELTranslator_0, node.getFullFunctionName())));
+			final int sev = getProblemSeverity(JSPCorePreferenceNames.VALIDATION_EL_FUNCTION_UNDEFINED);
+			if (sev != ValidationMessage.IGNORE) {
+				//column offsets are 1 based not 0 based, thus subtract one
+				final int problemOffset = fContentStart + node.getFirstToken().beginColumn - 1;
+				final int problemLength = node.getLastToken().endColumn - 1;
+	
+				//could not find function translation so report error
+				fELProblems.add(new ELProblem(sev, new Position(problemOffset, problemLength), NLS.bind(JSPCoreMessages.JSPELTranslator_0, node.getFullFunctionName())));
+			}
 			
 			//error message to be injected into translation purely for debugging purposes
 			String errorMsg = "\"Could not find function translation for: " + node.getFullFunctionName() + "\""; //$NON-NLS-1$ //$NON-NLS-2$
@@ -658,4 +677,45 @@
 		
 		return funcNameToken;
 	}
+	
+	/**
+	 * @param key preference key used to get the severity for a problem
+	 * @param contexts preference service contexts
+	 * @return The severity of the problem represented by the given preference key
+	 */
+	private int getProblemSeverity(String key) {
+		return Platform.getPreferencesService().getInt(PREFERENCE_NODE_QUALIFIER, key, IMessage.NORMAL_SEVERITY, fScopeContexts);
+	}
+
+	private IScopeContext[] getScopeContexts() {
+		IScopeContext[] scopes = new IScopeContext[]{new InstanceScope(), new DefaultScope()};
+		final IFile file = getFile();
+		if (file != null && file.exists()) {
+			final IProject project = file.getProject();
+			if (project.exists()) {
+				final ProjectScope projectScope = new ProjectScope(project);
+				if (projectScope.getNode(PREFERENCE_NODE_QUALIFIER).getBoolean(JSPCorePreferenceNames.VALIDATION_USE_PROJECT_SETTINGS, false)) {
+					scopes = new IScopeContext[]{projectScope, new InstanceScope(), new DefaultScope()};
+				}
+			}
+		}
+		return scopes;
+	}
+
+	private IFile getFile() {
+		IFile f = null;
+		if (fDocument != null) {
+			final ITextFileBuffer buffer = FileBufferModelManager.getInstance().getBuffer(fDocument);
+			if (buffer != null) {
+				final IPath path = buffer.getLocation();
+				if (path.segmentCount() > 1) {
+					f = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+				}
+				if (f != null && f.isAccessible()) {
+					return f;
+				}
+			}
+		}
+		return null;
+	}
 }
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/JSPELTranslator.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/JSPELTranslator.java
index c995a1a..727d863 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/JSPELTranslator.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/java/jspel/JSPELTranslator.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2006 BEA Systems and others.
+ * Copyright (c) 2005, 2010 BEA Systems 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
@@ -7,6 +7,7 @@
  * 
  * Contributors:
  *     BEA Systems - initial implementation
+ *     IBM Corporation - Bug 298304 User-configurable severities for EL problems
  *     
  *******************************************************************************/
 
@@ -16,15 +17,32 @@
 import java.util.HashMap;
 import java.util.List;
 
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ProjectScope;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IScopeContext;
+import org.eclipse.core.runtime.preferences.InstanceScope;
 import org.eclipse.jface.text.Position;
 import org.eclipse.jst.jsp.core.internal.JSPCoreMessages;
+import org.eclipse.jst.jsp.core.internal.JSPCorePlugin;
+import org.eclipse.jst.jsp.core.internal.preferences.JSPCorePreferenceNames;
 import org.eclipse.jst.jsp.core.jspel.ELProblem;
 import org.eclipse.jst.jsp.core.jspel.IJSPELTranslator;
+import org.eclipse.wst.sse.core.internal.FileBufferModelManager;
 import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
 import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.validate.ValidationMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IMessage;
 
 	
 public class JSPELTranslator implements IJSPELTranslator {
+
+	private static final String PREFERENCE_NODE_QUALIFIER = JSPCorePlugin.getDefault().getBundle().getSymbolicName();
 	/**
 	 * JSP Expression Language Parser.
 	 */
@@ -51,19 +69,64 @@
 				elProblems.addAll(generatorELProblems);
 			}
 		} catch (ParseException e) {
-			Token curTok = e.currentToken;
-			int problemStartOffset;
-			int problemEndOffset;
-			Position pos = null;
-			problemStartOffset =  contentStart + curTok.beginColumn;
-			problemEndOffset = contentStart + curTok.endColumn;
-			
-			pos = new Position(problemStartOffset, problemEndOffset - problemStartOffset + 1);
-			elProblems.add(new ELProblem(pos, e.getLocalizedMessage()));
+			final int sev = getProblemSeverity(JSPCorePreferenceNames.VALIDATION_EL_SYNTAX, getScopeContexts(document));
+			if (sev != ValidationMessage.IGNORE) {
+				Token curTok = e.currentToken;
+				int problemStartOffset;
+				int problemEndOffset;
+				Position pos = null;
+				problemStartOffset =  contentStart + curTok.beginColumn;
+				problemEndOffset = contentStart + curTok.endColumn;
+				
+				pos = new Position(problemStartOffset, problemEndOffset - problemStartOffset + 1);
+				elProblems.add(new ELProblem(sev, pos, e.getLocalizedMessage()));
+			}
 		} catch (TokenMgrError te) {
-			Position pos = new Position(contentStart, contentLength);
-			elProblems.add(new ELProblem(pos, JSPCoreMessages.JSPEL_Token));
+			int sev = getProblemSeverity(JSPCorePreferenceNames.VALIDATION_EL_LEXER, getScopeContexts(document));
+			if (sev != ValidationMessage.IGNORE) {
+				Position pos = new Position(contentStart, contentLength);
+				elProblems.add(new ELProblem(sev, pos, JSPCoreMessages.JSPEL_Token));
+			}
 		}
 		return elProblems;
 	}
+	
+	/**
+	 * @param key preference key used to get the severity for a problem
+	 * @param contexts preference service contexts
+	 * @return The severity of the problem represented by the given preference key
+	 */
+	private int getProblemSeverity(String key, IScopeContext[] contexts) {
+		return Platform.getPreferencesService().getInt(PREFERENCE_NODE_QUALIFIER, key, IMessage.NORMAL_SEVERITY, contexts);
+	}
+
+	private IScopeContext[] getScopeContexts(IStructuredDocument document) {
+		IScopeContext[] scopes = new IScopeContext[]{new InstanceScope(), new DefaultScope()};
+		final IFile file = getFile(document);
+		if (file != null && file.exists()) {
+			final IProject project = file.getProject();
+			if (project.exists()) {
+				ProjectScope projectScope = new ProjectScope(project);
+				if (projectScope.getNode(PREFERENCE_NODE_QUALIFIER).getBoolean(JSPCorePreferenceNames.VALIDATION_USE_PROJECT_SETTINGS, false)) {
+					scopes = new IScopeContext[]{projectScope, new InstanceScope(), new DefaultScope()};
+				}
+			}
+		}
+		return scopes;
+	}
+
+	private IFile getFile(IStructuredDocument document) {
+		IFile f = null;
+		final ITextFileBuffer buffer = FileBufferModelManager.getInstance().getBuffer(document);
+		if (buffer != null) {
+			final IPath path = buffer.getLocation();
+			if (path.segmentCount() > 1) {
+				f = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+			}
+			if (f != null && f.isAccessible()) {
+				return f;
+			}
+		}
+		return null;
+	}
 }
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/preferences/JSPCorePreferenceInitializer.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/preferences/JSPCorePreferenceInitializer.java
index 508773b..a7712e1 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/preferences/JSPCorePreferenceInitializer.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/preferences/JSPCorePreferenceInitializer.java
@@ -60,6 +60,7 @@
 
 		node.putInt(JSPCorePreferenceNames.VALIDATION_EL_SYNTAX, ValidationMessage.ERROR);
 		node.putInt(JSPCorePreferenceNames.VALIDATION_EL_LEXER, ValidationMessage.IGNORE);
+		node.putInt(JSPCorePreferenceNames.VALIDATION_EL_FUNCTION_UNDEFINED, ValidationMessage.ERROR);
 
 		node.putInt(JSPCorePreferenceNames.VALIDATION_ACTIONS_SEVERITY_MISSING_REQUIRED_ATTRIBUTE, ValidationMessage.ERROR);
 		node.putInt(JSPCorePreferenceNames.VALIDATION_ACTIONS_SEVERITY_UNKNOWN_ATTRIBUTE, ValidationMessage.WARNING);
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/preferences/JSPCorePreferenceNames.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/preferences/JSPCorePreferenceNames.java
index 1f8f2b0..ff8af9a 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/preferences/JSPCorePreferenceNames.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/internal/preferences/JSPCorePreferenceNames.java
@@ -66,6 +66,7 @@
 	
 	public static final String VALIDATION_EL_SYNTAX  ="validation.el-general-syntax";
 	public static final String VALIDATION_EL_LEXER  ="validation.el-lexical-failure";
+	public static final String VALIDATION_EL_FUNCTION_UNDEFINED = "validation.el-function-undefined";
 
 	public static final String VALIDATION_ACTIONS_SEVERITY_MISSING_REQUIRED_ATTRIBUTE = "validation.actions-missing-required-attribute";
 	public static final String VALIDATION_ACTIONS_SEVERITY_UNKNOWN_ATTRIBUTE = "validation.actions-unknown-attribute";
diff --git a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/jspel/ELProblem.java b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/jspel/ELProblem.java
index ef95d18..2188556 100644
--- a/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/jspel/ELProblem.java
+++ b/bundles/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/jspel/ELProblem.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2006 BEA Systems and others.
+ * Copyright (c) 2005, 2010 BEA Systems 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
@@ -7,6 +7,7 @@
  * 
  * Contributors:
  *     BEA Systems - initial implementation
+ *     IBM Corporation - Bug 298304 User-configurable severities for EL problems
  *     
  *******************************************************************************/
 
@@ -14,28 +15,40 @@
 
 import org.eclipse.jface.text.Position;
 import org.eclipse.jst.jsp.core.internal.java.IJSPProblem;
+import org.eclipse.wst.sse.core.internal.validate.ValidationMessage;
 
 /**
- * All ELProblems are currently assumed to be errors.
+ * <p>Represents an EL problem in a JSP document</p>
  */
 public class ELProblem implements IJSPProblem {
 	private Position fPos;
 	private String fMessage;
 	private int fId = IJSPProblem.ELProblem;
+	private int fSeverity;
 
 	/**
 	 * @param pos should be relative to the JSP document the error is to be reported on
 	 * @param message
 	 */
 	public ELProblem(Position pos, String message)	{
-		fPos = pos;
-		fMessage = message;
+		this(pos, message, ValidationMessage.ERROR);
 	}
 
 	public ELProblem(Position pos, String message, int id)	{
+		this(pos, message, ValidationMessage.ERROR, id);
+	}
+
+	public ELProblem(int severity, Position pos, String message) {
+		fPos = pos;
+		fMessage = message;
+		fSeverity = severity;
+	}
+
+	public ELProblem(Position pos, String message, int severity, int id)	{
 		fPos = pos;
 		fMessage = message;
 		fId = id;
+		fSeverity = severity;
 	}
 	
 	public String getMessage() {
@@ -75,11 +88,11 @@
 	}
 
 	public boolean isError() {
-		return true;
+		return fSeverity == ValidationMessage.ERROR;
 	}
 
 	public boolean isWarning() {
-		return false;
+		return fSeverity == ValidationMessage.WARNING;
 	}
 
 	public void setSourceEnd(int sourceEnd) {}
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java
index 5460e8e..1a31b64 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java
@@ -164,6 +164,7 @@
 	public static String VALIDATION_HEADER_EL;
 	public static String VALIDATION_EL_SYNTAX;
 	public static String VALIDATION_EL_LEXER;
+	public static String VALIDATION_EL_FUNCTION_UNDEFINED;
 
 	public static String VALIDATION_HEADER_CUSTOM_ACTIONS;
 	public static String VALIDATION_ACTIONS_SEVERITY_MISSING_REQUIRED_ATTRIBUTE;
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties
index 8d7e070..039e6d9 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties
@@ -144,6 +144,7 @@
 VALIDATION_HEADER_EL=Expression Language
 VALIDATION_EL_SYNTAX=EL Syntax problem:
 VALIDATION_EL_LEXER=Unable to analyze EL expression due to lexical analysis error: 
+VALIDATION_EL_FUNCTION_UNDEFINED=Function is undefined:
 
 VALIDATION_HEADER_CUSTOM_ACTIONS=Custom actions
 VALIDATION_ACTIONS_SEVERITY_MISSING_REQUIRED_ATTRIBUTE=Missing required attribute:
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/preferences/ui/JSPValidationPreferencePage.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/preferences/ui/JSPValidationPreferencePage.java
index 01a27c9..24d6831 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/preferences/ui/JSPValidationPreferencePage.java
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/preferences/ui/JSPValidationPreferencePage.java
@@ -196,6 +196,7 @@
 		section = createStyleSectionWithContentComposite(composite, JSPUIMessages.VALIDATION_HEADER_EL, nColumns);
 		addComboBox(section, JSPUIMessages.VALIDATION_EL_SYNTAX, JSPCorePreferenceNames.VALIDATION_EL_SYNTAX, SEVERITIES, errorWarningIgnoreLabels, 0);
 		addComboBox(section, JSPUIMessages.VALIDATION_EL_LEXER, JSPCorePreferenceNames.VALIDATION_EL_LEXER, SEVERITIES, errorWarningIgnoreLabels, 0);
+		addComboBox(section, JSPUIMessages.VALIDATION_EL_FUNCTION_UNDEFINED, JSPCorePreferenceNames.VALIDATION_EL_FUNCTION_UNDEFINED, SEVERITIES, errorWarningIgnoreLabels, 0);
 		// end EL section
 
 		restoreSectionExpansionStates(getDialogSettings().getSection(SETTINGS_SECTION_NAME));