home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / AIMP2 / aimp_2.61.583.exe / $TEMP / YandexPackSetup.msi / filDFB8D069BB0C3F726985645BE0C24FC4 < prev    next >
Text File  |  2010-07-12  |  3KB  |  87 lines

  1. /*
  2.     XB package manifest.
  3. */
  4.  
  5. XB.PackageManifest = function XBPkgMan_constructor(srcURL, XMLDocOrFile) {
  6.     if (!sysutils.isString(srcURL))
  7.         throw new CustomErrors.EArgType("srcURL", "String", typeof srcURL);
  8.     this._packageID = srcURL;
  9.     this._files = [];
  10.     if (XMLDocOrFile instanceof Ci.nsIFile)
  11.         this._loadFromFile(XMLDocOrFile);
  12.     else if (XMLDocOrFile instanceof Ci.nsIDOMDocument)
  13.         this._loadFromDocument(XMLDocOrFile);
  14.     else
  15.         throw new CustomErrors.EArgType("XMLDocOrFile", "nsIDOMDocument | nsIFile", typeof XMLDocOrFile);
  16. };
  17.  
  18. XB.PackageManifest.EPacManifestSyntax = CustomErrors.ECustom.extend({
  19.     $name: "EPacManifestSyntax",
  20.     
  21.     constructor: function EPacManifestSyntax_constructor(elementName) {
  22.         this.base("Package manifest parse error");
  23.         this._elementName = elementName.toString();
  24.     },
  25.     
  26.     get _details() {
  27.         return [this._elementName];
  28.     },
  29.     
  30.     _elementName: undefined
  31. });
  32.  
  33. XB.PackageManifest.prototype = {
  34.     constructor: XB.PackageManifest,
  35.     
  36.     get packageID() {
  37.         return this._packageID;
  38.     },
  39.     
  40.     get id() {
  41.         return this._packageID;
  42.     },
  43.     
  44.     get packagesInfo() {
  45.         var result = [];
  46.         for each (let packageInfo in this._files) {
  47.             result.push(sysutils.copyObj(packageInfo));
  48.         }
  49.         return result;
  50.     },
  51.     
  52.     _packageID: undefined,
  53.     _files: null,
  54.     
  55.     _loadFromFile: function(file) {
  56.         this._loadFromDocument(sysutils.xmlDocFromFile(file));
  57.     },
  58.     
  59.     _loadFromDocument: function XBPkgMan_loadFromDocument(document) {
  60.         var root = document.documentElement;
  61.         if (root.localName !== "manifest")
  62.             throw new XB.PackageManifest.EPacManifestSyntax(root.nodeName);
  63.         
  64.         var children = root.childNodes;
  65.         for (let i = 0, length = children.length; i < length; i++) {
  66.             let packageElement = children[i];
  67.             if ((packageElement.nodeType != packageElement.ELEMENT_NODE) || (packageElement.localName !== "package"))
  68.                 continue;
  69.             
  70.             let versionMin = parseInt( packageElement.getAttribute("platform-min"), 10 );
  71.             if (isNaN(versionMin))
  72.                 throw new XB.PackageManifest.EPacManifestSyntax(packageElement.nodeName);
  73.             
  74.             let packageVersion = packageElement.getAttribute("version") || "1";
  75.             packageInfo = {
  76.                 id: this._packageID,
  77.                 uri: this._packageID,
  78.                 version: packageVersion,
  79.                 fileURL: packageElement.getAttribute("url"),
  80.                 platformMin: versionMin
  81.             };
  82.             
  83.             this._files.push(packageInfo);
  84.         }
  85.     }
  86. };
  87.