Top Description Inners Fields Constructors Methods
org.testng.xml

public Class TestNGContentHandler

extends DefaultHandler
Class Inheritance
Static Imports
org.testng.internal.Utils.isStringBlank

Suite definition parser utility.
Authors
Cedric Beust, Alexandru Popescu

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv static enum

Field Summary

Modifier and TypeField and Description
private boolean
private XmlClass
private List<XmlClass>
private int
private Map<String, String>
private XmlDefine
private List<String>
private String
private XmlGroups
private TestNGContentHandler.Include
private ArrayList<XmlInclude>
private int
private String
private XmlPackage
private List<XmlPackage>
private XmlRun
private XmlMethodSelector
private ArrayList<XmlMethodSelector>
private XmlSuite
private Map<String, String>
private XmlTest
private int
private Map<String, String>
private boolean
private final String
private boolean
private List<String>
private final boolean
private final Stack<TestNGContentHandler.Location>
private final EntityResolver
private final List<String>
private final List<XmlSuite>
private boolean

Constructor Summary

AccessConstructor and Description
public
TestNGContentHandler(String fileName, boolean loadClasses)

Method Summary

Modifier and TypeMethod and Description
private boolean
areWhiteSpaces(char[] ch, int start, int length)

public void
characters(char[]
The characters.
ch
,
int
The start position in the character array.
start
,
int
The number of characters to use from the character array.
length
)

Overrides org.xml.sax.helpers.DefaultHandler.characters.

Implements org.xml.sax.ContentHandler.characters.

Receive notification of character data inside an element.
public void
endElement(String
The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
uri
,
String
The local name (without prefix), or the empty string if Namespace processing is not being performed.
localName
,
String
The qualified name (with prefix), or the empty string if qualified names are not available.
qName
)

Overrides org.xml.sax.helpers.DefaultHandler.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Receive notification of the end of an element.
public void
error(SAXParseException
The error information encoded as an exception.
e
)

Overrides org.xml.sax.helpers.DefaultHandler.error.

Implements org.xml.sax.ErrorHandler.error.

Receive notification of a recoverable parser error.
private static String
public XmlSuite
private static boolean
private static boolean
private InputStream
private void
private void
public InputSource
resolveEntity(String
The public identifier, or null if none is available.
publicId
,
String
The system identifier provided in the XML document.
systemId
)

Overrides org.xml.sax.helpers.DefaultHandler.resolveEntity.

Implements org.xml.sax.EntityResolver.resolveEntity.

Resolve an external entity.
private static boolean
public void
startElement(String
The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
uri
,
String
The local name (without prefix), or the empty string if Namespace processing is not being performed.
localName
,
String
The qualified name (with prefix), or the empty string if qualified names are not available.
qName
,
Attributes
The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
attributes
)

Overrides org.xml.sax.helpers.DefaultHandler.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Note

I only invoke xml*methods (e.g. xmlSuite()) if I am acting on both the start and the end of the tag.

private List<Integer>
private static void
public void
xmlClasses(boolean start)

private void
xmlDefine(boolean start, Attributes attributes)

Parse <define>

private void
xmlExclude(boolean start, Attributes attributes)

public void
xmlGroup(boolean start, Attributes attributes)

public void
xmlGroups(boolean start)

private void
xmlInclude(boolean start, Attributes attributes)

public void
xmlListener(boolean start, Attributes attributes)

public void
xmlListeners(boolean start)

private void
xmlMethod(boolean start)

public void
xmlMethodSelector(boolean start)

public void
xmlMethodSelectors(boolean start)

public void
xmlPackages(boolean start)

public void
xmlRun(boolean start)

private void
xmlScript(boolean start, Attributes attributes)

Parse <script>

public void
xmlSelectorClass(boolean start, Attributes attributes)

private void
xmlSuite(boolean start, Attributes attributes)

Parse <suite>

private void
xmlSuiteFile(boolean start, Attributes attributes)

Parse <suite-file>

private void
xmlTest(boolean start, Attributes attributes)

