* @return The control decoded from the provided string, or <CODE>null</CODE>
* if an error occurs while parsing the argument value.
*/
public static LDAPControl getControl(String argString, PrintStream err)
{
LDAPControl control = null;
String controlOID = null;
boolean controlCriticality = false;
ByteString controlValue = null;
int idx = argString.indexOf(":");
if(idx < 0)
{
controlOID = argString;
}
else
{
controlOID = argString.substring(0, idx);
}
String lowerOID = toLowerCase(controlOID);
if (lowerOID.equals("accountusable") || lowerOID.equals("accountusability"))
{
controlOID = OID_ACCOUNT_USABLE_CONTROL;
}
else if (lowerOID.equals("authzid") ||
lowerOID.equals("authorizationidentity"))
{
controlOID = OID_AUTHZID_REQUEST;
}
else if (lowerOID.equals("noop") || lowerOID.equals("no-op"))
{
controlOID = OID_LDAP_NOOP_OPENLDAP_ASSIGNED;
}
else if (lowerOID.equals("managedsait"))
{
controlOID = OID_MANAGE_DSAIT_CONTROL;
}
else if (lowerOID.equals("pwpolicy") || lowerOID.equals("passwordpolicy"))
{
controlOID = OID_PASSWORD_POLICY_CONTROL;
}
else if (lowerOID.equals("subtreedelete") || lowerOID.equals("treedelete"))
{
controlOID = OID_SUBTREE_DELETE_CONTROL;
}
else if (lowerOID.equals("realattrsonly") ||
lowerOID.equals("realattributesonly"))
{
controlOID = OID_REAL_ATTRS_ONLY;
}
else if (lowerOID.equals("virtualattrsonly") ||
lowerOID.equals("virtualattributesonly"))
{
controlOID = OID_VIRTUAL_ATTRS_ONLY;
}
else if(lowerOID.equals("effectiverights") ||
lowerOID.equals("geteffectiverights"))
{
controlOID = OID_GET_EFFECTIVE_RIGHTS;
}
if (idx < 0)
{
return new LDAPControl(controlOID);
}
String remainder = argString.substring(idx+1, argString.length());
idx = remainder.indexOf(":");
if(idx == -1)
{
if(remainder.equalsIgnoreCase("true"))
{
controlCriticality = true;
} else if(remainder.equalsIgnoreCase("false"))
{
controlCriticality = false;
} else
{
err.println("Invalid format for criticality value:" + remainder);
return null;
}
control = new LDAPControl(controlOID, controlCriticality);
return control;
}
String critical = remainder.substring(0, idx);
if(critical.equalsIgnoreCase("true"))
{
controlCriticality = true;
} else if(critical.equalsIgnoreCase("false"))
{
controlCriticality = false;
} else
{
err.println("Invalid format for criticality value:" + critical);
return null;
}
String valString = remainder.substring(idx+1, remainder.length());
if(valString.charAt(0) == ':')
{
controlValue =
ByteString.valueOf(valString.substring(1, valString.length()));
} else if(valString.charAt(0) == '<')
{
// Read data from the file.
String filePath = valString.substring(1, valString.length());
try
{
byte[] val = readBytesFromFile(filePath, err);
controlValue = ByteString.wrap(val);
}
catch (Exception e)
{
return null;
}
} else
{
controlValue = ByteString.valueOf(valString);
}
control = new LDAPControl(controlOID, controlCriticality, controlValue);
return control;
}