1 package org.apache.maven.doxia.module.confluence.parser;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.doxia.parser.ParseException;
23 import org.apache.maven.doxia.util.ByLineSource;
24
25
26
27
28
29
30
31 public class FigureBlockParser
32 implements BlockParser
33 {
34
35 public boolean accept( String line, ByLineSource source )
36 {
37 return line.startsWith( "!" ) && line.lastIndexOf( "!" ) > 1;
38 }
39
40
41 public Block visit( String line, ByLineSource source )
42 throws ParseException
43 {
44 String image = line.substring( 1, line.lastIndexOf( "!" ) );
45 if ( image.indexOf( "|" ) >= 0 )
46 {
47
48 image = image.substring( 0, image.indexOf( "|" ) );
49 }
50
51 line = line.substring( line.lastIndexOf( "!" ) + 1 ).trim();
52
53 if ( line.startsWith( "\\\\" ) )
54 {
55
56 line = line.substring( 2 );
57 }
58
59 String caption = line + appendUntilEmptyLine( source );
60
61 if ( caption.trim().length() > 0 )
62 {
63 return new FigureBlock( image, caption );
64 }
65
66 return new FigureBlock( image );
67 }
68
69
70
71
72
73
74
75
76
77 private String appendUntilEmptyLine( ByLineSource source )
78 throws ParseException
79 {
80 StringBuffer text = new StringBuffer();
81
82 String line;
83
84 while ( ( line = source.getNextLine() ) != null )
85 {
86
87 if ( line.trim().length() == 0 )
88 {
89 break;
90 }
91
92 if ( text.length() == 0 )
93 {
94 text.append( line.trim() );
95 }
96 else
97 {
98 text.append( " " + line.trim() );
99 }
100
101 }
102
103 return text.toString();
104 }
105 }