[Bug 306452] - [JSF 2.0] Internal API Utility class to access JSF specific WebApp options. (patch contributed by Debajit)
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUpdater.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUpdater.java
index 7ac4b8b..e3261ea 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUpdater.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUpdater.java
@@ -13,6 +13,8 @@
 package org.eclipse.jst.jsf.common.webxml;
 
 
+import java.util.List;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jst.j2ee.model.IModelProvider;
@@ -169,6 +171,48 @@
 
     /**
      * @param paramName
+     *            Name of context param
+     * @return Value of given context param.
+     */
+    public String getContextParamValue (final String paramName)
+    {
+        return updater.getContextParamValue(paramName);
+    }
+
+
+    /**
+     * @param paramName
+     *            Name of context param
+     * @param valuesDelimiterRegex
+     *            Delimiter string for values
+     * @return Values of given context param as a list. This is useful when the
+     *         multiple values are demarcated by a delimiter string.
+     * 
+     */
+    public List<String> getContextParamValuesAsList (final String paramName,
+                                                     final String valuesDelimiterRegex)
+    {
+        return updater.getContextParamValuesAsList(paramName, valuesDelimiterRegex);
+    }
+
+
+    /**
+     * Sets the value of the given context param name to the given value. If
+     * paramName is not found, a new context-param is created with the given
+     * paramName and paramValue.
+     * 
+     * @param paramName
+     * @param paramValue
+     */
+    public void setContextParamValue (final String paramName,
+                                      final String paramValue)
+    {
+        updater.setContextParamValue(paramName, paramValue);
+    }
+
+
+    /**
+     * @param paramName
      * @param paramValue
      * @param description
      */
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUtilsForJ2EE.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUtilsForJ2EE.java
index 2767628..6354dc8 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUtilsForJ2EE.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUtilsForJ2EE.java
@@ -11,6 +11,7 @@
 package org.eclipse.jst.jsf.common.webxml;
 
 
+import java.util.Arrays;
 import java.util.List;
 
 import org.eclipse.jst.j2ee.common.CommonFactory;
