View Javadoc

1   package com.atlassian.plugin.osgi.factory;
2   
3   import com.atlassian.plugin.parsers.XmlDescriptorParser;
4   import com.atlassian.plugin.PluginParseException;
5   import com.atlassian.plugin.ModuleDescriptor;
6   import com.atlassian.plugin.Plugin;
7   import com.atlassian.plugin.ModuleDescriptorFactory;
8   
9   import java.io.InputStream;
10  import java.util.HashSet;
11  import java.util.Arrays;
12  
13  import org.dom4j.Element;
14  
15  /**
16   * Descriptor parser that ignores certain modules
17   */
18  public class FilteringXmlDescriptorParser extends XmlDescriptorParser
19  {
20      private HashSet<String> modulesToIgnore;
21  
22      /**
23       * @throws com.atlassian.plugin.PluginParseException
24       *          if there is a problem reading the descriptor from the XML {@link java.io.InputStream}.
25       */
26      public FilteringXmlDescriptorParser(InputStream source, String... modulesToIgnore) throws PluginParseException
27      {
28          super(source);
29          this.modulesToIgnore = new HashSet<String>(Arrays.asList(modulesToIgnore));
30      }
31  
32      /**
33       * Ignores matched modules, otherwise, the normal behavior occurs
34       * @param plugin The plugin
35       * @param element The module element
36       * @param moduleDescriptorFactory The module descriptor factory
37       * @return The module, or null if the module cannot be found or is being ignored
38       * @throws PluginParseException
39       */
40      @Override
41      protected ModuleDescriptor createModuleDescriptor(Plugin plugin, Element element, ModuleDescriptorFactory moduleDescriptorFactory) throws PluginParseException
42      {
43          if (!modulesToIgnore.contains(element.getName()))
44          {
45              return super.createModuleDescriptor(plugin, element, moduleDescriptorFactory);
46          } else
47          {
48              return null;
49          }
50      }
51  }