Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcrogers2010-04-28 20:32:23 -0400
committercrogers2010-04-28 20:32:23 -0400
commitcf27afc27fabca8f4f9f82e62460535126c04394 (patch)
tree3c6942db135a485f53737adc3cf4f4557b313938
parent6b5f99ded11098e29045e8bf037904b9719e5c13 (diff)
downloadwebtools.jsf-cf27afc27fabca8f4f9f82e62460535126c04394.tar.gz
webtools.jsf-cf27afc27fabca8f4f9f82e62460535126c04394.tar.xz
webtools.jsf-cf27afc27fabca8f4f9f82e62460535126c04394.zip
[Bug 306452] - [JSF 2.0] Internal API Utility class to access JSF specific WebApp options. (patch contributed by Debajit)
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUpdater.java44
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUtilsForJ2EE.java72
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/WebXmlUtilsForJavaEE.java70
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/AbstractWebXmlUpdater.java33
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/WebXmlUpdaterForJ2EE.java25
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.common/src/org/eclipse/jst/jsf/common/webxml/internal/WebXmlUpdaterForJavaEE.java27
6 files changed, 270 insertions, 1 deletions
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 7ac4b8b86..e3261ead1 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 @@ public class WebXmlUpdater
/**
* @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 27676281c..6354dc8e3 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 @@ public class WebXmlUtilsForJ2EE
/**
+ * @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 59f58d0d7..6a3d59779 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 @@ public class WebXmlUtilsForJavaEE
/**
+ * @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 75460058a..b298bb7a5 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 @@ public abstract class AbstractWebXmlUpdater
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 142f3acf0..2d4ba290a 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 @@ public class WebXmlUpdaterForJ2EE extends AbstractWebXmlUpdater
@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 @@ public class WebXmlUpdaterForJ2EE extends AbstractWebXmlUpdater
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 fecb3253b..ee79863eb 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 @@ package org.eclipse.jst.jsf.common.webxml.internal;
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.Filter;
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 @@ public class WebXmlUpdaterForJavaEE extends AbstractWebXmlUpdater
}
+ @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 class WebXmlUpdaterForJavaEE extends AbstractWebXmlUpdater
public Object getWebApp()
{
return webApp;
- }}
+ }
+}

Back to the top