001package jmri.jmrit.logixng.util.configurexml; 002 003import java.nio.charset.Charset; 004 005import jmri.configurexml.JmriConfigureXmlException; 006import jmri.jmrit.logixng.util.LogixNG_SelectCharset; 007import jmri.jmrit.logixng.util.LogixNG_SelectCharset.Addressing; 008 009import org.jdom2.Element; 010 011/** 012 * Xml class for jmri.jmrit.logixng.util.LogixNG_SelectCharset. 013 * 014 * @author Daniel Bergqvist (C) 2023 015 */ 016public class LogixNG_SelectCharsetXml { 017 018 /** 019 * Default implementation for storing the contents of a LogixNG_SelectEnum 020 * 021 * @param selectCharset the LogixNG_SelectCharset object 022 * @param tagName the name of the element 023 * @return Element containing the complete info 024 */ 025 public Element store(LogixNG_SelectCharset selectCharset, String tagName) { 026 027 Element element = new Element(tagName); 028 029 element.addContent(new Element("addressing").addContent(selectCharset.getAddressing().name())); 030 if (selectCharset.getStandardValue() != null) { 031 element.addContent(new Element("standardValue").addContent(selectCharset.getStandardValue().name())); 032 } 033 if (selectCharset.getAllValue() != null) { 034 element.addContent(new Element("allValue").addContent(selectCharset.getAllValue().name())); 035 } 036 037 var selectUserSpecifiedXml = new LogixNG_SelectStringXml(); 038 element.addContent(selectUserSpecifiedXml.store(selectCharset.getSelectUserSpecified(), "userSpecified")); 039 040 return element; 041 } 042 043 public void load(Element strElement, LogixNG_SelectCharset selectCharset) 044 throws JmriConfigureXmlException { 045 046 if (strElement != null) { 047 048 Element elem = strElement.getChild("addressing"); 049 if (elem != null) { 050 selectCharset.setAddressing(Addressing.valueOf(elem.getTextTrim())); 051 } 052 053 elem = strElement.getChild("standardValue"); 054 if (elem != null) { 055 selectCharset.setStandardValue(Charset.forName(elem.getTextTrim())); 056 } 057 058 elem = strElement.getChild("allValue"); 059 if (elem != null) { 060 selectCharset.setAllValue(Charset.forName(elem.getTextTrim())); 061 } 062 063 var selectUserSpecifiedXml = new LogixNG_SelectStringXml(); 064 if (strElement.getChild("table") != null) { 065 selectUserSpecifiedXml.load(strElement.getChild("userSpecified"), 066 selectCharset.getSelectUserSpecified()); 067 } 068 } 069 } 070 071}