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
public final class ImportControlLoader extends XmlLoader
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
Fields Modifier and Type Field Description private static String
ALLOW_ELEMENT_NAME
Qualified name for element 'allow'.private static String
DTD_PUBLIC_CS_ID_1_0
The new public ID for version 1_0 of the configuration dtd.private static String
DTD_PUBLIC_CS_ID_1_1
The new public ID for version 1_1 of the configuration dtd.private static String
DTD_PUBLIC_CS_ID_1_2
The new public ID for version 1_2 of the configuration dtd.private static String
DTD_PUBLIC_CS_ID_1_3
The new public ID for version 1_3 of the configuration dtd.private static String
DTD_PUBLIC_CS_ID_1_4
The new public ID for version 1_4 of the configuration dtd.private static String
DTD_PUBLIC_ID_1_0
The public ID for the configuration dtd.private static String
DTD_PUBLIC_ID_1_1
The public ID for the configuration dtd.private static String
DTD_PUBLIC_ID_1_2
The public ID for the configuration dtd.private static String
DTD_PUBLIC_ID_1_3
The public ID for the configuration dtd.private static String
DTD_PUBLIC_ID_1_4
The public ID for the configuration dtd.private static Map<String,String>
DTD_RESOURCE_BY_ID
The map to look up the resource name by the id.private static String
DTD_RESOURCE_NAME_1_0
The resource for the configuration dtd.private static String
DTD_RESOURCE_NAME_1_1
The resource for the configuration dtd.private static String
DTD_RESOURCE_NAME_1_2
The resource for the configuration dtd.private static String
DTD_RESOURCE_NAME_1_3
The resource for the configuration dtd.private static String
DTD_RESOURCE_NAME_1_4
The resource for the configuration dtd.private static String
FILE_ELEMENT_NAME
Qualified name for element 'file'.private static String
NAME_ATTRIBUTE_NAME
Name for attribute 'name'.private static String
PKG_ATTRIBUTE_NAME
Name for attribute 'pkg'.private Deque<AbstractImportControl>
stack
Used to hold theAbstractImportControl
objects.private static String
STRATEGY_ON_MISMATCH_ALLOWED_VALUE
Value "allowed" for attribute 'strategyOnMismatch'.private static String
STRATEGY_ON_MISMATCH_ATTRIBUTE_NAME
Name for attribute 'strategyOnMismatch'.private static String
STRATEGY_ON_MISMATCH_DISALLOWED_VALUE
Value "disallowed" for attribute 'strategyOnMismatch'.private static String
SUBPACKAGE_ELEMENT_NAME
Qualified name for element 'subpackage'.
-
Constructor Summary
Constructors Modifier Constructor Description private
ImportControlLoader()
Constructs an instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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
load(URI uri)
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
loadUri(URI uri)
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 Detail
-
DTD_PUBLIC_ID_1_0
private static final String DTD_PUBLIC_ID_1_0
The public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_0
private static final String DTD_PUBLIC_CS_ID_1_0
The new public ID for version 1_0 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_ID_1_1
private static final String DTD_PUBLIC_ID_1_1
The public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_1
private static final String DTD_PUBLIC_CS_ID_1_1
The new public ID for version 1_1 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_ID_1_2
private static final String DTD_PUBLIC_ID_1_2
The public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_2
private static final String DTD_PUBLIC_CS_ID_1_2
The new public ID for version 1_2 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_ID_1_3
private static final String DTD_PUBLIC_ID_1_3
The public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_3
private static final String DTD_PUBLIC_CS_ID_1_3
The new public ID for version 1_3 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_ID_1_4
private static final String DTD_PUBLIC_ID_1_4
The public ID for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_PUBLIC_CS_ID_1_4
private static final String DTD_PUBLIC_CS_ID_1_4
The new public ID for version 1_4 of the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_NAME_1_0
private static final String DTD_RESOURCE_NAME_1_0
The resource for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_NAME_1_1
private static final String DTD_RESOURCE_NAME_1_1
The resource for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_NAME_1_2
private static final String DTD_RESOURCE_NAME_1_2
The resource for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_NAME_1_3
private static final String DTD_RESOURCE_NAME_1_3
The resource for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_NAME_1_4
private static final String DTD_RESOURCE_NAME_1_4
The resource for the configuration dtd.- See Also:
- Constant Field Values
-
DTD_RESOURCE_BY_ID
private static final Map<String,String> DTD_RESOURCE_BY_ID
The map to look up the resource name by the id.
-
PKG_ATTRIBUTE_NAME
private static final String PKG_ATTRIBUTE_NAME
Name for attribute 'pkg'.- See Also:
- Constant Field Values
-
NAME_ATTRIBUTE_NAME
private static final String NAME_ATTRIBUTE_NAME
Name for attribute 'name'.- See Also:
- Constant Field Values
-
STRATEGY_ON_MISMATCH_ATTRIBUTE_NAME
private static final String STRATEGY_ON_MISMATCH_ATTRIBUTE_NAME
Name for attribute 'strategyOnMismatch'.- See Also:
- Constant Field Values
-
STRATEGY_ON_MISMATCH_ALLOWED_VALUE
private static final String STRATEGY_ON_MISMATCH_ALLOWED_VALUE
Value "allowed" for attribute 'strategyOnMismatch'.- See Also:
- Constant Field Values
-
STRATEGY_ON_MISMATCH_DISALLOWED_VALUE
private static final String STRATEGY_ON_MISMATCH_DISALLOWED_VALUE
Value "disallowed" for attribute 'strategyOnMismatch'.- See Also:
- Constant Field Values
-
SUBPACKAGE_ELEMENT_NAME
private static final String SUBPACKAGE_ELEMENT_NAME
Qualified name for element 'subpackage'.- See Also:
- Constant Field Values
-
FILE_ELEMENT_NAME
private static final String FILE_ELEMENT_NAME
Qualified name for element 'file'.- See Also:
- Constant Field Values
-
ALLOW_ELEMENT_NAME
private static final String ALLOW_ELEMENT_NAME
Qualified name for element 'allow'.- See Also:
- Constant Field Values
-
stack
private final Deque<AbstractImportControl> stack
Used to hold theAbstractImportControl
objects.
-
-
Constructor Detail
-
ImportControlLoader
private ImportControlLoader() throws ParserConfigurationException, SAXException
Constructs an instance.- Throws:
ParserConfigurationException
- if an error occurs.SAXException
- if an error occurs.
-
-
Method Detail
-
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
private static boolean containsRegexAttribute(Attributes attributes)
Check if the given attributes contain the regex attribute.- Parameters:
attributes
- the attributes.- Returns:
- if the regex attribute is contained.
-
endElement
public void endElement(String namespaceUri, String localName, String qName)
- Specified by:
endElement
in interfaceContentHandler
- Overrides:
endElement
in classDefaultHandler
-
load
public static PkgImportControl load(URI uri) throws CheckstyleException
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
private static PkgImportControl load(InputSource source, URI uri) throws CheckstyleException
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
private static PkgImportControl loadUri(URI uri) throws CheckstyleException
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
private PkgImportControl getRoot()
Returns root PkgImportControl.- Returns:
- the root
PkgImportControl
object loaded.
-
getStrategyForImportControl
private static MismatchStrategy getStrategyForImportControl(Attributes attributes)
Utility to get a strategyOnMismatch property for "import-control" tag.- Parameters:
attributes
- collect to get attribute from.- Returns:
- the value of the attribute.
-
getStrategyForSubpackage
private static MismatchStrategy getStrategyForSubpackage(Attributes attributes)
Utility to get a strategyOnMismatch property for "subpackage" tag.- Parameters:
attributes
- collect to get attribute from.- Returns:
- the value of the attribute.
-
safeGet
private static String safeGet(Attributes attributes, String name) throws SAXException
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.
-
-