Author: nbelaevski
Date: 2010-10-24 15:11:47 -0400 (Sun, 24 Oct 2010)
New Revision: 19657
Added:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptObjectElement.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptOptionElement.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashStatement.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/PassThrough.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptObjectStatement.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java
trunk/cdk/generator/src/main/resources/META-INF/templates/java/add-attributes-to-script-hash.ftl
trunk/cdk/generator/src/main/resources/META-INF/templates/java/script-object.ftl
trunk/cdk/generator/src/main/resources/META-INF/templates/java/script-option.ftl
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashTest.java
Removed:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/ClassImport.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RuntimeImport.java
trunk/core/impl/src/main/java/org/richfaces/component/util/ComponentUtil.java
trunk/core/impl/src/test/java/org/richfaces/component/util/ComponentUtilTest.java
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CompositeInterface.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/util/JavaUtils.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/util/Strings.java
trunk/cdk/generator/src/main/resources/META-INF/schema/cdk-template.xsd
trunk/cdk/generator/src/main/resources/META-INF/templates/java/class.ftl
trunk/cdk/generator/src/main/resources/META-INF/templates/java/util.ftl
trunk/cdk/generator/src/main/resources/META-INF/templates/java/write-attributes-set.ftl
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetTest.java
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/util/RendererUtils.java
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/util/RendererUtilsTest.java
trunk/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
trunk/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java
trunk/ui/core/ui/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/ListRendererBase.java
trunk/ui/misc/ui/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java
trunk/ui/misc/ui/src/main/templates/jquery.template.xml
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarBaseRenderer.java
Log:
https://jira.jboss.org/browse/RF-8957
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.lang.reflect.Type;
+import java.text.MessageFormat;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
@@ -58,13 +59,17 @@
import org.richfaces.cdk.templatecompiler.model.CdkIfElement;
import org.richfaces.cdk.templatecompiler.model.CdkObjectElement;
import org.richfaces.cdk.templatecompiler.model.CdkOtherwiseElement;
+import org.richfaces.cdk.templatecompiler.model.CdkScriptObjectElement;
+import org.richfaces.cdk.templatecompiler.model.CdkScriptOptionElement;
import org.richfaces.cdk.templatecompiler.model.CdkSwitchElement;
import org.richfaces.cdk.templatecompiler.model.CdkWhenElement;
+import org.richfaces.cdk.templatecompiler.model.ClassImport;
import org.richfaces.cdk.templatecompiler.model.CompositeImplementation;
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
import org.richfaces.cdk.templatecompiler.model.ResourceDependency;
import org.richfaces.cdk.templatecompiler.model.Template;
import org.richfaces.cdk.templatecompiler.model.TemplateVisitor;
+import org.richfaces.cdk.templatecompiler.statements.AddAttributesToScriptHashStatement;
import org.richfaces.cdk.templatecompiler.statements.AttributesStatement;
import org.richfaces.cdk.templatecompiler.statements.CaseStatement;
import org.richfaces.cdk.templatecompiler.statements.ConstantReturnMethodBodyStatement;
@@ -76,6 +81,8 @@
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import org.richfaces.cdk.templatecompiler.statements.IfElseStatement;
import org.richfaces.cdk.templatecompiler.statements.IfStatement;
+import org.richfaces.cdk.templatecompiler.statements.ScriptObjectStatement;
+import org.richfaces.cdk.templatecompiler.statements.ScriptOptionStatement;
import org.richfaces.cdk.templatecompiler.statements.StartElementStatement;
import org.richfaces.cdk.templatecompiler.statements.StatementsContainer;
import org.richfaces.cdk.templatecompiler.statements.SwitchStatement;
@@ -85,6 +92,7 @@
import org.richfaces.cdk.util.Strings;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
import com.google.inject.Injector;
/**
@@ -131,11 +139,6 @@
*/
static final String CLIENT_ID_VARIABLE = "clientId";
- /**
- *
- */
- private static final String PASS_THROUGH_ATTRIBUTES_FIELD_NAME =
"PASS_THROUGH_ATTRIBUTES";
-
private final Logger log;
private final Injector injector;
@@ -148,8 +151,6 @@
private JavaClass generatedClass;
private Set<HelperMethod> addedHelperMethods =
EnumSet.noneOf(HelperMethod.class);
- private int passThroughCounter;
-
public RendererClassVisitor(CompositeInterface compositeInterface,
Collection<PropertyBase> attributes, Logger log,
Injector injector, TypesFactory typesFactory, HelperMethodFactory helperFactory)
{
this.compositeInterface = compositeInterface;
@@ -170,6 +171,18 @@
this.generatedClass.addImport(ResponseWriter.class);
this.generatedClass.addImport(UIComponent.class);
+ for (ClassImport classImport: compositeInterface.getClassImports()) {
+ List<String> importedNames = classImport.getNames();
+ if (importedNames == null || importedNames.isEmpty()) {
+ importedNames = Lists.newArrayList("*");
+ }
+
+ for (String importedName : importedNames) {
+
this.generatedClass.addImport(Strings.DOT_JOINER.join(classImport.getPackage(),
importedName),
+ classImport.isStatic());
+ }
+ }
+
// TODO - make this JavaDoc - Generated annotation is present since JDK6
// this.generatedClass.addAnnotation(Generated.class, "\"RichFaces
CDK\"");
// TODO remove this after improving Java model
@@ -603,7 +616,6 @@
*/
public void preProcess(CompositeImplementation impl) {
initializeJavaClass();
- passThroughCounter = -1;
}
/**
@@ -614,4 +626,51 @@
createRendersChildrenMethod();
}
+ @Override
+ public void startElement(CdkScriptObjectElement cdkScriptObjectElement) {
+ ScriptObjectStatement scriptObjectStatement =
pushStatement(ScriptObjectStatement.class);
+ scriptObjectStatement.setObject(cdkScriptObjectElement.getName(),
cdkScriptObjectElement.getBase());
+ }
+
+ @Override
+ public void endElement(CdkScriptObjectElement cdkScriptObjectElement) {
+ popStatement();
+ }
+
+ private void addScriptHashAttributesPassthroughStatement(List<String>
attributeNames, String wrapper) {
+ if (attributeNames == null || attributeNames.isEmpty()) {
+ return;
+ }
+
+ AddAttributesToScriptHashStatement statement =
addStatement(AddAttributesToScriptHashStatement.class);
+ statement.setWrapper(wrapper);
+ statement.setAttributes(attributeNames, attributes);
+ }
+
+ private void addScriptOptionStatement(String name, String value, String defaultValue,
String wrapper) {
+ ScriptOptionStatement scriptOptionStatement =
addStatement(ScriptOptionStatement.class);
+ scriptOptionStatement.setName(name);
+ scriptOptionStatement.setValueExpression(value);
+ scriptOptionStatement.setDefaultValue(defaultValue);
+ scriptOptionStatement.setWrapper(wrapper);
+ }
+
+ @Override
+ public void visitElement(CdkScriptOptionElement cdkScriptOptionElement) {
+
addScriptHashAttributesPassthroughStatement(cdkScriptOptionElement.getAttributes(),
cdkScriptOptionElement.getWrapper());
+
+ for (String variableName : cdkScriptOptionElement.getVariables()) {
+ addScriptOptionStatement(variableName,
+ MessageFormat.format("#'{'{0}'}'",
variableName),
+ cdkScriptOptionElement.getDefaultValue(),
+ cdkScriptOptionElement.getWrapper());
+ }
+
+ if (!Strings.isEmpty(cdkScriptOptionElement.getName())) {
+ addScriptOptionStatement(cdkScriptOptionElement.getName(),
+ cdkScriptOptionElement.getValue(),
+ cdkScriptOptionElement.getDefaultValue(),
+ cdkScriptOptionElement.getWrapper());
+ }
+ }
}
Deleted:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/ClassImport.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/ClassImport.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/ClassImport.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -1,48 +0,0 @@
-/**
- * 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.richfaces.cdk.templatecompiler.builder.model;
-
-/**
- * @author Maksim Kaszynski
- */
-public class ClassImport implements JavaImport {
- private Class<?> clazz;
-
- public ClassImport(Class<?> clazz) {
- super();
- this.clazz = clazz;
- }
-
- public String getName() {
- return clazz.getName();
- }
-
- @Override
- public boolean isDefault() {
- if(clazz.isPrimitive()){
- return true;
- } else if("java.lang".equals(clazz.getPackage().getName())){
- return true;
- }
- return false;
- }
-}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -71,18 +71,20 @@
public void addImport(String name) {
- addImport(new RuntimeImport(name));
+ addImport(new JavaImportImpl(name));
}
- public void addImport(JavaImport javaImport) {
- imports.add(javaImport);
+ public void addImport(String name, boolean _static) {
+ addImport(new JavaImportImpl(name, _static));
}
public void addImport(Class<?> claz) {
- if (shouldAddToImports(claz.getName())) {
- imports.add(new ClassImport(claz));
- }
+ addImport(claz.getName());
}
+
+ public void addImport(JavaImport javaImport) {
+ imports.add(javaImport);
+ }
public void addImports(Iterable<JavaImport> imports) {
for (JavaImport elType : imports) {
@@ -141,20 +143,4 @@
return simpleName;
}
- private boolean shouldAddToImports(String className) {
- if (className == null || className.length() == 0) {
- return false;
- }
-
- // default package & primitive types
- if (className.indexOf('.') == -1) {
- return false;
- }
-
- if (className.matches("^java\\.lang\\.[^\\.]+$")) {
- return false;
- }
-
- return true;
- }
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -27,12 +27,17 @@
* @author Maksim Kaszynski
*/
public interface JavaImport {
+
public Comparator<? super JavaImport> COMPARATOR = new
Comparator<JavaImport>() {
public int compare(JavaImport o1, JavaImport o2) {
return o1.getName().compareTo(o2.getName());
}
};
- String getName();
-
- boolean isDefault();
+
+ public String getName();
+
+ public boolean isStatic();
+
+ public boolean isDefault();
+
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -6,6 +6,7 @@
import com.google.common.base.Function;
public interface RequireImports {
+
public static final Function<RequireImports, Iterable<JavaImport>>
IMPORTS_TRANSFORM = new Function<RequireImports, Iterable<JavaImport>>() {
@Override
Deleted:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RuntimeImport.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RuntimeImport.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RuntimeImport.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -1,59 +0,0 @@
-/**
- * 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.richfaces.cdk.templatecompiler.builder.model;
-
-import java.util.regex.Pattern;
-
-/**
- * Implementation of import taht cannot be resolved in design time
- *
- * @author Maksim Kaszynski
- */
-public class RuntimeImport implements JavaImport {
-
- private static final Pattern JAVA_LANG_PATTERN =
Pattern.compile("^java\\.lang\\.[^\\.]+$");
-
- private String name;
-
- public RuntimeImport(String name) {
- super();
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public boolean isDefault() {
- // default package & primitive types
- if (name.indexOf('.') == -1) {
- return true;
- }
-
- if (JAVA_LANG_PATTERN.matcher(name).matches()) {
- return true;
- }
-
- return false;
- }
-}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -22,12 +22,18 @@
package org.richfaces.cdk.templatecompiler.el.node;
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.COMMA;
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.LEFT_BRACKET;
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.RIGHT_BRACKET;
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.THIS_PREFIX;
+
import org.jboss.el.parser.AstFunction;
import org.jboss.el.parser.Node;
-import org.richfaces.cdk.templatecompiler.el.ELNodeConstants;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.types.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethod;
import org.richfaces.cdk.util.Strings;
/**
@@ -45,23 +51,68 @@
@Override
public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
AstFunction functionNode = (AstFunction) getNode();
- String functionPrefix = functionNode.getPrefix();
- String functionName = functionNode.getLocalName();
-
- String identifierName;
- if (!Strings.isEmpty(functionPrefix)) {
- // TODO: this should be a property getter, not property name. NB:
'this' & 'super' keywords
- identifierName = functionPrefix;
+
+ HelperMethod helperMethod = findMatchingHelperMethod(functionNode);
+ if (helperMethod != null) {
+ visitHelperMethod(sb, visitor, helperMethod, functionNode);
} else {
- identifierName = ELNodeConstants.THIS_PREFIX;
+ visitObjectMethod(sb, visitor, functionNode);
}
+ }
+ /**
+ * @param sb
+ * @param visitor
+ * @param helperMethod
+ * @param functionNode
+ * @throws ParsingException
+ */
+ private void visitHelperMethod(StringBuilder sb, ELVisitor visitor, HelperMethod
helperMethod,
+ AstFunction functionNode) throws ParsingException {
+ visitor.addHelperMethods(helperMethod);
+
+ visitor.setLiteral(false);
+
+ //TODO - helper method doesn't provide this info
+ visitor.setExpressionType(TypesFactory.OBJECT_TYPE);
+
+ sb.append(helperMethod.getName());
+ sb.append(LEFT_BRACKET);
+
+ for (int i = 0; i < functionNode.jjtGetNumChildren(); i++) {
+ if (i != 0) {
+ sb.append(COMMA);
+ }
+
+ String childOutput = getChildOutput(i, visitor);
+ sb.append(childOutput);
+ }
+
+ sb.append(RIGHT_BRACKET);
+ }
+
+ private HelperMethod findMatchingHelperMethod(AstFunction functionNode) {
+ if (Strings.isEmpty(functionNode.getPrefix())) {
+ for (HelperMethod helperMethod: HelperMethod.values()) {
+ if (helperMethod.getName().equals(functionNode.getLocalName())) {
+ return helperMethod;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private void visitObjectMethod(StringBuilder sb, ELVisitor visitor, AstFunction
functionNode)
+ throws ParsingException {
+
+ String identifierName = Strings.firstNonEmpty(functionNode.getPrefix(),
THIS_PREFIX);
sb.append(identifierName);
ELType identifierType = visitor.getVariable(identifierName);
visitor.setExpressionType(identifierType);
- visitMethod(sb, visitor, functionName);
+ visitMethod(sb, visitor, functionNode.getLocalName());
visitor.setLiteral(false);
}
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -25,8 +25,8 @@
import java.util.Collections;
import java.util.Set;
-import org.richfaces.cdk.templatecompiler.builder.model.ClassImport;
import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImportImpl;
/**
* @author Nick Belaevski
@@ -48,7 +48,7 @@
}
this.clazz = clazz;
- this.imports = Collections.<JavaImport>singleton(new ClassImport(clazz));
+ this.imports = Collections.<JavaImport>singleton(new
JavaImportImpl(clazz));
}
public Class<?> getPlainJavaClass(){
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -79,7 +79,8 @@
static final ImmutableMap<Class<?>, Class<?>>
PRIMITIVE_TO_WRAPPER_CLASSES_MAP = ImmutableMap
.<Class<?>, Class<?>> builder().put(Boolean.TYPE,
Boolean.class).put(Float.TYPE, Float.class)
.put(Long.TYPE, Long.class).put(Integer.TYPE, Integer.class).put(Short.TYPE,
Short.class)
- .put(Byte.TYPE, Byte.class).put(Double.TYPE, Double.class).put(Character.TYPE,
Character.class).build();
+ .put(Byte.TYPE, Byte.class).put(Double.TYPE, Double.class).put(Character.TYPE,
Character.class)
+ .put(Void.TYPE, Void.class).build();
static final ImmutableMap<String, Class<?>> PRIMITIVE_CLASSES_MAP;
Added:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptObjectElement.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptObjectElement.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptObjectElement.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "scriptObject", namespace = Template.CDK_NAMESPACE)
+public class CdkScriptObjectElement extends ModelFragment {
+
+ @XmlAttribute(required = true)
+ @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
+ private String name;
+
+ @XmlAttribute
+ private String base;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getBase() {
+ return base;
+ }
+
+ public void setBase(String base) {
+ this.base = base;
+ }
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptOptionElement.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptOptionElement.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptOptionElement.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "scriptOption", namespace = Template.CDK_NAMESPACE)
+public class CdkScriptOptionElement implements ModelElement {
+
+ @XmlAttribute
+ private List<String> variables = new ArrayList<String>();
+
+ @XmlAttribute
+ private List<String> attributes = new ArrayList<String>();
+
+ @XmlAttribute
+ private String name;
+
+ @XmlAttribute
+ private String value;
+
+ @XmlAttribute
+ private String defaultValue;
+
+ @XmlAttribute
+ private String wrapper;
+
+ public List<String> getVariables() {
+ return variables;
+ }
+
+ public void setVariables(List<String> variables) {
+ this.variables = variables;
+ }
+
+ public List<String> getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(List<String> attributes) {
+ this.attributes = attributes;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ public String getWrapper() {
+ return wrapper;
+ }
+
+ public void setWrapper(String wrapper) {
+ this.wrapper = wrapper;
+ }
+
+ @Override
+ public void visit(TemplateVisitor visitor) throws CdkException {
+ visitor.visitElement(this);
+ }
+
+}
Added:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.model;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ClassImport {
+
+ @XmlAttribute(required = true)
+ @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
+ private String _package;
+
+ @XmlAttribute
+ private boolean _static;
+
+ @XmlAttribute
+ private List<String> names;
+
+ /**
+ * @return the package_
+ */
+ public String getPackage() {
+ return _package;
+ }
+
+ /**
+ * @param _package the package_ to set
+ */
+ public void setPackage(String _package) {
+ this._package = _package;
+ }
+
+ /**
+ * @return the static_
+ */
+ public boolean isStatic() {
+ return _static;
+ }
+
+ /**
+ * @param static_ the static_ to set
+ */
+ public void setStatic(boolean _static) {
+ this._static = _static;
+ }
+
+ /**
+ * @return the classes
+ */
+ public List<String> getNames() {
+ return names;
+ }
+
+ /**
+ * @param classes the classes to set
+ */
+ public void setNames(List<String> classes) {
+ this.names = classes;
+ }
+
+}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CompositeInterface.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CompositeInterface.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CompositeInterface.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -67,6 +67,8 @@
private Boolean rendersChildren = null;
+ private List<ClassImport> classImports = Lists.newArrayList();
+
/**
* <p class="changed_added_4_0"></p>
*
@@ -243,4 +245,18 @@
this.attributesImports = attributesImports;
}
+ /**
+ * @return the classImports
+ */
+ @XmlElement(name = "import", namespace = Template.CDK_NAMESPACE)
+ public List<ClassImport> getClassImports() {
+ return classImports;
+ }
+
+ /**
+ * @param classImports the classImports to set
+ */
+ public void setClassImports(List<ClassImport> classImports) {
+ this.classImports = classImports;
+ }
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -19,7 +19,8 @@
*/
@XmlSeeAlso( { CdkCallElement.class, CdkBodyElement.class, CdkIfElement.class,
CdkObjectElement.class,
CdkChooseElement.class, CdkWhenElement.class, CdkOtherwiseElement.class,
CdkForEachElement.class,
- CdkSwitchElement.class, CdkCaseElement.class, CdkDefaultElement.class })
+ CdkSwitchElement.class, CdkCaseElement.class, CdkDefaultElement.class,
+ CdkScriptObjectElement.class, CdkScriptOptionElement.class })
public class ModelFragment implements LeafModelElement {
private List<Object> children = Lists.newArrayList();
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -82,4 +82,10 @@
void postProcess(CompositeImplementation compositeImplementation);
+ void startElement(CdkScriptObjectElement cdkScriptObjectElement);
+
+ void endElement(CdkScriptObjectElement cdkScriptObjectElement);
+
+ void visitElement(CdkScriptOptionElement cdkScriptOptionElement);
+
}
Added:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashStatement.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashStatement.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashStatement.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.statements;
+
+import java.util.Collection;
+import java.util.NoSuchElementException;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.xml.namespace.QName;
+
+import org.richfaces.cdk.attributes.Attribute.Kind;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.Named.NamePredicate;
+import org.richfaces.cdk.model.PropertyBase;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.inject.Inject;
+
+/**
+ * @author Nick Belaevski
+ */
+public class AddAttributesToScriptHashStatement extends FreeMarkerTemplateStatementBase
{
+
+ /**
+ *
+ */
+ private static final String ATTRIBUTES_FIELD_NAME =
"ATTRIBUTES_FOR_SCRIPT_HASH";
+
+ private static AtomicInteger fieldCounter = new AtomicInteger(0);
+
+ private String fieldName;
+
+ private String wrapper;
+
+ private Collection<PassThrough> attributes = Lists.newArrayList();
+
+ private Collection<PropertyBase> componentAttributes;
+
+ @Inject
+ public AddAttributesToScriptHashStatement(@TemplateModel FreeMarkerRenderer renderer)
{
+ super(renderer, "add-attributes-to-script-hash");
+ fieldName = ATTRIBUTES_FIELD_NAME + fieldCounter.getAndIncrement();
+ }
+
+ /**
+ * @return the fieldName
+ */
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param fieldName the fieldName to set
+ */
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the attributes
+ */
+ public Collection<PassThrough> getAttributes() {
+ return this.attributes;
+ }
+
+ /**
+ * @return the wrapper
+ */
+ public String getWrapper() {
+ return wrapper;
+ }
+
+ /**
+ * @param wrapper the wrapper to set
+ */
+ public void setWrapper(String wrapper) {
+ this.wrapper = wrapper;
+ }
+
+ /**
+ * @param attributeNames
+ * @param attributes
+ */
+ public void setAttributes(Collection<String> attributeNames,
Collection<PropertyBase> componentAttributes) {
+ this.componentAttributes = componentAttributes;
+
+ for (String attributeName : attributeNames) {
+ PassThrough passThrough = new PassThrough();
+ passThrough.name = QName.valueOf(attributeName);
+ passThrough.componentAttribute = attributeName;
+
+ try {
+ PropertyBase componentAttribute = findComponentAttribute(attributeName);
+ for (EventName event : componentAttribute.getEventNames()) {
+ passThrough.behaviors.add(event.getName());
+ }
+ passThrough.defaultValue = componentAttribute.getDefaultValue();
+ passThrough.type = componentAttribute.getType().getSimpleName();
+
+ } catch (NoSuchElementException e) {
+ passThrough.type = Object.class.getName();
+ }
+
+ if (Boolean.TYPE.equals(passThrough.type) ||
Boolean.class.equals(passThrough.type)) {
+ passThrough.kind = Kind.BOOLEAN;
+ } else {
+ passThrough.kind = Kind.GENERIC;
+ }
+
+ attributes.add(passThrough);
+ }
+ }
+ private PropertyBase findComponentAttribute(final String name)
+ throws NoSuchElementException {
+
+ return Iterables.find(componentAttributes, new NamePredicate(name));
+ }
+}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -15,13 +15,12 @@
import org.richfaces.cdk.attributes.Element;
import org.richfaces.cdk.attributes.Schema;
import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.Named.NamePredicate;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.templatecompiler.model.AnyElement;
import org.richfaces.cdk.templatecompiler.model.Template;
-import
org.richfaces.cdk.templatecompiler.statements.WriteAttributesSetStatement.PassThrough;
import org.richfaces.cdk.util.Strings;
-import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
@@ -66,7 +65,7 @@
public void processAttributes(AnyElement element, Collection<PropertyBase>
componentAttributes) {
this.componentAttributes = componentAttributes;
Set<String> processedAttributes = Sets.newHashSet();
- TreeSet<WriteAttributesSetStatement.PassThrough> passThroughAttributes =
Sets.newTreeSet();
+ TreeSet<PassThrough> passThroughAttributes = Sets.newTreeSet();
this.elementName = element.getName();
processRegularAttributes(element, processedAttributes, passThroughAttributes);
String passThrough = element.getPassThrough();
@@ -81,7 +80,7 @@
}
private void processPassThroughWithExclusions(Set<String> processedAttributes,
- TreeSet<WriteAttributesSetStatement.PassThrough> passThroughAttributes,
String passThroughWithExclusions) {
+ TreeSet<PassThrough> passThroughAttributes, String
passThroughWithExclusions) {
if (null != passThroughWithExclusions) {
// cdk:passThroughWithExclusions="id,class,style"
Map<String, Element> elements = attributesSchema.getElements();
@@ -101,7 +100,7 @@
}
private void processPassThrough(Set<String> processedAttributes,
- TreeSet<WriteAttributesSetStatement.PassThrough> passThroughAttributes,
String passThrough) {
+ TreeSet<PassThrough> passThroughAttributes, String passThrough) {
if (null != passThrough) {
// cdk:passThrough="class:styleClass,style , id:clientId"
Iterable<String> split = PASS_THGOUGH_SPLITTER.split(passThrough);
@@ -117,7 +116,7 @@
}
private void processRegularAttributes(AnyElement element, Set<String>
processedAttributes,
- TreeSet<WriteAttributesSetStatement.PassThrough> passThroughAttributes) {
+ TreeSet<PassThrough> passThroughAttributes) {
for (Map.Entry<QName, Object> entry : element.getAttributes().entrySet())
{
QName qName = entry.getKey();
if (Template.CDK_NAMESPACE.equals(qName.getNamespaceURI())) {
@@ -174,13 +173,7 @@
private PropertyBase findComponentAttribute(final String name)
throws NoSuchElementException {
- return Iterables.find(componentAttributes, new Predicate<PropertyBase>() {
- @Override
- public boolean apply(PropertyBase input) {
- return name.equals(input.getName());
- }
- });
-
+ return Iterables.find(componentAttributes, new NamePredicate(name));
}
private WriteAttributeStatement setupAttributeStatement(QName qName, Object value,
Attribute schemaAttribute) {
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -28,8 +28,8 @@
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImportImpl;
import org.richfaces.cdk.templatecompiler.builder.model.JavaModifier;
-import org.richfaces.cdk.templatecompiler.builder.model.RuntimeImport;
import org.richfaces.cdk.templatecompiler.el.types.ReferencedType;
import org.richfaces.cdk.util.Strings;
@@ -121,7 +121,7 @@
}
public void addImport(String name) {
- imports.add(new RuntimeImport(name));
+ imports.add(new JavaImportImpl(name));
}
protected void addImports(Iterable<JavaImport> requiredImports) {
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -21,11 +21,20 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.*;
+import static com.google.common.collect.Iterators.forArray;
+import static com.google.common.collect.Iterators.toArray;
+import static com.google.common.collect.Iterators.transform;
+import static
org.richfaces.cdk.templatecompiler.el.ELNodeConstants.CONVERT_TO_BOOLEAN_FUNCTION;
+import static
org.richfaces.cdk.templatecompiler.el.ELNodeConstants.CONVERT_TO_STRING_FUNCTION;
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.IS_EMPTY_FUNCTION;
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.IS_EQUAL_FUNCTION;
+import static org.richfaces.cdk.util.JavaUtils.CLASS_TO_CLASS_NAME;
import java.util.Collection;
import java.util.EnumMap;
import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
import javax.faces.component.UIComponent;
@@ -46,7 +55,14 @@
SHOULD_RENDER_ATTRIBUTE("shouldRenderAttribute", Boolean.TYPE,
Object.class),
CREATE_ATTRIBUTES("attributes", "Attributes"),
RENDER_ATTRIBUTES_SET("renderPassThroughAttributes",
Void.TYPE,FacesContext.class,UIComponent.class,Collection.class),
-
RENDER_ATTRIBUTE("renderAttribute",Void.TYPE,FacesContext.class,String.class,Object.class);
+
RENDER_ATTRIBUTE("renderAttribute",Void.TYPE,FacesContext.class,String.class,Object.class),
+ ADD_TO_SCRIPT_HASH("addToScriptHash", Void.TYPE.getName(),
Map.class.getName(), String.class.getName(),
+ Object.class.getName(), Object.class.getName(),
"ScriptHashVariableWrapper"),
+ ADD_TO_SCRIPT_HASH_ATTRIBUTES("addToScriptHash", Void.TYPE.getName(),
Map.class.getName(),
+ FacesContext.class.getName(), UIComponent.class.getName(),
+ "Attributes", "ScriptHashVariableWrapper"),
+ TO_SCRIPT_ARGS("toScriptArgs", String.class, Object[].class),
+ CONCAT("concat", String.class, String[].class);
public static final EnumMap<HelperMethod, String> METHOD_NAMES =
Maps.newEnumMap(HelperMethod.class);
@@ -56,7 +72,7 @@
private final String returnType;
- private final Class<?>[] argumentTypes;
+ private final String[] argumentTypes;
static {
for (HelperMethod method : HelperMethod.values()) {
@@ -64,14 +80,19 @@
}
}
- private HelperMethod(String name, String returnType, Class<?>... argumentTypes)
{
+ private static String[] transformClassesToClassNames(Class<?>[] s) {
+ Iterator<String> transformed = transform(forArray(s),
CLASS_TO_CLASS_NAME);
+ return toArray(transformed, String.class);
+ }
+
+ private HelperMethod(String name, String returnType, String... argumentTypes) {
this.name = name;
this.returnType = returnType;
this.argumentTypes = argumentTypes;
}
private HelperMethod(String name, Class<?> returnType, Class<?>...
argumentTypes) {
- this(name,returnType.getName(),argumentTypes);
+ this(name, CLASS_TO_CLASS_NAME.apply(returnType),
transformClassesToClassNames(argumentTypes));
}
public String getName() {
@@ -82,7 +103,7 @@
return returnType;
}
- public Class<?>[] getArgumentTypes() {
+ public String[] getArgumentTypes() {
return argumentTypes;
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -91,6 +91,10 @@
arguments.add(new
Argument("attributes",typesFactory.getType("Attributes")));
renderAttributes.getExceptions().add(typesFactory.getType(IOException.class));
buildHelperMethod(HelperMethod.CREATE_ATTRIBUTES, true,
"create-attributes");
+ buildHelperMethod(HelperMethod.ADD_TO_SCRIPT_HASH, true, null);
+ buildHelperMethod(HelperMethod.ADD_TO_SCRIPT_HASH_ATTRIBUTES, true, null);
+ buildHelperMethod(HelperMethod.TO_SCRIPT_ARGS, true, null);
+ buildHelperMethod(HelperMethod.CONCAT, true, null);
}
private JavaMethod buildHelperMethod(HelperMethod helperMethod, boolean utilsMethod,
String templateName,
@@ -99,7 +103,7 @@
if (utilsMethod &&
!RendererUtilsMethod.BUILT_IN.equals(rendererUtilsClass)) {
helperJavaMethod = new RendererUtilsMethod(helperMethod,
rendererUtilsClass);
} else {
- Class<?>[] argumentTypes = helperMethod.getArgumentTypes();
+ String[] argumentTypes = helperMethod.getArgumentTypes();
Argument[] arguments = new Argument[argumentNames.length];
for (int i = 0; i < argumentNames.length; i++) {
arguments[i] = new Argument(argumentNames[i],
typesFactory.getType(argumentTypes[i]));
Added:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/PassThrough.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/PassThrough.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/PassThrough.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -0,0 +1,78 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.richfaces.cdk.attributes.Attribute.Kind;
+
+import com.google.common.collect.Sets;
+
+/**
+ * <p class="changed_added_4_0">object contains information about
attribute</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public final class PassThrough implements Comparable<PassThrough> {
+ QName name;
+ Kind kind = Kind.GENERIC;
+ String componentAttribute;
+ String type;
+ Object defaultValue;
+ Set<String> behaviors = Sets.newHashSet();
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the name
+ */
+ public QName getName() {
+ return this.name;
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the kind
+ */
+ public Kind getKind() {
+ return this.kind;
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the componentAttribute
+ */
+ public String getComponentAttribute() {
+ return this.componentAttribute;
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the type
+ */
+ public String getType() {
+ return this.type;
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the defaultValue
+ */
+ public Object getDefaultValue() {
+ return this.defaultValue;
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the behaviors
+ */
+ public Set<String> getBehaviors() {
+ return this.behaviors;
+ }
+ public String getBuilderMethod() {
+ if(Kind.BOOLEAN.equals(kind)){
+ return "bool";
+ } else {
+ return kind.toString().toLowerCase();
+ }
+ }
+ @Override
+
+ public int compareTo(PassThrough o) {
+ return name.toString().compareTo(o.name.toString());
+ }
+}
\ No newline at end of file
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -26,8 +26,8 @@
import java.util.TreeSet;
import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImportImpl;
import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
-import org.richfaces.cdk.templatecompiler.builder.model.RuntimeImport;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
@@ -45,9 +45,10 @@
public RendererUtilsMethod(HelperMethod helper,String rendererUtilsClassName) {
super(helper.getName());
- this.runtimeImport.add(new RuntimeImport("static "
+rendererUtilsClassName+".*"));
- this.runtimeImport.add(new RuntimeImport(rendererUtilsClassName));
- this.runtimeImport.add(new
RuntimeImport(rendererUtilsClassName+".Attributes"));
+ this.runtimeImport.add(new JavaImportImpl(rendererUtilsClassName +
".*", true));
+ this.runtimeImport.add(new JavaImportImpl(rendererUtilsClassName));
+ this.runtimeImport.add(new
JavaImportImpl(rendererUtilsClassName+".Attributes"));
+ this.runtimeImport.add(new
JavaImportImpl(rendererUtilsClassName+".ScriptHashVariableWrapper"));
}
@Override
Added:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptObjectStatement.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptObjectStatement.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptObjectStatement.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static
org.richfaces.cdk.templatecompiler.builder.model.RequireImports.IMPORTS_TRANSFORM;
+import static
org.richfaces.cdk.templatecompiler.statements.TemplateStatement.FIELDS_TRANSFORM;
+
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+//TODO - configure initial map size
+public class ScriptObjectStatement extends FreeMarkerTemplateStatementBase {
+
+ private String name;
+
+ private ELParser parser;
+
+ private TypedTemplateStatement base;
+
+ private Logger logger;
+
+ private TypesFactory typesFactory;
+
+ private ELType mapType;
+
+ private ELType mapImplementationType;
+
+ @Inject
+ public ScriptObjectStatement(@TemplateModel FreeMarkerRenderer renderer, ELParser
parser, Logger logger,
+ TypesFactory typesFactory) {
+
+ super(renderer, "script-object");
+
+ this.parser = parser;
+ this.logger = logger;
+ this.typesFactory = typesFactory;
+ }
+
+ /**
+ * @return the keyExpression
+ */
+ public TemplateStatement getBaseExpression() {
+ return base;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ public ELType getType() {
+ return mapType;
+ }
+
+ public ELType getImplementationType() {
+ return mapImplementationType;
+ }
+
+ public void setObject(String name, String baseExpression) {
+ this.mapType = typesFactory.getType("Map<String, Object>");
+ this.mapImplementationType = typesFactory.getType("LinkedHashMap<String,
Object>");
+ this.name = name;
+
+ if (!Strings.isNullOrEmpty(baseExpression)) {
+ try {
+ this.base = parser.parse(baseExpression, this, getType());
+ base.setParent(this);
+ } catch (ParsingException e) {
+ logger.error("Error parse scriptObject statement expression",
e);
+ }
+ }
+
+ setVariable(name, getType());
+ }
+
+ @Override
+ public Iterable<JavaImport> getRequiredImports() {
+ return Iterables.concat(super.getRequiredImports(),
mapImplementationType.getRequiredImports(),
+ mapType.getRequiredImports(),
+ IMPORTS_TRANSFORM.apply(base));
+ }
+
+ @Override
+ public Iterable<HelperMethod> getRequiredMethods() {
+ return Iterables.concat(super.getRequiredMethods(),
+ METHODS_TRANSFORM.apply(base));
+ }
+
+ @Override
+ public Iterable<JavaField> getRequiredFields() {
+ return Iterables.concat(super.getRequiredFields(),
+ FIELDS_TRANSFORM.apply(base));
+ }
+}
Added:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static
org.richfaces.cdk.templatecompiler.builder.model.RequireImports.IMPORTS_TRANSFORM;
+import static
org.richfaces.cdk.templatecompiler.statements.TemplateStatement.FIELDS_TRANSFORM;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ScriptOptionStatement extends FreeMarkerTemplateStatementBase {
+
+ private String name;
+
+ private String defaultValue;
+
+ private TypedTemplateStatement value;
+
+ private String wrapper;
+
+ private ELParser parser;
+
+ private Logger logger;
+
+ @Inject
+ public ScriptOptionStatement(@TemplateModel FreeMarkerRenderer renderer, ELParser
parser, Logger logger) {
+ super(renderer, "script-option");
+
+ this.parser = parser;
+ this.logger = logger;
+ }
+
+ /**
+ * @param defaultValue the defaultValue to set
+ */
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @param value the value to set
+ */
+ public void setValueExpression(String valueExpression) {
+ try {
+ this.value = parser.parse(valueExpression, this, TypesFactory.OBJECT_TYPE);
+ } catch (ParsingException e) {
+ logger.error("Error parse scriptOption value expression: " +
valueExpression, e);
+ }
+ }
+
+ /**
+ * @param wrapper the wrapper to set
+ */
+ public void setWrapper(String wrapper) {
+ this.wrapper = wrapper;
+ }
+
+ @Override
+ public List<TemplateStatement> getStatements() {
+ return value != null ? Collections.<TemplateStatement>singletonList(value)
:
+ Collections.<TemplateStatement>emptyList();
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the value
+ */
+ public TypedTemplateStatement getValue() {
+ return value;
+ }
+
+ /**
+ * @return the defaultValue
+ */
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ /**
+ * @return the wrapper
+ */
+ public String getWrapper() {
+ return wrapper;
+ }
+
+ @Override
+ public Iterable<JavaField> getRequiredFields() {
+ return Iterables.concat(super.getRequiredFields(),
FIELDS_TRANSFORM.apply(value));
+ }
+
+ @Override
+ public Iterable<JavaImport> getRequiredImports() {
+ return Iterables.concat(super.getRequiredImports(),
IMPORTS_TRANSFORM.apply(value));
+ }
+
+ @Override
+ public Iterable<HelperMethod> getRequiredMethods() {
+ return Iterables.concat(super.getRequiredMethods(),
METHODS_TRANSFORM.apply(value));
+ }
+}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -3,17 +3,40 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import java.util.Collections;
+
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
import org.richfaces.cdk.templatecompiler.builder.model.JavaStatement;
import org.richfaces.cdk.templatecompiler.builder.model.RequireImports;
+import com.google.common.base.Function;
+
/**
* @author asmirnov
*
*/
public interface TemplateStatement extends JavaStatement, RequireImports {
+ public static final Function<TemplateStatement, Iterable<JavaField>>
FIELDS_TRANSFORM = new Function<TemplateStatement, Iterable<JavaField>>() {
+ public Iterable<JavaField> apply(TemplateStatement from) {
+ if (from == null) {
+ return Collections.emptyList();
+ }
+
+ return from.getRequiredFields();
+ };
+ };
+ public static final Function<TemplateStatement, Iterable<HelperMethod>>
METHODS_TRANSFORM = new Function<TemplateStatement, Iterable<HelperMethod>>()
{
+ public Iterable<HelperMethod> apply(TemplateStatement from) {
+ if (from == null) {
+ return Collections.emptyList();
+ }
+
+ return from.getRequiredMethods();
+ };
+ };
+
Iterable<JavaField> getRequiredFields();
Iterable<HelperMethod> getRequiredMethods();
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -22,17 +22,12 @@
package org.richfaces.cdk.templatecompiler.statements;
import java.util.Collection;
-import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
-import javax.xml.namespace.QName;
-
-import org.richfaces.cdk.attributes.Attribute.Kind;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
-import com.google.inject.internal.Sets;
/**
* @author Nick Belaevski
@@ -40,75 +35,6 @@
public class WriteAttributesSetStatement extends FreeMarkerTemplateStatementBase {
/**
- * <p class="changed_added_4_0">object contains information about
attribute</p>
- * @author asmirnov(a)exadel.com
- *
- */
- public static final class PassThrough implements Comparable<PassThrough> {
- QName name;
- Kind kind = Kind.GENERIC;
- String componentAttribute;
- String type;
- Object defaultValue;
- Set<String> behaviors = Sets.newHashSet();
-
- /**
- * <p class="changed_added_4_0"></p>
- * @return the name
- */
- public QName getName() {
- return this.name;
- }
- /**
- * <p class="changed_added_4_0"></p>
- * @return the kind
- */
- public Kind getKind() {
- return this.kind;
- }
- /**
- * <p class="changed_added_4_0"></p>
- * @return the componentAttribute
- */
- public String getComponentAttribute() {
- return this.componentAttribute;
- }
- /**
- * <p class="changed_added_4_0"></p>
- * @return the type
- */
- public String getType() {
- return this.type;
- }
- /**
- * <p class="changed_added_4_0"></p>
- * @return the defaultValue
- */
- public Object getDefaultValue() {
- return this.defaultValue;
- }
- /**
- * <p class="changed_added_4_0"></p>
- * @return the behaviors
- */
- public Set<String> getBehaviors() {
- return this.behaviors;
- }
- public String getBuilderMethod() {
- if(Kind.BOOLEAN.equals(kind)){
- return "bool";
- } else {
- return kind.toString().toLowerCase();
- }
- }
- @Override
-
- public int compareTo(PassThrough o) {
- return name.toString().compareTo(o.name.toString());
- }
- }
-
- /**
*
*/
private static final String PASS_THROUGH_ATTRIBUTES_FIELD_NAME =
"PASS_THROUGH_ATTRIBUTES";
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/util/JavaUtils.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/util/JavaUtils.java 2010-10-22
16:54:29 UTC (rev 19656)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/util/JavaUtils.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -31,6 +31,7 @@
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.xmlconfig.JAXBBinding;
+import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
/**
@@ -43,6 +44,12 @@
Character.class).put(Byte.TYPE, Byte.class).put(Short.TYPE,
Short.class).put(Integer.TYPE, Integer.class)
.put(Long.TYPE, Long.class).put(Float.TYPE, Float.class).put(Double.TYPE,
Double.class).build();
+ public static final Function<Class<?>, String> CLASS_TO_CLASS_NAME = new
Function<Class<?>, String>() {
+ public String apply(java.lang.Class<?> from) {
+ return from.getName();
+ }
+ };
+
private JavaUtils() {
// private constructor
}
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/util/Strings.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/util/Strings.java 2010-10-22
16:54:29 UTC (rev 19656)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/util/Strings.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -23,12 +23,20 @@
package org.richfaces.cdk.util;
+import java.util.NoSuchElementException;
+
+import com.google.common.base.Joiner;
+
+
/**
* <p class="changed_added_4_0">String manipulation utils.</p>
*
* @author asmirnov(a)exadel.com
*/
public final class Strings {
+
+ public static final Joiner DOT_JOINER = Joiner.on('.');
+
private Strings() {
// this is utility class with static methods only.
@@ -88,4 +96,14 @@
public static boolean isEmpty(String type) {
return type == null || type.length() == 0;
}
+
+ public static String firstNonEmpty(String... strings) {
+ for (String s : strings) {
+ if (!isEmpty(s)) {
+ return s;
+ }
+ }
+
+ throw new NoSuchElementException();
+ }
}
Modified: trunk/cdk/generator/src/main/resources/META-INF/schema/cdk-template.xsd
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2010-10-22
16:54:29 UTC (rev 19656)
+++ trunk/cdk/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2010-10-24
19:11:47 UTC (rev 19657)
@@ -582,4 +582,39 @@
<xs:attribute name="key" use="required"
form="unqualified" type="c:elStrictExpression" />
</xs:complexType>
</xs:element>
+
+ <xs:element name="import">
+ <xs:complexType>
+ <xs:attribute type="xs:string" use="required"
name="package" />
+ <xs:attribute type="xs:NMTOKENS" name="names" />
+ <xs:attribute type="xs:boolean" name="static" />
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="scriptObject">
+ <xs:complexType>
+ <xs:attribute type="xs:string" name="name"
use="required" />
+ <xs:attribute type="c:elStrictExpression" name="base"
/>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:element name="scriptOption">
+ <xs:complexType>
+ <xs:attribute type="xs:NMTOKENS" name="attributes"
/>
+ <xs:attribute type="xs:NMTOKENS" name="variables"
/>
+ <xs:attribute type="xs:string" name="name" />
+ <xs:attribute type="c:elFreeformExpression"
name="value" />
+ <xs:attribute type="c:literalExpression"
name="defaultValue" />
+ <xs:attribute name="wrapper">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:enumeration value="noop" />
+ <xs:enumeration value="asArray" />
+ <xs:enumeration value="eventHandler" />
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:attribute>
+ </xs:complexType>
+ </xs:element>
+
</xs:schema>
Added:
trunk/cdk/generator/src/main/resources/META-INF/templates/java/add-attributes-to-script-hash.ftl
===================================================================
---
trunk/cdk/generator/src/main/resources/META-INF/templates/java/add-attributes-to-script-hash.ftl
(rev 0)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates/java/add-attributes-to-script-hash.ftl 2010-10-24
19:11:47 UTC (rev 19657)
@@ -0,0 +1,5 @@
+<(a)util.require "ADD_TO_SCRIPT_HASH_ATTRIBUTES"/>
+
+<(a)util.attributesField "${fieldName}" attributes />
+
+${ADD_TO_SCRIPT_HASH_ATTRIBUTES}(${parent.name}, ${facesContextVariable},
${componentVariable}, ${fieldName}, <#if
wrapper?exists>${wrapper}<#else>null</#if>);
\ No newline at end of file
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates/java/class.ftl
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates/java/class.ftl 2010-10-22
16:54:29 UTC (rev 19656)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates/java/class.ftl 2010-10-24
19:11:47 UTC (rev 19657)
@@ -1,7 +1,7 @@
package ${package.name};
<#list imports as import><#if !import.default >
-import ${import.name};
+import<#if import.static> static</#if> ${import.name};
</#if></#list>
<@renderCommonJavaElementStuff element=.data_model />class ${simpleName} <#if
superClass.name != 'java.lang.Object'>extends ${superClass.simpleName}
</#if>{
Added: trunk/cdk/generator/src/main/resources/META-INF/templates/java/script-object.ftl
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates/java/script-object.ftl
(rev 0)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates/java/script-object.ftl 2010-10-24
19:11:47 UTC (rev 19657)
@@ -0,0 +1,4 @@
+${type} ${name} = new ${implementationType}(<#if base?exists>${base}</#if>);
+<#list statements as subStatement>
+${subStatement.code}
+</#list>
\ No newline at end of file
Added: trunk/cdk/generator/src/main/resources/META-INF/templates/java/script-option.ftl
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates/java/script-option.ftl
(rev 0)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates/java/script-option.ftl 2010-10-24
19:11:47 UTC (rev 19657)
@@ -0,0 +1,2 @@
+<(a)util.require "ADD_TO_SCRIPT_HASH" />
+${ADD_TO_SCRIPT_HASH}(${parent.name}, "${name}", ${value}, <#if
defaultValue?exists>${defaultValue}<#else>null</#if>, <#if
wrapper?exists>ScriptHashVariableWrapper.${wrapper}<#else>null</#if>);
Modified: trunk/cdk/generator/src/main/resources/META-INF/templates/java/util.ftl
===================================================================
--- trunk/cdk/generator/src/main/resources/META-INF/templates/java/util.ftl 2010-10-22
16:54:29 UTC (rev 19656)
+++ trunk/cdk/generator/src/main/resources/META-INF/templates/java/util.ftl 2010-10-24
19:11:47 UTC (rev 19657)
@@ -3,3 +3,10 @@
<#macro import name>${addImport(name)}</#macro>
<#macro concat seq delimiter=","><#list seq as item><#nested
item/><#if item_has_next>${delimiter}</#if></#list></#macro>
+<#macro attributesField fieldName attributes>
+ <@require "CREATE_ATTRIBUTES"/>
+ <@constant "Attributes"
"${fieldName}">${CREATE_ATTRIBUTES}()<#list attributes as attribute>
+
.${attribute.builderMethod}("${attribute.name}","${attribute.componentAttribute}"<#list
attribute.behaviors as behavior>,"${behavior}"</#list>)
+ <#if attribute.defaultValue?exists
>.defaultValue("${attribute.defaultValue}")</#if>
+ </#list></@constant>
+</#macro>
Modified:
trunk/cdk/generator/src/main/resources/META-INF/templates/java/write-attributes-set.ftl
===================================================================
---
trunk/cdk/generator/src/main/resources/META-INF/templates/java/write-attributes-set.ftl 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/main/resources/META-INF/templates/java/write-attributes-set.ftl 2010-10-24
19:11:47 UTC (rev 19657)
@@ -1,7 +1,6 @@
-<(a)util.require "RENDER_ATTRIBUTES_SET"/><(a)util.require
"CREATE_ATTRIBUTES"/>
-<(a)util.constant "Attributes"
"${fieldName}">${CREATE_ATTRIBUTES}()<#list attributes as attribute>
-
.${attribute.builderMethod}("${attribute.name}","${attribute.componentAttribute}"<#list
attribute.behaviors as behavior>,"${behavior}"</#list>)
- <#if attribute.defaultValue?exists
>.defaultValue("${attribute.defaultValue}")</#if>
-</#list></(a)util.constant>
+<(a)util.require "RENDER_ATTRIBUTES_SET"/>
+
+<(a)util.attributesField "${fieldName}" attributes />
+
${RENDER_ATTRIBUTES_SET}(${facesContextVariable}, ${componentVariable},
${fieldName});
\ No newline at end of file
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -23,8 +23,14 @@
package org.richfaces.cdk.templatecompiler.model;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
import org.junit.Test;
@@ -32,6 +38,8 @@
import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.xmlconfig.JaxbTestBase;
+import com.google.common.collect.Iterables;
+
/**
* <p class="changed_added_4_0">
* </p>
@@ -230,7 +238,11 @@
+
"<cdk:component-family>org.richfaces.TreeFamily</cdk:component-family>"
+
"<cdk:renderer-type>org.richfaces.TreeRenderer</cdk:renderer-type>"
+ "<cdk:renderkit-id>RF4_XHTML</cdk:renderkit-id>"
- +
"<cdk:renders-children>false</cdk:renders-children>" +
TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
+ +
"<cdk:renders-children>false</cdk:renders-children>"
+ + "<cdk:import package=\"com.foo\" names=\"Bar
Fooz\" />"
+ + "<cdk:import package=\"net.foo\"
names=\"Field\" static=\"true\" />"
+ + "<cdk:import package=\"org.foo\"
names=\"*\" />"
+ + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
CompositeInterface interfaceSection = template.getInterface();
assertNotNull(interfaceSection);
@@ -242,6 +254,28 @@
assertEquals("RF4_XHTML", interfaceSection.getRenderKitId());
assertEquals(Boolean.FALSE, interfaceSection.getRendersChildren());
+ List<ClassImport> classImports = interfaceSection.getClassImports();
+
+ ClassImport importElement;
+
+ Iterator<ClassImport> children = classImports.iterator();
+
+ importElement = children.next();
+ assertEquals("com.foo", importElement.getPackage());
+ assertEquals(Arrays.asList("Bar", "Fooz"),
importElement.getNames());
+ assertFalse(importElement.isStatic());
+
+ importElement = children.next();
+ assertEquals("net.foo", importElement.getPackage());
+ assertEquals(Arrays.asList("Field"), importElement.getNames());
+ assertTrue(importElement.isStatic());
+
+ importElement = children.next();
+ assertEquals("org.foo", importElement.getPackage());
+ assertEquals(Arrays.asList("*"), importElement.getNames());
+ assertFalse(importElement.isStatic());
+
+ assertFalse(children.hasNext());
}
@Test
@@ -397,4 +431,51 @@
assertNotNull(template.getInterface());
assertNotNull(template.getImplementation());
}
+
+ @Test
+ public void testScriptObject() throws Exception {
+ Template template =
+ unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE
+ + "<cdk:scriptObject name=\"hash\"
base=\"#{getBaseOptions(context)}\">"
+ + "<cdk:scriptOption name=\"name\"
value=\"#{value}\" />"
+ + "<cdk:scriptOption name=\"delay\"
value=\"#{delay}\" defaultValue=\"100\" />"
+ + "<cdk:scriptOption name=\"rowClasses\"
value=\"#{rowClasses}\" wrapper=\"asArray\" />"
+ + "<cdk:scriptOption attributes=\"min max\"
/>"
+ + "<cdk:scriptOption variables=\"allowHeader
allowFooter\" />"
+ + "</cdk:scriptObject>" +
+
+ TEMPLATE_EPILOG);
+
+ CompositeImplementation implementation = template.getImplementation();
+ assertNotNull(implementation);
+
+ CdkScriptObjectElement scriptObject = (CdkScriptObjectElement)
Iterables.getOnlyElement(implementation.getChildren());
+ assertEquals("hash", scriptObject.getName());
+ assertEquals("#{getBaseOptions(context)}", scriptObject.getBase());
+
+ CdkScriptOptionElement scriptOption;
+ Iterator<Object> children = scriptObject.getChildren().iterator();
+
+ scriptOption = (CdkScriptOptionElement) children.next();
+ assertEquals("name", scriptOption.getName());
+ assertEquals("#{value}", scriptOption.getValue());
+
+ scriptOption = (CdkScriptOptionElement) children.next();
+ assertEquals("delay", scriptOption.getName());
+ assertEquals("#{delay}", scriptOption.getValue());
+ assertEquals("100", scriptOption.getDefaultValue());
+
+ scriptOption = (CdkScriptOptionElement) children.next();
+ assertEquals("rowClasses", scriptOption.getName());
+ assertEquals("#{rowClasses}", scriptOption.getValue());
+ assertEquals("asArray", scriptOption.getWrapper());
+
+ scriptOption = (CdkScriptOptionElement) children.next();
+ assertEquals(Arrays.asList("min", "max"),
scriptOption.getAttributes());
+
+ scriptOption = (CdkScriptOptionElement) children.next();
+ assertEquals(Arrays.asList("allowHeader", "allowFooter"),
scriptOption.getVariables());
+
+ assertFalse(children.hasNext());
+ }
}
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -21,9 +21,14 @@
package org.richfaces.cdk.templatecompiler.parser.el.test;
-import static org.junit.Assert.*;
-import static org.easymock.EasyMock.*;
-import static org.richfaces.cdk.templatecompiler.statements.HelperMethod.*;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static
org.richfaces.cdk.templatecompiler.statements.HelperMethod.EMPTINESS_CHECK;
+import static org.richfaces.cdk.templatecompiler.statements.HelperMethod.EQUALS_CHECK;
+import static
org.richfaces.cdk.templatecompiler.statements.HelperMethod.TO_BOOLEAN_CONVERSION;
+import static
org.richfaces.cdk.templatecompiler.statements.HelperMethod.TO_STRING_CONVERSION;
import java.util.HashMap;
import java.util.List;
@@ -668,4 +673,12 @@
assertEquals("\"Literal\"",parseExpression.getCode());
assertEquals(String.class.getName(), parseExpression.getType().getRawName());
}
+
+ @Test
+ public void testToScriptArgs() throws Exception {
+ TypedTemplateStatement parseExpression =
parseExpression("#{toScriptArgs(clientId, bean)}");
+
+ assertTrue(Iterables.contains(parseExpression.getRequiredMethods(),
HelperMethod.TO_SCRIPT_ARGS));
+ assertEquals("toScriptArgs(clientId,bean)",
parseExpression.getCode());
+ }
}
Added:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashTest.java
(rev 0)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashTest.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -0,0 +1,92 @@
+/*
+ * $Id$
+ *
+ * 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.richfaces.cdk.templatecompiler.statements;
+
+import java.util.Collections;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkClassLoader;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.model.PropertyBase;
+import org.richfaces.cdk.model.PropertyModel;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactoryImpl;
+
+import com.google.common.collect.Iterables;
+import com.google.inject.Binder;
+import com.google.inject.Inject;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+(a)RunWith(CdkTestRunner.class)
+public class AddAttributesToScriptHashTest extends FreeMarkerTestBase {
+
+ @Inject
+ private TypesFactory typesFactory;
+
+ @Inject
+ private ScriptObjectStatement parentStatement;
+
+ @Inject
+ private AddAttributesToScriptHashStatement statement;
+
+ @Override
+ public void configure(Binder binder) {
+ super.configure(binder);
+ binder.bind(TypesFactory.class).to(TypesFactoryImpl.class);
+ binder.bind(CdkClassLoader.class).toInstance(createClassLoader());
+ }
+
+ /**
+ * Test method for {@link
org.richfaces.cdk.templatecompiler.statements.FreeMarkerTemplateStatementBase#getCode()}.
+ */
+ @Test
+ public void testGetCode() {
+ statement.setParent(parentStatement);
+ parentStatement.setObject("hash", null);
+
+ PropertyBase property = new PropertyModel();
+ property.setName("bar");
+ property.setDefaultValue("deflt");
+ property.setType(ClassName.get(String.class));
+
+ controller.replay();
+ statement.setAttributes(Collections.singleton("bar"),
Collections.singleton(property));
+ String code = statement.getCode();
+ controller.verify();
+ verifyCode(code, "!attributes()", "!defaultValue(",
"!if(", "");
+ verifyHelpers(statement, HelperMethod.CREATE_ATTRIBUTES,
HelperMethod.ADD_TO_SCRIPT_HASH_ATTRIBUTES);
+ JavaField javaField = Iterables.getOnlyElement(statement.getRequiredFields());
+ verifyCode(javaField.getValue().getCode(), "attributes()",
"generic(", "defaultValue(");
+ }
+
+}
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -1,7 +1,7 @@
package org.richfaces.cdk.templatecompiler.statements;
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.*;
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
import java.util.Collections;
@@ -15,7 +15,7 @@
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
-import org.richfaces.cdk.templatecompiler.builder.model.RuntimeImport;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImportImpl;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import com.google.common.collect.Iterables;
@@ -64,7 +64,7 @@
public void testGetRequiredImports() {
freeMarkerStatement.addImport("foo.Bar");
expect(statement.getRequiredImports()).andStubReturn(
- Collections.<JavaImport> singleton(new
RuntimeImport("foo.baz")));
+ Collections.<JavaImport> singleton(new
JavaImportImpl("foo.baz")));
expect(renderer.renderTemplate("foo.ftl",
freeMarkerStatement)).andReturn(FOO_CODE);
controller.replay();
freeMarkerStatement.addStatement(statement);
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetTest.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetTest.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -55,7 +55,7 @@
*/
@Test
public void testGetCode() {
- WriteAttributesSetStatement.PassThrough passThrough = new
WriteAttributesSetStatement.PassThrough();
+ PassThrough passThrough = new PassThrough();
passThrough.name = QName.valueOf("foo");
passThrough.type = "String";
passThrough.componentAttribute = "bar";
Deleted: trunk/core/impl/src/main/java/org/richfaces/component/util/ComponentUtil.java
===================================================================
---
trunk/core/impl/src/main/java/org/richfaces/component/util/ComponentUtil.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/core/impl/src/main/java/org/richfaces/component/util/ComponentUtil.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -1,83 +0,0 @@
-/**
- * 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.richfaces.component.util;
-
-import java.util.Collection;
-import java.util.Iterator;
-
-/**
- * @author Nick Belaevski
- * mailto:nbelaevski@exadel.com
- * created 20.07.2007
- */
-public final class ComponentUtil {
- private ComponentUtil() {
- }
-
- public static String[] asArray(Object object) {
- if (object == null) {
- return null;
- }
-
- Class componentType = object.getClass().getComponentType();
-
- if (String.class.equals(componentType)) {
- return (String[]) object;
- } else if (componentType != null) {
- Object[] objects = (Object[]) object;
- String[] result = new String[objects.length];
-
- for (int i = 0; i < objects.length; i++) {
- Object o = objects[i];
-
- if (o == null) {
- continue;
- }
-
- result[i] = o.toString();
- }
-
- return result;
- } else if (object instanceof Collection) {
- Collection collection = (Collection) object;
- String[] result = new String[collection.size()];
- Iterator iterator = collection.iterator();
-
- for (int i = 0; i < result.length; i++) {
- Object next = iterator.next();
-
- if (next == null) {
- continue;
- }
-
- result[i] = next.toString();
- }
-
- return result;
- } else {
- String string = object.toString().trim();
- String[] split = string.split("\\s*,\\s*");
-
- return split;
- }
- }
-}
Deleted:
trunk/core/impl/src/test/java/org/richfaces/component/util/ComponentUtilTest.java
===================================================================
---
trunk/core/impl/src/test/java/org/richfaces/component/util/ComponentUtilTest.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/core/impl/src/test/java/org/richfaces/component/util/ComponentUtilTest.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -1,93 +0,0 @@
-/**
- * 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.richfaces.component.util;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Set;
-import java.util.TreeSet;
-
-import junit.framework.TestCase;
-
-/**
- * @author Nick Belaevski
- * mailto:nbelaevski@exadel.com
- * created 20.07.2007
- *
- */
-public class ComponentUtilTest extends TestCase {
- public void testAsArray() {
- assertNull(ComponentUtil.asArray(null));
- }
-
- public void testAsArray1() {
- String[] strings = new String[] {"a", "b"};
- String[] array = ComponentUtil.asArray(strings);
-
- assertSame(strings, array);
- }
-
- public void testAsArray2() {
- Object[] objects = new Object[] {Integer.valueOf(12), null, Integer.valueOf(22),
Integer.valueOf(42)};
- String[] array = ComponentUtil.asArray(objects);
- String[] etalon = new String[] {"12", null, "22",
"42"};
-
- assertTrue(Arrays.equals(etalon, array));
- }
-
- public void testAsArray3() {
- ArrayList list = new ArrayList();
-
- list.add(new Integer(12));
- list.add(null);
- list.add(new Integer(22));
- list.add(new Integer(42));
-
- String[] array = ComponentUtil.asArray(list);
- String[] etalon = new String[] {"12", null, "22",
"42"};
-
- assertTrue(Arrays.equals(etalon, array));
- }
-
- public void testAsArray31() {
- Set set = new TreeSet();
-
- set.add(new Integer(12));
- set.add(new Integer(22));
- set.add(new Integer(42));
-
- String[] array = ComponentUtil.asArray(set);
- String[] etalon = new String[] {"12", "22", "42"};
-
- assertTrue(Arrays.equals(etalon, array));
- }
-
- public void testAsArray4() {
- String string = " a , \t\n b \n , c ";
- String[] strings = ComponentUtil.asArray(string);
- String[] etalon = new String[] {"a", "b", "c"};
-
- assertTrue(Arrays.equals(etalon, strings));
- }
-}
Modified: trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
===================================================================
---
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -22,10 +22,12 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -41,6 +43,8 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.javascript.ScriptUtils;
import org.richfaces.renderkit.ComponentAttribute.Kind;
/**
@@ -82,10 +86,115 @@
private static final String DISABLED_ATTRIBUTE_NAME = "disabled";
+ /**
+ * Wrapper class around object value used to transform values into particular JS
objects
+ *
+ * @author Nick Belaevski
+ * @since 3.3.2
+ */
+ public enum ScriptHashVariableWrapper {
+
+ /**
+ * No-op default wrapper
+ */
+ noop {
+
+ @Override
+ Object wrap(Object o) {
+ return o;
+ }
+
+ },
+
+
+ /**
+ * Convert parameter to array of srings.
+ */
+ asArray {
+
+ @Override
+ Object wrap(Object o) {
+ return asArray(o);
+ }
+
+ },
+
+ /**
+ * Event handler functions wrapper. Wraps <pre>functionCode</pre>
object into:
+ * <pre>function(event) {
+ * functionCode
+ * }</pre>
+ */
+ eventHandler {
+
+ @Override
+ Object wrap(Object o) {
+ return new JSFunctionDefinition("event").addToBody(o);
+ }
+
+ };
+
+ /**
+ * Method that does the wrapping
+ *
+ * @param o object to wrap
+ * @return wrapped object
+ */
+ abstract Object wrap(Object o);
+ }
+
private RenderKitUtils() {
// utility constructor
}
+ static String[] asArray(Object object) {
+ if (object == null) {
+ return null;
+ }
+
+ Class<?> componentType = object.getClass().getComponentType();
+
+ if (String.class.equals(componentType)) {
+ return (String[]) object;
+ } else if (componentType != null) {
+ Object[] objects = (Object[]) object;
+ String[] result = new String[objects.length];
+
+ for (int i = 0; i < objects.length; i++) {
+ Object o = objects[i];
+
+ if (o == null) {
+ continue;
+ }
+
+ result[i] = o.toString();
+ }
+
+ return result;
+ } else if (object instanceof Collection) {
+ Collection<?> collection = (Collection<?>) object;
+ String[] result = new String[collection.size()];
+ Iterator<?> iterator = collection.iterator();
+
+ for (int i = 0; i < result.length; i++) {
+ Object next = iterator.next();
+
+ if (next == null) {
+ continue;
+ }
+
+ result[i] = next.toString();
+ }
+
+ return result;
+ } else {
+ String string = object.toString().trim();
+ String[] split = string.split("\\s*,\\s*");
+
+ return split;
+ }
+ }
+
private static Map<String, List<ClientBehavior>>
getClientBehaviorsMap(UIComponent component) {
Map<String, List<ClientBehavior>> result;
if (component instanceof ClientBehaviorHolder) {
@@ -196,6 +305,7 @@
}
public static boolean shouldRenderAttribute(Object attributeValue) {
+ //TODO - consider required attributes with "" value (like
'alt')
if (attributeValue == null) {
return false;
} else if (attributeValue instanceof String) {
@@ -422,6 +532,148 @@
return res;
}
+ /**
+ * Checks if the argument passed in is empty or not.
+ * Object is empty if it is: <br />
+ * - <code>null<code><br />
+ * - zero-length string<br />
+ * - empty collection<br />
+ * - empty map<br />
+ * - zero-length array<br />
+ *
+ * @param o object to check for emptiness
+ * @since 3.3.2
+ * @return <code>true</code> if the argument is empty,
<code>false</code> otherwise
+ */
+ private static boolean isEmpty(Object o) {
+ if (null == o) {
+ return true;
+ }
+ if (o instanceof String ) {
+ return (0 == ((String)o).length());
+ }
+ if (o instanceof Collection) {
+ return ((Collection<?>)o).isEmpty();
+ }
+ if (o instanceof Map) {
+ return ((Map<?, ?>)o).isEmpty();
+ }
+ if (o.getClass().isArray()) {
+ return Array.getLength(o) == 0;
+ }
+ return false;
+ }
+
+ public static void addToScriptHash(Map<String, Object> hash,
+ String name,
+ Object value) {
+
+ addToScriptHash(hash, name, value, null, null);
+ }
+
+ public static void addToScriptHash(Map<String, Object> hash,
+ String name,
+ Object value,
+ Object defaultValue) {
+
+ addToScriptHash(hash, name, value, defaultValue, null);
+ }
+
+ /**
+ * Puts value into map under specified key if the value is not empty and not default.
+ * Performs optional value wrapping.
+ *
+ * @param hash
+ * @param name
+ * @param value
+ * @param defaultValue
+ * @param wrapper
+ *
+ * @since 3.3.2
+ */
+ public static void addToScriptHash(Map<String, Object> hash,
+ String name,
+ Object value,
+ Object defaultValue,
+ ScriptHashVariableWrapper wrapper) {
+
+ ScriptHashVariableWrapper wrapperOrDefault = wrapper != null ? wrapper :
ScriptHashVariableWrapper.noop;
+
+ if (!isEmpty(value) && shouldRenderAttribute(value)) {
+ if (defaultValue != null) {
+ if (!String.valueOf(defaultValue).equals(value.toString())) {
+ hash.put(name, wrapperOrDefault.wrap(value));
+ }
+ } else {
+ if (!(value instanceof Boolean) || ((Boolean) value).booleanValue()) {
+ hash.put(name, wrapperOrDefault.wrap(value));
+ }
+ }
+ }
+ }
+
+ public static void addToScriptHash(Map<String, Object> hash, FacesContext
facesContext, UIComponent component,
+ Attributes attributes, ScriptHashVariableWrapper wrapper) {
+
+ boolean disabled = isDisabled(component);
+ for (ComponentAttribute knownAttribute : attributes) {
+ if (!disabled || knownAttribute.getEventNames().length == 0) {
+ String attributeName = knownAttribute.getComponentAttributeName();
+ addToScriptHash(hash, attributeName,
+ getAttributeAndBehaviorsValue(facesContext, component,
knownAttribute),
+ knownAttribute.getDefaultValue(), wrapper);
+ }
+ }
+ }
+
+ public static String concat(String... strings) {
+ if (strings == null) {
+ return "";
+ }
+
+ StringBuilder sb = new StringBuilder();
+ for (String s : strings) {
+ if (s == null || s.length() == 0) {
+ continue;
+ }
+
+ sb.append(s);
+ }
+ return sb.toString();
+ }
+
+ public static String toScriptArgs(Object... objects) {
+ if (objects == null) {
+ return "";
+ }
+
+ int lastNonNullIdx = objects.length - 1;
+ for (; 0 <= lastNonNullIdx; lastNonNullIdx--) {
+ if (!isEmpty(objects[lastNonNullIdx])) {
+ break;
+ }
+ }
+
+ if (lastNonNullIdx < 0) {
+ return "";
+ }
+
+ if (lastNonNullIdx == 0) {
+ return ScriptUtils.toScript(objects[lastNonNullIdx]);
+ }
+
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i <= lastNonNullIdx; i++) {
+ if (sb.length() > 0) {
+ sb.append(",");
+ }
+
+ sb.append(ScriptUtils.toScript(objects[i]));
+ }
+
+ return sb.toString();
+ }
+
@SuppressWarnings("serial")
public static final class Attributes extends TreeSet<ComponentAttribute> {
Modified:
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/util/RendererUtils.java
===================================================================
---
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/util/RendererUtils.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/common/ui/src/main/java/org/richfaces/renderkit/util/RendererUtils.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -28,11 +28,9 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Set;
import javax.faces.FacesException;
import javax.faces.application.ViewHandler;
@@ -51,10 +49,9 @@
import org.ajax4jsf.Messages;
import org.ajax4jsf.component.JavaScriptParameter;
-import org.ajax4jsf.javascript.JSEncoder;
-import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.ajax4jsf.javascript.JSReference;
import org.richfaces.renderkit.HtmlConstants;
+import org.richfaces.renderkit.RenderKitUtils;
/**
* Util class for common render operations - render passthru html attributes,
@@ -76,12 +73,8 @@
*/
private static final Map<String, String> SUBSTITUTIONS = new HashMap<String,
String>();
- private static final Set<String> REQUIRED_ATTRIBUTES = new
HashSet<String>();
-
static {
SUBSTITUTIONS.put(HtmlConstants.CLASS_ATTRIBUTE, "styleClass");
-
- REQUIRED_ATTRIBUTES.add(HtmlConstants.ALT_ATTRIBUTE);
Arrays.sort(HtmlConstants.PASS_THRU);
Arrays.sort(HtmlConstants.PASS_THRU_EVENTS);
@@ -96,46 +89,6 @@
}
/**
- * Wrapper class around object value used to transform values into particular JS
objects
- *
- * @author Nick Belaevski
- * @since 3.3.2
- */
- public static enum ScriptHashVariableWrapper {
-
- /**
- * No-op default wrapper
- */
- DEFAULT {
- @Override
- Object wrap(Object o) {
- return o;
- }
- },
-
- /**
- * Event handler functions wrapper. Wraps <pre>functionCode</pre>
object into:
- * <pre>function(event) {
- * functionCode
- * }</pre>
- */
- EVENT_HANDLER {
- @Override
- Object wrap(Object o) {
- return new JSFunctionDefinition("event").addToBody(o);
- }
- };
-
- /**
- * Method that does the wrapping
- *
- * @param o object to wrap
- * @return wrapped object
- */
- abstract Object wrap(Object o);
- }
-
- /**
* Use this method to get singleton instance of RendererUtils
* @return singleton instance
*/
@@ -360,7 +313,7 @@
Object value = attributeValue(attribute,
attributes.get(getComponentAttributeName(attribute)));
- if ((null != value) && shouldRenderAttribute(attribute, value)) {
+ if ((null != value) && RenderKitUtils.shouldRenderAttribute(value)) {
if (Arrays.binarySearch(HtmlConstants.PASS_THRU_URI, attribute) >= 0) {
String url =
context.getApplication().getViewHandler().getResourceURL(context, value.toString());
@@ -418,7 +371,7 @@
ResponseWriter writer = context.getResponseWriter();
Object value = component.getAttributes().get(property);
- if (shouldRenderAttribute(attributeName, value)) {
+ if (RenderKitUtils.shouldRenderAttribute(value)) {
writer.writeAttribute(attributeName, value, property.toString());
}
}
@@ -428,81 +381,6 @@
}
/**
- * Write html-attribute
- *
- * @param writer
- * @param attribute
- * @param value
- * @throws IOException
- */
- public void writeAttribute(ResponseWriter writer, String attribute, Object value)
throws IOException {
- if (shouldRenderAttribute(attribute, value)) {
- writer.writeAttribute(attribute, value.toString(), attribute);
- }
- }
-
- /**
- * @return true if and only if the argument <code>attributeVal</code> is
- * an instance of a wrapper for a primitive type and its value is
- * equal to the default value for that type as given in the spec.
- */
- public boolean shouldRenderAttribute(Object attributeVal) {
- if (null == attributeVal) {
- return false;
- } else if ((attributeVal instanceof Boolean)
- && ((Boolean) attributeVal).booleanValue() ==
Boolean.FALSE.booleanValue()) {
- return false;
- } else if (attributeVal.toString().length() == 0) {
- return false;
- } else {
- return isValidProperty(attributeVal);
- }
- }
-
- public boolean shouldRenderAttribute(String attributeName, Object attributeVal) {
- if (REQUIRED_ATTRIBUTES.contains(attributeName)) {
- if (attributeVal == null) {
- return false;
- }
- } else {
- return shouldRenderAttribute(attributeVal);
- }
-
- return true;
- }
-
- /**
- * Test for valid value of property. by default, for non-setted properties
- * with Java primitive types of JSF component return appropriate MIN_VALUE .
- *
- * @param property -
- * value of property returned from
- * {@link UIComponent#getAttributes()}
- * @return true for setted property, false otherthise.
- */
- public boolean isValidProperty(Object property) {
- if (null == property) {
- return false;
- } else if ((property instanceof Integer) && ((Integer)
property).intValue() == Integer.MIN_VALUE) {
- return false;
- } else if ((property instanceof Double) && ((Double)
property).doubleValue() == Double.MIN_VALUE) {
- return false;
- } else if ((property instanceof Character) && ((Character)
property).charValue() == Character.MIN_VALUE) {
- return false;
- } else if ((property instanceof Float) && ((Float) property).floatValue()
== Float.MIN_VALUE) {
- return false;
- } else if ((property instanceof Short) && ((Short) property).shortValue()
== Short.MIN_VALUE) {
- return false;
- } else if ((property instanceof Byte) && ((Byte) property).byteValue() ==
Byte.MIN_VALUE) {
- return false;
- } else if ((property instanceof Long) && ((Long) property).longValue() ==
Long.MIN_VALUE) {
- return false;
- }
-
- return true;
- }
-
- /**
* Checks if the argument passed in is empty or not.
* Object is empty if it is: <br />
* - <code>null</code><br />
@@ -540,64 +418,6 @@
}
/**
- * Puts value into map under specified key if the value is not empty and not
default.
- * Performs optional value wrapping.
- *
- * @param hash
- * @param name
- * @param value
- * @param defaultValue
- * @param wrapper
- *
- * @since 3.3.2
- */
- public void addToScriptHash(Map<String, Object> hash, String name, Object
value, String defaultValue,
- ScriptHashVariableWrapper wrapper) {
- ScriptHashVariableWrapper wrapperOrDefault = (wrapper != null) ? wrapper :
ScriptHashVariableWrapper.DEFAULT;
-
- if (isValidProperty(value) && !isEmpty(value)) {
- if (!isEmpty(defaultValue)) {
- if (!defaultValue.equals(value.toString())) {
- hash.put(name, wrapperOrDefault.wrap(value));
- }
- } else {
- if (!(value instanceof Boolean) || ((Boolean) value).booleanValue()) {
- hash.put(name, wrapperOrDefault.wrap(value));
- }
- }
- }
- }
-
- /**
- * Puts value into map under specified key if the value is not empty and not
default.
- * Performs optional value wrapping.
- *
- * @param hash
- * @param name
- * @param value
- * @param defaultValue
- *
- * @since 3.3.2
- */
- public void addToScriptHash(Map<String, Object> hash, String name, Object
value, String defaultValue) {
- addToScriptHash(hash, name, value, defaultValue, null);
- }
-
- /**
- * Puts value into map under specified key if the value is not empty and not
default.
- * Performs optional value wrapping.
- *
- * @param hash
- * @param name
- * @param value
- *
- * @since 3.3.2
- */
- public void addToScriptHash(Map<String, Object> hash, String name, Object
value) {
- addToScriptHash(hash, name, value, null, null);
- }
-
- /**
* Convert HTML attribute name to component property name.
*
* @param key
@@ -916,83 +736,6 @@
return forAttr;
}
- public static void writeEventHandlerFunction(FacesContext context, UIComponent
component, String eventName)
- throws IOException {
-
- ResponseWriter writer = context.getResponseWriter();
- Object script = component.getAttributes().get(eventName);
-
- if ((script != null) && !script.equals("")) {
- JSFunctionDefinition onEventDefinition = new JSFunctionDefinition();
-
- onEventDefinition.addParameter("event");
- onEventDefinition.addToBody(script);
- writer.writeText(eventName + ": " + onEventDefinition.toScript(),
null);
- } else {
- writer.writeText(eventName + ": ''", null);
- }
- }
-
- public JSFunctionDefinition getAsEventHandler(FacesContext context, UIComponent
component, String attributeName,
- String append) {
- String event = (String) component.getAttributes().get(attributeName);
-
- if (event != null) {
- event = event.trim();
-
- if (event.length() != 0) {
- JSFunctionDefinition function = new JSFunctionDefinition();
-
- function.addParameter("event");
-
- if ((null != append) && (append.length() > 0)) {
- function.addToBody(event + append);
- } else {
- function.addToBody(event);
- }
-
- return function;
- }
- }
-
- return null;
- }
-
- public String escapeJavaScript(Object o) {
- if (o != null) {
- StringBuilder result = new StringBuilder();
- JSEncoder encoder = new JSEncoder();
- char[] chars = o.toString().toCharArray();
- int start = 0;
- int end = chars.length;
-
- for (int x = start; x < end; x++) {
- char c = chars[x];
-
- if (encoder.compile(c)) {
- continue;
- }
-
- if (start != x) {
- result.append(chars, start, x - start);
- }
-
- result.append(encoder.encode(c));
- start = x + 1;
-
- continue;
- }
-
- if (start != end) {
- result.append(chars, start, end - start);
- }
-
- return result.toString();
- } else {
- return null;
- }
- }
-
public void encodeChildren(FacesContext context, UIComponent component) throws
IOException {
if (component.getChildCount() > 0) {
for (UIComponent child : component.getChildren()) {
Modified:
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java
===================================================================
---
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/RenderKitUtilsTest.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -23,9 +23,24 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.richfaces.renderkit.RenderKitUtils.addToScriptHash;
+import static org.richfaces.renderkit.RenderKitUtils.concat;
+import static org.richfaces.renderkit.RenderKitUtils.toScriptArgs;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.ajax4jsf.javascript.JSFunctionDefinition;
import org.junit.Test;
+import org.richfaces.renderkit.RenderKitUtils.ScriptHashVariableWrapper;
/**
* @author Nick Belaevski
@@ -107,4 +122,173 @@
assertFalse(RenderKitUtils.shouldRenderAttribute(Boolean.FALSE));
}
-}
\ No newline at end of file
+ @Test
+ public void testConcat() throws Exception {
+ assertEquals("", concat());
+ assertEquals("", concat((String) null));
+ assertEquals("", concat((String[]) null));
+ assertEquals("", concat(""));
+ assertEquals("test", concat("test"));
+ assertEquals("build a string", concat("build", " a
", "string"));
+ assertEquals("omit nulls", concat(null, "omit", null, "
", null, "nulls", null));
+ }
+
+ private static String dehydrate(String s) {
+ return s.replaceAll("\\s+", "");
+ }
+
+ @Test
+ public void testToScriptArgs() throws Exception {
+ assertEquals("", toScriptArgs());
+ assertEquals("", toScriptArgs((Object) null));
+ assertEquals("", toScriptArgs((Object[]) null));
+
+ assertEquals("\"test\"", toScriptArgs("test"));
+ assertEquals("[5,8]", dehydrate(toScriptArgs(Arrays.asList(5, 8))));
+ assertEquals("{\"a\":true}",
dehydrate(toScriptArgs(Collections.singletonMap("a", true))));
+
+ assertEquals("\"test\"", toScriptArgs("test",
null));
+ assertEquals("null,\"test\"", toScriptArgs(null,
"test"));
+
+ assertEquals("\"test\"", toScriptArgs("test",
Collections.emptyList()));
+ assertEquals("[],\"test\"",
dehydrate(toScriptArgs(Collections.emptyList(), "test")));
+
+ assertEquals("\"test\"", toScriptArgs("test",
Collections.emptyMap()));
+ assertEquals("{},\"test\"",
dehydrate(toScriptArgs(Collections.emptyMap(), "test")));
+
+ assertEquals("\"test\"", toScriptArgs("test",
""));
+ assertEquals("\"\",\"test\"",
dehydrate(toScriptArgs("", "test")));
+
+ assertEquals("1,2,3", toScriptArgs(1, 2, 3, null));
+ assertEquals("1,2,null,3", toScriptArgs(1, 2, null, 3));
+ }
+
+ public void testScriptHashVariableWrapper() throws Exception {
+ assertEquals("abc",
ScriptHashVariableWrapper.noop.wrap("abc"));
+
+ Object eventHandler =
ScriptHashVariableWrapper.eventHandler.wrap("abc");
+
+ assertTrue(eventHandler instanceof JSFunctionDefinition);
+
+ JSFunctionDefinition handlerFunction = (JSFunctionDefinition) eventHandler;
+ assertEquals("function(event){abc}",
dehydrate(handlerFunction.toScript()));
+
+ Object arrayObject = ScriptHashVariableWrapper.asArray.wrap("header,
footer");
+ assertEquals("[\"header\",\"footer\"]",
arrayObject.toString().replaceAll("\\s", ""));
+ }
+
+ public void testAddToScriptHash() throws Exception {
+ Map<String, Object> hash = new HashMap<String, Object>();
+
+ addToScriptHash(hash, "x", "y", null, null);
+ assertEquals("y", hash.get("x"));
+ addToScriptHash(hash, "y", "", null, null);
+ assertNull(hash.get("y"));
+ assertFalse(hash.containsKey("y"));
+ addToScriptHash(hash, "y1", null, null, null);
+ assertNull(hash.get("y1"));
+ assertFalse(hash.containsKey("y1"));
+ addToScriptHash(hash, "st", "server", "", null);
+ assertEquals("server", hash.get("st"));
+ addToScriptHash(hash, "st1", "ajax", "ajax",
null);
+ assertNull(hash.get("st1"));
+ assertFalse(hash.containsKey("st1"));
+ addToScriptHash(hash, "st2", "", "ajax", null);
+ assertNull(hash.get("st2"));
+ assertFalse(hash.containsKey("st2"));
+ addToScriptHash(hash, "null", null, "server", null);
+ assertNull(hash.get("null"));
+ assertFalse(hash.containsKey("null"));
+ addToScriptHash(hash, "b", false, null, null);
+ assertNull(hash.get("b"));
+ assertFalse(hash.containsKey("b"));
+ addToScriptHash(hash, "b1", true, null, null);
+ assertEquals(Boolean.TRUE, hash.get("b1"));
+ addToScriptHash(hash, "b2", true, "true", null);
+ assertNull(hash.get("b2"));
+ assertFalse(hash.containsKey("b2"));
+ addToScriptHash(hash, "b3", false, "true", null);
+ assertEquals(Boolean.FALSE, hash.get("b3"));
+ addToScriptHash(hash, "b4", true, "false", null);
+ assertEquals(Boolean.TRUE, hash.get("b4"));
+ addToScriptHash(hash, "b5", false, "false", null);
+ assertNull(hash.get("b5"));
+ assertFalse(hash.containsKey("b5"));
+ addToScriptHash(hash, "i", Integer.valueOf(0), null, null);
+ assertEquals(Integer.valueOf(0), hash.get("i"));
+ addToScriptHash(hash, "i1", Integer.valueOf(0), "0", null);
+ assertNull(hash.get("i1"));
+ assertFalse(hash.containsKey("i1"));
+ addToScriptHash(hash, "i2", Integer.valueOf(0), "1", null);
+ assertEquals(Integer.valueOf(0), hash.get("i2"));
+ addToScriptHash(hash, "i3", Integer.MIN_VALUE, null, null);
+ assertNull(hash.get("i3"));
+ assertFalse(hash.containsKey("i3"));
+ addToScriptHash(hash, "i4", Integer.MIN_VALUE, "0", null);
+ assertNull(hash.get("i4"));
+ assertFalse(hash.containsKey("i4"));
+ addToScriptHash(hash, "plain", "test", null,
ScriptHashVariableWrapper.noop);
+ assertEquals("test", hash.get("plain"));
+ addToScriptHash(hash, "plain1", "newtest", "blank",
ScriptHashVariableWrapper.noop);
+ assertEquals("newtest", hash.get("plain1"));
+ addToScriptHash(hash, "onclick", "alert(1)", null,
ScriptHashVariableWrapper.eventHandler);
+ assertTrue(hash.get("onclick") instanceof JSFunctionDefinition);
+ addToScriptHash(hash, "onclick1", "alert(1)",
"no-val", ScriptHashVariableWrapper.eventHandler);
+ assertTrue(hash.get("onclick1") instanceof JSFunctionDefinition);
+ }
+
+
+ public void testAsArray() {
+ assertNull(RenderKitUtils.asArray(null));
+ }
+
+ public void testAsArray1() {
+ String[] strings = new String[] {"a", "b"};
+ String[] array = RenderKitUtils.asArray(strings);
+
+ assertSame(strings, array);
+ }
+
+ public void testAsArray2() {
+ Object[] objects = new Object[] {Integer.valueOf(12), null, Integer.valueOf(22),
Integer.valueOf(42)};
+ String[] array = RenderKitUtils.asArray(objects);
+ String[] etalon = new String[] {"12", null, "22",
"42"};
+
+ assertTrue(Arrays.equals(etalon, array));
+ }
+
+ public void testAsArray3() {
+ ArrayList<Integer> list = new ArrayList<Integer>();
+
+ list.add(new Integer(12));
+ list.add(null);
+ list.add(new Integer(22));
+ list.add(new Integer(42));
+
+ String[] array = RenderKitUtils.asArray(list);
+ String[] etalon = new String[] {"12", null, "22",
"42"};
+
+ assertTrue(Arrays.equals(etalon, array));
+ }
+
+ public void testAsArray31() {
+ Set<Integer> set = new TreeSet<Integer>();
+
+ set.add(new Integer(12));
+ set.add(new Integer(22));
+ set.add(new Integer(42));
+
+ String[] array = RenderKitUtils.asArray(set);
+ String[] etalon = new String[] {"12", "22", "42"};
+
+ assertTrue(Arrays.equals(etalon, array));
+ }
+
+ public void testAsArray4() {
+ String string = " a , \t\n b \n , c ";
+ String[] strings = RenderKitUtils.asArray(string);
+ String[] etalon = new String[] {"a", "b", "c"};
+
+ assertTrue(Arrays.equals(etalon, strings));
+ }
+}
Modified:
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/util/RendererUtilsTest.java
===================================================================
---
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/util/RendererUtilsTest.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/common/ui/src/test/java/org/richfaces/renderkit/util/RendererUtilsTest.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -31,10 +31,6 @@
import junit.framework.TestCase;
-import org.ajax4jsf.javascript.JSFunctionDefinition;
-import org.richfaces.renderkit.util.RendererUtils;
-import org.richfaces.renderkit.util.RendererUtils.ScriptHashVariableWrapper;
-
/**
* @author Nick Belaevski
* @since 3.3.2
@@ -71,77 +67,4 @@
assertFalse(utils.isEmpty(new Object[1]));
assertFalse(utils.isEmpty(new int[1]));
}
-
- public void testScriptHashVariableWrapper() throws Exception {
- assertEquals("abc",
RendererUtils.ScriptHashVariableWrapper.DEFAULT.wrap("abc"));
-
- Object eventHandler =
RendererUtils.ScriptHashVariableWrapper.EVENT_HANDLER.wrap("abc");
-
- assertTrue(eventHandler instanceof JSFunctionDefinition);
-
- JSFunctionDefinition handlerFunction = (JSFunctionDefinition) eventHandler;
-
- assertEquals("function(event){abc}",
handlerFunction.toScript().replaceAll("\\s", ""));
- }
-
- public void testAddToScriptHash() throws Exception {
- Map<String, Object> hash = new HashMap<String, Object>();
- RendererUtils utils = RendererUtils.getInstance();
-
- utils.addToScriptHash(hash, "x", "y", null, null);
- assertEquals("y", hash.get("x"));
- utils.addToScriptHash(hash, "y", "", null, null);
- assertNull(hash.get("y"));
- assertFalse(hash.containsKey("y"));
- utils.addToScriptHash(hash, "y1", null, null, null);
- assertNull(hash.get("y1"));
- assertFalse(hash.containsKey("y1"));
- utils.addToScriptHash(hash, "st", "server", "",
null);
- assertEquals("server", hash.get("st"));
- utils.addToScriptHash(hash, "st1", "ajax", "ajax",
null);
- assertNull(hash.get("st1"));
- assertFalse(hash.containsKey("st1"));
- utils.addToScriptHash(hash, "st2", "", "ajax",
null);
- assertNull(hash.get("st2"));
- assertFalse(hash.containsKey("st2"));
- utils.addToScriptHash(hash, "null", null, "server", null);
- assertNull(hash.get("null"));
- assertFalse(hash.containsKey("null"));
- utils.addToScriptHash(hash, "b", false, null, null);
- assertNull(hash.get("b"));
- assertFalse(hash.containsKey("b"));
- utils.addToScriptHash(hash, "b1", true, null, null);
- assertEquals(Boolean.TRUE, hash.get("b1"));
- utils.addToScriptHash(hash, "b2", true, "true", null);
- assertNull(hash.get("b2"));
- assertFalse(hash.containsKey("b2"));
- utils.addToScriptHash(hash, "b3", false, "true", null);
- assertEquals(Boolean.FALSE, hash.get("b3"));
- utils.addToScriptHash(hash, "b4", true, "false", null);
- assertEquals(Boolean.TRUE, hash.get("b4"));
- utils.addToScriptHash(hash, "b5", false, "false", null);
- assertNull(hash.get("b5"));
- assertFalse(hash.containsKey("b5"));
- utils.addToScriptHash(hash, "i", Integer.valueOf(0), null, null);
- assertEquals(Integer.valueOf(0), hash.get("i"));
- utils.addToScriptHash(hash, "i1", Integer.valueOf(0), "0",
null);
- assertNull(hash.get("i1"));
- assertFalse(hash.containsKey("i1"));
- utils.addToScriptHash(hash, "i2", Integer.valueOf(0), "1",
null);
- assertEquals(Integer.valueOf(0), hash.get("i2"));
- utils.addToScriptHash(hash, "i3", Integer.MIN_VALUE, null, null);
- assertNull(hash.get("i3"));
- assertFalse(hash.containsKey("i3"));
- utils.addToScriptHash(hash, "i4", Integer.MIN_VALUE, "0",
null);
- assertNull(hash.get("i4"));
- assertFalse(hash.containsKey("i4"));
- utils.addToScriptHash(hash, "plain", "test", null,
ScriptHashVariableWrapper.DEFAULT);
- assertEquals("test", hash.get("plain"));
- utils.addToScriptHash(hash, "plain1", "newtest",
"blank", ScriptHashVariableWrapper.DEFAULT);
- assertEquals("newtest", hash.get("plain1"));
- utils.addToScriptHash(hash, "onclick", "alert(1)", null,
ScriptHashVariableWrapper.EVENT_HANDLER);
- assertTrue(hash.get("onclick") instanceof JSFunctionDefinition);
- utils.addToScriptHash(hash, "onclick1", "alert(1)",
"no-val", ScriptHashVariableWrapper.EVENT_HANDLER);
- assertTrue(hash.get("onclick1") instanceof JSFunctionDefinition);
- }
}
Modified:
trunk/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java
===================================================================
---
trunk/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxPushRenderer.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -21,6 +21,8 @@
package org.richfaces.renderkit.html;
+import static org.richfaces.renderkit.RenderKitUtils.shouldRenderAttribute;
+
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -89,7 +91,7 @@
Map<String, Object> options = new HashMap<String, Object>();
int interval = push.getInterval();
- if (!getUtils().shouldRenderAttribute(interval)) {
+ if (shouldRenderAttribute(interval)) {
String intervalInitParameter =
context.getExternalContext().getInitParameter(PUSH_INTERVAL_PARAMETER);
if (null != intervalInitParameter) {
interval = Integer.parseInt(intervalInitParameter);
Modified:
trunk/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java
===================================================================
---
trunk/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/core/ui/src/main/java/org/richfaces/renderkit/html/AjaxStatusRenderer.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -21,6 +21,9 @@
package org.richfaces.renderkit.html;
+import static org.richfaces.renderkit.RenderKitUtils.addToScriptHash;
+import static org.richfaces.renderkit.RenderKitUtils.renderAttribute;
+
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -35,10 +38,9 @@
import org.richfaces.component.AbstractAjaxStatus;
import org.richfaces.component.util.HtmlUtil;
import org.richfaces.renderkit.HtmlConstants;
+import org.richfaces.renderkit.RenderKitUtils.ScriptHashVariableWrapper;
import org.richfaces.renderkit.RendererBase;
import org.richfaces.renderkit.util.HandlersChain;
-import org.richfaces.renderkit.util.RendererUtils;
-import org.richfaces.renderkit.util.RendererUtils.ScriptHashVariableWrapper;
/**
* @author Nick Belaevski
@@ -128,8 +130,6 @@
}
}
- private RendererUtils rendererUtils = RendererUtils.getInstance();
-
protected void encodeState(FacesContext facesContext, AbstractAjaxStatus status,
StatusState state) throws IOException {
@@ -150,14 +150,13 @@
String stateStyle = (String)
statusAttributes.get(state.getStyleAttributeName());
- rendererUtils.writeAttribute(writer, HtmlConstants.STYLE_ATTRIBUTE,
- HtmlUtil.concatStyles(stateStyle,
- state.isInitial() ? null : "display:none")
+ renderAttribute(facesContext, HtmlConstants.STYLE_ATTRIBUTE,
+ HtmlUtil.concatStyles(stateStyle, state.isInitial() ? null :
"display:none")
);
String stateStyleClass = (String)
statusAttributes.get(state.getStyleClassAttributeName());
- rendererUtils.writeAttribute(writer, HtmlConstants.CLASS_ATTRIBUTE,
+ renderAttribute(facesContext, HtmlConstants.CLASS_ATTRIBUTE,
HtmlUtil.concatClasses(state.getDefaultStyleClass(),
stateStyleClass));
@@ -201,12 +200,12 @@
HandlersChain handlersChain = new HandlersChain(context, component, true);
handlersChain.addInlineHandlerFromAttribute(eventAttribute);
handlersChain.addBehaviors(eventName);
- rendererUtils.addToScriptHash(options, eventAttribute,
+ addToScriptHash(options, eventAttribute,
handlersChain.toScript(), null,
- ScriptHashVariableWrapper.EVENT_HANDLER);
+ ScriptHashVariableWrapper.eventHandler);
}
- rendererUtils.addToScriptHash(options, "statusName",
attributes.get("name"));
+ addToScriptHash(options, "statusName",
attributes.get("name"));
if (!options.isEmpty()) {
statusConstructor.addParameter(options);
Modified:
trunk/ui/core/ui/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java
===================================================================
---
trunk/ui/core/ui/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/core/ui/src/main/java/org/richfaces/renderkit/html/QueueResourceComponentRenderer.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -22,6 +22,7 @@
package org.richfaces.renderkit.html;
import static
org.richfaces.application.configuration.ConfigurationServiceHelper.getBooleanConfigurationValue;
+import static org.richfaces.renderkit.RenderKitUtils.addToScriptHash;
import java.io.IOException;
import java.util.LinkedHashMap;
@@ -40,7 +41,6 @@
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.component.QueueRegistry;
import org.richfaces.renderkit.HtmlConstants;
-import org.richfaces.renderkit.util.RendererUtils;
/**
* @author Nick Belaevski
@@ -52,8 +52,6 @@
private static final String FUNCTION_NAME =
"RichFaces.queue.setQueueOptions";
- private final RendererUtils utils = RendererUtils.getInstance();
-
private enum QueueOptions {
onbeforedomupdate, oncomplete, onerror, onevent, onrequestdequeue,
onrequestqueue, onsubmit,
requestDelay, timeout, status, queueId, ignoreDupResponses, requestGroupingId
@@ -65,7 +63,7 @@
for (QueueOptions option : QueueOptions.values()) {
String optionName = option.name();
Object value = attributes.get(optionName);
- utils.addToScriptHash(optionsHash, optionName, value);
+ addToScriptHash(optionsHash, optionName, value);
}
}
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
===================================================================
---
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -21,6 +21,8 @@
*/
package org.richfaces.renderkit;
+import static org.richfaces.renderkit.RenderKitUtils.addToScriptHash;
+
import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;
@@ -52,8 +54,7 @@
import org.richfaces.component.AutocompleteLayout;
import org.richfaces.component.MetaComponentResolver;
import org.richfaces.component.util.InputUtils;
-import org.richfaces.renderkit.util.RendererUtils;
-import org.richfaces.renderkit.util.RendererUtils.ScriptHashVariableWrapper;
+import org.richfaces.renderkit.RenderKitUtils.ScriptHashVariableWrapper;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterators;
@@ -89,32 +90,31 @@
public String getScriptOptions(UIComponent component) {
Map<String, Object> attributes = component.getAttributes();
Map<String, Object> options = new HashMap<String, Object>();
- RendererUtils utils = getUtils();
- utils.addToScriptHash(options, "buttonId", component.getClientId() +
"Button");
- utils.addToScriptHash(options, "selectedItemClass",
attributes.get("selectedItemClass"));
- utils.addToScriptHash(options, "minChars",
attributes.get("minChars"), "1");
- utils.addToScriptHash(options, "filterFunction",
attributes.get("filterFunction"));
- utils.addToScriptHash(options, "autofill",
attributes.get("autofill"), "true");
- utils.addToScriptHash(options, "disabled",
attributes.get("disabled"), "false");
- utils.addToScriptHash(options, "selectFirst",
attributes.get("selectFirst"), "true");
- utils.addToScriptHash(options, "tokens",
attributes.get("tokens"));
- utils.addToScriptHash(options, "onbegin",
attributes.get("onbegin"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
- utils.addToScriptHash(options, "oncomplete",
attributes.get("oncomplete"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
- utils.addToScriptHash(options, "onerror",
attributes.get("onerror"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
- utils.addToScriptHash(options, "onbeforedomupdate",
attributes.get("onbeforedomupdate"), null,
ScriptHashVariableWrapper.EVENT_HANDLER);
- utils.addToScriptHash(options, "onchange",
attributes.get("onchange"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
- utils.addToScriptHash(options, "onselectitem",
attributes.get("onselectitem"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
- utils.addToScriptHash(options, "onfocus",
attributes.get("onfocus"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
- utils.addToScriptHash(options, "onblur",
attributes.get("onblur"), null, ScriptHashVariableWrapper.EVENT_HANDLER);
- utils.addToScriptHash(options, "filterFunction",
getClientFilterFunction(component));
+ addToScriptHash(options, "buttonId", component.getClientId() +
"Button");
+ addToScriptHash(options, "selectedItemClass",
attributes.get("selectedItemClass"));
+ addToScriptHash(options, "minChars",
attributes.get("minChars"), 1);
+ addToScriptHash(options, "filterFunction",
attributes.get("filterFunction"));
+ addToScriptHash(options, "autofill",
attributes.get("autofill"), true);
+ addToScriptHash(options, "disabled",
attributes.get("disabled"), false);
+ addToScriptHash(options, "selectFirst",
attributes.get("selectFirst"), true);
+ addToScriptHash(options, "tokens",
attributes.get("tokens"));
+ addToScriptHash(options, "onbegin",
attributes.get("onbegin"), null, ScriptHashVariableWrapper.eventHandler);
+ addToScriptHash(options, "oncomplete",
attributes.get("oncomplete"), null, ScriptHashVariableWrapper.eventHandler);
+ addToScriptHash(options, "onerror",
attributes.get("onerror"), null, ScriptHashVariableWrapper.eventHandler);
+ addToScriptHash(options, "onbeforedomupdate",
attributes.get("onbeforedomupdate"), null,
ScriptHashVariableWrapper.eventHandler);
+ addToScriptHash(options, "onchange",
attributes.get("onchange"), null, ScriptHashVariableWrapper.eventHandler);
+ addToScriptHash(options, "onselectitem",
attributes.get("onselectitem"), null, ScriptHashVariableWrapper.eventHandler);
+ addToScriptHash(options, "onfocus",
attributes.get("onfocus"), null, ScriptHashVariableWrapper.eventHandler);
+ addToScriptHash(options, "onblur", attributes.get("onblur"),
null, ScriptHashVariableWrapper.eventHandler);
+ addToScriptHash(options, "filterFunction",
getClientFilterFunction(component));
String mode = (String) attributes.get("mode");
if (mode != null) {
if (mode.equals("ajax")) {
- utils.addToScriptHash(options, "isCachedAjax", false,
"true");
+ addToScriptHash(options, "isCachedAjax", false, true);
} else if (mode.equals("client") ||
mode.equals("lazyClient")) {
- utils.addToScriptHash(options, "ajaxMode", false,
"true");
+ addToScriptHash(options, "ajaxMode", false, true);
if (mode.equals("lazyClient")) {
- utils.addToScriptHash(options, "lazyClientMode", true,
"false");
+ addToScriptHash(options, "lazyClientMode", true, false);
}
}
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/ExtendedDataTableRenderer.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -21,6 +21,8 @@
*/
package org.richfaces.renderkit;
+import static org.richfaces.renderkit.RenderKitUtils.addToScriptHash;
+import static org.richfaces.renderkit.RenderKitUtils.renderAttribute;
import static org.richfaces.renderkit.util.AjaxRendererUtils.AJAX_FUNCTION_NAME;
import static org.richfaces.renderkit.util.AjaxRendererUtils.buildAjaxFunction;
import static org.richfaces.renderkit.util.AjaxRendererUtils.buildEventOptions;
@@ -56,8 +58,7 @@
import org.richfaces.component.util.HtmlUtil;
import org.richfaces.context.OnOffResponseWriter;
import org.richfaces.model.SelectionMode;
-import org.richfaces.renderkit.util.RendererUtils;
-import org.richfaces.renderkit.util.RendererUtils.ScriptHashVariableWrapper;
+import org.richfaces.renderkit.RenderKitUtils.ScriptHashVariableWrapper;
/**
* @author Konstantin Mishin
@@ -581,7 +582,7 @@
writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, component.getClientId(context),
null);
writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
HtmlUtil.concatClasses("rf-edt",
(String) attributes.get("styleClass")), null);
- getUtils().writeAttribute(writer, HtmlConstants.STYLE_ATTRIBUTE,
attributes.get("style"));
+ renderAttribute(context, HtmlConstants.STYLE_ATTRIBUTE,
attributes.get("style"));
}
public RendererState createRowHolder(FacesContext context, UIComponent component,
Object[] options) {
@@ -645,14 +646,13 @@
ajaxFunction.addParameter(eventOptions);
Map<String, Object> attributes = component.getAttributes();
Map<String, Object> options = new HashMap<String, Object>();
- RendererUtils utils = getUtils();
- utils.addToScriptHash(options, "parameters", parameters);
- utils.addToScriptHash(options, "selectionMode",
attributes.get("selectionMode"),
- SelectionMode.multiple.toString());
- utils.addToScriptHash(options, "onbeforeselectionchange",
RenderKitUtils.getAttributeAndBehaviorsValue(context,
- component, EVENT_ATTRIBUTES.get("onbeforeselectionchange")), null,
ScriptHashVariableWrapper.EVENT_HANDLER);
- utils.addToScriptHash(options, "onselectionchange",
RenderKitUtils.getAttributeAndBehaviorsValue(context,
- component, EVENT_ATTRIBUTES.get("onselectionchange")), null,
ScriptHashVariableWrapper.EVENT_HANDLER);
+ addToScriptHash(options, "parameters", parameters);
+ addToScriptHash(options, "selectionMode",
attributes.get("selectionMode"),
+ SelectionMode.multiple);
+ addToScriptHash(options, "onbeforeselectionchange",
RenderKitUtils.getAttributeAndBehaviorsValue(context,
+ component, EVENT_ATTRIBUTES.get("onbeforeselectionchange")), null,
ScriptHashVariableWrapper.eventHandler);
+ addToScriptHash(options, "onselectionchange",
RenderKitUtils.getAttributeAndBehaviorsValue(context,
+ component, EVENT_ATTRIBUTES.get("onselectionchange")), null,
ScriptHashVariableWrapper.eventHandler);
StringBuilder builder = new StringBuilder("new
RichFaces.ExtendedDataTable('");
builder.append(component.getClientId(context)).append("',
").append(getRowCount(component))
.append(", function(event, parameters)
{").append(ajaxFunction.toScript()).append(";}");
@@ -660,7 +660,7 @@
builder.append(",").append(ScriptUtils.toScript(options));
}
builder.append(");");
- utils.writeScript(context, component, builder.toString());
+ getUtils().writeScript(context, component, builder.toString());
writer.endElement(HtmlConstants.DIV_ELEM);
}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/ListRendererBase.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/ListRendererBase.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/renderkit/ListRendererBase.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -96,11 +96,11 @@
writer.startElement(HtmlConstants.LI_ELEMENT, sequence);
if (rendererUtils.hasExplicitId(sequence)) {
- rendererUtils.writeAttribute(writer, HtmlConstants.ID_ATTRIBUTE,
sequence.getClientId(context));
+ writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
sequence.getClientId(context), null);
}
- rendererUtils.writeAttribute(writer, HtmlConstants.CLASS_ATTRIBUTE,
- HtmlUtil.concatClasses(helper.getRowClass(), helper.getColumnClass(),
itemClass));
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
+ HtmlUtil.concatClasses(helper.getRowClass(), helper.getColumnClass(),
itemClass), null);
renderHandlers(context, sequence);
rendererUtils.encodeChildren(context, sequence);
writer.endElement(HtmlConstants.LI_ELEMENT);
@@ -129,11 +129,11 @@
writer.startElement(HtmlConstants.DT_ELEMENT, sequence);
if (rendererUtils.hasExplicitId(sequence)) {
- rendererUtils.writeAttribute(writer, HtmlConstants.ID_ATTRIBUTE,
sequence.getClientId(context) + ".dt");
+ writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
sequence.getClientId(context) + ".dt", null);
}
- rendererUtils.writeAttribute(writer, HtmlConstants.CLASS_ATTRIBUTE,
- HtmlUtil.concatClasses(helper.getRowClass(), helper.getColumnClass(),
"rf-dlst-trm"));
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
+ HtmlUtil.concatClasses(helper.getRowClass(), helper.getColumnClass(),
"rf-dlst-trm"), null);
termFacet.encodeAll(context);
writer.endElement(HtmlConstants.DT_ELEMENT);
}
@@ -141,11 +141,11 @@
writer.startElement(HtmlConstants.DD_ELEMENT, sequence);
if (rendererUtils.hasExplicitId(sequence)) {
- rendererUtils.writeAttribute(writer, HtmlConstants.ID_ATTRIBUTE,
sequence.getClientId(context));
+ writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
sequence.getClientId(context), null);
}
- rendererUtils.writeAttribute(writer, HtmlConstants.CLASS_ATTRIBUTE,
- HtmlUtil.concatClasses(helper.getRowClass(), helper.getColumnClass(),
"rf-dlst-dfn"));
+ writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
+ HtmlUtil.concatClasses(helper.getRowClass(), helper.getColumnClass(),
"rf-dlst-dfn"), null);
renderHandlers(context, sequence);
rendererUtils.encodeChildren(context, sequence);
writer.endElement(HtmlConstants.DD_ELEMENT);
Modified: trunk/ui/misc/ui/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java
===================================================================
---
trunk/ui/misc/ui/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/misc/ui/src/main/java/org/richfaces/renderkit/JQueryRendererBase.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -22,21 +22,13 @@
package org.richfaces.renderkit;
-import java.util.HashMap;
-import java.util.Map;
-
import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.render.Renderer;
-import org.ajax4jsf.javascript.ScriptUtils;
-import org.richfaces.component.AbstractJQuery;
-import org.richfaces.component.JQueryAttachType;
-import org.richfaces.component.JQueryTiming;
import org.richfaces.component.util.HtmlUtil;
-import org.richfaces.renderkit.util.RendererUtils;
/**
* @author nick
@@ -48,8 +40,6 @@
})
public abstract class JQueryRendererBase extends Renderer {
- private RendererUtils rendererUtils = RendererUtils.getInstance();
-
protected String getEscapedSelector(FacesContext context, UIComponent component) {
String selector = (String) component.getAttributes().get("selector");
@@ -60,17 +50,4 @@
return selector;
}
- protected String getOptionsAsJavascriptString(FacesContext context, UIComponent
component) {
- AbstractJQuery jQuery = (AbstractJQuery) component;
-
- Map<String,Object> map = new HashMap<String, Object>();
-
- rendererUtils.addToScriptHash(map, "selector",
getEscapedSelector(context, jQuery));
- rendererUtils.addToScriptHash(map, "event", jQuery.getEvent());
- rendererUtils.addToScriptHash(map, "query", jQuery.getQuery());
- rendererUtils.addToScriptHash(map, "attachType",
jQuery.getAttachType(), JQueryAttachType.DEFAULT.toString());
- rendererUtils.addToScriptHash(map, "timing", jQuery.getTiming(),
JQueryTiming.DEFAULT.toString());
-
- return ScriptUtils.toScript(map);
- }
}
Modified: trunk/ui/misc/ui/src/main/templates/jquery.template.xml
===================================================================
--- trunk/ui/misc/ui/src/main/templates/jquery.template.xml 2010-10-22 16:54:29 UTC (rev
19656)
+++ trunk/ui/misc/ui/src/main/templates/jquery.template.xml 2010-10-24 19:11:47 UTC (rev
19657)
@@ -10,20 +10,28 @@
<cdk:component-family>org.richfaces.JQuery</cdk:component-family>
<cdk:renderer-type>org.richfaces.JQueryRenderer</cdk:renderer-type>
<cdk:renders-children>true</cdk:renders-children>
+
+ <cdk:import package="org.richfaces.component"
names="JQueryAttachType JQueryTiming" />
</cc:interface>
<cc:implementation>
<span id="#{clientId}" style="display: none;">
<script type="text/javascript">
<cdk:object name="functionName"
value="#{component.attributes['name']}" />
- <cdk:object name="options"
value="#{getOptionsAsJavascriptString(facesContext, component)}" />
+
+ <cdk:scriptObject name="options">
+ <cdk:scriptOption name="selector"
value="#{getEscapedSelector(facesContext, component)}" />
+ <cdk:scriptOption attributes="event query" />
+ <cdk:scriptOption name="attachType"
value="#{component.attributes['attachType']}"
defaultValue="JQueryAttachType.DEFAULT" />
+ <cdk:scriptOption name="timing"
value="#{component.attributes['timing']}"
defaultValue="JQueryTiming.DEFAULT" />
+ </cdk:scriptObject>
<c:choose>
<c:when test="#{not empty functionName}">
- #{functionName} = RichFaces.jQuery.createFunction(#{options});
+ #{functionName} = RichFaces.jQuery.createFunction(#{toScriptArgs(options)});
</c:when>
<c:otherwise>
- RichFaces.jQuery.query(#{options});
+ RichFaces.jQuery.query(#{toScriptArgs(options)});
</c:otherwise>
</c:choose>
</script>
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/PopupPanelBaseRenderer.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -1,5 +1,7 @@
package org.richfaces.renderkit.html;
+import static org.richfaces.renderkit.RenderKitUtils.addToScriptHash;
+
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
@@ -20,7 +22,6 @@
import org.richfaces.json.JSONException;
import org.richfaces.json.JSONMap;
import org.richfaces.renderkit.RendererBase;
-import org.richfaces.renderkit.util.RendererUtils;
//TODO nick - JSF have concept of library, it should be used instead of '/' in
resource names
@ResourceDependencies( {
@@ -176,35 +177,34 @@
result.append("',");
Map<String, Object> attributes = component.getAttributes();
Map<String, Object> options = new HashMap<String, Object>();
- RendererUtils utils = getUtils();
- utils.addToScriptHash(options, "width", panel.getWidth(),
"-1");
- utils.addToScriptHash(options, "height", panel.getHeight(),
"-1");
- utils.addToScriptHash(options, "minWidth", panel.getMinWidth(),
"-1");
- utils.addToScriptHash(options, "minHeight", panel.getMinHeight(),
"-1");
- utils.addToScriptHash(options, "maxWidth", panel.getMaxWidth(),
"" +Integer.MAX_VALUE);
- utils.addToScriptHash(options, "maxHeight", panel.getMaxHeight(),
"" +Integer.MAX_VALUE);
- utils.addToScriptHash(options, "moveable", panel.isMoveable(),
"true");
- utils.addToScriptHash(options, "followByScroll",
panel.isFollowByScroll(), "true");
- utils.addToScriptHash(options, "left", panel.getLeft(),
"auto");
- utils.addToScriptHash(options, "top", panel.getTop(),
"auto");
- utils.addToScriptHash(options, "zindex", panel.getZIndex(),
"100");
- utils.addToScriptHash(options, "shadowDepth", panel.getShadowDepth(),
"2");
- utils.addToScriptHash(options, "shadowOpacity",
panel.getShadowOpacity(), "0.1");
- utils.addToScriptHash(options, "domElementAttachment",
panel.getDomElementAttachment());
+ addToScriptHash(options, "width", panel.getWidth(), "-1");
+ addToScriptHash(options, "height", panel.getHeight(), "-1");
+ addToScriptHash(options, "minWidth", panel.getMinWidth(),
"-1");
+ addToScriptHash(options, "minHeight", panel.getMinHeight(),
"-1");
+ addToScriptHash(options, "maxWidth", panel.getMaxWidth(), ""
+Integer.MAX_VALUE);
+ addToScriptHash(options, "maxHeight", panel.getMaxHeight(),
"" +Integer.MAX_VALUE);
+ addToScriptHash(options, "moveable", panel.isMoveable(),
"true");
+ addToScriptHash(options, "followByScroll", panel.isFollowByScroll(),
"true");
+ addToScriptHash(options, "left", panel.getLeft(), "auto");
+ addToScriptHash(options, "top", panel.getTop(), "auto");
+ addToScriptHash(options, "zindex", panel.getZIndex(),
"100");
+ addToScriptHash(options, "shadowDepth", panel.getShadowDepth(),
"2");
+ addToScriptHash(options, "shadowOpacity", panel.getShadowOpacity(),
"0.1");
+ addToScriptHash(options, "domElementAttachment",
panel.getDomElementAttachment());
- utils.addToScriptHash(options, "keepVisualState",
panel.isKeepVisualState(), "false");
- utils.addToScriptHash(options, "show", panel.isShow(),
"false");
- utils.addToScriptHash(options, "modal", panel.isModal(),
"true");
- utils.addToScriptHash(options, "autosized", panel.isAutosized(),
"false");
- utils.addToScriptHash(options, "resizeable", panel.isResizeable(),
"false");
- utils.addToScriptHash(options, "overlapEmbedObjects",
panel.isOverlapEmbedObjects(), "false");
- utils.addToScriptHash(options, "visualOptions",
writeVisualOptions(context, panel));
- utils.addToScriptHash(options, "onresize",
buildEventFunction(attributes.get("onresize")));
- utils.addToScriptHash(options, "onmove",
buildEventFunction(attributes.get("onmove")));
- utils.addToScriptHash(options, "onshow",
buildEventFunction(attributes.get("onshow")));
- utils.addToScriptHash(options, "onhide",
buildEventFunction(attributes.get("onhide")));
- utils.addToScriptHash(options, "onbeforeshow",
buildEventFunction(attributes.get("onbeforeshow")));
- utils.addToScriptHash(options, "onbeforehide",
buildEventFunction(attributes.get("onbeforehide")));
+ addToScriptHash(options, "keepVisualState", panel.isKeepVisualState(),
"false");
+ addToScriptHash(options, "show", panel.isShow(), "false");
+ addToScriptHash(options, "modal", panel.isModal(), "true");
+ addToScriptHash(options, "autosized", panel.isAutosized(),
"false");
+ addToScriptHash(options, "resizeable", panel.isResizeable(),
"false");
+ addToScriptHash(options, "overlapEmbedObjects",
panel.isOverlapEmbedObjects(), "false");
+ addToScriptHash(options, "visualOptions", writeVisualOptions(context,
panel));
+ addToScriptHash(options, "onresize",
buildEventFunction(attributes.get("onresize")));
+ addToScriptHash(options, "onmove",
buildEventFunction(attributes.get("onmove")));
+ addToScriptHash(options, "onshow",
buildEventFunction(attributes.get("onshow")));
+ addToScriptHash(options, "onhide",
buildEventFunction(attributes.get("onhide")));
+ addToScriptHash(options, "onbeforeshow",
buildEventFunction(attributes.get("onbeforeshow")));
+ addToScriptHash(options, "onbeforehide",
buildEventFunction(attributes.get("onbeforehide")));
result.append(ScriptUtils.toScript(options));
result.append(");");
Modified:
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarBaseRenderer.java
===================================================================
---
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarBaseRenderer.java 2010-10-22
16:54:29 UTC (rev 19656)
+++
trunk/ui/output/ui/src/main/java/org/richfaces/renderkit/html/ProgressBarBaseRenderer.java 2010-10-24
19:11:47 UTC (rev 19657)
@@ -27,6 +27,8 @@
package org.richfaces.renderkit.html;
+import static org.richfaces.renderkit.RenderKitUtils.addToScriptHash;
+
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
@@ -202,18 +204,18 @@
String clientId = component.getClientId(context);
- utils.addToScriptHash(options, "mode",
component.getAttributes().get("mode"), "ajax");
- utils.addToScriptHash(options, "minValue",
component.getAttributes().get("minValue"), "0");
- utils.addToScriptHash(options, "maxValue",
component.getAttributes().get("maxValue"), "100");
- utils.addToScriptHash(options, "context", getContext(component));
+ addToScriptHash(options, "mode",
component.getAttributes().get("mode"), "ajax");
+ addToScriptHash(options, "minValue",
component.getAttributes().get("minValue"), "0");
+ addToScriptHash(options, "maxValue",
component.getAttributes().get("maxValue"), "100");
+ addToScriptHash(options, "context", getContext(component));
Integer interval = new Integer(progressBar.getInterval());
- utils.addToScriptHash(options, "pollinterval", interval);
- utils.addToScriptHash(options, "enabled", progressBar.isEnabled());
- utils.addToScriptHash(options, "pollId",
progressBar.getClientId(context));
- utils.addToScriptHash(options, "state", state,
"initialState");
- utils.addToScriptHash(options, "value",
NumberUtils.getNumber(component.getAttributes().get("value")));
- utils.addToScriptHash(options, "onsubmit",
buildEventFunction(component.getAttributes().get("onsubmit")));
+ addToScriptHash(options, "pollinterval", interval);
+ addToScriptHash(options, "enabled", progressBar.isEnabled());
+ addToScriptHash(options, "pollId", progressBar.getClientId(context));
+ addToScriptHash(options, "state", state, "initialState");
+ addToScriptHash(options, "value",
NumberUtils.getNumber(component.getAttributes().get("value")));
+ addToScriptHash(options, "onsubmit",
buildEventFunction(component.getAttributes().get("onsubmit")));
script.append("new
RichFaces.ui.ProgressBar('").append(clientId).append("'");
if (!options.isEmpty()) {
script.append(",").append(ScriptUtils.toScript(options));