Parse <test>

Inherited from org.xml.sax.helpers.DefaultHandler:
endDocumentendPrefixMappingfatalErrorignorableWhitespacenotationDeclprocessingInstructionsetDocumentLocatorskippedEntitystartDocumentstartPrefixMappingunparsedEntityDeclwarning

Field Detail

isSuiteFileTagback to summary
private boolean isSuiteFileTag
m_currentClassback to summary
private XmlClass m_currentClass
m_currentClassesback to summary
private List<XmlClass> m_currentClasses
m_currentClassIndexback to summary
private int m_currentClassIndex
m_currentClassParametersback to summary
private Map<String, String> m_currentClassParameters
m_currentDefineback to summary
private XmlDefine m_currentDefine
m_currentExcludedMethodsback to summary
private List<String> m_currentExcludedMethods
m_currentExpressionback to summary
private String m_currentExpression
m_currentGroupsback to summary
private XmlGroups m_currentGroups
m_currentIncludeback to summary
private TestNGContentHandler.Include m_currentInclude
m_currentIncludedMethodsback to summary
private ArrayList<XmlInclude> m_currentIncludedMethods
m_currentIncludeIndexback to summary
private int m_currentIncludeIndex
m_currentLanguageback to summary
private String m_currentLanguage
m_currentPackageback to summary
private XmlPackage m_currentPackage
m_currentPackagesback to summary
private List<XmlPackage> m_currentPackages
m_currentRunback to summary
private XmlRun m_currentRun
m_currentSelectorback to summary
private XmlMethodSelector m_currentSelector
m_currentSelectorsback to summary
private ArrayList<XmlMethodSelector> m_currentSelectors
m_currentSuiteback to summary
private XmlSuite m_currentSuite
m_currentSuiteParametersback to summary
private Map<String, String> m_currentSuiteParameters
m_currentTestback to summary
private XmlTest m_currentTest
m_currentTestIndexback to summary
private int m_currentTestIndex
m_currentTestParametersback to summary
private Map<String, String> m_currentTestParameters
m_enabledTestback to summary
private boolean m_enabledTest
m_fileNameback to summary
private final String m_fileName
m_hasWarnback to summary
private boolean m_hasWarn
m_listenersback to summary
private List<String> m_listeners
m_loadClassesback to summary
private final boolean m_loadClasses
m_locationsback to summary
private final Stack<TestNGContentHandler.Location> m_locations
m_redirectionAwareResolverback to summary
private final EntityResolver m_redirectionAwareResolver
m_suiteFilesback to summary
private final List<String> m_suiteFiles
m_suitesback to summary
private final List<XmlSuite> m_suites
m_validateback to summary
private boolean m_validate

Constructor Detail

TestNGContentHandlerback to summary
public TestNGContentHandler(String fileName, boolean loadClasses)

Method Detail

areWhiteSpacesback to summary
private boolean areWhiteSpaces(char[] ch, int start, int length)
charactersback to summary
public void characters(char[] ch, int start, int length)

Overrides org.xml.sax.helpers.DefaultHandler.characters.

Implements org.xml.sax.ContentHandler.characters.

Doc from org.xml.sax.helpers.DefaultHandler.characters.

Receive notification of character data inside an element.

By default, do nothing. Application writers may override this method to take specific actions for each chunk of character data (such as adding the data to a node or buffer, or printing it to a file).

Parameters
ch:char[]

The characters.

start:int

The start position in the character array.

length:int

The number of characters to use from the character array.

Annotations
@Override
endElementback to summary
public void endElement(String uri, String localName, String qName)

Overrides org.xml.sax.helpers.DefaultHandler.endElement.

Implements org.xml.sax.ContentHandler.endElement.

Doc from org.xml.sax.helpers.DefaultHandler.endElement.

Receive notification of the end of an element.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each element (such as finalising a tree node or writing output to a file).

Parameters
uri:String

The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.

localName:String

The local name (without prefix), or the empty string if Namespace processing is not being performed.

qName:String

