Search in sources :

Example 1 with Parent

use of org.jdom2.Parent in project gocd by gocd.

the class StageCctrayPresentationModel method createProjectElement.

private void createProjectElement(Element parent, String name, String activity, String lastBuildStatus, String lastBuildLabel, String lastBuildTime, String webUrl) {
    Element project = new Element("Project");
    project.setAttribute("name", name);
    project.setAttribute("activity", activity);
    project.setAttribute("lastBuildStatus", lastBuildStatus);
    project.setAttribute("lastBuildLabel", lastBuildLabel);
    project.setAttribute("lastBuildTime", lastBuildTime);
    project.setAttribute("webUrl", webUrl);
    parent.addContent(project);
}
Also used : Element(org.jdom2.Element)

Example 2 with Parent

use of org.jdom2.Parent in project JMRI by JMRI.

the class DefaultCatalogTreeManagerXml method loadNode.

/**
     * Recursively load a CatalogTree.
     *
     * @param element element containing the node to load
     * @param parent  the parent node of the node in element
     * @param model   the tree model containing the tree to add the node to
     */
public void loadNode(Element element, CatalogTreeNode parent, DefaultTreeModel model) {
    List<Element> nodeList = element.getChildren("node");
    if (log.isDebugEnabled()) {
        log.debug("Found " + nodeList.size() + " CatalogTreeNode objects");
    }
    for (int i = 0; i < nodeList.size(); i++) {
        Element elem = nodeList.get(i);
        Attribute attr = elem.getAttribute("nodeName");
        if (attr == null) {
            log.warn("unexpected null nodeName. elem= " + elem + ", attrs= " + elem.getAttributes());
            continue;
        }
        String nodeName = attr.getValue();
        CatalogTreeNode n = new CatalogTreeNode(nodeName);
        addLeaves(elem, n);
        model.insertNodeInto(n, parent, parent.getChildCount());
        loadNode(elem, n, model);
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode)

Example 3 with Parent

use of org.jdom2.Parent in project JMRI by JMRI.

the class QualifierAdder method processModifierElements.

public void processModifierElements(Element e, VariableTableModel model) {
    ArrayList<Qualifier> lq = new ArrayList<Qualifier>();
    // we assign to this to allow us to suppress unchecked error
    List<Element> le = e.getChildren("qualifier");
    processList(le, lq, model);
    // search for enclosing element so we can find all relevant qualifiers
    Parent p = e;
    while ((p = p.getParent()) != null && p instanceof Element) {
        Element el = (Element) p;
        if (el.getName().equals("pane")) {
            // stop when we get to an enclosing pane element
            break;
        }
        @SuppressWarnings("unchecked") List<Element> // we assign to this to allow us to suppress unchecked error
        le2 = el.getChildren("qualifier");
        processList(le2, lq, model);
    }
    // Add the AND logic - listen for change and ensure result correct
    if (lq.size() > 1) {
        QualifierCombiner qc = new QualifierCombiner(lq);
        addListener(qc);
    }
}
Also used : Parent(org.jdom2.Parent) Element(org.jdom2.Element) ArrayList(java.util.ArrayList)

Example 4 with Parent

use of org.jdom2.Parent in project JMRI by JMRI.

the class VSDecoderPreferences method save.

public void save() {
    if (prefFile == null) {
        return;
    }
    XmlFile xf = new XmlFile() {
    };
    // odd syntax is due to XmlFile being abstract
    xf.makeBackupFile(prefFile);
    File file = new File(prefFile);
    try {
        //The file does not exist, create it before writing
        File parentDir = file.getParentFile();
        if (!parentDir.exists()) {
            if (// make directory, check result
            !parentDir.mkdir()) {
                log.error("failed to make parent directory");
            }
        }
        if (// create file, check result
        !file.createNewFile()) {
            log.error("createNewFile failed");
        }
    } catch (Exception exp) {
        log.error("Exception while writing the new VSDecoder preferences file, may not be complete: " + exp);
    }
    try {
        Element root = new Element("vsdecoder-preferences");
        //Document doc = XmlFile.newDocument(root, XmlFile.dtdLocation+"vsdecoder-preferences.dtd");
        Document doc = XmlFile.newDocument(root);
        // add XSLT processing instruction
        // <?xml-stylesheet type="text/xsl" href="XSLT/throttle.xsl"?>
        /*TODO      java.util.Map<String,String> m = new java.util.HashMap<String,String>();
             m.put("type", "text/xsl");
             m.put("href", jmri.jmrit.XmlFile.xsltLocation+"throttles-preferences.xsl");
             ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
             doc.addContent(0,p);*/
        root.setContent(store());
        xf.writeXML(file, doc);
    } catch (Exception ex) {
        // TODO fix null value for Attribute
        log.warn("Exception in storing vsdecoder preferences xml: " + ex);
    }
}
Also used : XmlFile(jmri.jmrit.XmlFile) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) XmlFile(jmri.jmrit.XmlFile)