@@ -497,6 +498,77 @@
 
 
     /**
+     * @param webApp
+     * @param paramName
+     * @return the param value or null if not found
+     */
+    public static String getContextParamValue (final WebApp webApp,
+                                               final String paramName)
+    {
+        for (final Object param : webApp.getContextParams())
+        {
+            final ParamValue contextParam = (ParamValue) param;
+            if (contextParam.getName().equals(paramName))
+            {
+                return contextParam.getValue();
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * @param webApp
+     * @param paramName Name of context param
+     * @param valuesDelimiterRegex
+     * @return Values of the given context param as a list
+     */
+    public static List<String> getContextParamValuesAsList (final WebApp webApp,
+                                                            final String paramName,
+                                                            final String valuesDelimiterRegex)
+    {
+        final String valuesString = getContextParamValue(webApp, paramName);
+        return Arrays.asList(valuesString.split(valuesDelimiterRegex));
+    }
+
+
+    /**
+     * Updates the value of a context param if it exists. Otherwise, adds this
+     * as a new context param.
+     * 
+     * @param webApp
+     * @param paramName
+     * @param paramValue
+     */
+    public static void setContextParamValue (final WebApp webApp,
+                                             final String paramName,
+                                             final String paramValue)
+    {
+        ParamValue contextParam = null;
+
+        for (final Object p : webApp.getContextParams())
+        {
+            final ParamValue param = (ParamValue) p;
+            if (param.getName().equals(paramName))
+            {
+                contextParam = param;
+                break;
+            }
+        }
+
+        if (contextParam == null)
+        {
+            webApp.getContextParams().add(createContextParam(paramName, paramValue, null));
+        }
+        else
+        {
+            contextParam.setValue(paramValue);
+        }
+    }
+
+
+    /**
      * @param webapp
      * @param listenerClass
      */
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUtilsForJavaEE.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUtilsForJavaEE.java
index 59f58d0..6a3d597 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUtilsForJavaEE.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUtilsForJavaEE.java
@@ -10,6 +10,7 @@
 
 package org.eclipse.jst.jsf.common.webxml;
 
+import java.util.Arrays;
 import java.util.List;
 
 import org.eclipse.jst.javaee.core.Description;
@@ -482,6 +483,75 @@
 
 
     /**
+     * @param webApp
+     * @param paramName Name of context param
+     * @return Value of the given context param 
+     */
+    public static String getContextParamValue (final WebApp webApp,
+                                               final String paramName)
+    {
+        for (final Object param : webApp.getContextParams())
+        {
+            final ParamValue contextParam = (ParamValue) param;
+            if (contextParam.getParamName().equals(paramName))
+                return contextParam.getParamValue();
+        }
+
+        return null;
+    }
+
+
+    /**
+     * @param webApp
+     * @param paramName Name of context param
+     * @param valuesDelimiterRegex
+     * @return Values of the given context param as a list
+     */
+    public static List<String> getContextParamValuesAsList (final WebApp webApp,
+                                                            final String paramName,
+                                                            final String valuesDelimiterRegex)
+    {
+        final String valueString = getContextParamValue(webApp, paramName);
+        return Arrays.asList(valueString.split(valuesDelimiterRegex));
+    }
+
+
+    /**
+     * Updates the value of a context param if it exists. Otherwise, adds this
+     * as a new context param.
+     * 
+     * @param webApp
+     * @param paramName
+     * @param paramValue
+     */
+    public static void setContextParamValue (final WebApp webApp,
+                                             final String paramName,
+                                             final String paramValue)
+    {
+        ParamValue contextParam = null;
+
+        for (final Object p : webApp.getContextParams())
+        {
+            final ParamValue param = (ParamValue) p;
+            if (param.getParamName().equals(paramName))
+            {
+                contextParam = param;
+                break;
+            }
+        }
+
+        if (contextParam == null)
+        {
+            webApp.getContextParams().add(createContextParam(paramName, paramValue, null));
+        }
+        else
+        {
+            contextParam.setParamValue(paramValue);
+        }
+    }
+    
+
+    /**
      * @param webapp
      * @param listenerClass
      */
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/AbstractWebXmlUpdater.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/AbstractWebXmlUpdater.java
index 7546005..b298bb7 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/AbstractWebXmlUpdater.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/AbstractWebXmlUpdater.java
@@ -13,6 +13,8 @@
 package org.eclipse.jst.jsf.common.webxml.internal;
 
 
+import java.util.List;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jst.j2ee.model.IModelProvider;
@@ -117,6 +119,37 @@
                                            final String filterClass,
                                            final String servletName);
 
+    /**
+     * @param paramName
+     *            Name of context param
+     * @return Value of given context param.
+     */
+    public abstract String getContextParamValue (final String paramName);
+
+
+    /**
+     * @param paramName
+     *            Name of context param
+     * @param valuesDelimiterRegex
+     *            Delimiter string for values
+     * @return Values of given context param as a list. This is useful when the
+     *         multiple values are demarcated by a delimiter string.
+     */
+    public abstract List<String> getContextParamValuesAsList (final String paramName,
+                                                              final String valuesDelimiterRegex);
+
+
+    /**
+     * Sets the value of the given context param name to the given value. If
+     * paramName is not found, a new context-param is created with the given
+     * paramName and paramValue.
+     *
+     * @param paramName
+     * @param paramValue
+     */
+    public abstract void setContextParamValue (final String paramName,
+                                               final String paramValue);
+
 
     /**
      * @param paramName
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/WebXmlUpdaterForJ2EE.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/WebXmlUpdaterForJ2EE.java
index 142f3ac..2d4ba29 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/WebXmlUpdaterForJ2EE.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/WebXmlUpdaterForJ2EE.java
@@ -12,6 +12,8 @@
 
 package org.eclipse.jst.jsf.common.webxml.internal;
 
+import java.util.List;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jst.j2ee.model.IModelProvider;
@@ -113,6 +115,28 @@
 
 
     @Override
+    public String getContextParamValue (final String paramName)
+    {
+        return WebXmlUtilsForJ2EE.getContextParamValue(webApp, paramName);
+    }
+
+
+    @Override
+    public List<String> getContextParamValuesAsList(String paramName, String valuesDelimiterRegex)
+    {
+        return WebXmlUtilsForJ2EE.getContextParamValuesAsList(webApp, paramName, valuesDelimiterRegex);
+    }
+
+
+    @Override
+    public void setContextParamValue(String paramName, String paramValue)
+    {
+        WebXmlUtilsForJ2EE.setContextParamValue(webApp, paramName, paramValue);
+    }
+
+
+    @Override
+    
     public void addContextParam (final String paramName,
                                  final String paramValue,
                                  final String description)
@@ -134,3 +158,4 @@
         return webApp;
     }
 }
+
diff --git a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/WebXmlUpdaterForJavaEE.java b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/WebXmlUpdaterForJavaEE.java
index fecb325..ee79863 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/WebXmlUpdaterForJavaEE.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/WebXmlUpdaterForJavaEE.java
@@ -15,6 +15,8 @@
 import static org.eclipse.jst.jsf.common.webxml.WebXmlUtilsForJavaEE.findFilter;
 import static org.eclipse.jst.jsf.common.webxml.WebXmlUtilsForJavaEE.findServlet;
 
+import java.util.List;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jst.j2ee.model.IModelProvider;
@@ -22,6 +24,7 @@
 import org.eclipse.jst.javaee.web.Servlet;
 import org.eclipse.jst.javaee.web.WebApp;
 import org.eclipse.jst.jsf.common.webxml.WebXmlUtils;
+import org.eclipse.jst.jsf.common.webxml.WebXmlUtilsForJavaEE;
 import org.eclipse.jst.jsf.common.webxml.internal.operations.ContextParamAdderForJavaEE;
 import org.eclipse.jst.jsf.common.webxml.internal.operations.FilterAdderForJavaEE;
 import org.eclipse.jst.jsf.common.webxml.internal.operations.FilterMapperAdderForJavaEE;
@@ -114,6 +117,27 @@
     }
 
 
+    @Override
+    public String getContextParamValue (final String paramName)
+    {
+        return WebXmlUtilsForJavaEE.getContextParamValue(webApp, paramName);
+    }
+
+
+    @Override
+    public List<String> getContextParamValuesAsList (final String paramName,
+                                                    final String valuesDelimiterRegex)
+    {
+        return WebXmlUtilsForJavaEE.getContextParamValuesAsList(webApp, paramName, valuesDelimiterRegex);
+    }
+
+    
+    @Override
+    public void setContextParamValue(String paramName, String paramValue)
+    {
+        WebXmlUtilsForJavaEE.setContextParamValue(webApp, paramName, paramValue);
+    }
+
 
     @Override
     public void addContextParam (final String paramName,
@@ -135,4 +159,5 @@
     public Object getWebApp()
     {
         return webApp;
-    }}
+    }
+}