Search in sources :

Example 6 with Format

use of org.jdom2.output.Format in project JMRI by JMRI.

the class PaneProgFrameTest method setupDoc.

// provide a test document in the above static variables
void setupDoc() {
    // create a JDOM tree with just some elements
    root = new Element("programmer-config");
    doc = new Document(root);
    doc.setDocType(new DocType("programmer-config", "programmer-config.dtd"));
    // add some elements
    root.addContent(new Element("programmer").setAttribute("showFnLanelPane", "yes").setAttribute("showRosterMediaPane", "yes").addContent(new Element("pane").setAttribute("name", "Basic").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Start voltage")).addContent(new Element("display").setAttribute("item", "Normal direction of motion"))).addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Normal direction of motion")).addContent(new Element("display").setAttribute("item", "Normal direction of motion").setAttribute("format", "checkbox")).addContent(new Element("display").setAttribute("item", "Normal direction of motion").setAttribute("format", "radiobuttons")))).addContent(new Element("pane").setAttribute("name", "CV").addContent(new Element("column").addContent(new Element("cvtable")))).addContent(new Element("pane").setAttribute("name", "Other").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Normal direction of motion")))));
    return;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 7 with Format

use of org.jdom2.output.Format in project JMRI by JMRI.

the class LoadXmlThrottlesLayoutAction method loadThrottlesLayout.

/**
     * Parse the XML file and create ThrottleFrames. Returns true if throttle
     * loaded successfully.
     *
     * @param f The XML file containing throttles.
     */
@SuppressWarnings("unchecked")
public boolean loadThrottlesLayout(java.io.File f) throws java.io.IOException {
    try {
        ThrottlePrefs prefs = new ThrottlePrefs();
        Element root = prefs.rootFromFile(f);
        List<Element> throttles = root.getChildren("ThrottleFrame");
        if ((throttles != null) && (throttles.size() > 0)) {
            // OLD FORMAT    
            for (java.util.Iterator<Element> i = throttles.iterator(); i.hasNext(); ) {
                ThrottleFrame tf = ThrottleFrameManager.instance().createThrottleFrame();
                tf.setXml(i.next());
                tf.toFront();
            }
        } else {
            throttles = root.getChildren("ThrottleWindow");
            for (java.util.Iterator<Element> i = throttles.iterator(); i.hasNext(); ) {
                ThrottleWindow tw = ThrottleFrameManager.instance().createThrottleWindow();
                tw.setXml(i.next());
                tw.setVisible(true);
            }
            Element tlp = root.getChild("ThrottlesListPanel");
            if (tlp != null) {
                ThrottleFrameManager.instance().getThrottlesListPanel().setXml(tlp);
            }
        }
    } catch (org.jdom2.JDOMException ex) {
        log.warn("Loading Throttles exception", ex);
        return false;
    }
    return true;
}
Also used : Element(org.jdom2.Element)

Example 8 with Format

use of org.jdom2.output.Format in project JMRI by JMRI.

the class LocoAddressXml method store.

/**
     * Default implementation for storing the contents of a LocoAddress
     *
     * @param o Object to store, of type LocoAddress
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    LocoAddress p = (LocoAddress) o;
    Element element = new Element("locoaddress");
    // include contents, we shall also store the old format for backward compatability
    DccLocoAddressXml adapter = new DccLocoAddressXml();
    element.addContent(adapter.store(p));
    if (p != null) {
        element.addContent(new Element("number").addContent("" + p.getNumber()));
        element.addContent(new Element("protocol").addContent(p.getProtocol().getShortName()));
    } else {
        element.addContent(new Element("number").addContent(""));
        element.addContent(new Element("protocol").addContent(""));
    }
    return element;
}
Also used : LocoAddress(jmri.LocoAddress) Element(org.jdom2.Element)

Example 9 with Format

use of org.jdom2.output.Format in project JMRI by JMRI.

the class CarManager method load.

public void load(Element root) {
    // new format using elements starting version 3.3.1
    if (root.getChild(Xml.NEW_KERNELS) != null) {
        @SuppressWarnings("unchecked") List<Element> eKernels = root.getChild(Xml.NEW_KERNELS).getChildren(Xml.KERNEL);
        log.debug("Car manager sees {} kernels", eKernels.size());
        Attribute a;
        for (Element eKernel : eKernels) {
            if ((a = eKernel.getAttribute(Xml.NAME)) != null) {
                newKernel(a.getValue());
            }
        }
    } else // old format
    if (root.getChild(Xml.KERNELS) != null) {
        String names = root.getChildText(Xml.KERNELS);
        if (!names.equals("")) {
            // NOI18N
            String[] kernelNames = names.split("%%");
            log.debug("kernels: {}", names);
            for (String name : kernelNames) {
                newKernel(name);
            }
        }
    }
    if (root.getChild(Xml.CARS) != null) {
        @SuppressWarnings("unchecked") List<Element> eCars = root.getChild(Xml.CARS).getChildren(Xml.CAR);
        log.debug("readFile sees {} cars", eCars.size());
        for (Element eCar : eCars) {
            register(new Car(eCar));
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 10 with Format

use of org.jdom2.output.Format in project JMRI by JMRI.

the class DefaultIdTag method store.

@Override
public Element store(boolean storeState) {
    //NOI18N
    Element e = new Element("idtag");
    // e.setAttribute("systemName", this.mSystemName); // not needed from 2.11.1
    //NOI18N
    e.addContent(new Element("systemName").addContent(this.mSystemName));
    if (this.mUserName != null && this.mUserName.length() > 0) {
        // e.setAttribute("userName", this.mUserName); // not needed from 2.11.1
        //NOI18N
        e.addContent(new Element("userName").addContent(this.mUserName));
    }
    if (this.getComment() != null && this.getComment().length() > 0) {
        //NOI18N
        e.addContent(new Element("comment").addContent(this.getComment()));
    }
    if (this.getWhereLastSeen() != null && storeState) {
        //NOI18N
        e.addContent(new Element("whereLastSeen").addContent(this.getWhereLastSeen().getSystemName()));
    }
    if (this.getWhenLastSeen() != null && storeState) {
        //NOI18N
        e.addContent(new Element("whenLastSeen").addContent(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(this.getWhenLastSeen())));
    }
    return e;
}
Also used : Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)57 Document (org.jdom2.Document)20 XMLOutputter (org.jdom2.output.XMLOutputter)19 IOException (java.io.IOException)15 StringWriter (java.io.StringWriter)9 Attribute (org.jdom2.Attribute)9 Format (org.jdom2.output.Format)7 File (java.io.File)5 ArrayList (java.util.ArrayList)5 MCRRestAPIError (org.mycore.restapi.v1.errors.MCRRestAPIError)5 MCRRestAPIException (org.mycore.restapi.v1.errors.MCRRestAPIException)5 JsonWriter (com.google.gson.stream.JsonWriter)4 Date (java.util.Date)4 SAXBuilder (org.jdom2.input.SAXBuilder)4 SimpleDateFormat (java.text.SimpleDateFormat)3 JDOMException (org.jdom2.JDOMException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 List (java.util.List)2 JComponent (javax.swing.JComponent)2