use of com.google.cloud.language.v1.Document in project JMRI by JMRI.
the class EngineManagerXml 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-engines.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-engines.xsl");
// NOI18N
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
EngineModels.instance().store(root);
EngineTypes.instance().store(root);
EngineLengths.instance().store(root);
EngineManager.instance().store(root);
writeXML(file, doc);
// done - engine file now stored, so can't be dirty
setDirty(false);
}
use of com.google.cloud.language.v1.Document in project JMRI by JMRI.
the class OperationsSetupXml 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-config.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-config.xsl");
// NOI18N
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
// add top-level elements
root.addContent(Setup.store());
// add manifest header text strings
root.addContent(TrainManifestHeaderText.store());
// add manifest text strings
root.addContent(TrainManifestText.store());
// add switch list text strings
root.addContent(TrainSwitchListText.store());
// add control elements
root.addContent(Control.store());
writeXML(file, doc);
// done, so can't be dirty
setDirty(false);
}
use of com.google.cloud.language.v1.Document in project JMRI by JMRI.
the class TrainManagerXml 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-trains.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-trains.xsl");
// NOI18N
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
TrainManager.instance().store(root);
TrainScheduleManager.instance().store(root);
AutomationManager.instance().store(root);
writeXML(file, doc);
// done - train file now stored, so can't be dirty
setDirty(false);
}
use of com.google.cloud.language.v1.Document 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);
}
}
use of com.google.cloud.language.v1.Document in project ParadoxosModManager by ThibautSF.
the class MyXML method readFile.
// public MyXML(){}
/**
* @param file
* @throws IOException
* @throws JDOMException
* @throws Exception
*/
public void readFile(String file) throws JDOMException, IOException {
SAXBuilder sxb = new SAXBuilder();
File xml = new File(file);
if (xml.exists()) {
document = sxb.build(xml);
root = document.getRootElement();
} else {
root = new Element(USER_LISTS);
document = new Document(root);
}
// Init for export lists
root_exported = new Element(EXPORTED_LIST);
root_exported.setAttribute(GAME_ID, ModManager.STEAM_ID.toString());
document_exported = new Document(root_exported);
this.file = file;
}
Aggregations