Author: scabanovich
Date: 2009-06-10 08:15:45 -0400 (Wed, 10 Jun 2009)
New Revision: 15849
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/handlers/CreateFaceletTaglibSupport.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
trunk/jsf/plugins/org.jboss.tools.jsf/resources/meta/facelet-taglib.meta
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFProjectTagLibs.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/JSFWebHelper.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4213
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2009-06-10 11:53:27 UTC (rev 15848)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2009-06-10 12:15:45 UTC (rev 15849)
@@ -341,8 +341,8 @@
class="org.jboss.tools.jsf.model.handlers.bean.AddManagedBeanSupport"/>
<xclass id="org.jboss.tools.jsf.model.handlers.CreateFacesConfigSupport"
class="org.jboss.tools.jsf.model.handlers.CreateFacesConfigSupport"/>
- <xclass id="org.jboss.tools.jsf.model.handlers.CreateFacesConfigSupport"
- class="org.jboss.tools.jsf.model.handlers.CreateFacesConfigSupport"/>
+ <xclass
id="org.jboss.tools.jsf.model.handlers.CreateFaceletTaglibSupport"
+ class="org.jboss.tools.jsf.model.handlers.CreateFaceletTaglibSupport"/>
<xclass id="org.jboss.tools.jsf.model.handlers.AddViewSupport"
class="org.jboss.tools.jsf.model.handlers.AddViewSupport"/>
<xclass id="org.jboss.tools.jsf.model.handlers.AddEntrySupport"
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/resources/meta/facelet-taglib.meta
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/resources/meta/facelet-taglib.meta 2009-06-10
11:53:27 UTC (rev 15848)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/resources/meta/facelet-taglib.meta 2009-06-10
12:15:45 UTC (rev 15849)
@@ -608,19 +608,16 @@
<XActionItem displayName="JSF" kind="list"
name="JSF">
<XActionItem HandlerClassName="%SpecialWizard%"
ICON="action.new.facelet.facelet-taglib"
-
PROPERTIES="entity=FileFaceletTaglib;extensions=.xml.;validator.addfile=true;support=org.jboss.tools.common.model.files.handlers.CreateFileSupport;extension=xml;entityVersion=FaceletTaglib"
+
PROPERTIES="entity=FileFaceletTaglib;extensions=.xml.;validator.addfile=true;support=org.jboss.tools.jsf.model.handlers.CreateFaceletTaglibSupport;extension=xml;entityVersion=FaceletTaglib"
displayName="Facelet Taglib" kind="action"
name="CreateFaceletTaglib">
- <EntityData EntityName="NewFileWizard">
+ <EntityData EntityName="CreateFacesConfigHelper">
<AttributeData AttributeName="folder"/>
<AttributeData AttributeName="separator"
Mandatory="no"/>
<AttributeData AttributeName="name"/>
<AttributeData AttributeName="version"
Mandatory="no"/>
+ <AttributeData AttributeName="register in web.xml"
Mandatory="no"/>
</EntityData>
</XActionItem>
- <XActionItem HandlerClassName="%WizardInvoker%"
- ICON="action.new.facelet.facelet-taglib"
-
PROPERTIES="plugin=org.jboss.tools.jsf.ui;wizard=org.jboss.tools.jsf.ui.wizard.newfile.NewFacesConfigFileWizard"
- displayName="Facelet Taglib" kind="action"
name="CreateFaceletTaglibV"/>
</XActionItem>
</XActionItem>
</XActionItem>
@@ -638,7 +635,7 @@
<XActionItem displayName="JSF" kind="list"
name="JSF">
<XActionItem HandlerClassName="%SpecialWizard%"
ICON="action.new.facelet.facelet-taglib"
-
PROPERTIES="entity=FileFaceletTaglib;extensions=.xml.;validator.addfile=true;support=org.jboss.tools.common.model.files.handlers.CreateFileSupport;extension=xml;entityVersion=FileFaceletTaglib"
+
PROPERTIES="entity=FileFaceletTaglib;extensions=.xml.;validator.addfile=true;support=org.jboss.tools.jsf.model.handlers.CreateFaceletTaglibSupport;extension=xml;entityVersion=FileFaceletTaglib"
displayName="Facelet Taglib" kind="action"
name="CreateFaceletTaglib">
<EntityData EntityName="CreateFacesConfigHelper">
<AttributeData AttributeName="folder"/>
@@ -648,10 +645,6 @@
<AttributeData AttributeName="register in web.xml"
Mandatory="no"/>
</EntityData>
</XActionItem>
- <XActionItem HandlerClassName="%WizardInvoker%"
- ICON="action.new.facelet.facelet-taglib"
-
PROPERTIES="plugin=org.jboss.tools.jsf.ui;wizard=org.jboss.tools.jsf.ui.wizard.newfile.NewFacesConfigFileWizard"
- displayName="Facelet Taglib" kind="action"
name="CreateFaceletTaglibV"/>
</XActionItem>
</XActionItem>
</XActionItem>
Added:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/handlers/CreateFaceletTaglibSupport.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/handlers/CreateFaceletTaglibSupport.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/handlers/CreateFaceletTaglibSupport.java 2009-06-10
12:15:45 UTC (rev 15849)
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jsf.model.handlers;
+
+import java.util.*;
+import org.jboss.tools.common.meta.action.impl.*;
+import org.jboss.tools.common.model.*;
+import org.jboss.tools.common.model.files.handlers.CreateFileSupport;
+import org.jboss.tools.common.model.filesystems.impl.FileAnyImpl;
+import org.jboss.tools.common.model.undo.*;
+import org.jboss.tools.jsf.model.*;
+import org.jboss.tools.jsf.web.JSFWebHelper;
+import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
+
+public class CreateFaceletTaglibSupport extends CreateFileSupport implements JSFConstants
{
+ static String REGISTER = "register in web.xml";
+
+ public void reset() {
+ super.reset();
+ initDefaultName();
+ initRegister();
+ }
+
+ void initDefaultName() {
+ XModelObject[] cs = getFaceletsTaglibs(getTarget());
+ Set<String> names = new HashSet<String>();
+ for (int i = 0; i < cs.length; i++) {
+ names.add(cs[i].getAttributeValue("name"));
+ }
+ if(cs.length == 0) {
+ setAttributeValue(0, "name", "facelets-taglib");
+ return;
+ }
+ String name = "facelets-taglib", namef = name;
+ int i = 0;
+ while(names.contains(namef)) namef = name + "-" + (++i);
+ setAttributeValue(0, "name", namef);
+ }
+
+ void initRegister() {
+ if(checkRegister(getTarget(), getAttributeValue(0, REGISTER)) != null) {
+ setAttributeValue(0, REGISTER, "no");
+ }
+ }
+
+ protected void execute() throws XModelException {
+ Properties p0 = extractStepData(0);
+ XUndoManager undo = getTarget().getModel().getUndoManager();
+ XTransactionUndo u = new XTransactionUndo("Create facelets taglib in " +
getTarget().getAttributeValue("element type")+"
"+getTarget().getPresentationString(), XTransactionUndo.ADD);
+ undo.addUndoable(u);
+ try {
+ doExecute(p0);
+ } catch (RuntimeException e) {
+ undo.rollbackTransactionInProgress();
+ throw e;
+ } finally {
+ u.commit();
+ }
+ }
+
+ private void doExecute(Properties p0) throws XModelException {
+ Properties p = extractStepData(0);
+ String path = p.getProperty("name");
+ path = revalidatePath(path);
+ XModelObject file = createFile(path);
+ if(file == null) return;
+
+ register(file.getParent(), file, p0);
+
+ open(file);
+ }
+
+ private void register(XModelObject object, XModelObject created, Properties prop) throws
XModelException {
+ boolean register = "yes".equals(getAttributeValue(0, "register in
web.xml"));
+ if(!register) return;
+ String uri = getURI(created);
+ JSFWebHelper.registerFaceletsTaglib(created.getModel(), uri);
+ }
+
+ private String getURI(XModelObject file) {
+ String result = "/" + FileAnyImpl.toFileName(file);
+ XModelObject o = file.getParent();
+ while(o != null && o.getFileType() != XModelObject.SYSTEM) {
+ result = "/" + o.getAttributeValue("name") + result;
+ o = o.getParent();
+ }
+ if(o == null || !"WEB-ROOT".equals(o.getAttributeValue("name"))) {
+ //TODO resolve to webRoot
+// result = "/WEB-INF" + result;
+ }
+ return result;
+ }
+
+ protected DefaultWizardDataValidator createValidator() {
+ return new CreateFaceletsTaglibValidator();
+ }
+
+ class CreateFaceletsTaglibValidator extends CreateFileSupport.Validator {
+ public void validate(Properties data) {
+ super.validate(data);
+ if(message != null) return;
+ message = checkRegister(getTarget(), data.getProperty("register in
web.xml"));
+ }
+ }
+
+ private String checkRegister(XModelObject object, String register) {
+ if(!"yes".equals(register)) return null;
+ XModelObject webxml = WebAppHelper.getWebApp(object.getModel());
+ if(webxml == null) return "Facelets taglib cannot be registered because web.xml is
not found.";
+ if("yes".equals(webxml.get("isIncorrect"))) return "Faces
config file cannot be registered because web.xml is incorrect.";
+ if(!webxml.isObjectEditable()) return "Facelets taglib file cannot be registered
because web.xml is read only.";
+ return null;
+ }
+
+ public static XModelObject[] getFaceletsTaglibs(XModelObject folder) {
+ XModelObject[] cs = folder.getChildren();
+ List<XModelObject> list = new ArrayList<XModelObject>();
+ for (int i = 0; i < cs.length; i++) {
+ if(cs[i].getModelEntity().getName().startsWith("FileFaceletTaglib"))
list.add(cs[i]);
+ }
+ return list.toArray(new XModelObject[0]);
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/handlers/CreateFaceletTaglibSupport.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFProjectTagLibs.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFProjectTagLibs.java 2009-06-10
11:53:27 UTC (rev 15848)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/model/pv/JSFProjectTagLibs.java 2009-06-10
12:15:45 UTC (rev 15849)
@@ -11,10 +11,10 @@
package org.jboss.tools.jsf.model.pv;
import java.util.*;
+
import org.eclipse.core.resources.IResource;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.filesystems.FileSystemsHelper;
-import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
public class JSFProjectTagLibs extends JSFProjectResourceBundles {
@@ -38,9 +38,11 @@
protected List<XModelObject> collect(Iterator<XModelObject> rs) {
List<XModelObject> list = super.collect(rs);
- XModelObject faceletTaglib = getFaceletTaglibs();
- if(faceletTaglib != null && faceletTaglib.getAttributeValue("uri") !=
null) {
- list.add(faceletTaglib);
+ List<XModelObject> faceletTaglibs = getFaceletTaglibs();
+ if(faceletTaglibs != null) for (XModelObject faceletTaglib: faceletTaglibs) {
+ if(faceletTaglib.getAttributeValue("uri") != null) {
+ list.add(faceletTaglib);
+ }
}
Iterator<XModelObject> it = list.iterator();
@@ -57,7 +59,7 @@
return list;
}
- private XModelObject getFaceletTaglibs() {
+ private List<XModelObject> getFaceletTaglibs() {
XModelObject webxml = getModel().getByPath("/web.xml");
XModelObject webRoot = FileSystemsHelper.getWebRoot(getModel());
if(webxml == null || webRoot == null) return null;
@@ -65,8 +67,15 @@
if(cp == null) return null;
String value = cp.getAttributeValue("param-value");
if(value == null || value.length() == 0) return null;
- if(value.startsWith("/")) value = value.substring(1);
- return webRoot.getChildByPath(value);
+ List<XModelObject> result = new ArrayList<XModelObject>();
+ StringTokenizer st = new StringTokenizer(value, ";,");
+ while(st.hasMoreTokens()) {
+ String path = st.nextToken();
+ if(path.startsWith("/")) path = path.substring(1);
+ XModelObject o = webRoot.getChildByPath(path);
+ if(o != null) result.add(o);
+ }
+ return result;
}
static String TLD_ENTITIES =
".FileTLD_PRO.FileTLD_1_2.FileTLD_2_0.FileTLD_2_1.";
@@ -80,6 +89,11 @@
return TLD_ENTITIES.indexOf(entity) >= 0;
}
+ public static boolean isFaceletTaglibFile(XModelObject o) {
+ String entity = "." + o.getModelEntity().getName();
+ return entity.startsWith("FileFaceletTaglib");
+ }
+
public Object getAdapter(Class adapter) {
if(adapter == IResource.class) {
XModelObject o = getModel().getByPath("FileSystems/WEB-INF");
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/JSFWebHelper.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/JSFWebHelper.java 2009-06-10
11:53:27 UTC (rev 15848)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/JSFWebHelper.java 2009-06-10
12:15:45 UTC (rev 15849)
@@ -31,6 +31,13 @@
new String[]{"/WEB-INF/faces-config.xml"}
);
+ public static ConfigFilesData FACELET_TAGLIB_DATA =
+ new ConfigFilesData(
+ "facelets.LIBRARIES",
+ new String[]{},
+ ";"
+ );
+
static {
FACES_CONFIG_DATA.usesDefaultWithoutRegistration = true;
}
@@ -59,6 +66,10 @@
unregisterConfigFile(model, path, FACES_CONFIG_DATA);
}
+ public static void registerFaceletsTaglib(XModel model, String path) throws
XModelException {
+ registerConfigFile(model, path, FACELET_TAGLIB_DATA);
+ }
+
public static XModelObject findInitParam(XModelObject webxml) {
return findInitParam(webxml, FACES_CONFIG_DATA.param);
}