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 javax.xml.namespace.QName; 022 023import org.jivesoftware.smack.packet.ExtensionElement; 024import org.jivesoftware.smack.packet.XmlEnvironment; 025import org.jivesoftware.smack.util.XmlStringBuilder; 026 027import org.jivesoftware.smackx.sid.element.OriginIdElement; 028 029public class RetractedElement implements ExtensionElement { 030 031 public static final String ELEMENT = "retracted"; 032 public static final QName QNAME = new QName(RetractElement.NAMESPACE, ELEMENT); 033 public static final String ATTR_STAMP = "stamp"; 034 035 private final Date stamp; 036 private final OriginIdElement originId; 037 038 public RetractedElement(Date stamp, OriginIdElement originId) { 039 this.stamp = stamp; 040 this.originId = originId; 041 } 042 043 public Date getStamp() { 044 return stamp; 045 } 046 047 public OriginIdElement getOriginId() { 048 return originId; 049 } 050 051 @Override 052 public String getNamespace() { 053 return QNAME.getNamespaceURI(); 054 } 055 056 @Override 057 public String getElementName() { 058 return QNAME.getLocalPart(); 059 } 060 061 @Override 062 public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) { 063 return new XmlStringBuilder(this) 064 .attribute(ATTR_STAMP, getStamp()) 065 .rightAngleBracket() 066 .append(getOriginId()) 067 .closeElement(this); 068 } 069}