Exemplo n.º 1
0
 /**
  * Get version for the specified Firefox extension ID
  *
  * @param extensionID
  * @param profileDir
  * @return
  */
 public static String getExtensionVersion(String extensionID, IPath profileDir) {
   try {
     IPath dir = profileDir.append("extensions").append(extensionID); // $NON-NLS-1$
     InputStream rdfInputStream = null;
     if (dir.toFile().isFile()) {
       dir = Path.fromOSString(IOUtil.read(new FileInputStream(dir.toFile())));
     }
     if (dir.toFile().isDirectory()) {
       File installRdf = dir.append("install.rdf").toFile(); // $NON-NLS-1$
       if (installRdf.exists()) {
         rdfInputStream = new FileInputStream(installRdf);
       }
     } else if (dir.addFileExtension("xpi").toFile().isFile()) // $NON-NLS-1$
     {
       rdfInputStream =
           ZipUtil.openEntry(
               dir.addFileExtension("xpi").toFile(), // $NON-NLS-1$
               Path.fromPortableString("install.rdf")); // $NON-NLS-1$
     }
     if (rdfInputStream != null) {
       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
       DocumentBuilder parser = factory.newDocumentBuilder();
       Document document = parser.parse(rdfInputStream);
       Node node = document.getDocumentElement().getFirstChild();
       while (node != null) {
         if ("description".equals(node.getNodeName().toLowerCase()) // $NON-NLS-1$
             || "rdf:description".equals(node.getNodeName().toLowerCase())) { // $NON-NLS-1$
           NamedNodeMap attrs = node.getAttributes();
           Node about = attrs.getNamedItem("about"); // $NON-NLS-1$
           if (about == null) {
             about = attrs.getNamedItem("RDF:about"); // $NON-NLS-1$
           }
           if (about != null) {
             if ("urn:mozilla:install-manifest".equals(about.getNodeValue())) { // $NON-NLS-1$
               break;
             }
           }
         }
         node = node.getNextSibling();
       }
       if (node != null) {
         NamedNodeMap attrs = node.getAttributes();
         Node version = attrs.getNamedItem("em:version"); // $NON-NLS-1$
         if (version != null) {
           return version.getNodeValue();
         }
         node = node.getFirstChild();
       }
       while (node != null) {
         if ("em:version".equals(node.getNodeName().toLowerCase())) { // $NON-NLS-1$
           break;
         }
         node = node.getNextSibling();
       }
       if (node != null) {
         return node.getTextContent();
       }
     }
   } catch (Exception e) {
     IdeLog.logError(CorePlugin.getDefault(), e.getMessage(), e);
   }
   return null;
 }