You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/11/13 22:37:18 UTC
svn commit: r1034886 - in
/myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator:
AbstractDateRestrictionValidator.java
ValidateDateRestrictionTagHandler.java _DateRestrictionRule.java
Author: lu4242
Date: Sat Nov 13 21:37:18 2010
New Revision: 1034886
URL: http://svn.apache.org/viewvc?rev=1034886&view=rev
Log:
MFCOMMONS-25 Add Facelets Support to myfaces commons
Added:
myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/ValidateDateRestrictionTagHandler.java
myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/_DateRestrictionRule.java
Modified:
myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/AbstractDateRestrictionValidator.java
Modified: myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/AbstractDateRestrictionValidator.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/AbstractDateRestrictionValidator.java?rev=1034886&r1=1034885&r2=1034886&view=diff
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/AbstractDateRestrictionValidator.java (original)
+++ myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/AbstractDateRestrictionValidator.java Sat Nov 13 21:37:18 2010
@@ -49,6 +49,7 @@ import org.apache.myfaces.commons.valida
clazz = "org.apache.myfaces.commons.validator.DateRestrictionValidator",
bodyContent = "empty",
tagClass = "org.apache.myfaces.commons.validator.ValidateDateRestrictionTag",
+ tagHandler = "org.apache.myfaces.commons.validator.ValidateDateRestrictionTagHandler",
serialuidtag = "6805174635196400967L")
public abstract class AbstractDateRestrictionValidator extends ValidatorBase
{
Added: myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/ValidateDateRestrictionTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/ValidateDateRestrictionTagHandler.java?rev=1034886&view=auto
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/ValidateDateRestrictionTagHandler.java (added)
+++ myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/ValidateDateRestrictionTagHandler.java Sat Nov 13 21:37:18 2010
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.validator;
+
+import com.sun.facelets.tag.MetaRuleset;
+import com.sun.facelets.tag.jsf.ValidatorConfig;
+
+public class ValidateDateRestrictionTagHandler extends ValidatorBaseTagHandler
+{
+
+ public ValidateDateRestrictionTagHandler(ValidatorConfig config)
+ {
+ super(config);
+ }
+
+ @Override
+ protected MetaRuleset createMetaRuleset(Class type)
+ {
+ MetaRuleset ruleSet = super.createMetaRuleset(type);
+
+ ruleSet.addRule(_DateRestrictionRule.Instance);
+ return ruleSet;
+ }
+}
Added: myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/_DateRestrictionRule.java
URL: http://svn.apache.org/viewvc/myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/_DateRestrictionRule.java?rev=1034886&view=auto
==============================================================================
--- myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/_DateRestrictionRule.java (added)
+++ myfaces/commons/trunk/myfaces-commons-validators/src/main/java/org/apache/myfaces/commons/validator/_DateRestrictionRule.java Sat Nov 13 21:37:18 2010
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.commons.validator;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.text.ParseException;
+
+import com.sun.facelets.FaceletContext;
+import com.sun.facelets.tag.MetaRule;
+import com.sun.facelets.tag.Metadata;
+import com.sun.facelets.tag.MetadataTarget;
+import com.sun.facelets.tag.TagAttribute;
+import com.sun.facelets.tag.TagAttributeException;
+
+public class _DateRestrictionRule extends MetaRule
+{
+ final static class DateRestrictionMetadata extends Metadata {
+
+ private final String name;
+
+ private final TagAttribute attr;
+
+ private final Method method;
+
+ private final Class type;
+
+ private Object[] value;
+
+ public DateRestrictionMetadata(String name, Method method, Class type,
+ TagAttribute attr) {
+ this.name = name;
+ this.attr = attr;
+ this.method = method;
+ this.type = type;
+ }
+
+ @Override
+ public void applyMetadata(FaceletContext ctx, Object instance)
+ {
+ if (this.attr.isLiteral())
+ {
+ try
+ {
+ if (value == null) {
+ value = new Object[] {
+ org.apache.myfaces.commons.util.TagUtils.getStringArray(
+ ctx.getExpressionFactory().coerceToType(
+ this.attr.getValue(),
+ String.class)
+ ) };
+ }
+ try {
+ method.invoke(instance, this.value);
+ } catch (InvocationTargetException e) {
+ throw new TagAttributeException(this.attr, e.getCause());
+ } catch (Exception e) {
+ throw new TagAttributeException(this.attr, e);
+ }
+ }
+ catch(ParseException e)
+ {
+ throw new TagAttributeException(this.attr, e);
+ }
+ }
+ else
+ {
+ ((ValidatorBase) instance).setValueExpression(this.name, this.attr
+ .getValueExpression(ctx, this.type));
+ }
+ }
+
+ }
+
+ public final static _DateRestrictionRule Instance = new _DateRestrictionRule();
+
+ public _DateRestrictionRule()
+ {
+ super();
+ }
+
+ @Override
+ public Metadata applyRule(String name, TagAttribute attribute,
+ MetadataTarget meta)
+ {
+ if (meta.isTargetInstanceOf(DateRestrictionValidator.class)) {
+
+ if ("invalidMonths".equals(name) || "invalidDaysOfWeek".equals(name) || "invalidDays".equals(name))
+ {
+ Method m = meta.getWriteMethod(name);
+ Class type = meta.getPropertyType(name);
+ if (type == null) {
+ type = Object.class;
+ }
+ return new DateRestrictionMetadata(name, m, type, attribute);
+ }
+ }
+ return null;
+ }
+
+}
+