Merge branch '4.3'

This commit is contained in:
Florian Schmaus 2018-11-29 22:39:55 +01:00
commit 62a0c6f26e
9 changed files with 46 additions and 9 deletions

View File

@ -89,6 +89,11 @@
<property name="message" value="Usage of println"/> <property name="message" value="Usage of println"/>
<property name="ignoreComments" value="true"/> <property name="ignoreComments" value="true"/>
</module> </module>
<module name="RegexpSinglelineJava">
<property name="format" value="Boolean\.valueOf\("/>
<property name="message" value="Usage Boolean.valueOf(), consider using ParserUtils.parseXmlBoolean() instead (if you want to parse xs:boolean values)"/>
<property name="ignoreComments" value="true"/>
</module>
<module name="RegexpSinglelineJava"> <module name="RegexpSinglelineJava">
<property name="format" value="^\t+"/> <property name="format" value="^\t+"/>
<property name="message" value="Indent must not use tab characters. Use space instead."/> <property name="message" value="Indent must not use tab characters. Use space instead."/>

View File

@ -123,7 +123,9 @@ public class IntrospectionProvider{
case "java.lang.String": case "java.lang.String":
return value; return value;
case "boolean": case "boolean":
// CHECKSTYLE:OFF
return Boolean.valueOf(value); return Boolean.valueOf(value);
// CHECKSTYLE:ON
case "int": case "int":
return Integer.valueOf(value); return Integer.valueOf(value);
case "long": case "long":

View File

@ -129,6 +129,27 @@ public class ParserUtils {
return Resourcepart.from(resourcepartString); return Resourcepart.from(resourcepartString);
} }
/**
* Prase a string to a boolean value as per "xs:boolean". Valid input strings are "true", "1" for true, and "false", "0" for false.
*
* @param booleanString the input string.
* @return the boolean representation of the input string
* @throws IllegalArgumentException if the input string is not valid.
* @since 4.3.2
*/
public static boolean parseXmlBoolean(String booleanString) {
switch (booleanString) {
case "true":
case "1":
return true;
case "false":
case "0":
return false;
default:
throw new IllegalArgumentException(booleanString + " is not a valid boolean string");
}
}
/** /**
* Get the boolean value of an argument. * Get the boolean value of an argument.
* *
@ -141,7 +162,7 @@ public class ParserUtils {
if (valueString == null) if (valueString == null)
return null; return null;
valueString = valueString.toLowerCase(Locale.US); valueString = valueString.toLowerCase(Locale.US);
return valueString.equals("true") || valueString.equals("0"); return parseXmlBoolean(valueString);
} }
public static boolean getBooleanAttribute(XmlPullParser parser, String name, public static boolean getBooleanAttribute(XmlPullParser parser, String name,

View File

@ -16,6 +16,8 @@
*/ */
package org.jivesoftware.smackx.hoxt.provider; package org.jivesoftware.smackx.hoxt.provider;
import org.jivesoftware.smack.util.ParserUtils;
import org.jivesoftware.smackx.hoxt.packet.HttpMethod; import org.jivesoftware.smackx.hoxt.packet.HttpMethod;
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq; import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq;
@ -47,13 +49,13 @@ public class HttpOverXmppReqProvider extends AbstractHttpOverXmppProvider<HttpOv
String jingleStr = parser.getAttributeValue("", AbstractHttpOverXmppProvider.ELEMENT_JINGLE); String jingleStr = parser.getAttributeValue("", AbstractHttpOverXmppProvider.ELEMENT_JINGLE);
if (sipubStr != null) { if (sipubStr != null) {
builder.setSipub(Boolean.valueOf(sipubStr)); builder.setSipub(ParserUtils.parseXmlBoolean(sipubStr));
} }
if (ibbStr != null) { if (ibbStr != null) {
builder.setIbb(Boolean.valueOf(ibbStr)); builder.setIbb(ParserUtils.parseXmlBoolean(ibbStr));
} }
if (jingleStr != null) { if (jingleStr != null) {
builder.setJingle(Boolean.valueOf(jingleStr)); builder.setJingle(ParserUtils.parseXmlBoolean(jingleStr));
} }
String maxChunkSize = parser.getAttributeValue("", ATTRIBUTE_MAX_CHUNK_SIZE); String maxChunkSize = parser.getAttributeValue("", ATTRIBUTE_MAX_CHUNK_SIZE);

