X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Fremote%2FCommand.java;h=3704c26936923ac16f9797ad63d2bb033b7ecec2;hb=e4444b0bc462544629d9e7e7ab62b96a4d9cab10;hp=0fb0a7383da119523d32d2029e151a8af42b7f26;hpb=ebead449cce5df1849d54796fd2515a9e0556fee;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/remote/Command.java b/src/be/nikiroo/jvcard/remote/Command.java index 0fb0a73..3704c26 100644 --- a/src/be/nikiroo/jvcard/remote/Command.java +++ b/src/be/nikiroo/jvcard/remote/Command.java @@ -1,143 +1,233 @@ package be.nikiroo.jvcard.remote; -public class Command { - public enum Verb { - /** VERSION of the protocol */ - VERSION, - /** TIME of the remote server in milliseconds since the Unix epoch */ - TIME, - /** STOP the communication (client stops) */ - STOP, - /** - * LIST all the contacts on the remote server that contain the search - * term, or all contacts if no search term given - */ - LIST, - /** HELP about the protocol for interactive access */ - HELP, - /** GET a remote contact */ - GET, - /** PUT a new contact to the remote server or update an existing one */ - PUT, - /** POST a new contact to the remote server */ - POST, - /** DELETE an existing contact from the remote server */ - DELETE, - } - - private Verb verb; - private int version; - private String param; - +/** + * This enum list all the possible {@link Command}s you can send to a jVCard + * remote servrer. + * + * @author niki + * + */ +public enum Command { /** - * Create a new, empty {@link Command} with the given {@link Verb} and - * version. + * Protocol version. * - * @param verb - * the {@link Verb} - * @param version - * the version + * @return the version of the protocol used by this server */ - public Command(Verb verb, int version) { - this(verb, null, version); - } - + VERSION, /** - * Create a new, empty {@link Command} with the given {@link Verb} and - * version. + * Server time. * - * @param verb - * the {@link Verb} - * @param version - * the version + * @return the TIME of the remote server with the format yyyy-MM-dd HH:mm:ss */ - public Command(Verb verb, String param, int version) { - this.verb = verb; - this.version = version; - this.param = param; - } - + TIME, + /** + * STOP the client communication (the server will now close the + * communication) + */ + STOP, /** - * Read a command line (starting with a {@link Verb}) and process its - * content here in a more readable format. + * LIST the cards available on this server. * - * @param input - * the command line - * @param version - * the version (which can be overrided by a {@link Verb#VERSION} - * command) + * @param parameter + * (optional) a search term that, if given, must be in the name + * of the card for it to be returned (case insensitive) + * + * @return a LIST of all the cards on the remote server that contain the + * search term, or all cards if no search term given + * + * @note The cards are listed each on their own line, preceded by their last + * modified time and a space character (" ") + *

+ * Example: + *

+ * 2016-03-19 11:13:23 Family.vcf + *

+ * 2016-03-19 11:13:23 CoWorkers.vcf */ - public Command(String input, int version) { - this.version = version; - - if (input != null) { - String v = input; - int indexSp = input.indexOf(" "); - if (indexSp >= 0) { - v = input.substring(0, indexSp); - } - - for (Verb verb : Verb.values()) { - if (v.equals(verb.name())) { - this.verb = verb; - } - } - - if (verb != null) { - String param = null; - if (indexSp >= 0) - param = input.substring(indexSp + 1); - - this.param = param; - - if (verb == Verb.VERSION) { - try { - version = Integer.parseInt(param); - } catch (NumberFormatException e) { - e.printStackTrace(); - } - } - } - } - } - + LIST_CARD, /** - * Return the version + * Internationalised help message. * - * @return the version + * @return some HELP about the protocol for interactive access */ - public int getVersion() { - return version; - } - + HELP, /** - * Return the {@link Verb} + * SELECT a resource (a card) to work on (you can issue *_CARD commands when + * in SELECT mode), or leave SELECT mode if already enabled. + * + * @param parameter + * the resource name (the card name) to work on to enter SELECT + * mode, or nothing to leave it * - * @return the {@link Verb} + * @return the last modified date of the selected card */ - public Verb getVerb() { - return verb; - } - + SELECT, /** - * Return the parameter of this {@link Command} if any. + * GET a remote card and return it as VCF data. * - * @return the parameter or NULL + * @return VCF data */ - public String getParam() { - return param; - } - - @Override - public String toString() { - if (verb == null) - return "[null command]"; - - switch (verb) { - case VERSION: - return verb.name() + " " + version; - default: - return verb.name() + (param == null ? "" : " " + param); - } - } -} + GET_CARD, + /** + * Enter into PUT_CARD mode for the selected card (you can issue *_CONTACT + * commands when in PUT_CARD mode), or leave PUT_CARD mode if already + * enabled. + * + * @requires SELECT mode must be enabled before + */ + PUT_CARD, + /** + * POST a new card to the remote server as the selected resource. + * + * @input will wait for the card content as VCF data + * + * @requires SELECT mode must be enabled before + */ + POST_CARD, + /** + * DELETE the selected contact from the remote server. + * + * @requires SELECT mode must be enabled before + */ + DELETE_CARD, + /** + * HASH the selected contact and return the hash, or return empty if not + * found. + * + * @param parameter + * the UID of the contact to hash + * + * @return the hash, or an empty message if not found + * + * @requires PUT_CARD mode must be enabled before + */ + HASH_CONTACT, + /** + * LIST the contacts available in the selected card. + * + * @param parameter + * (optional) a search term that, if given, must be present in + * the N or FN property of the contact for the contact to be + * returned (case insensitive) + * + * @return a LIST of all the contacts in the selected card that contain the + * search term, or all contacts if no search term given + * + * @requires PUT_CARD mode must be enabled before + * + * @note The contacts are listed each on their own line, preceded by their + * hashes and a space character (" ") + *

+ * Example: + *

+ * 5d1db4f26410eae670852b53e6ea80be 6pXXHy8T3b + *

+ * 477eef8e57a12dffeeb4063d5a138c9a FoYJUyDOwM + */ + LIST_CONTACT, + /** + * GET a remote contact if found. + * + * @param parameter + * the UID of the contact to return + * + * @return the contact as VCF data or an empty message if the UID was not + * found + * + * @requires PUT_CARD mode must be enabled before + * + */ + GET_CONTACT, + /** + * Select the given contact by UID and enter into PUT_CONTACT mode (you can + * issue *_DATA commands when in PUT_CONTACT mode), or leave PUT_CONTACT + * mode if already enabled. + * + * @param parameter + * the UID of the contact to select to enter PUT_CONTACT mode, or + * nothing to leave it + * + * @requires PUT_CARD mode must be enabled before + */ + PUT_CONTACT, + /** + * POST a new contact to the remote server in the selected card. + * + * @input will wait for the contact VCF data + * + * @requires PUT_CARD mode must be enabled before + */ + POST_CONTACT, + /** + * DELETE an existing contact from the remote server. + * + * @param parameter + * the UID of the contact to delete + * + * @requires PUT_CARD mode must be enabled before + */ + DELETE_CONTACT, + /** + * HASH the data(s) with the given name. + * + * @param parameter + * the name of the data(s) you want + * + * @return the hashes of all the datas that correspond to the given name + * + * @requires PUT_CONTACT mode must be enabled before + */ + HASH_DATA, + /** + * LIST the datas available in the selected contact. + * + * @param parameter + * (optional) a search term that, if given, must be present in + * the name of the data for it to be returned (case insensitive) + * + * @return a LIST of all the datas in the selected contact that contain the + * search term, or all datas if no search term given + * + * @requires PUT_CONTACT mode must be enabled before + * + * @note The datas' names are listed each on their own line, preceded by + * their hashes and a space character (" ") + *

+ * Example: + *

+ * 5d1db4f26410eae670852b53e6ea80be FN + *

+ * 477eef8e57a12dffeeb4063d5a138c9a TEL + */ + LIST_DATA, + /** + * GET one or more remote data(s) by name. + * + * @param parameter + * the name of the data(s) to return + * + * @return the datas as VCF data or an empty message if no data were found + * with that name + * + * @requires PUT_CONTACT mode must be enabled before + * + */ + GET_DATA, + /** + * POST a new data to the remote server in the selected contact. + * + * @input will wait for the data VCF data + * + * @requires PUT_CONTACT mode must be enabled before + */ + POST_DATA, + /** + * DELETE an existing data from the remote server. + * + * @param parameter + * the hash of the data to delete + * + * @requires PUT_CONTACT mode must be enabled before + */ + DELETE_DATA, +} \ No newline at end of file