The qualified name (with prefix), or the empty string if qualified names are not available.

Annotations
@Override
errorback to summary
public void error(SAXParseException e) throws SAXException

Overrides org.xml.sax.helpers.DefaultHandler.error.

Implements org.xml.sax.ErrorHandler.error.

Doc from org.xml.sax.helpers.DefaultHandler.error.

Receive notification of a recoverable parser error.

The default implementation does nothing. Application writers may override this method in a subclass to take specific actions for each error, such as inserting the message in a log file or printing it to the console.

Parameters
e:SAXParseException

The error information encoded as an exception.

Annotations
@Override
Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
expandValueback to summary
private static String expandValue(String value)
getSuiteback to summary
public XmlSuite getSuite()
isMalformedFileSystemBasedSystemIdback to summary
private static boolean isMalformedFileSystemBasedSystemId(String systemId)
isUnsecuredUrlback to summary
private static boolean isUnsecuredUrl(String str)
loadDtdUsingClassLoaderback to summary
private InputStream loadDtdUsingClassLoader()
popLocationback to summary
private void popLocation()
pushLocationback to summary
private void pushLocation(TestNGContentHandler.Location l)
resolveEntityback to summary
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException

Overrides org.xml.sax.helpers.DefaultHandler.resolveEntity.

Implements org.xml.sax.EntityResolver.resolveEntity.

Doc from org.xml.sax.helpers.DefaultHandler.resolveEntity.

Resolve an external entity.

Always return null, so that the parser will use the system identifier provided in the XML document. This method implements the SAX default behaviour: application writers can override it in a subclass to do special translations such as catalog lookups or URI redirection.

Parameters
publicId:String

The public identifier, or null if none is available.

systemId:String

The system identifier provided in the XML document.

Returns:InputSource

The new input source, or null to require the default behaviour.

Annotations
@Override
Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
IOException:
If there is an error setting up the new input source.
skipConsideringSystemIdback to summary
private static boolean skipConsideringSystemId(String systemId)
startElementback to summary
public void startElement(String uri, String localName, String qName, Attributes attributes)

Overrides org.xml.sax.helpers.DefaultHandler.startElement.

Implements org.xml.sax.ContentHandler.startElement.

Note

I only invoke xml*methods (e.g. xmlSuite()) if I am acting on both the start and the end of the tag. This way I can keep the treatment of this tag in one place. If I am only doing something when the tag opens, the code is inlined below in the startElement() method.

Parameters
uri:String

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.

localName:String

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

The local name (without prefix), or the empty string if Namespace processing is not being performed.

qName:String

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

The qualified name (with prefix), or the empty string if qualified names are not available.

attributes:Attributes

Doc from org.xml.sax.helpers.DefaultHandler.startElement.

The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.

Annotations
@Override
stringToListback to summary
private List<Integer> stringToList(String in)
warnSinceJUnitDetectedback to summary
private static void warnSinceJUnitDetected()
xmlClassesback to summary
public void xmlClasses(boolean start)
xmlDefineback to summary
private void xmlDefine(boolean start, Attributes attributes)

Parse

xmlExcludeback to summary
private void xmlExclude(boolean start, Attributes attributes)
xmlGroupback to summary
public void xmlGroup(boolean start, Attributes attributes)
xmlGroupsback to summary
public void xmlGroups(boolean start)
xmlIncludeback to summary
private void xmlInclude(boolean start, Attributes attributes)
xmlListenerback to summary
public void xmlListener(boolean start, Attributes attributes)
xmlListenersback to summary
public void xmlListeners(boolean start)
xmlMethodback to summary
private void xmlMethod(boolean start)
xmlMethodSelectorback to summary
public void xmlMethodSelector(boolean start)
xmlMethodSelectorsback to summary
public void xmlMethodSelectors(boolean start)
xmlPackagesback to summary
public void xmlPackages(boolean start)
xmlRunback to summary
public void xmlRun(boolean start)
xmlScriptback to summary
private void xmlScript(boolean start, Attributes attributes)

Parse