1 package org.apache.maven.doxia.parser;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.io.StringReader;
26
27 import java.util.Properties;
28
29 import org.apache.maven.doxia.logging.Log;
30 import org.apache.maven.doxia.logging.SystemStreamLog;
31 import org.apache.maven.doxia.macro.Macro;
32 import org.apache.maven.doxia.macro.MacroExecutionException;
33 import org.apache.maven.doxia.macro.MacroRequest;
34 import org.apache.maven.doxia.macro.manager.MacroManager;
35 import org.apache.maven.doxia.macro.manager.MacroNotFoundException;
36 import org.apache.maven.doxia.sink.Sink;
37 import org.codehaus.plexus.component.annotations.Component;
38 import org.codehaus.plexus.component.annotations.Requirement;
39
40
41
42
43
44
45
46
47
48 @Component( role = Parser.class )
49 public abstract class AbstractParser
50 implements Parser
51 {
52
53 private boolean secondParsing = false;
54
55 @Requirement
56 private MacroManager macroManager;
57
58
59 private Log logger;
60
61 private static final String DOXIA_VERSION;
62
63 static
64 {
65 final Properties props = new Properties();
66 final InputStream is = AbstractParser.class.getResourceAsStream( "/build-info.properties" );
67
68 if ( is == null )
69 {
70 props.setProperty( "version", "unknown" );
71 }
72 else
73 {
74 try
75 {
76 props.load( is );
77 }
78 catch ( IOException ex )
79 {
80 props.setProperty( "version", "unknown" );
81 }
82 finally
83 {
84 try
85 {
86 is.close();
87 }
88 catch ( IOException ex )
89 {
90
91 }
92 }
93 }
94
95 DOXIA_VERSION = props.getProperty( "version" );
96 }
97
98
99 public int getType()
100 {
101 return UNKNOWN_TYPE;
102 }
103
104
105
106
107
108
109
110
111
112
113
114
115 public void executeMacro( String macroId, MacroRequest request, Sink sink )
116 throws MacroExecutionException, MacroNotFoundException
117 {
118 Macro macro = getMacroManager().getMacro( macroId );
119
120 macro.enableLogging( getLog() );
121
122 macro.execute( sink, request );
123 }
124
125
126
127
128
129
130
131
132 protected File getBasedir()
133 {
134
135
136
137 String basedir = System.getProperty( "basedir" );
138
139 if ( basedir != null )
140 {
141 return new File( basedir );
142 }
143
144 return new File( new File( "" ).getAbsolutePath() );
145 }
146
147
148
149
150
151
152
153
154
155 public void parse( String string, Sink sink )
156 throws ParseException
157 {
158 parse( new StringReader( string ), sink );
159 }
160
161
162
163
164
165
166 public void setSecondParsing( boolean second )
167 {
168 this.secondParsing = second;
169 }
170
171
172
173
174
175
176
177 protected boolean isSecondParsing()
178 {
179 return secondParsing;
180 }
181
182
183 public void enableLogging( Log log )
184 {
185 this.logger = log;
186 }
187
188
189
190
191
192
193
194
195 protected Log getLog()
196 {
197 if ( logger == null )
198 {
199 logger = new SystemStreamLog();
200 }
201
202 return logger;
203 }
204
205
206
207
208
209
210
211 protected MacroManager getMacroManager()
212 {
213 return macroManager;
214 }
215
216
217
218
219
220
221
222
223 protected void init()
224 {
225
226 }
227
228
229
230
231
232
233
234
235 protected static String doxiaVersion()
236 {
237 return DOXIA_VERSION;
238 }
239 }