1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-29 23:42:06 +01:00

DisabledSmackClasses now also take package names

So that whole packages can be disabled.
This commit is contained in:
Florian Schmaus 2014-09-25 09:42:55 +02:00
parent b0f774a2cf
commit 9580784bbf
2 changed files with 31 additions and 17 deletions

View file

@ -283,7 +283,11 @@ public final class SmackConfiguration {
} }
/** /**
* Add a class to the disabled smack classes * Add a class to the disabled smack classes.
* <p>
* {@code className} can also be a package name, in this case, the entire
* package is disabled (but can be manually enabled).
* </p>
* *
* @param className * @param className
*/ */

View file

@ -166,31 +166,41 @@ public final class SmackInitialization {
final String startName = parser.getName(); final String startName = parser.getName();
int eventType; int eventType;
String name; String name;
do { outerloop: do {
eventType = parser.next(); eventType = parser.next();
name = parser.getName(); name = parser.getName();
if (eventType == XmlPullParser.START_TAG && "className".equals(name)) { if (eventType == XmlPullParser.START_TAG && "className".equals(name)) {
String classToLoad = parser.nextText(); String classToLoad = parser.nextText();
if (SmackConfiguration.disabledSmackClasses.contains(classToLoad)) { for (String disabledClassOrPackage : SmackConfiguration.disabledSmackClasses) {
LOGGER.info("Not loading disabled Smack class " + classToLoad); if (disabledClassOrPackage.equals(classToLoad)) {
// Skip disabled class
continue outerloop;
} }
else { int lastDotIndex = disabledClassOrPackage.lastIndexOf('.');
// Security check to avoid NPEs if someone entered 'foo.bar.'
if (disabledClassOrPackage.length() > lastDotIndex
// disabledClassOrPackage is not an Class
&& !Character.isUpperCase(disabledClassOrPackage.charAt(lastDotIndex + 1))
// classToLoad startsWith the package disabledClassOrPackage disables
&& classToLoad.startsWith(disabledClassOrPackage)) {
// Skip the class because the whole package was disabled
continue outerloop;
}
}
try { try {
loadSmackClass(classToLoad, optional, classLoader); loadSmackClass(classToLoad, optional, classLoader);
} } catch (Exception e) {
catch (Exception e) {
// Don't throw the exception if an exceptions collection is given, instead // Don't throw the exception if an exceptions collection is given, instead
// record it there. This is used for unit testing purposes. // record it there. This is used for unit testing purposes.
if (exceptions != null) { if (exceptions != null) {
exceptions.add(e); exceptions.add(e);
} } else {
else {
throw e; throw e;
} }
} }
} }
} }
}
while (!(eventType == XmlPullParser.END_TAG && startName.equals(name))); while (!(eventType == XmlPullParser.END_TAG && startName.equals(name)));
} }