View File

@ -1,6 +1,6 @@
/** /**
* *
* Copyright © 2016 Florian Schmaus * Copyright © 2016-2018 Florian Schmaus
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
*/ */
package org.jivesoftware.smackx.iot.control.element; package org.jivesoftware.smackx.iot.control.element;
import org.jivesoftware.smack.util.ParserUtils;
public class SetBoolData extends SetData { public class SetBoolData extends SetData {
public SetBoolData(String name, boolean value) { public SetBoolData(String name, boolean value) {
@ -31,7 +33,7 @@ public class SetBoolData extends SetData {
public Boolean getBooleanValue() { public Boolean getBooleanValue() {
if (booleanCache != null) { if (booleanCache != null) {
booleanCache = Boolean.valueOf(getValue()); booleanCache = ParserUtils.parseXmlBoolean(getValue());
} }
return booleanCache; return booleanCache;
} }

View File

@ -269,12 +269,12 @@ public class Bookmarks implements PrivateData {
private static BookmarkedConference getConferenceStorage(XmlPullParser parser) throws XmlPullParserException, IOException { private static BookmarkedConference getConferenceStorage(XmlPullParser parser) throws XmlPullParserException, IOException {
String name = parser.getAttributeValue("", "name"); String name = parser.getAttributeValue("", "name");
String autojoin = parser.getAttributeValue("", "autojoin"); boolean autojoin = ParserUtils.getBooleanAttribute(parser, "autojoin", false);
EntityBareJid jid = ParserUtils.getBareJidAttribute(parser); EntityBareJid jid = ParserUtils.getBareJidAttribute(parser);
BookmarkedConference conf = new BookmarkedConference(jid); BookmarkedConference conf = new BookmarkedConference(jid);
conf.setName(name); conf.setName(name);
conf.setAutoJoin(Boolean.valueOf(autojoin)); conf.setAutoJoin(autojoin);
// Check for nickname // Check for nickname
boolean done = false; boolean done = false;

View File

@ -92,7 +92,9 @@ public class JivePropertiesExtensionProvider extends ExtensionElementProvider<Ji
value = Double.valueOf(valueText); value = Double.valueOf(valueText);
} }
else if ("boolean".equals(type)) { else if ("boolean".equals(type)) {
// CHECKSTYLE:OFF
value = Boolean.valueOf(valueText); value = Boolean.valueOf(valueText);
// CHECKSTYLE:ON
} }
else if ("string".equals(type)) { else if ("string".equals(type)) {
value = valueText; value = valueText;

View File

@ -207,7 +207,8 @@ public class RoomInfo {
FormField subjectmodField = form.getField("muc#roominfo_subjectmod"); FormField subjectmodField = form.getField("muc#roominfo_subjectmod");
if (subjectmodField != null && !subjectmodField.getValues().isEmpty()) { if (subjectmodField != null && !subjectmodField.getValues().isEmpty()) {
subjectmod = Boolean.valueOf(subjectmodField.getFirstValue()); String firstValue = subjectmodField.getFirstValue();
subjectmod = ("true".equals(firstValue) || "1".equals(firstValue));
} }
FormField urlField = form.getField("muc#roominfo_logs"); FormField urlField = form.getField("muc#roominfo_logs");

View File

@ -104,7 +104,9 @@ public class WorkgroupProperties extends IQ {
while (!done) { while (!done) {
int eventType = parser.next(); int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && "authRequired".equals(parser.getName())) { if (eventType == XmlPullParser.START_TAG && "authRequired".equals(parser.getName())) {
// CHECKSTYLE:OFF
props.setAuthRequired(Boolean.valueOf(parser.nextText()).booleanValue()); props.setAuthRequired(Boolean.valueOf(parser.nextText()).booleanValue());
// CHECKSTYLE:ON
} }
else if (eventType == XmlPullParser.START_TAG && "email".equals(parser.getName())) { else if (eventType == XmlPullParser.START_TAG && "email".equals(parser.getName())) {
props.setEmail(parser.nextText()); props.setEmail(parser.nextText());