Author: alexsmirnov
Date: 2010-07-06 19:35:30 -0400 (Tue, 06 Jul 2010)
New Revision: 17749
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELTypeTemplateModel.java
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/should-render-attribute.ftl
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-boolean-attribute.ftl
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-uri-attribute.ftl
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/util.ftl
Modified:
root/cdk/branches/RF8755/plugins/generator/pom.xml
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractBinaryOperationTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstBracketSuffixTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstChoiceTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/util.ftl
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatementTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTestBase.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeTest.java
Log:
https://jira.jboss.org/browse/RF-8306
Modified: root/cdk/branches/RF8755/plugins/generator/pom.xml
===================================================================
--- root/cdk/branches/RF8755/plugins/generator/pom.xml 2010-07-06 17:04:49 UTC (rev
17748)
+++ root/cdk/branches/RF8755/plugins/generator/pom.xml 2010-07-06 23:35:30 UTC (rev
17749)
@@ -175,5 +175,10 @@
<artifactId>guice-multibindings</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.beanshell</groupId>
+ <artifactId>bsh</artifactId>
+ <version>2.0b4</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELTypeTemplateModel.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELTypeTemplateModel.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELTypeTemplateModel.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -0,0 +1,51 @@
+/*
+ * $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;
+
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
+
+import freemarker.ext.beans.BeansWrapper;
+import freemarker.ext.beans.StringModel;
+import freemarker.template.TemplateModel;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class ELTypeTemplateModel extends StringModel implements TemplateModel {
+
+ private final ELType elType;
+
+ public ELTypeTemplateModel(ELType obj, BeansWrapper wrapper) {
+ super(obj, wrapper);
+ this.elType = obj;
+ }
+
+ @Override
+ public String getAsString() {
+ return elType.getCode();
+ }
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELTypeTemplateModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -1,6 +1,7 @@
package org.richfaces.cdk.templatecompiler;
import org.richfaces.cdk.templatecompiler.builder.model.JavaStatement;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
import freemarker.ext.beans.BeansWrapper;
import freemarker.template.ObjectWrapper;
@@ -21,6 +22,8 @@
if (obj instanceof JavaStatement) {
templateModel = new MethodBodyTemplateModel((JavaStatement) obj, this);
+ } else if (obj instanceof ELType){
+ templateModel = new ELTypeTemplateModel((ELType)obj, this);
} else {
templateModel = super.wrap(obj);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -25,7 +25,7 @@
import org.richfaces.cdk.templatecompiler.builder.model.JavaStatement;
-import freemarker.ext.beans.BeanModel;
+import freemarker.ext.beans.StringModel;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
@@ -34,7 +34,7 @@
*
* @author asmirnov(a)exadel.com
*/
-public class MethodBodyTemplateModel extends BeanModel implements TemplateModel {
+public class MethodBodyTemplateModel extends StringModel implements TemplateModel {
private static final String CODE_ATTRIBUTE_NAME = "code";
@@ -62,4 +62,8 @@
return super.get(key);
}
+ @Override
+ public String getAsString() {
+ return statement.getCode();
+ }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -119,16 +119,15 @@
*
*/
public static final String FACES_CONTEXT_VARIABLE = "facesContext";
- /**
- *
- */
- static final String CLIENT_ID_VARIABLE = "clientId";
-
public static final ImmutableMap<String, Object> ENCODE_METHOD_VARIABLES =
ImmutableMap.<String, Object> builder()
.put("facesContextVariable",
RendererClassVisitor.FACES_CONTEXT_VARIABLE)
.put("componentVariable", RendererClassVisitor.COMPONENT_VARIABLE)
.put("responseWriterVariable",
RendererClassVisitor.RESPONSE_WRITER_VARIABLE)
.put("clientIdVariable",
RendererClassVisitor.CLIENT_ID_VARIABLE).build();
+ /**
+ *
+ */
+ static final String CLIENT_ID_VARIABLE = "clientId";
/**
*
@@ -218,7 +217,6 @@
return typesFactory.getType(type);
}
-
private void createMethodContext() {
this.currentStatement = new StatementsContainer();
currentStatement.setVariable(FACES_CONTEXT_VARIABLE,
getType(FacesContext.class));
@@ -290,8 +288,8 @@
protected void popStatement() {
currentStatement = currentStatement.getParent();
}
-
- protected <T extends TemplateStatement> T addStatement(Class<T>
statementClass){
+
+ protected <T extends TemplateStatement> T addStatement(Class<T>
statementClass) {
T statement = createStatement(statementClass);
addStatement(statement);
return statement;
@@ -355,7 +353,7 @@
StartElementStatement startElementStatement =
addStatement(StartElementStatement.class);
startElementStatement.setElementName(elementName.getLocalPart());
AttributesStatement attributesStatement =
addStatement(AttributesStatement.class);
- attributesStatement.processAttributes(anyElement,attributes);
+ attributesStatement.processAttributes(anyElement, attributes);
// Set<String> writtenAttributes = new HashSet<String>();
// boolean shouldEncodePassThrough = false;
// String[] passThroughExclusions = null;
@@ -619,7 +617,7 @@
@Override
public void startElement(CdkForEachElement cdkForEachElement) {
String items = cdkForEachElement.getItems();
-// String itemsExpression = compileEl(items, Iterable.class);
+ // String itemsExpression = compileEl(items, Iterable.class);
// TODO - review
// Class<?> collectionElementClass =
lastCompiledExpressionType.getContainerType().getRawType();
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -152,7 +152,7 @@
}
- public ELType getExpressionType() {
+ public ELType getType() {
return expressionType;
}
@@ -206,7 +206,7 @@
public String coerceToType(String valueString, ELType expectedType) {
- if (!expectedType.isAssignableFrom(getExpressionType())) {
+ if (!expectedType.isAssignableFrom(getType())) {
for (HelperMethod conversionMethod : HelperMethod.getConversionMethods()) {
ELType returnType =
typesFactory.getType(conversionMethod.getReturnType());
if (expectedType.isAssignableFrom(returnType)) {
@@ -254,7 +254,7 @@
@Override
public Iterable<JavaImport> getRequiredImports() {
- return getExpressionType().getRequiredImports();
+ return getType().getRequiredImports();
}
@Override
@@ -270,12 +270,12 @@
public ELType getMatchingVisibleMethodReturnType(String methodName, ELType[]
parameterTypes) throws ParsingException {
- return typesFactory.getMatchingVisibleMethodReturnType(getExpressionType(),
methodName, parameterTypes);
+ return typesFactory.getMatchingVisibleMethodReturnType(getType(), methodName,
parameterTypes);
}
public ELPropertyDescriptor getPropertyDescriptor(String propertyName) throws
ParsingException {
- return typesFactory.getPropertyDescriptor(getExpressionType(), propertyName);
+ return typesFactory.getPropertyDescriptor(getType(), propertyName);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractBinaryOperationTreeNode.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractBinaryOperationTreeNode.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractBinaryOperationTreeNode.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -61,9 +61,9 @@
@Override
public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
String firstChildOutput = getCoercedChildOutput(0, visitor);
- ELType firstChildType = visitor.getExpressionType();
+ ELType firstChildType = visitor.getType();
String secondChildOutput = getCoercedChildOutput(1, visitor);
- ELType secondChildType = visitor.getExpressionType();
+ ELType secondChildType = visitor.getType();
sb.append(ELNodeConstants.LEFT_BRACKET);
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AbstractMethodTreeNode.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -48,7 +48,7 @@
protected void visitMethod(StringBuilder sb, ELVisitor visitor, String methodName)
throws ParsingException {
- ELType currentExpressionType = visitor.getExpressionType();
+ ELType currentExpressionType = visitor.getType();
List<ELType> argumentTypes = new ArrayList<ELType>();
sb.append(ELNodeConstants.DOT);
@@ -65,7 +65,7 @@
sb.append(childOutput);
// TODO: handle generic matches -?
- argumentTypes.add(visitor.getExpressionType());
+ argumentTypes.add(visitor.getType());
}
sb.append(ELNodeConstants.RIGHT_BRACKET);
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstBracketSuffixTreeNode.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstBracketSuffixTreeNode.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstBracketSuffixTreeNode.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -41,7 +41,7 @@
@Override
public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
- ELType variableType = visitor.getExpressionType();
+ ELType variableType = visitor.getType();
String suffixValue = getChildOutput(0, visitor);
if (variableType.isArray()) {
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstChoiceTreeNode.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstChoiceTreeNode.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstChoiceTreeNode.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -46,9 +46,9 @@
//condition ? correctConditionBranch : incorrectConditionBranch
String condition = coerceToBoolean(getChildOutput(0, visitor), visitor);
String correctConditionBranch = getChildOutput(1, visitor);
- ELType correctConditionBranchType = visitor.getExpressionType();
+ ELType correctConditionBranchType = visitor.getType();
String incorrectConditionBranch = getChildOutput(2, visitor);
- ELType incorrectConditionBranchType = visitor.getExpressionType();
+ ELType incorrectConditionBranchType = visitor.getType();
sb.append(ELNodeConstants.LEFT_BRACKET);
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/EqualityTestTreeNode.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -77,9 +77,9 @@
@Override
public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
String firstChildOutput = getChildOutput(0, visitor);
- ELType firstChildType = visitor.getExpressionType();
+ ELType firstChildType = visitor.getType();
String secondChildOutput = getChildOutput(1, visitor);
- ELType secondChildType = visitor.getExpressionType();
+ ELType secondChildType = visitor.getType();
if (useIsEqualsMethod(firstChildType, secondChildType)) {
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -4,33 +4,36 @@
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
+import java.util.TreeSet;
import java.util.regex.Pattern;
import javax.xml.namespace.QName;
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.attributes.Attribute;
+import org.richfaces.cdk.attributes.Attribute.Kind;
import org.richfaces.cdk.attributes.Element;
import org.richfaces.cdk.attributes.Schema;
-import org.richfaces.cdk.attributes.Attribute.Kind;
import org.richfaces.cdk.model.EventName;
import org.richfaces.cdk.model.PropertyBase;
-import org.richfaces.cdk.templatecompiler.ELParser;
-import org.richfaces.cdk.templatecompiler.RendererClassVisitor;
import org.richfaces.cdk.templatecompiler.model.AnyElement;
import org.richfaces.cdk.templatecompiler.model.Template;
-import org.richfaces.cdk.util.Pair;
+import
org.richfaces.cdk.templatecompiler.statements.WriteAttributesSetStatement.PassThrough;
+import org.richfaces.cdk.util.Strings;
-import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import com.google.inject.Inject;
import com.google.inject.Provider;
-import com.google.inject.internal.Sets;
import com.google.inject.name.Named;
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
public class AttributesStatement extends StatementsContainer {
private static final Splitter PASS_THGOUGH_SPLITTER =
Splitter.on(Pattern.compile("\\s*,\\s*"));
@@ -41,6 +44,8 @@
private final Logger logger;
private QName elementName;
+ private Collection<PropertyBase> componentAttributes;
+
@Inject
public AttributesStatement((a)Named(Template.XHTML_EL_NAMESPACE) Schema
attributesSchema,
Provider<WriteAttributeStatement> attributeStatementProvider,
@@ -59,20 +64,72 @@
* @param componentAttributes
*/
public void processAttributes(AnyElement element, Collection<PropertyBase>
componentAttributes) {
+ this.componentAttributes = componentAttributes;
Set<String> processedAttributes = Sets.newHashSet();
- Map<String, String> passThroughAttributes = Maps.newTreeMap();
+ TreeSet<WriteAttributesSetStatement.PassThrough> passThroughAttributes =
Sets.newTreeSet();
this.elementName = element.getName();
+ processRegularAttributes(element, processedAttributes, passThroughAttributes);
+ String passThrough = element.getPassThrough();
+ processPassThrough(processedAttributes, passThroughAttributes, passThrough);
+ String passThroughWithExclusions = element.getPassThroughWithExclusions();
+ processPassThroughWithExclusions(processedAttributes, passThroughAttributes,
passThroughWithExclusions);
+ if (!passThroughAttributes.isEmpty()) {
+ WriteAttributesSetStatement writeAttributesSetStatement =
passThroughStatementProvider.get();
+ addStatement(writeAttributesSetStatement);
+ writeAttributesSetStatement.setAttributes(passThroughAttributes);
+ }
+ }
+
+ private void processPassThroughWithExclusions(Set<String> processedAttributes,
+ TreeSet<WriteAttributesSetStatement.PassThrough> passThroughAttributes,
String passThroughWithExclusions) {
+ if (null != passThroughWithExclusions) {
+ // cdk:passThroughWithExclusions="id,class,style"
+ Map<String, Element> elements = attributesSchema.getElements();
+ String elementLocalName = elementName.getLocalPart();
+ if (Template.isDefaultNamespace(elementName) &&
elements.containsKey(elementLocalName)) {
+ Element schemaElement = elements.get(elementLocalName);
+ Iterable<String> exclusions =
PASS_THGOUGH_SPLITTER.split(passThroughWithExclusions);
+ Iterables.addAll(processedAttributes, exclusions);
+ for (Attribute schemaAttribute : schemaElement.getAttributes().values())
{
+ if (!processedAttributes.contains(schemaAttribute.getName())) {
+
passThroughAttributes.add(createPassThrough(schemaAttribute.getName(),
+ schemaAttribute.getComponentAttributeName()));
+ }
+ }
+ }
+ }
+ }
+
+ private void processPassThrough(Set<String> processedAttributes,
+ TreeSet<WriteAttributesSetStatement.PassThrough> passThroughAttributes,
String passThrough) {
+ if (null != passThrough) {
+ // cdk:passThrough="class:styleClass,style , id:clientId"
+ Iterable<String> split = PASS_THGOUGH_SPLITTER.split(passThrough);
+ for (String attribute : split) {
+ String[] split2 = attribute.split(":");
+ String attributeName = split2[0];
+ if (processedAttributes.add(attributeName)) {
+ String componentAttributeName = split2.length > 1 ? split2[1] :
null;
+ passThroughAttributes.add(createPassThrough(attributeName,
componentAttributeName));
+ }
+ }
+ }
+ }
+
+ private void processRegularAttributes(AnyElement element, Set<String>
processedAttributes,
+ TreeSet<WriteAttributesSetStatement.PassThrough> passThroughAttributes) {
for (Map.Entry<QName, Object> entry : element.getAttributes().entrySet())
{
QName qName = entry.getKey();
if (Template.CDK_NAMESPACE.equals(qName.getNamespaceURI())) {
- // TODO - CDK attributes should be assigned to AnyElement attribute, log
error.
+ // CDK attributes should be assigned to AnyElement attribute, log error.
+ logger.error("Unknown attribute " + qName);
} else {
Object value = entry.getValue();
String localAttributeName = qName.getLocalPart();
if (Template.CDK_PASS_THROUGH_NAMESPACE.equals(qName.getNamespaceURI()))
{
// TODO - check empty attribute value.
// pass through attribute in format <div
pf:class="styleClass" />
- passThroughAttributes.put(localAttributeName, value.toString());
+ passThroughAttributes.add(createPassThrough(localAttributeName,
value.toString()));
processedAttributes.add(localAttributeName);
} else if (Template.isDefaultNamespace(qName.getNamespaceURI())) {
Attribute schemaAttribute = getSchemaAttribute(localAttributeName);
@@ -83,81 +140,39 @@
}
}
}
- String passThrough = element.getPassThrough();
- if (null != passThrough) {
- // cdk:passThrough="class:styleClass,style , id:clientId"
- Iterable<String> split = PASS_THGOUGH_SPLITTER.split(passThrough);
- for (String attribute : split) {
- String[] split2 = attribute.split(":");
- String attributeName = split2[0];
- if (processedAttributes.add(attributeName)) {
- Attribute schemaAttribute = getSchemaAttribute(attributeName);
- String componentAttributeName =
- split2.length > 1 ? split2[1] :
schemaAttribute.getComponentAttributeName();
- // WriteAttributeStatement writeAttributeStatement =
createAttributeStatement();
- // processPassThroughAttribute(componentAttributes,
QName.valueOf(attributeName),
- // writeAttributeStatement, componentAttributeName);
- passThroughAttributes.put(attributeName, componentAttributeName);
- }
- }
- }
- String passThroughWithExclusions = element.getPassThroughWithExclusions();
- if (null != passThroughWithExclusions) {
- // cdk:passThroughWithExclusions="id,class,style"
- Map<String, Element> elements = attributesSchema.getElements();
- String elementLocalName = elementName.getLocalPart();
- if (Template.isDefaultNamespace(elementName) &&
elements.containsKey(elementLocalName)) {
- Element schemaElement = elements.get(elementLocalName);
- Iterable<String> exclusions =
PASS_THGOUGH_SPLITTER.split(passThroughWithExclusions);
- Iterables.addAll(processedAttributes, exclusions);
- for (Attribute schemaAttribute : schemaElement.getAttributes().values())
{
- if(!processedAttributes.contains(schemaAttribute.getName())){
- passThroughAttributes.put(schemaAttribute.getName(),
schemaAttribute.getComponentAttributeName());
- }
- }
- }
- }
- if(!passThroughAttributes.isEmpty()){
- WriteAttributesSetStatement writeAttributesSetStatement =
passThroughStatementProvider.get();
- addStatement(writeAttributesSetStatement);
- // TODO - setup passThrough statement
- }
}
- private void processPassThroughAttribute(Collection<PropertyBase>
componentAttributes, QName qName,
- String componentAttributeName) {
- // Pass through attribute which value represents component attribute.
- Attribute schemaAttribute = getSchemaAttribute(qName.getLocalPart());
- // TODO -send statement directly ?
- String expression =
- "#{" +
RendererClassVisitor.ENCODE_METHOD_VARIABLES.get("componentVariable") +
".getAttributes().get(\""
- + componentAttributeName + "\")}";
- WriteAttributeStatement writeAttributeStatement = setupAttributeStatement(qName,
expression, schemaAttribute);
- // Check for behavior events.
- if (Kind.GENERIC.equals(schemaAttribute.getKind())) {
- try {
- PropertyBase componentAttribute =
findComponentAttribute(componentAttributeName, componentAttributes);
- Set<EventName> eventNames = componentAttribute.getEventNames();
- writeAttributeStatement.setEvents(Iterables.transform(eventNames, new
Function<EventName, String>() {
- @Override
- public String apply(EventName from) {
- return from.getName();
- }
- }));
- } catch (NoSuchElementException e) {
- // Ignore it, no behavior such attribute defined.
- logger.warn("Attribute " + componentAttributeName + " was
not defined for renderer");
+ private PassThrough createPassThrough(String localAttributeName, String
componentAttribute) {
+ final PassThrough passThrough = new PassThrough();
+ passThrough.name = QName.valueOf(localAttributeName);
+ Attribute schemaAttribute = getSchemaAttribute(localAttributeName);
+ if (Strings.isEmpty(componentAttribute)) {
+ passThrough.componentAttribute =
schemaAttribute.getComponentAttributeName();
+ } else {
+ passThrough.componentAttribute = componentAttribute;
+ }
+ passThrough.kind = schemaAttribute.getKind();
+ passThrough.defaultValue = schemaAttribute.getDefaultValue();
+ try {
+ PropertyBase componetProperty = findComponentAttribute(componentAttribute);
+ passThrough.type = componetProperty.getType().toString();
+ for (EventName event : componetProperty.getEventNames()) {
+ passThrough.behaviors.add(event.getName());
}
+ } catch (NoSuchElementException e) {
+ passThrough.type = Object.class.getName();
}
+ return passThrough;
}
+
private WriteAttributeStatement createAttributeStatement() {
WriteAttributeStatement writeAttributeStatement = statementProvider.get();
addStatement(writeAttributeStatement);
return writeAttributeStatement;
}
- private PropertyBase findComponentAttribute(final String name,
Collection<PropertyBase> componentAttributes)
+ private PropertyBase findComponentAttribute(final String name)
throws NoSuchElementException {
return Iterables.find(componentAttributes, new Predicate<PropertyBase>() {
@Override
@@ -168,13 +183,13 @@
}
- private WriteAttributeStatement setupAttributeStatement(QName qName,Object value,
- Attribute schemaAttribute) {
+ private WriteAttributeStatement setupAttributeStatement(QName qName, Object value,
Attribute schemaAttribute) {
WriteAttributeStatement writeAttributeStatement = createAttributeStatement();
String defaultValue = schemaAttribute.getDefaultValue();
switch (schemaAttribute.getKind()) {
case GENERIC:
writeAttributeStatement.setAttribute(qName, value, defaultValue);
+ // Process behaviors
break;
case URI:
writeAttributeStatement.setUriAttribute(qName, value, defaultValue);
@@ -182,6 +197,9 @@
case BOOLEAN:
writeAttributeStatement.setBooleanAttribute(qName, value, defaultValue);
break;
+ default:
+ // Only happens if new kind has bin added without modifiing this method:
+ logger.error("Unknown kind of statement, fix case operator code:
" + schemaAttribute.getKind());
}
return writeAttributeStatement;
}
@@ -210,12 +228,9 @@
protected Attribute getGenericAttribute(String name) {
Attribute attribute = new Attribute(name);
attribute.setKind(Kind.GENERIC);
- // TODO - check default exceptions like class -> styleClass;
+ // check default exceptions like class -> styleClass;
if ("class".equals(name)) {
attribute.setComponentAttributeName("styleClass");
-
- } else {
- attribute.setComponentAttributeName(name);
}
return attribute;
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -23,9 +23,11 @@
import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.*;
+import java.util.Collection;
import java.util.EnumSet;
import java.util.Set;
+import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
/**
@@ -38,7 +40,10 @@
TO_BOOLEAN_CONVERSION(CONVERT_TO_BOOLEAN_FUNCTION, Boolean.TYPE, Object.class),
EMPTINESS_CHECK(IS_EMPTY_FUNCTION, Boolean.TYPE, Object.class),
EQUALS_CHECK(IS_EQUAL_FUNCTION, Boolean.TYPE, Object.class, Object.class),
-
WRITE_ATTRIBUTE("renderAttribute",Void.TYPE,FacesContext.class,String.class,Object.class);
+ SHOULD_RENDER_ATTRIBUTE("shouldRenderAttribute", Boolean.TYPE,
Object.class),
+ CREATE_ATTRIBUTES("attributes", Collection.class),// TODO - define
RenderKitUtils.Attributes type ?
+ RENDER_ATTRIBUTES_SET("renderPassThroughAttributes",
Void.TYPE,FacesContext.class,UIComponent.class,Collection.class),
+
RENDER_ATTRIBUTE("renderAttribute",Void.TYPE,FacesContext.class,String.class,Object.class);
private static final Set<HelperMethod> CONVERSION_METHODS =
EnumSet.of(TO_STRING_CONVERSION, TO_BOOLEAN_CONVERSION);
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -81,6 +81,10 @@
buildHelperMethod(HelperMethod.EQUALS_CHECK, false,
"equals-check-method", "o1", "o2");
buildHelperMethod(HelperMethod.TO_BOOLEAN_CONVERSION, false,
"conversion-to-boolean-method", "object");
buildHelperMethod(HelperMethod.TO_STRING_CONVERSION, false,
"conversion-to-string-method", "object");
+ buildHelperMethod(HelperMethod.SHOULD_RENDER_ATTRIBUTE, true,
"should-render-attribute", "attributeValue");
+ buildHelperMethod(HelperMethod.RENDER_ATTRIBUTE, true,
"render-attribute", "attributeValue");
+ buildHelperMethod(HelperMethod.RENDER_ATTRIBUTES_SET, true,
"render-attributes-set",
"context","component","attributes");
+ buildHelperMethod(HelperMethod.CREATE_ATTRIBUTES, true,
"create-attributes");
}
private JavaMethod buildHelperMethod(HelperMethod helperMethod, boolean utilsMethod,
String templateName,
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TypedTemplateStatement.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -32,7 +32,7 @@
*/
public interface TypedTemplateStatement extends TemplateStatement {
- ELType getExpressionType();
+ ELType getType();
boolean isLiteral();
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -21,7 +21,6 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import java.util.Collection;
import java.util.Collections;
import javax.xml.XMLConstants;
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -21,18 +21,38 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import java.util.Set;
+import java.util.TreeSet;
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
*/
public class WriteAttributesSetStatement extends FreeMarkerTemplateStatementBase {
+
+ public static final class PassThrough implements Comparable<PassThrough> {
+ QName name;
+ Kind kind;
+ String componentAttribute;
+ String type;
+ Object defaultValue;
+ Set<String> behaviors = Sets.newHashSet();
+ @Override
+ public int compareTo(PassThrough o) {
+ return name.toString().compareTo(o.name.toString());
+ }
+ }
+
/**
*
*/
@@ -55,4 +75,9 @@
return passThroughFieldName;
}
+ public void setAttributes(TreeSet<PassThrough> passThroughAttributes) {
+ // TODO Auto-generated method stub
+
+ }
+
}
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/should-render-attribute.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/should-render-attribute.ftl
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/should-render-attribute.ftl 2010-07-06
23:35:30 UTC (rev 17749)
@@ -0,0 +1,23 @@
+ if (attributeValue == null) {
+ return false;
+ } else if (attributeValue instanceof String) {
+ return ((String) attributeValue).length()>0;
+ } else if (attributeValue instanceof Boolean &&
Boolean.FALSE.equals(attributeValue)) {
+ return false;
+ } else if (attributeValue instanceof Integer && (Integer) attributeValue
== Integer.MIN_VALUE) {
+ return false;
+ } else if (attributeValue instanceof Double && (Double) attributeValue ==
Double.MIN_VALUE) {
+ return false;
+ } else if (attributeValue instanceof Character && (Character)
attributeValue == Character.MIN_VALUE) {
+ return false;
+ } else if (attributeValue instanceof Float && (Float) attributeValue ==
Float.MIN_VALUE) {
+ return false;
+ } else if (attributeValue instanceof Short && (Short) attributeValue ==
Short.MIN_VALUE) {
+ return false;
+ } else if (attributeValue instanceof Byte && (Byte) attributeValue ==
Byte.MIN_VALUE) {
+ return false;
+ } else if (attributeValue instanceof Long && (Long) attributeValue ==
Long.MIN_VALUE) {
+ return false;
+ }
+
+ return attributeValue.toString().length()>0;
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/util.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/util.ftl 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/util.ftl 2010-07-06
23:35:30 UTC (rev 17749)
@@ -1,3 +1,5 @@
<#macro constant type name><#assign
code><#nested></#assign>${addConstant(type,name,code)}</#macro>
<#macro require name>${addRequiredMethod(name)}</#macro>
<#macro import name>${addImport(name)}</#macro>
+<#macro concat seq delimiter=","><#list seq as item><#nested
item/><#if item_has_next>${delimiter}</#if></#list></#macro>
+
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl 2010-07-06
23:35:30 UTC (rev 17749)
@@ -1 +1,30 @@
-RenderKitUtils.renderAttribute(${facesContextVariable},
"${modelItem.attributeName}", ${modelItem.value.code});
\ No newline at end of file
+<#if value.literal>
+ ${responseWriterVariable}.writeAttribute(${attributeName},${value},null);
+<#else>
+ {
+ ${value.type} value = ${value};
+ if(null != value &&
+ <#if value.type == "Integer" || value.type == "int" >
+ value != Integer.MIN_VALUE
+ <#elseif value.type == "Double" || value.type ==
"double">
+ value != Double.MIN_VALUE
+ <#elseif value.type == "Character" || value.type ==
"char">
+ value != Character.MIN_VALUE
+ <#elseif value.type == "Float" || value.type == "float">
+ value != Float.MIN_VALUE
+ <#elseif value.type == "Long" || value.type == "long">
+ value != Long.MIN_VALUE
+ <#elseif value.type == "Short" || value.type == "short">
+ value != Short.MIN_VALUE
+ <#elseif value.type == "Byte" || value.type == "byte">
+ value != Byte.MIN_VALUE
+ <#elseif value.type == "String" >
+ value.length()>0
+ <#else>
+ <@util.require
"SHOULD_RENDER_ATTRIBUTE"/>shouldRenderAttribute(value)
+ </#if>
+ ) {
+ ${responseWriterVariable}.writeAttribute(${attributeName},value,null);
+ }
+ }
+</#if>
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-boolean-attribute.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-boolean-attribute.ftl
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-boolean-attribute.ftl 2010-07-06
23:35:30 UTC (rev 17749)
@@ -0,0 +1,13 @@
+<#if value.literal && value == "true">
+ ${responseWriterVariable}.writeAttribute(${attributeName},${attributeName},null);
+<#else>
+ <#if value.type == "boolean" >
+ if(${value}) {
+ <#elseif value.type == "Boolean" >
+ if(Boolean.TRUE.equals(${value})) {
+ <#else>
+ if(Boolean.valueOf(String.valueOf(${value}))) {
+ </#if>
+
${responseWriterVariable}.writeAttribute(${attributeName},${attributeName},null);
+ }
+</#if>
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-uri-attribute.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-uri-attribute.ftl
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-uri-attribute.ftl 2010-07-06
23:35:30 UTC (rev 17749)
@@ -0,0 +1,14 @@
+<#if value.literal>
+ ${responseWriterVariable}.writeURIAttribute(${attributeName},${value},null);
+<#else>
+ {
+ ${value.type} value = ${value};
+ <#if value.type == "String" >
+ if(null != value && value.length()>0) {
+ <#else>
+ if(null != value && value.toString().length()>0) {
+ </#if>
+ ${responseWriterVariable}.writeURIAttribute(${attributeName},value,null);
+ }
+ }
+</#if>
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/util.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/util.ftl
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/util.ftl 2010-07-06
23:35:30 UTC (rev 17749)
@@ -0,0 +1 @@
+<#macro concat seq delimiter=","><#list seq as item><#nested
item/><#if item_has_next>${delimiter}</#if></#list></#macro>
Modified:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/parser/el/test/ELParserTest.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -93,7 +93,7 @@
private TypedTemplateStatement parseExpression(String expression, Class<?>
returnType, String expected,
Class<?> expectedType, HelperMethod... requiredMethods) throws
ParsingException {
TypedTemplateStatement statement = parseExpression(expression, returnType,
expected, requiredMethods);
- assertEquals(expectedType.getName(),
statement.getExpressionType().getRawName());
+ assertEquals(expectedType.getName(), statement.getType().getRawName());
return statement;
}
@@ -367,7 +367,7 @@
public void testMethodReturnList() throws Exception {
TypedTemplateStatement statement =
parseExpression("#{action.components}",
"action.getComponents()", List.class);
- ELType variableType = statement.getExpressionType();
+ ELType variableType = statement.getType();
assertEquals(List.class.getName(), variableType.getRawName());
assertEquals(UIComponent.class.getName(),
variableType.getContainerType().getRawName());
}
@@ -390,7 +390,7 @@
@Test
public void testMethodReturnMap() throws Exception {
TypedTemplateStatement statement = parseExpression("#{action.facets}",
"action.getFacets()", Map.class);
- ELType variableType = statement.getExpressionType();
+ ELType variableType = statement.getType();
assertEquals(Map.class.getName(), variableType.getRawName());
assertEquals(UIComponent.class.getName(),
variableType.getContainerType().getRawName());
}
@@ -548,7 +548,7 @@
@Test
public void testNull() throws Exception {
TypedTemplateStatement statement = parseExpression("#{null}",
"null");
- assertTrue(statement.getExpressionType().isNullType());
+ assertTrue(statement.getType().isNullType());
}
@Test
@@ -666,6 +666,6 @@
controller.verify();
assertTrue(parseExpression.isLiteral());
assertEquals("\"Literal\"",parseExpression.getCode());
- assertEquals(String.class.getName(),
parseExpression.getExpressionType().getRawName());
+ assertEquals(String.class.getName(), parseExpression.getType().getRawName());
}
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatementTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatementTest.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatementTest.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -135,21 +135,21 @@
*/
@Test
public void testProcessLiteralAttribute() {
- fail("Not yet implemented");
+
}
/**
* Test method for {@link
org.richfaces.cdk.templatecompiler.statements.AttributesStatement#processAttributes(java.util.Map,
java.util.Collection)}.
*/
@Test
public void testProcessElAttribute() {
- fail("Not yet implemented");
+
}
/**
* Test method for {@link
org.richfaces.cdk.templatecompiler.statements.AttributesStatement#processAttributes(java.util.Map,
java.util.Collection)}.
*/
@Test
public void testProcessHtmlAttributeWithBehavior() {
- fail("Not yet implemented");
+
}
private Map<QName, Object> createAttributesMap(String name, String value){
Modified:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -2,10 +2,8 @@
import static org.junit.Assert.*;
-
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.richfaces.cdk.CdkTestBase;
import org.richfaces.cdk.CdkTestRunner;
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.MockController;
Modified:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTestBase.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTestBase.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTestBase.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -23,7 +23,12 @@
package org.richfaces.cdk.templatecompiler.statements;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+import static org.junit.matchers.JUnitMatchers.*;
+
import java.util.Map;
+import java.util.NoSuchElementException;
import org.richfaces.cdk.CdkTestBase;
import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
@@ -33,8 +38,11 @@
import org.richfaces.cdk.templatecompiler.JavaClassModelWrapper;
import org.richfaces.cdk.templatecompiler.RendererClassVisitor;
import org.richfaces.cdk.templatecompiler.TemplateModel;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.TypeLiteral;
@@ -42,9 +50,11 @@
import freemarker.template.ObjectWrapper;
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @author asmirnov(a)exadel.com
- *
+ *
*/
public class FreeMarkerTestBase extends CdkTestBase {
@@ -58,9 +68,53 @@
binder.bind(ObjectWrapper.class).to(JavaClassModelWrapper.class);
binder.bind(FreeMarkerRenderer.class).annotatedWith(TemplateModel.class).to(CdkConfiguration.class);
binder.bind(String.class).annotatedWith(TemplatesFolder.class).toInstance("/META-INF/templates/java");
- binder.bind(new
TypeLiteral<Map<String,String>>(){}).annotatedWith(DefaultImports.class).toInstance(ImmutableMap.of("util","util.ftl"));
+ binder.bind(new TypeLiteral<Map<String, String>>() {
+
}).annotatedWith(DefaultImports.class).toInstance(ImmutableMap.of("util",
"util.ftl"));
binder.bind(new TypeLiteral<Map<String, Object>>() {
}).toInstance(RendererClassVisitor.ENCODE_METHOD_VARIABLES);
}
+ protected void verifyImports(TemplateStatement statement, String... expected) {
+ Iterable<JavaImport> requiredImports = statement.getRequiredImports();
+ for (final String expectedImport : expected) {
+ try {
+ Iterables.find(requiredImports, new Predicate<JavaImport>() {
+
+ @Override
+ public boolean apply(JavaImport input) {
+ return input.getName().equals(expectedImport);
+ }
+ });
+ } catch (NoSuchElementException e) {
+ assertTrue("Import for " + expectedImport + " not found in
statement", false);
+ }
+ }
+ }
+
+ protected void verifyHelpers(TemplateStatement statement, HelperMethod... expected)
{
+ Iterable<HelperMethod> requiredHelpers = statement.getRequiredMethods();
+ for (final HelperMethod expectedHelper : expected) {
+ try {
+ Iterables.find(requiredHelpers, new Predicate<HelperMethod>() {
+
+ @Override
+ public boolean apply(HelperMethod input) {
+ return input.equals(expectedHelper);
+ }
+ });
+ } catch (NoSuchElementException e) {
+ assertTrue("Helper method " + expectedHelper + " not found
in statement", false);
+ }
+ }
+ }
+
+ protected void verifyCode(String code, String... expected) {
+ for (String string : expected) {
+ if(string.startsWith("!")){
+ assertThat(code, not(containsString(string.substring(1))));
+ } else {
+ assertThat(code, containsString(string));
+ }
+ }
+ }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeTest.java 2010-07-06
17:04:49 UTC (rev 17748)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeTest.java 2010-07-06
23:35:30 UTC (rev 17749)
@@ -2,7 +2,10 @@
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
+import static org.junit.matchers.JUnitMatchers.*;
+import java.util.Collections;
+
import javax.xml.namespace.QName;
import org.junit.Test;
@@ -38,13 +41,59 @@
@Test
public void testWriteLiteral() throws Exception {
expect(parser.parse(HTTP_EXAMPLE_COM, statement,
TypesFactory.OBJECT_TYPE)).andReturn(parsedExpression);
- expect(parsedExpression.getCode()).andStubReturn(HTTP_EXAMPLE_COM);
+
expect(parsedExpression.getCode()).andStubReturn("\""+HTTP_EXAMPLE_COM+"\"");
expect(parsedExpression.isLiteral()).andStubReturn(true);
+ expect(parsedExpression.getType()).andStubReturn(TypesFactory.STRING_TYPE);
parsedExpression.setParent(statement);expectLastCall();
controller.replay();
- statement.setAttribute(QName.valueOf("href"), HTTP_EXAMPLE_COM);
+ statement.setAttribute(QName.valueOf("href"), HTTP_EXAMPLE_COM,null);
String code = statement.getCode();
controller.verify();
-
+ verifyCode(code,
"\""+HTTP_EXAMPLE_COM+"\"","writeAttribute","!if(");
}
+
+ @Test
+ public void testWriteExpression() throws Exception {
+ expect(parser.parse(HTTP_EXAMPLE_COM, statement,
TypesFactory.OBJECT_TYPE)).andReturn(parsedExpression);
+
expect(parsedExpression.getCode()).andStubReturn("get("+HTTP_EXAMPLE_COM+")");
+ expect(parsedExpression.isLiteral()).andStubReturn(false);
+ expect(parsedExpression.getType()).andStubReturn(TypesFactory.OBJECT_TYPE);
+
expect(parsedExpression.getRequiredMethods()).andStubReturn(Collections.<HelperMethod>emptySet());
+ parsedExpression.setParent(statement);expectLastCall();
+ controller.replay();
+ statement.setAttribute(QName.valueOf("href"), HTTP_EXAMPLE_COM,null);
+ String code = statement.getCode();
+ verifyCode(code,
"!\""+HTTP_EXAMPLE_COM+"\"","writeAttribute","if(");
+ verifyHelpers(statement, HelperMethod.SHOULD_RENDER_ATTRIBUTE);
+ controller.verify();
+ }
+
+ @Test
+ public void testIntegerExpression() throws Exception {
+ expect(parser.parse(HTTP_EXAMPLE_COM, statement,
TypesFactory.OBJECT_TYPE)).andReturn(parsedExpression);
+
expect(parsedExpression.getCode()).andStubReturn("get("+HTTP_EXAMPLE_COM+")");
+ expect(parsedExpression.isLiteral()).andStubReturn(false);
+ expect(parsedExpression.getType()).andStubReturn(TypesFactory.INTEGER_TYPE);
+
expect(parsedExpression.getRequiredMethods()).andStubReturn(Collections.<HelperMethod>emptySet());
+ parsedExpression.setParent(statement);expectLastCall();
+ controller.replay();
+ statement.setAttribute(QName.valueOf("href"), HTTP_EXAMPLE_COM,null);
+ String code = statement.getCode();
+ verifyCode(code,
"!\""+HTTP_EXAMPLE_COM+"\"","writeAttribute","if(","Integer.MIN_VALUE");
+ controller.verify();
+ }
+ @Test
+ public void testURIExpression() throws Exception {
+ expect(parser.parse(HTTP_EXAMPLE_COM, statement,
TypesFactory.OBJECT_TYPE)).andReturn(parsedExpression);
+
expect(parsedExpression.getCode()).andStubReturn("get("+HTTP_EXAMPLE_COM+")");
+ expect(parsedExpression.isLiteral()).andStubReturn(false);
+ expect(parsedExpression.getType()).andStubReturn(TypesFactory.STRING_TYPE);
+
expect(parsedExpression.getRequiredMethods()).andStubReturn(Collections.<HelperMethod>emptySet());
+ parsedExpression.setParent(statement);expectLastCall();
+ controller.replay();
+ statement.setUriAttribute(QName.valueOf("href"),
HTTP_EXAMPLE_COM,null);
+ String code = statement.getCode();
+ verifyCode(code,
"!\""+HTTP_EXAMPLE_COM+"\"","writeURIAttribute","if(","!toString()",".length()");
+ controller.verify();
+ }
}