webinf.mkdirs();
File destWebXML = new File(webinf, "web.xml");
File configDir = getGenerateDir();
File webXML = new File(configDir, "web.xml");
EnunciateFreemarkerModel model = getModel();
model.setFileOutputDirectory(configDir);
try {
//delayed to the "build" phase to enable modules to supply their web app fragments.
model.put("displayName", model.getEnunciateConfig().getLabel());
model.put("webAppFragments", enunciate.getWebAppFragments());
List<WebAppResource> envEntries = Collections.<WebAppResource>emptyList();
List<WebAppResource> resourceEnvRefs = Collections.<WebAppResource>emptyList();
List<WebAppResource> resourceRefs = Collections.<WebAppResource>emptyList();
WebAppConfig webAppConfig = getWebAppConfig();
if (webAppConfig != null) {
envEntries = webAppConfig.getEnvEntries();
resourceEnvRefs = webAppConfig.getResourceEnvRefs();
resourceRefs = webAppConfig.getResourceRefs();
}
model.put("envEntries", envEntries);
model.put("resourceEnvRefs", resourceEnvRefs);
model.put("resourceRefs", resourceRefs);
if (webAppConfig != null) {
model.put("webappAttributes", webAppConfig.getWebXmlAttributes());
}
processTemplate(getWebXmlTemplateURL(), model);
}
catch (TemplateException e) {
throw new EnunciateException("Error processing web.xml template file.", e);
}
File mergedWebXml = webXML;
WebAppConfig webAppConfig = getWebAppConfig();
if ((webAppConfig != null) && (webAppConfig.getMergeWebXMLURL() != null || webAppConfig.getMergeWebXML() != null)) {
URL webXmlToMerge = webAppConfig.getMergeWebXMLURL();
if (webXmlToMerge == null) {
webXmlToMerge = enunciate.resolvePath(webAppConfig.getMergeWebXML()).toURL();
}
try {
Document source1Doc = loadMergeXml(webXmlToMerge.openStream());
NodeModel.simplify(source1Doc);
Document source2Doc = loadMergeXml(new FileInputStream(webXML));
NodeModel.simplify(source2Doc);
Map<String, String> mergedAttributes = new HashMap<String, String>();
NamedNodeMap source2Attributes = source2Doc.getDocumentElement().getAttributes();
for (int i = 0; i < source2Attributes.getLength(); i++) {
mergedAttributes.put(source2Attributes.item(i).getNodeName(), source2Attributes.item(i).getNodeValue());
}
NamedNodeMap source1Attributes = source1Doc.getDocumentElement().getAttributes();
for (int i = 0; i < source1Attributes.getLength(); i++) {
mergedAttributes.put(source1Attributes.item(i).getNodeName(), source1Attributes.item(i).getNodeValue());
}
model.put("source1", NodeModel.wrap(source1Doc.getDocumentElement()));
model.put("source2", NodeModel.wrap(source2Doc.getDocumentElement()));
model.put("mergedAttributes", mergedAttributes);
processTemplate(getMergeWebXmlTemplateURL(), model);
}
catch (TemplateException e) {
throw new EnunciateException("Error while merging web xml files.", e);
}