Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcbateman2010-03-08 18:37:48 +0000
committercbateman2010-03-08 18:37:48 +0000
commit27e71d9e9580d525bc160f0c86482d5dc4891400 (patch)
tree4d0889142356da2ed75f381c9e92e3b3e481a4d0
parent799a62996de3e42bbbb63ec5138ec3cfa280fdb4 (diff)
downloadwebtools.jsf-27e71d9e9580d525bc160f0c86482d5dc4891400.tar.gz
webtools.jsf-27e71d9e9580d525bc160f0c86482d5dc4891400.tar.xz
webtools.jsf-27e71d9e9580d525bc160f0c86482d5dc4891400.zip
Complete refactoring and JUnit test coverage of the JSFUtils family of utility classes.
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF1
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/IJSFFacetInstallDataModelProperties.java6
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils.java2
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils11.java76
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils12.java22
-rw-r--r--jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils20.java25
6 files changed, 76 insertions, 56 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF b/jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF
index a222c0275..5809de985 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/META-INF/MANIFEST.MF
@@ -44,6 +44,7 @@ Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.jst.jsf.core,
org.eclipse.jst.jsf.core.internal;x-friends:="org.eclipse.jst.jsf.core.tests,org.eclipse.jst.jsf.ui,org.eclipse.jst.jsf.ui.tests",
org.eclipse.jst.jsf.core.internal.contentassist.el;x-friends:="org.eclipse.jst.jsf.contentassist.tests",
+ org.eclipse.jst.jsf.core.internal.contenttype;x-internal:=true,
org.eclipse.jst.jsf.core.internal.jem;x-internal:=true,
org.eclipse.jst.jsf.core.internal.jsflibraryconfig;x-friends:="org.eclipse.jst.jsf.core.tests,org.eclipse.jst.jsf.ui.tests,org.eclipse.jst.pagedesigner.tests",
org.eclipse.jst.jsf.core.internal.jsflibraryregistry;
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/IJSFFacetInstallDataModelProperties.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/IJSFFacetInstallDataModelProperties.java
index 3f5004f6b..da030b789 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/IJSFFacetInstallDataModelProperties.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/IJSFFacetInstallDataModelProperties.java
@@ -21,7 +21,8 @@ public interface IJSFFacetInstallDataModelProperties extends
IFacetInstallDataModelProperties {
/**
- * TODO:
+ * Refers to the path where the faces config file will be created.
+ * Expects a string that can be interpreted as a web root relative path.
*/
public static final String CONFIG_PATH = "IJSFFacetInstallDataModelProperties.CONFIG_PATH"; //$NON-NLS-1$
@@ -36,7 +37,8 @@ public interface IJSFFacetInstallDataModelProperties extends
public static final String SERVLET_CLASSNAME = "IJSFFacetInstallDataModelProperties.SERVLET_CLASSNAME"; //$NON-NLS-1$
/**
- * TODO:
+ * Refers to configuration information about servlet url patterns to add on install
+ * The model value must be a String[].
*/
public static final String SERVLET_URL_PATTERNS = "IJSFFacetInstallDataModelProperties.SERVLET_URL_PATTERNS"; //$NON-NLS-1$
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils.java
index 97c74a24f..22c3f72dc 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils.java
@@ -192,7 +192,7 @@ public abstract class JSFUtils {
/**
* @param pw
*/
- protected abstract void doVersionSpecificConfigFile(final PrintWriter pw);
+ public abstract void doVersionSpecificConfigFile(final PrintWriter pw);
/**
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils11.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils11.java
index 9de1ec8d0..7ba1a5878 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils11.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils11.java
@@ -90,7 +90,7 @@ import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
* path
*/
@Override
- protected void doVersionSpecificConfigFile(final PrintWriter pw)
+ public void doVersionSpecificConfigFile(final PrintWriter pw)
{
final String QUOTE = new String(new char[]
{ '"' });
@@ -209,9 +209,12 @@ import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
List mappings = webApp.getServletMappings();
String servletName = servlet.getServletName();
- if (servletName != null) {
- for (int i=mappings.size()-1;i>=0;--i){
- ServletMapping mapping = (ServletMapping)mappings.get(i);
+ if (servletName != null)
+ {
+ final Iterator it = mappings.iterator();
+ while(it.hasNext())
+ {
+ ServletMapping mapping = (ServletMapping) it.next();
if (mapping != null &&
mapping.getServlet() != null &&
mapping.getServlet().getServletName() != null &&
@@ -344,16 +347,37 @@ import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
private String getDefaultSuffix(final WebApp webApp)
{
String defaultSuffix = getDefaultDefaultSuffix();
- for (Iterator it = webApp.getContexts().iterator(); it.hasNext();)
+ if ("2.3".equals(webApp.getVersion())) //$NON-NLS-1$
+ {
+ for (Iterator it = webApp.getContexts().iterator(); it.hasNext();)
+ {
+ ContextParam cp = (ContextParam) it.next();
+ if (cp != null)
+ {
+ final String paramName = cp.getParamName();
+ final String suffix = calculateSuffix(paramName, cp
+ .getParamValue());
+ if (suffix != null)
+ {
+ return suffix;
+ }
+ }
+ }
+ }
+ else if ("2.4".equals(webApp.getVersion())) //$NON-NLS-1$
{
- ContextParam cp = (ContextParam) it.next();
- if (cp != null)
+ for (Iterator it = webApp.getContextParams().iterator(); it.hasNext();)
{
- final String paramName = cp.getParamName();
- final String suffix = calculateSuffix(paramName, cp.getParamValue());
- if (suffix != null)
+ ParamValue cp = (ParamValue) it.next();
+ if (cp != null)
{
- return suffix;
+ final String paramName = cp.getName();
+ final String suffix = calculateSuffix(paramName, cp
+ .getValue());
+ if (suffix != null)
+ {
+ return suffix;
+ }
}
}
}
@@ -463,14 +487,32 @@ import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
}
private void removeJSFContextParams(final org.eclipse.jst.j2ee.webapplication.WebApp webApp, final org.eclipse.jst.j2ee.webapplication.Servlet servlet) {
- Iterator it = webApp.getContextParams().iterator();
- while (it.hasNext()) {
- org.eclipse.jst.j2ee.common.ParamValue cp = (org.eclipse.jst.j2ee.common.ParamValue) it.next();
- if (cp.getName().equals(JSFUtils.JSF_CONFIG_CONTEXT_PARAM)) {
- webApp.getContextParams().remove(cp);
- break;
+ if ("2.3".equals(webApp.getVersion())) //$NON-NLS-1$
+ {
+ Iterator it = webApp.getContexts().iterator();
+ while (it.hasNext())
+ {
+ final ContextParam cp = (ContextParam) it.next();
+ if (JSFUtils.JSF_CONFIG_CONTEXT_PARAM.equals(cp.getParamName()))
+ {
+ webApp.getContexts().remove(cp);
+ break;
+ }
+ }
+ }
+ else if ("2.4".equals(webApp.getVersion())) //$NON-NLS-1$
+ {
+ Iterator it = webApp.getContextParams().iterator();
+ while (it.hasNext())
+ {
+ ParamValue cp = (ParamValue) it.next();
+ if (cp.getName().equals(JSFUtils.JSF_CONFIG_CONTEXT_PARAM)) {
+ webApp.getContextParams().remove(cp);
+ break;
+ }
}
}
+ // otherwise do nothing
}
private void removeJSFServlet(final org.eclipse.jst.j2ee.webapplication.WebApp webApp, final org.eclipse.jst.j2ee.webapplication.Servlet servlet) {
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils12.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils12.java
index e8e804963..811a0eb87 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils12.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils12.java
@@ -87,14 +87,12 @@ import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
return null;
}
- /**
- * Creates a stubbed JSF v1.2 configuration file for specified JSF version and path
- */
- @Override
- public void doVersionSpecificConfigFile(final PrintWriter pw)
+ @Override
+ public void doVersionSpecificConfigFile(PrintWriter pw)
{
final String QUOTE = new String(new char[]
{ '"' });
+ final String schemaVersionString = getVersion().toString().replaceAll("\\.", "_"); //$NON-NLS-1$//$NON-NLS-2$
pw.write("<?xml version=" + QUOTE + "1.0" + QUOTE + " encoding=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ QUOTE + "UTF-8" + QUOTE + "?>\n\n"); //$NON-NLS-1$ //$NON-NLS-2$
pw.write("<faces-config\n"); //$NON-NLS-1$
@@ -106,9 +104,9 @@ import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
pw.write(" " //$NON-NLS-1$
+ "xsi:schemaLocation=" //$NON-NLS-1$
+ QUOTE
- + "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd" //$NON-NLS-1$
+ + String.format("http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_%s.xsd", schemaVersionString) //$NON-NLS-1$
+ QUOTE + "\n"); //$NON-NLS-1$
- pw.write(" " + "version=" + QUOTE + "1.2" + QUOTE + ">\n\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ pw.write(" " + "version=" + QUOTE + getVersion().toString() + QUOTE + ">\n\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
pw.write("</faces-config>\n"); //$NON-NLS-1$
}
@@ -264,7 +262,9 @@ import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
ParamValue foundCP = null;
ParamValue cp = null;
boolean found = false;
- if (!config.getStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH).equals(JSF_DEFAULT_CONFIG_PATH)) {
+ String stringProperty = config.getStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH);
+ if (stringProperty != null &&
+ !stringProperty.equals(JSF_DEFAULT_CONFIG_PATH)) {
// check to see if present
Iterator it = webApp.getContextParams().iterator();
while (it.hasNext()) {
@@ -279,13 +279,13 @@ import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
if (!found) {
ParamValue pv = JavaeeFactory.eINSTANCE.createParamValue();
pv.setParamName(JSF_CONFIG_CONTEXT_PARAM);
- pv.setParamValue(config.getStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH));
+ pv.setParamValue(stringProperty);
webApp.getContextParams().add(pv);
} else {
cp = foundCP;
- if (cp.getParamValue().indexOf(config.getStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH)) < 0) {
+ if (cp.getParamValue().indexOf(stringProperty) < 0) {
String curVal = cp.getParamValue();
- String val = config.getStringProperty(IJSFFacetInstallDataModelProperties.CONFIG_PATH);
+ String val = stringProperty;
if (curVal != null && !"".equals(curVal.trim())) { //$NON-NLS-1$
val = curVal + ",\n" + val; //$NON-NLS-1$
}
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils20.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils20.java
index 332c14d40..28583ae1e 100644
--- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils20.java
+++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils20.java
@@ -1,7 +1,5 @@
package org.eclipse.jst.jsf.core.internal.project.facet;
-import java.io.PrintWriter;
-
import org.eclipse.jst.j2ee.model.IModelProvider;
import org.eclipse.jst.jsf.core.JSFVersion;
@@ -28,27 +26,4 @@ import org.eclipse.jst.jsf.core.JSFVersion;
{
return DEFAULT_DEFAULT_MAPPING_SUFFIX;
}
-
- @Override
- public void doVersionSpecificConfigFile(PrintWriter pw)
- {
- final String QUOTE = new String(new char[]
- { '"' });
- pw.write("<?xml version=" + QUOTE + "1.0" + QUOTE + " encoding=" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + QUOTE + "UTF-8" + QUOTE + "?>\n\n"); //$NON-NLS-1$ //$NON-NLS-2$
- pw.write("<faces-config\n"); //$NON-NLS-1$
- pw.write(" " + "xmlns=" + QUOTE //$NON-NLS-1$ //$NON-NLS-2$
- + "http://java.sun.com/xml/ns/javaee" + QUOTE + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
- pw.write(" " + "xmlns:xsi=" + QUOTE //$NON-NLS-1$ //$NON-NLS-2$
- + "http://www.w3.org/2001/XMLSchema-instance" + QUOTE //$NON-NLS-1$
- + "\n"); //$NON-NLS-1$
- pw.write(" " //$NON-NLS-1$
- + "xsi:schemaLocation=" //$NON-NLS-1$
- + QUOTE
- + "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" //$NON-NLS-1$
- + QUOTE + "\n"); //$NON-NLS-1$
- pw.write(" " + "version=" + QUOTE + "2.0" + QUOTE + ">\n\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- pw.write("</faces-config>\n"); //$NON-NLS-1$
- }
-
}

Back to the top