use of org.apache.type_test.types1.Document in project JMRI by JMRI.
the class XmlFile method newDocument.
/**
* Create the Document object to store a particular root Element, without a
* DocType DTD (e.g. for using a schema)
*
* @param root Root element of the final document
* @return new Document, with root installed
*/
public static Document newDocument(Element root) {
Document doc = new Document(root);
addDefaultInfo(root);
return doc;
}
use of org.apache.type_test.types1.Document 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);
}
use of org.apache.type_test.types1.Document 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);
}
use of org.apache.type_test.types1.Document in project JMRI by JMRI.
the class NodeIdentity method saveIdentity.
/**
* Save the current node identity and all former identities to file.
*/
private void saveIdentity() {
Document doc = new Document();
doc.setRootElement(new Element(ROOT_ELEMENT));
Element identityElement = new Element(NODE_IDENTITY);
Element formerIdentitiesElement = new Element(FORMER_IDENTITIES);
if (this.identity == null) {
this.getIdentity(false);
}
identityElement.setAttribute(NODE_IDENTITY, this.identity);
this.formerIdentities.stream().forEach((formerIdentity) -> {
log.debug("Retaining former node identity {}", formerIdentity);
Element e = new Element(NODE_IDENTITY);
e.setAttribute(NODE_IDENTITY, formerIdentity);
formerIdentitiesElement.addContent(e);
});
doc.getRootElement().addContent(identityElement);
doc.getRootElement().addContent(formerIdentitiesElement);
try (Writer w = new OutputStreamWriter(new FileOutputStream(this.identityFile()), "UTF-8")) {
// NOI18N
XMLOutputter fmt = new XMLOutputter();
fmt.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.PRESERVE));
fmt.output(doc, w);
} catch (IOException ex) {
log.error("Unable to store node identities: {}", ex.getLocalizedMessage());
}
}
use of org.apache.type_test.types1.Document in project JMRI by JMRI.
the class XmlFileTest method testProcessPI.
public void testProcessPI() throws org.jdom2.JDOMException, java.io.IOException {
// Document from test file
Document doc;
Element e;
FileInputStream fs = new FileInputStream(new File("java/test/jmri/jmrit/XmlFileTest_PI.xml"));
try {
// argument controls validation
SAXBuilder builder = XmlFile.getBuilder(XmlFile.Validate.None);
doc = builder.build(new BufferedInputStream(fs));
Assert.assertNotNull("Original Document found", doc);
e = doc.getRootElement();
Assert.assertNotNull("Original root element found", e);
XmlFile x = new XmlFile() {
};
Document d = x.processInstructions(doc);
Assert.assertNotNull(d);
// test transform changes <contains> element to <content>
e = d.getRootElement();
Assert.assertNotNull("Transformed root element found", e);
Assert.assertTrue("Transformed root element is right type", e.getName().equals("top"));
Assert.assertTrue("Old element gone", e.getChild("contains") == null);
Assert.assertTrue("New element there", e.getChild("content") != null);
Assert.assertTrue("New element has content", e.getChild("content").getChildren().size() == 2);
} catch (java.io.IOException ex) {
throw ex;
} catch (org.jdom2.JDOMException ex) {
throw ex;
} finally {
fs.close();
}
}
Aggregations