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 org.codehaus.plexus.util.xml.XMLWriter; |
23 | |
|
24 | |
import java.io.Writer; |
25 | |
import java.util.Iterator; |
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 String version; |
45 | |
|
46 | |
ApplicationXmlWriter( String version, String encoding ) |
47 | |
{ |
48 | 0 | super( encoding ); |
49 | 0 | this.version = version; |
50 | 0 | } |
51 | |
|
52 | |
public void write( ApplicationXmlWriterContext context ) |
53 | |
throws EarPluginException |
54 | |
{ |
55 | 0 | Writer w = initializeWriter( context.getDestinationFile() ); |
56 | |
|
57 | 0 | XMLWriter writer = null; |
58 | 0 | if ( GenerateApplicationXmlMojo.VERSION_1_3.equals( version ) ) |
59 | |
{ |
60 | 0 | writer = initializeRootElementOneDotThree( w ); |
61 | |
} |
62 | 0 | else if ( GenerateApplicationXmlMojo.VERSION_1_4.equals( version ) ) |
63 | |
{ |
64 | 0 | writer = initializeRootElementOneDotFour( w ); |
65 | |
} |
66 | 0 | else if ( GenerateApplicationXmlMojo.VERSION_5.equals( version ) ) |
67 | |
{ |
68 | 0 | writer = initializeRootElementFive( w ); |
69 | |
} |
70 | 0 | else if ( GenerateApplicationXmlMojo.VERSION_6.equals( version ) ) |
71 | |
{ |
72 | 0 | writer = initializeRootElementSix( w ); |
73 | |
} |
74 | |
|
75 | |
|
76 | |
|
77 | 0 | if ( GenerateApplicationXmlMojo.VERSION_1_3.equals( version ) ) |
78 | |
{ |
79 | 0 | writeDisplayName( context.getDisplayName(), writer ); |
80 | 0 | writeDescription( context.getDescription(), writer ); |
81 | |
} |
82 | |
else |
83 | |
{ |
84 | 0 | writeDescription( context.getDescription(), writer ); |
85 | 0 | writeDisplayName( context.getDisplayName(), writer ); |
86 | |
} |
87 | |
|
88 | |
|
89 | |
|
90 | 0 | final Iterator moduleIt = context.getEarModules().iterator(); |
91 | 0 | while ( moduleIt.hasNext() ) |
92 | |
{ |
93 | 0 | EarModule module = (EarModule) moduleIt.next(); |
94 | 0 | module.appendModule( writer, version ); |
95 | 0 | } |
96 | |
|
97 | 0 | final Iterator securityRoleIt = context.getSecurityRoles().iterator(); |
98 | 0 | while ( securityRoleIt.hasNext() ) |
99 | |
{ |
100 | 0 | SecurityRole securityRole = (SecurityRole) securityRoleIt.next(); |
101 | 0 | securityRole.appendSecurityRole( writer ); |
102 | 0 | } |
103 | |
|
104 | 0 | if ( GenerateApplicationXmlMojo.VERSION_5.equals( version ) ) |
105 | |
{ |
106 | 0 | writeLibraryDirectory( context.getLibraryDirectory(), writer ); |
107 | |
} |
108 | |
|
109 | 0 | writer.endElement(); |
110 | |
|
111 | 0 | close( w ); |
112 | 0 | } |
113 | |
|
114 | |
private void writeDescription( String description, XMLWriter writer ) |
115 | |
{ |
116 | 0 | if ( description != null ) |
117 | |
{ |
118 | 0 | writer.startElement( "description" ); |
119 | 0 | writer.writeText( description ); |
120 | 0 | writer.endElement(); |
121 | |
} |
122 | 0 | } |
123 | |
|
124 | |
private void writeDisplayName( String displayName, XMLWriter writer ) |
125 | |
{ |
126 | 0 | if ( displayName != null ) |
127 | |
{ |
128 | 0 | writer.startElement( "display-name" ); |
129 | 0 | writer.writeText( displayName ); |
130 | 0 | writer.endElement(); |
131 | |
} |
132 | 0 | } |
133 | |
|
134 | |
private void writeLibraryDirectory( String libraryDirectory, XMLWriter writer ) |
135 | |
{ |
136 | 0 | if ( libraryDirectory != null ) |
137 | |
{ |
138 | 0 | writer.startElement( "library-directory" ); |
139 | 0 | writer.writeText( libraryDirectory ); |
140 | 0 | writer.endElement(); |
141 | |
} |
142 | 0 | } |
143 | |
|
144 | |
private XMLWriter initializeRootElementOneDotThree( Writer w ) |
145 | |
{ |
146 | 0 | XMLWriter writer = initializeXmlWriter( w, DOCTYPE_1_3 ); |
147 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
148 | 0 | return writer; |
149 | |
} |
150 | |
|
151 | |
private XMLWriter initializeRootElementOneDotFour( Writer w ) |
152 | |
{ |
153 | 0 | XMLWriter writer = initializeXmlWriter( w, null ); |
154 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
155 | 0 | writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/j2ee" ); |
156 | 0 | writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
157 | 0 | writer.addAttribute( "xsi:schemaLocation", |
158 | |
"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" ); |
159 | 0 | writer.addAttribute( "version", "1.4" ); |
160 | 0 | return writer; |
161 | |
} |
162 | |
|
163 | |
private XMLWriter initializeRootElementFive( Writer w ) |
164 | |
{ |
165 | 0 | XMLWriter writer = initializeXmlWriter( w, null ); |
166 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
167 | 0 | writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/javaee" ); |
168 | 0 | writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
169 | 0 | writer.addAttribute( "xsi:schemaLocation", |
170 | |
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" ); |
171 | 0 | writer.addAttribute( "version", "5" ); |
172 | 0 | return writer; |
173 | |
} |
174 | |
|
175 | |
private XMLWriter initializeRootElementSix( Writer w ) |
176 | |
{ |
177 | 0 | XMLWriter writer = initializeXmlWriter( w, null ); |
178 | 0 | writer.startElement( APPLICATION_ELEMENT ); |
179 | 0 | writer.addAttribute( "xmlns", "http://java.sun.com/xml/ns/javaee" ); |
180 | 0 | writer.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
181 | 0 | writer.addAttribute( "xsi:schemaLocation", |
182 | |
"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" ); |
183 | 0 | writer.addAttribute( "version", "6" ); |
184 | 0 | return writer; |
185 | |
} |
186 | |
|
187 | |
} |