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