X-Git-Url: https://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Fremote%2FCommand.java;h=6ab044e8ffd09afdc510241f54d27d852508915c;hb=845fb1d7c3adc0d6cdf9465c0e983ba447cfab6d;hp=1132bb279f8014925c284e75c286636a9d260f9d;hpb=6a77f2ed5996a89e82edd6552942bf23123c205f;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/remote/Command.java b/src/be/nikiroo/jvcard/remote/Command.java index 1132bb2..6ab044e 100644 --- a/src/be/nikiroo/jvcard/remote/Command.java +++ b/src/be/nikiroo/jvcard/remote/Command.java @@ -1,165 +1,55 @@ 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, - /** SELECT a resource (a card) to work on */ - SELECT, - /** GET a remote card */ - GET_CARD, - /** - * PUT mode activation toggle for a card on the remote server (you can - * issue *_CONTACT commands when in PUT mode) - */ - PUT_CARD, - /** POST a new card to the remote server */ - POST_CARD, - /** DELETE an existing contact from the remote server */ - DELETE_CARD, - /** GET a remote contact */ - GET_CONTACT, - /** - * PUT mode activation toggle for a contact on the remote server (you - * can issue *_DATA commands when in PUT mode) - */ - PUT_CONTACT, - /** POST a new contact to the remote server */ - POST_CONTACT, - /** DELETE an existing contact from the remote server */ - DELETE_CONTACT, - /** GET a remote data */ - GET_DATA, - /** POST a new data to the remote server */ - POST_DATA, - /** DELETE an existing data from the remote server */ - DELETE_DATA, - } - - private Verb verb; - private int version; - private String param; - - /** - * Create a new, empty {@link Command} with the given {@link Verb} and - * version. - * - * @param verb - * the {@link Verb} - * @param version - * the version - */ - public Command(Verb verb, int version) { - this(verb, null, version); - } - - /** - * Create a new, empty {@link Command} with the given {@link Verb} and - * version. - * - * @param verb - * the {@link Verb} - * @param version - * the version - */ - public Command(Verb verb, String param, int version) { - this.verb = verb; - this.version = version; - this.param = param; - } - - /** - * Read a command line (starting with a {@link Verb}) and process its - * content here in a more readable format. - * - * @param input - * the command line - * @param version - * the version (which can be overrided by a {@link Verb#VERSION} - * command) - */ - 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(); - } - } - } - } - } - +public enum Command { + /** VERSION of the protocol */ + VERSION, + /** TIME of the remote server in milliseconds since the Unix epoch */ + TIME, + /** STOP the communication (client stops) */ + STOP, /** - * Return the version - * - * @return the version + * LIST all the cards on the remote server that contain the search term, + * or all contacts if no search term given; also add their timestamps */ - public int getVersion() { - return version; - } - + LIST_CARD, + /** HELP about the protocol for interactive access */ + HELP, + /** SELECT a resource (a card) to work on */ + SELECT, + /** GET a remote card */ + GET_CARD, /** - * Return the {@link Verb} - * - * @return the {@link Verb} + * PUT mode activation toggle for a card on the remote server (you can issue + * *_CONTACT commands when in PUT mode) */ - public Verb getVerb() { - return verb; - } - + PUT_CARD, + /** POST a new card to the remote server */ + POST_CARD, + /** DELETE an existing contact from the remote server */ + DELETE_CARD, + /** HASH the given contact and return the hash, or empty if not found */ + HASH_CONTACT, + /** LIST all the contacts of the current card; also add their hashes */ + LIST_CONTACT, + /** GET a remote contact */ + GET_CONTACT, /** - * Return the parameter of this {@link Command} if any. - * - * @return the parameter or NULL + * PUT mode activation toggle for a contact on the remote server (you can + * issue *_DATA commands when in PUT mode), param = uid */ - 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); - } - } -} + PUT_CONTACT, + /** POST a new contact to the remote server */ + POST_CONTACT, + /** DELETE an existing contact from the remote server */ + DELETE_CONTACT, + /** HASH the data(s) with the given name */ + HASH_DATA, + /** LIST all the datas of the current contact; also add their hashes */ + LIST_DATA, + /** GET a (or more) remote data(s) by name */ + GET_DATA, + /** POST a new data to the remote server */ + POST_DATA, + /** DELETE an existing data from the remote server */ + DELETE_DATA, +} \ No newline at end of file