+ }
+
+ return clientContinue;
+ }
+
+ /**
+ * Process a subcommand while protected for resource <tt>name</tt>.
+ *
+ * @param s
+ * the {@link SimpleSocket} to process
+ *
+ * @param name
+ * the resource that is protected (and to target)
+ *
+ * @return TRUE if the client is ready for another command, FALSE when the
+ * client is done
+ *
+ * @throws IOException
+ * in case of IO error
+ *
+ * @throw InvalidParameterException in case of invalid subcommand
+ */
+ private boolean processLockedCmd(SimpleSocket s, String name)
+ throws IOException {
+ CommandInstance cmd = s.receiveCommand();
+ Command command = cmd.getCommand();
+
+ if (command == null)
+ return false;
+
+ boolean clientContinue = true;
+
+ System.out.println(s + " -> " + command);
+
+ switch (command) {
+ case GET_CARD: {
+ s.sendBlock(doGetCard(name));
+ break;
+ }
+ case POST_CARD: {
+ s.sendLine(doPostCard(name, s.receiveBlock()));
+ break;
+ }
+ case PUT_CARD: {
+ File vcf = getFile(name);
+ if (vcf == null) {
+ System.err
+ .println("Fail to update a card, file not available: "
+ + name);
+ clientContinue = false;
+ } else {
+ Card card = new Card(vcf, Format.VCard21);
+ try {
+ while (processContactCmd(s, card))
+ ;
+ card.save();
+ s.sendLine(StringUtils.fromTime(card.getLastModified()));
+ } catch (InvalidParameterException e) {
+ System.err
+ .println("Unsupported command received from a client connection, closing it: "
+ + command + " (" + e.getMessage() + ")");
+ clientContinue = false;
+ }
+ }
+ break;
+ }
+ case DELETE_CARD: {
+ // TODO
+ System.err
+ .println("Unsupported command received from a client connection, closing it: "
+ + command);
+ clientContinue = false;
+ break;
+ }
+ case SELECT: {
+ clientContinue = false;
+ break;
+ }
+ default: {
+ throw new InvalidParameterException("command invalid here: "
+ + command);
+ }
+ }