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