001/**
002 *
003 * Copyright 2020 Paul Schaub
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.message_retraction.element;
018
019import java.util.Date;
020
021import org.jivesoftware.smack.packet.ExtensionElement;
022import org.jivesoftware.smack.packet.XmlEnvironment;
023import org.jivesoftware.smack.util.XmlStringBuilder;
024import org.jivesoftware.smackx.sid.element.OriginIdElement;
025
026public class RetractedElement implements ExtensionElement {
027
028    public static final String ELEMENT = "retracted";
029    public static final String ATTR_STAMP = "stamp";
030
031    private final Date stamp;
032    private final OriginIdElement originId;
033
034    public RetractedElement(Date stamp, OriginIdElement originId) {
035        this.stamp = stamp;
036        this.originId = originId;
037    }
038
039    public Date getStamp() {
040        return stamp;
041    }
042
043    public OriginIdElement getOriginId() {
044        return originId;
045    }
046
047    @Override
048    public String getNamespace() {
049        return RetractElement.NAMESPACE;
050    }
051
052    @Override
053    public String getElementName() {
054        return ELEMENT;
055    }
056
057    @Override
058    public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
059        return new XmlStringBuilder(this)
060                .attribute(ATTR_STAMP, getStamp())
061                .rightAngleBracket()
062                .append(getOriginId())
063                .closeElement(this);
064    }
065}