Простой filefix @author kreon
| 43 | * |
| 44 | */ |
| 45 | public class FileFix extends AbstractRobot { |
| 46 | private static final Pattern LIST = Pattern.compile("^%LIST$", |
| 47 | Pattern.CASE_INSENSITIVE); |
| 48 | private static final Pattern QUERY = Pattern.compile("^%QUERY$", |
| 49 | Pattern.CASE_INSENSITIVE); |
| 50 | private static final Pattern ADD = Pattern.compile("^%?\\+?(\\S+)$", |
| 51 | Pattern.CASE_INSENSITIVE); |
| 52 | private static final Pattern REM = Pattern.compile("^%?\\-(\\S+)$", |
| 53 | Pattern.CASE_INSENSITIVE); |
| 54 | |
| 55 | @Override |
| 56 | public void execute(FtnMessage fmsg) throws Exception { |
| 57 | Link link = getAndCheckLink(fmsg); |
| 58 | if (link == null) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | StringBuilder reply = new StringBuilder(); |
| 63 | for (String line : fmsg.getText().split("\n")) { |
| 64 | line = line.toLowerCase(); |
| 65 | if (HELP.matcher(line).matches()) { |
| 66 | FtnTools.writeReply(fmsg, |
| 67 | MessageFormat.format("{0} help", getRobotName()), |
| 68 | help()); |
| 69 | } else if (LIST.matcher(line).matches()) { |
| 70 | FtnTools.writeReply(fmsg, |
| 71 | MessageFormat.format("{0} list", getRobotName()), |
| 72 | list(link)); |
| 73 | } else if (QUERY.matcher(line).matches()) { |
| 74 | FtnTools.writeReply(fmsg, |
| 75 | MessageFormat.format("{0} query", getRobotName()), |
| 76 | query(link)); |
| 77 | } else { |
| 78 | Matcher m = REM.matcher(line); |
| 79 | if (m.matches()) { |
| 80 | String area = m.group(1); |
| 81 | reply.append(rem(link, area)); |
| 82 | continue; |
| 83 | } |
| 84 | m = ADD.matcher(line); |
| 85 | if (m.matches()) { |
| 86 | String area = m.group(1); |
| 87 | reply.append(add(link, area)); |
| 88 | continue; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | if (reply.length() > 0) { |
| 93 | FtnTools.writeReply(fmsg, |
| 94 | MessageFormat.format("{0} reply", getRobotName()), |
| 95 | reply.toString()); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Отправляем %HELP |
| 101 | * |
| 102 | * @return |
nothing calls this directly
no outgoing calls
no test coverage detected