Coverage Report - org.apache.maven.doxia.module.twiki.parser.HRuleBlockParser
 
Classes in this File Line Coverage Branch Coverage Complexity
HRuleBlockParser
94%
17/18
75%
6/8
3,5
 
 1  
 package org.apache.maven.doxia.module.twiki.parser;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.util.regex.Matcher;
 23  
 import java.util.regex.Pattern;
 24  
 
 25  
 import org.apache.maven.doxia.util.ByLineSource;
 26  
 import org.apache.maven.doxia.parser.ParseException;
 27  
 
 28  
 /**
 29  
  * Block that represents an horizontal rule
 30  
  *
 31  
  * @author Juan F. Codagnone
 32  
  * @version $Id: HRuleBlockParser.java 746991 2009-02-23 12:35:46Z vsiveton $
 33  
  */
 34  95
 public class HRuleBlockParser
 35  
     implements BlockParser
 36  
 {
 37  
     /**
 38  
      * pattern used to detect horizontal rulers
 39  
      */
 40  1
     private static final Pattern HRULE_PATTERN = Pattern.compile( "^(---)(-*)(.*)$" );
 41  
 
 42  
     /** {@inheritDoc} */
 43  
     public final boolean accept( final String line )
 44  
     {
 45  44
         final Matcher m = HRULE_PATTERN.matcher( line );
 46  44
         boolean ret = false;
 47  
 
 48  44
         if ( m.lookingAt() )
 49  
         {
 50  6
             final int textGroup = 3;
 51  6
             String s = m.group( textGroup );
 52  6
             if ( s != null && !s.startsWith( "+" ) )
 53  
             {
 54  5
                 ret = true;
 55  
             }
 56  
         }
 57  
 
 58  44
         return ret;
 59  
     }
 60  
 
 61  
     /**
 62  
      * {@inheritDoc}
 63  
      */
 64  
     public final Block visit( final String line, final ByLineSource source )
 65  
         throws ParseException
 66  
     {
 67  4
         Block ret = new HorizontalRuleBlock();
 68  4
         final Matcher matcher = HRULE_PATTERN.matcher( line );
 69  4
         if ( matcher.lookingAt() )
 70  
         {
 71  4
             final int textGroup = 3;
 72  4
             source.unget( matcher.group( textGroup ) );
 73  4
         }
 74  
         else
 75  
         {
 76  0
             throw new ParseException( "i was expecting a hruler!" );
 77  
         }
 78  
 
 79  4
         return ret;
 80  
     }
 81  
 }