001/** 002 * 003 * Copyright © 2018 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_markup.element; 018 019import java.util.Collections; 020import java.util.Set; 021 022import javax.xml.namespace.QName; 023 024import org.jivesoftware.smack.util.XmlStringBuilder; 025 026public class SpanElement extends MarkupElement.NonEmptyChildElement { 027 028 public static final String ELEMENT = "span"; 029 public static final QName QNAME = new QName(NAMESPACE, ELEMENT); 030 031 private final Set<SpanStyle> styles; 032 033 /** 034 * Create a new Span element. 035 * 036 * @param start start index 037 * @param end end index 038 * @param styles list of styles that apply to this span 039 */ 040 public SpanElement(int start, int end, Set<SpanStyle> styles) { 041 super(start, end); 042 this.styles = Collections.unmodifiableSet(styles); 043 } 044 045 /** 046 * Return all styles of this span. 047 * 048 * @return styles TODO javadoc me please 049 */ 050 public Set<SpanStyle> getStyles() { 051 return styles; 052 } 053 054 public static final String emphasis = "emphasis"; 055 public static final String code = "code"; 056 public static final String deleted = "deleted"; 057 058 public enum SpanStyle { 059 emphasis, 060 code, 061 deleted 062 } 063 064 @Override 065 public String getElementName() { 066 return QNAME.getLocalPart(); 067 } 068 069 @Override 070 protected void appendInnerXml(XmlStringBuilder xml) { 071 for (SpanStyle style : getStyles()) { 072 xml.emptyElement(style); 073 } 074 } 075}