Class XmlDescriptorParser

java.lang.Object
com.atlassian.plugin.internal.parsers.XmlDescriptorParser
All Implemented Interfaces:
DescriptorParser

public class XmlDescriptorParser extends Object implements DescriptorParser
Provides access to the descriptor information retrieved from an XML InputStream.

Uses the dom4j SAXReader to parse the XML stream into a document when the parser is constructed.

See Also:
  • Constructor Details

    • XmlDescriptorParser

      public XmlDescriptorParser(org.dom4j.Document source, Set<Application> applications)
      Constructs a parser with an already-constructed document
      Parameters:
      source - the source document
      applications - the application key to filter modules with, null for all unspecified
      Throws:
      PluginParseException - if there is a problem reading the descriptor from the XML InputStream.
      Since:
      2.2.0
    • XmlDescriptorParser

      public XmlDescriptorParser(InputStream source, Set<Application> applications)
      Constructs a parser with a stream of an XML document for a specific application
      Parameters:
      source - The descriptor stream
      applications - the application key to filter modules with, null for all unspecified
      Throws:
      PluginParseException - if there is a problem reading the descriptor from the XML InputStream.
      Since:
      2.2.0
    • XmlDescriptorParser

      public XmlDescriptorParser(InputStream source, Iterable<InputStream> supplementalSources, Set<Application> applications)
      Constructs a parser with a stream of an XML document for a specific application
      Parameters:
      source - The descriptor stream
      supplementalSources - a collection of streams containing supplemental ModuleDescriptors
      applications - the application key to filter modules with, null for all unspecified
      Throws:
      PluginParseException - if there is a problem reading the descriptor from the XML InputStream.
      Since:
      3.2.16
  • Method Details

    • createDocument

      protected static org.dom4j.Document createDocument(InputStream source)
    • mergeDocuments

      protected static org.dom4j.Document mergeDocuments(org.dom4j.Document mainDocument, Iterable<org.dom4j.Document> supplementalDocuments)
    • getDocument

      protected org.dom4j.Document getDocument()
    • configurePlugin

      public Plugin configurePlugin(ModuleDescriptorFactory moduleDescriptorFactory, Plugin plugin)
      Description copied from interface: DescriptorParser
      Sets the configuration on the plugin argument to match the configuration specified in the plugin descriptor (typically an XML file).
      Specified by:
      configurePlugin in interface DescriptorParser
      Parameters:
      moduleDescriptorFactory - a factory for instantiating the required plugin modules
      plugin - the plugin whose configuration will be modified
      Returns:
      the original plugin with the configuration changed and the module descriptors added
    • addModule

      public ModuleDescriptor<?> addModule(ModuleDescriptorFactory moduleDescriptorFactory, Plugin plugin, Element module)
      Description copied from interface: DescriptorParser
      Create a new module and createElement it with the plugin, then return it.

      In the event of a problem loading the module, return an UnrecognisedModuleDescriptor with error.

      Specified by:
      addModule in interface DescriptorParser
      Parameters:
      moduleDescriptorFactory - basic factory, may be overridden
      plugin - that the module will be initialised with
      module - to create
    • parseChildModulesFromSource

      public List<Element> parseChildModulesFromSource()
      Description copied from interface: DescriptorParser
      Retrieves the Elements representing the modules from the input source (plugin descriptor file snippet). Does not instantiate or validate that the returned Elements represent valid modules.

      Eg. For a snippet such as:

       <root-element>
           <module1 key=""/>
           <module2 key=""><otherModules/></module2>
       </root-element>
       
      The elements returned will be the module1 and module2 elements.
      Specified by:
      parseChildModulesFromSource in interface DescriptorParser
    • createModuleDescriptor

      protected ModuleDescriptor<?> createModuleDescriptor(Plugin plugin, Element element, ModuleDescriptorFactory moduleDescriptorFactory)
    • createPluginInformation

      protected PluginInformation createPluginInformation()
    • getKey

      public String getKey()
      Specified by:
      getKey in interface DescriptorParser
      Returns:
      the key of the plugin specified in the descriptor
    • getPluginsVersion

      public int getPluginsVersion()
      Specified by:
      getPluginsVersion in interface DescriptorParser
      Returns:
      The version of the plugin system expected by this plugin. If unknown, it is assumed to be 1.
    • getPluginInformation

      public PluginInformation getPluginInformation()
      Specified by:
      getPluginInformation in interface DescriptorParser
    • isSystemPlugin

      public boolean isSystemPlugin()
      Specified by:
      isSystemPlugin in interface DescriptorParser
      Returns:
      true if this plugin is marked as a system plugin in the descriptor. This should only be acted on by plugin loaders which can trust their plugins implicitly (e.g. a classpath plugin loader).