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 public class HRuleBlockParser
34 implements BlockParser
35 {
36
37
38
39 private static final Pattern HRULE_PATTERN = Pattern.compile( "^(---)(-*)(.*)$" );
40
41
42 public final boolean accept( final String line )
43 {
44 final Matcher m = HRULE_PATTERN.matcher( line );
45 boolean ret = false;
46
47 if ( m.lookingAt() )
48 {
49 final int textGroup = 3;
50 String s = m.group( textGroup );
51 if ( s != null && !s.startsWith( "+" ) )
52 {
53 ret = true;
54 }
55 }
56
57 return ret;
58 }
59
60
61 public final Block visit( final String line, final ByLineSource source )
62 throws ParseException
63 {
64 Block ret = new HorizontalRuleBlock();
65 final Matcher matcher = HRULE_PATTERN.matcher( line );
66 if ( matcher.lookingAt() )
67 {
68 final int textGroup = 3;
69 source.unget( matcher.group( textGroup ) );
70 }
71 else
72 {
73 throw new ParseException( "i was expecting a hruler!" );
74 }
75
76 return ret;
77 }
78 }