1 package org.apache.maven.plugins.ear;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.util.WriterFactory;
23 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
24 import org.codehaus.plexus.util.xml.XMLWriter;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.Writer;
29
30
31
32
33
34
35 abstract class AbstractXmlWriter
36 {
37
38 private final String encoding;
39
40 protected static final String MODULE_ELEMENT = "module";
41
42 protected static final String SERVICE_ELEMENT = "service";
43
44 AbstractXmlWriter( String encoding )
45 {
46 this.encoding = encoding;
47 }
48
49 protected Writer initializeWriter( final File destinationFile )
50 throws EarPluginException
51 {
52 try
53 {
54 return WriterFactory.newXmlWriter( destinationFile );
55 }
56 catch ( IOException ex )
57 {
58
59 throw new EarPluginException( "Exception while opening file[" + destinationFile.getAbsolutePath() + "]", ex );
60
61 }
62 }
63
64 protected XMLWriter initializeXmlWriter( final Writer writer, final String docType )
65 {
66 return new PrettyPrintXMLWriter( writer, encoding, docType );
67 }
68
69 protected void close( Writer closeable )
70 {
71 if ( closeable == null )
72 {
73 return;
74 }
75
76 try
77 {
78 closeable.close();
79 }
80 catch ( Exception e )
81 {
82
83 }
84 }
85
86 public String getEncoding()
87 {
88 return encoding;
89 }
90 }