RetractedElement.java

  1. /**
  2.  *
  3.  * Copyright 2020 Paul Schaub
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.message_retraction.element;

  18. import java.util.Date;

  19. import javax.xml.namespace.QName;

  20. import org.jivesoftware.smack.packet.ExtensionElement;
  21. import org.jivesoftware.smack.packet.XmlEnvironment;
  22. import org.jivesoftware.smack.util.XmlStringBuilder;

  23. import org.jivesoftware.smackx.sid.element.OriginIdElement;

  24. public class RetractedElement implements ExtensionElement {

  25.     public static final String ELEMENT = "retracted";
  26.     public static final QName QNAME = new QName(RetractElement.NAMESPACE, ELEMENT);
  27.     public static final String ATTR_STAMP = "stamp";

  28.     private final Date stamp;
  29.     private final OriginIdElement originId;

  30.     public RetractedElement(Date stamp, OriginIdElement originId) {
  31.         this.stamp = stamp;
  32.         this.originId = originId;
  33.     }

  34.     public Date getStamp() {
  35.         return stamp;
  36.     }

  37.     public OriginIdElement getOriginId() {
  38.         return originId;
  39.     }

  40.     @Override
  41.     public String getNamespace() {
  42.         return QNAME.getNamespaceURI();
  43.     }

  44.     @Override
  45.     public String getElementName() {
  46.         return QNAME.getLocalPart();
  47.     }

  48.     @Override
  49.     public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
  50.         return new XmlStringBuilder(this)
  51.                 .attribute(ATTR_STAMP, getStamp())
  52.                 .rightAngleBracket()
  53.                 .append(getOriginId())
  54.                 .closeElement(this);
  55.     }
  56. }