1 | |
package org.apache.maven.plugin.ear; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.Writer; |
23 | |
|
24 | |
import org.apache.maven.plugin.ear.util.JavaEEVersion; |
25 | |
import org.codehaus.plexus.util.xml.XMLWriter; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
final class ApplicationXmlWriter |
35 | |
extends AbstractXmlWriter |
36 | |
{ |
37 | |
public static final String DOCTYPE_1_3 = |
38 | |
"application PUBLIC\n" + "\t\"-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN\"\n" |
39 | |
+ "\t\"http://java.sun.com/dtd/application_1_3.dtd\""; |
40 | |
|
41 | |
private static final String APPLICATION_ELEMENT = "application"; |
42 | |
|
43 | |
|
44 | |
private final JavaEEVersion version; |
45 | |
|
46 | |
private final Boolean generateModuleId; |
47 | |
|
48 | |
ApplicationXmlWriter( JavaEEVersion version, String encoding, Boolean generateModuleId ) |
49 | |
{ |
50 | 0 | super( encoding ); |
51 | 0 | this.version = version; |
52 | 0 | this.generateModuleId = generateModuleId; |
53 | 0 | } |
54 | |
|
55 | |
public void write( ApplicationXmlWriterContext context ) |
56 | |
throws EarPluginException |
57 | |
{ |
58 | 0 | Writer w = initializeWriter( context.getDestinationFile() ); |
59 | |
|
60 | 0 | XMLWriter writer = null; |
61 | 0 | if ( JavaEEVersion.OneDotThree.eq( version ) ) |
62 | |
{ |
63 | 0 | writer = initializeRootElementOneDotThree( w ); |
64 | |
} |
65 | 0 | else if ( JavaEEVersion.OneDotFour.eq( version ) ) |
66 | |
{ |
67 | 0 | writer = initializeRootElementOneDotFour( w ); |
68 | |
} |
69 | 0 | else if ( JavaEEVersion.Five.eq( version ) ) |
70 | |
{ |
71 | 0 | writer = initializeRootElementFive( w ); |
72 | |
} |
73 | 0 | else if ( JavaEEVersion.Six.eq( version ) ) |
74 | |
{ |
75 | 0 | writer = initializeRootElementSix( w ); |
76 | |
} |
77 | |
|
78 | |
|
79 | 0 | if ( version.ge( JavaEEVersion.Six ) ) |
80 | |
{ |
81 | 0 | writeApplicationName( context.getApplicationName(), writer ); |
82 | |
} |
83 | |
|
84 | |
|
85 | |
|
86 | 0 | if ( version.eq( JavaEEVersion.OneDotThree ) ) |
87 | |
{ |
88 | 0 | writeDisplayName( context.getDisplayName(), writer ); |
89 | 0 | writeDescription( context.getDescription(), writer ); |
90 | |
} |
91 | |
else |
92 | |
{ |
93 | 0 | writeDescription( context.getDescription(), writer ); |
94 | 0 | writeDisplayName( context.getDisplayName(), writer ); |
95 | |
} |
96 | |
|
97 | |
|
98 | 0 | if ( version.ge( JavaEEVersion.Six ) ) |
99 | |
{ |
100 | 0 | writeInitializeInOrder( context.getInitializeInOrder(), writer ); |
101 | |
} |
102 | |
|
103 | |
|
104 | 0 | for ( EarModule module : context.getEarModules() ) |
105 | |
{ |
106 | 0 | module.appendModule( writer, version.getVersion(), generateModuleId ); |
107 | |
} |
108 | |
|
109 | 0 | for ( SecurityRole securityRole : context.getSecurityRoles() ) |
110 | |
{ |
111 | 0 | securityRole.appendSecurityRole( writer ); |
112 | |
} |
113 | |
|
114 | 0 | if ( version.ge( JavaEEVersion.Six ) ) |
115 | |
{ |
116 | 0 | for ( EnvEntry envEntry : context.getEnvEntries() ) |
117 | |
{ |
118 | 0 | envEntry.appendEnvEntry( writer ); |
119 | |
} |
120 | |
} |
121 | |
|
122 | 0 | if ( version.ge( JavaEEVersion.Five ) ) |
123 | |
{ |
124 | 0 | writeLibraryDirectory( context.getLibraryDirectory(), writer ); |
125 | |
} |
126 | |
|
127 | 0 | writer.endElement(); |
128 | |
|
129 | 0 | close( w ); |
130 | 0 | } |
131 | |
|
132 | |
private void writeApplicationName( String applicationName, XMLWriter writer ) |
133 | |
{ |
134 | 0 | if ( applicationName != null ) |
135 | |
{ |
136 | 0 | writer.startElement( "application-name" ); |
137 | 0 | writer.writeText( applicationName ); |
138 | 0 | writer.endElement(); |
139 | |
} |
140 | 0 | } |
141 | |
|
142 | |
private void writeDescription( String description, XMLWriter writer ) |
143 | |
{ |
144 | 0 | if ( description != null ) |
145 | |
{ |
146 | 0 | writer.startElement( "description" ); |
147 | 0 | writer.writeText( description ); |
148 | 0 | writer.endElement(); |
149 | |
} |
150 | 0 | } |
151 | |
|
152 | |
private void writeDisplayName( String displayName, XMLWriter writer ) |
153 | |
{ |
154 | 0 | if ( displayName != null ) |
155 | |
{ |
156 | 0 | writer.startElement( "display-name" ); |
157 | 0 | writer.writeText( displayName ); |
158 | 0 | writer.endElement(); |
159 | |
} |
160 | 0 | } |
161 | |
|
162 | |
private void writeInitializeInOrder( Boolean initializeInOrder, XMLWriter writer ) |
163 | |
{ |
164 | 0 | if ( initializeInOrder != null ) |
165 | |
{ |
166 | 0 | writer.startElement( "initialize-in-order" ); |
167 | 0 | writer.writeText( initializeInOrder.toString() ); |
168 | 0 | writer.endElement(); |
169 | |
} |
170 | 0 | } |
171 | |
|
172 | |
private void writeLibraryDirectory( String libraryDirectory, XMLWriter writer ) |
173 | |
{ |
174 | 0 | if ( libraryDirectory != null ) |
175 | |
{ |
176 | 0 | writer.startElement( "library-directory" ); |
177 | 0 | writer.writeText( libraryDirectory ); |
178 | 0 | writer.endElement(); |
179 | |
} |
180 | 0 | } |
181 | |
|
182 | |
private XMLWriter initializeRootElementOneDotThree( Writer w ) |
183 | |
{ |
184 | 0 | XMLWriter writer = initializeXmlWriter( w, DOCTYPE_1_3 ); |
185 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
186 | 0 | return writer; |
187 | |
} |
188 | |
|
189 | |
private XMLWriter initializeRootElementOneDotFour( Writer w ) |
190 | |
{ |
191 | 0 | XMLWriter writer = initializeXmlWriter( w, null ); |
192 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
193 | 0 | writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/j2ee" ); |
194 | 0 | writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
195 | 0 | writer.addAttribute( "xsi:schemaLocation", |
196 | |
"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" ); |
197 | 0 | writer.addAttribute( "version", "1.4" ); |
198 | 0 | return writer; |
199 | |
} |
200 | |
|
201 | |
private XMLWriter initializeRootElementFive( Writer w ) |
202 | |
{ |
203 | 0 | XMLWriter writer = initializeXmlWriter( w, null ); |
204 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
205 | 0 | writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/javaee" ); |
206 | 0 | writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
207 | 0 | writer.addAttribute( "xsi:schemaLocation", |
208 | |
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" ); |
209 | 0 | writer.addAttribute( "version", "5" ); |
210 | 0 | return writer; |
211 | |
} |
212 | |
|
213 | |
private XMLWriter initializeRootElementSix( Writer w ) |
214 | |
{ |
215 | 0 | XMLWriter writer = initializeXmlWriter( w, null ); |
216 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
217 | 0 | writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/javaee" ); |
218 | 0 | writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
219 | 0 | writer.addAttribute( "xsi:schemaLocation", |
220 | |
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" ); |
221 | 0 | writer.addAttribute( "version", "6" ); |
222 | 0 | return writer; |
223 | |
} |
224 | |
|
225 | |
} |