Exemplo n.º 1
0
  /**
   * Build a list of installed plugins.
   *
   * @return a list of plugin names and version numbers.
   */
  public static EventList<NameAndVersion> findInstalledPlugins() {
    EventList<NameAndVersion> plugins = new BasicEventList<NameAndVersion>();
    if (!PluginCore.userPluginDir.exists()) return plugins;
    String[] files =
        PluginCore.userPluginDir.list(
            new FilenameFilter() {
              public boolean accept(File dir, String name) {
                return name.endsWith(".jar");
              }
            });

    HashMap<String, PluginDescriptor> urls = new HashMap<String, PluginDescriptor>();
    Collection<PluginDescriptor> descriptors =
        PluginCore.getManager().getRegistry().getPluginDescriptors();
    for (PluginDescriptor desc : descriptors) {
      if ((desc.getPluginClassName() == null)
          || !desc.getPluginClassName().equals("net.sf.jabref.plugin.core.JabRefPlugin")) {
        urls.put(desc.getId(), desc);
      }
    }

    for (String file1 : files) {
      File file = new File(PluginCore.userPluginDir, file1);
      String[] nav = getNameAndVersion(file);
      if (nav != null) {
        VersionNumber vn = nav[1] != null ? new VersionNumber(nav[1]) : null;
        NameAndVersion nameAndVersion = new NameAndVersion(nav[0], vn, true, file);
        for (Iterator<String> it = urls.keySet().iterator(); it.hasNext(); ) {
          String loc = it.next();
          if (loc.contains(nav[0])) {
            PluginDescriptor desc = urls.get(loc);
            // System.out.println("Accounted for: "+desc.getId()+" "+desc.getVersion().toString());
            if (!PluginCore.getManager().isPluginEnabled(urls.get(loc)))
              nameAndVersion.setStatus(BAD);
            else nameAndVersion.setStatus(LOADED);
            it.remove();
          }
        }
        plugins.add(nameAndVersion);
      }
    }

    for (String url : urls.keySet()) {
      PluginDescriptor desc = urls.get(url);
      File location = new File(desc.getLocation().getFile());
      if (location.getPath().contains(PluginCore.userPluginDir.getPath()))
        continue; // This must be a loaded user dir plugin that's been deleted.
      // System.out.println("File: "+desc.getLocation().getFile());
      NameAndVersion nameAndVersion =
          new NameAndVersion(
              desc.getId(), new VersionNumber(desc.getVersion().toString()), false, location);
      if (!PluginCore.getManager().isPluginEnabled(urls.get(url))) nameAndVersion.setStatus(BAD);
      else nameAndVersion.setStatus(LOADED);
      plugins.add(nameAndVersion);
    }
    return plugins;
  }
  /**
   * Method to return an array list containing plugins of a certain editor type and category
   *
   * @param editorType The editor type
   * @param category The category
   * @return An array list of any plugins found
   */
  public ArrayList<ATPlugin> getEmbeddedEditorPlugins(String editorType, String category) {
    ArrayList<ATPlugin> foundPlugins = new ArrayList<ATPlugin>();

    try {
      Iterator it = pluginManager.getRegistry().getPluginDescriptors().iterator();

      while (it.hasNext()) {
        PluginDescriptor pluginDescriptor = (PluginDescriptor) it.next();
        String id = pluginDescriptor.getId();
        ATPlugin plugin = (org.archiviststoolkit.plugin.ATPlugin) pluginManager.getPlugin(id);

        String cat = plugin.getCategory();
        String et = plugin.getEditorType();

        // check to make sure that the plugin is of the right category and
        // editor type and that it has a panel that can be embedded into
        // the resource editor panel
        if (cat.indexOf(category) != -1
            && et.indexOf(editorType) != -1
            && plugin.getEmbeddedPanels() != null) {
          foundPlugins.add(plugin);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return foundPlugins;
  }
  /**
   * Method to return the ATPlugin for a particular and domain object
   *
   * @param domainObject The domain object to find a plugin for
   * @param category The category to find a domain object for
   * @return The plugin found or null if none can be located.
   */
  private ATPlugin getATPlugin(DomainObject domainObject, String category) {
    String editorType = getEditorTypeForDomainObject(domainObject);

    if (editorType != null) {
      ATPlugin foundPlugin = null;

      try {
        Iterator it = pluginManager.getRegistry().getPluginDescriptors().iterator();

        while (it.hasNext()) {
          PluginDescriptor pluginDescriptor = (PluginDescriptor) it.next();
          String id = pluginDescriptor.getId();
          ATPlugin plugin = (org.archiviststoolkit.plugin.ATPlugin) pluginManager.getPlugin(id);

          String cat = plugin.getCategory();
          String et = plugin.getEditorType();

          if (cat.indexOf(category) != -1 && et.indexOf(editorType) != -1) {
            foundPlugin = plugin;
            break;
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      return foundPlugin;
    } else {
      return null;
    }
  }
  /**
   * Method to return the name of all plugins in a particular category. It is used to add plugins to
   * plugin menu in the main application frame
   *
   * @return HashMap containing the names and ids of all the plugins found
   */
  public HashMap getPluginNamesByCategory(String inCategory) {
    HashMap<String, String> pluginNames = new HashMap<String, String>();

    try {
      Iterator it = pluginManager.getRegistry().getPluginDescriptors().iterator();

      while (it.hasNext()) {
        PluginDescriptor pluginDescriptor = (PluginDescriptor) it.next();
        String id = pluginDescriptor.getId();
        ATPlugin plugin = (org.archiviststoolkit.plugin.ATPlugin) pluginManager.getPlugin(id);
        String name = plugin.getName();
        String category = plugin.getCategory();
        if (category.indexOf(inCategory) != -1) {
          if (plugin.getTaskList() == null) { // no list of task so just return the id and name
            pluginNames.put(id, name);
          } else { // list of task so return the name::task1::task2::task3 etc ...
            String nameWithTask = getNameWithTask(name, plugin.getTaskList());
            pluginNames.put(id, nameWithTask);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (pluginNames.size() == 0) {
      return null; // no plugins in this category so return null
    } else {
      return pluginNames;
    }
  }
  /**
   * Method to return an list of all the plugin names and ids in a hasmap
   *
   * @return HashMap containing the names and ids of all the plugins found
   */
  public HashMap getPluginNames() {
    HashMap<String, String> pluginNames = new HashMap<String, String>();

    try {
      Iterator it = pluginManager.getRegistry().getPluginDescriptors().iterator();

      while (it.hasNext()) {
        PluginDescriptor pluginDescriptor = (PluginDescriptor) it.next();
        String id = pluginDescriptor.getId();
        ATPlugin plugin = (org.archiviststoolkit.plugin.ATPlugin) pluginManager.getPlugin(id);
        String name = plugin.getName();
        pluginNames.put(id, name);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (pluginNames.size() == 0) {
      return null; // no plugins found so return null
    } else {
      return pluginNames;
    }
  }
Exemplo n.º 6
0
 public void drawWindow() {
   HashSet<SettingsExtension> set = new HashSet<SettingsExtension>();
   try {
     for (Extension e : ext.getAvailableExtensions()) {
       PluginDescriptor pd = e.getDeclaringPluginDescriptor();
       // if(manager.isPluginActivated(pd)){
       Plugin plugin = manager.getPlugin(pd.getId());
       if (plugin instanceof SettingsExtension) {
         set.add((SettingsExtension) plugin);
       }
       // }
     }
   } catch (PluginLifecycleException x) {
     x.printStackTrace();
   }
   set.add(new NTorrentPlugins());
   SettingsExtension[] array = new SettingsExtension[set.size()];
   set.toArray(array);
   SettingsWindow window = new SettingsWindow(array);
   window.validate();
   window.pack();
   window.setSize(640, 480);
   window.setVisible(true);
 }