Modify the way of pcd warning message reporting to be a total in the end.
[mirror_edk2.git] / Tools / Java / Source / GenBuild / org / tianocore / build / fpd / PlatformBuildFileGenerator.java
CommitLineData
a29c47e0 1/** @file\r
2 \r
3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 **/\r
12package org.tianocore.build.fpd;\r
13\r
14import java.io.File;\r
4b5f5549 15import java.util.HashMap;\r
a29c47e0 16import java.util.Iterator;\r
17import java.util.Map;\r
18import java.util.Set;\r
19\r
20import javax.xml.parsers.DocumentBuilder;\r
21import javax.xml.parsers.DocumentBuilderFactory;\r
22import javax.xml.transform.OutputKeys;\r
23import javax.xml.transform.Result;\r
24import javax.xml.transform.Source;\r
25import javax.xml.transform.Transformer;\r
26import javax.xml.transform.TransformerFactory;\r
27import javax.xml.transform.dom.DOMSource;\r
28import javax.xml.transform.stream.StreamResult;\r
29\r
30import org.apache.tools.ant.BuildException;\r
31import org.apache.tools.ant.Project;\r
32import org.tianocore.build.global.GlobalData;\r
33import org.tianocore.build.global.SurfaceAreaQuery;\r
34import org.tianocore.build.id.FpdModuleIdentification;\r
35import org.tianocore.build.id.ModuleIdentification;\r
36import org.w3c.dom.Comment;\r
37import org.w3c.dom.Document;\r
38import org.w3c.dom.Element;\r
8031d48d 39import org.w3c.dom.NamedNodeMap;\r
a29c47e0 40import org.w3c.dom.Node;\r
8031d48d 41import org.w3c.dom.NodeList;\r
a29c47e0 42\r
82516887 43/**\r
44 class PlatformBuildFileGenerator is used to generate ${PLATFORM}_build.xml file. \r
45\r
46 @since GenBuild 1.0\r
47**/\r
a29c47e0 48public class PlatformBuildFileGenerator {\r
49\r
a29c47e0 50 ///\r
51 /// Mapping from modules identification to out put file name\r
52 ///\r
53 private Map<FpdModuleIdentification, String> outfiles;\r
4b5f5549 54 \r
55 ///\r
56 /// Mapping from FV name to its modules\r
57 ///\r
58 private Map<String, Set<FpdModuleIdentification>> fvs = new HashMap<String, Set<FpdModuleIdentification>>();\r
59\r
a29c47e0 60\r
a29c47e0 61 private boolean isUnified = true;\r
62 \r
83fba802 63 private SurfaceAreaQuery saq = null;\r
64 \r
02c768ee 65 private File platformBuildFile = null;\r
66 \r
a29c47e0 67 private Project project;\r
68 \r
69 private String info = "DO NOT EDIT \n" \r
391dbbb1 70 + "This file is auto-generated by the build utility\n" \r
a29c47e0 71 + "\n" \r
72 + "Abstract:\n"\r
391dbbb1 73 + "Auto-generated ANT build file for building EFI Modules and Platforms\n";\r
a29c47e0 74\r
02c768ee 75 public PlatformBuildFileGenerator(Project project, Map<FpdModuleIdentification, String> outfiles, Map<String, Set<FpdModuleIdentification>> fvs, boolean isUnified, SurfaceAreaQuery saq, String platformBuildFile){\r
a29c47e0 76 this.project = project;\r
77 this.outfiles = outfiles;\r
a29c47e0 78 this.isUnified = isUnified;\r
4b5f5549 79 this.fvs = fvs;\r
83fba802 80 this.saq = saq;\r
02c768ee 81 this.platformBuildFile = new File(platformBuildFile);\r
a29c47e0 82 }\r
83 \r
84 /**\r
85 Generate build.out.xml file.\r
86 \r
87 @throws BuildException\r
88 build.out.xml XML document create error\r
89 **/\r
90 public void genBuildFile() throws BuildException {\r
91 DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();\r
92 try {\r
93 DocumentBuilder dombuilder = domfac.newDocumentBuilder();\r
94 Document document = dombuilder.newDocument();\r
95 Comment rootComment = document.createComment(info);\r
96 //\r
97 // create root element and its attributes\r
98 //\r
99 Element root = document.createElement("project");\r
100 root.setAttribute("name", project.getProperty("PLATFORM"));\r
101 root.setAttribute("default", "all");\r
102 root.setAttribute("basedir", ".");\r
103 \r
104 //\r
105 // element for External ANT tasks\r
106 //\r
107 root.appendChild(document.createComment("Apply external ANT tasks"));\r
108 Element ele = document.createElement("taskdef");\r
109 ele.setAttribute("resource", "GenBuild.tasks");\r
110 root.appendChild(ele);\r
111\r
112 ele = document.createElement("taskdef");\r
113 ele.setAttribute("resource", "frameworktasks.tasks");\r
114 root.appendChild(ele);\r
115\r
e1347472 116 ele = document.createElement("taskdef");\r
117 ele.setAttribute("resource", "net/sf/antcontrib/antlib.xml");\r
118 root.appendChild(ele);\r
119 \r
a29c47e0 120 ele = document.createElement("property");\r
121 ele.setAttribute("environment", "env");\r
122 root.appendChild(ele);\r
123 \r
a29c47e0 124 //\r
125 // Default Target\r
126 //\r
127 root.appendChild(document.createComment("Default target"));\r
128 ele = document.createElement("target");\r
129 ele.setAttribute("name", "all");\r
01413f0c 130 ele.setAttribute("depends", "prebuild, modules, fvs, postbuild");\r
a29c47e0 131 root.appendChild(ele);\r
132 \r
133 //\r
134 // Modules and Fvs Target\r
135 //\r
01413f0c 136 applyModules(document, root);\r
137 \r
138 applyFvs(document, root);\r
a29c47e0 139\r
140 //\r
141 // Clean Target\r
142 //\r
143 applyClean(document, root);\r
144 \r
145 //\r
146 // Deep Clean Target\r
147 //\r
148 applyCleanall(document, root);\r
149 \r
150 //\r
8cf5da75 151 // User Extension pre build\r
a29c47e0 152 //\r
8cf5da75 153 applyUserExtensionsPreBuild(document, root);\r
154 \r
155 //\r
156 // User Extension Post build\r
157 //\r
158 applyUserExtensionsPostBuild(document, root);\r
a29c47e0 159 \r
160 document.appendChild(rootComment);\r
161 document.appendChild(root);\r
162 //\r
163 // Prepare the DOM document for writing\r
164 //\r
165 Source source = new DOMSource(document);\r
166 //\r
a29c47e0 167 // generate all directory path\r
168 //\r
02c768ee 169 (new File(platformBuildFile.getParent())).mkdirs();\r
170 Result result = new StreamResult(platformBuildFile);\r
a29c47e0 171 //\r
172 // Write the DOM document to the file\r
173 //\r
174 Transformer xformer = TransformerFactory.newInstance().newTransformer();\r
175 xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");\r
176 xformer.setOutputProperty(OutputKeys.INDENT, "yes");\r
177 xformer.transform(source, result);\r
178 } catch (Exception ex) {\r
02c768ee 179 throw new BuildException("Generating platform build file [" + platformBuildFile.getPath() + "_build.xml] failed. \n" + ex.getMessage());\r
a29c47e0 180 }\r
181 }\r
8031d48d 182 \r
4b5f5549 183 /**\r
184 1. Get All valid Fv Image Names in sequence\r
185 2. For each FV, get modules by sequences\r
186 3. Get other modules\r
187 \r
188 @param document XML document\r
189 @param root Node\r
190 **/\r
01413f0c 191 private void applyModules(Document document, Node root) {\r
a29c47e0 192 root.appendChild(document.createComment("Modules target"));\r
193 Element ele = document.createElement("target");\r
01413f0c 194 ele.setAttribute("name", "modules");\r
a29c47e0 195\r
4b5f5549 196 //\r
197 // Get all valid FV name\r
198 //\r
83fba802 199 String[] validFv = saq.getFpdValidImageNames();\r
4b5f5549 200 \r
201 //\r
202 // For each valid FV, get all modules in sequence\r
203 //\r
204 for (int i = 0; i < validFv.length; i++) {\r
205 if (fvs.containsKey(validFv[i])) {\r
206 Set<FpdModuleIdentification> set = fvs.get(validFv[i]);\r
207 Iterator<FpdModuleIdentification> iter = set.iterator();\r
208 while (iter.hasNext()) {\r
209 FpdModuleIdentification fpdModuleId = iter.next();\r
210 applySingleModule(document, ele, fpdModuleId);\r
211 }\r
212 }\r
a29c47e0 213 }\r
4b5f5549 214 \r
215 //\r
216 // Get all other modules\r
217 //\r
218 Iterator<String> fvsNameIter = fvs.keySet().iterator();\r
219 \r
220 while (fvsNameIter.hasNext()) {\r
221 String fvName = fvsNameIter.next();\r
222 if (!isContain(validFv, fvName)) {\r
223 Set<FpdModuleIdentification> set = fvs.get(fvName);\r
224 Iterator iter = set.iterator();\r
225 while (iter.hasNext()) {\r
226 FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
227 applySingleModule(document, ele, fpdModuleId);\r
228 }\r
229 }\r
230 }\r
231\r
a29c47e0 232 root.appendChild(ele);\r
233 }\r
234 \r
4b5f5549 235 private void applySingleModule(Document document, Node root, FpdModuleIdentification fpdModuleId) {\r
236 ModuleIdentification moduleId = fpdModuleId.getModule();\r
237 Element moduleEle = document.createElement("GenBuild");\r
238 moduleEle.setAttribute("type", "build");\r
239 //\r
240 // Inherit Properties.\r
241 //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"}\r
242 //\r
243 \r
244 //\r
245 // ARCH\r
246 //\r
247 Element property = document.createElement("property");\r
248 property.setAttribute("name", "ARCH");\r
249 property.setAttribute("value", fpdModuleId.getArch());\r
250 moduleEle.appendChild(property);\r
251\r
252 //\r
253 // MODULE_GUID\r
254 //\r
255 property = document.createElement("property");\r
256 property.setAttribute("name", "MODULE_GUID");\r
257 property.setAttribute("value", moduleId.getGuid());\r
258 moduleEle.appendChild(property);\r
259 \r
260 //\r
261 // MODULE_VERSION\r
262 //\r
263 property = document.createElement("property");\r
264 property.setAttribute("name", "MODULE_VERSION");\r
265 property.setAttribute("value", moduleId.getVersion());\r
266 moduleEle.appendChild(property);\r
267 \r
268 //\r
269 // PACKAGE_GUID\r
270 //\r
271 property = document.createElement("property");\r
272 property.setAttribute("name", "PACKAGE_GUID");\r
273 property.setAttribute("value", moduleId.getPackage().getGuid());\r
274 moduleEle.appendChild(property);\r
275 \r
276 //\r
277 // PACKAGE_VERSION\r
278 //\r
279 property = document.createElement("property");\r
280 property.setAttribute("name", "PACKAGE_VERSION");\r
281 property.setAttribute("value", moduleId.getPackage().getVersion());\r
282 moduleEle.appendChild(property);\r
283 \r
284 root.appendChild(moduleEle);\r
285 }\r
286 \r
287 private boolean isContain(String[] list, String item) {\r
288 for (int i = 0; i < list.length; i++) {\r
289 if (list[i].equalsIgnoreCase(item)) {\r
290 return true;\r
291 }\r
292 }\r
293 return false;\r
294 }\r
295 \r
01413f0c 296 private void applyFvs(Document document, Node root) {\r
a29c47e0 297 //\r
298 // FVS Target\r
299 //\r
300 root.appendChild(document.createComment("FVs target"));\r
301 Element ele = document.createElement("target");\r
01413f0c 302 ele.setAttribute("name", "fvs");\r
a29c47e0 303\r
304 //\r
305 // For every Target and ToolChain\r
306 //\r
307 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
308 for (int i = 0; i < targetList.length; i++){\r
309 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
310 for(int j = 0; j < toolchainList.length; j++){\r
311 String fvOutputDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
6ae1510e 312 + targetList[i] + "_" \r
bdaa67b1 313 + toolchainList[j] + File.separatorChar + "FV";\r
83fba802 314 String[] validFv = saq.getFpdValidImageNames();\r
a29c47e0 315 for (int k = 0; k < validFv.length; k++) {\r
01413f0c 316 String inputFile = fvOutputDir + "" + File.separatorChar + validFv[k].toUpperCase() + ".inf";\r
317 Element fvEle = document.createElement("genfvimage");\r
318 fvEle.setAttribute("infFile", inputFile);\r
319 fvEle.setAttribute("outputDir", fvOutputDir);\r
320 ele.appendChild(fvEle);\r
a29c47e0 321 }\r
322 }\r
323 }\r
324 root.appendChild(ele);\r
325 }\r
326 \r
327 private void applyClean(Document document, Node root) {\r
328 //\r
329 // Clean Target\r
330 //\r
331 root.appendChild(document.createComment("Clean target"));\r
332 Element ele = document.createElement("target");\r
333 ele.setAttribute("name", "clean");\r
334\r
335 if (isUnified) {\r
336 Element cleanEle = document.createElement("delete");\r
337 cleanEle.setAttribute("includeemptydirs", "true");\r
338 Element filesetEle = document.createElement("fileset");\r
339 filesetEle.setAttribute("dir", project.getProperty("BUILD_DIR"));\r
340 filesetEle.setAttribute("includes", "**\\OUTPUT\\**");\r
341 cleanEle.appendChild(filesetEle);\r
342 ele.appendChild(cleanEle);\r
343 } else {\r
344 Set set = outfiles.keySet();\r
345 Iterator iter = set.iterator();\r
346 while (iter.hasNext()) {\r
347 FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
348 ModuleIdentification moduleId = fpdModuleId.getModule();\r
349\r
350 Element ifEle = document.createElement("if");\r
351 Element availableEle = document.createElement("available");\r
352 availableEle.setAttribute("file", moduleId.getMsaFile().getParent() + File.separatorChar\r
353 + "build.xml");\r
354 ifEle.appendChild(availableEle);\r
355 Element elseEle = document.createElement("then");\r
356\r
357 Element moduleEle = document.createElement("ant");\r
358 moduleEle.setAttribute("antfile", moduleId.getMsaFile().getParent() + File.separatorChar\r
359 + "build.xml");\r
360 moduleEle.setAttribute("target", "clean");\r
361 //\r
362 // Inherit Properties.\r
363 //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"}\r
364 //\r
365 \r
366 //\r
367 // ARCH\r
368 //\r
369 Element property = document.createElement("property");\r
370 property.setAttribute("name", "ARCH");\r
371 property.setAttribute("value", fpdModuleId.getArch());\r
372 moduleEle.appendChild(property);\r
373\r
374 //\r
375 // PACKAGE\r
376 //\r
377 property = document.createElement("property");\r
378 property.setAttribute("name", "PACKAGE");\r
379 property.setAttribute("value", moduleId.getPackage().getName());\r
380 moduleEle.appendChild(property);\r
381 \r
382 //\r
383 // PACKAGE_GUID\r
384 //\r
385 property = document.createElement("property");\r
386 property.setAttribute("name", "PACKAGE_GUID");\r
387 property.setAttribute("value", moduleId.getPackage().getGuid());\r
388 moduleEle.appendChild(property);\r
389 \r
390 //\r
391 // PACKAGE_VERSION\r
392 //\r
393 property = document.createElement("property");\r
394 property.setAttribute("name", "PACKAGE_VERSION");\r
395 property.setAttribute("value", moduleId.getPackage().getVersion());\r
396 moduleEle.appendChild(property);\r
397 \r
398 //\r
399 // MODULE_DIR\r
400 //\r
401 property = document.createElement("property");\r
402 property.setAttribute("name", "MODULE_DIR");\r
403 property.setAttribute("value", moduleId.getMsaFile().getParent());\r
404 moduleEle.appendChild(property);\r
405 elseEle.appendChild(moduleEle);\r
406 ifEle.appendChild(elseEle);\r
407 ele.appendChild(ifEle);\r
408 }\r
409 }\r
410 root.appendChild(ele);\r
411 }\r
412 \r
413 private void applyCleanall(Document document, Node root) {\r
414 //\r
415 // Deep Clean Target\r
416 //\r
391dbbb1 417 root.appendChild(document.createComment("Target: cleanall"));\r
a29c47e0 418 Element ele = document.createElement("target");\r
419 ele.setAttribute("name", "cleanall");\r
420\r
421 if (isUnified) {\r
d3dfaf4b 422 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
423 for (int i = 0; i < targetList.length; ++i) {\r
6ae1510e 424 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
425 for(int j = 0; j < toolchainList.length; j++) {\r
426 Element cleanAllEle = document.createElement("delete");\r
427 cleanAllEle.setAttribute("dir", project.getProperty("BUILD_DIR") + File.separatorChar + targetList[i] + "_" + toolchainList[j]);\r
428 ele.appendChild(cleanAllEle);\r
429 }\r
d3dfaf4b 430 }\r
a29c47e0 431 } else {\r
432 Set set = outfiles.keySet();\r
433 Iterator iter = set.iterator();\r
434 while (iter.hasNext()) {\r
435 FpdModuleIdentification fpdModuleId = (FpdModuleIdentification) iter.next();\r
436 ModuleIdentification moduleId = fpdModuleId.getModule();\r
437\r
438 Element ifEle = document.createElement("if");\r
439 Element availableEle = document.createElement("available");\r
440 availableEle.setAttribute("file", moduleId.getMsaFile().getParent() + File.separatorChar\r
441 + "build.xml");\r
442 ifEle.appendChild(availableEle);\r
443 Element elseEle = document.createElement("then");\r
444\r
445 Element moduleEle = document.createElement("ant");\r
446 moduleEle.setAttribute("antfile", moduleId.getMsaFile().getParent() + File.separatorChar\r
447 + "build.xml");\r
448 moduleEle.setAttribute("target", "cleanall");\r
449 //\r
450 // Inherit Properties.\r
451 //{"ARCH", "PACKAGE", "PACKAGE_GUID", "PACKAGE_VERSION", "MODULE_DIR"}\r
452 //\r
453 \r
454 //\r
455 // ARCH\r
456 //\r
457 Element property = document.createElement("property");\r
458 property.setAttribute("name", "ARCH");\r
459 property.setAttribute("value", fpdModuleId.getArch());\r
460 moduleEle.appendChild(property);\r
461\r
462 //\r
463 // PACKAGE\r
464 //\r
465 property = document.createElement("property");\r
466 property.setAttribute("name", "PACKAGE");\r
467 property.setAttribute("value", moduleId.getPackage().getName());\r
468 moduleEle.appendChild(property);\r
469 \r
470 //\r
471 // PACKAGE_GUID\r
472 //\r
473 property = document.createElement("property");\r
474 property.setAttribute("name", "PACKAGE_GUID");\r
475 property.setAttribute("value", moduleId.getPackage().getGuid());\r
476 moduleEle.appendChild(property);\r
477 \r
478 //\r
479 // PACKAGE_VERSION\r
480 //\r
481 property = document.createElement("property");\r
482 property.setAttribute("name", "PACKAGE_VERSION");\r
483 property.setAttribute("value", moduleId.getPackage().getVersion());\r
484 moduleEle.appendChild(property);\r
485 \r
486 //\r
487 // MODULE_DIR\r
488 //\r
489 property = document.createElement("property");\r
490 property.setAttribute("name", "MODULE_DIR");\r
491 property.setAttribute("value", moduleId.getMsaFile().getParent());\r
492 moduleEle.appendChild(property);\r
493 elseEle.appendChild(moduleEle);\r
494 ifEle.appendChild(elseEle);\r
495 ele.appendChild(ifEle);\r
496 }\r
497 }\r
498 root.appendChild(ele);\r
499 }\r
500 \r
8cf5da75 501 private void applyUserExtensionsPreBuild(Document document, Node root) {\r
502 //\r
503 // User Extensions\r
504 //\r
391dbbb1 505 root.appendChild(document.createComment("Pre-Build Processing"));\r
8cf5da75 506 Element ele = document.createElement("target");\r
507 ele.setAttribute("name", "prebuild");\r
508 \r
83fba802 509 Node node = saq.getFpdUserExtensionPreBuild();\r
8cf5da75 510 if (node != null) {\r
511 //\r
512 // For every Target and ToolChain\r
513 //\r
514 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
515 for (int i = 0; i < targetList.length; i++){\r
516 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
517 for(int j = 0; j < toolchainList.length; j++){\r
518 //\r
519 // Prepare FV_DIR\r
520 //\r
521 String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
6ae1510e 522 + targetList[i] + "_" \r
8cf5da75 523 + toolchainList[j];\r
524 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
525 Element fvEle = document.createElement("var");\r
526 fvEle.setAttribute("name", "FV_DIR");\r
527 fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
528 ele.appendChild(fvEle);\r
529 \r
4250be6c 530 Element targetDirEle = document.createElement("var");\r
531 targetDirEle.setAttribute("name", "TARGET_DIR");\r
532 targetDirEle.setAttribute("value", ffsCommonDir.replaceAll("(\\\\)", "/"));\r
533 ele.appendChild(targetDirEle);\r
534 \r
8cf5da75 535 NodeList childNodes = node.getChildNodes();\r
536 for (int k = 0; k < childNodes.getLength(); k++) {\r
537 Node childItem = childNodes.item(k);\r
538 if (childItem.getNodeType() == Node.ELEMENT_NODE) {\r
539 ele.appendChild(recursiveNode(childItem, document));\r
540 }\r
541 }\r
8cf5da75 542 }\r
543 }\r
544 }\r
545 \r
546 root.appendChild(ele);\r
547 }\r
548 \r
549 private void applyUserExtensionsPostBuild(Document document, Node root) {\r
a29c47e0 550 //\r
551 // User Extensions\r
552 //\r
391dbbb1 553 root.appendChild(document.createComment("Post-Build Processing"));\r
a29c47e0 554 Element ele = document.createElement("target");\r
8cf5da75 555 ele.setAttribute("name", "postbuild");\r
a29c47e0 556 \r
83fba802 557 Node node = saq.getFpdUserExtensionPostBuild();\r
8031d48d 558 if (node != null) {\r
559 //\r
560 // For every Target and ToolChain\r
561 //\r
562 String[] targetList = GlobalData.getToolChainInfo().getTargets();\r
563 for (int i = 0; i < targetList.length; i++){\r
564 String[] toolchainList = GlobalData.getToolChainInfo().getTagnames();\r
565 for(int j = 0; j < toolchainList.length; j++){\r
566 //\r
567 // Prepare FV_DIR\r
568 //\r
569 String ffsCommonDir = project.getProperty("BUILD_DIR") + File.separatorChar \r
6ae1510e 570 + targetList[i] + "_" \r
8031d48d 571 + toolchainList[j];\r
572 File fvDir = new File(ffsCommonDir + File.separatorChar + "FV");\r
573 Element fvEle = document.createElement("var");\r
574 fvEle.setAttribute("name", "FV_DIR");\r
575 fvEle.setAttribute("value", fvDir.getPath().replaceAll("(\\\\)", "/"));\r
576 ele.appendChild(fvEle);\r
577 \r
4250be6c 578 Element targetDirEle = document.createElement("var");\r
579 targetDirEle.setAttribute("name", "TARGET_DIR");\r
580 targetDirEle.setAttribute("value", ffsCommonDir.replaceAll("(\\\\)", "/"));\r
581 ele.appendChild(targetDirEle);\r
582 \r
8031d48d 583 NodeList childNodes = node.getChildNodes();\r
584 for (int k = 0; k < childNodes.getLength(); k++) {\r
585 Node childItem = childNodes.item(k);\r
586 if (childItem.getNodeType() == Node.ELEMENT_NODE) {\r
587 ele.appendChild(recursiveNode(childItem, document));\r
588 }\r
589 }\r
590 \r
591 }\r
592 }\r
593 }\r
594 \r
a29c47e0 595 root.appendChild(ele);\r
596 }\r
597 \r
8031d48d 598 private Element recursiveNode(Node node, Document document) {\r
599 Element root = document.createElement(node.getNodeName());\r
600 NamedNodeMap attr = node.getAttributes();\r
601 for (int i = 0; i < attr.getLength(); i++) {\r
602 Node attrItem = attr.item(i);\r
603 root.setAttribute(attrItem.getNodeName(), attrItem.getNodeValue());\r
604 }\r
605 NodeList childNodes = node.getChildNodes();\r
606 for (int i = 0; i < childNodes.getLength(); i++) {\r
607 Node childItem = childNodes.item(i);\r
608 if (childItem.getNodeType() == Node.ELEMENT_NODE) {\r
609 root.appendChild(recursiveNode(childItem, document));\r
610 }\r
611 else if (childItem.getNodeType() == Node.TEXT_NODE){\r
91f7d582 612 if (!childItem.getNodeValue().trim().equalsIgnoreCase("")) {\r
8031d48d 613 root.setTextContent(childItem.getNodeValue());\r
614 }\r
615 }\r
616 }\r
617 return root;\r
618 }\r
a29c47e0 619}\r