Example 5 with Parent

use of org.jdom2.Parent in project JMRI by JMRI.

the class TransitManagerXml method loadTransits.

/**
     * Utility method to load the individual Transit objects. If there's no
     * additional info needed for a specific Transit type, invoke this with the
     * parent of the set of Transit elements.
     *
     * @param sharedTransits  Element containing the Transit elements to load.
     * @param perNodeTransits Per-node Element containing the Transit elements
     *                        to load.
     */
@SuppressWarnings("null")
public void loadTransits(Element sharedTransits, Element perNodeTransits) {
    List<Element> transitList = sharedTransits.getChildren("transit");
    if (log.isDebugEnabled()) {
        log.debug("Found " + transitList.size() + " transits");
    }
    TransitManager tm = InstanceManager.getDefault(jmri.TransitManager.class);
    for (int i = 0; i < transitList.size(); i++) {
        String sysName = getSystemName(transitList.get(i));
        String userName = getUserName(transitList.get(i));
        Transit x = tm.createNewTransit(sysName, userName);
        if (x != null) {
            // load common part
            loadCommon(x, transitList.get(i));
            // load transitsection children
            List<Element> transitTransitSectionList = transitList.get(i).getChildren("transitsection");
            for (int n = 0; n < transitTransitSectionList.size(); n++) {
                Element elem = transitTransitSectionList.get(n);
                int seq = 0;
                int dir = Section.UNKNOWN;
                boolean alt = false;
                String sectionName = elem.getAttribute("sectionname").getValue();
                if (sectionName.equals("null")) {
                    log.warn("When loading configuration - missing Section in Transit " + sysName);
                }
                try {
                    seq = elem.getAttribute("sequence").getIntValue();
                    dir = elem.getAttribute("direction").getIntValue();
                } catch (Exception e) {
                    log.error("Data Conversion Exception when loading direction of entry point - " + e);
                }
                if (elem.getAttribute("alternate").getValue().equals("yes")) {
                    alt = true;
                }
                TransitSection ts = new TransitSection(sectionName, seq, dir, alt);
                x.addTransitSection(ts);
                // load transitsectionaction children, if any
                List<Element> transitTransitSectionActionList = transitTransitSectionList.get(n).getChildren("transitsectionaction");
                for (int m = 0; m < transitTransitSectionActionList.size(); m++) {
                    Element elemx = transitTransitSectionActionList.get(m);
                    int tWhen = 1;
                    int tWhat = 1;
                    int tWhenData = 0;
                    String tWhenString = elemx.getAttribute("whenstring").getValue();
                    int tWhatData1 = 0;
                    int tWhatData2 = 0;
                    String tWhatString = elemx.getAttribute("whatstring").getValue();
                    try {
                        tWhen = elemx.getAttribute("whencode").getIntValue();
                        tWhat = elemx.getAttribute("whatcode").getIntValue();
                        tWhenData = elemx.getAttribute("whendata").getIntValue();
                        tWhatData1 = elemx.getAttribute("whatdata1").getIntValue();
                        tWhatData2 = elemx.getAttribute("whatdata2").getIntValue();
                    } catch (Exception e) {
                        log.error("Data Conversion Exception when loading transit section action - " + e);
                    }
                    TransitSectionAction tsa = new TransitSectionAction(tWhen, tWhat, tWhenData, tWhatData1, tWhatData2, tWhenString, tWhatString);
                    ts.addAction(tsa);
                }
            }
        }
    }
}
Also used : TransitSection(jmri.TransitSection) TransitManager(jmri.TransitManager) Element(org.jdom2.Element) TransitSectionAction(jmri.TransitSectionAction) Transit(jmri.Transit)

Aggregations

Element (org.jdom2.Element)24 File (java.io.File)6 XmlFile (jmri.jmrit.XmlFile)6 Document (org.jdom2.Document)6 Attribute (org.jdom2.Attribute)4 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 Logix (jmri.Logix)2 AppConfigBase (apps.AppConfigBase)1 ConfigBundle (apps.ConfigBundle)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 BorderLayout (java.awt.BorderLayout)1 CardLayout (java.awt.CardLayout)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 FileOutputStream (java.io.FileOutputStream)1 HashSet (java.util.HashSet)1 List (java.util.List)1 ServiceLoader (java.util.ServiceLoader)1