001package jmri.jmrit.signalsystemeditor.configurexml;
002
003import org.jdom2.Attribute;
004import org.jdom2.Element;
005
006import jmri.jmrit.signalsystemeditor.StringWithComment;
007
008/**
009 * Load and store StringWithComment
010 *
011 * @author Daniel Bergqvist (C) 2022
012 */
013public class StringWithCommentXml {
014
015    public static StringWithComment load(Element element) {
016        StringWithComment stringWithComment = new StringWithComment(element.getText());
017        Attribute commentAttr = element.getAttribute("comment");
018        if (commentAttr != null) {
019            stringWithComment.setComment(commentAttr.getValue());
020        }
021        return stringWithComment;
022    }
023
024    public static Element store(StringWithComment stringWithComment, String tagName) {
025
026        Element element = new Element(tagName);
027        element.setText(stringWithComment.getString());
028
029        if (stringWithComment.getComment() != null) {
030            element.setAttribute("comment", stringWithComment.getComment());
031        }
032
033        return element;
034    }
035
036}