SpanElement.java

  1. /**
  2.  *
  3.  * Copyright © 2018 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_markup.element;

  18. import java.util.Collections;
  19. import java.util.Set;

  20. import javax.xml.namespace.QName;

  21. import org.jivesoftware.smack.util.XmlStringBuilder;

  22. public class SpanElement extends MarkupElement.NonEmptyChildElement {

  23.     public static final String ELEMENT = "span";
  24.     public static final QName QNAME = new QName(NAMESPACE, ELEMENT);

  25.     private final Set<SpanStyle> styles;

  26.     /**
  27.      * Create a new Span element.
  28.      *
  29.      * @param start start index
  30.      * @param end end index
  31.      * @param styles list of styles that apply to this span
  32.      */
  33.     public SpanElement(int start, int end, Set<SpanStyle> styles) {
  34.         super(start, end);
  35.         this.styles = Collections.unmodifiableSet(styles);
  36.     }

  37.     /**
  38.      * Return all styles of this span.
  39.      *
  40.      * @return styles TODO javadoc me please
  41.      */
  42.     public Set<SpanStyle> getStyles() {
  43.         return styles;
  44.     }

  45.     public static final String emphasis = "emphasis";
  46.     public static final String code = "code";
  47.     public static final String deleted = "deleted";

  48.     public enum SpanStyle {
  49.         emphasis,
  50.         code,
  51.         deleted
  52.     }

  53.     @Override
  54.     public String getElementName() {
  55.         return QNAME.getLocalPart();
  56.     }

  57.     @Override
  58.     protected void appendInnerXml(XmlStringBuilder xml) {
  59.         for (SpanStyle style : getStyles()) {
  60.             xml.emptyElement(style);
  61.         }
  62.     }
  63. }