|
From: Jae G. <ja...@gn...> - 2005-09-13 22:13:23
|
i could definately use the regex type functionality now.
would you be able to post the code for the RegExVistor (or even better,
could it be checked directly into the sandbox?)
--
-jae
-----Original Message-----
From: spr...@li...
[mailto:spr...@li...] On Behalf Of
ty...@me...
Sent: Tuesday, September 13, 2005 4:35 PM
To: spr...@li...
Subject: Re: [Springframework-developer] More Fun with Validation
Hi again Steven,
One other thing that we just worked on in our sandbox was a simple Regular
Expression Function for using the ValangVisitor interface. Now we can use
this to handle all kinds of difference scenarios
(phone/email/creditcard/ssn/etc). I have included an example of how we are
wiring it up, for anyone who is interested. I know know there was talk
about something similar the other day.
Let me know if you think this would be useful for Valang. Or if there would
be better way to implement this.
Thanks,
Tyler
<bean id="visitorValidator"
class="org.springmodules.validation.ValangValidatorFactoryBean">
<property name="valang">
<value><![CDATA[
{ phoneNumber : isPhoneNumber(?) == TRUE : 'Invalid
Phone Number. Must be in format (###)###-####' }
{ email : isEmail(?) == TRUE : 'Invalid
E-mail Address. Must be in format a@b.c' }
]]>
</value>
</property>
<!-- Here, we inject necessary properties to create the Function -->
<property name="visitor">
<bean class="org.springmodules.validation.RegExVisitor">
<property
name="regExPatternString"><value>\(\d{3}\)\d{3}-\d{4}</value></property>
<property
name="functionName"><value>isPhoneNumber</value></property>
<property name="visitor">
<bean
class="org.govgrnds.core.validation.valang.RegExVisitor">
<property name="regExPatternString">
<value>"(\w+)@(\w+\.)(\w+)(\.\w+)*</value>
</property>
<property name="functionName">
<value>isEmail</value>
</property>
</bean>
</property>
</bean>
</property>
</bean>
> Hi Steven,
> ValidatingSupport does support my needs quite well. I was moreso
> talking about the interceptors that are in the
> "org.springmodules.orm.support.validation" package. Also
> ValidatingSupport really be under the org.springmodules.orm package
> when it is not orm specfic. I guess I'm being a little picky :)
>
> I have attached my code, like I said its not perfect and took we about
> a whole 10 minutes to do. But it is working for us right now pretty
nicely.
>
> Also we are setting basic validation funcations for standard
> validations like phonenumber, email, etc. Are there standard
> validation functions like these for Valang already?
>
> /*
> * Copyright 2004-2005 the original author or authors.
> *
> * Licensed 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.springmodules.orm.support.validation;
>
> import org.aopalliance.intercept.MethodInterceptor;
> import org.aopalliance.intercept.MethodInvocation;
> import org.apache.commons.logging.Log; import
> org.apache.commons.logging.LogFactory;
> import org.springframework.beans.factory.InitializingBean;
> import org.springmodules.orm.support.validation.ValidatingSupport;
>
>
> /**
> * <p>
> * Interceptor Process different validations on method invocations,
> * uses springmodules
> * ValidatingSupport to validate any method from any bean and not
> just
> * ORM beans like in the HibernateIntercepter examples.
> * </p>
> *
> * <p>
> * Combination of springmodules and acegisecurity's
> * validationexamples. Took the pieces we needed and
> * glued them together
> * </p>
> *
> *
> *
> * @author Tyler Nelson
> * @see org.springmodules.orm.support.validation.ValidatingSupport
> *
> */
> public class ValidatingInterceptor extends ValidatingSupport
> implements MethodInterceptor, InitializingBean {
>
> protected final Log log = LogFactory.getLog(getClass());
>
> private Class[] argumentClasses;
>
> public void afterPropertiesSet() throws Exception {
>
> }
>
> /**
> * <p>This method binds and unbinds the validator maps
> * configured in the validators
> * property.
> *
> * @param methodInvocation the method invocation
> * @return the result of the method invocation
> */
> public Object invoke(MethodInvocation mi) throws Throwable {
>
> try {
> bindValidators();
>
> Object[] args = mi.getArguments();
>
> for (int i = 0; i < args.length; i++) {
> if (isValidatable(args[i])) {
> if (log.isDebugEnabled()) {
> log.debug("Validatingnterceptor calling "
> + "for: '" + args[i] + "'");
> }
> ValidatingSupport.validate(args[i],
> mi.getMethod().getName());
> }
> }
>
>
> return mi.proceed();
> }
> finally {
> unbindValidators();
> }
>
> }
>
> /**
> * @return Returns the argumentClasses.
> */
> public Class[] getArgumentClasses() {
> return argumentClasses;
> }
> /**
> * @param argumentClasses The argumentClasses to set.
> */
> public void setArgumentClasses(Class[] argumentClasses) {
> this.argumentClasses = argumentClasses;
> }
> /**
> * Determines if an attribute needs to be validated
> *
> * @param argument
> * @return
> */
> private boolean isValidatable(Object argument) {
> // if argumentClasses is null or empty advise all arguments
> if(argumentClasses == null || argumentClasses.length < 1){
> return true;
> }
>
> if (argument == null) {
> return false;
> }
>
> for (int i = 0; i < argumentClasses.length; i++) {
> if
> (argumentClasses[i].isAssignableFrom(argument.getClass()))
> {
> return true;
> }
> }
>
> return false;
> }
> }
>
>
>
>> Tyler,
>>
>> What kind of validation do you want to do? Obviously
>> ValidatingSupport can be reused in other scenario's than just
>> persistence. The event mechanism should be sufficiently powerful to
>> leverage it in other place. Could you please provide some code
>> example of the integration with Acegi?
>>
>> Thanks
>>
>> Steven Devijver
>> Senior consultant
>> @ Interface21
>> ste...@in...
>>
>>
>>
>> On 13 Sep 2005, at 17:16, ty...@me... wrote:
>>
>>> Hi,
>>> With all this talk about Validation made me want to speak up. I am
>>> currently using Valang validation which works great. However I
>>> wanted a way to trigger the validation on different layers of our
>>> application. I was thinking of injecting a map of Validator object
>>> into a method interceptor. Then I found ValidatingInterceptor and
>>> ValidatingSupport in SpringModules, which does this already. However
>>> it seems to be very ORM specific where it doesn't need to be.
>>>
>>> To make it more generic, I combined it with a ValidationInterceptor
>>> that Ben Alex had in the Acegi Domain project. Like the Acegi
>>> version I included a way to filter out objects on the interceptor
>>> level.
>>> However it
>>> seems a little redundant right now since ValidatingSupport figures
>>> out via the map keys. I see real value in adding something like this
>>> interceptor to Spring Modules. Does anyone have any interest in
>>> using it?
>>>
>>> Thanks,
>>> Tyler
>>>
>>>
>>>
>>> -------------------------------------------------------
>>> SF.Net email is Sponsored by the Better Software Conference & EXPO
>>> September 19-22, 2005 * San Francisco, CA * Development Lifecycle
>>> Practices Agile & Plan-Driven Development * Managing Projects &
>>> Teams * Testing & QA Security * Process Improvement & Measurement *
>>> http://www.sqe.com/ bsce5sf
>>> _______________________________________________
>>> Springframework-developer mailing list
>>> Spr...@li...
>>> https://lists.sourceforge.net/lists/listinfo/springframework-develop
>>> er
>>>
>>>
>>
>>
>>
>> -------------------------------------------------------
>> SF.Net email is Sponsored by the Better Software Conference & EXPO
>> September 19-22, 2005 * San Francisco, CA * Development Lifecycle
>> Practices Agile & Plan-Driven Development * Managing Projects & Teams
>> * Testing & QA Security * Process Improvement & Measurement *
>> http://www.sqe.com/bsce5sf
>> _______________________________________________
>> Springframework-developer mailing list
>> Spr...@li...
>> https://lists.sourceforge.net/lists/listinfo/springframework-develope
>> r
>>
>
>
>
> -------------------------------------------------------
> SF.Net email is Sponsored by the Better Software Conference & EXPO
> September 19-22, 2005 * San Francisco, CA * Development Lifecycle
> Practices Agile & Plan-Driven Development * Managing Projects & Teams
> * Testing & QA Security * Process Improvement & Measurement *
> http://www.sqe.com/bsce5sf
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|