Coverage report

  %line %branch
org.apache.commons.jelly.tags.regexp.RegexpTag
0% 
0% 

 1  
 /*
 2  
  * Copyright 2002,2004 The Apache Software Foundation.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.commons.jelly.tags.regexp;
 17  
 
 18  
 import org.apache.commons.jelly.TagSupport;
 19  
 import org.apache.commons.jelly.XMLOutput;
 20  
 import org.apache.commons.jelly.MissingAttributeException;
 21  
 import org.apache.commons.jelly.JellyTagException;
 22  
 import org.apache.oro.text.regex.Perl5Matcher;
 23  
 import org.apache.oro.text.regex.Perl5Compiler;
 24  
 import org.apache.oro.text.regex.Pattern;
 25  
 import org.apache.oro.text.regex.MalformedPatternException;
 26  
 
 27  
 /**
 28  
  * Base class for tags using the Oro Regexp library.
 29  
  *
 30  
  * @author <a href="mailto:christian@inx-soft.com">Christian Amor Kvalheim</a>
 31  
  * @version $Revision: 1.1 $
 32  
  */
 33  0
 public abstract class RegexpTag extends TagSupport {
 34  0
     private Perl5Matcher patternMatcher = new Perl5Matcher();
 35  
     private Pattern pattern;
 36  
     private String var;
 37  
     private String text;
 38  
     private String scope;
 39  
 
 40  
     protected final String getText() {
 41  0
         return text;
 42  
     }
 43  
 
 44  
     protected final Pattern getPattern() {
 45  0
         return pattern;
 46  
     }
 47  
 
 48  
     protected final Perl5Matcher getPatternMatcher() {
 49  0
         return patternMatcher;
 50  
     }
 51  
 
 52  
     public final void setExpr(String expr) throws MalformedPatternException {
 53  0
         Perl5Compiler patternCompiler = new Perl5Compiler();
 54  0
         pattern = patternCompiler.compile(expr);
 55  0
     }
 56  
 
 57  
     public final void setText(String text) {
 58  0
         this.text = text;
 59  0
     }
 60  
 
 61  
     // Sets the variable name to define for this expression
 62  
     public final void setVar(String var) {
 63  0
         this.var = class="keyword">var;
 64  0
     }
 65  
 
 66  
     /**
 67  
      * Sets the variable scope for this variable. For example setting this value to 'parent' will
 68  
      * set this value in the parent scope. When Jelly is run from inside a Servlet environment
 69  
      * then other scopes will be available such as 'request', 'session' or 'application'.
 70  
      *
 71  
      * Other applications may implement their own custom scopes.
 72  
      */
 73  
     public final void setScope(String scope) {
 74  0
         this.scope = scope;
 75  0
     }
 76  
 
 77  
     public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
 78  
         // Check required properties
 79  0
         if (getText() == null || getText().length() == 0)
 80  0
             throw new MissingAttributeException("text must be provided");
 81  
 
 82  0
         if (pattern == null)
 83  0
             throw new MissingAttributeException("expr must be provided");
 84  
 
 85  0
         if (var == null || class="keyword">var.length() == 0)
 86  0
             throw new MissingAttributeException("var must be provided");
 87  
 
 88  
         // Evaluate pattern against text string
 89  0
         boolean result = getResult();
 90  0
         String resultString = result ? "true" : "false";
 91  
 
 92  0
         if (var != null) {
 93  0
             if (scope != null) {
 94  0
                 context.setVariable(var, scope, resultString);
 95  
             } else {
 96  0
                 context.setVariable(var, resultString);
 97  
             }
 98  
         }
 99  0
     }
 100  
 
 101  
     protected abstract boolean getResult();
 102  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.