break;
}
case VERSION: {
- s.sendCommand(Command.VERSION);
+ s.sendLine("" + SimpleSocket.CURRENT_VERSION);
break;
}
case TIME: {
}
case LIST_CARD: {
for (File file : dataDir.listFiles()) {
- if (cmd.getParam() == null || cmd.getParam().length() == 0
- || file.getName().contains(cmd.getParam())) {
+ if (cmd.getParam() == null
+ || cmd.getParam().length() == 0
+ || file.getName().toLowerCase()
+ .contains(cmd.getParam().toLowerCase())) {
s.send(StringUtils.fromTime(file.lastModified()) + " "
+ file.getName());
}
s.send("The following commands are available:");
s.send("- TIME: get the server time");
s.send("- HELP: this help screen");
- s.send("- LIST: list the available cards on this server");
- s.send("- VERSION/GET/PUT/POST/DELETE/STOP: TODO");
+ s.send("- LIST_CARD: list the available cards on this server");
+ s.send("- VERSION/GET_*/PUT_*/POST_*/DELETE_*/STOP: TODO");
s.sendBlock();
break;
}
break;
}
default: {
- throw new InvalidParameterException("command invalid here");
+ throw new InvalidParameterException("command invalid here: "
+ + command);
}
}
break;
}
case POST_CONTACT: {
- String uid = cmd.getParam();
- Contact contact = card.getById(uid);
- if (contact != null)
- contact.delete();
List<Contact> list = Vcard21Parser.parseContact(s.receiveBlock());
if (list.size() > 0) {
- contact = list.get(0);
- contact.getPreferredData("UID").setValue(uid);
- card.add(contact);
+ Contact newContact = list.get(0);
+ String uid = newContact.getPreferredDataValue("UID");
+ Contact oldContact = card.getById(uid);
+ if (oldContact != null)
+ oldContact.delete();
+ card.add(newContact);
}
+
break;
}
case PUT_CONTACT: {
}
case LIST_CONTACT: {
for (Contact contact : card) {
- s.send(contact.getContentState() + " " + contact.getId());
+ if (cmd.getParam() == null
+ || cmd.getParam().length() == 0
+ || (contact.getPreferredDataValue("FN") + contact
+ .getPreferredDataValue("N")).toLowerCase()
+ .contains(cmd.getParam().toLowerCase())) {
+ s.send(contact.getContentState() + " " + contact.getId());
+ }
}
s.sendBlock();
break;
break;
}
default: {
- throw new InvalidParameterException("command invalid here");
+ throw new InvalidParameterException("command invalid here: "
+ + command);
}
}
}
case LIST_DATA: {
for (Data data : contact) {
- s.send(data.getContentState() + " " + data.getName());
+ if (cmd.getParam() == null
+ || cmd.getParam().length() == 0
+ || data.getName().toLowerCase()
+ .contains(cmd.getParam().toLowerCase())) {
+ s.send(data.getContentState() + " " + data.getName());
+ }
}
s.sendBlock();
break;
break;
}
default: {
- throw new InvalidParameterException("command invalid here");
+ throw new InvalidParameterException("command invalid here: "
+ + command);
}
}
if (vcf != null && vcf.exists()) {
Card card = new Card(vcf, Format.VCard21);
- // timestamp:
+ // timestamp + data
lines.add(StringUtils.fromTime(card.getLastModified()));
lines.addAll(Vcard21Parser.toStrings(card));
}