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.Five ) ) |
115 | |
{ |
116 | 0 | writeLibraryDirectory( context.getLibraryDirectory(), writer ); |
117 | |
} |
118 | |
|
119 | 0 | writer.endElement(); |
120 | |
|
121 | 0 | close( w ); |
122 | 0 | } |
123 | |
|
124 | |
private void writeApplicationName( String applicationName, XMLWriter writer ) |
125 | |
{ |
126 | 0 | if ( applicationName != null ) |
127 | |
{ |
128 | 0 | writer.startElement( "application-name" ); |
129 | 0 | writer.writeText( applicationName ); |
130 | 0 | writer.endElement(); |
131 | |
} |
132 | 0 | } |
133 | |
|
134 | |
private void writeDescription( String description, XMLWriter writer ) |
135 | |
{ |
136 | 0 | if ( description != null ) |
137 | |
{ |
138 | 0 | writer.startElement( "description" ); |
139 | 0 | writer.writeText( description ); |
140 | 0 | writer.endElement(); |
141 | |
} |
142 | 0 | } |
143 | |
|
144 | |
private void writeDisplayName( String displayName, XMLWriter writer ) |
145 | |
{ |
146 | 0 | if ( displayName != null ) |
147 | |
{ |
148 | 0 | writer.startElement( "display-name" ); |
149 | 0 | writer.writeText( displayName ); |
150 | 0 | writer.endElement(); |
151 | |
} |
152 | 0 | } |
153 | |
|
154 | |
private void writeInitializeInOrder( Boolean initializeInOrder, XMLWriter writer ) |
155 | |
{ |
156 | 0 | if ( initializeInOrder != null ) |
157 | |
{ |
158 | 0 | writer.startElement( "initialize-in-order" ); |
159 | 0 | writer.writeText( initializeInOrder.toString() ); |
160 | 0 | writer.endElement(); |
161 | |
} |
162 | 0 | } |
163 | |
|
164 | |
private void writeLibraryDirectory( String libraryDirectory, XMLWriter writer ) |
165 | |
{ |
166 | 0 | if ( libraryDirectory != null ) |
167 | |
{ |
168 | 0 | writer.startElement( "library-directory" ); |
169 | 0 | writer.writeText( libraryDirectory ); |
170 | 0 | writer.endElement(); |
171 | |
} |
172 | 0 | } |
173 | |
|
174 | |
private XMLWriter initializeRootElementOneDotThree( Writer w ) |
175 | |
{ |
176 | 0 | XMLWriter writer = initializeXmlWriter( w, DOCTYPE_1_3 ); |
177 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
178 | 0 | return writer; |
179 | |
} |
180 | |
|
181 | |
private XMLWriter initializeRootElementOneDotFour( Writer w ) |
182 | |
{ |
183 | 0 | XMLWriter writer = initializeXmlWriter( w, null ); |
184 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
185 | 0 | writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/j2ee" ); |
186 | 0 | writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
187 | 0 | writer.addAttribute( "xsi:schemaLocation", |
188 | |
"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" ); |
189 | 0 | writer.addAttribute( "version", "1.4" ); |
190 | 0 | return writer; |
191 | |
} |
192 | |
|
193 | |
private XMLWriter initializeRootElementFive( Writer w ) |
194 | |
{ |
195 | 0 | XMLWriter writer = initializeXmlWriter( w, null ); |
196 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
197 | 0 | writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/javaee" ); |
198 | 0 | writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
199 | 0 | writer.addAttribute( "xsi:schemaLocation", |
200 | |
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" ); |
201 | 0 | writer.addAttribute( "version", "5" ); |
202 | 0 | return writer; |
203 | |
} |
204 | |
|
205 | |
private XMLWriter initializeRootElementSix( Writer w ) |
206 | |
{ |
207 | 0 | XMLWriter writer = initializeXmlWriter( w, null ); |
208 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
209 | 0 | writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/javaee" ); |
210 | 0 | writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
211 | 0 | writer.addAttribute( "xsi:schemaLocation", |
212 | |
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" ); |
213 | 0 | writer.addAttribute( "version", "6" ); |
214 | 0 | return writer; |
215 | |
} |
216 | |
|
217 | |
} |