Author: nbelaevski
Date: 2009-06-03 12:59:48 -0400 (Wed, 03 Jun 2009)
New Revision: 14461
Added:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/NameValuePair.java
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptOptionTemplateElement.java
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/scriptObject.vm
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/scriptOption.vm
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/scriptObject.vm
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/scriptOption.vm
Modified:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ELCompiler.java
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/ComponentTemplate.vm
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/ComponentTemplate.vm
Log:
https://jira.jboss.org/jira/browse/RF-7247
Modified:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ELCompiler.java
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ELCompiler.java 2009-06-03
16:15:49 UTC (rev 14460)
+++
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/el/ELCompiler.java 2009-06-03
16:59:48 UTC (rev 14461)
@@ -240,7 +240,7 @@
}
if (returnValue) {
- sbMain.append(" isEmpty( ");
+ sbMain.append(" getUtils().isEmpty( ");
sbMain.append(sb1);
sbMain.append(" ) ");
}
Modified:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java 2009-06-03
16:15:49 UTC (rev 14460)
+++
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/A4JRendererElementsFactory.java 2009-06-03
16:59:48 UTC (rev 14461)
@@ -30,7 +30,14 @@
import org.ajax4jsf.templatecompiler.elements.html.CommentElement;
import org.ajax4jsf.templatecompiler.elements.html.PIElement;
import org.ajax4jsf.templatecompiler.elements.html.TextElement;
+import org.ajax4jsf.templatecompiler.elements.std.ForEachTemplateElement;
+import org.ajax4jsf.templatecompiler.elements.std.IFTemplateElement;
+import org.ajax4jsf.templatecompiler.elements.std.ObjectTemplateElement;
+import org.ajax4jsf.templatecompiler.elements.std.ScriptObjectTemplateElement;
+import org.ajax4jsf.templatecompiler.elements.std.ScriptOptionTemplateElement;
+import org.ajax4jsf.templatecompiler.elements.std.SetTemplateElement;
import org.ajax4jsf.templatecompiler.elements.vcp.AjaxRenderedAreaElement;
+import org.ajax4jsf.templatecompiler.elements.vcp.FClientIDTemplateElement;
import org.ajax4jsf.templatecompiler.elements.vcp.HeaderScriptsElement;
import org.ajax4jsf.templatecompiler.elements.vcp.HeaderStylesElement;
import org.apache.commons.logging.Log;
@@ -61,23 +68,14 @@
private final static HashMap<String, String> mapClasses = new HashMap<String,
String>();
static {
- mapClasses
- .put("c:set",
- "org.ajax4jsf.templatecompiler.elements.std.SetTemplateElement");
- mapClasses
- .put("c:object",
- "org.ajax4jsf.templatecompiler.elements.std.ObjectTemplateElement");
- mapClasses.put("c:if",
- "org.ajax4jsf.templatecompiler.elements.std.IFTemplateElement");
- mapClasses
- .put("c:forEach",
- "org.ajax4jsf.templatecompiler.elements.std.ForEachTemplateElement");
- mapClasses
- .put("f:clientid",
- "org.ajax4jsf.templatecompiler.elements.vcp.FClientIDTemplateElement");
- mapClasses
- .put("f:clientId",
- "org.ajax4jsf.templatecompiler.elements.vcp.FClientIDTemplateElement");
+ mapClasses.put("c:scriptObject",
ScriptObjectTemplateElement.class.getName());
+ mapClasses.put("c:scriptOption",
ScriptOptionTemplateElement.class.getName());
+ mapClasses.put("c:set", SetTemplateElement.class.getName());
+ mapClasses.put("c:object", ObjectTemplateElement.class.getName());
+ mapClasses.put("c:if", IFTemplateElement.class.getName());
+ mapClasses.put("c:forEach", ForEachTemplateElement.class.getName());
+ mapClasses.put("f:clientid", FClientIDTemplateElement.class.getName());
+ mapClasses.put("f:clientId", FClientIDTemplateElement.class.getName());
mapClasses.put("f:insertComponent",
"org.ajax4jsf.templatecompiler.elements.vcp.InsertComponent");
Added:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/NameValuePair.java
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/NameValuePair.java
(rev 0)
+++
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/NameValuePair.java 2009-06-03
16:59:48 UTC (rev 14461)
@@ -0,0 +1,89 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.2
+ */
+public class NameValuePair {
+
+ private String name;
+
+ private String value;
+
+ public NameValuePair(String name, String value) {
+ super();
+ this.name = name;
+ this.value = value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((value == null) ? 0 : value.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ NameValuePair other = (NameValuePair) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (value == null) {
+ if (other.value != null)
+ return false;
+ } else if (!value.equals(other.value))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return name + ": "+ value;
+ }
+}
\ No newline at end of file
Added:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java
(rev 0)
+++
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptObjectTemplateElement.java 2009-06-03
16:59:48 UTC (rev 14461)
@@ -0,0 +1,90 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.std;
+
+import java.util.HashMap;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.TemplateElement;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing c:scriptObject
+ *
+ * @author Nick Belaevski
+ * @since 3.3.2
+ *
+ */
+public class ScriptObjectTemplateElement extends TemplateElementBase {
+
+ private static final String TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/scriptObject.vm";
+
+ private String variableName;
+
+ private static final Class<?> VARIABLE_TYPE = HashMap.class;
+
+ public ScriptObjectTemplateElement(final Node element,
+ final CompilationContext componentBean) {
+ super(element, componentBean);
+
+ NamedNodeMap nnm = element.getAttributes();
+ variableName = nnm.getNamedItem("var").getNodeValue();
+ if (variableName == null || variableName.length() == 0) {
+ throw new RuntimeException("'var' attribute required for c:scriptObject
tag!");
+ }
+
+ this.getComponentBean().addVariable(variableName, VARIABLE_TYPE);
+ }
+
+ @Override
+ public void addSubElement(TemplateElement e) {
+ super.addSubElement(e);
+
+ if (e instanceof ScriptOptionTemplateElement) {
+ ((ScriptOptionTemplateElement) e).setMapName(variableName);
+ }
+ }
+
+ public String getBeginElement() throws CompilationException {
+ VelocityContext context = new VelocityContext();
+ context.put("variable", this.variableName);
+ context.put("type", VARIABLE_TYPE.getName().replace('$',
'.'));
+
+ return this.getComponentBean().processTemplate(getTemplateName(), context);
+ }
+
+ /**
+ * @return
+ */
+ protected String getTemplateName() {
+ return TEMPLATE;
+ }
+
+ public String getEndElement() {
+ return null;
+ }
+}
\ No newline at end of file
Added:
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptOptionTemplateElement.java
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptOptionTemplateElement.java
(rev 0)
+++
branches/community/3.3.X/cdk/generator/src/main/java/org/ajax4jsf/templatecompiler/elements/std/ScriptOptionTemplateElement.java 2009-06-03
16:59:48 UTC (rev 14461)
@@ -0,0 +1,184 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.templatecompiler.elements.std;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.ajax4jsf.templatecompiler.builder.CompilationContext;
+import org.ajax4jsf.templatecompiler.builder.CompilationException;
+import org.ajax4jsf.templatecompiler.el.ELParser;
+import org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory;
+import org.ajax4jsf.templatecompiler.elements.NameValuePair;
+import org.ajax4jsf.templatecompiler.elements.TemplateElementBase;
+import org.apache.velocity.VelocityContext;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Processing c:scriptOption
+ * @author Nick Belaevski
+ * @since 3.3.2
+ */
+public class ScriptOptionTemplateElement extends TemplateElementBase {
+
+ private static final String TEMPLATE =
A4JRendererElementsFactory.TEMPLATES_TEMPLATECOMPILER_PATH+"/scriptOption.vm";
+
+ private List<NameValuePair> values = new ArrayList<NameValuePair>();
+
+ private String defaultValue;
+
+ private String mapName;
+
+ private String variables = null;
+ private String attributes = null;
+
+ private String name = null;
+ private String value = null;
+
+ private String wrapperName;
+
+ private static boolean isEmpty(String s) {
+ return s == null || s.length() == 0;
+ }
+
+ private static String getWrapperName(String wrapper) {
+ String result = "DEFAULT";
+
+ if (!isEmpty(wrapper)) {
+ result = wrapper.replaceAll("(\\p{Upper})",
"_$1").toUpperCase(Locale.US);
+ }
+
+ return result;
+ }
+
+ private void initializeSettings(Node element) {
+ NamedNodeMap nnm = element.getAttributes();
+
+ Node variablesNode = nnm.getNamedItem("variables");
+ if (variablesNode != null) {
+ variables = variablesNode.getNodeValue();
+ }
+
+ Node attributesNode = nnm.getNamedItem("attributes");
+ if (attributesNode != null) {
+ attributes = attributesNode.getNodeValue();
+ }
+
+ Node nameNode = nnm.getNamedItem("name");
+ if (nameNode != null) {
+ name = nameNode.getNodeValue();
+ }
+
+ Node valueNode = nnm.getNamedItem("value");
+ if (valueNode != null) {
+ value = valueNode.getNodeValue();
+ }
+
+ Node defaultValueNode = nnm.getNamedItem("defaultValue");
+ if (defaultValueNode != null) {
+ defaultValue = defaultValueNode.getNodeValue();
+ }
+
+ Node wrapperNode = nnm.getNamedItem("wrapper");
+ String wrapperNodeValue = null;
+ if (wrapperNode != null) {
+ wrapperNodeValue = wrapperNode.getNodeValue();
+ }
+
+ wrapperName = getWrapperName(wrapperNodeValue);
+ }
+
+ private void checkSettings() {
+ if (!isEmpty(attributes) || !isEmpty(variables)) {
+ if (!isEmpty(name) || !isEmpty(value)) {
+ throw new RuntimeException("c:scriptOption tag misconfiguration: use either
'attributes'/'variables' or 'name' and 'value'!");
+ }
+ } else {
+ if (isEmpty(name) || isEmpty(value)) {
+ throw new RuntimeException("c:scriptOption tag misconfiguration: 'name'
and 'value' should be both set!");
+ }
+ }
+ }
+
+ private void addELValues(String namesList, String elFormat, CompilationContext
componentBean) {
+ if (!isEmpty(namesList)) {
+ String[] attributesSet = namesList.split(",");
+ for (String attribute : attributesSet) {
+ String trimmedAttribute = attribute.trim();
+ if (trimmedAttribute.length() != 0) {
+ String elExpression = String.format(elFormat, trimmedAttribute);
+ values.add(new NameValuePair(trimmedAttribute,
+ ELParser.compileEL(elExpression, componentBean)));
+ }
+ }
+ }
+ }
+
+ public ScriptOptionTemplateElement(Node element,
+ CompilationContext componentBean) {
+ super(element, componentBean);
+
+ componentBean.addToImport("org.ajax4jsf.renderkit.RendererUtils.ScriptHashVariableWrapper");
+
+ initializeSettings(element);
+ checkSettings();
+
+ addELValues(this.attributes, "#{component.attributes['%s']}",
componentBean);
+ addELValues(this.variables, "#{%s}", componentBean);
+
+ if (!isEmpty(name) && !isEmpty(value)) {
+ values.add(new NameValuePair(name.trim(), ELParser.compileEL(value.trim(),
componentBean)));
+ }
+ }
+
+ public void setMapName(String mapName) {
+ this.mapName = mapName;
+ }
+
+ protected String getTemplateName() {
+ return TEMPLATE;
+ }
+
+ public String getBeginElement() throws CompilationException {
+ VelocityContext context = new VelocityContext();
+
+ context.put("mapName", mapName);
+ context.put("valuesList", values);
+
+ if (!isEmpty(defaultValue)) {
+ context.put("defaultValue", defaultValue);
+ } else {
+ context.put("defaultValue", null);
+ }
+
+ context.put("wrapperName", wrapperName);
+
+ return this.getComponentBean().processTemplate(getTemplateName(), context);
+ }
+
+ public String getEndElement() throws CompilationException {
+ return null;
+ }
+
+}
Modified:
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/ComponentTemplate.vm
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/ComponentTemplate.vm 2009-06-03
16:15:49 UTC (rev 14460)
+++
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/ComponentTemplate.vm 2009-06-03
16:59:48 UTC (rev 14461)
@@ -83,7 +83,6 @@
//
#end
-
private String convertToString(Object obj ) {
return ( obj == null ? "" : obj.toString() );
}
@@ -97,25 +96,6 @@
return b!=Long.MIN_VALUE?String.valueOf(b):"";
}
- private boolean isEmpty(Object o) {
- if (null == o) {
- return true;
- }
- if (o instanceof String ) {
- return (0 == ((String)o).length());
- }
- if (o instanceof Collection) {
- return (0 == ((Collection)o).size());
- }
- if (o instanceof Map) {
- return (0 == ((Map)o).size());
- }
- if (o.getClass().isArray()) {
- return (0 == ((Object [])o).length);
- }
- return false;
- }
-
/**
* Get base component class, targetted for this renderer. Used for check arguments in
decode/encode.
* @return
Added:
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/scriptObject.vm
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/scriptObject.vm
(rev 0)
+++
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/scriptObject.vm 2009-06-03
16:59:48 UTC (rev 14461)
@@ -0,0 +1 @@
+$type $variable = new $type();
\ No newline at end of file
Added:
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/scriptOption.vm
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/scriptOption.vm
(rev 0)
+++
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates/templatecompiler/scriptOption.vm 2009-06-03
16:59:48 UTC (rev 14461)
@@ -0,0 +1,3 @@
+#foreach ($nvp in $valuesList)
+ getUtils().addToScriptHash(${mapName}, "${nvp.name}", ${nvp.value}, #if
($defaultValue) "${defaultValue}" #else null #end,
ScriptHashVariableWrapper.${wrapperName});
+#end
\ No newline at end of file
Modified:
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/ComponentTemplate.vm
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/ComponentTemplate.vm 2009-06-03
16:15:49 UTC (rev 14460)
+++
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/ComponentTemplate.vm 2009-06-03
16:59:48 UTC (rev 14461)
@@ -83,7 +83,6 @@
//
#end
-
private String convertToString(Object obj ) {
return ( obj == null ? "" : obj.toString() );
}
@@ -97,25 +96,6 @@
return b!=Long.MIN_VALUE?String.valueOf(b):"";
}
- private boolean isEmpty(Object o) {
- if (null == o) {
- return true;
- }
- if (o instanceof String ) {
- return (0 == ((String)o).length());
- }
- if (o instanceof Collection) {
- return (0 == ((Collection)o).size());
- }
- if (o instanceof Map) {
- return (0 == ((Map)o).size());
- }
- if (o.getClass().isArray()) {
- return (0 == ((Object [])o).length);
- }
- return false;
- }
-
/**
* Get base component class, targetted for this renderer. Used for check arguments in
decode/encode.
* @return
Added:
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/scriptObject.vm
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/scriptObject.vm
(rev 0)
+++
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/scriptObject.vm 2009-06-03
16:59:48 UTC (rev 14461)
@@ -0,0 +1 @@
+$type $variable = new $type();
\ No newline at end of file
Added:
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/scriptOption.vm
===================================================================
---
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/scriptOption.vm
(rev 0)
+++
branches/community/3.3.X/cdk/generator/src/main/resources/META-INF/templates12/templatecompiler/scriptOption.vm 2009-06-03
16:59:48 UTC (rev 14461)
@@ -0,0 +1,3 @@
+#foreach ($nvp in $valuesList)
+ getUtils().addToScriptHash(${mapName}, "${nvp.name}", ${nvp.value}, #if
($defaultValue) "${defaultValue}" #else null #end,
ScriptHashVariableWrapper.${wrapperName});
+#end
\ No newline at end of file