3 The file is used to create Far's manifest 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 Manifest
implements ManifestInterface
{
52 // / manifest document
54 Document manifestDoc
= null;
57 // / Manfiest file element name
59 final static String mfFileName
= "FrameworkArchiveManifest.xml";
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
= "License";
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 // manifest 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
>();
132 public File mfFile
= null;
134 public FarHeader
getHeader() {
138 public Manifest() throws Exception
{
139 DocumentBuilderFactory domfac
= DocumentBuilderFactory
.newInstance();
140 DocumentBuilder dombuilder
= domfac
.newDocumentBuilder();
141 Document document
= dombuilder
.newDocument();
142 this.manifestDoc
= document
;
146 public Manifest(InputStream manifestInputStream
) throws Exception
{
147 DocumentBuilderFactory domfac
= DocumentBuilderFactory
.newInstance();
149 if (manifestInputStream
!= null) {
150 DocumentBuilder dombuilder
= domfac
.newDocumentBuilder();
151 this.manifestDoc
= dombuilder
.parse(manifestInputStream
);
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 manifestFile
) throws Exception
{
198 DocumentBuilderFactory domfac
= DocumentBuilderFactory
.newInstance();
199 DocumentBuilder dombuilder
= domfac
.newDocumentBuilder();
200 InputStream is
= new FileInputStream(manifestFile
);
201 this.manifestDoc
= 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.manifestDoc
.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 manifest root node
594 Element rootNode
= this.manifestDoc
.createElement("FrameworkArchiveManifest");
595 this.manifestDoc
.appendChild(rootNode
);
598 // create manifest header node
600 Element headerNode
= this.manifestDoc
.createElement(farHeader
);
601 rootNode
.appendChild(headerNode
);
603 // Add FarHeader to headerNode.
605 Element farName
= this.manifestDoc
.createElement(farHeader_FarName
);
606 farName
.setTextContent(this.fhInfo
.getFarName());
607 headerNode
.appendChild(farName
);
609 Element gv
= this.manifestDoc
.createElement(guidValue
);
610 gv
.setTextContent(this.fhInfo
.getGuidValue());
611 headerNode
.appendChild(gv
);
613 Element ver
= this.manifestDoc
.createElement(version
);
614 ver
.setTextContent(this.fhInfo
.getVersion());
615 headerNode
.appendChild(ver
);
617 Element abstra
= this.manifestDoc
.createElement(farHeader_Abstract
);
618 abstra
.setTextContent(this.fhInfo
.getAbstractStr());
619 headerNode
.appendChild(abstra
);
621 Element descr
= this.manifestDoc
.createElement(farHeader_Description
);
622 descr
.setTextContent(this.fhInfo
.getDescription());
623 headerNode
.appendChild(descr
);
625 Element copyright
= this.manifestDoc
.createElement(farHeader_CopyRight
);
626 copyright
.setTextContent(this.fhInfo
.getCopyright());
627 headerNode
.appendChild(copyright
);
629 Element license
= this.manifestDoc
.createElement(farHeader_License
);
630 license
.setTextContent(this.fhInfo
.getLicense());
631 headerNode
.appendChild(license
);
633 Element spec
= this.manifestDoc
.createElement(farHeader_Specification
);
634 spec
.setTextContent(this.fhInfo
.getSpecification());
635 System
.out
.println(this.fhInfo
.getSpecification());
636 headerNode
.appendChild(spec
);
639 // create manifest FarPackageList node
641 Element pkgListNode
= this.manifestDoc
.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 manifest FarPlatformList node
656 Element plfListNode
= this.manifestDoc
.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.manifestDoc
);
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
);
690 // Close result. Flush file by manual for Jdk1.5.0_04.
692 ((StreamResult
) result
).getOutputStream().close();
695 public void pkgToFarPkgNode(Element parentNode
, FarPackage pkgItem
) {
696 Element pkgNode
= this.manifestDoc
.createElement(farPackageList_FarPackage
);
700 ffiToFfNode(pkgNode
, pkgItem
.getFarFile());
704 setStrItemToNode(pkgNode
, pkgItem
.getGuidValue(), guidValue
);
708 setStrItemToNode(pkgNode
, pkgItem
.getVersion(), version
);
712 setStrItemToNode(pkgNode
, pkgItem
.getDefaultPath(), farPackage_DefaultPath
);
717 Element contentNode
= this.manifestDoc
.createElement(contents
);
718 Iterator iterator
= pkgItem
.getContentList().iterator();
719 while (iterator
.hasNext()) {
720 ffiToFfNode(contentNode
, (FarFileItem
) iterator
.next());
722 pkgNode
.appendChild(contentNode
);
723 parentNode
.appendChild(pkgNode
);
726 public void PlfToPlatformNode(Element parentNode
, FarPlatformItem fplItem
) {
727 Element fplNode
= this.manifestDoc
.createElement(farPlatformList_FarPlatform
);
731 ffiToFfNode(fplNode
, fplItem
.getFarFile());
735 setStrItemToNode(fplNode
, fplItem
.getGuidValue(), guidValue
);
739 setStrItemToNode(fplNode
, fplItem
.getVersion(), version
);
741 // Add to <PlatformList>
743 parentNode
.appendChild(fplNode
);
747 public void ffiToFfNode(Element parentNode
, FarFileItem ffi
) {
748 Element farFileName
= this.manifestDoc
.createElement(farPackage_FarfileName
);
749 farFileName
.setTextContent(ffi
.getRelativeFilename());
750 System
.out
.println(farFileName
.getTextContent());
751 System
.out
.println(ffi
.getRelativeFilename());
752 farFileName
.setAttribute(farFileName_Md5sum
, ffi
.getMd5Value());
753 parentNode
.appendChild(farFileName
);
756 public void setStrItemToNode(Element parentNode
, String strValue
, String strName
) {
757 Element node
= this.manifestDoc
.createElement(strName
);
758 node
.setTextContent(strValue
);
759 parentNode
.appendChild(node
);
762 private void parseManifest() {
769 // parse <farPackageList>
771 parseHeaderFarPackageList();
774 // parse <farPlatformList>
776 NodeList ele
= this.manifestDoc
.getElementsByTagName(farPlatformList
);
778 if (ele
.getLength() > 0) {
780 // Only have one <FarPlatformList> node under manifest root node.
782 plfNode
= ele
.item(0);
783 parseFarPlatformList(plfNode
, this.fPlfList
);
787 private void parseMfHeader() {
789 NodeList ele
= this.manifestDoc
.getElementsByTagName(farHeader
);
790 if (ele
.getLength() > 0) {
792 // For manifest file only have one <FarHeader>
794 headerNode
= ele
.item(0);
798 NodeList childList
= headerNode
.getChildNodes();
800 String nodeName
= null;
801 for (int i
= 0; i
< childList
.getLength(); i
++) {
802 node
= childList
.item(i
);
803 nodeName
= node
.getNodeName();
804 if (nodeName
.equalsIgnoreCase(farHeader_FarName
)) {
805 String nodeValue
= node
.getTextContent();
806 this.fhInfo
.setFarName(nodeValue
);
807 } else if (nodeName
.equalsIgnoreCase(guidValue
)) {
808 this.fhInfo
.setGuidValue(node
.getTextContent());
809 } else if (nodeName
.equalsIgnoreCase(version
)) {
810 this.fhInfo
.setVersion(node
.getTextContent());
811 } else if (nodeName
.equalsIgnoreCase(farHeader_Abstract
)) {
812 this.fhInfo
.setAbstractStr(node
.getTextContent());
813 } else if (nodeName
.equalsIgnoreCase(farHeader_Description
)) {
814 this.fhInfo
.setDescription(node
.getTextContent());
815 } else if (nodeName
.equalsIgnoreCase(farHeader_CopyRight
)) {
816 this.fhInfo
.setCopyright(node
.getTextContent());
817 } else if (nodeName
.equalsIgnoreCase(farHeader_License
)) {
818 this.fhInfo
.setLicense(node
.getTextContent());
819 } else if (nodeName
.equalsIgnoreCase(farHeader_Specification
)) {
820 this.fhInfo
.setSpecification(node
.getTextContent());
825 public void parseHeaderFarPackageList() {
827 NodeList ele
= this.manifestDoc
.getElementsByTagName(farPackageList
);
828 if (ele
.getLength() > 0) {
830 // For manifest file only have one <FarHeader>
832 farPkgNode
= ele
.item(0);
836 NodeList fpnList
= farPkgNode
.getChildNodes();
837 for (int i
= 0; i
< fpnList
.getLength(); i
++) {
838 if (fpnList
.item(i
).getNodeType() == Node
.TEXT_NODE
) {
841 FarPackage fpItem
= new FarPackage();
842 parseFarPackage(fpnList
.item(i
), fpItem
);
843 this.fPkgList
.add(fpItem
);
847 public void parseFarPackage(Node farPkgNode
, FarPackage fpItem
) {
848 NodeList childList
= farPkgNode
.getChildNodes();
851 for (int i
= 0; i
< childList
.getLength(); i
++) {
852 childNode
= childList
.item(i
);
853 childName
= childNode
.getNodeName();
854 if (childName
.equalsIgnoreCase(farPackage_FarfileName
)) {
855 fpItem
.setFarFile(parseFarFile(childNode
));
856 } else if (childName
.equalsIgnoreCase(guidValue
)) {
857 fpItem
.setGuidValue(childNode
.getTextContent());
858 } else if (childName
.equalsIgnoreCase(version
)) {
859 fpItem
.setVersion(childNode
.getTextContent());
860 } else if (childName
.equalsIgnoreCase(farPackage_DefaultPath
)) {
861 fpItem
.setDefaultPath(childNode
.getTextContent());
862 } else if (childName
.equalsIgnoreCase(farPlatformList
)) {
863 List
<FarPlatformItem
> plfList
= new ArrayList
<FarPlatformItem
>();
864 parseFarPlatformList(childNode
, plfList
);
865 fpItem
.setFarPlatformList(plfList
);
866 } else if (childName
.equalsIgnoreCase(contents
)) {
867 List
<FarFileItem
> ffList
= new ArrayList
<FarFileItem
>();
868 parseContents(childNode
, ffList
);
869 fpItem
.setContentList(ffList
);
879 public void parseFarPlatformList(Node fpfListNode
, List
<FarPlatformItem
> plfList
) {
881 // Get <FarPlatform> list.
883 NodeList child
= fpfListNode
.getChildNodes();
885 for (int i
= 0; i
< child
.getLength(); i
++) {
886 if (child
.item(i
).getNodeType() == Node
.TEXT_NODE
) {
889 farPlfNode
= child
.item(i
);
890 plfList
.add(parseFarPlatform(farPlfNode
));
899 public FarPlatformItem
parseFarPlatform(Node fpfNode
) {
901 // New FarPlatformItem.
903 FarPlatformItem fplItem
= new FarPlatformItem();
905 // Get <FarPlatform> elements;
907 NodeList childList
= fpfNode
.getChildNodes();
910 for (int i
= 0; i
< childList
.getLength(); i
++) {
911 child
= childList
.item(i
);
912 nodeName
= child
.getNodeName();
913 if (nodeName
.equalsIgnoreCase(farPackage_FarfileName
)) {
914 fplItem
.setFarFile(parseFarFile(child
));
915 } else if (nodeName
.equalsIgnoreCase(guidValue
)) {
916 fplItem
.setGuidValue(child
.getTextContent());
917 } else if (nodeName
.equalsIgnoreCase(version
)) {
918 fplItem
.setVersion(child
.getTextContent());
925 public void parseContents(Node contentsNode
, List
<FarFileItem
> ffList
) {
926 NodeList contentList
= contentsNode
.getChildNodes();
928 for (int i
= 0; i
< contentList
.getLength(); i
++) {
929 if (contentList
.item(i
).getNodeType() == Node
.TEXT_NODE
) {
932 contentNode
= contentList
.item(i
);
934 // Parse each <FarFileName>.
936 ffList
.add(parseFarFile(contentNode
));
940 public FarFileItem
parseFarFile(Node farFileNode
) {
941 String ffName
= farFileNode
.getTextContent();
942 NamedNodeMap attr
= farFileNode
.getAttributes();
943 FarFileItem ffItem
= new FarFileItem(ffName
, attr
.getNamedItem(farFileName_Md5sum
).getTextContent());
947 public boolean isFilter(File file
, Set
<String
> fileter
) {
948 Iterator
<String
> iter
= fileter
.iterator();
949 while (iter
.hasNext()) {
950 Pattern pattern
= Pattern
.compile(iter
.next());
951 Matcher matcher
= pattern
.matcher(file
.getName());
953 if (matcher
.find()) {