Package org.exist.fulltext

Source Code of org.exist.fulltext.ElementContent$TextSpan

package org.exist.fulltext;

import org.apache.log4j.Logger;
import org.exist.dom.QName;
import org.exist.util.XMLString;

/**
*
*/
public class ElementContent {

    private static final Logger LOG = Logger.getLogger(ElementContent.class);

    public static class TextSpan {
        XMLString content;
        TextSpan next = null;

        TextSpan(XMLString content) {
            this.content = new XMLString(content);
        }

        public XMLString getContent() {
            return content;
        }

        public TextSpan getNext() {
            return next;
        }
    }

    private QName nodeName;
    private boolean mixedContent;
    private TextSpan first = null;
    private TextSpan last = null;

    public ElementContent(QName nodeName, boolean mixedContent) {
        this.nodeName = nodeName;
        this.mixedContent = mixedContent;
    }

    public void append(XMLString string) {
        if (mixedContent)
            {appendString(string);}
        else
            {appendSpan(string);}
    }

    public void appendSpan(XMLString string) {
        if (first == null) {
            first = new TextSpan(string);
            last = first;
        } else {
            TextSpan span = new TextSpan(string);
            last.next = span;
            last = span;
        }
    }

    public void appendString(XMLString string) {
        if (first == null) {
            first = new TextSpan(string);
            last = first;
        } else {
            last.content.append(string);
        }
    }

    public QName getNodeName() {
        return nodeName;
    }

    public void setMixedContent(boolean mixedContent) {
        this.mixedContent = mixedContent;
    }

    public TextSpan getFirst() {
        return first;
    }

    @Override
    public String toString() {
        final StringBuilder buf = new StringBuilder();
        TextSpan span = getFirst();
        while (span != null) {
            buf.append(span.getContent()).append('|');
            span = span.getNext();
        }
        return buf.toString();
    }
}
TOP

Related Classes of org.exist.fulltext.ElementContent$TextSpan

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.