3 The file is used to create Far's mainfest file
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 package org
.tianocore
.frameworkwizard
.far
;
18 import java
.io
.FileInputStream
;
19 import java
.io
.IOException
;
20 import java
.io
.InputStream
;
21 import java
.util
.ArrayList
;
22 import java
.util
.Iterator
;
23 import java
.util
.LinkedHashSet
;
24 import java
.util
.List
;
26 import java
.util
.regex
.Matcher
;
27 import java
.util
.regex
.Pattern
;
29 import javax
.xml
.parsers
.DocumentBuilder
;
30 import javax
.xml
.parsers
.DocumentBuilderFactory
;
31 import javax
.xml
.transform
.OutputKeys
;
32 import javax
.xml
.transform
.Result
;
33 import javax
.xml
.transform
.Source
;
34 import javax
.xml
.transform
.Transformer
;
35 import javax
.xml
.transform
.TransformerFactory
;
36 import javax
.xml
.transform
.dom
.DOMSource
;
37 import javax
.xml
.transform
.stream
.StreamResult
;
39 import org
.apache
.xmlbeans
.XmlException
;
40 import org
.tianocore
.frameworkwizard
.common
.Tools
;
41 import org
.tianocore
.frameworkwizard
.packaging
.PackageIdentification
;
42 import org
.tianocore
.frameworkwizard
.platform
.PlatformIdentification
;
43 import org
.tianocore
.frameworkwizard
.workspace
.Workspace
;
44 import org
.w3c
.dom
.Document
;
45 import org
.w3c
.dom
.Element
;
46 import org
.w3c
.dom
.NamedNodeMap
;
47 import org
.w3c
.dom
.Node
;
48 import org
.w3c
.dom
.NodeList
;
50 public class Mainfest
implements ManifestInterface
{
52 // / mainfest document
54 Document mainfestDoc
= null;
57 // / Mainfest file element name
59 final static String mfFileName
= "FarMainfest.MF";
64 final static String farHeader
= "FarHeader";
66 final static String farHeader_FarName
= "FarName";
68 final static String farHeader_Abstract
= "Abstract";
70 final static String farHeader_Description
= "Description";
72 final static String farHeader_CopyRight
= "CopyRight";
74 final static String farHeader_License
= "Licese";
76 final static String farHeader_Specification
= "Specification";
81 final static String farPackageList
= "FarPackageList";
83 final static String farPlatformList
= "FarPlatformList";
85 final static String contents
= "Contents";
87 final static String userExtensions
= "UserExtensions";
93 final static String guidValue
= "GuidValue";
95 final static String version
= "Version";
98 // FarPackage node name
100 final static String farPackageList_FarPackage
= "FarPackage";
102 final static String farPackage_FarfileName
= "FarFileName";
104 final static String farPackage_DefaultPath
= "DefaultPath";
106 final static String farPlatformList_FarPlatform
= "FarPlatform";
108 final static String farFileName_FarGuid
= "FarGuid";
110 final static String farFileName_Md5sum
= "Md5sum";
113 // mainfest header information.
115 FarHeader fhInfo
= new FarHeader();
120 List
<FarPackage
> fPkgList
= new ArrayList
<FarPackage
>();
125 List
<FarPlatformItem
> fPlfList
= new ArrayList
<FarPlatformItem
>();
127 Set
<File
> files
= new LinkedHashSet
<File
>();
134 public FarHeader
getHeader() {
138 public Mainfest() throws Exception
{
139 DocumentBuilderFactory domfac
= DocumentBuilderFactory
.newInstance();
140 DocumentBuilder dombuilder
= domfac
.newDocumentBuilder();
141 Document document
= dombuilder
.newDocument();
142 this.mainfestDoc
= document
;
146 public Mainfest(InputStream mainfestInputStream
) throws Exception
{
147 DocumentBuilderFactory domfac
= DocumentBuilderFactory
.newInstance();
149 if (mainfestInputStream
!= null) {
150 DocumentBuilder dombuilder
= domfac
.newDocumentBuilder();
151 this.mainfestDoc
= dombuilder
.parse(mainfestInputStream
);
155 } catch (Exception e
) {
157 // Will change to throw Wizader exception.
159 throw new Exception(e
.getMessage());
163 public void setFarHeader(FarHeader fHeader
) {
164 this.fhInfo
= fHeader
;
167 public void createManifest(List
<PackageIdentification
> pkgList
, List
<PlatformIdentification
> plfList
,
168 Set
<String
> fileFilter
) throws Exception
{
171 // Add Package and it's contents to FarPackageList.
173 Iterator
<PackageIdentification
> pkgItem
= pkgList
.iterator();
174 while (pkgItem
.hasNext()) {
175 PackageIdentification pkgId
= pkgItem
.next();
178 // Add package and it's contents to <FarPackageList>.
180 addPkgToPkgList(pkgId
, fileFilter
);
184 // Add FarPlatform to this.farPlatformList.
186 Iterator
<PlatformIdentification
> plfItem
= plfList
.iterator();
187 while (plfItem
.hasNext()) {
188 PlatformIdentification plfId
= plfItem
.next();
191 // Add platform to Mainifest.
193 addPlatformIdToFarPlatformItemList(plfId
);
197 public void setManifestFile(File mainfestFile
) throws Exception
{
198 DocumentBuilderFactory domfac
= DocumentBuilderFactory
.newInstance();
199 DocumentBuilder dombuilder
= domfac
.newDocumentBuilder();
200 InputStream is
= new FileInputStream(mainfestFile
);
201 this.mainfestDoc
= dombuilder
.parse(is
);
204 public void addPkgToPkgList(PackageIdentification packageId
, Set
<String
> fileFilter
) throws Exception
{
205 files
.add(packageId
.getSpdFile());
207 FarPackage farPackage
= new FarPackage();
209 // Add SPD file to FarPackage
211 File spdFile
= new File(packageId
.getPath());
213 FarFileItem ffItem
= new FarFileItem(spdFile
.getName(), FarMd5
.md5(spdFile
));
214 farPackage
.setFarFile(ffItem
);
217 // Add package guid value.
219 farPackage
.setGuidValue(packageId
.getGuid());
222 // Add package version
224 farPackage
.setVersion(packageId
.getVersion());
227 // Add DefaultPat: Package absoulte path - Workspace absolut
230 String pkgDir
= Tools
.getFilePathOnly(packageId
.getPath());
231 File rootDir
= new File(pkgDir
);
232 farPackage
.setDefaultPath(Tools
.getRelativePath(rootDir
.getPath(), Workspace
.getCurrentWorkspace()));
235 // Get package root dir contains.
237 Set
<File
> fileSet
= new LinkedHashSet
<File
>();
238 Set
<File
> fpdFileSet
= new LinkedHashSet
<File
>();
241 // Get all files and fpd files
243 recursiveDirectory(fileSet
, fpdFileSet
, rootDir
, fileFilter
);
246 // Remove current package's SPD file
248 fileSet
.remove(packageId
.getSpdFile());
250 files
.addAll(fileSet
);
252 Iterator
<File
> iter
= fileSet
.iterator();
253 List
<FarFileItem
> contents
= new ArrayList
<FarFileItem
>();
254 while (iter
.hasNext()) {
255 File normalFile
= iter
.next();
256 String fileRelativePath
= Tools
.getRelativePath(normalFile
.getPath(), pkgDir
);
257 ffItem
= new FarFileItem(fileRelativePath
, FarMd5
.md5(normalFile
));
258 contents
.add(ffItem
);
261 farPackage
.setContentList(contents
);
263 // List<FarPlatformItem> fpfList = new ArrayList<FarPlatformItem>();
265 // iter = fpdFileSet.iterator();
267 // while (iter.hasNext()) {
268 // File fpdFile = iter.next();
269 // PlatformIdentification platformId = new PlatformIdentification(wsTool
270 // .getId(fpdFile.getPath(), OpenFile.openFpdFile(fpdFile
272 // addPlatformIdToFarPlatformItemList(fpfList, platformId);
274 // farPackage.setFarPlatformList(fpfList);
275 fPkgList
.add(farPackage
);
278 private void recursiveDirectory(Set
<File
> files
, Set
<File
> fpds
, File dir
, Set
<String
> fileFilter
) {
279 if (isFilter(dir
, fileFilter
)) {
282 File
[] allFilesInDir
= dir
.listFiles();
283 for (int i
= 0; i
< allFilesInDir
.length
; i
++) {
284 if (allFilesInDir
[i
].isFile()) {
285 if (isFilter(allFilesInDir
[i
], fileFilter
)) {
288 // if (allFilesInDir[i].getPath().toLowerCase().endsWith(".fpd")) {
289 // fpds.add(allFilesInDir[i]);
291 files
.add(allFilesInDir
[i
]);
294 recursiveDirectory(files
, fpds
, allFilesInDir
[i
], fileFilter
);
299 public void addPlatformIdToFarPlatformItemList(PlatformIdentification platformId
) throws Exception
{
300 files
.add(platformId
.getFpdFile());
302 FarPlatformItem fpfItem
= new FarPlatformItem();
304 String fpfPath
= platformId
.getPath();
305 File fpfFile
= new File(fpfPath
);
309 ffItem
= new FarFileItem(Tools
.getRelativePath(fpfFile
.getPath(), Workspace
.getCurrentWorkspace()),
310 FarMd5
.md5(fpfFile
));
311 fpfItem
.setFarFile(ffItem
);
316 fpfItem
.setGuidValue(platformId
.getGuid());
321 fpfItem
.setVersion(platformId
.getVersion());
323 fPlfList
.add(fpfItem
);
329 * @return Set<PackageIdentification> list of PackageIdentification.
331 public List
<PackageIdentification
> getPackageList() throws Exception
{
333 // PackageIdentification set.
335 List
<PackageIdentification
> pkgList
= new ArrayList
<PackageIdentification
>();
339 Iterator pkgItem
= this.fPkgList
.iterator();
340 while (pkgItem
.hasNext()) {
341 FarPackage fPkg
= (FarPackage
) pkgItem
.next();
343 // Get package information from SPD file and create a package
347 PackageIdentification pkgId
= new PackageIdentification(fPkg
.getFarFile().getRelativeFilename(),
348 fPkg
.getGuidValue(), fPkg
.getVersion());
349 pkgId
.setPath(Workspace
.getCurrentWorkspace() + File
.separatorChar
+ fPkg
.getDefaultPath()
350 + File
.separatorChar
+ fPkg
.getFarFile().getRelativeFilename());
352 // Workspace.getCurrentWorkspace() + File.separatorChar
353 // + fPkg.getDefaultPath(), OpenFile
354 // .openFpdFile(Workspace.getCurrentWorkspace()
355 // + File.separatorChar
356 // + fPkg.getDefaultPath()
357 // + File.separatorChar
358 // + fPkg.getFarFile().getRelativeFilename()));
367 public List
<PlatformIdentification
> getPlatformList() throws Exception
, IOException
, XmlException
{
369 // PlatformIdentification set.
371 List
<PlatformIdentification
> plfList
= new ArrayList
<PlatformIdentification
>();
372 Iterator plfItem
= this.fPlfList
.iterator();
373 while (plfItem
.hasNext()) {
374 FarPlatformItem fpfItem
= (FarPlatformItem
) plfItem
.next();
375 File file
= new File(Workspace
.getCurrentWorkspace() + File
.separatorChar
376 + fpfItem
.getFarFile().getRelativeFilename());
378 // Set platformIdentificaiton's path as absolutly path (include
379 // workspace and FPD relatively path)
381 PlatformIdentification plfId
= new PlatformIdentification(fpfItem
.getFarFile().getRelativeFilename(),
382 fpfItem
.getGuidValue(), fpfItem
.getVersion(),
385 // (PlatformIdentification) wsTool
386 // .getId(file.getParent(), OpenFile.openFpdFile(Workspace
387 // .getCurrentWorkspace()
388 // + File.separatorChar
389 // + fpfItem.getFarFile().getRelativeFilename()));
395 public List
<FarFileItem
> getPlatformContents(PlatformIdentification platformId
) {
396 List
<FarFileItem
> result
= new ArrayList
<FarFileItem
>();
397 Iterator
<FarPlatformItem
> iter
= this.fPlfList
.iterator();
399 while (iter
.hasNext()) {
400 FarPlatformItem item
= iter
.next();
401 if (item
.isIdentityPlf(platformId
)) {
402 FarFileItem farFileItem
= item
.getFarFile();
403 farFileItem
.setDefaultPath(farFileItem
.getRelativeFilename());
404 farFileItem
.setRelativeFilename(Tools
.getFileNameOnly(farFileItem
.getRelativeFilename()));
405 result
.add(farFileItem
);
412 public List
<FarFileItem
> getPackageContents(PackageIdentification packageId
) {
413 List
<FarFileItem
> farFileList
= new ArrayList
<FarFileItem
>();
414 Iterator pkgItem
= this.fPkgList
.iterator();
415 while (pkgItem
.hasNext()) {
416 FarPackage pkg
= (FarPackage
) pkgItem
.next();
417 if (pkg
.isIdentityPkg(packageId
)) {
419 // Add spd far file to list.
421 farFileList
.add(pkg
.getFarFile());
423 // Add all files in contents to list.
425 farFileList
.addAll(pkg
.getContentList());
427 // Add all farfiles in <FarPlatformList> to list.
429 // List<FarPlatformItem> plfList = pkg.getFarPlatformList();
430 // Iterator plfItem = plfList.iterator();
431 // while (plfItem.hasNext()) {
432 // farFileList.add(((FarPlatformItem) plfItem.next())
436 Iterator
<FarFileItem
> ffIter
= farFileList
.iterator();
437 while (ffIter
.hasNext()) {
438 FarFileItem ffItem
= ffIter
.next();
439 ffItem
.setDefaultPath(pkg
.getDefaultPath() + File
.separatorChar
+ ffItem
.getRelativeFilename());
451 * @return String: return string represent jar file entry;
453 public String
[] getPackgeSpd(PackageIdentification pkgId
) {
454 Iterator pkgItem
= this.fPkgList
.iterator();
455 String
[] entryStr
= new String
[2];
456 while (pkgItem
.hasNext()) {
457 FarPackage pkg
= (FarPackage
) pkgItem
.next();
458 if (pkg
.isIdentityPkg(pkgId
)) {
459 entryStr
[0] = pkg
.getFarFile().getRelativeFilename();
460 entryStr
[1] = pkg
.getDefaultPath();
467 public List
<FarFileItem
> getPackageContents() {
469 // In this farFilelist,all FarFileItem's relativeFileName should be
470 // set as absolutely path.
472 List
<FarFileItem
> farFileList
= new ArrayList
<FarFileItem
>();
473 Iterator pkgItem
= this.fPkgList
.iterator();
474 FarFileItem ffItem
= null;
476 while (pkgItem
.hasNext()) {
477 FarPackage pkg
= (FarPackage
) pkgItem
.next();
480 // Add spd far file to list.
482 ffItem
= pkg
.getFarFile();
484 // Set farFileItem relativeFileName = absolutePath + file Name.
486 farFileList
.add(new FarFileItem(pkg
.getDefaultPath() + File
.separatorChar
+ ffItem
.getRelativeFilename(),
487 ffItem
.getMd5Value()));
489 // Add all files in contents to list.
491 Iterator contentsItem
= pkg
.getContentList().iterator();
492 while (contentsItem
.hasNext()) {
493 ffItem
= (FarFileItem
) contentsItem
.next();
494 farFileList
.add(new FarFileItem(pkg
.getDefaultPath() + File
.separator
+ ffItem
.getRelativeFilename(),
495 ffItem
.getMd5Value()));
498 // Add all farfiles in <FarPlatformList> to list.
500 List
<FarPlatformItem
> plfList
= pkg
.getFarPlatformList();
501 Iterator plfItem
= plfList
.iterator();
502 while (plfItem
.hasNext()) {
503 ffItem
= ((FarPlatformItem
) plfItem
.next()).getFarFile();
504 farFileList
.add(new FarFileItem(pkg
.getDefaultPath() + File
.separator
+ ffItem
.getRelativeFilename(),
505 ffItem
.getMd5Value()));
511 public String
getPackageDefaultPath(PackageIdentification packageId
) {
512 Iterator pkgItr
= this.fPkgList
.iterator();
513 while (pkgItr
.hasNext()) {
514 FarPackage farPackage
= (FarPackage
) pkgItr
.next();
515 if (farPackage
.isIdentityPkg(packageId
)) {
516 return farPackage
.getDefaultPath();
522 // public void setPackageInstallPath(PackageIdentification packageId, String path) {
523 // Iterator<FarPackage> pkgItr = this.fPkgList.iterator();
524 // while (pkgItr.hasNext()) {
525 // FarPackage farPackage = pkgItr.next();
526 // if (farPackage.isIdentityPkg(packageId)) {
527 // farPackage.setDefaultPath(path);
533 // public void setPlatformInstallPath(PlatformIdentification platformId, String path) {
534 // Iterator<FarPlatformItem> plfItr = this.fPlfList.iterator();
535 // while (plfItr.hasNext()) {
536 // FarPlatformItem farPlatform = plfItr.next();
537 // if (farPlatform.i.isIdentity(platformId)) {
538 // farPackage.setDefaultPath(path);
544 public List
<FarFileItem
> getAllFileItem() {
546 // The farFileName in this list are all abosulte path.
548 List
<FarFileItem
> ffiList
= new ArrayList
<FarFileItem
>();
550 // Add far files in <FarPackageList> to list.
552 ffiList
= this.getPackageContents();
555 // Add far files in <FarPlatformList> to list
557 NodeList elementList
= this.mainfestDoc
.getElementsByTagName(farPlatformList
);
558 for (int i
= 0; i
< elementList
.getLength(); i
++) {
560 // Get <farPlatform> node list.
562 Node item
= elementList
.item(i
);
563 NodeList plfElements
= item
.getChildNodes();
564 for (int j
= 0; j
< plfElements
.getLength(); j
++) {
566 // Get each <FarPlatform> content.
568 NodeList plfChildNode
= plfElements
.item(i
).getChildNodes();
569 Node tempNode
= null;
570 for (int t
= 0; t
< plfChildNode
.getLength(); t
++) {
571 tempNode
= plfChildNode
.item(t
);
573 // Get child node value and set to platformIdentification.
575 if (tempNode
.getNodeName().equalsIgnoreCase(farPackage_FarfileName
)) {
576 NamedNodeMap farAttr
= tempNode
.getAttributes();
578 // Change relative path to absolute one
580 FarFileItem farFile
= new FarFileItem(tempNode
.getTextContent(),
581 farAttr
.getNamedItem(farFileName_Md5sum
).getTextContent());
582 ffiList
.add(farFile
);
590 public void hibernateToFile() throws Exception
{
592 // create mainfest root node
594 Element rootNode
= this.mainfestDoc
.createElement("FrameworkArchiveManifest");
595 this.mainfestDoc
.appendChild(rootNode
);
598 // create mainfest header node
600 Element headerNode
= this.mainfestDoc
.createElement(farHeader
);
601 rootNode
.appendChild(headerNode
);
603 // Add FarHeader to headerNode.
605 Element farName
= this.mainfestDoc
.createElement(farHeader_FarName
);
606 farName
.setTextContent(this.fhInfo
.getFarName());
607 headerNode
.appendChild(farName
);
609 Element gv
= this.mainfestDoc
.createElement(guidValue
);
610 gv
.setTextContent(this.fhInfo
.getGuidValue());
611 headerNode
.appendChild(gv
);
613 Element ver
= this.mainfestDoc
.createElement(version
);
614 ver
.setTextContent(this.fhInfo
.getVersion());
615 headerNode
.appendChild(ver
);
617 Element abstra
= this.mainfestDoc
.createElement(farHeader_Abstract
);
618 abstra
.setTextContent(this.fhInfo
.getAbstractStr());
619 headerNode
.appendChild(abstra
);
621 Element descr
= this.mainfestDoc
.createElement(farHeader_Description
);
622 descr
.setTextContent(this.fhInfo
.getDescription());
623 headerNode
.appendChild(descr
);
625 Element copyright
= this.mainfestDoc
.createElement(farHeader_CopyRight
);
626 copyright
.setTextContent(this.fhInfo
.getCopyright());
627 headerNode
.appendChild(copyright
);
629 Element license
= this.mainfestDoc
.createElement(farHeader_License
);
630 license
.setTextContent(this.fhInfo
.getLicense());
631 headerNode
.appendChild(license
);
633 Element spec
= this.mainfestDoc
.createElement(farHeader_Specification
);
634 spec
.setTextContent(this.fhInfo
.getSpecification());
635 System
.out
.println(this.fhInfo
.getSpecification());
636 headerNode
.appendChild(spec
);
639 // create mainfest FarPackageList node
641 Element pkgListNode
= this.mainfestDoc
.createElement(farPackageList
);
642 rootNode
.appendChild(pkgListNode
);
645 // Save each item in farPackage list to <FarPackage>.
647 Iterator pkgItem
= this.fPkgList
.iterator();
648 while (pkgItem
.hasNext()) {
649 pkgToFarPkgNode(pkgListNode
, (FarPackage
) pkgItem
.next());
654 // create mainfest FarPlatformList node
656 Element plfListNode
= this.mainfestDoc
.createElement(farPlatformList
);
657 rootNode
.appendChild(plfListNode
);
660 // Save farPakcage list info to <FarPackageList> node
662 Iterator plfItem
= this.fPlfList
.iterator();
663 while (plfItem
.hasNext()) {
664 FarPlatformItem plfIterator
= (FarPlatformItem
) plfItem
.next();
665 PlfToPlatformNode(plfListNode
, plfIterator
);
669 // Write the DOM document to the file
671 Transformer xformer
= TransformerFactory
.newInstance().newTransformer();
672 xformer
.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
673 xformer
.setOutputProperty(OutputKeys
.INDENT
, "yes");
676 // Prepare the DOM document for writing
678 Source source
= new DOMSource(this.mainfestDoc
);
680 // Prepare the output file, get the Mainifest file name from <FarHeader>
683 this.mfFile
= new File(Workspace
.getCurrentWorkspace() + File
.separatorChar
+ mfFileName
);
685 // generate all directory path
687 Result result
= new StreamResult(this.mfFile
);
688 xformer
.transform(source
, result
);
691 public void pkgToFarPkgNode(Element parentNode
, FarPackage pkgItem
) {
692 Element pkgNode
= this.mainfestDoc
.createElement(farPackageList_FarPackage
);
696 ffiToFfNode(pkgNode
, pkgItem
.getFarFile());
700 setStrItemToNode(pkgNode
, pkgItem
.getGuidValue(), guidValue
);
704 setStrItemToNode(pkgNode
, pkgItem
.getVersion(), version
);
708 setStrItemToNode(pkgNode
, pkgItem
.getDefaultPath(), farPackage_DefaultPath
);
713 Element contentNode
= this.mainfestDoc
.createElement(contents
);
714 Iterator iterator
= pkgItem
.getContentList().iterator();
715 while (iterator
.hasNext()) {
716 ffiToFfNode(contentNode
, (FarFileItem
) iterator
.next());
718 pkgNode
.appendChild(contentNode
);
719 parentNode
.appendChild(pkgNode
);
722 public void PlfToPlatformNode(Element parentNode
, FarPlatformItem fplItem
) {
723 Element fplNode
= this.mainfestDoc
.createElement(farPlatformList_FarPlatform
);
727 ffiToFfNode(fplNode
, fplItem
.getFarFile());
731 setStrItemToNode(fplNode
, fplItem
.getGuidValue(), guidValue
);
735 setStrItemToNode(fplNode
, fplItem
.getVersion(), version
);
737 // Add to <PlatformList>
739 parentNode
.appendChild(fplNode
);
743 public void ffiToFfNode(Element parentNode
, FarFileItem ffi
) {
744 Element farFileName
= this.mainfestDoc
.createElement(farPackage_FarfileName
);
745 farFileName
.setTextContent(ffi
.getRelativeFilename());
746 System
.out
.println(farFileName
.getTextContent());
747 System
.out
.println(ffi
.getRelativeFilename());
748 farFileName
.setAttribute(farFileName_Md5sum
, ffi
.getMd5Value());
749 parentNode
.appendChild(farFileName
);
752 public void setStrItemToNode(Element parentNode
, String strValue
, String strName
) {
753 Element node
= this.mainfestDoc
.createElement(strName
);
754 node
.setTextContent(strValue
);
755 parentNode
.appendChild(node
);
758 private void parseMainfest() {
765 // parse <farPackageList>
767 parseHeaderFarPackageList();
770 // parse <farPlatformList>
772 NodeList ele
= this.mainfestDoc
.getElementsByTagName(farPlatformList
);
774 if (ele
.getLength() > 0) {
776 // Only have one <FarPlatformList> node under mainfest root node.
778 plfNode
= ele
.item(0);
779 parseFarPlatformList(plfNode
, this.fPlfList
);
783 private void parseMfHeader() {
785 NodeList ele
= this.mainfestDoc
.getElementsByTagName(farHeader
);
786 if (ele
.getLength() > 0) {
788 // For mainfest file only have one <FarHeader>
790 headerNode
= ele
.item(0);
794 NodeList childList
= headerNode
.getChildNodes();
796 String nodeName
= null;
797 for (int i
= 0; i
< childList
.getLength(); i
++) {
798 node
= childList
.item(i
);
799 nodeName
= node
.getNodeName();
800 if (nodeName
.equalsIgnoreCase(farHeader_FarName
)) {
801 String nodeValue
= node
.getTextContent();
802 this.fhInfo
.setFarName(nodeValue
);
803 } else if (nodeName
.equalsIgnoreCase(guidValue
)) {
804 this.fhInfo
.setGuidValue(node
.getTextContent());
805 } else if (nodeName
.equalsIgnoreCase(version
)) {
806 this.fhInfo
.setVersion(node
.getTextContent());
807 } else if (nodeName
.equalsIgnoreCase(farHeader_Abstract
)) {
808 this.fhInfo
.setAbstractStr(node
.getTextContent());
809 } else if (nodeName
.equalsIgnoreCase(farHeader_Description
)) {
810 this.fhInfo
.setDescription(node
.getTextContent());
811 } else if (nodeName
.equalsIgnoreCase(farHeader_CopyRight
)) {
812 this.fhInfo
.setCopyright(node
.getTextContent());
813 } else if (nodeName
.equalsIgnoreCase(farHeader_License
)) {
814 this.fhInfo
.setLicense(node
.getTextContent());
815 } else if (nodeName
.equalsIgnoreCase(farHeader_Specification
)) {
816 this.fhInfo
.setSpecification(node
.getTextContent());
821 public void parseHeaderFarPackageList() {
823 NodeList ele
= this.mainfestDoc
.getElementsByTagName(farPackageList
);
824 if (ele
.getLength() > 0) {
826 // For mainfest file only have one <FarHeader>
828 farPkgNode
= ele
.item(0);
832 NodeList fpnList
= farPkgNode
.getChildNodes();
833 for (int i
= 0; i
< fpnList
.getLength(); i
++) {
834 if (fpnList
.item(i
).getNodeType() == Node
.TEXT_NODE
) {
837 FarPackage fpItem
= new FarPackage();
838 parseFarPackage(fpnList
.item(i
), fpItem
);
839 this.fPkgList
.add(fpItem
);
843 public void parseFarPackage(Node farPkgNode
, FarPackage fpItem
) {
844 NodeList childList
= farPkgNode
.getChildNodes();
847 for (int i
= 0; i
< childList
.getLength(); i
++) {
848 childNode
= childList
.item(i
);
849 childName
= childNode
.getNodeName();
850 if (childName
.equalsIgnoreCase(farPackage_FarfileName
)) {
851 fpItem
.setFarFile(parseFarFile(childNode
));
852 } else if (childName
.equalsIgnoreCase(guidValue
)) {
853 fpItem
.setGuidValue(childNode
.getTextContent());
854 } else if (childName
.equalsIgnoreCase(version
)) {
855 fpItem
.setVersion(childNode
.getTextContent());
856 } else if (childName
.equalsIgnoreCase(farPackage_DefaultPath
)) {
857 fpItem
.setDefaultPath(childNode
.getTextContent());
858 } else if (childName
.equalsIgnoreCase(farPlatformList
)) {
859 List
<FarPlatformItem
> plfList
= new ArrayList
<FarPlatformItem
>();
860 parseFarPlatformList(childNode
, plfList
);
861 fpItem
.setFarPlatformList(plfList
);
862 } else if (childName
.equalsIgnoreCase(contents
)) {
863 List
<FarFileItem
> ffList
= new ArrayList
<FarFileItem
>();
864 parseContents(childNode
, ffList
);
865 fpItem
.setContentList(ffList
);
875 public void parseFarPlatformList(Node fpfListNode
, List
<FarPlatformItem
> plfList
) {
877 // Get <FarPlatform> list.
879 NodeList child
= fpfListNode
.getChildNodes();
881 for (int i
= 0; i
< child
.getLength(); i
++) {
882 if (child
.item(i
).getNodeType() == Node
.TEXT_NODE
) {
885 farPlfNode
= child
.item(i
);
886 plfList
.add(parseFarPlatform(farPlfNode
));
895 public FarPlatformItem
parseFarPlatform(Node fpfNode
) {
897 // New FarPlatformItem.
899 FarPlatformItem fplItem
= new FarPlatformItem();
901 // Get <FarPlatform> elements;
903 NodeList childList
= fpfNode
.getChildNodes();
906 for (int i
= 0; i
< childList
.getLength(); i
++) {
907 child
= childList
.item(i
);
908 nodeName
= child
.getNodeName();
909 if (nodeName
.equalsIgnoreCase(farPackage_FarfileName
)) {
910 fplItem
.setFarFile(parseFarFile(child
));
911 } else if (nodeName
.equalsIgnoreCase(guidValue
)) {
912 fplItem
.setGuidValue(child
.getTextContent());
913 } else if (nodeName
.equalsIgnoreCase(version
)) {
914 fplItem
.setVersion(child
.getTextContent());
921 public void parseContents(Node contentsNode
, List
<FarFileItem
> ffList
) {
922 NodeList contentList
= contentsNode
.getChildNodes();
924 for (int i
= 0; i
< contentList
.getLength(); i
++) {
925 if (contentList
.item(i
).getNodeType() == Node
.TEXT_NODE
) {
928 contentNode
= contentList
.item(i
);
930 // Parse each <FarFileName>.
932 ffList
.add(parseFarFile(contentNode
));
936 public FarFileItem
parseFarFile(Node farFileNode
) {
937 String ffName
= farFileNode
.getTextContent();
938 NamedNodeMap attr
= farFileNode
.getAttributes();
939 FarFileItem ffItem
= new FarFileItem(ffName
, attr
.getNamedItem(farFileName_Md5sum
).getTextContent());
943 public boolean isFilter(File file
, Set
<String
> fileter
) {
944 Iterator
<String
> iter
= fileter
.iterator();
945 while (iter
.hasNext()) {
946 Pattern pattern
= Pattern
.compile(iter
.next());
947 Matcher matcher
= pattern
.matcher(file
.getName());
949 if (matcher
.find()) {