Class PackageNamesLoader

  • All Implemented Interfaces:
    org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

    public final class PackageNamesLoader
    extends XmlLoader
    Loads a list of package names from a package name XML file.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String CHECKSTYLE_PACKAGES
      Name of default checkstyle package names resource file.
      private static java.lang.String DTD_PUBLIC_CS_ID
      The new public ID for the configuration dtd.
      private static java.lang.String DTD_PUBLIC_ID
      The public ID for the configuration dtd.
      private static java.lang.String DTD_RESOURCE_NAME
      The resource for the configuration dtd.
      private static java.lang.String PACKAGE_ELEMENT_NAME
      Qualified name for element 'package'.
      private java.util.Set<java.lang.String> packageNames
      The fully qualified package names.
      private java.util.Deque<java.lang.String> packageStack
      The temporary stack of package name parts.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private PackageNamesLoader()
      Creates a new PackageNamesLoader instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.util.Map<java.lang.String,​java.lang.String> createIdToResourceNameMap()
      Creates mapping between local resources and dtd ids.
      void endElement​(java.lang.String uri, java.lang.String localName, java.lang.String qName)  
      private java.lang.String getPackageName()
      Creates a full package name from the package names on the stack.
      static java.util.Set<java.lang.String> getPackageNames​(java.lang.ClassLoader classLoader)
      Returns the set of package names, compiled from all checkstyle_packages.xml files found on the given class loaders classpath.
      private static void processFile​(java.net.URL packageFile, PackageNamesLoader namesLoader)
      Reads the file provided and parses it with package names loader.
      void startElement​(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)  
      • Methods inherited from class org.xml.sax.helpers.DefaultHandler

        characters, endDocument, endPrefixMapping, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
      • Methods inherited from class java.lang.Object

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

      • PackageNamesLoader

        private PackageNamesLoader()
                            throws javax.xml.parsers.ParserConfigurationException,
                                   org.xml.sax.SAXException
        Creates a new PackageNamesLoader instance.
        Throws:
        javax.xml.parsers.ParserConfigurationException - if an error occurs
        org.xml.sax.SAXException - if an error occurs
    • Method Detail

      • startElement

        public void startElement​(java.lang.String uri,
                                 java.lang.String localName,
                                 java.lang.String qName,
                                 org.xml.sax.Attributes attributes)
        Specified by:
        startElement in interface org.xml.sax.ContentHandler
        Overrides:
        startElement in class org.xml.sax.helpers.DefaultHandler
      • getPackageName

        private java.lang.String getPackageName()
        Creates a full package name from the package names on the stack.
        Returns:
        the full name of the current package.
      • endElement

        public void endElement​(java.lang.String uri,
                               java.lang.String localName,
                               java.lang.String qName)
        Specified by:
        endElement in interface org.xml.sax.ContentHandler
        Overrides:
        endElement in class org.xml.sax.helpers.DefaultHandler
      • getPackageNames

        public static java.util.Set<java.lang.String> getPackageNames​(java.lang.ClassLoader classLoader)
                                                               throws CheckstyleException
        Returns the set of package names, compiled from all checkstyle_packages.xml files found on the given class loaders classpath.
        Parameters:
        classLoader - the class loader for loading the checkstyle_packages.xml files.
        Returns:
        the set of package names.
        Throws:
        CheckstyleException - if an error occurs.
      • processFile

        private static void processFile​(java.net.URL packageFile,
                                        PackageNamesLoader namesLoader)
                                 throws org.xml.sax.SAXException,
                                        CheckstyleException
        Reads the file provided and parses it with package names loader.
        Parameters:
        packageFile - file from package
        namesLoader - package names loader
        Throws:
        org.xml.sax.SAXException - if an error while parsing occurs
        CheckstyleException - if unable to open file
      • createIdToResourceNameMap

        private static java.util.Map<java.lang.String,​java.lang.String> createIdToResourceNameMap()
        Creates mapping between local resources and dtd ids.
        Returns:
        map between local resources and dtd ids.