Author: scabanovich
Date: 2008-06-30 10:07:18 -0400 (Mon, 30 Jun 2008)
New Revision: 9016
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFConstants.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/helpers/context/AdoptJSFProjectFinisher.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/helpers/context/ImportJSFWarContext.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/pattern/PatternLoader.java
Log:
JBIDE-1970
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFConstants.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFConstants.java 2008-06-30
14:00:15 UTC (rev 9015)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/JSFConstants.java 2008-06-30
14:07:18 UTC (rev 9016)
@@ -56,5 +56,6 @@
public static final String ENT_FILEXHTML = "FileXHTML";
public static final String EMPTY_NAVIGATION_RULE_NAME = "[any]";
-
+
+ public static final String FACES_SERVLET_CLASS =
"javax.faces.webapp.FacesServlet";
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/helpers/context/AdoptJSFProjectFinisher.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/helpers/context/AdoptJSFProjectFinisher.java 2008-06-30
14:00:15 UTC (rev 9015)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/helpers/context/AdoptJSFProjectFinisher.java 2008-06-30
14:07:18 UTC (rev 9016)
@@ -17,22 +17,27 @@
import java.util.List;
import java.util.Map;
+import org.jboss.tools.common.meta.action.impl.handlers.DefaultCreateHandler;
import org.jboss.tools.common.model.XModel;
import org.jboss.tools.common.model.XModelConstants;
import org.jboss.tools.common.model.XModelException;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.filesystems.FileSystemsHelper;
+import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.jsf.model.JSFConstants;
import org.jboss.tools.jst.web.context.IImportWebProjectContext;
+import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
import org.jboss.tools.jst.web.project.WebModuleConstants;
public class AdoptJSFProjectFinisher {
protected IImportWebProjectContext context = null;
- protected XModel model = null;
- protected XModelObject web;
- protected XModelObject fss;
- protected String workspace = null;
- protected String srclocation = "";
- protected Map<String,XModelObject> filesystems = new
HashMap<String,XModelObject>();
+ protected XModel model = null;
+ protected XModelObject web;
+ protected XModelObject fss;
+ protected String workspace = null;
+ protected String srclocation = "";
+ protected Map<String,XModelObject> filesystems = new
HashMap<String,XModelObject>();
public void setContext(XModel model, IImportWebProjectContext context) {
this.context = context;
@@ -40,137 +45,160 @@
}
public void execute() throws XModelException {
- filesystems.clear();
- workspace = context.getWebInfLocation();
- fss = model.getByPath("FileSystems");
- web = model.getByPath("Web");
+ filesystems.clear();
+ workspace = context.getWebInfLocation();
+ fss = model.getByPath("FileSystems");
+ web = model.getByPath("Web");
- createBuildFileSystem();
- createWebInfFileSystem();
- createWebXMLFileSystem();
- createWebRootFileSystem();
- createSrcFileSystems();
- createClassesFileSystem();
- createLibFileSystems();
-
- String an = context.getApplicationName();
- if(an == null) an = context.getProjectName();
- fss.setAttributeValue("application name", an);
-
- fss.setModified(true);
- appendModules();
- model.save();
- }
+ createBuildFileSystem();
+ createWebInfFileSystem();
+ createWebXMLFileSystem();
+ createWebRootFileSystem();
+ createSrcFileSystems();
+ createClassesFileSystem();
+ createLibFileSystems();
+ String an = context.getApplicationName();
+ if (an == null)
+ an = context.getProjectName();
+ fss.setAttributeValue("application name", an);
+
+ fss.setModified(true);
+ appendModules();
+
+ modifyWebXML();
+
+ model.save();
+ }
+
private XModelObject getOrCreateFileSystem(String name, String location, boolean req)
{
- return getOrCreateFileSystem(name, location, null, req, false);
- }
+ return getOrCreateFileSystem(name, location, null, req, false);
+ }
- private XModelObject getOrCreateFileSystem(String name, String location, String info)
{
- return getOrCreateFileSystem(name, location, info, true, false);
- }
+ private XModelObject getOrCreateFileSystem(String name, String location, String info) {
+ return getOrCreateFileSystem(name, location, info, true, false);
+ }
- private XModelObject getOrCreateFileSystem(String name, String location, String info,
boolean req, boolean jar) {
- XModelObject fs = (req) ? null : (XModelObject)filesystems.get(location);
- if(fs != null) return fs;
- String entity = (!jar) ? "FileSystemFolder" :
"FileSystemJar";
- fs = model.createModelObject(entity, null);
- fs.setAttributeValue("name", name);
- fs.setAttributeValue("location", location);
- if(info != null) fs.setAttributeValue("info", info);
- fss.addChild(fs);
- filesystems.put(location, fs);
- return fs;
- }
+ private XModelObject getOrCreateFileSystem(String name, String location,
+ String info, boolean req, boolean jar) {
+ XModelObject fs = (req) ? null : (XModelObject) filesystems.get(location);
+ if (fs != null)
+ return fs;
+ String entity = (!jar) ? "FileSystemFolder" : "FileSystemJar";
+ fs = model.createModelObject(entity, null);
+ fs.setAttributeValue("name", name);
+ fs.setAttributeValue("location", location);
+ if (info != null)
+ fs.setAttributeValue("info", info);
+ fss.addChild(fs);
+ filesystems.put(location, fs);
+ return fs;
+ }
private void createWebInfFileSystem() {
- getOrCreateFileSystem("WEB-INF", XModelConstants.WORKSPACE_REF, true);
- }
+ getOrCreateFileSystem("WEB-INF", XModelConstants.WORKSPACE_REF, true);
+ }
private void createWebXMLFileSystem() {
File webxml = new File(context.getWebXmlLocation());
- String webxmlfolder = webxml.getParent();
- String relative = getRelativePath(workspace, webxmlfolder);
- if(relative == null || relative.startsWith("/..")) {
- String loc = (relative == null) ? webxmlfolder :
XModelConstants.WORKSPACE_REF + relative;
- getOrCreateFileSystem("web-xml", loc, true);
- web.setAttributeValue("model path", "/" +
webxml.getName());
- } else {
- web.setAttributeValue("model path", relative + "/" +
webxml.getName());
- }
- }
+ String webxmlfolder = webxml.getParent();
+ String relative = getRelativePath(workspace, webxmlfolder);
+ if (relative == null || relative.startsWith("/..")) {
+ String loc = (relative == null) ? webxmlfolder
+ : XModelConstants.WORKSPACE_REF + relative;
+ getOrCreateFileSystem("web-xml", loc, true);
+ web.setAttributeValue("model path", "/" + webxml.getName());
+ } else {
+ web.setAttributeValue("model path", relative + "/"
+ + webxml.getName());
+ }
+ }
private XModelObject getDefaultModule() {
- XModelObject[] ms = context.getModules();
- for (int i = 0; i < ms.length; i++)
- if(ms[i].getAttributeValue("name").length() == 0) return ms[i];
- return null;
- }
+ XModelObject[] ms = context.getModules();
+ for (int i = 0; i < ms.length; i++) {
+ if (ms[i].getAttributeValue("name").length() == 0)
+ return ms[i];
+ }
+ return null;
+ }
private void createWebRootFileSystem() {
- XModelObject m = getDefaultModule();
- if(m == null) return;
- String loc = getFileSystemLocation(workspace,
m.getAttributeValue("root"));
- m.setAttributeValue(WebModuleConstants.ATTR_ROOT_FS, "WEB-ROOT");
- getOrCreateFileSystem("WEB-ROOT", loc, "Content-Type=Web");
- }
+ XModelObject m = getDefaultModule();
+ if (m == null)
+ return;
+ String loc = getFileSystemLocation(workspace, m
+ .getAttributeValue("root"));
+ m.setAttributeValue(WebModuleConstants.ATTR_ROOT_FS, "WEB-ROOT");
+ getOrCreateFileSystem("WEB-ROOT", loc, "Content-Type=Web");
+ }
- private void createSrcFileSystems() {
- createWebRootSrcFileSystem();
- }
+ private void createSrcFileSystems() {
+ createWebRootSrcFileSystem();
+ }
private void createWebRootSrcFileSystem() {
- XModelObject m = getDefaultModule();
- String[] srcs = context.getExistingSources();
- List<String> l = new ArrayList<String>();
- if(srcs != null) for (int i = 0; i < srcs.length; i++) l.add(srcs[i]);
+ XModelObject m = getDefaultModule();
+ String[] srcs = context.getExistingSources();
+ List<String> l = new ArrayList<String>();
+ if (srcs != null)
+ for (int i = 0; i < srcs.length; i++)
+ l.add(srcs[i]);
String s = m.getAttributeValue("java src");
- if(!l.contains(s)) l.add(s);
- srcs = l.toArray(new String[0]);
- String srcAttr = "";
- int j = 0;
- for (int i = 0; i < srcs.length; i++) {
+ if (!l.contains(s))
+ l.add(s);
+ srcs = l.toArray(new String[0]);
+ String srcAttr = "";
+ int j = 0;
+ for (int i = 0; i < srcs.length; i++) {
srclocation = srcs[i];
- if(srclocation.length() == 0) continue;
+ if (srclocation.length() == 0)
+ continue;
String loc = getFileSystemLocation(workspace, srclocation);
++j;
- String fsn = (j == 1) ? "src" : "src" + j;
+ String fsn = (j == 1) ? "src" : "src" + j;
getOrCreateFileSystem(fsn, loc, false);
- if(j > 1) srcAttr += ",";
+ if (j > 1)
+ srcAttr += ",";
srcAttr += fsn;
- }
- m.setAttributeValue("src file system", srcAttr);
- }
+ }
+ m.setAttributeValue("src file system", srcAttr);
+ }
private void createLibFileSystems() {
String lib = context.getLibLocation();
- if(lib == null || lib.length() == 0) return;
- File f = new File(lib);
- if(!f.isDirectory()) return;
- String loc = getFileSystemLocation(workspace, lib);
+ if (lib == null || lib.length() == 0)
+ return;
+ File f = new File(lib);
+ if (!f.isDirectory())
+ return;
+ String loc = getFileSystemLocation(workspace, lib);
getOrCreateFileSystem("lib", loc, true);
- File[] jars = f.listFiles(new FileFilter() {
- public boolean accept(File file) {
- if (!file.isFile()) return false;
- String name = file.getName().toLowerCase();
- return name.endsWith(".jar") ||
name.endsWith(".zip");
- }
- });
- if(jars != null) for (int i = 0; i < jars.length; i++) {
- String n = jars[i].getName();
- getOrCreateFileSystem("lib-" + n, loc + "/" + n,
"hidden=yes", true, true);
- }
- }
+ File[] jars = f.listFiles(new FileFilter() {
+ public boolean accept(File file) {
+ if (!file.isFile())
+ return false;
+ String name = file.getName().toLowerCase();
+ return name.endsWith(".jar") || name.endsWith(".zip");
+ }
+ });
+ if (jars != null)
+ for (int i = 0; i < jars.length; i++) {
+ String n = jars[i].getName();
+ getOrCreateFileSystem("lib-" + n, loc + "/" + n,
"hidden=yes",
+ true, true);
+ }
+ }
- private void createClassesFileSystem() {
+ private void createClassesFileSystem() {
String classes = context.getClassesLocation();
- if(classes == null || classes.length() == 0) return;
- if(!new File(classes).isDirectory()) return;
- String loc = getFileSystemLocation(workspace, classes);
- getOrCreateFileSystem("classes", loc, false);
- }
+ if(classes == null || classes.length() == 0) return;
+ if(!new File(classes).isDirectory()) return;
+ String loc = getFileSystemLocation(workspace, classes);
+ getOrCreateFileSystem("classes", loc, false);
+ }
- private void createBuildFileSystem() {
+ private void createBuildFileSystem() {
String build = context.getBuildXmlLocation();
if(build == null || build.length() == 0) return;
File f = new File(build);
@@ -178,28 +206,54 @@
f = f.getParentFile();
build = f.getAbsolutePath();
}
- if(!new File(build).isDirectory()) return;
- String loc = getFileSystemLocation(workspace, build);
- getOrCreateFileSystem("build", loc, false);
- }
+ if(!new File(build).isDirectory()) return;
+ String loc = getFileSystemLocation(workspace, build);
+ getOrCreateFileSystem("build", loc, false);
+ }
protected void appendModules() {
- XModelObject[] ms = web.getChildren("WebJSFModule");
- for (int i = 0; i < ms.length; i++) ms[i].removeFromParent();
- ms = context.getModules();
- for (int i = 0; i < ms.length; i++) web.addChild(ms[i]);
- web.setModified(true);
- }
+ XModelObject[] ms = web.getChildren("WebJSFModule");
+ for (int i = 0; i < ms.length; i++) ms[i].removeFromParent();
+ ms = context.getModules();
+ for (int i = 0; i < ms.length; i++) web.addChild(ms[i]);
+ web.setModified(true);
+ }
public static String getRelativePath(String rootpath, String path) {
- return FileUtil.getRelativePath(rootpath, path);
- }
+ return FileUtil.getRelativePath(rootpath, path);
+ }
- public static String getFileSystemLocation(String rootpath, String path) {
- path = path.replace('\\', '/');
- String relative = getRelativePath(rootpath, path);
- return (relative == null) ? path : XModelConstants.WORKSPACE_REF + relative;
- }
+ public static String getFileSystemLocation(String rootpath, String path) {
+ path = path.replace('\\', '/');
+ String relative = getRelativePath(rootpath, path);
+ return (relative == null) ? path : XModelConstants.WORKSPACE_REF + relative;
+ }
+ void modifyWebXML() throws XModelException {
+ XModelObject webxml = WebAppHelper.getWebApp(model);
+ XModelObject servlet = WebAppHelper.findServlet(webxml,
+ JSFConstants.FACES_SERVLET_CLASS, "Faces Config");
+ if (servlet == null) {
+ servlet = WebAppHelper.findOrCreateServlet(webxml,
+ JSFConstants.FACES_SERVLET_CLASS, "Faces Config", -1);
+ }
+ String servletName = servlet.getAttributeValue("servlet-name");
+ XModelObject mapping = WebAppHelper.findServletMapping(webxml,
+ servletName);
+ if (mapping == null) {
+ mapping = WebAppHelper.findOrCreateServletMapping(webxml, servletName);
+ }
+
+ XModelObject facesConfig = model.getByPath("/faces-config.xml");
+ if (facesConfig == null) {
+ XModelObject webinf = FileSystemsHelper.getWebInf(model);
+ if (webinf != null) {
+ facesConfig = XModelObjectLoaderUtil.createValidObject(model,
JSFConstants.ENT_FACESCONFIG_12);
+ DefaultCreateHandler.addCreatedObject(webinf, facesConfig, -1);
+ }
+ }
+
+ }
+
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/helpers/context/ImportJSFWarContext.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/helpers/context/ImportJSFWarContext.java 2008-06-30
14:00:15 UTC (rev 9015)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/helpers/context/ImportJSFWarContext.java 2008-06-30
14:07:18 UTC (rev 9016)
@@ -12,6 +12,7 @@
import org.jboss.tools.common.model.XModelException;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.jsf.model.JSFConstants;
import org.jboss.tools.jsf.project.JSFNature;
import org.jboss.tools.jsf.web.JSFWebHelper;
import org.jboss.tools.jst.web.context.AdoptWebProjectContext;
@@ -30,7 +31,7 @@
protected void loadWebXML(String body, String location) throws XModelException {
super.loadWebXML(body, location);
- if(WebAppHelper.findServlet(webxml, "javax.faces.webapp.FacesServlet", null)
== null) {
+ if(WebAppHelper.findServlet(webxml, JSFConstants.FACES_SERVLET_CLASS, null) == null) {
String webXMLErrorMessage = "No JSF support found in the project.";
throw new XModelException(webXMLErrorMessage);
}
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/pattern/PatternLoader.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/pattern/PatternLoader.java 2008-06-30
14:00:15 UTC (rev 9015)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/pattern/PatternLoader.java 2008-06-30
14:07:18 UTC (rev 9016)
@@ -13,6 +13,7 @@
import java.util.ArrayList;
import org.jboss.tools.common.model.*;
+import org.jboss.tools.jsf.model.JSFConstants;
import org.jboss.tools.jst.web.browser.wtp.RunOnServerContext;
import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
@@ -65,7 +66,7 @@
}
String getFacesServletName(XModelObject webxml) {
- XModelObject s = WebAppHelper.findServlet(webxml,
"javax.faces.webapp.FacesServlet", null);
+ XModelObject s = WebAppHelper.findServlet(webxml, JSFConstants.FACES_SERVLET_CLASS,
null);
return (s != null) ? s.getAttributeValue("servlet-name") :
"FacesServlet";
}