Author: dmaliarevich
Date: 2008-11-11 11:36:39 -0500 (Tue, 11 Nov 2008)
New Revision: 11682
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/META-INF/MANIFEST.MF
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfFacet.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2938, attributes were added, facet processing was
added.
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/META-INF/MANIFEST.MF
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/META-INF/MANIFEST.MF 2008-11-11 16:36:29
UTC (rev 11681)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/META-INF/MANIFEST.MF 2008-11-11 16:36:39
UTC (rev 11682)
@@ -18,4 +18,5 @@
Eclipse-LazyStart: true
Export-Package: org.jboss.tools.jsf.vpe.jsf.template
Bundle-Localization: plugin
+Import-Package: org.jboss.tools.jst.web.tld
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfFacet.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfFacet.java 2008-11-11
16:36:29 UTC (rev 11681)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.vpe.jsf/src/org/jboss/tools/jsf/vpe/jsf/template/JsfFacet.java 2008-11-11
16:36:39 UTC (rev 11682)
@@ -10,11 +10,15 @@
******************************************************************************/
package org.jboss.tools.jsf.vpe.jsf.template;
+import java.util.List;
+
+import org.jboss.tools.jst.web.tld.TaglibData;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.VpeAbstractTemplate;
import org.jboss.tools.vpe.editor.template.VpeChildrenInfo;
import org.jboss.tools.vpe.editor.template.VpeCreationData;
import org.jboss.tools.vpe.editor.util.HTML;
+import org.jboss.tools.vpe.editor.util.XmlUtil;
import org.mozilla.interfaces.nsIDOMDocument;
import org.mozilla.interfaces.nsIDOMElement;
import org.w3c.dom.Node;
@@ -26,45 +30,53 @@
*/
public class JsfFacet extends VpeAbstractTemplate {
+ private static String JSF_CORE_URI = "http://java.sun.com/jsf/core";
//$NON-NLS-1$
+ private static String JSF_HTML_URI = "http://java.sun.com/jsf/html";
//$NON-NLS-1$
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.jboss.tools.vpe.editor.template.VpeTemplate#create(org.jboss.tools
+ * .vpe.editor.context.VpePageContext, org.w3c.dom.Node,
+ * org.mozilla.interfaces.nsIDOMDocument)
+ */
+ public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
+ nsIDOMDocument visualDocument) {
+ nsIDOMElement div = visualDocument.createElement(HTML.TAG_DIV);
+ VpeCreationData creationData = new VpeCreationData(div);
+ NodeList children = sourceNode.getChildNodes();
+ boolean jsfComponentFound = false;
/*
- * (non-Javadoc)
- *
- * @see
org.jboss.tools.vpe.editor.template.VpeTemplate#create(org.jboss.tools.vpe.editor.context.VpePageContext,
- * org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMDocument)
+ * Only one JSF component may be present inside a facet tag,
+ * if more are present only the first one is rendered and the
+ * other ones are ignored.
*/
- public VpeCreationData create(VpePageContext pageContext, Node sourceNode,
- nsIDOMDocument visualDocument) {
-
- nsIDOMElement div = visualDocument.createElement(HTML.TAG_DIV);
-
- VpeCreationData creationData = new VpeCreationData(div);
-
- NodeList children = sourceNode.getChildNodes();
-
- /*
- * <f:facet .../> can contain only one element. so we find first visible
- * node and add to "div"
- */
-
- for (int i = 0; i < children.getLength(); i++) {
-
- Node child = children.item(i);
-
- // we add to "div" non-empty text node or tag
- if (((child.getNodeType() == Node.TEXT_NODE) && !(child
- .getNodeValue().trim().length() == 0))
- || child.getNodeType() == (Node.ELEMENT_NODE)) {
-
- VpeChildrenInfo childrenInfo = new VpeChildrenInfo(div);
-
- childrenInfo.addSourceChild(children.item(i));
-
- creationData.addChildrenInfo(childrenInfo);
-
- break;
- }
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ String sourcePrefix = child.getPrefix();
+ List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode,pageContext);
+ TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourcePrefix, taglibs);
+ if (null != sourceNodeTaglib) {
+ String sourceNodeUri = sourceNodeTaglib.getUri();
+ if ((child.getNodeType() == (Node.ELEMENT_NODE))
+ && (JSF_CORE_URI.equalsIgnoreCase(sourceNodeUri) || JSF_HTML_URI
+ .equalsIgnoreCase(sourceNodeUri))) {
+ VpeChildrenInfo childrenInfo = new VpeChildrenInfo(div);
+ childrenInfo.addSourceChild(children.item(i));
+ creationData.addChildrenInfo(childrenInfo);
+ jsfComponentFound = true;
+ break;
}
+ }
+
+ }
+
+ if (!jsfComponentFound) {
+ div.setAttribute(HTML.ATTR_STYLE, "display: none; "); //$NON-NLS-1$
+ creationData.addChildrenInfo(new VpeChildrenInfo(div));
+ }
- return creationData;
- }
+ return creationData;
+ }
}