Search in sources :

Example 66 with Content

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;
}
Also used : Element(org.jdom2.Element) NotNull(org.jetbrains.annotations.NotNull)

Example 67 with Content

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
// }
}
Also used : Element(org.jdom2.Element) Test(org.junit.Test)

Example 68 with Content

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
// }
}
Also used : Element(org.jdom2.Element) Test(org.junit.Test)

Example 69 with Content

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);
    }
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Element(org.jdom2.Element) File(java.io.File)

Example 70 with Content

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();
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) BufferedInputStream(java.io.BufferedInputStream) Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

Element (org.jdom2.Element)77 Document (org.jdom2.Document)27 IOException (java.io.IOException)18 JDOMException (org.jdom2.JDOMException)16 File (java.io.File)11 MCRException (org.mycore.common.MCRException)11 Content (org.jdom2.Content)10 MCRContent (org.mycore.common.content.MCRContent)10 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)10 XMLOutputter (org.jdom2.output.XMLOutputter)9 SAXBuilder (org.jdom2.input.SAXBuilder)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 Attribute (org.jdom2.Attribute)6 MCRPath (org.mycore.datamodel.niofs.MCRPath)6 SAXException (org.xml.sax.SAXException)6 JsonElement (com.google.gson.JsonElement)5 Color (java.awt.Color)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 MCRObject (org.mycore.datamodel.metadata.MCRObject)4