001package jmri.jmrit.logixng.actions.configurexml;
002
003import jmri.InstanceManager;
004import jmri.jmrit.logixng.*;
005import jmri.jmrit.logixng.actions.WebBrowser;
006
007import org.jdom2.Element;
008
009/**
010 * Handle XML configuration for WebBrowser objects.
011 *
012 * @author Bob Jacobsen Copyright: Copyright (c) 2004, 2008, 2010
013 * @author Daniel Bergqvist Copyright (C) 2020
014 */
015public class WebBrowserXml extends jmri.managers.configurexml.AbstractNamedBeanManagerConfigXML {
016
017    public WebBrowserXml() {
018    }
019
020    /**
021     * Default implementation for storing the contents of a WebBrowser
022     *
023     * @param o Object to store, of type WebBrowser
024     * @return Element containing the complete info
025     */
026    @Override
027    public Element store(Object o) {
028        WebBrowser p = (WebBrowser) o;
029
030        Element element = new Element("WebBrowser");
031        element.setAttribute("class", this.getClass().getName());
032        element.addContent(new Element("systemName").addContent(p.getSystemName()));
033
034        storeCommon(p, element);
035
036        Element e2 = new Element("Socket");
037        e2.addContent(new Element("socketName").addContent(p.getChild(0).getName()));
038        MaleSocket socket = p.getStringExpressionSocket().getConnectedSocket();
039        String socketSystemName;
040        if (socket != null) {
041            socketSystemName = socket.getSystemName();
042        } else {
043            socketSystemName = p.getStringExpressionSocketSystemName();
044        }
045        if (socketSystemName != null) {
046            e2.addContent(new Element("systemName").addContent(socketSystemName));
047        }
048        element.addContent(e2);
049
050        return element;
051    }
052
053    @Override
054    public boolean load(Element shared, Element perNode) {
055
056        String sys = getSystemName(shared);
057        String uname = getUserName(shared);
058        WebBrowser h = new WebBrowser(sys, uname);
059
060        loadCommon(h, shared);
061
062        Element socketElement = shared.getChild("Socket");
063        if (socketElement != null) {
064            Element socketName = socketElement.getChild("socketName");
065            h.getChild(0).setName(socketName.getTextTrim());
066            Element socketSystemName = socketElement.getChild("systemName");
067            if (socketSystemName != null) {
068                h.setStringExpressionSocketSystemName(socketSystemName.getTextTrim());
069            }
070        }
071
072        // For backwards compability
073        Element expressionSystemNameElement = shared.getChild("expressionSystemName");
074        if (expressionSystemNameElement != null) {
075            h.setStringExpressionSocketSystemName(expressionSystemNameElement.getTextTrim());
076        }
077        // For backwards compability
078
079        InstanceManager.getDefault(DigitalActionManager.class).registerAction(h);
080        return true;
081    }
082
083//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DoStringActionXml.class);
084}