use of org.jdom2.Content in project hippo by NHS-digital-website.
the class RssModifier method getImageElement.
@NotNull
private Element getImageElement(String imageUrl) {
String type = imageUrl.substring(imageUrl.lastIndexOf(".") + 1);
final Element element = new Element("content", Namespace.getNamespace("http://search.yahoo.com/mrss/"));
element.setAttribute("type", "image/" + type);
element.setAttribute("url", imageUrl);
return element;
}
use of org.jdom2.Content in project dq-easy-cloud by dq-open-cloud.
the class XmlUtilsTest method testReadXml.
@Test
public void testReadXml() {
// 获取根元素
Element root = doc.getRootElement();
System.out.println("---获取第一个子节点和子节点下面的节点信息------");
Element rmElement = root.getChild("resultMap");
System.out.println("resultMap属性的值列表" + rmElement.getChildren("result").size());
// 第一次输入张三 第二次输出123123
System.out.println("getContentSize:" + rmElement.getChildren("result").size());
// for (Content content : rmElement.getContent()) {
// System.out.println("content" + content);
// }
// System.out.println("result:" + rmElement.getChild("result").getAttributes());
// for(Element el: rmElement.getChildren()){
// System.out.println("attribute:" + el.getAttributes());//第一次输入张三 第二次输出123123
// }
//
// System.out.println("---直接在根节点下就遍历所有的子节点---");
// for(Element el: root.getChildren()){
// System.out.println(el.getText());//这里输出4行空格
// System.out.println(el.getChildText("username"));//输出张三 & 1111111112
// System.out.println(el.getChildText("password"));//输出123123 & password2
// }
}
use of org.jdom2.Content in project dq-easy-cloud by dq-open-cloud.
the class XmlUtilsTest method testReadXml.
@Test
public void testReadXml() {
// 获取根元素
Element root = doc.getRootElement();
System.out.println("---获取第一个子节点和子节点下面的节点信息------");
Element rmElement = root.getChild("resultMap");
System.out.println("resultMap属性的值列表" + rmElement.getChildren("result").size());
// 第一次输入张三 第二次输出123123
System.out.println("getContentSize:" + rmElement.getChildren("result").size());
// for (Content content : rmElement.getContent()) {
// System.out.println("content" + content);
// }
// System.out.println("result:" + rmElement.getChild("result").getAttributes());
// for(Element el: rmElement.getChildren()){
// System.out.println("attribute:" + el.getAttributes());//第一次输入张三 第二次输出123123
// }
//
// System.out.println("---直接在根节点下就遍历所有的子节点---");
// for(Element el: root.getChildren()){
// System.out.println(el.getText());//这里输出4行空格
// System.out.println(el.getChildText("username"));//输出张三 & 1111111112
// System.out.println(el.getChildText("password"));//输出123123 & password2
// }
}
use of org.jdom2.Content 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);
}
}
use of org.jdom2.Content 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