mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-29 09:42:06 +01:00
DisabledSmackClasses now also take package names
So that whole packages can be disabled.
This commit is contained in:
parent
b0f774a2cf
commit
9580784bbf
2 changed files with 31 additions and 17 deletions
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -166,31 +166,41 @@ public final class SmackInitialization {
|
|||
final String startName = parser.getName();
|
||||
int eventType;
|
||||
String name;
|
||||
do {
|
||||
outerloop: do {
|
||||
eventType = parser.next();
|
||||
name = parser.getName();
|
||||
if (eventType == XmlPullParser.START_TAG && "className".equals(name)) {
|
||||
String classToLoad = parser.nextText();
|
||||
if (SmackConfiguration.disabledSmackClasses.contains(classToLoad)) {
|
||||
LOGGER.info("Not loading disabled Smack class " + classToLoad);
|
||||
for (String disabledClassOrPackage : SmackConfiguration.disabledSmackClasses) {
|
||||
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 {
|
||||
loadSmackClass(classToLoad, optional, classLoader);
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
// Don't throw the exception if an exceptions collection is given, instead
|
||||
// record it there. This is used for unit testing purposes.
|
||||
if (exceptions != null) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!(eventType == XmlPullParser.END_TAG && startName.equals(name)));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue