# HG changeset patch # User Da Risk # Date 1285022073 -7200 # Node ID 9093c2de4159b90149fed82f6eb4efddf8cfcbfc # Parent 1eefc5da624a5f21312dd7ea221009041b0602ae Documentation. diff -r 1eefc5da624a -r 9093c2de4159 src/com/beem/project/beem/smack/avatar/AvatarCache.java --- a/src/com/beem/project/beem/smack/avatar/AvatarCache.java Mon Sep 20 23:02:55 2010 +0200 +++ b/src/com/beem/project/beem/smack/avatar/AvatarCache.java Tue Sep 21 00:34:33 2010 +0200 @@ -1,13 +1,90 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ package com.beem.project.beem.smack.avatar; import java.io.IOException; import java.io.InputStream; +/** + * Interface for an AvatarCache. + * This can be improved to a generic cache. + * + */ public interface AvatarCache { + /** + * Put some datas in cache. + * + * @param id the key id of the data + * @param data the datato cache + * @throws IOException if an IO error occurs while caching the data + */ void put(String id, byte[] data) throws IOException; + + /** + * Put some datas in cache. + * + * @param id the key id of the data + * @param data an InputStream to the data to cache + * @throws IOException if an IO error occurs while caching the data + */ void put(String id, InputStream data) throws IOException; + /** + * Get some data from the cache. + * + * @param id the id of the data to get + * @return the cached data + * @throws IOException if an IO error occurs while geting the data + */ byte[] get(String id) throws IOException; + + /** + * Test if a data is in cache. + * + * @param id the id of the data + * @return true if data is in cache false otherwise + */ boolean contains(String id); } diff -r 1eefc5da624a -r 9093c2de4159 src/com/beem/project/beem/smack/avatar/AvatarManager.java --- a/src/com/beem/project/beem/smack/avatar/AvatarManager.java Mon Sep 20 23:02:55 2010 +0200 +++ b/src/com/beem/project/beem/smack/avatar/AvatarManager.java Tue Sep 21 00:34:33 2010 +0200 @@ -1,4 +1,46 @@ +/* + BEEM is a videoconference application on the Android Platform. + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ package com.beem.project.beem.smack.avatar; import android.util.Log; @@ -10,21 +52,33 @@ import java.util.List; -import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.Connection; import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smackx.pubsub.Item; import org.jivesoftware.smackx.pubsub.PayloadItem; import com.beem.project.beem.smack.pep.PepSubManager; import com.beem.project.beem.smack.pep.PEPListener; +/** + * This class deals with the avatar data. + * It can be configured to auto retrieve the avatar and put it in cache. + * + */ public class AvatarManager { private PepSubManager mPep; - private XMPPConnection mCon; + private Connection mCon; private boolean mAutoDownload; private AvatarCache mCache; - public AvatarManager(XMPPConnection con, AvatarCache cache, boolean autoDownload) { + /** + * Create an AvatarManager. + * + * @param con the connection + * @param cache the cache which will store the avatars + * @param autoDownload true to enable auto download of avatars + */ + public AvatarManager(final Connection con, final AvatarCache cache, final boolean autoDownload) { Log.d("AvatarMgr", "creation"); mCon = con; mPep = new PepSubManager(mCon); @@ -34,6 +88,12 @@ mPep.addPEPListener(new Listener()); } + /** + * Get an avatar from the cache. + * + * @param avatarId the id of the avatar + * @return the avatar or null if it cannot be retrieved from the cache + */ public byte[] getAvatar(String avatarId) { try { return mCache.get(avatarId); @@ -42,39 +102,61 @@ } } + /** + * Select the avatar to download. + * Subclass should override this method to take control over the selection process. + * This implementation select the first element. + * + * @param available list of the avatar metadata information + * @return the metadata of the avatar to download + */ protected Info selectAvatar(List available) { return available.get(0); } + /** + * Doawload an avatar. + * + * @param from The jid of the user + * @param info the metadata information of the avatar to download + */ private void downloadAvatar(String from, Info info) { try { AvatarRetriever retriever = AvatarRetrieverFactory.getRetriever(mCon, from, info); byte[] avatar = retriever.getAvatar(); - // TODO verifier le hash avant de stocker ? + // TODO check the hash before store mCache.put(info.getId(), avatar); } catch (IOException e) { Log.d("AvatarMgr", "Error while downloading avatar", e); } } + /** + * A listener to PEPEevent. + */ private class Listener implements PEPListener { + + /** + * Create a listener. + */ + public Listener() { + } + @Override public void eventReceived(String from, String node, List items) { - - Log.d("AvatarMgr", "Received pep event "); - Item i = items.get(0); - if (i instanceof PayloadItem) { - PayloadItem pi = (PayloadItem) i; - PacketExtension ex = pi.getPayload(); - if (ex instanceof AvatarMetadataExtension) { - Log.d("AvatarMgr", "Received avatar meta"); - AvatarMetadataExtension ext = (AvatarMetadataExtension) ex; - Info info = selectAvatar(ext.getInfos()); - if (!mCache.contains(info.getId())) - downloadAvatar(from, info); - } - } + Log.d("AvatarMgr", "Received pep event "); + Item i = items.get(0); + if (i instanceof PayloadItem) { + PayloadItem pi = (PayloadItem) i; + PacketExtension ex = pi.getPayload(); + if (ex instanceof AvatarMetadataExtension) { + Log.d("AvatarMgr", "Received avatar meta"); + AvatarMetadataExtension ext = (AvatarMetadataExtension) ex; + Info info = selectAvatar(ext.getInfos()); + if (!mCache.contains(info.getId())) + downloadAvatar(from, info); + } + } } } - } diff -r 1eefc5da624a -r 9093c2de4159 src/com/beem/project/beem/smack/avatar/AvatarRetriever.java --- a/src/com/beem/project/beem/smack/avatar/AvatarRetriever.java Mon Sep 20 23:02:55 2010 +0200 +++ b/src/com/beem/project/beem/smack/avatar/AvatarRetriever.java Tue Sep 21 00:34:33 2010 +0200 @@ -1,8 +1,60 @@ +/* + BEEM is a videoconference application on the Android Platform. + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ package com.beem.project.beem.smack.avatar; import java.io.IOException; +/** + * Interface for an AvatarRetriever. + */ public interface AvatarRetriever { - public byte[] getAvatar() throws IOException; + + /** + * Retrieve the avatar. + * + * @return the avatar + * @throws IOException if an IO error occurs while retrieving the avatar + */ + byte[] getAvatar() throws IOException; } diff -r 1eefc5da624a -r 9093c2de4159 src/com/beem/project/beem/smack/avatar/AvatarRetrieverFactory.java --- a/src/com/beem/project/beem/smack/avatar/AvatarRetrieverFactory.java Mon Sep 20 23:02:55 2010 +0200 +++ b/src/com/beem/project/beem/smack/avatar/AvatarRetrieverFactory.java Tue Sep 21 00:34:33 2010 +0200 @@ -1,12 +1,71 @@ +/* + BEEM is a videoconference application on the Android Platform. + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ package com.beem.project.beem.smack.avatar; import com.beem.project.beem.smack.AvatarMetadataExtension.Info; -import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.Connection; +/** + * A factory for AvatarRetriever. + */ public class AvatarRetrieverFactory { - public static AvatarRetriever getRetriever(XMPPConnection con, String from, Info info) { + /** + * Private constructor. + */ + private AvatarRetrieverFactory() { + } + + /** + * Get a AvatarRetriever to retrieve this avatar. + * + * @param con the connection + * @param from the user which own the avatar + * @param info the metadata information of the avatar to retrieve + * @return an AvatarRetriever null if none can retrieve this avatar + */ + public static AvatarRetriever getRetriever(Connection con, String from, Info info) { String url = info.getUrl(); if (url != null) { return new HttpAvatarRetriever(url); diff -r 1eefc5da624a -r 9093c2de4159 src/com/beem/project/beem/smack/avatar/FileAvatarCache.java --- a/src/com/beem/project/beem/smack/avatar/FileAvatarCache.java Mon Sep 20 23:02:55 2010 +0200 +++ b/src/com/beem/project/beem/smack/avatar/FileAvatarCache.java Tue Sep 21 00:34:33 2010 +0200 @@ -1,3 +1,46 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ package com.beem.project.beem.smack.avatar; import java.io.BufferedInputStream; @@ -8,14 +51,21 @@ import java.io.FileOutputStream; import java.io.InputStream; import java.io.IOException; -import java.io.IOException; import java.io.OutputStream; +/** + * An implementation of an AvatarCache which store the data of the filesystem. + */ public class FileAvatarCache implements AvatarCache { private File mStoreDir; - public FileAvatarCache(File storedir) { + /** + * Create a FileAvatarCache. + * + * @param storedir The directory used to store the data. + */ + public FileAvatarCache(final File storedir) { if (storedir.exists() && !storedir.isDirectory()) throw new IllegalArgumentException("The store directory must be a directory"); mStoreDir = storedir; diff -r 1eefc5da624a -r 9093c2de4159 src/com/beem/project/beem/smack/avatar/HttpAvatarRetriever.java --- a/src/com/beem/project/beem/smack/avatar/HttpAvatarRetriever.java Mon Sep 20 23:02:55 2010 +0200 +++ b/src/com/beem/project/beem/smack/avatar/HttpAvatarRetriever.java Tue Sep 21 00:34:33 2010 +0200 @@ -1,4 +1,46 @@ +/* + BEEM is a videoconference application on the Android Platform. + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ package com.beem.project.beem.smack.avatar; import java.io.InputStream; @@ -6,16 +48,29 @@ import java.io.IOException; import java.net.URL; +/** + * An AvatarRetriever which retrieve the avatar over HTTP. + */ public class HttpAvatarRetriever implements AvatarRetriever { private URL mUrl; private String mUrlString; - public HttpAvatarRetriever(URL url) { + /** + * Create a HttpAvatarRetriever. + * + * @param url the url of the avatar to download. + */ + public HttpAvatarRetriever(final URL url) { mUrl = url; } - public HttpAvatarRetriever(String url) { + /** + * Create a HttpAvatarRetriever. + * + * @param url the url of the avatar to download. + */ + public HttpAvatarRetriever(final String url) { mUrlString = url; } diff -r 1eefc5da624a -r 9093c2de4159 src/com/beem/project/beem/smack/avatar/XmppAvatarRetriever.java --- a/src/com/beem/project/beem/smack/avatar/XmppAvatarRetriever.java Mon Sep 20 23:02:55 2010 +0200 +++ b/src/com/beem/project/beem/smack/avatar/XmppAvatarRetriever.java Tue Sep 21 00:34:33 2010 +0200 @@ -1,22 +1,68 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ package com.beem.project.beem.smack.avatar; import java.util.List; import java.util.Arrays; -import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.Connection; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smackx.pubsub.PubSubManager; import org.jivesoftware.smackx.pubsub.Node; import org.jivesoftware.smackx.pubsub.LeafNode; import org.jivesoftware.smackx.pubsub.Item; +/** + * An AvatarRetriever which retrieve the avatar over the XMPP connection. + */ public class XmppAvatarRetriever implements AvatarRetriever { + private static String AVATARDATANODE = "urn:xmpp:avatar:data"; private PubSubManager mPubsub; private String mFrom; private String mId; - private static String AVATARDATANODE = "urn:xmpp:avatar:data"; - public XmppAvatarRetriever(XMPPConnection con, String from, String id) { + public XmppAvatarRetriever(final Connection con, final String from, final String id) { mPubsub = new PubSubManager(con, from); mFrom = from; mId = id; @@ -29,13 +75,12 @@ if (node instanceof LeafNode) { LeafNode lnode = (LeafNode) node; List items = lnode.getItems(Arrays.asList(mId)); - // TODO la suite + // TODO the rest ^^ } - } catch (XMPPException e) { return null; } - return null; + return null; } } diff -r 1eefc5da624a -r 9093c2de4159 src/com/beem/project/beem/smack/avatar/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/avatar/package-info.java Tue Sep 21 00:34:33 2010 +0200 @@ -0,0 +1,48 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ + +/** + * This package contains implementation of XEP-0084 User Avatar. + */ +package com.beem.project.beem.smack.avatar; diff -r 1eefc5da624a -r 9093c2de4159 src/com/beem/project/beem/smack/pep/PEPListener.java --- a/src/com/beem/project/beem/smack/pep/PEPListener.java Mon Sep 20 23:02:55 2010 +0200 +++ b/src/com/beem/project/beem/smack/pep/PEPListener.java Tue Sep 21 00:34:33 2010 +0200 @@ -1,10 +1,63 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ package com.beem.project.beem.smack.pep; import org.jivesoftware.smackx.pubsub.Item; import java.util.List; +/** + * A listener that is fired anytime a PEP event message is received. + */ public interface PEPListener { + /** + * Called when PEP events are received. + * + * @param from the JID of the user who send the event + * @param node the node of the items in the event + * @param items the different items of the event + */ void eventReceived(String from, String node, List items); } diff -r 1eefc5da624a -r 9093c2de4159 src/com/beem/project/beem/smack/pep/PepSubManager.java --- a/src/com/beem/project/beem/smack/pep/PepSubManager.java Mon Sep 20 23:02:55 2010 +0200 +++ b/src/com/beem/project/beem/smack/pep/PepSubManager.java Tue Sep 21 00:34:33 2010 +0200 @@ -1,51 +1,123 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ package com.beem.project.beem.smack.pep; +import java.util.ArrayList; +import java.util.List; + import org.jivesoftware.smack.Connection; +import org.jivesoftware.smack.filter.PacketExtensionFilter; +import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.PacketListener; import org.jivesoftware.smack.packet.Packet; -import org.jivesoftware.smack.packet.PacketExtension; -import org.jivesoftware.smack.filter.PacketFilter; -import org.jivesoftware.smack.filter.PacketExtensionFilter; -import org.jivesoftware.smackx.pubsub.PubSubManager; -import org.jivesoftware.smackx.pubsub.PayloadItem; +import org.jivesoftware.smackx.pubsub.EventElement; +import org.jivesoftware.smackx.pubsub.EventElementType; import org.jivesoftware.smackx.pubsub.Item; import org.jivesoftware.smackx.pubsub.ItemsExtension; -import org.jivesoftware.smackx.pubsub.EventElement; -import org.jivesoftware.smackx.pubsub.EventElementType; - -import java.util.List; -import java.util.ArrayList; +import org.jivesoftware.smackx.pubsub.PubSubManager; +/** + * Little extension of {@link PubSubManager} which allows to add {@link PEPListener}. + * + */ public class PepSubManager extends PubSubManager { - private List pepListeners = new ArrayList(); - private PacketFilter packetFilter = new PacketExtensionFilter("event", "http://jabber.org/protocol/pubsub#event"); + private List mPepListeners = new ArrayList(); + private PacketFilter mPacketFilter = new PacketExtensionFilter("event", "http://jabber.org/protocol/pubsub#event"); - public PepSubManager(Connection connection) { + /** + * Create a PepSubManager. + * + * @param connection the connection + */ + public PepSubManager(final Connection connection) { super(connection); init(connection); } - public PepSubManager(Connection connection, String toAddress) { + /** + * Create a PepSubManager associated to the specified connection where the pubsub + * requests require a specific to address for packets. + * + * @param connection the connection + * @param toAddress The pubsub specific to address (required for some servers) + */ + public PepSubManager(final Connection connection, final String toAddress) { super(connection, toAddress); init(connection); } + /** + * Add a listener to PEP event. + * + * @param listener the listener + */ public void addPEPListener(PEPListener listener) { - if (!pepListeners.contains(listener)) - pepListeners.add(listener); + if (!mPepListeners.contains(listener)) + mPepListeners.add(listener); } + /** + * Remove a listener to PEP event. + * + * @param listener the listener + */ public void removePEPListener(PEPListener listener) { - pepListeners.remove(listener); + mPepListeners.remove(listener); } + /** + * Initialize the PepSubManager. + * + * @param con the connection + */ private void init(Connection con) { PacketListener packetListener = new PacketListener() { @Override public void processPacket(Packet packet) { EventElement e = (EventElement) packet.getExtension("event", "http://jabber.org/protocol/pubsub#event"); - if(e.getEventType() != EventElementType.items) + if (e.getEventType() != EventElementType.items) return; ItemsExtension it = (ItemsExtension) e.getEvent(); if (it.getItemsElementType() != ItemsExtension.ItemsElementType.items) @@ -54,11 +126,18 @@ firePEPListeners(packet.getFrom(), it.getNode(), items); } }; - con.addPacketListener(packetListener, packetFilter); + con.addPacketListener(packetListener, mPacketFilter); } + /** + * Fire the PEP listeners. + * + * @param from the JID of the user who send the event + * @param node the node of the items in the event + * @param items the different items of the event + */ private void firePEPListeners(String from, String node, List items) { - for(PEPListener listener : pepListeners) { + for (PEPListener listener : mPepListeners) { listener.eventReceived(from, node, items); } } diff -r 1eefc5da624a -r 9093c2de4159 src/com/beem/project/beem/smack/pep/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/smack/pep/package-info.java Tue Sep 21 00:34:33 2010 +0200 @@ -0,0 +1,49 @@ +/* + BEEM is a videoconference application on the Android Platform. + + Copyright (C) 2009 by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + This file is part of BEEM. + + BEEM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + BEEM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with BEEM. If not, see . + + Please send bug reports with examples or suggestions to + contact@beem-project.com or http://dev.beem-project.com/ + + Epitech, hereby disclaims all copyright interest in the program "Beem" + written by Frederic-Charles Barthelery, + Jean-Manuel Da Silva, + Nikita Kozlov, + Philippe Lago, + Jean Baptiste Vergely, + Vincent Veronis. + + Nicolas Sadirac, November 26, 2009 + President of Epitech. + + Flavien Astraud, November 26, 2009 + Head of the EIP Laboratory. + +*/ + +/** + * This package contains an implementation of XEP-0163 Personnal Eventing Protocol based on the pubsub implementation. + */ +package com.beem.project.beem.smack.pep; +