src/main/java/org/jivesoftware/smack/util/StringUtils.java
public static String escapeNode(String node) {
        if (node == null) {
            return null;
        }
        StringBuilder buf = new StringBuilder(node.length() + 8);
        for (int i = 0, n = node.length(); i < n; i++) {
            char c = node.charAt(i);
            switch (c) {
            case '"':
                buf.append("\\22");
                break;
            case '&':
                buf.append("\\26");
                break;
            case '\'':
                buf.append("\\27");
                break;
            case '/':
                buf.append("\\2f");
                break;
            case ':':
                buf.append("\\3a");
                break;
            case '<':
                buf.append("\\3c");
                break;
            case '>':
                buf.append("\\3e");
                break;
            case '@':
                buf.append("\\40");
                break;
            case '\\':
                buf.append("\\5c");
                break;
            default: {
                if (Character.isWhitespace(c)) {
                    buf.append("\\20");
                } else {
                    buf.append(c);
                }
            }
            }
        }
        return buf.toString();
    }
public static String escapeNode(String node) {
        if (node == null) {
            return null;
        }
        StringBuilder buf = new StringBuilder(node.length() + 8);
        for (int i = 0, n = node.length(); i < n; i++) {
            char c = node.charAt(i);
            switch (c) {
            case '"':
                buf.append("\\22");
                break;
            case '&':
                buf.append("\\26");
                break;
            case '\'':
                buf.append("\\27");
                break;
            case '/':
                buf.append("\\2f");
                break;
            case ':':
                buf.append("\\3a");
                break;
            case '<':
                buf.append("\\3c");
                break;
            case '>':
                buf.append("\\3e");
                break;
            case '@':
                buf.append("\\40");
                break;
            case '\\':
                buf.append("\\5c");
                break;
            default: {
                if (Character.isWhitespace(c)) {
                    buf.append("\\20");
                } else {
                    buf.append(c);
                }
            }
            }
        }
        return buf.toString();
    }
public static String escapeNode ( String node ) { if ( node == null ) { return null ; } StringBuilder buf = new StringBuilder ( node . length ( ) + 8 ) ; for ( int i = 0 , n = node . length ( ) ; i < n ; i ++ ) { char c = node . charAt ( i ) ; switch ( c ) { case ' ' : buf . append ( "\\22" ) ; break ; case ' ' : buf . append ( "\\26" ) ; break ; case ' ' : buf . append ( "\\27" ) ; break ; case ' ' : buf . append ( "\\2f" ) ; break ; case ' ' : buf . append ( "\\3a" ) ; break ; case ' ' : buf . append ( "\\3c" ) ; break ; case ' ' : buf . append ( "\\3e" ) ; break ; case ' ' : buf . append ( "\\40" ) ; break ; case ' ' : buf . append ( "\\5c" ) ; break ; default : { if ( Character . isWhitespace ( c ) ) { buf . append ( "\\20" ) ; } else { buf . append ( c ) ; } } } } return buf . toString ( ) ; }
Escapes the node portion of a JID according to "JID Escaping" (JEP-0106).
Escaping replaces characters prohibited by node-prep with escape
sequences, as follows:
<p>

<table border="1">
<tr>
<td><b>Unescaped Character</b></td>
<td><b>Encoded Sequence</b></td>
</tr>
<tr>
<td>&lt;space&gt;</td>
<td>\20</td>
</tr>
<tr>
<td>"</td>
<td>\22</td>
</tr>
<tr>
<td>&</td>
<td>\26</td>
</tr>
<tr>
<td>'</td>
<td>\27</td>
</tr>
<tr>
<td>/</td>
<td>\2f</td>
</tr>
<tr>
<td>:</td>
<td>\3a</td>
</tr>
<tr>
<td>&lt;</td>
<td>\3c</td>
</tr>
<tr>
<td>&gt;</td>
<td>\3e</td>
</tr>
<tr>
<td>@</td>
<td>\40</td>
</tr>
<tr>
<td>\</td>
<td>\5c</td>
</tr>
</table>
<p>

This process is useful when the node comes from an external source that
doesn't conform to nodeprep. For example, a username in LDAP may be
"Joe Smith". Because the &lt;space&gt; character isn't a valid part of a
node, the username should be escaped to "Joe\20Smith" before being made
into a JID (e.g. "joe\20smith@example.com" after case-folding, etc. has
been applied).
<p>

All node escaping and un-escaping must be performed manually at the
appropriate time; the JID class will not escape or un-escape
automatically.

@param node
the node.
@return the escaped version of the node.
Escapes the node portion of a JID according to JID Escaping ( JEP - 0106 ) . Escaping replaces characters prohibited by node - prep with escape sequences as follows : <p >