ImpsUtils.javaAPI DocAndroid 1.5 API5701Wed May 06 22:42:46 BST


public class ImpsUtils extends Object

Fields Summary
private static final HashMap
private static String
private static int
Constructors Summary
private ImpsUtils()

Methods Summary
public static ImpsErrorInfocheckResultError(Primitive response)
Checks if the response primitive indicates successful.

response the response primitive.
null if the status code is 200 or an ImpsErrorInfo instance

        PrimitiveElement result = response.getElement(ImpsTags.Result);
        if (result == null) {
            return null;

        String resultCode = result.getChild(ImpsTags.Code).getContents();
        if (!ImpsConstants.SUCCESS_CODE.equals(resultCode)) {
            PrimitiveElement descElem = result.getChild(ImpsTags.Description);
            String errorDesc = (descElem == null) ? "" : descElem.getContents();
            int statusCode = parseInt(resultCode, ImErrorInfo.ILLEGAL_SERVER_RESPONSE);
            return new ImpsErrorInfo(statusCode, errorDesc, response);
        return null;
static synchronized java.lang.StringgenSessionCookie()

        if(sSessionCookie == null) {
            Random random = new Random();
            sSessionCookie = System.currentTimeMillis() + "" + random.nextInt();
        return sSessionCookie + (sSessionCookieNumber++);
public static java.util.MapgetClientInfo()

        return Collections.unmodifiableMap(sClientInfo);
public static booleanisFalse(java.lang.String value)
Checks if a string is a boolean value of false in IMPS.

value the string value.
true if it's false in IMPS

        return ImpsConstants.FALSE.equalsIgnoreCase(value);
public static booleanisQualifiedPresence(PrimitiveElement elem)
Check whether the presence element has a qualified attribute value. An attribute value is invalid when: 1. An attribute is authorized but not yet updated for the first time 2. The user wants to indicate that the value of the attribute is unknown.

elem the presence element
true if the value of attribute is valid.

        if (null == elem || null == elem.getChild(ImpsTags.Qualifier)) {
            return false;

        return ImpsUtils.isTrue(elem.getChildContents(ImpsTags.Qualifier));
public static booleanisTrue(java.lang.String value)
Checks if a string is a boolean value of true IMPS.

value the string value.
true if it's true in IMPS.

        // TODO: v1.2 doesn't support ClientContentLimit
        sClientInfo = new HashMap<String, String>();
        sClientInfo.put(ImpsTags.ClientType, ImpsClientCapability.getClientType());
        sClientInfo.put(ImpsTags.ClientProducer, ImpsConstants.CLIENT_PRODUCER);
        sClientInfo.put(ImpsTags.ClientVersion, ImpsConstants.CLIENT_VERSION);
        return ImpsConstants.TRUE.equalsIgnoreCase(value);
public static intparseInt(java.lang.String s, int defaultValue)

        try {
            return Integer.parseInt(s);
        } catch (NumberFormatException e) {
            // ignore
            return defaultValue;
public static longparseLong(java.lang.String s, long defaultValue)

        try {
            return Long.parseLong(s);
        } catch (NumberFormatException e) {
            // ignore
            return defaultValue;
public static java.lang.StringtoImpsBool(boolean isTrue)
Return the IMPS String presentation of the boolean value

isTrue the boolean value
the String presentation

        if (isTrue) {
            return ImpsConstants.TRUE;

        return ImpsConstants.FALSE;
public static java.lang.Stringtrim(java.lang.String str)
Returns a copy of the string, with leading and trailing whitespace omitted. Unlike the standard trim which just removes '\u0020'(the space character), it removes all possible leading and trailing whitespace character.

str the string.
a copy of the string, with leading and trailing whitespace omitted.

        if (null == str || "".equals(str))
            return str;

        int strLen = str.length();
        int start = 0;
        while (start < strLen && Character.isWhitespace(str.charAt(start)))
        int end = strLen - 1;
        while (end >= 0 && Character.isWhitespace(str.charAt(end)))
        if (end < start)
            return "";
        str = str.substring(start, end + 1);
        return str;