Search in sources :

Example 16 with ProcessingInstruction

use of org.jdom2.ProcessingInstruction 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 17 with ProcessingInstruction

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

the class LocationManagerXml method writeFile.

@Override
public void writeFile(String name) throws java.io.FileNotFoundException, java.io.IOException {
    log.debug("writeFile {}", name);
    // This is taken in large part from "Java and XML" page 368
    File file = findFile(name);
    if (file == null) {
        file = new File(name);
    }
    // create root element
    // NOI18N
    Element root = new Element("operations-config");
    // NOI18N
    Document doc = newDocument(root, dtdLocation + "operations-locations.dtd");
    // add XSLT processing instruction
    java.util.Map<String, String> m = new java.util.HashMap<String, String>();
    // NOI18N
    m.put("type", "text/xsl");
    // NOI18N
    m.put("href", xsltLocation + "operations-locations.xsl");
    // NOI18N
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    LocationManager.instance().store(root);
    ScheduleManager.instance().store(root);
    writeXML(file, doc);
    // done - location file now stored, so can't be dirty
    setDirty(false);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Example 18 with ProcessingInstruction

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

the class CarManagerXml method writeFile.

@Override
public void writeFile(String name) throws java.io.FileNotFoundException, java.io.IOException {
    log.debug("writeFile {}", name);
    // This is taken in large part from "Java and XML" page 368
    File file = findFile(name);
    if (file == null) {
        file = new File(name);
    }
    // create root element
    // NOI18N
    Element root = new Element("operations-config");
    // NOI18N
    Document doc = newDocument(root, dtdLocation + "operations-cars.dtd");
    // add XSLT processing instruction
    java.util.Map<String, String> m = new java.util.HashMap<String, String>();
    // NOI18N
    m.put("type", "text/xsl");
    // NOI18N
    m.put("href", xsltLocation + "operations-cars.xsl");
    // NOI18N
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    // note all comments line feeds have been changed to processor directives
    CarRoads.instance().store(root);
    CarTypes.instance().store(root);
    CarColors.instance().store(root);
    CarLengths.instance().store(root);
    CarOwners.instance().store(root);
    CarLoads.instance().store(root);
    CarManager.instance().store(root);
    writeXML(file, doc);
    // done - car file now stored, so can't be dirty
    setDirty(false);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Example 19 with ProcessingInstruction

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

the class OptionsFile method writeDispatcherOptions.

/*
     *  Writes out Dispatcher options to a file in the user's preferences directory
     */
public void writeDispatcherOptions(DispatcherFrame f) throws java.io.IOException {
    log.debug("Saving Dispatcher options to file {}", defaultFileName);
    dispatcher = f;
    root = new Element("dispatcheroptions");
    doc = newDocument(root, dtdLocation + "dispatcher-options.dtd");
    // add XSLT processing instruction
    // <?xml-stylesheet type="text/xsl" href="XSLT/block-values.xsl"?>
    java.util.Map<String, String> m = new java.util.HashMap<String, String>();
    m.put("type", "text/xsl");
    m.put("href", xsltLocation + "dispatcheroptions.xsl");
    org.jdom2.ProcessingInstruction p = new org.jdom2.ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    // save Dispatcher Options in xml format
    Element options = new Element("options");
    LayoutEditor le = dispatcher.getLayoutEditor();
    if (le != null) {
        options.setAttribute("lename", le.getTitle());
    }
    options.setAttribute("useconnectivity", "" + (dispatcher.getUseConnectivity() ? "yes" : "no"));
    options.setAttribute("trainsfromroster", "" + (dispatcher.getTrainsFromRoster() ? "yes" : "no"));
    options.setAttribute("trainsfromtrains", "" + (dispatcher.getTrainsFromTrains() ? "yes" : "no"));
    options.setAttribute("trainsfromuser", "" + (dispatcher.getTrainsFromUser() ? "yes" : "no"));
    options.setAttribute("autoallocate", "" + (dispatcher.getAutoAllocate() ? "yes" : "no"));
    options.setAttribute("autoturnouts", "" + (dispatcher.getAutoTurnouts() ? "yes" : "no"));
    options.setAttribute("trustknownturnouts", "" + (dispatcher.getTrustKnownTurnouts() ? "yes" : "no"));
    options.setAttribute("minthrottleinterval", "" + (dispatcher.getMinThrottleInterval()));
    options.setAttribute("fullramptime", "" + (dispatcher.getFullRampTime()));
    options.setAttribute("hasoccupancydetection", "" + (dispatcher.getHasOccupancyDetection() ? "yes" : "no"));
    options.setAttribute("shortactivetrainnames", "" + (dispatcher.getShortActiveTrainNames() ? "yes" : "no"));
    options.setAttribute("shortnameinblock", "" + (dispatcher.getShortNameInBlock() ? "yes" : "no"));
    options.setAttribute("extracolorforallocated", "" + (dispatcher.getExtraColorForAllocated() ? "yes" : "no"));
    options.setAttribute("nameinallocatedblock", "" + (dispatcher.getNameInAllocatedBlock() ? "yes" : "no"));
    options.setAttribute("supportvsdecoder", "" + (dispatcher.getSupportVSDecoder() ? "yes" : "no"));
    options.setAttribute("layoutscale", Scale.getShortScaleID(dispatcher.getScale()));
    options.setAttribute("usescalemeters", "" + (dispatcher.getUseScaleMeters() ? "yes" : "no"));
    options.setAttribute("userosterentryinblock", "" + (dispatcher.getRosterEntryInBlock() ? "yes" : "no"));
    if (dispatcher.getSignalType() == 0x00) {
        options.setAttribute("usesignaltype", "signalhead");
    } else {
        options.setAttribute("usesignaltype", "signalmast");
    }
    root.addContent(options);
    // write out the file
    try {
        if (!checkFile(defaultFileName)) {
            // file does not exist, create it
            File file = new File(defaultFileName);
            if (// create new file and check result
            !file.createNewFile()) {
                log.error("createNewFile failed");
            }
        }
        // write content to file
        writeXML(findFile(defaultFileName), doc);
    } catch (java.io.IOException ioe) {
        log.error("IO Exception " + ioe);
        throw (ioe);
    }
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Element(org.jdom2.Element) File(java.io.File)

Example 20 with ProcessingInstruction

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

the class ThrottlesPreferences 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 throttles preferences file, may not be complete: " + exp);
    }
    try {
        Element root = new Element("throttles-preferences");
        Document doc = XmlFile.newDocument(root, XmlFile.getDefaultDtdLocation() + "throttles-preferences.dtd");
        // 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) {
        log.warn("Exception in storing throttles preferences xml: " + ex);
    }
    this.dirty = false;
}
Also used : XmlFile(jmri.jmrit.XmlFile) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) XmlFile(jmri.jmrit.XmlFile)

Aggregations

Element (org.jdom2.Element)23 Document (org.jdom2.Document)20 File (java.io.File)18 ProcessingInstruction (org.jdom2.ProcessingInstruction)15 XmlFile (jmri.jmrit.XmlFile)9 IOException (java.io.IOException)5 FileNotFoundException (java.io.FileNotFoundException)3 HashMap (java.util.HashMap)3 XMLOutputter (org.jdom2.output.XMLOutputter)3 FileOutputStream (java.io.FileOutputStream)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Block (jmri.Block)1 CatalogTree (jmri.CatalogTree)1 CatalogTreeManager (jmri.CatalogTreeManager)1 Consist (jmri.Consist)1 CatalogTreeNode (jmri.jmrit.catalog.CatalogTreeNode)1