/**
* Combine user credentials into an appropriately formatted string.
*
* @param credentials An array of credential strings. Credential
* strings may contain any character but ';'
* (semicolon), '\\' (backslash), and control
* characters (with ASCII codes 0-31 and 127).
*
* @return <CODE>null</CODE> only if any credential strings are invalid.
*/
public String getCredentialsString(String[] credentials) {
// Create a buffer with which to generate the credentials string.
StringBuffer buffer = new StringBuffer();
// Verify and add each credential to the buffer.
if (credentials != null) {
for (int i = 0; i < credentials.length; ++i) {
if (i > 0) buffer.append(';');
for (int j = 0, n = credentials[i].length(); j < n; ++j) {
char c = credentials[i].charAt(j);
if (c != ';' && c != '\\' && c >= ' ' && c != 127) {
buffer.append(c);
} else {
return null;
}
}
}
}
// Return the credentials string.
return buffer.toString();
} |
© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-11-04)