* @param command command.
* @return supported command.
*/
private NntpCommand findCommand(String command) {
String[] parts = StringUtils.split(command, DELIMITER);
NntpCommand foundedCommand;
if (parts == null) {
throw new UnknownCommandException();
}
if (parts.length == 1) {
foundedCommand = NntpCommand.find(command);
if (foundedCommand == null) {
throw new UnknownCommandException();
}
foundedCommand.setParams(EMPTY_LIST);
return foundedCommand;
}
foundedCommand = NntpCommand.find(parts[0] + DELIMITER + parts[1]);
if (foundedCommand == null) {
foundedCommand = findCommand(parts[0]);
if (foundedCommand == null) {
throw new UnknownCommandException();
} else {
foundedCommand.setParams(prepareParams(parts, true));
}
} else {
foundedCommand.setParams(prepareParams(parts, false));
}
return foundedCommand;
}