Class PackageNamesLoader

All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

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

    • DTD_PUBLIC_ID

      private static final String DTD_PUBLIC_ID
      The public ID for the configuration dtd.
      See Also:
    • DTD_PUBLIC_CS_ID

      private static final String DTD_PUBLIC_CS_ID
      The new public ID for the configuration dtd.
      See Also:
    • DTD_RESOURCE_NAME

      private static final String DTD_RESOURCE_NAME
      The resource for the configuration dtd.
      See Also:
    • CHECKSTYLE_PACKAGES

      private static final String CHECKSTYLE_PACKAGES
      Name of default checkstyle package names resource file. The file must be in the classpath.
      See Also:
    • PACKAGE_ELEMENT_NAME

      private static final String PACKAGE_ELEMENT_NAME
      Qualified name for element 'package'.
      See Also:
    • packageStack

      private final Deque<String> packageStack
      The temporary stack of package name parts.
    • packageNames

      private final Set<String> packageNames
      The fully qualified package names.
  • Constructor Details

  • Method Details

    • startElement

      public void startElement(String uri, String localName, String qName, Attributes attributes)
      Specified by:
      startElement in interface ContentHandler
      Overrides:
      startElement in class DefaultHandler
    • getPackageName

      private 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(String uri, String localName, String qName)
      Specified by:
      endElement in interface ContentHandler
      Overrides:
      endElement in class DefaultHandler
    • getPackageNames

      public static Set<String> getPackageNames(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(URL packageFile, PackageNamesLoader namesLoader) throws SAXException, CheckstyleException
      Reads the file provided and parses it with package names loader.
      Parameters:
      packageFile - file from package
      namesLoader - package names loader
      Throws:
      SAXException - if an error while parsing occurs
      CheckstyleException - if unable to open file
    • createIdToResourceNameMap

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