Class XmlMetaReader


  • public final class XmlMetaReader
    extends java.lang.Object
    Class having utilities required to read module details from an XML metadata file of a module. This class is used by plugins that need load of metadata from XML files.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String XML_TAG_DESCRIPTION
      Description tag of metadata XML files.
      private static java.lang.String XML_TAG_NAME
      Name tag of metadata XML files.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private XmlMetaReader()
      Do no allow XmlMetaReader instances to be created.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.util.List<ModulePropertyDetails> createProperties​(org.w3c.dom.Element properties)
      Create module property details from the XML metadata.
      private static java.lang.String getAttributeValue​(org.w3c.dom.Element element, java.lang.String attribute)
      Utility to get attribute value of an element.
      private static java.util.List<org.w3c.dom.Element> getDirectChildsByTag​(org.w3c.dom.Element element, java.lang.String sTagName)
      Utility to get the children of an element by tag name.
      private static java.util.List<java.lang.String> getListContentByAttribute​(org.w3c.dom.Element element, java.lang.String listParent, java.lang.String listOption, java.lang.String attribute)
      Utility to get the list contents by the attribute specified.
      private static void populateModule​(org.w3c.dom.Element mod, ModuleDetails moduleDetails)
      Populate the module detail object from XML metadata.
      static ModuleDetails read​(java.io.InputStream moduleMetadataStream, ModuleType moduleType)
      Read the module details from the supplied input stream of the module's XML metadata file.
      static java.util.List<ModuleDetails> readAllModulesIncludingThirdPartyIfAny​(java.lang.String... thirdPartyPackages)
      Utility to load all the metadata files present in the checkstyle JAR including third parties' module metadata files.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XmlMetaReader

        private XmlMetaReader()
        Do no allow XmlMetaReader instances to be created.
    • Method Detail

      • readAllModulesIncludingThirdPartyIfAny

        public static java.util.List<ModuleDetailsreadAllModulesIncludingThirdPartyIfAny​(java.lang.String... thirdPartyPackages)
        Utility to load all the metadata files present in the checkstyle JAR including third parties' module metadata files. checkstyle metadata files are grouped in a folder hierarchy similar to that of their corresponding source files. Third party(e.g. SevNTU Checks) metadata files are prefixed with checkstylemeta- to their file names.
        Parameters:
        thirdPartyPackages - fully qualified third party package names(can be only a hint, e.g. for SevNTU it can be com.github.sevntu / com.github)
        Returns:
        list of module details found in the classpath satisfying the above conditions
        Throws:
        java.lang.IllegalStateException - if there was a problem reading the module metadata files
      • read

        public static ModuleDetails read​(java.io.InputStream moduleMetadataStream,
                                         ModuleType moduleType)
                                  throws javax.xml.parsers.ParserConfigurationException,
                                         java.io.IOException,
                                         org.xml.sax.SAXException
        Read the module details from the supplied input stream of the module's XML metadata file.
        Parameters:
        moduleMetadataStream - input stream object of a module's metadata file
        moduleType - type of module
        Returns:
        module detail object extracted from the XML metadata file
        Throws:
        javax.xml.parsers.ParserConfigurationException - if a parser configuration exception occurs
        java.io.IOException - if a IO exception occurs
        org.xml.sax.SAXException - if a SAX exception occurs during parsing the XML file
      • populateModule

        private static void populateModule​(org.w3c.dom.Element mod,
                                           ModuleDetails moduleDetails)
        Populate the module detail object from XML metadata.
        Parameters:
        mod - root XML document element
        moduleDetails - module detail object, which is to be updated
      • createProperties

        private static java.util.List<ModulePropertyDetailscreateProperties​(org.w3c.dom.Element properties)
        Create module property details from the XML metadata.
        Parameters:
        properties - parent document element which contains property's metadata
        Returns:
        list of property details object created
      • getListContentByAttribute

        private static java.util.List<java.lang.String> getListContentByAttribute​(org.w3c.dom.Element element,
                                                                                  java.lang.String listParent,
                                                                                  java.lang.String listOption,
                                                                                  java.lang.String attribute)
        Utility to get the list contents by the attribute specified.
        Parameters:
        element - doc element
        listParent - parent element of list
        listOption - child list element
        attribute - attribute key
        Returns:
        list of strings containing the XML list data
      • getDirectChildsByTag

        private static java.util.List<org.w3c.dom.Element> getDirectChildsByTag​(org.w3c.dom.Element element,
                                                                                java.lang.String sTagName)
        Utility to get the children of an element by tag name.
        Parameters:
        element - parent element
        sTagName - tag name of children required
        Returns:
        list of elements retrieved
      • getAttributeValue

        private static java.lang.String getAttributeValue​(org.w3c.dom.Element element,
                                                          java.lang.String attribute)
        Utility to get attribute value of an element.
        Parameters:
        element - target element
        attribute - attribute key
        Returns:
        attribute value