diff options
author | Gurmeen Bindra <gurmeen.bindra@isode.com> | 2012-04-19 09:13:47 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-04-27 11:06:22 (GMT) |
commit | e2f24c6930603dbd016a6530f7d12b08c97ea900 (patch) | |
tree | bcdcf5e98616db5859775b1a91a6200add5e4fc2 /src | |
parent | 9217dc0c6033f9d70c87ba4a84f5bbafe2c1e6ac (diff) | |
download | stroke-e2f24c6930603dbd016a6530f7d12b08c97ea900.zip stroke-e2f24c6930603dbd016a6530f7d12b08c97ea900.tar.bz2 |
Port Classes for Storage/Private Storage
This patch ports the classes for Storage, PrivateStorage and PrivateStorage
requests from Swiften to Stroke.
Test-information:
junit test for GetPrivateStorageRequestTest is also ported and tested
Diffstat (limited to 'src')
5 files changed, 288 insertions, 0 deletions
diff --git a/src/com/isode/stroke/elements/PrivateStorage.java b/src/com/isode/stroke/elements/PrivateStorage.java new file mode 100644 index 0000000..171e56e --- /dev/null +++ b/src/com/isode/stroke/elements/PrivateStorage.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2010, Remko Tronçon. + * All rights reserved. + */ +package com.isode.stroke.elements; + +/** + * Class representing Private XML Storage for storing arbitrary private + * user data on User's server(such as XEP-0048's bookmarks) + * + */ +public class PrivateStorage extends Payload { + + /** + * Constructor + * @param p payload, not null + */ + public PrivateStorage(Payload p) { + this.payload = p; + } + + /** + * Get payload + * @return payload, not null + */ + public Payload getPayload() { + return payload; + } + + /** + * Set payload + * @param p payload, not null + */ + public void setPayload(Payload p) { + payload = p; + } + + private Payload payload; +} diff --git a/src/com/isode/stroke/elements/Storage.java b/src/com/isode/stroke/elements/Storage.java new file mode 100644 index 0000000..8597c27 --- /dev/null +++ b/src/com/isode/stroke/elements/Storage.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2012, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2010, Remko Tronçon. + * All rights reserved. + */ + +package com.isode.stroke.elements; + +import java.util.Vector; +import com.isode.stroke.jid.JID; + +/** + * Class representing storage for storing payloads + * + */ +public class Storage extends Payload { + private Vector<Room> rooms = new Vector<Room>(); + private Vector<URL> urls = new Vector<URL>(); + + /** + * Class representing a chat room + * + */ + public static class Room { + public Room() { + autoJoin = false; + } + + public String name = ""; + public JID jid = JID.fromString(""); + public boolean autoJoin = false; + public String nick = ""; + public String password; + } + + /** + * Class for bookmarking web pages, i.e., HTTP or HTTPS URLs. + * + */ + public class URL { + public URL() { + + } + public String name = ""; + public String url = ""; + } + + /** + * Constructor + */ + public Storage() { + } + + /** + * Clear the list of rooms + */ + public void clearRooms() { + rooms.clear(); + } + + /** + * Get the list of rooms + * @return room list, can be empty but not null + */ + public Vector<Room> getRooms() { + return rooms; + } + + /** + * Add a room to the list + * @param room room, not null + */ + public void addRoom(Room room) { + rooms.add(room); + } + + /** + * Get a list of URLs + * @return URL list, can be empty but not null + */ + public Vector<URL> getURLs() { + return urls; + } + + /** + * Add a URL + * @param url rul, not null + */ + public void addURL(URL url) { + urls.add(url); + } +} diff --git a/src/com/isode/stroke/queries/DummyIQChannel.java b/src/com/isode/stroke/queries/DummyIQChannel.java new file mode 100644 index 0000000..fbd69b9 --- /dev/null +++ b/src/com/isode/stroke/queries/DummyIQChannel.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2010, Remko Tronçon + * All rights reserved. + */ +package com.isode.stroke.queries; + +import java.util.Vector; + +import com.isode.stroke.elements.IQ; + +/** + * Dummy IQ Channel + * + */ +public class DummyIQChannel extends IQChannel { + + /** + * Constructor + */ + public DummyIQChannel() {} + + @Override + public void sendIQ(IQ iq) { + iqs_.add(iq); + } + + @Override + public String getNewIQID() { + return "test-id"; + } + + @Override + public boolean isAvailable() { + return true; + } + + public Vector<IQ> iqs_ = new Vector<IQ>(); +} diff --git a/src/com/isode/stroke/queries/requests/GetPrivateStorageRequest.java b/src/com/isode/stroke/queries/requests/GetPrivateStorageRequest.java new file mode 100644 index 0000000..a453d62 --- /dev/null +++ b/src/com/isode/stroke/queries/requests/GetPrivateStorageRequest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2012, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2010, Remko Tronçon + * All rights reserved. + */ +package com.isode.stroke.queries.requests; + +import com.isode.stroke.elements.ErrorPayload; +import com.isode.stroke.elements.IQ; +import com.isode.stroke.elements.Payload; +import com.isode.stroke.elements.PrivateStorage; +import com.isode.stroke.jid.JID; +import com.isode.stroke.queries.IQRouter; +import com.isode.stroke.queries.Request; +import com.isode.stroke.signals.Signal2; + +/** + * Class representing a request to get a private storage + * + * @param <T> type extending {@link Payload} + */ +public class GetPrivateStorageRequest <T extends Payload> extends Request { + + /** + * Create the request + * @param <T> Payload Type + * @param payload object of type payload + * @param router IQ router + * @return request to get Private storage + */ + public static<T extends Payload> GetPrivateStorageRequest<T> create(T payload,IQRouter router) { + return new GetPrivateStorageRequest<T>(payload,router); + } + + private GetPrivateStorageRequest(T payload,IQRouter router) { + super(IQ.Type.Get,new JID(),new PrivateStorage(payload),router); + } + + @Override + public void handleResponse(Payload payload, ErrorPayload error) { + PrivateStorage storage = null; + if(payload instanceof PrivateStorage) { + storage = (PrivateStorage)payload; + } + if (storage != null) { + onResponse.emit((T) storage.getPayload(), error); + } + else { + onResponse.emit(null, error); + } + } + + /** + * Siganl to be notified on receiving the response for the request sent + */ + public Signal2<T, ErrorPayload> onResponse = new Signal2<T, ErrorPayload>(); +} diff --git a/src/com/isode/stroke/queries/requests/SetPrivateStorageRequest.java b/src/com/isode/stroke/queries/requests/SetPrivateStorageRequest.java new file mode 100644 index 0000000..21d753f --- /dev/null +++ b/src/com/isode/stroke/queries/requests/SetPrivateStorageRequest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2012, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2010, Remko Tronçon. + * All rights reserved. + */ +package com.isode.stroke.queries.requests; + +import com.isode.stroke.elements.ErrorPayload; +import com.isode.stroke.elements.IQ; +import com.isode.stroke.elements.Payload; +import com.isode.stroke.elements.PrivateStorage; +import com.isode.stroke.jid.JID; +import com.isode.stroke.queries.IQRouter; +import com.isode.stroke.queries.Request; +import com.isode.stroke.signals.Signal1; + +/** + * Class representing a request to set a private storage + * + * @param <T> type extending {@link Payload} + */ +public class SetPrivateStorageRequest<T extends Payload> extends Request { + + /** + * Create the request + * @param <T> Payload Type + * @param payload object of type payload + * @param router IQ router + * @return request to set Private storage + */ + public static<T extends Payload> SetPrivateStorageRequest<T> create(T payload, IQRouter router) { + return new SetPrivateStorageRequest<T>(payload, router); + } + + private SetPrivateStorageRequest(T payload, IQRouter router) { + super(IQ.Type.Set, new JID(), new PrivateStorage(payload), router); + } + + @Override + public void handleResponse(Payload p, ErrorPayload error) { + onResponse.emit(error); + } + + public Signal1<ErrorPayload> onResponse = new Signal1<ErrorPayload>(); +} |