1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-14 16:22:07 +01:00
Smack/experimental/source/org/jivesoftware/smackx/carbons/Carbon.java
rcollier 33e2094fe4 SMACK-434 (and 529) Added support for experimental code, that is XEP's that have not yet made it to the draft state.
This new souce directory and artifact initially contains message carbons (XEP-0280) code provided by George Lukas.


git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/branches/smack_3_4_0@13882 b35dd754-fafc-0310-a699-88a17e54d16e
2014-01-31 03:41:25 +00:00

117 lines
3.3 KiB
Java

/**
* Copyright 2013 Georg Lukas
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.carbons;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.forward.Forwarded;
/**
* Packet extension for XEP-0280: Message Carbons. The extension
* <a href="http://xmpp.org/extensions/xep-0280.html">XEP-0280</a> is
* meant to synchronize a message flow to multiple presences of a user.
*
* <p>
* It accomplishes this by wrapping a {@link Forwarded} packet in a <b>sent</b>
* or <b>received</b> element
*
* @author Georg Lukas
*/
public class Carbon implements PacketExtension {
public static final String NAMESPACE = "urn:xmpp:carbons:2";
private Direction dir;
private Forwarded fwd;
/**
* Construct a Carbon message extension.
*
* @param dir Determines if the carbon is being sent/received
* @param fwd The forwarded message.
*/
public Carbon(Direction dir, Forwarded fwd) {
this.dir = dir;
this.fwd = fwd;
}
/**
* Get the direction (sent or received) of the carbon.
*
* @return the {@link Direction} of the carbon.
*/
public Direction getDirection() {
return dir;
}
/**
* Get the forwarded packet.
*
* @return the {@link Forwarded} message contained in this Carbon.
*/
public Forwarded getForwarded() {
return fwd;
}
@Override
public String getElementName() {
return dir.toString();
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public String toXML() {
StringBuilder buf = new StringBuilder();
buf.append("<").append(getElementName()).append(" xmlns=\"")
.append(getNamespace()).append("\">");
buf.append(fwd.toXML());
buf.append("</").append(getElementName()).append(">");
return buf.toString();
}
/**
* Defines the direction of a {@link Carbon} message.
*/
public static enum Direction {
received,
sent
}
/**
* Packet extension indicating that a message may not be carbon-copied. Adding this
* extension to any message will disallow that message from being copied.
*/
public static class Private implements PacketExtension {
public static final String ELEMENT = "private";
public String getElementName() {
return ELEMENT;
}
public String getNamespace() {
return Carbon.NAMESPACE;
}
public String toXML() {
return "<" + ELEMENT + " xmlns=\"" + Carbon.NAMESPACE + "\"/>";
}
}
}