1 package org.apache.maven.doxia.module.twiki.parser;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
30
31
32
33
34 public class HRuleBlockParser
35 implements BlockParser
36 {
37
38
39
40 private static final Pattern HRULE_PATTERN = Pattern.compile( "^(---)(-*)(.*)$" );
41
42
43 public final boolean accept( final String line )
44 {
45 final Matcher m = HRULE_PATTERN.matcher( line );
46 boolean ret = false;
47
48 if ( m.lookingAt() )
49 {
50 final int textGroup = 3;
51 String s = m.group( textGroup );
52 if ( s != null && !s.startsWith( "+" ) )
53 {
54 ret = true;
55 }
56 }
57
58 return ret;
59 }
60
61
62
63
64 public final Block visit( final String line, final ByLineSource source )
65 throws ParseException
66 {
67 Block ret = new HorizontalRuleBlock();
68 final Matcher matcher = HRULE_PATTERN.matcher( line );
69 if ( matcher.lookingAt() )
70 {
71 final int textGroup = 3;
72 source.unget( matcher.group( textGroup ) );
73 }
74 else
75 {
76 throw new ParseException( "i was expecting a hruler!" );
77 }
78
79 return ret;
80 }
81 }