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 result
.add(farFileItem
);
411 public List
<FarFileItem
> getPackageContents(PackageIdentification packageId
) {
412 List
<FarFileItem
> farFileList
= new ArrayList
<FarFileItem
>();
413 Iterator pkgItem
= this.fPkgList
.iterator();
414 while (pkgItem
.hasNext()) {
415 FarPackage pkg
= (FarPackage
) pkgItem
.next();
416 if (pkg
.isIdentityPkg(packageId
)) {
418 // Add spd far file to list.
420 farFileList
.add(pkg
.getFarFile());
422 // Add all files in contents to list.
424 farFileList
.addAll(pkg
.getContentList());
426 // Add all farfiles in <FarPlatformList> to list.
428 // List<FarPlatformItem> plfList = pkg.getFarPlatformList();
429 // Iterator plfItem = plfList.iterator();
430 // while (plfItem.hasNext()) {
431 // farFileList.add(((FarPlatformItem) plfItem.next())
435 Iterator
<FarFileItem
> ffIter
= farFileList
.iterator();
436 while (ffIter
.hasNext()) {
437 FarFileItem ffItem
= ffIter
.next();
438 ffItem
.setDefaultPath(pkg
.getDefaultPath() + File
.separatorChar
+ ffItem
.getRelativeFilename());
450 * @return String: return string represent jar file entry;
452 public String
[] getPackgeSpd(PackageIdentification pkgId
) {
453 Iterator pkgItem
= this.fPkgList
.iterator();
454 String
[] entryStr
= new String
[2];
455 while (pkgItem
.hasNext()) {
456 FarPackage pkg
= (FarPackage
) pkgItem
.next();
457 if (pkg
.isIdentityPkg(pkgId
)) {
458 entryStr
[0] = pkg
.getFarFile().getRelativeFilename();
459 entryStr
[1] = pkg
.getDefaultPath();
466 public List
<FarFileItem
> getPackageContents() {
468 // In this farFilelist,all FarFileItem's relativeFileName should be
469 // set as absolutely path.
471 List
<FarFileItem
> farFileList
= new ArrayList
<FarFileItem
>();
472 Iterator pkgItem
= this.fPkgList
.iterator();
473 FarFileItem ffItem
= null;
475 while (pkgItem
.hasNext()) {
476 FarPackage pkg
= (FarPackage
) pkgItem
.next();
479 // Add spd far file to list.
481 ffItem
= pkg
.getFarFile();
483 // Set farFileItem relativeFileName = absolutePath + file Name.
485 farFileList
.add(new FarFileItem(pkg
.getDefaultPath() + File
.separatorChar
+ ffItem
.getRelativeFilename(),
486 ffItem
.getMd5Value()));
488 // Add all files in contents to list.
490 Iterator contentsItem
= pkg
.getContentList().iterator();
491 while (contentsItem
.hasNext()) {
492 ffItem
= (FarFileItem
) contentsItem
.next();
493 farFileList
.add(new FarFileItem(pkg
.getDefaultPath() + File
.separator
+ ffItem
.getRelativeFilename(),
494 ffItem
.getMd5Value()));
497 // Add all farfiles in <FarPlatformList> to list.
499 List
<FarPlatformItem
> plfList
= pkg
.getFarPlatformList();
500 Iterator plfItem
= plfList
.iterator();
501 while (plfItem
.hasNext()) {
502 ffItem
= ((FarPlatformItem
) plfItem
.next()).getFarFile();
503 farFileList
.add(new FarFileItem(pkg
.getDefaultPath() + File
.separator
+ ffItem
.getRelativeFilename(),
504 ffItem
.getMd5Value()));
510 public String
getPackageDefaultPath(PackageIdentification packageId
) {
511 Iterator pkgItr
= this.fPkgList
.iterator();
512 while (pkgItr
.hasNext()) {
513 FarPackage farPackage
= (FarPackage
) pkgItr
.next();
514 if (farPackage
.isIdentityPkg(packageId
)) {
515 return farPackage
.getDefaultPath();
521 // public void setPackageInstallPath(PackageIdentification packageId, String path) {
522 // Iterator<FarPackage> pkgItr = this.fPkgList.iterator();
523 // while (pkgItr.hasNext()) {
524 // FarPackage farPackage = pkgItr.next();
525 // if (farPackage.isIdentityPkg(packageId)) {
526 // farPackage.setDefaultPath(path);
532 // public void setPlatformInstallPath(PlatformIdentification platformId, String path) {
533 // Iterator<FarPlatformItem> plfItr = this.fPlfList.iterator();
534 // while (plfItr.hasNext()) {
535 // FarPlatformItem farPlatform = plfItr.next();
536 // if (farPlatform.i.isIdentity(platformId)) {
537 // farPackage.setDefaultPath(path);
543 public List
<FarFileItem
> getAllFileItem() {
545 // The farFileName in this list are all abosulte path.
547 List
<FarFileItem
> ffiList
= new ArrayList
<FarFileItem
>();
549 // Add far files in <FarPackageList> to list.
551 ffiList
= this.getPackageContents();
554 // Add far files in <FarPlatformList> to list
556 NodeList elementList
= this.mainfestDoc
.getElementsByTagName(farPlatformList
);
557 for (int i
= 0; i
< elementList
.getLength(); i
++) {
559 // Get <farPlatform> node list.
561 Node item
= elementList
.item(i
);
562 NodeList plfElements
= item
.getChildNodes();
563 for (int j
= 0; j
< plfElements
.getLength(); j
++) {
565 // Get each <FarPlatform> content.
567 NodeList plfChildNode
= plfElements
.item(i
).getChildNodes();
568 Node tempNode
= null;
569 for (int t
= 0; t
< plfChildNode
.getLength(); t
++) {
570 tempNode
= plfChildNode
.item(t
);
572 // Get child node value and set to platformIdentification.
574 if (tempNode
.getNodeName().equalsIgnoreCase(farPackage_FarfileName
)) {
575 NamedNodeMap farAttr
= tempNode
.getAttributes();
577 // Change relative path to absolute one
579 FarFileItem farFile
= new FarFileItem(tempNode
.getTextContent(),
580 farAttr
.getNamedItem(farFileName_Md5sum
).getTextContent());
581 ffiList
.add(farFile
);
589 public void hibernateToFile() throws Exception
{
591 // create mainfest root node
593 Element rootNode
= this.mainfestDoc
.createElement("FrameworkArchiveManifest");
594 this.mainfestDoc
.appendChild(rootNode
);
597 // create mainfest header node
599 Element headerNode
= this.mainfestDoc
.createElement(farHeader
);
600 rootNode
.appendChild(headerNode
);
602 // Add FarHeader to headerNode.
604 Element farName
= this.mainfestDoc
.createElement(farHeader_FarName
);
605 farName
.setTextContent(this.fhInfo
.getFarName());
606 headerNode
.appendChild(farName
);
608 Element gv
= this.mainfestDoc
.createElement(guidValue
);
609 gv
.setTextContent(this.fhInfo
.getGuidValue());
610 headerNode
.appendChild(gv
);
612 Element ver
= this.mainfestDoc
.createElement(version
);
613 ver
.setTextContent(this.fhInfo
.getVersion());
614 headerNode
.appendChild(ver
);
616 Element abstra
= this.mainfestDoc
.createElement(farHeader_Abstract
);
617 abstra
.setTextContent(this.fhInfo
.getAbstractStr());
618 headerNode
.appendChild(abstra
);
620 Element descr
= this.mainfestDoc
.createElement(farHeader_Description
);
621 descr
.setTextContent(this.fhInfo
.getDescription());
622 headerNode
.appendChild(descr
);
624 Element copyright
= this.mainfestDoc
.createElement(farHeader_CopyRight
);
625 copyright
.setTextContent(this.fhInfo
.getCopyright());
626 headerNode
.appendChild(copyright
);
628 Element license
= this.mainfestDoc
.createElement(farHeader_License
);
629 license
.setTextContent(this.fhInfo
.getLicense());
630 headerNode
.appendChild(license
);
632 Element spec
= this.mainfestDoc
.createElement(farHeader_Specification
);
633 spec
.setTextContent(this.fhInfo
.getSpecification());
634 System
.out
.println(this.fhInfo
.getSpecification());
635 headerNode
.appendChild(spec
);
638 // create mainfest FarPackageList node
640 Element pkgListNode
= this.mainfestDoc
.createElement(farPackageList
);
641 rootNode
.appendChild(pkgListNode
);
644 // Save each item in farPackage list to <FarPackage>.
646 Iterator pkgItem
= this.fPkgList
.iterator();
647 while (pkgItem
.hasNext()) {
648 pkgToFarPkgNode(pkgListNode
, (FarPackage
) pkgItem
.next());
653 // create mainfest FarPlatformList node
655 Element plfListNode
= this.mainfestDoc
.createElement(farPlatformList
);
656 rootNode
.appendChild(plfListNode
);
659 // Save farPakcage list info to <FarPackageList> node
661 Iterator plfItem
= this.fPlfList
.iterator();
662 while (plfItem
.hasNext()) {
663 FarPlatformItem plfIterator
= (FarPlatformItem
) plfItem
.next();
664 PlfToPlatformNode(plfListNode
, plfIterator
);
668 // Write the DOM document to the file
670 Transformer xformer
= TransformerFactory
.newInstance().newTransformer();
671 xformer
.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
672 xformer
.setOutputProperty(OutputKeys
.INDENT
, "yes");
675 // Prepare the DOM document for writing
677 Source source
= new DOMSource(this.mainfestDoc
);
679 // Prepare the output file, get the Mainifest file name from <FarHeader>
682 this.mfFile
= new File(Workspace
.getCurrentWorkspace() + File
.separatorChar
+ mfFileName
);
684 // generate all directory path
686 Result result
= new StreamResult(this.mfFile
);
687 xformer
.transform(source
, result
);
690 public void pkgToFarPkgNode(Element parentNode
, FarPackage pkgItem
) {
691 Element pkgNode
= this.mainfestDoc
.createElement(farPackageList_FarPackage
);
695 ffiToFfNode(pkgNode
, pkgItem
.getFarFile());
699 setStrItemToNode(pkgNode
, pkgItem
.getGuidValue(), guidValue
);
703 setStrItemToNode(pkgNode
, pkgItem
.getVersion(), version
);
707 setStrItemToNode(pkgNode
, pkgItem
.getDefaultPath(), farPackage_DefaultPath
);
712 Element contentNode
= this.mainfestDoc
.createElement(contents
);
713 Iterator iterator
= pkgItem
.getContentList().iterator();
714 while (iterator
.hasNext()) {
715 ffiToFfNode(contentNode
, (FarFileItem
) iterator
.next());
717 pkgNode
.appendChild(contentNode
);
718 parentNode
.appendChild(pkgNode
);
721 public void PlfToPlatformNode(Element parentNode
, FarPlatformItem fplItem
) {
722 Element fplNode
= this.mainfestDoc
.createElement(farPlatformList_FarPlatform
);
726 ffiToFfNode(fplNode
, fplItem
.getFarFile());
730 setStrItemToNode(fplNode
, fplItem
.getGuidValue(), guidValue
);
734 setStrItemToNode(fplNode
, fplItem
.getVersion(), version
);
736 // Add to <PlatformList>
738 parentNode
.appendChild(fplNode
);
742 public void ffiToFfNode(Element parentNode
, FarFileItem ffi
) {
743 Element farFileName
= this.mainfestDoc
.createElement(farPackage_FarfileName
);
744 farFileName
.setTextContent(ffi
.getRelativeFilename());
745 System
.out
.println(farFileName
.getTextContent());
746 System
.out
.println(ffi
.getRelativeFilename());
747 farFileName
.setAttribute(farFileName_Md5sum
, ffi
.getMd5Value());
748 parentNode
.appendChild(farFileName
);
751 public void setStrItemToNode(Element parentNode
, String strValue
, String strName
) {
752 Element node
= this.mainfestDoc
.createElement(strName
);
753 node
.setTextContent(strValue
);
754 parentNode
.appendChild(node
);
757 private void parseMainfest() {
764 // parse <farPackageList>
766 parseHeaderFarPackageList();
769 // parse <farPlatformList>
771 NodeList ele
= this.mainfestDoc
.getElementsByTagName(farPlatformList
);
773 if (ele
.getLength() > 0) {
775 // Only have one <FarPlatformList> node under mainfest root node.
777 plfNode
= ele
.item(0);
778 parseFarPlatformList(plfNode
, this.fPlfList
);
782 private void parseMfHeader() {
784 NodeList ele
= this.mainfestDoc
.getElementsByTagName(farHeader
);
785 if (ele
.getLength() > 0) {
787 // For mainfest file only have one <FarHeader>
789 headerNode
= ele
.item(0);
793 NodeList childList
= headerNode
.getChildNodes();
795 String nodeName
= null;
796 for (int i
= 0; i
< childList
.getLength(); i
++) {
797 node
= childList
.item(i
);
798 nodeName
= node
.getNodeName();
799 if (nodeName
.equalsIgnoreCase(farHeader_FarName
)) {
800 String nodeValue
= node
.getTextContent();
801 this.fhInfo
.setFarName(nodeValue
);
802 } else if (nodeName
.equalsIgnoreCase(guidValue
)) {
803 this.fhInfo
.setGuidValue(node
.getTextContent());
804 } else if (nodeName
.equalsIgnoreCase(version
)) {
805 this.fhInfo
.setVersion(node
.getTextContent());
806 } else if (nodeName
.equalsIgnoreCase(farHeader_Abstract
)) {
807 this.fhInfo
.setAbstractStr(node
.getTextContent());
808 } else if (nodeName
.equalsIgnoreCase(farHeader_Description
)) {
809 this.fhInfo
.setDescription(node
.getTextContent());
810 } else if (nodeName
.equalsIgnoreCase(farHeader_CopyRight
)) {
811 this.fhInfo
.setCopyright(node
.getTextContent());
812 } else if (nodeName
.equalsIgnoreCase(farHeader_License
)) {
813 this.fhInfo
.setLicense(node
.getTextContent());
814 } else if (nodeName
.equalsIgnoreCase(farHeader_Specification
)) {
815 this.fhInfo
.setSpecification(node
.getTextContent());
820 public void parseHeaderFarPackageList() {
822 NodeList ele
= this.mainfestDoc
.getElementsByTagName(farPackageList
);
823 if (ele
.getLength() > 0) {
825 // For mainfest file only have one <FarHeader>
827 farPkgNode
= ele
.item(0);
831 NodeList fpnList
= farPkgNode
.getChildNodes();
832 for (int i
= 0; i
< fpnList
.getLength(); i
++) {
833 if (fpnList
.item(i
).getNodeType() == Node
.TEXT_NODE
) {
836 FarPackage fpItem
= new FarPackage();
837 parseFarPackage(fpnList
.item(i
), fpItem
);
838 this.fPkgList
.add(fpItem
);
842 public void parseFarPackage(Node farPkgNode
, FarPackage fpItem
) {
843 NodeList childList
= farPkgNode
.getChildNodes();
846 for (int i
= 0; i
< childList
.getLength(); i
++) {
847 childNode
= childList
.item(i
);
848 childName
= childNode
.getNodeName();
849 if (childName
.equalsIgnoreCase(farPackage_FarfileName
)) {
850 fpItem
.setFarFile(parseFarFile(childNode
));
851 } else if (childName
.equalsIgnoreCase(guidValue
)) {
852 fpItem
.setGuidValue(childNode
.getTextContent());
853 } else if (childName
.equalsIgnoreCase(version
)) {
854 fpItem
.setVersion(childNode
.getTextContent());
855 } else if (childName
.equalsIgnoreCase(farPackage_DefaultPath
)) {
856 fpItem
.setDefaultPath(childNode
.getTextContent());
857 } else if (childName
.equalsIgnoreCase(farPlatformList
)) {
858 List
<FarPlatformItem
> plfList
= new ArrayList
<FarPlatformItem
>();
859 parseFarPlatformList(childNode
, plfList
);
860 fpItem
.setFarPlatformList(plfList
);
861 } else if (childName
.equalsIgnoreCase(contents
)) {
862 List
<FarFileItem
> ffList
= new ArrayList
<FarFileItem
>();
863 parseContents(childNode
, ffList
);
864 fpItem
.setContentList(ffList
);
874 public void parseFarPlatformList(Node fpfListNode
, List
<FarPlatformItem
> plfList
) {
876 // Get <FarPlatform> list.
878 NodeList child
= fpfListNode
.getChildNodes();
880 for (int i
= 0; i
< child
.getLength(); i
++) {
881 if (child
.item(i
).getNodeType() == Node
.TEXT_NODE
) {
884 farPlfNode
= child
.item(i
);
885 plfList
.add(parseFarPlatform(farPlfNode
));
894 public FarPlatformItem
parseFarPlatform(Node fpfNode
) {
896 // New FarPlatformItem.
898 FarPlatformItem fplItem
= new FarPlatformItem();
900 // Get <FarPlatform> elements;
902 NodeList childList
= fpfNode
.getChildNodes();
905 for (int i
= 0; i
< childList
.getLength(); i
++) {
906 child
= childList
.item(i
);
907 nodeName
= child
.getNodeName();
908 if (nodeName
.equalsIgnoreCase(farPackage_FarfileName
)) {
909 fplItem
.setFarFile(parseFarFile(child
));
910 } else if (nodeName
.equalsIgnoreCase(guidValue
)) {
911 fplItem
.setGuidValue(child
.getTextContent());
912 } else if (nodeName
.equalsIgnoreCase(version
)) {
913 fplItem
.setVersion(child
.getTextContent());
920 public void parseContents(Node contentsNode
, List
<FarFileItem
> ffList
) {
921 NodeList contentList
= contentsNode
.getChildNodes();
923 for (int i
= 0; i
< contentList
.getLength(); i
++) {
924 if (contentList
.item(i
).getNodeType() == Node
.TEXT_NODE
) {
927 contentNode
= contentList
.item(i
);
929 // Parse each <FarFileName>.
931 ffList
.add(parseFarFile(contentNode
));
935 public FarFileItem
parseFarFile(Node farFileNode
) {
936 String ffName
= farFileNode
.getTextContent();
937 NamedNodeMap attr
= farFileNode
.getAttributes();
938 FarFileItem ffItem
= new FarFileItem(ffName
, attr
.getNamedItem(farFileName_Md5sum
).getTextContent());
942 public boolean isFilter(File file
, Set
<String
> fileter
) {
943 Iterator
<String
> iter
= fileter
.iterator();
944 while (iter
.hasNext()) {
945 Pattern pattern
= Pattern
.compile(iter
.next());
946 Matcher matcher
= pattern
.matcher(file
.getName());
948 if (matcher
.find()) {