use of com.google.firestore.v1.Document in project JMRI by JMRI.
the class ProfileManager method readProfiles.
private void readProfiles() throws JDOMException, IOException {
try {
boolean reWrite = false;
if (!catalog.exists()) {
this.writeProfiles();
}
if (!catalog.canRead()) {
return;
}
this.readingProfiles = true;
Document doc = (new SAXBuilder()).build(catalog);
profiles.clear();
for (Element e : doc.getRootElement().getChild(PROFILES).getChildren()) {
File pp = FileUtil.getFile(e.getAttributeValue(Profile.PATH));
try {
Profile p = new Profile(pp);
this.addProfile(p);
} catch (FileNotFoundException ex) {
log.info("Cataloged profile \"{}\" not in expected location\nSearching for it in {}", e.getAttributeValue(Profile.ID), pp.getParentFile());
this.findProfiles(pp.getParentFile());
reWrite = true;
}
}
searchPaths.clear();
for (Element e : doc.getRootElement().getChild(SEARCH_PATHS).getChildren()) {
File path = FileUtil.getFile(e.getAttributeValue(Profile.PATH));
if (!searchPaths.contains(path)) {
this.addSearchPath(path);
}
if (Boolean.parseBoolean(e.getAttributeValue(DEFAULT))) {
this.defaultSearchPath = path;
}
}
if (searchPaths.isEmpty()) {
this.addSearchPath(FileUtil.getFile(FileUtil.getPreferencesPath()));
}
this.readingProfiles = false;
if (reWrite) {
this.writeProfiles();
}
this.profiles.sort(null);
} catch (JDOMException | IOException ex) {
this.readingProfiles = false;
throw ex;
}
}
use of com.google.firestore.v1.Document in project JMRI by JMRI.
the class NodeIdentity method init.
private synchronized void init() {
File identityFile = this.identityFile();
if (identityFile.exists()) {
try {
Document doc = (new SAXBuilder()).build(identityFile);
String id = doc.getRootElement().getChild(NODE_IDENTITY).getAttributeValue(NODE_IDENTITY);
this.formerIdentities.clear();
doc.getRootElement().getChild(FORMER_IDENTITIES).getChildren().stream().forEach((e) -> {
this.formerIdentities.add(e.getAttributeValue(NODE_IDENTITY));
});
if (!this.validateIdentity(id)) {
log.debug("Node identity {} is invalid. Generating new node identity.", id);
this.formerIdentities.add(id);
this.getIdentity(true);
} else {
this.getIdentity(true);
}
} catch (JDOMException | IOException ex) {
log.error("Unable to read node identities: {}", ex.getLocalizedMessage());
this.getIdentity(true);
}
} else {
this.getIdentity(true);
}
}
use of com.google.firestore.v1.Document in project JMRI by JMRI.
the class DecoderFileTest method setupDecoder.
// provide a test document in the above static variables
public void setupDecoder() {
// create a JDOM tree with just some elements
root = new Element("decoder-config");
doc = new Document(root);
doc.setDocType(new DocType("decoder-config", "decoder-config.dtd"));
// add some elements
root.addContent(decoder = new Element("decoder").addContent(new Element("family").setAttribute("family", "DH142 etc").setAttribute("mfg", "Digitrax").setAttribute("defnVersion", "242").setAttribute("comment", "DH142 decoder: FX, transponding")).addContent(new Element("programming").setAttribute("direct", "byteOnly").setAttribute("paged", "yes").setAttribute("register", "yes").setAttribute("ops", "yes")).addContent(new Element("variables").addContent(new Element("variable").setAttribute("label", "Address").setAttribute("CV", "1").setAttribute("minFn", "4").setAttribute("mask", "VVVVVVVV").setAttribute("readOnly", "no").addContent(new Element("decVal").setAttribute("max", "127"))).addContent(new Element("variable").setAttribute("label", "Acceleration rate").setAttribute("CV", "3").setAttribute("minOut", "2").setAttribute("mask", "VVVVVVVV").setAttribute("readOnly", "no").addContent(new Element("decVal").setAttribute("max", "127"))).addContent(new Element("variable").setAttribute("label", "Normal direction of motion").setAttribute("CV", "29").setAttribute("minFn", "2").setAttribute("minOut", "5").setAttribute("mask", "XXXXXXXV").setAttribute("readOnly", "no").addContent(new Element("enumVal").addContent(new Element("enumChoice").setAttribute("choice", "forward")).addContent(new Element("enumChoice").setAttribute("choice", "reverse"))))));
return;
}
use of com.google.firestore.v1.Document in project JMRI by JMRI.
the class DecoderIndexFileTest method setupDoc.
// provide a test document in the above static variables
void setupDoc() {
// create a JDOM tree with just some elements
root = new Element("decoderIndex-config");
doc = new Document(root);
doc.setDocType(new DocType("decoderIndex-config", "decoderIndex-config.dtd"));
// add some elements
root.addContent(decoderIndexElement = new Element("decoderIndex").addContent(new Element("mfgList").addContent(new Element("manufacturer").setAttribute("mfg", "NMRA")).addContent(new Element("manufacturer").setAttribute("mfg", "Digitrax").setAttribute("mfgID", "129"))).addContent(new Element("familyList").addContent(family1 = new Element("family").setAttribute("mfg", "NMRA").setAttribute("name", "NMRA S&RP definitions").setAttribute("file", "NMRA.xml").addContent(new Element("model").setAttribute("model", "full set").setAttribute("comment", "all CVs in RP 9.2.1")).addContent(new Element("model").setAttribute("model", "required set").setAttribute("comment", "required CVs in RP 9.2.1"))).addContent(family2 = new Element("family").setAttribute("mfg", "Digitrax").setAttribute("name", "FX2 family").setAttribute("file", "DH142.xml").addContent(new Element("model").setAttribute("model", "DH142").setAttribute("numFns", "4").setAttribute("numOuts", "2").setAttribute("lowVersionID", "21")).addContent(new Element("model").setAttribute("model", "DN142").setAttribute("numFns", "5").setAttribute("numOuts", "1").addContent(new Element("versionCV").setAttribute("lowVersionID", "22").setAttribute("highVersionID", "24"))))));
return;
}
use of com.google.firestore.v1.Document in project JMRI by JMRI.
the class RouteManagerXml 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-routes.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-routes.xsl");
// NOI18N
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
RouteManager.instance().store(root);
writeXML(file, doc);
// done - route file now stored, so can't be dirty
setDirty(false);
}
Aggregations