From 4c6085ca1475c7a3d6f92b4e6950c325c19d57bf Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Tue, 4 Dec 2007 15:20:30 +0000 Subject: "leave" extension added to jabber whiteboard extensions --- .../whiteboard/WhiteboardObjectJabberProvider.java | 37 ++- .../WhiteboardObjectPacketExtension.java | 283 ++++++++++++++++++++ .../WhiteboardObjectPacketExtensionImpl.java | 285 --------------------- .../WhiteboardSessionPacketExtension.java | 217 ++++++++++++++++ 4 files changed, 524 insertions(+), 298 deletions(-) create mode 100644 src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardObjectPacketExtension.java delete mode 100644 src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardObjectPacketExtensionImpl.java create mode 100644 src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardSessionPacketExtension.java (limited to 'src/net/java/sip/communicator') diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardObjectJabberProvider.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardObjectJabberProvider.java index c20724e..2f1b8e2 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardObjectJabberProvider.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardObjectJabberProvider.java @@ -38,14 +38,19 @@ public class WhiteboardObjectJabberProvider public PacketExtension parseExtension (XmlPullParser parser) throws Exception { + PacketExtension extension = null; + StringBuilder sb = new StringBuilder (); boolean done = false; while (!done) { int eventType = parser.next (); - if (eventType == XmlPullParser.START_TAG && - !parser.getName ().equals ( - WhiteboardObjectPacketExtensionImpl.ELEMENT_NAME)) + + if (eventType == XmlPullParser.START_TAG + && !parser.getName ().equals ( + WhiteboardObjectPacketExtension.ELEMENT_NAME) + && !parser.getName ().equals ( + WhiteboardSessionPacketExtension.ELEMENT_NAME)) { sb.append (parser.getText ()); } @@ -53,26 +58,32 @@ public class WhiteboardObjectJabberProvider { sb.append (parser.getText ()); } - else if (eventType == XmlPullParser.END_TAG && - parser.getName ().equals ("image")) + else if (eventType == XmlPullParser.END_TAG + && parser.getName ().equals ("image")) { sb.append (parser.getText ()); } - else if (eventType == XmlPullParser.END_TAG && - parser.getName ().equals ("text")) + else if (eventType == XmlPullParser.END_TAG + && parser.getName ().equals ("text")) { sb.append (parser.getText ()); } - else if (eventType == XmlPullParser.END_TAG && - parser.getName ().equals ( - WhiteboardObjectPacketExtensionImpl.ELEMENT_NAME)) + else if (eventType == XmlPullParser.END_TAG + && parser.getName ().equals ( + WhiteboardObjectPacketExtension.ELEMENT_NAME)) + { + extension = new WhiteboardObjectPacketExtension(sb.toString ()); + done = true; + } + else if (eventType == XmlPullParser.END_TAG + && parser.getName ().equals ( + WhiteboardSessionPacketExtension.ELEMENT_NAME)) { + extension = new WhiteboardSessionPacketExtension(sb.toString ()); done = true; } } - WhiteboardObjectPacketExtensionImpl wbo - = new WhiteboardObjectPacketExtensionImpl(sb.toString ()); - return wbo; + return extension; } } \ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardObjectPacketExtension.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardObjectPacketExtension.java new file mode 100644 index 0000000..f5ed288 --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardObjectPacketExtension.java @@ -0,0 +1,283 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ + +package net.java.sip.communicator.impl.protocol.jabber.extensions.whiteboard; + +import java.io.*; + +import javax.xml.parsers.*; + +import net.java.sip.communicator.util.*; + +import org.jivesoftware.smack.packet.*; +import org.w3c.dom.*; + +/** + * WhiteboardObjectPacketExtension + * + * @author Julien Waechter + */ +public class WhiteboardObjectPacketExtension implements PacketExtension +{ + private static final Logger logger = + Logger.getLogger (WhiteboardObjectPacketExtension.class); + + /** + * The name of the XML element used for transport of white-board parameters. + */ + public static final String ELEMENT_NAME = "xObject"; + + /** + * The names XMPP space that the white-board elements belong to. + */ + public static final String NAMESPACE = "http://jabber.org/protocol/swb"; + + /** + * A type string constant indicating that the current object must be deleted. + */ + public static final String ACTION_DELETE = "DELETE"; + + /** + * A type string constant indicating that the current object must be drawn. + */ + public static final String ACTION_DRAW = "DRAW"; + + /** + * A type string constant indicating that the current object must be moved. + */ + public static final String ACTION_MOVE = "MOVE"; + + /** + * The current WhiteboardObject to be sent. + */ + private WhiteboardObjectJabberImpl whiteboardObject; + + /** + * The current action associated with the WhiteboardObject. + */ + private String action; + + /** + * The identifier of the WhiteboardObject to be treated + * When we receive a delete message, + * we've only the identifier of the WhiteboardObject + */ + private String whiteboardObjectID; + + /** + * Default WhiteboardObjectPacketExtension constructor. + */ + public WhiteboardObjectPacketExtension () + { + this.action = ACTION_DRAW; + } + + /** + * WhiteboardObjectPacketExtension constructor. + * + * @param id Identifier of the WhiteboardObject to be treated + * @param action The current action associated with the WhiteboardObject. + */ + public WhiteboardObjectPacketExtension (String id, String action) + { + this.whiteboardObjectID = id; + this.action = action; + } + + /** + * Constructs and initializes a WhiteboardObjectPacketExtension. + * + * @param whiteboardObject The WhiteboardObject to be treated + * @param action The current action associated with the WhiteboardObject. + */ + public WhiteboardObjectPacketExtension ( + WhiteboardObjectJabberImpl whiteboardObject, String action) + { + this.whiteboardObject = whiteboardObject; + this.action = action; + } + + /** + * WhiteboardObjectPacketExtension constructor with a XML-SVG String. + * + * @param xml XML-SVG String + */ + public WhiteboardObjectPacketExtension (String xml) + { + DocumentBuilderFactory factory = + DocumentBuilderFactory.newInstance (); + DocumentBuilder builder; + try + { + builder = factory.newDocumentBuilder (); + InputStream in = new ByteArrayInputStream (xml.getBytes ()); + Document doc = builder.parse (in); + + Element e = doc.getDocumentElement (); + String elementName = e.getNodeName (); + this.action = WhiteboardObjectPacketExtension.ACTION_DRAW; + + if (elementName.equals ("rect")) + { + //we have a rectangle + whiteboardObject = new WhiteboardObjectRectJabberImpl (xml); + } + else if (elementName.equals ("circle")) + { + //we have a circle + whiteboardObject = new WhiteboardObjectCircleJabberImpl (xml); + } + else if (elementName.equals ("path")) + { + //we have a path + whiteboardObject = new WhiteboardObjectPathJabberImpl (xml); + } + else if (elementName.equals ("polyline")) + { + //we have polyline + whiteboardObject = new WhiteboardObjectPolyLineJabberImpl (xml); + } + else if (elementName.equals ("polygon")) + { + //we have a polygon + whiteboardObject = new WhiteboardObjectPolygonJabberImpl (xml); + } + else if (elementName.equals ("line")) + { + //we have a line + whiteboardObject = new WhiteboardObjectLineJabberImpl (xml); + } + else if (elementName.equals ("text")) + { + //we have a text + whiteboardObject = new WhiteboardObjectTextJabberImpl (xml); + } + else if (elementName.equals ("image")) + { + //we have an image + whiteboardObject = new WhiteboardObjectImageJabberImpl (xml); + } + else if (elementName.equals ("delete")) + { + //we have a delete action + this.setWhiteboardObjectID (e.getAttribute ("id")); + this.action = WhiteboardObjectPacketExtension.ACTION_DELETE; + } + else //we have a problem :p + logger.debug ("elementName unknow\n"); + } + catch (ParserConfigurationException ex) + { + logger.debug ("Problem WhiteboardObject : " + xml, ex); + } + catch (IOException ex) + { + logger.debug ("Problem WhiteboardObject : " + xml, ex); + } + catch (Exception ex) + { + logger.debug ("Problem WhiteboardObject : " + xml, ex); + } + + } + + /** + * Returns the root element name. + * + * @return the element name. + */ + public String getElementName () + { + return ELEMENT_NAME; + } + + /** + * Returns the root element XML namespace. + * + * @return the namespace. + */ + public String getNamespace () + { + return NAMESPACE; + } + + /** + * Returns the XML representation of the WhiteboardObject + * + * @return the WhiteboardObject as XML. + */ + public String toXML () + { + String s=""; + if(getAction ().equals ( + WhiteboardObjectPacketExtension.ACTION_DELETE)) + { + s = ""; + s = s.replaceAll ("#i", getWhiteboardObjectID()); + } + else + s = getWhiteboardObject ().toXML (); + + return "<" + WhiteboardObjectPacketExtension.ELEMENT_NAME + + " xmlns=\"" + WhiteboardObjectPacketExtension.NAMESPACE + + "\">"+s+""; + } + + /** + * Returns the current action associated with the WhiteboardObject to send. + * (DELETE - DRAW - MOVE) + * + * @return current action. + */ + public String getAction () + { + return action; + } + + /** + * Sets the action associated with the WhiteboardObject to send. + * (DELETE - DRAW - MOVE) + * + * @param action the action associated with the WhiteboardObject to send. + */ + public void setAction (String action) + { + this.action = action; + } + + /** + * Returns the current WhiteboardObject to be sent. + * + * @return WhiteboardObject to be sent + */ + public WhiteboardObjectJabberImpl getWhiteboardObject () + { + return whiteboardObject; + } + + /** + * Returns the current WhiteboardObject's identifier to be sent. + * (For a delete WhiteboardObject message) + * + * @return WhiteboardObject's identifier + */ + public String getWhiteboardObjectID () + { + return whiteboardObjectID; + } + + /** + * Sets the current WhiteboardObject's identifier to be sent. + * (For a delete WhiteboardObject message) + * + * @param objectID WhiteboardObject's identifier + */ + public void setWhiteboardObjectID (String objectID) + { + this.whiteboardObjectID = objectID; + } +} \ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardObjectPacketExtensionImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardObjectPacketExtensionImpl.java deleted file mode 100644 index 7e110fc..0000000 --- a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardObjectPacketExtensionImpl.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. - * - * Distributable under LGPL license. - * See terms of license at gnu.org. - */ - -package net.java.sip.communicator.impl.protocol.jabber.extensions.whiteboard; - -import java.io.*; - -import javax.xml.parsers.*; - -import net.java.sip.communicator.util.*; - -import org.jivesoftware.smack.packet.*; -import org.w3c.dom.*; - -/** - * WhiteboardObjectPacketExtensionImpl - * - * @author Julien Waechter - */ -public class WhiteboardObjectPacketExtensionImpl implements PacketExtension -{ - private static final Logger logger = - Logger.getLogger (WhiteboardObjectPacketExtensionImpl.class); - - /** - * The name of the XML element used for transport of white-board parameters. - */ - public static final String ELEMENT_NAME = "x"; - - /** - * The names XMPP space that the white-board elements belong to. - */ - public static final String NAMESPACE = "http://jabber.org/protocol/swb"; - - /** - * A type string constant indicating that the current object must be deleted. - */ - public static final String ACTION_DELETE = "DELETE"; - - /** - * A type string constant indicating that the current object must be drawn. - */ - public static final String ACTION_DRAW = "DRAW"; - - /** - * A type string constant indicating that the current object must be moved. - */ - public static final String ACTION_MOVE = "MOVE"; - - /** - * The current WhiteboardObject to be sent. - */ - private WhiteboardObjectJabberImpl whiteboardObject; - - /** - * The current action associated with the WhiteboardObject. - */ - private String action; - - /** - * The identifier of the WhiteboardObject to be treated - * When we receive a delete message, - * we've only the identifier of the WhiteboardObject - */ - private String whiteboardObjectID; - - /** - * Default WhiteboardObjectPacketExtensionImpl constructor. - */ - public WhiteboardObjectPacketExtensionImpl () - { - this.action = ACTION_DRAW; - } - - /** - * WhiteboardObjectPacketExtensionImpl constructor. - * - * @param id Identifier of the WhiteboardObject to be treated - * @param action The current action associated with the WhiteboardObject. - */ - public WhiteboardObjectPacketExtensionImpl (String id, String action) - { - this.whiteboardObjectID = id; - this.action = action; - } - - /** - * Constructs and initializes a WhiteboardObjectPacketExtension. - * - * @param whiteboardObject The WhiteboardObject to be treated - * @param action The current action associated with the WhiteboardObject. - */ - public WhiteboardObjectPacketExtensionImpl ( - WhiteboardObjectJabberImpl whiteboardObject, String action) - { - this.whiteboardObject = whiteboardObject; - this.action = action; - } - - /** - * WhiteboardObjectPacketExtensionImpl constructor with a XML-SVG String. - * - * @param xml XML-SVG String - */ - public WhiteboardObjectPacketExtensionImpl (String xml) - { - DocumentBuilderFactory factory = - DocumentBuilderFactory.newInstance (); - DocumentBuilder builder; - try - { - builder = factory.newDocumentBuilder (); - InputStream in = new ByteArrayInputStream (xml.getBytes ()); - Document doc = builder.parse (in); - - Element e = doc.getDocumentElement (); - String elementName = e.getNodeName (); - this.action = WhiteboardObjectPacketExtensionImpl.ACTION_DRAW; - - if (elementName.equals ("rect")) - { - //we have a rectangle - whiteboardObject = new WhiteboardObjectRectJabberImpl (xml); - } - else if (elementName.equals ("circle")) - { - //we have a circle - whiteboardObject = new WhiteboardObjectCircleJabberImpl (xml); - } - else if (elementName.equals ("path")) - { - //we have a path - whiteboardObject = new WhiteboardObjectPathJabberImpl (xml); - } - else if (elementName.equals ("polyline")) - { - //we have polyline - whiteboardObject = new WhiteboardObjectPolyLineJabberImpl (xml); - } - else if (elementName.equals ("polygon")) - { - //we have a polygon - whiteboardObject = new WhiteboardObjectPolygonJabberImpl (xml); - } - else if (elementName.equals ("line")) - { - //we have a line - whiteboardObject = new WhiteboardObjectLineJabberImpl (xml); - } - else if (elementName.equals ("text")) - { - //we have a text - whiteboardObject = new WhiteboardObjectTextJabberImpl (xml); - } - else if (elementName.equals ("image")) - { - //we have an image - whiteboardObject = new WhiteboardObjectImageJabberImpl (xml); - } - else if (elementName.equals ("delete")) - { - //we have a delete action - this.setWhiteboardObjectID (e.getAttribute ("id")); - this.action = WhiteboardObjectPacketExtensionImpl.ACTION_DELETE; - } - else //we have a problem :p - logger.debug ("elementName unknow\n"); - - System.out.println("XML =====================================" + xml); - } - catch (ParserConfigurationException ex) - { - logger.debug ("Problem WhiteboardObject : " + xml, ex); - } - catch (IOException ex) - { - logger.debug ("Problem WhiteboardObject : " + xml, ex); - } - catch (Exception ex) - { - logger.debug ("Problem WhiteboardObject : " + xml, ex); - } - - } - - /** - * Returns the root element name. - * - * @return the element name. - */ - public String getElementName () - { - return ELEMENT_NAME; - } - - /** - * Returns the root element XML namespace. - * - * @return the namespace. - */ - public String getNamespace () - { - return NAMESPACE; - } - - /** - * Returns the XML representation of the WhiteboardObject - * - * @return the WhiteboardObject as XML. - */ - public String toXML () - { - String s=""; - if(getAction ().equals ( - WhiteboardObjectPacketExtensionImpl.ACTION_DELETE)) - { - s = ""; - s = s.replaceAll ("#i", getWhiteboardObjectID()); - } - else - s = getWhiteboardObject ().toXML (); - - return "<" + WhiteboardObjectPacketExtensionImpl.ELEMENT_NAME + - " xmlns=\"" + WhiteboardObjectPacketExtensionImpl.NAMESPACE + - "\">"+s+""; - } - - /** - * Returns the current action associated with the WhiteboardObject to send. - * (DELETE - DRAW - MOVE) - * - * @return current action. - */ - public String getAction () - { - return action; - } - - /** - * Sets the action associated with the WhiteboardObject to send. - * (DELETE - DRAW - MOVE) - * - * @param action the action associated with the WhiteboardObject to send. - */ - public void setAction (String action) - { - this.action = action; - } - - /** - * Returns the current WhiteboardObject to be sent. - * - * @return WhiteboardObject to be sent - */ - public WhiteboardObjectJabberImpl getWhiteboardObject () - { - return whiteboardObject; - } - - /** - * Returns the current WhiteboardObject's identifier to be sent. - * (For a delete WhiteboardObject message) - * - * @return WhiteboardObject's identifier - */ - public String getWhiteboardObjectID () - { - return whiteboardObjectID; - } - - /** - * Sets the current WhiteboardObject's identifier to be sent. - * (For a delete WhiteboardObject message) - * - * @param objectID WhiteboardObject's identifier - */ - public void setWhiteboardObjectID (String objectID) - { - this.whiteboardObjectID = objectID; - } -} \ No newline at end of file diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardSessionPacketExtension.java b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardSessionPacketExtension.java new file mode 100644 index 0000000..258e36f --- /dev/null +++ b/src/net/java/sip/communicator/impl/protocol/jabber/extensions/whiteboard/WhiteboardSessionPacketExtension.java @@ -0,0 +1,217 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.impl.protocol.jabber.extensions.whiteboard; + +import java.io.*; + +import javax.xml.parsers.*; + +import net.java.sip.communicator.impl.protocol.jabber.*; +import net.java.sip.communicator.util.*; + +import org.jivesoftware.smack.packet.*; +import org.w3c.dom.*; + +public class WhiteboardSessionPacketExtension + implements PacketExtension +{ + private Logger logger + = Logger.getLogger(WhiteboardSessionPacketExtension.class); + + /** + * A type string constant indicating that the user would like to leave the + * current white board session. + */ + public static final String ACTION_LEAVE = "LEAVE"; + + /** + * The name of the XML element used for transport of white-board parameters. + */ + public static final String ELEMENT_NAME = "xSession"; + + /** + * The names XMPP space that the white-board elements belong to. + */ + public static final String NAMESPACE = "http://jabber.org/protocol/swb"; + + /** + * The current action associated with the WhiteboardObject. + */ + private String action; + + /** + * The white board session for which the action is about. + */ + private WhiteboardSessionJabberImpl whiteboardSession; + + /** + * The address of the contact associated with this packet extension. + */ + private String contactAddress; + + private String whiteboardSessionId; + + /** + * Constructs and initializes a WhiteboardObjectPacketExtension. + * + * @param session The WhiteboardSession to be treated + * @param contactAddress The address of the contact associated with this + * packet extension + * @param action The current action associated with the WhiteboardSession. + */ + public WhiteboardSessionPacketExtension ( + WhiteboardSessionJabberImpl session, + String contactAddress, + String action) + { + this.whiteboardSession = session; + this.whiteboardSessionId = session.getWhiteboardID(); + this.contactAddress = contactAddress; + this.action = action; + } + + /** + * WhiteboardSessionPacketExtension constructor with a XML-SVG String. + * + * @param xml XML-SVG String + */ + public WhiteboardSessionPacketExtension (String xml) + { + DocumentBuilderFactory factory = + DocumentBuilderFactory.newInstance (); + + DocumentBuilder builder; + try + { + builder = factory.newDocumentBuilder (); + InputStream in = new ByteArrayInputStream (xml.getBytes ()); + Document doc = builder.parse (in); + + Element e = doc.getDocumentElement (); + String elementName = e.getNodeName (); + + if (elementName.equals (ACTION_LEAVE)) + { + this.setWhiteboardSessionId(e.getAttribute ("id")); + this.setContactAddress(e.getAttribute ("userId")); + this.action = WhiteboardSessionPacketExtension.ACTION_LEAVE; + } + else + logger.debug ("Element name unknown!"); + } + catch (ParserConfigurationException ex) + { + logger.debug ("Problem WhiteboardSession : " + xml, ex); + } + catch (IOException ex) + { + logger.debug ("Problem WhiteboardSession : " + xml, ex); + } + catch (Exception ex) + { + logger.debug ("Problem WhiteboardSession : " + xml, ex); + } + } + + /** + * Returns the root element name. + * + * @return the element name. + */ + public String getElementName () + { + return ELEMENT_NAME; + } + + /** + * Returns the root element XML namespace. + * + * @return the namespace. + */ + public String getNamespace () + { + return NAMESPACE; + } + + public String toXML() + { + String s = ""; + + if(action.equals ( + WhiteboardSessionPacketExtension.ACTION_LEAVE)) + { + s = ""; + s = s.replaceAll ("#sessionId", whiteboardSession.getWhiteboardID()); + s = s.replaceAll ("#userId", contactAddress); + } + + return "<" + WhiteboardSessionPacketExtension.ELEMENT_NAME + + " xmlns=\"" + WhiteboardSessionPacketExtension.NAMESPACE + + "\">"+s+""; + } + + /** + * Returns the white board session identifier. + * + * @return the white board session identifier + */ + public String getWhiteboardSessionId() + { + return whiteboardSessionId; + } + + /** + * Sets the white board session identifier. + * + * @param whiteboardSessionId the identifier of the session + */ + public void setWhiteboardSessionId(String whiteboardSessionId) + { + this.whiteboardSessionId = whiteboardSessionId; + } + + /** + * Returns the action associated with this session packet extension. + * + * @return the action associated with this session packet extension. + */ + public String getAction() + { + return action; + } + + /** + * Sets the action associated with this session packet extension. + * + * @param action the action associated with this session packet extension. + */ + public void setAction(String action) + { + this.action = action; + } + + /** + * Returns the address of the contact associated with this packet extension + * + * @return the address of the contact associated with this packet extension + */ + public String getContactAddress() + { + return contactAddress; + } + + /** + * Sets the address of the contact associated with this packet extension + * + * @param contactAddress the address of the contact associated with this + * packet extension + */ + public void setContactAddress(String contactAddress) + { + this.contactAddress = contactAddress; + } +} -- cgit v1.1