Class ImportControlLoader
java.lang.Object
org.xml.sax.helpers.DefaultHandler
com.puppycrawl.tools.checkstyle.XmlLoader
com.puppycrawl.tools.checkstyle.checks.imports.ImportControlLoader
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
Responsible for loading the contents of an import control configuration file.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.XmlLoader
XmlLoader.LoadExternalDtdFeatureProvider
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final String
Qualified name for element 'allow'.private static final String
The new public ID for version 1_0 of the configuration dtd.private static final String
The new public ID for version 1_1 of the configuration dtd.private static final String
The new public ID for version 1_2 of the configuration dtd.private static final String
The new public ID for version 1_3 of the configuration dtd.private static final String
The new public ID for version 1_4 of the configuration dtd.private static final String
The public ID for the configuration dtd.private static final String
The public ID for the configuration dtd.private static final String
The public ID for the configuration dtd.private static final String
The public ID for the configuration dtd.private static final String
The public ID for the configuration dtd.The map to look up the resource name by the id.private static final String
The resource for the configuration dtd.private static final String
The resource for the configuration dtd.private static final String
The resource for the configuration dtd.private static final String
The resource for the configuration dtd.private static final String
The resource for the configuration dtd.private static final String
Qualified name for element 'file'.private static final String
Name for attribute 'name'.private static final String
Name for attribute 'pkg'.private final Deque<AbstractImportControl>
Used to hold theAbstractImportControl
objects.private static final String
Value "allowed" for attribute 'strategyOnMismatch'.private static final String
Name for attribute 'strategyOnMismatch'.private static final String
Value "disallowed" for attribute 'strategyOnMismatch'.private static final String
Qualified name for element 'subpackage'. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
containsRegexAttribute
(Attributes attributes) Check if the given attributes contain the regex attribute.private static AbstractImportRule
createImportRule
(String qName, Attributes attributes) Constructs an instance of an import rule based on the givenname
andattributes
.void
endElement
(String namespaceUri, String localName, String qName) private PkgImportControl
getRoot()
Returns root PkgImportControl.private static MismatchStrategy
getStrategyForImportControl
(Attributes attributes) Utility to get a strategyOnMismatch property for "import-control" tag.private static MismatchStrategy
getStrategyForSubpackage
(Attributes attributes) Utility to get a strategyOnMismatch property for "subpackage" tag.static PkgImportControl
Loads the import control file from a file.private static PkgImportControl
load
(InputSource source, URI uri) Loads the import control file from aInputSource
.private static PkgImportControl
Loads the import control file from a URI.private static String
safeGet
(Attributes attributes, String name) Utility to safely get an attribute.void
startElement
(String namespaceUri, String localName, String qName, Attributes attributes) Methods inherited from class com.puppycrawl.tools.checkstyle.XmlLoader
error, parseInputSource, resolveEntity
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endPrefixMapping, fatalError, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
-
Field Details
-
DTD_PUBLIC_ID_1_0
The public ID for the configuration dtd.- See Also:
-
DTD_PUBLIC_CS_ID_1_0
The new public ID for version 1_0 of the configuration dtd.- See Also:
-
DTD_PUBLIC_ID_1_1
The public ID for the configuration dtd.- See Also:
-
DTD_PUBLIC_CS_ID_1_1
The new public ID for version 1_1 of the configuration dtd.- See Also:
-
DTD_PUBLIC_ID_1_2
The public ID for the configuration dtd.- See Also:
-
DTD_PUBLIC_CS_ID_1_2
The new public ID for version 1_2 of the configuration dtd.- See Also:
-
DTD_PUBLIC_ID_1_3
The public ID for the configuration dtd.- See Also:
-
DTD_PUBLIC_CS_ID_1_3
The new public ID for version 1_3 of the configuration dtd.- See Also:
-
DTD_PUBLIC_ID_1_4
The public ID for the configuration dtd.- See Also:
-
DTD_PUBLIC_CS_ID_1_4
The new public ID for version 1_4 of the configuration dtd.- See Also:
-
DTD_RESOURCE_NAME_1_0
The resource for the configuration dtd.- See Also:
-
DTD_RESOURCE_NAME_1_1
The resource for the configuration dtd.- See Also:
-
DTD_RESOURCE_NAME_1_2
The resource for the configuration dtd.- See Also:
-
DTD_RESOURCE_NAME_1_3
The resource for the configuration dtd.- See Also:
-
DTD_RESOURCE_NAME_1_4
The resource for the configuration dtd.- See Also:
-
DTD_RESOURCE_BY_ID
The map to look up the resource name by the id. -
PKG_ATTRIBUTE_NAME
Name for attribute 'pkg'.- See Also:
-
NAME_ATTRIBUTE_NAME
Name for attribute 'name'.- See Also:
-
STRATEGY_ON_MISMATCH_ATTRIBUTE_NAME
Name for attribute 'strategyOnMismatch'.- See Also:
-
STRATEGY_ON_MISMATCH_ALLOWED_VALUE
Value "allowed" for attribute 'strategyOnMismatch'.- See Also:
-
STRATEGY_ON_MISMATCH_DISALLOWED_VALUE
Value "disallowed" for attribute 'strategyOnMismatch'.- See Also:
-
SUBPACKAGE_ELEMENT_NAME
Qualified name for element 'subpackage'.- See Also:
-
FILE_ELEMENT_NAME
Qualified name for element 'file'.- See Also:
-
ALLOW_ELEMENT_NAME
Qualified name for element 'allow'.- See Also:
-
stack
Used to hold theAbstractImportControl
objects.
-
-
Constructor Details
-
ImportControlLoader
Constructs an instance.- Throws:
ParserConfigurationException
- if an error occurs.SAXException
- if an error occurs.
-
-
Method Details
-
startElement
public void startElement(String namespaceUri, String localName, String qName, Attributes attributes) throws SAXException - Specified by:
startElement
in interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
-
createImportRule
private static AbstractImportRule createImportRule(String qName, Attributes attributes) throws SAXException Constructs an instance of an import rule based on the givenname
andattributes
.- Parameters:
qName
- The qualified name.attributes
- The attributes attached to the element.- Returns:
- The created import rule.
- Throws:
SAXException
- if an error occurs.
-
containsRegexAttribute
Check if the given attributes contain the regex attribute.- Parameters:
attributes
- the attributes.- Returns:
- if the regex attribute is contained.
-
endElement
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
-
load
Loads the import control file from a file.- Parameters:
uri
- the uri of the file to load.- Returns:
- the root
PkgImportControl
object. - Throws:
CheckstyleException
- if an error occurs.
-
load
Loads the import control file from aInputSource
.- Parameters:
source
- the source to load from.uri
- uri of the source being loaded.- Returns:
- the root
PkgImportControl
object. - Throws:
CheckstyleException
- if an error occurs.
-
loadUri
Loads the import control file from a URI.- Parameters:
uri
- the uri of the file to load.- Returns:
- the root
PkgImportControl
object. - Throws:
CheckstyleException
- if an error occurs.
-
getRoot
Returns root PkgImportControl.- Returns:
- the root
PkgImportControl
object loaded.
-
getStrategyForImportControl
Utility to get a strategyOnMismatch property for "import-control" tag.- Parameters:
attributes
- collect to get attribute from.- Returns:
- the value of the attribute.
-
getStrategyForSubpackage
Utility to get a strategyOnMismatch property for "subpackage" tag.- Parameters:
attributes
- collect to get attribute from.- Returns:
- the value of the attribute.
-
safeGet
Utility to safely get an attribute. If it does not exist an exception is thrown.- Parameters:
attributes
- collect to get attribute from.name
- name of the attribute to get.- Returns:
- the value of the attribute.
- Throws:
SAXException
- if the attribute does not exist.
-