use of org.jdom2.ProcessingInstruction in project JMRI by JMRI.
the class ThrottleFrame method saveThrottle.
private void saveThrottle(String sfile) {
// Save throttle: title / window position
// as strongly linked to extended throttles and roster presence, do not save function buttons and background window as they're stored in the roster entry
XmlFile xf = new XmlFile() {
};
// odd syntax is due to XmlFile being abstract
xf.makeBackupFile(sfile);
File file = new File(sfile);
try {
//The file does not exist, create it before writing
File parentDir = file.getParentFile();
if (!parentDir.exists()) {
if (// make directory and check result
!parentDir.mkdir()) {
log.error("could not make parent directory");
}
}
if (// create file, check success
!file.createNewFile()) {
log.error("createNewFile failed");
}
} catch (Exception exp) {
log.error("Exception while writing the throttle file, may not be complete: " + exp);
}
try {
Element root = new Element("throttle-config");
Document doc = XmlFile.newDocument(root, XmlFile.getDefaultDtdLocation() + "throttle-config.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/throttle.xsl"?>
/* java.util.Map<String,String> m = new java.util.HashMap<String,String>();
m.put("type", "text/xsl");
m.put("href", jmri.jmrit.XmlFile.xsltLocation+"throttle.xsl");
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0,p);*/
Element throttleElement = getXml();
// throttleElement.getChild("AddressPanel").removeChild("locoaddress");
if (// don't save function buttons labels, they're in roster entry
(this.getRosterEntry() != null) && (getDefaultThrottleFolder() + addressPanel.getRosterEntry().getId().trim() + ".xml").compareTo(sfile) == 0) {
throttleElement.getChild("FunctionPanel").removeChildren("FunctionButton");
}
root.setContent(throttleElement);
xf.writeXML(file, doc);
setLastUsedSaveFile(sfile);
} catch (Exception ex) {
log.warn("Exception while storing throttle xml: " + ex);
}
}
use of org.jdom2.ProcessingInstruction in project JMRI by JMRI.
the class StoreXmlThrottlesLayoutAction method saveThrottlesLayout.
public void saveThrottlesLayout(java.io.File f) {
try {
Element root = new Element("throttle-layout-config");
Document doc = XmlFile.newDocument(root, XmlFile.getDefaultDtdLocation() + "throttle-layout-config.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/throttle-layout-config.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 + "throttle-layout-config.xsl");
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p); */
java.util.ArrayList<Element> children = new java.util.ArrayList<Element>(5);
// throttle list window
children.add(ThrottleFrameManager.instance().getThrottlesListPanel().getXml());
// throttle windows
for (Iterator<ThrottleWindow> i = ThrottleFrameManager.instance().getThrottleWindows(); i.hasNext(); ) {
ThrottleWindow tw = i.next();
Element throttleElement = tw.getXml();
children.add(throttleElement);
}
root.setContent(children);
FileOutputStream o = new java.io.FileOutputStream(f);
try {
XMLOutputter fmt = new XMLOutputter();
fmt.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.PRESERVE));
fmt.output(doc, o);
} catch (IOException ex) {
log.warn("Exception in storing throttle xml: " + ex);
} finally {
o.close();
}
} catch (FileNotFoundException ex) {
log.warn("Exception in storing throttle xml: " + ex);
} catch (IOException ex) {
log.warn("Exception in storing throttle xml: " + ex);
}
}
use of org.jdom2.ProcessingInstruction in project mycore by MyCoRe-Org.
the class MCROAIDataProvider method addXSLStyle.
/**
* Add link to XSL stylesheet for displaying OAI response in web browser.
*/
private Document addXSLStyle(Document doc) {
String styleSheet = MCROAIAdapter.PREFIX + getServletName() + ".ResponseStylesheet";
String xsl = MCRConfiguration.instance().getString(styleSheet, "oai/oai2.xsl");
if (!xsl.isEmpty()) {
Map<String, String> pairs = new HashMap<>();
pairs.put("type", "text/xsl");
pairs.put("href", MCRFrontendUtil.getBaseURL() + xsl);
doc.addContent(0, new ProcessingInstruction("xml-stylesheet", pairs));
}
return doc;
}
use of org.jdom2.ProcessingInstruction in project jspwiki by apache.
the class JSPWikiMarkupParser method paragraphify.
/**
* Checks out that the first paragraph is correctly installed.
*
* @param rootElement
*/
private void paragraphify(final Element rootElement) {
//
// Add the paragraph tag to the first paragraph
//
final List<Content> kids = rootElement.getContent();
if (rootElement.getChild("p") != null) {
final ArrayList<Content> ls = new ArrayList<>();
int idxOfFirstContent = 0;
int count = 0;
for (final Iterator<Content> i = kids.iterator(); i.hasNext(); count++) {
final Content c = i.next();
if (c instanceof Element) {
final String name = ((Element) c).getName();
if (isBlockLevel(name))
break;
}
if (!(c instanceof ProcessingInstruction)) {
ls.add(c);
if (idxOfFirstContent == 0)
idxOfFirstContent = count;
}
}
//
if (ls.size() > 0) {
final Element newel = new Element("p");
for (final Iterator<Content> i = ls.iterator(); i.hasNext(); ) {
final Content c = i.next();
c.detach();
newel.addContent(c);
}
//
if (!newel.getTextTrim().isEmpty() || !newel.getChildren().isEmpty())
rootElement.addContent(idxOfFirstContent, newel);
}
}
}
Aggregations