You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2003/07/13 03:27:48 UTC

cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl RegExpValidationRule.java RegExpValidationRuleBuilder.java

vgritsenko    2003/07/12 18:27:48

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl
                        RegExpValidationRule.java
                        RegExpValidationRuleBuilder.java
  Log:
  Fix line endings
  
  Revision  Changes    Path
  1.2       +96 -96    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/RegExpValidationRule.java
  
  Index: RegExpValidationRule.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/RegExpValidationRule.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RegExpValidationRule.java	9 Jul 2003 12:17:21 -0000	1.1
  +++ RegExpValidationRule.java	13 Jul 2003 01:27:48 -0000	1.2
  @@ -1,96 +1,96 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
  -    used to  endorse or promote  products derived from  this software without
  -    prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation and was  originally created by
  - Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
  - Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.cocoon.woody.datatype.validationruleimpl;
  -
  -import org.apache.cocoon.woody.datatype.ValidationError;
  -import org.apache.cocoon.woody.datatype.validationruleimpl.AbstractValidationRule;
  -import org.apache.oro.text.regex.Pattern;
  -import org.apache.oro.text.regex.PatternMatcher;
  -import org.apache.oro.text.regex.Perl5Matcher;
  -import org.outerj.expression.ExpressionContext;
  -
  -
  -/**
  - * Checks that a String matches a regular expression.
  - *
  - * <p>The <a href="http://jakarta.apache.org/oro/">Jakarta ORO</a> library
  - * is used as regexp engine.
  - */
  -public class RegExpValidationRule extends AbstractValidationRule {
  -	/** Compiled regular expression. */
  -	private Pattern pattern;
  -    /** Original string representation of the regexp, used for informational purposes only. */
  -    private String regexp;
  -
  -    public ValidationError validate(Object value, ExpressionContext expressionContext) {
  -    	String string = (String)value;
  -    	
  -    	if(matchesRegExp(string))
  -	     	return null;   
  -	    else
  -	    	return hasFailMessage() ? getFailMessage() : new ValidationError("validation.string.regexp", new String[] {regexp});
  -    }
  -    
  -    private boolean matchesRegExp(String string) {
  -        PatternMatcher matcher = new Perl5Matcher();
  -        return matcher.matches(string, pattern);
  -    }
  -    
  -    void setPattern(String regexp, Pattern pattern) {
  -        this.regexp = regexp;
  -    	this.pattern = pattern;
  -    }
  -
  -    
  -    public boolean supportsType(Class clazz, boolean arrayType) {
  -        return clazz.isAssignableFrom(String.class) && !arrayType;
  -    }
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
  +    used to  endorse or promote  products derived from  this software without
  +    prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation and was  originally created by
  + Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
  + Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.cocoon.woody.datatype.validationruleimpl;
  +
  +import org.apache.cocoon.woody.datatype.ValidationError;
  +import org.apache.cocoon.woody.datatype.validationruleimpl.AbstractValidationRule;
  +import org.apache.oro.text.regex.Pattern;
  +import org.apache.oro.text.regex.PatternMatcher;
  +import org.apache.oro.text.regex.Perl5Matcher;
  +import org.outerj.expression.ExpressionContext;
  +
  +
  +/**
  + * Checks that a String matches a regular expression.
  + *
  + * <p>The <a href="http://jakarta.apache.org/oro/">Jakarta ORO</a> library
  + * is used as regexp engine.
  + */
  +public class RegExpValidationRule extends AbstractValidationRule {
  +	/** Compiled regular expression. */
  +	private Pattern pattern;
  +    /** Original string representation of the regexp, used for informational purposes only. */
  +    private String regexp;
  +
  +    public ValidationError validate(Object value, ExpressionContext expressionContext) {
  +    	String string = (String)value;
  +    	
  +    	if(matchesRegExp(string))
  +	     	return null;   
  +	    else
  +	    	return hasFailMessage() ? getFailMessage() : new ValidationError("validation.string.regexp", new String[] {regexp});
  +    }
  +    
  +    private boolean matchesRegExp(String string) {
  +        PatternMatcher matcher = new Perl5Matcher();
  +        return matcher.matches(string, pattern);
  +    }
  +    
  +    void setPattern(String regexp, Pattern pattern) {
  +        this.regexp = regexp;
  +    	this.pattern = pattern;
  +    }
  +
  +    
  +    public boolean supportsType(Class clazz, boolean arrayType) {
  +        return clazz.isAssignableFrom(String.class) && !arrayType;
  +    }
  +}
  
  
  
  1.2       +86 -86    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/RegExpValidationRuleBuilder.java
  
  Index: RegExpValidationRuleBuilder.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/RegExpValidationRuleBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RegExpValidationRuleBuilder.java	9 Jul 2003 12:17:21 -0000	1.1
  +++ RegExpValidationRuleBuilder.java	13 Jul 2003 01:27:48 -0000	1.2
  @@ -1,86 +1,86 @@
  -/*
  -
  - ============================================================================
  -                   The Apache Software License, Version 1.1
  - ============================================================================
  -
  - Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without modifica-
  - tion, are permitted provided that the following conditions are met:
  -
  - 1. Redistributions of  source code must  retain the above copyright  notice,
  -    this list of conditions and the following disclaimer.
  -
  - 2. Redistributions in binary form must reproduce the above copyright notice,
  -    this list of conditions and the following disclaimer in the documentation
  -    and/or other materials provided with the distribution.
  -
  - 3. The end-user documentation included with the redistribution, if any, must
  -    include  the following  acknowledgment:  "This product includes  software
  -    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  -    Alternately, this  acknowledgment may  appear in the software itself,  if
  -    and wherever such third-party acknowledgments normally appear.
  -
  - 4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
  -    used to  endorse or promote  products derived from  this software without
  -    prior written permission. For written permission, please contact
  -    apache@apache.org.
  -
  - 5. Products  derived from this software may not  be called "Apache", nor may
  -    "Apache" appear  in their name,  without prior written permission  of the
  -    Apache Software Foundation.
  -
  - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  - FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  - APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  - INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  - DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  - ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  - (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -
  - This software  consists of voluntary contributions made  by many individuals
  - on  behalf of the Apache Software  Foundation and was  originally created by
  - Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
  - Software Foundation, please see <http://www.apache.org/>.
  -
  -*/
  -package org.apache.cocoon.woody.datatype.validationruleimpl;
  -
  -import org.apache.cocoon.woody.datatype.ValidationRule;
  -import org.apache.cocoon.woody.datatype.validationruleimpl.AbstractValidationRuleBuilder;
  -import org.apache.cocoon.woody.util.DomHelper;
  -import org.apache.oro.text.regex.Perl5Compiler;
  -import org.apache.oro.text.regex.Pattern;
  -import org.apache.oro.text.regex.MalformedPatternException;
  -import org.w3c.dom.Element;
  -
  -/**
  - * Builds {@link RegExpValidationRule}s.
  - */
  -public class RegExpValidationRuleBuilder extends AbstractValidationRuleBuilder {
  -
  -    public ValidationRule build(Element validationRuleElement) throws Exception {
  -        RegExpValidationRule rule = new RegExpValidationRule();
  -
  -        String regexp = DomHelper.getAttribute(validationRuleElement, "pattern");
  -        buildFailMessage(validationRuleElement, rule);
  -
  -        Perl5Compiler compiler = new Perl5Compiler();
  -        Pattern pattern = null;
  -        try {
  -            pattern = compiler.compile(regexp, Perl5Compiler.READ_ONLY_MASK);
  -        } catch (MalformedPatternException e) {
  -            throw new Exception("Invalid regular expression at " + DomHelper.getLocation(validationRuleElement) + ": " + e.getMessage());
  -        }
  -        rule.setPattern(regexp, pattern);
  -
  -        buildFailMessage(validationRuleElement, rule);
  -
  -        return rule;
  -    }
  -
  -}
  +/*
  +
  + ============================================================================
  +                   The Apache Software License, Version 1.1
  + ============================================================================
  +
  + Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  +
  + Redistribution and use in source and binary forms, with or without modifica-
  + tion, are permitted provided that the following conditions are met:
  +
  + 1. Redistributions of  source code must  retain the above copyright  notice,
  +    this list of conditions and the following disclaimer.
  +
  + 2. Redistributions in binary form must reproduce the above copyright notice,
  +    this list of conditions and the following disclaimer in the documentation
  +    and/or other materials provided with the distribution.
  +
  + 3. The end-user documentation included with the redistribution, if any, must
  +    include  the following  acknowledgment:  "This product includes  software
  +    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  +    Alternately, this  acknowledgment may  appear in the software itself,  if
  +    and wherever such third-party acknowledgments normally appear.
  +
  + 4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
  +    used to  endorse or promote  products derived from  this software without
  +    prior written permission. For written permission, please contact
  +    apache@apache.org.
  +
  + 5. Products  derived from this software may not  be called "Apache", nor may
  +    "Apache" appear  in their name,  without prior written permission  of the
  +    Apache Software Foundation.
  +
  + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  +
  + This software  consists of voluntary contributions made  by many individuals
  + on  behalf of the Apache Software  Foundation and was  originally created by
  + Stefano Mazzocchi  <st...@apache.org>. For more  information on the Apache
  + Software Foundation, please see <http://www.apache.org/>.
  +
  +*/
  +package org.apache.cocoon.woody.datatype.validationruleimpl;
  +
  +import org.apache.cocoon.woody.datatype.ValidationRule;
  +import org.apache.cocoon.woody.datatype.validationruleimpl.AbstractValidationRuleBuilder;
  +import org.apache.cocoon.woody.util.DomHelper;
  +import org.apache.oro.text.regex.Perl5Compiler;
  +import org.apache.oro.text.regex.Pattern;
  +import org.apache.oro.text.regex.MalformedPatternException;
  +import org.w3c.dom.Element;
  +
  +/**
  + * Builds {@link RegExpValidationRule}s.
  + */
  +public class RegExpValidationRuleBuilder extends AbstractValidationRuleBuilder {
  +
  +    public ValidationRule build(Element validationRuleElement) throws Exception {
  +        RegExpValidationRule rule = new RegExpValidationRule();
  +
  +        String regexp = DomHelper.getAttribute(validationRuleElement, "pattern");
  +        buildFailMessage(validationRuleElement, rule);
  +
  +        Perl5Compiler compiler = new Perl5Compiler();
  +        Pattern pattern = null;
  +        try {
  +            pattern = compiler.compile(regexp, Perl5Compiler.READ_ONLY_MASK);
  +        } catch (MalformedPatternException e) {
  +            throw new Exception("Invalid regular expression at " + DomHelper.getLocation(validationRuleElement) + ": " + e.getMessage());
  +        }
  +        rule.setPattern(regexp, pattern);
  +
  +        buildFailMessage(validationRuleElement, rule);
  +
  +        return rule;
  +    }
  +
  +}