Author: alexsmirnov
Date: 2010-07-08 20:18:37 -0400 (Thu, 08 Jul 2010)
New Revision: 17776
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/ContextVariables.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/QNameTemplateModel.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/ForEachTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WtiteTextTest.java
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELParser.java
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/RendererClassVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Template.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.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/IfStatement.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/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/schema/xhtml-el.xsd
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/define-object.ftl
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/for-each.ftl
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/if-else.ftl
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-attributes-set.ftl
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-text.ftl
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.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
root/commons/branches/RF8755/api/src/main/java/org/richfaces/renderkit/ComponentAttribute.java
root/commons/branches/RF8755/api/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
Log:
https://jira.jboss.org/browse/RF-8306
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -66,7 +66,7 @@
}
@Inject(optional=true)
- protected void setSharedVariables(Map<String,Object> variables) {
+ public void setSharedVariables(@ContextVariables Map<String,Object> variables)
{
// template method for subclasses.
for (Map.Entry<String,Object> entry : variables.entrySet()) {
try {
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/ContextVariables.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/ContextVariables.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/ContextVariables.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -0,0 +1,48 @@
+/*
+ * $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.generate.freemarker;
+
+import static java.lang.annotation.ElementType.*;
+import static java.lang.annotation.RetentionPolicy.*;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+/**
+ * <p class="changed_added_4_0">
+ * Marks {@link org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer} instance that
is targeted to work with JSF
+ * library model
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@Retention(RUNTIME)
+@Target({ FIELD, PARAMETER, METHOD })
+@BindingAnnotation
+public @interface ContextVariables {
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/ContextVariables.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELParser.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELParser.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ELParser.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -10,6 +10,8 @@
TypedTemplateStatement parse(String expression, Variables variables, ELType
expectedType) throws ParsingException;
+ TypedTemplateStatement parse(String expression, Variables variables, String
expectedType) throws ParsingException;
+
ELType getType(Class<?> targetClass);
ELType getType(String classExpression);
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-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -1,5 +1,7 @@
package org.richfaces.cdk.templatecompiler;
+import javax.xml.namespace.QName;
+
import org.richfaces.cdk.templatecompiler.builder.model.JavaStatement;
import org.richfaces.cdk.templatecompiler.el.types.ELType;
@@ -24,6 +26,8 @@
templateModel = new MethodBodyTemplateModel((JavaStatement) obj, this);
} else if (obj instanceof ELType){
templateModel = new ELTypeTemplateModel((ELType)obj, this);
+ } else if (obj instanceof QName){
+ templateModel = new QNameTemplateModel((QName)obj, this);
} else {
templateModel = super.wrap(obj);
}
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/QNameTemplateModel.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/QNameTemplateModel.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/QNameTemplateModel.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -0,0 +1,57 @@
+/*
+ * $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 javax.xml.namespace.QName;
+
+import org.richfaces.cdk.templatecompiler.model.Template;
+
+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 QNameTemplateModel extends StringModel implements TemplateModel {
+
+ private final QName qName;
+
+ public QNameTemplateModel(QName obj, BeansWrapper wrapper) {
+ super(obj, wrapper);
+ this.qName = obj;
+ }
+
+ @Override
+ public String getAsString() {
+ StringBuilder nameBuilder = new StringBuilder();
+ if(!Template.isDefaultNamespace(qName)){
+ nameBuilder.append(qName.getPrefix()).append(':');
+ }
+ return nameBuilder.append(qName.getLocalPart()).toString();
+ }
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/QNameTemplateModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -27,7 +27,6 @@
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.EnumSet;
-import java.util.Map;
import java.util.Set;
import javax.faces.component.UIComponent;
@@ -83,7 +82,6 @@
import org.richfaces.cdk.util.Strings;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
/**
@@ -134,9 +132,6 @@
*/
private static final String PASS_THROUGH_ATTRIBUTES_FIELD_NAME =
"PASS_THROUGH_ATTRIBUTES";
- private static final Set<String> DEFAULT_NAMESPACES =
ImmutableSet.of(Template.XHTML_EL_NAMESPACE,
- Template.XHTML_NAMESPACE);
-
private final Logger log;
private final Injector injector;
@@ -200,19 +195,6 @@
}
}
- private boolean isDefaultNamespace(String namespaceURI) {
- // TODO - another namespaces
- if (Strings.isEmpty(namespaceURI)) {
- return true;
- }
-
- if (DEFAULT_NAMESPACES.contains(namespaceURI)) {
- return true;
- }
-
- return false;
- }
-
private ELType getType(Type type) {
return typesFactory.getType(type);
}
@@ -281,7 +263,7 @@
protected <T extends StatementsContainer> T pushStatement(Class<T>
container) {
T statement = createStatement(container);
- pushStatement(container);
+ pushStatement(statement);
return statement;
}
@@ -344,69 +326,14 @@
@Override
public void startElement(AnyElement anyElement) throws CdkException {
QName elementName = anyElement.getName();
- Map<QName, Object> elementAttributes = anyElement.getAttributes();
-
- if (!isDefaultNamespace(elementName.getNamespaceURI())) {
- // TODO: add support
- return;
+ if (Template.isDirectiveNamespace(elementName)) {
+ log.error("Unknown directive element "+elementName);
+ } else {
+ StartElementStatement startElementStatement =
addStatement(StartElementStatement.class);
+ startElementStatement.setElementName(elementName);
+ AttributesStatement attributesStatement =
addStatement(AttributesStatement.class);
+ attributesStatement.processAttributes(anyElement, attributes);
}
- StartElementStatement startElementStatement =
addStatement(StartElementStatement.class);
- startElementStatement.setElementName(elementName.getLocalPart());
- AttributesStatement attributesStatement =
addStatement(AttributesStatement.class);
- attributesStatement.processAttributes(anyElement, attributes);
- // Set<String> writtenAttributes = new HashSet<String>();
- // boolean shouldEncodePassThrough = false;
- // String[] passThroughExclusions = null;
- //
- // Map<QName, Object> sortedElementAttributes = new TreeMap<QName,
Object>(QNAME_COMPARATOR);
- // sortedElementAttributes.putAll(elementAttributes);
- //
- // for (Map.Entry<QName, Object> attribute :
sortedElementAttributes.entrySet()) {
- // QName attributeName = attribute.getKey();
- // Object attributeValue = attribute.getValue();
- //
- // if (!isDefaultNamespace(attributeName.getNamespaceURI())) {
- // // TODO: add support
- // if (Template.CDK_NAMESPACE.equals(attributeName.getNamespaceURI())
- // &&
"passThroughWithExclusions".equals(attributeName.getLocalPart())) {
- //
- // shouldEncodePassThrough = true;
- // if (attributeValue != null) {
- // passThroughExclusions = attributeValue.toString().split("\\s+");
- // }
- // }
- // } else {
- // String attributeLocalName = attributeName.getLocalPart();
- // if (writtenAttributes.add(attributeLocalName)) {
- // addStatement(new WriteAttributeStatement(attributeLocalName, compileEl(
- // attributeValue.toString(), Object.class)));
- // }
- // }
- // }
- //
- // if (shouldEncodePassThrough) {
- // Element attributesElement =
attributesSchema.getElements().get(elementName.getLocalPart());
- // if (attributesElement != null) {
- // // make a copy of original set
- // TreeMap<String, Attribute> actualAttributesMap =
- // new TreeMap<String, Attribute>(attributesElement.getAttributes());
- //
- // if (passThroughExclusions != null) {
- // for (String passThroughExclusion : passThroughExclusions) {
- // actualAttributesMap.remove(passThroughExclusion);
- // }
- // }
- //
- // for (String writtenAttribute : writtenAttributes) {
- // actualAttributesMap.remove(writtenAttribute);
- // }
- //
- // if (!actualAttributesMap.isEmpty()) {
- // String passThroughFieldName = createPassThroughField(actualAttributesMap);
- // addStatement(new WriteAttributesSetStatement(passThroughFieldName));
- // }
- // }
- // }
}
/*
@@ -420,7 +347,7 @@
public void endElement(AnyElement anyElement) throws CdkException {
QName elementName = anyElement.getName();
EndElementStatement endElementStatement =
addStatement(EndElementStatement.class);
- endElementStatement.setElementName(elementName.getLocalPart());
+ endElementStatement.setElementName(elementName);
}
/*
@@ -433,7 +360,7 @@
public void visitElement(String text) throws CdkException {
if (text != null) {
String trimmedText = text.trim();
- if (!Strings.isEmpty(trimmedText)) {
+ if (trimmedText.length()>0) {
WriteTextStatement statement = addStatement(WriteTextStatement.class);
statement.setExpression(trimmedText);
}
@@ -541,7 +468,7 @@
@Override
public void startElement(CdkOtherwiseElement cdkOtherwiseElement) {
- IfStatement ifStatement = pushStatement(IfStatement.class);
+ pushStatement(StatementsContainer.class);
}
/*
@@ -566,45 +493,13 @@
@Override
public void visitElement(CdkObjectElement cdkObjectElement) {
String name = cdkObjectElement.getName();
-
String value = cdkObjectElement.getValue();
if (Strings.isEmpty(value)) {
value = cdkObjectElement.getBodyValue();
}
-
- String typeString = cdkObjectElement.getType();
- String typeArgumentsString = cdkObjectElement.getTypeArguments();
- if (!Strings.isEmpty(typeArgumentsString)) {
- // TODO: generic arrays
- typeString += "<" + typeArgumentsString + ">";
- }
-
- // ELType type = null;
- // if (!Strings.isEmpty(typeString)) {
- // type = TypesFactoryImpl.getType(typeString, typesFactory);
- // }
- //
- // if (!Strings.isEmpty(value)) {
- // Class<?> valueType;
- // if (type != null) {
- // valueType = type.getRawType();
- // } else {
- // valueType = Object.class;
- // }
- //
- // value = compileEl(value, valueType);
- // if (type == null) {
- // type = lastCompiledExpressionType;
- // }
- // }
- //
- // if (type == null) {
- // type = TypesFactory.OBJECT_TYPE;
- // }
- //
- // defineObject(type, name, value);
+ String type = cdkObjectElement.getType();
DefineObjectStatement statement = addStatement(DefineObjectStatement.class);
- // TODO - set parameters.
+ statement.setObject(name,type,value);
}
/*
@@ -625,7 +520,7 @@
// collectionElementClass = Object.class;
// }
ForEachStatement forEachStatement = pushStatement(ForEachStatement.class);
- forEachStatement.setItemsExpression(items);
+ forEachStatement.setItemsExpression(items,cdkForEachElement.getVar());
// currentStatement.setVariable(cdkForEachElement.getVar(),
lastCompiledExpressionType.getContainerType());
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -29,6 +29,7 @@
import org.richfaces.cdk.ModelBuilder;
import org.richfaces.cdk.attributes.Schema;
import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
+import org.richfaces.cdk.generate.freemarker.ContextVariables;
import org.richfaces.cdk.generate.freemarker.DefaultImports;
import org.richfaces.cdk.generate.freemarker.FreeMakerUtils;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
@@ -37,10 +38,12 @@
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactoryImpl;
import org.richfaces.cdk.templatecompiler.model.Template;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethod;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactoryImpl;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
import com.google.inject.AbstractModule;
import com.google.inject.PrivateBinder;
import com.google.inject.Singleton;
@@ -83,9 +86,17 @@
privateBinder.bind(FreeMakerUtils.class);
privateBinder.bind(ObjectWrapper.class).to(JavaClassModelWrapper.class);
privateBinder.bind(new TypeLiteral<Map<String, Object>>() {
- }).toInstance(RendererClassVisitor.ENCODE_METHOD_VARIABLES);
+ }).annotatedWith(ContextVariables.class).toInstance(buildVariables());
privateBinder.bind(String.class).annotatedWith(TemplatesFolder.class).toInstance("/META-INF/templates/java");
privateBinder.bind(new
TypeLiteral<Map<String,String>>(){}).annotatedWith(DefaultImports.class).toInstance(ImmutableMap.of("util","util.ftl"));
}
+ public static Map<String, Object> buildVariables() {
+ Map<String, Object> variables =
Maps.newHashMap(RendererClassVisitor.ENCODE_METHOD_VARIABLES);
+ for (Map.Entry<HelperMethod, String> entry :
HelperMethod.METHOD_NAMES.entrySet()) {
+ variables.put(entry.getKey().toString(),entry.getValue());
+ }
+ return variables;
+ }
+
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserImpl.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserImpl.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELParserImpl.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -38,6 +38,12 @@
return visitor;
}
+ @Override
+ public TypedTemplateStatement parse(String expression, Variables variables, String
expectedType)
+ throws ParsingException {
+ return parse(expression,variables,typesFactory.getType(expectedType));
+ }
+
/* (non-Javadoc)
* @see org.richfaces.cdk.templatecompiler.ELParser#getType(java.lang.Class)
*/
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Template.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Template.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Template.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -43,7 +43,7 @@
public static final String CDK_NAMESPACE =
"http://richfaces.org/cdk/core";
- public static final String CDK_PASS_THROUGH_NAMESPACE =
"http://richfaces.org/cdk/passThrough";
+ public static final String CDK_PASS_THROUGH_NAMESPACE =
"http://richfaces.org/cdk/ext";
public static final String COMPOSITE_NAMESPACE =
"http://richfaces.org/cdk/jsf/composite";
@@ -111,6 +111,15 @@
this.compositeImplementation = implementation;
}
+ public static boolean isDirectiveNamespace(QName name) {
+ return isDirectiveNamespace(name.getNamespaceURI());
+ }
+
+ public static boolean isDirectiveNamespace(String namespace) {
+ return JSTL_CORE_NAMESPACE.equals(namespace) || CDK_NAMESPACE.equals(namespace)
+ || CDK_PASS_THROUGH_NAMESPACE.equals(namespace)||
COMPOSITE_NAMESPACE.equals(namespace);
+ }
+
public static boolean isDefaultNamespace(QName name) {
return isDefaultNamespace(name.getNamespaceURI());
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -21,12 +21,17 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+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.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.types.ELType;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+import org.richfaces.cdk.util.Strings;
import com.google.inject.Inject;
@@ -41,47 +46,46 @@
private final ELParser parser;
+ private final Logger log;
+
+ private final TypesFactory typesFactory;
+
private TypedTemplateStatement initializationStatement;
@Inject
- public DefineObjectStatement(@TemplateModel FreeMarkerRenderer renderer, ELParser
parser) {
+ public DefineObjectStatement(Logger log, @TemplateModel FreeMarkerRenderer renderer,
ELParser parser,
+ TypesFactory typesFactory) {
super(renderer, "define-object");
+ this.log = log;
this.parser = parser;
+ this.typesFactory = typesFactory;
}
/**
* <p class="changed_added_4_0">
* </p>
*
- * @param type
- * the type to set
- */
- public void setType(ELType type) {
- this.type = type;
- }
-
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @param name
- * the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
* @param initializationExpression
* the initializationExpression to set
* @throws ParsingException
*/
- public void setInitializationExpression(String initializationExpression) throws
ParsingException {
- initializationStatement = parser.parse(initializationExpression, this,
TypesFactory.OBJECT_TYPE);
- initializationStatement.setParent(this);
+ public void setObject(String name, String type, String initializationExpression) {
+ try {
+ this.name = name;
+ if (!Strings.isEmpty(initializationExpression)) {
+ initializationStatement = parser.parse(initializationExpression, this,
TypesFactory.OBJECT_TYPE);
+ initializationStatement.setParent(this);
+ this.type = initializationStatement.getType();
+ } else {
+ this.type = TypesFactory.OBJECT_TYPE;
+ }
+ if (!Strings.isEmpty(type)) {
+ this.type = typesFactory.getType(type);
+ addImports(this.type.getRequiredImports());
+ }
+ } catch (ParsingException e) {
+ log.error("Error parse initialization expression for variable " +
name, e);
+ }
}
/**
@@ -99,10 +103,18 @@
}
/**
- * @return the initializationExpression
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the initializationStatement
*/
- public TemplateStatement getInitializationExpression() {
- return initializationStatement;
+ public TypedTemplateStatement getInitializationStatement() {
+ return this.initializationStatement;
}
+ @Override
+ public List<TemplateStatement> getStatements() {
+ return null != initializationStatement ? Collections.<TemplateStatement>
singletonList(initializationStatement)
+ : Collections.<TemplateStatement> emptyList();
+ }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -21,6 +21,8 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import javax.xml.namespace.QName;
+
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
/**
@@ -29,7 +31,7 @@
*/
public class ElementStatement extends FreeMarkerTemplateStatementBase {
- private String elementName;
+ private QName elementName;
public ElementStatement(FreeMarkerRenderer renderer, String template) {
super(renderer, template);
@@ -38,7 +40,7 @@
/**
* @return the elementName
*/
- public String getElementName() {
+ public QName getElementName() {
return elementName;
}
@@ -49,7 +51,7 @@
* @param elementName
* the elementName to set
*/
- public void setElementName(String elementName) {
+ public void setElementName(QName elementName) {
this.elementName = elementName;
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -21,9 +21,16 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+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 com.google.common.collect.Iterables;
import com.google.inject.Inject;
/**
@@ -31,22 +38,28 @@
*/
public class ForEachStatement extends FreeMarkerTemplateStatementBase {
- private String itemsExpression;
+ private TypedTemplateStatement itemsStatement;
private String var;
- private String varType;
+ private ELType varType;
+ private final ELParser parser;
+
+ private final Logger log;
+
@Inject
- public ForEachStatement(@TemplateModel FreeMarkerRenderer renderer) {
+ public ForEachStatement(@TemplateModel FreeMarkerRenderer renderer,ELParser
parser,Logger log) {
super(renderer,"for-each");
+ this.parser = parser;
+ this.log = log;
}
/**
* @return the itemsExpression
*/
- public String getItemsExpression() {
- return itemsExpression;
+ public TypedTemplateStatement getItemsExpression() {
+ return itemsStatement;
}
/**
@@ -59,32 +72,39 @@
/**
* @return the varType
*/
- public String getVarType() {
+ public ELType getVarType() {
return varType;
}
/**
* <p class="changed_added_4_0"></p>
* @param itemsExpression the itemsExpression to set
+ * @param var
*/
- public void setItemsExpression(String itemsExpression) {
- this.itemsExpression = itemsExpression;
+ public void setItemsExpression(String itemsExpression, String var) {
+ try {
+ this.itemsStatement = parser.parse(itemsExpression, this,
Iterable.class.getName());
+ this.itemsStatement.setParent(this);
+ this.varType = this.itemsStatement.getType().getContainerType();
+ this.var=var;
+ setVariable(var, this.varType);
+ } catch (ParsingException e) {
+ log.error("Error parsing expression for iteration in <foreach>
statement",e);
+ }
}
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param var the var to set
- */
- public void setVar(String var) {
- this.var = var;
+ @Override
+ public Iterable<JavaImport> getRequiredImports() {
+ return
Iterables.concat(super.getRequiredImports(),itemsStatement.getRequiredImports());
}
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param varType the varType to set
- */
- public void setVarType(String varType) {
- this.varType = varType;
+
+ @Override
+ public Iterable<HelperMethod> getRequiredMethods() {
+ return
Iterables.concat(super.getRequiredMethods(),itemsStatement.getRequiredMethods());
}
+
+ @Override
+ public Iterable<JavaField> getRequiredFields() {
+ return
Iterables.concat(super.getRequiredFields(),itemsStatement.getRequiredFields());
+ }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -124,6 +124,11 @@
imports.add(new RuntimeImport(name));
}
+ protected void addImports(Iterable<JavaImport> requiredImports) {
+ Iterables.addAll(imports, requiredImports);
+ }
+
+
public void addRequiredMethod(String helperMethodName) {
HelperMethod helperMethod = HelperMethod.valueOf(helperMethodName);
requiredMethods.add(helperMethod);
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-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -24,12 +24,15 @@
import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.*;
import java.util.Collection;
+import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Set;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import com.google.common.collect.Maps;
+
/**
* @author Nick Belaevski
*
@@ -45,6 +48,8 @@
RENDER_ATTRIBUTES_SET("renderPassThroughAttributes",
Void.TYPE,FacesContext.class,UIComponent.class,Collection.class),
RENDER_ATTRIBUTE("renderAttribute",Void.TYPE,FacesContext.class,String.class,Object.class);
+ public static final EnumMap<HelperMethod, String> METHOD_NAMES =
Maps.newEnumMap(HelperMethod.class);
+
private static final Set<HelperMethod> CONVERSION_METHODS =
EnumSet.of(TO_STRING_CONVERSION, TO_BOOLEAN_CONVERSION);
private String name;
@@ -53,7 +58,13 @@
private Class<?>[] argumentTypes;
+ static {
+ for (HelperMethod method : HelperMethod.values()) {
+ METHOD_NAMES.put(method, method.getName());
+ }
+ }
+
private HelperMethod(String name, Class<?> returnType, Class<?>...
argumentTypes) {
this.name = name;
this.returnType = returnType;
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfStatement.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfStatement.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -21,13 +21,28 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.templatecompiler.ELParser;
+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;
+
+
public final class IfStatement extends StatementsContainer {
- private String test;
+ private TypedTemplateStatement testStatement;
+ private final ELParser parser;
+ private final Logger log;
- public IfStatement() {
+ @Inject
+ public IfStatement(ELParser parser,Logger log) {
super();
+ this.parser = parser;
+ this.log = log;
}
/**
@@ -35,10 +50,30 @@
* @param test the test to set
*/
public void setTest(String test) {
- this.test = test;
+ try {
+ testStatement = parser.parse(test, this, TypesFactory.BOOLEAN_TYPE);
+ testStatement.setParent(this);
+ } catch (ParsingException e) {
+ log.error("Error parsing if statement condition",e);
+ }
}
- public String getTest() {
- return test;
+ public TypedTemplateStatement getTest() {
+ return testStatement;
}
+
+ @Override
+ public Iterable<JavaImport> getRequiredImports() {
+ return
Iterables.concat(super.getRequiredImports(),testStatement.getRequiredImports());
+ }
+
+ @Override
+ public Iterable<HelperMethod> getRequiredMethods() {
+ return
Iterables.concat(super.getRequiredMethods(),testStatement.getRequiredMethods());
+ }
+
+ @Override
+ public Iterable<JavaField> getRequiredFields() {
+ return
Iterables.concat(super.getRequiredFields(),testStatement.getRequiredFields());
+ }
}
\ No newline at end of file
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-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -23,7 +23,6 @@
import java.util.Collections;
-import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import org.richfaces.cdk.Logger;
@@ -41,7 +40,7 @@
*/
public class WriteAttributeStatement extends FreeMarkerTemplateStatementBase {
- private String attributeName;
+ private QName attributeName;
private TypedTemplateStatement valueExpression;
@@ -87,14 +86,10 @@
}
private void setAttributeName(QName qName) {
- StringBuilder nameBuilder = new StringBuilder();
- if(!XMLConstants.DEFAULT_NS_PREFIX.equals(qName.getPrefix())){
- nameBuilder.append(qName.getPrefix()).append(':');
- }
- this.attributeName = nameBuilder.append(qName.getLocalPart()).toString();
+ this.attributeName = qName;
}
- public String getAttributeName() {
+ public QName getAttributeName() {
return attributeName;
}
@@ -107,6 +102,7 @@
* @return the defaultValue
*/
public String getDefaultValue() {
+ // TODO - convert to Java syntax according to type.
return this.defaultValue;
}
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-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -21,8 +21,8 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import java.util.Collection;
import java.util.Set;
-import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;
import javax.xml.namespace.QName;
@@ -39,14 +39,61 @@
*/
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 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";
@@ -70,7 +117,7 @@
private String fieldName;
- private TreeSet<PassThrough> attributes;
+ private Collection<PassThrough> attributes;
@Inject
public WriteAttributesSetStatement(@TemplateModel FreeMarkerRenderer renderer) {
@@ -93,7 +140,7 @@
this.fieldName = fieldName;
}
- public void setAttributes(TreeSet<PassThrough> passThroughAttributes) {
+ public void setAttributes(Collection<PassThrough> passThroughAttributes) {
this.attributes = passThroughAttributes;
}
@@ -101,7 +148,7 @@
* <p class="changed_added_4_0"></p>
* @return the attributes
*/
- public TreeSet<PassThrough> getAttributes() {
+ public Collection<PassThrough> getAttributes() {
return this.attributes;
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -49,7 +49,7 @@
this.log = log;
}
- public TemplateStatement getTextStatement() {
+ public TemplateStatement getValue() {
return textStatement;
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/schema/xhtml-el.xsd
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/schema/xhtml-el.xsd 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/schema/xhtml-el.xsd 2010-07-09
00:18:37 UTC (rev 17776)
@@ -1,30 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--
-JBoss, Home of Professional Open Source
-Copyright ${year}, Red Hat, Inc. and individual contributors
-by the @authors tag. See the copyright.txt in the distribution for a
-full listing of individual contributors.
+<!-- JBoss, Home of Professional Open Source Copyright ${year}, 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. -->
-
-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.
--->
-
<xs:schema version="1.0" xml:lang="en"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://richfaces.org/cdk/xhtml-el"
xmlns="http://richfaces.org/cdk/xhtml-el"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
@@ -472,7 +461,8 @@
<xs:attribute name="class" type="NMTOKENS">
<xs:annotation>
<xs:appinfo>
- <cdk-addinfo:component-attribute-name>styleClass</cdk-addinfo:component-attribute-name>
+ <cdk-addinfo:component-attribute-name>styleClass
+ </cdk-addinfo:component-attribute-name>
</xs:appinfo>
</xs:annotation>
</xs:attribute>
@@ -2194,7 +2184,7 @@
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
-
+
<xs:attributeGroup name="disabledGroup">
<xs:attribute name="disabled">
<xs:simpleType>
@@ -2211,7 +2201,7 @@
</xs:simpleType>
</xs:attribute>
</xs:attributeGroup>
-
+
<xs:attributeGroup name="readonlyGroup">
<xs:attribute name="readonly">
<xs:simpleType>
@@ -2973,7 +2963,13 @@
<xs:group ref="cdk:structural" minOccurs="0"
maxOccurs="unbounded" />
<xs:attributeGroup ref="attrs"></xs:attributeGroup>
<xs:attribute use="required" name="src"
type="URI"></xs:attribute>
- <xs:attribute use="required" name="alt"
type="Text"></xs:attribute>
+ <xs:attribute use="required" name="alt"
type="Text">
+ <xs:annotation>
+ <xs:appinfo>
+ <cdk-addinfo:default-value></cdk-addinfo:default-value>
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:attribute>
<xs:attribute name="name"
type="NMTOKEN"></xs:attribute>
<xs:attribute name="longdesc"
type="URI"></xs:attribute>
<xs:attribute name="height"
type="Length"></xs:attribute>
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/define-object.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/define-object.ftl 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/define-object.ftl 2010-07-09
00:18:37 UTC (rev 17776)
@@ -1 +1 @@
-${modelItem.type.code} ${modelItem.name} <#if
modelItem.initializationExpression.length() != 0> =
${modelItem.initializationExpression}</#if>;
\ No newline at end of file
+${type} ${name} <#if initializationStatement?exists> =
${initializationStatement}</#if>;
\ No newline at end of file
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/for-each.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/for-each.ftl 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/for-each.ftl 2010-07-09
00:18:37 UTC (rev 17776)
@@ -1,5 +1,5 @@
-for (${modelItem.varType} ${modelItem.var}: ${modelItem.itemsExpression}) {
- <#list modelItem.statements as subStatement>
+for (${varType} ${var}: ${itemsExpression}) {
+ <#list statements as subStatement>
${subStatement.code}
</#list>
}
\ No newline at end of file
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/if-else.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/if-else.ftl 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/if-else.ftl 2010-07-09
00:18:37 UTC (rev 17776)
@@ -2,7 +2,7 @@
<#if statement_index == 0>
if (${statement.test}) {
<#else>
- } else <#if statement.test.length() != 0>if (${statement.test}) </#if> {
+ } else <#if statement.test?exists>if (${statement.test}) </#if> {
</#if>
<#list statement.statements as subStatement>
${subStatement.code}
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-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl 2010-07-09
00:18:37 UTC (rev 17776)
@@ -3,7 +3,7 @@
<#else>
{
${value.type} value = ${value};
- if(null != value &&
+ if(<#if defaultValue?exists>null == value || !(<#else>null != value
&&</#if>
<#if value.type == "Integer" || value.type == "int" >
value != Integer.MIN_VALUE
<#elseif value.type == "Double" || value.type ==
"double">
@@ -21,10 +21,18 @@
<#elseif value.type == "String" >
value.length()>0
<#else>
- <@util.require
"SHOULD_RENDER_ATTRIBUTE"/>shouldRenderAttribute(value)
+ <@util.require
"SHOULD_RENDER_ATTRIBUTE"/>${SHOULD_RENDER_ATTRIBUTE}(value)
</#if>
+ <#if defaultValue?exists>
+ )) {
+ value="${defaultValue}";
+ }
+ ${responseWriterVariable}.writeAttribute(${attributeName},value,null);
+ <#else>
) {
${responseWriterVariable}.writeAttribute(${attributeName},value,null);
}
+ </#if>
+
}
</#if>
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-attributes-set.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-attributes-set.ftl 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-attributes-set.ftl 2010-07-09
00:18:37 UTC (rev 17776)
@@ -1,6 +1,7 @@
-<(a)util.constant "Attributes" "${fieldName}"><#list
attributes as attribute>
-
.{attribute.builderMethod}(${attribute.name},${attribute.componentAttribute}<#list
attribute.behaviors as behavior>,${behavior}</#list>)
+<(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"/>
-renderPassThroughAttributes(${facesContextVariable}, ${componentVariable},
+${RENDER_ATTRIBUTES_SET}(${facesContextVariable}, ${componentVariable},
${fieldName});
\ No newline at end of file
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-text.ftl
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-text.ftl 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/resources/META-INF/templates/java/write-text.ftl 2010-07-09
00:18:37 UTC (rev 17776)
@@ -1,6 +1,10 @@
+<#if value.literal>
+ ${responseWriterVariable}.writeText(${value},null);
+<#else>
{
- Object text = ${modelItem.textExpression};
+ Object text = ${value};
if (text != null) {
${responseWriterVariable}.writeText(text, null);
}
-}
\ No newline at end of file
+}
+</#if>
\ No newline at end of file
Modified:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -69,9 +69,10 @@
protected Logger log;
@Mock
- @Output(Outputs.RESOURCES)
+ @Output(Outputs.JAVA_CLASSES)
protected FileManager output;
+
@Inject
@As(LibraryModelWrapper.class)
protected ObjectWrapper wrapper;
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-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatementTest.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -32,7 +32,6 @@
import javax.xml.namespace.QName;
-import org.easymock.EasyMock;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestBase;
Added:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectTest.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectTest.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -0,0 +1,67 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+
+import javax.xml.namespace.QName;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.Mock;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.inject.Inject;
+
+(a)RunWith(CdkTestRunner.class)
+public class DefineObjectTest extends FreeMarkerTestBase {
+
+ @Mock
+ private TypesFactory typesFactory;
+
+ @Inject
+ private DefineObjectStatement statement;
+
+ @Test
+ public void testDefineVariable() throws Exception {
+
expect(typesFactory.getType("java.lang.String")).andReturn(TypesFactory.STRING_TYPE);
+ controller.replay();
+ statement.setObject("foo","java.lang.String",null);
+ String code = statement.getCode();
+ controller.verify();
+ verifyCode(code, "String"," foo","!=");
+ }
+
+ @Test
+ public void testDefineAndInitVariable() 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());
+
expect(typesFactory.getType("java.lang.String")).andReturn(TypesFactory.STRING_TYPE);
+ parsedExpression.setParent(statement);expectLastCall();
+ controller.replay();
+
statement.setObject("foo","java.lang.String",HTTP_EXAMPLE_COM);
+ String code = statement.getCode();
+ verifyCode(code, HTTP_EXAMPLE_COM,"String","=");
+ controller.verify();
+ }
+ @Test
+ public void testDefineAndInitUnknownVariable() 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.setObject("foo",null,HTTP_EXAMPLE_COM);
+ String code = statement.getCode();
+ verifyCode(code, "Integer","foo","=");
+ controller.verify();
+ }
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/ForEachTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/ForEachTest.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/ForEachTest.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -0,0 +1,43 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+
+import javax.xml.namespace.QName;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.Mock;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.inject.Inject;
+
+(a)RunWith(CdkTestRunner.class)
+public class ForEachTest extends FreeMarkerTestBase {
+
+ @Mock
+ private TypesFactory typesFactory;
+
+ @Inject
+ private ForEachStatement statement;
+
+
+ @Test
+ public void testSetItemsExpression() throws Exception {
+ expect(parser.parse(HTTP_EXAMPLE_COM, statement,
Iterable.class.getName())).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.setItemsExpression(HTTP_EXAMPLE_COM,"foo");
+ String code = statement.getCode();
+ verifyCode(code, HTTP_EXAMPLE_COM,"for");
+ controller.verify();
+ }
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/ForEachTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementTest1.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -5,14 +5,10 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestRunner;
-import org.richfaces.cdk.Logger;
-import org.richfaces.cdk.MockController;
-import org.richfaces.cdk.Stub;
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
import com.google.common.collect.Iterables;
-import com.google.inject.Inject;
@RunWith(CdkTestRunner.class)
@@ -20,14 +16,6 @@
private static final String FOO_CODE = "private static final String foo;";
- @Stub
- private Logger log;
-
- @Inject
- private MockController controller;
-
-
-
public FreeMarkerTemplateStatementBase setUpStatement(String template) {
FreeMarkerTemplateStatementBase freeMarkerStatement = new
FreeMarkerTemplateStatementBase(renderer, template);
return freeMarkerStatement;
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-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTestBase.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -31,13 +31,19 @@
import java.util.NoSuchElementException;
import org.richfaces.cdk.CdkTestBase;
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.Mock;
+import org.richfaces.cdk.MockController;
+import org.richfaces.cdk.Stub;
import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
+import org.richfaces.cdk.generate.freemarker.ContextVariables;
import org.richfaces.cdk.generate.freemarker.DefaultImports;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.generate.freemarker.TemplatesFolder;
+import org.richfaces.cdk.templatecompiler.ELParser;
import org.richfaces.cdk.templatecompiler.JavaClassModelWrapper;
-import org.richfaces.cdk.templatecompiler.RendererClassVisitor;
import org.richfaces.cdk.templatecompiler.TemplateModel;
+import org.richfaces.cdk.templatecompiler.TemplateModule;
import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
import com.google.common.base.Predicate;
@@ -58,9 +64,18 @@
*/
public class FreeMarkerTestBase extends CdkTestBase {
+ protected static final String HTTP_EXAMPLE_COM = "http://example.com/";
@Inject
@TemplateModel
protected FreeMarkerRenderer renderer;
+ @Stub
+ protected Logger log;
+ @Mock
+ protected ELParser parser;
+ @Mock
+ protected TypedTemplateStatement parsedExpression;
+ @Inject
+ protected MockController controller;
@Override
public void configure(Binder binder) {
@@ -71,7 +86,7 @@
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);
+
}).annotatedWith(ContextVariables.class).toInstance(TemplateModule.buildVariables());
}
protected void verifyImports(TemplateStatement statement, String... expected) {
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-08
15:35:39 UTC (rev 17775)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeTest.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -11,31 +11,13 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.richfaces.cdk.CdkTestRunner;
-import org.richfaces.cdk.Logger;
-import org.richfaces.cdk.Mock;
-import org.richfaces.cdk.MockController;
-import org.richfaces.cdk.Stub;
-import org.richfaces.cdk.templatecompiler.ELParser;
import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
import com.google.inject.Inject;
@RunWith(CdkTestRunner.class)
public class WriteAttributeTest extends FreeMarkerTestBase {
- private static final String HTTP_EXAMPLE_COM = "http://example.com/";
-
- @Stub
- private Logger log;
-
- @Mock
- private ELParser parser;
- @Mock
- private TypedTemplateStatement parsedExpression;
-
@Inject
- private MockController controller;
-
- @Inject
private WriteAttributeStatement statement;
@Test
@@ -63,7 +45,7 @@
controller.replay();
statement.setAttribute(QName.valueOf("href"), HTTP_EXAMPLE_COM,null);
String code = statement.getCode();
- verifyCode(code,
"!\""+HTTP_EXAMPLE_COM+"\"","writeAttribute","if(");
+ verifyCode(code,
"!\""+HTTP_EXAMPLE_COM+"\"","writeAttribute","if(",HelperMethod.SHOULD_RENDER_ATTRIBUTE.getName());
verifyHelpers(statement, HelperMethod.SHOULD_RENDER_ATTRIBUTE);
controller.verify();
}
Added:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetTest.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetTest.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -0,0 +1,73 @@
+/*
+ * $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 static org.junit.Assert.*;
+
+import java.util.Collections;
+
+import javax.xml.namespace.QName;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+(a)RunWith(CdkTestRunner.class)
+public class WriteAttributesSetTest extends FreeMarkerTestBase {
+
+ @Inject
+ private WriteAttributesSetStatement statement;
+
+ /**
+ * Test method for {@link
org.richfaces.cdk.templatecompiler.statements.FreeMarkerTemplateStatementBase#getCode()}.
+ */
+ @Test
+ public void testGetCode() {
+ WriteAttributesSetStatement.PassThrough passThrough = new
WriteAttributesSetStatement.PassThrough();
+ passThrough.name = QName.valueOf("foo");
+ passThrough.type = "String";
+ passThrough.componentAttribute = "bar";
+ passThrough.defaultValue = "deflt";
+ controller.replay();
+ statement.setAttributes(Collections.singleton(passThrough));
+ String code = statement.getCode();
+ controller.verify();
+ verifyCode(code, "!attributes()", "!defaultValue(",
"!if(", "");
+ verifyHelpers(statement, HelperMethod.CREATE_ATTRIBUTES,
HelperMethod.RENDER_ATTRIBUTES_SET);
+ JavaField javaField = Iterables.getOnlyElement(statement.getRequiredFields());
+ verifyCode(javaField.getValue().getCode(), "attributes()",
"generic(", "defaultValue(");
+ }
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WtiteTextTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WtiteTextTest.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WtiteTextTest.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -0,0 +1,52 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static org.easymock.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+
+import javax.xml.namespace.QName;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.richfaces.cdk.CdkTestRunner;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.inject.Inject;
+
+(a)RunWith(CdkTestRunner.class)
+public class WtiteTextTest extends FreeMarkerTestBase {
+
+ @Inject
+ private WriteTextStatement statement;
+
+ @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.isLiteral()).andStubReturn(true);
+ expect(parsedExpression.getType()).andStubReturn(TypesFactory.STRING_TYPE);
+ parsedExpression.setParent(statement);expectLastCall();
+ controller.replay();
+ statement.setExpression(HTTP_EXAMPLE_COM);
+ String code = statement.getCode();
+ controller.verify();
+ verifyCode(code,
"\""+HTTP_EXAMPLE_COM+"\"","writeText","!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.setExpression(HTTP_EXAMPLE_COM);
+ String code = statement.getCode();
+ verifyCode(code,
"!\""+HTTP_EXAMPLE_COM+"\"","writeText","if");
+ controller.verify();
+ }
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/statements/WtiteTextTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/commons/branches/RF8755/api/src/main/java/org/richfaces/renderkit/ComponentAttribute.java
===================================================================
---
root/commons/branches/RF8755/api/src/main/java/org/richfaces/renderkit/ComponentAttribute.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/commons/branches/RF8755/api/src/main/java/org/richfaces/renderkit/ComponentAttribute.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -31,7 +31,7 @@
public class ComponentAttribute implements Comparable<ComponentAttribute> {
public enum Kind {
- BOOLEAN,
+ BOOL,
GENERIC,
URI
}
@@ -40,6 +40,24 @@
private String componentAttributeName;
+ private Object dafaultValue;
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the dafaultValue
+ */
+ public Object getDafaultValue() {
+ return this.dafaultValue;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param dafaultValue the dafaultValue to set
+ */
+ public void setDafaultValue(Object dafaultValue) {
+ this.dafaultValue = dafaultValue;
+ }
+
private String[] eventNames = {};
private Kind kind = Kind.GENERIC;
Modified:
root/commons/branches/RF8755/api/src/main/java/org/richfaces/renderkit/RenderKitUtils.java
===================================================================
---
root/commons/branches/RF8755/api/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-07-08
15:35:39 UTC (rev 17775)
+++
root/commons/branches/RF8755/api/src/main/java/org/richfaces/renderkit/RenderKitUtils.java 2010-07-09
00:18:37 UTC (rev 17776)
@@ -406,6 +406,8 @@
@SuppressWarnings("serial")
public static final class Attributes extends TreeSet<ComponentAttribute> {
+
+ private ComponentAttribute last;
public void render(FacesContext context, UIComponent component) throws
IOException {
renderPassThroughAttributes(context, component, this);
@@ -421,6 +423,8 @@
private ComponentAttribute createAttribute(String name, String
componentAttribute) {
ComponentAttribute attribute = new ComponentAttribute(name);
attribute.setComponentAttributeName(componentAttribute);
+ add(attribute);
+ last = attribute;
return attribute;
}
@@ -432,9 +436,14 @@
public Attributes bool(String name, String componentAttribute) {
ComponentAttribute attribute = createAttribute(name, componentAttribute);
- attribute.setKind(Kind.BOOLEAN);
+ attribute.setKind(Kind.BOOL);
return this;
}
+
+ public Attributes defaultValue(Object value){
+ last.setDafaultValue(value);
+ return this;
+ }
}