Search in sources :

Example 1 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("---获取第一个子节点和子节点下面的节点信息------");
    List<Element> rmElements = root.getChildren();
    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 2 with Content

use of org.jdom2.Content in project ddf by codice.

the class OpenSearchSource method createResponseFromEntry.

/**
     * Creates a single response from input parameters. Performs XPath operations on the document to
     * retrieve data not passed in.
     *
     * @param entry a single Atom entry
     * @return single response
     * @throws ddf.catalog.source.UnsupportedQueryException
     */
private List<Result> createResponseFromEntry(SyndEntry entry) throws UnsupportedQueryException {
    String id = entry.getUri();
    if (id != null && !id.isEmpty()) {
        id = id.substring(id.lastIndexOf(':') + 1);
    }
    List<SyndContent> contents = entry.getContents();
    List<SyndCategory> categories = entry.getCategories();
    List<Metacard> metacards = new ArrayList<>();
    List<Element> foreignMarkup = entry.getForeignMarkup();
    String relevance = "";
    String source = "";
    for (Element element : foreignMarkup) {
        if (element.getName().equals("score")) {
            relevance = element.getContent(0).getValue();
        }
    }
    //we currently do not support downloading content via an RSS enclosure, this support can be added at a later date if we decide to include it
    for (SyndContent content : contents) {
        MetacardImpl metacard = getMetacardImpl(parseContent(content.getValue(), id));
        metacard.setSourceId(this.shortname);
        String title = metacard.getTitle();
        if (StringUtils.isEmpty(title)) {
            metacard.setTitle(entry.getTitle());
        }
        if (!source.isEmpty()) {
            metacard.setSourceId(source);
        }
        metacards.add(metacard);
    }
    for (int i = 0; i < categories.size() && i < metacards.size(); i++) {
        SyndCategory category = categories.get(i);
        Metacard metacard = metacards.get(i);
        if (StringUtils.isBlank(metacard.getContentTypeName())) {
            ((MetacardImpl) metacard).setContentTypeName(category.getName());
        }
    }
    List<Result> results = new ArrayList<>();
    for (Metacard metacard : metacards) {
        ResultImpl result = new ResultImpl(metacard);
        if (relevance == null || relevance.isEmpty()) {
            LOGGER.debug("couldn't find valid relevance. Setting relevance to 0");
            relevance = "0";
        }
        result.setRelevanceScore(new Double(relevance));
        results.add(result);
    }
    return results;
}
Also used : SyndCategory(com.rometools.rome.feed.synd.SyndCategory) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) SyndContent(com.rometools.rome.feed.synd.SyndContent)

Example 3 with Content

use of org.jdom2.Content in project JMRI by JMRI.

the class SwitchboardServlet method getXmlPanel.

@Override
protected String getXmlPanel(String name) {
    log.debug("Getting {} for {}", getPanelType(), name);
    try {
        SwitchboardEditor editor = (SwitchboardEditor) getEditor(name);
        Element panel = new Element("panel");
        JFrame frame = editor.getTargetFrame();
        panel.setAttribute("name", name);
        panel.setAttribute("height", Integer.toString(frame.getContentPane().getHeight()));
        panel.setAttribute("width", Integer.toString(frame.getContentPane().getWidth()));
        panel.setAttribute("panelheight", Integer.toString(editor.getTargetPanel().getHeight()));
        panel.setAttribute("panelwidth", Integer.toString(editor.getTargetPanel().getWidth()));
        // add more properties
        panel.setAttribute("showtooltips", (editor.showTooltip()) ? "yes" : "no");
        panel.setAttribute("controlling", (editor.allControlling()) ? "yes" : "no");
        panel.setAttribute("hideunconnected", (editor.hideUnconnected()) ? "yes" : "no");
        panel.setAttribute("rangemin", Integer.toString(editor.getPanelMenuRangeMin()));
        panel.setAttribute("rangemax", Integer.toString(editor.getPanelMenuRangeMax()));
        panel.setAttribute("type", editor.getSwitchType());
        panel.setAttribute("connection", editor.getSwitchManu());
        panel.setAttribute("shape", editor.getSwitchShape());
        panel.setAttribute("columns", Integer.toString(editor.getColumns()));
        panel.setAttribute("defaulttextcolor", editor.getDefaultTextColor());
        log.debug("webserver Switchboard attribs ready");
        Element bgColor = new Element("backgroundColor");
        if (editor.getBackgroundColor() == null) {
            // set to light grey
            bgColor.setAttribute("red", Integer.toString(192));
            bgColor.setAttribute("green", Integer.toString(192));
            bgColor.setAttribute("blue", Integer.toString(192));
        } else {
            bgColor.setAttribute("red", Integer.toString(editor.getBackgroundColor().getRed()));
            bgColor.setAttribute("green", Integer.toString(editor.getBackgroundColor().getGreen()));
            bgColor.setAttribute("blue", Integer.toString(editor.getBackgroundColor().getBlue()));
        }
        panel.addContent(bgColor);
        Element text = new Element("text");
        text.setAttribute("color", editor.getDefaultTextColor());
        text.setAttribute("content", "For now, Switchboards only present buttons in JMRI WebServer.");
        panel.addContent(text);
        // include switches, Bug: how to delete the old ones?
        // call method in SwitchboardEditor
        List<BeanSwitch> _switches = editor.getSwitches();
        log.debug("SwbServlet N switches: {}", _switches.size());
        for (BeanSwitch sub : _switches) {
            if (sub != null) {
                try {
                    Element e = ConfigXmlManager.elementFromObject(sub);
                    if (e != null) {
                        log.debug("element name: {}", e.getName());
                        // }
                        try {
                            e.setAttribute("label", sub.getNameString());
                            e.setAttribute(JSON.ID, sub.getNamedBean().getSystemName());
                            if (sub.getNamedBean() == null) {
                                e.setAttribute("connected", "false");
                                log.debug("switch {} NOT connected", sub.getNameString());
                            } else {
                                // activate click action via class
                                e.setAttribute("connected", "true");
                            }
                        } catch (NullPointerException ex) {
                            if (sub.getNamedBean() == null) {
                                log.debug("{} {} does not have an associated NamedBean", e.getName(), e.getAttribute(JSON.NAME));
                            } else {
                                log.debug("{} {} does not have a SystemName", e.getName(), e.getAttribute(JSON.NAME));
                            }
                        }
                        // read shared attribs
                        e.setAttribute("textcolor", editor.getDefaultTextColor());
                        e.setAttribute("type", editor.getSwitchType());
                        e.setAttribute("connection", editor.getSwitchManu());
                        e.setAttribute("shape", editor.getSwitchShape());
                        e.setAttribute("columns", Integer.toString(editor.getColumns()));
                        // process and add
                        parsePortableURIs(e);
                        panel.addContent(e);
                    }
                } catch (Exception ex) {
                    log.error("Error reading xml panel element: " + ex, ex);
                }
            }
        }
        Document doc = new Document(panel);
        XMLOutputter out = new XMLOutputter();
        out.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.TRIM));
        return out.outputString(doc);
    } catch (NullPointerException ex) {
        log.warn("Requested Switchboard [" + name + "] does not exist.");
        return "ERROR Requested Switchboard [" + name + "] does not exist.";
    }
}
Also used : SwitchboardEditor(jmri.jmrit.display.switchboardEditor.SwitchboardEditor) XMLOutputter(org.jdom2.output.XMLOutputter) JFrame(javax.swing.JFrame) Element(org.jdom2.Element) BeanSwitch(jmri.jmrit.display.switchboardEditor.SwitchboardEditor.BeanSwitch) Document(org.jdom2.Document)

Example 4 with Content

use of org.jdom2.Content in project JMRI by JMRI.

the class SampleFactory method getBasicSample.

public static Element getBasicSample() {
    Element root = new Element("cdi");
    root.addContent(new Element("identification").addContent(new Element("manufacturer").addContent("OpenLCB Prototype")).addContent(new Element("model").addContent("Basic sketch")).addContent(new Element("hardwareVersion").addContent("Arduino (any)")).addContent(new Element("softwareVersion").addContent("0.4")).addContent(new Element("map").addContent(new Element("relation").addContent(new Element("property").addContent("size")).addContent(new Element("value").addContent("8 cm by 12 cm"))).addContent(new Element("relation").addContent(new Element("property").addContent("weight")).addContent(new Element("value").addContent("220g"))).addContent(new Element("relation").addContent(new Element("property").addContent("power")).addContent(new Element("value").addContent("12V at 100mA")))));
    root.addContent(new Element("segment").setAttribute("space", "0").setAttribute("origin", "0").addContent(new Element("name").addContent("Content")).addContent(new Element("description").addContent("Variables for controlling general operation")).addContent(new Element("group").addContent(new Element("name").addContent("Produced Events")).addContent(new Element("description").addContent("The EventIDs for the producers")).addContent(new Element("eventid")).addContent(new Element("eventid"))).addContent(new Element("group").addContent(new Element("name").addContent("Consumed Events")).addContent(new Element("description").addContent("The EventIDs for the consumers")).addContent(new Element("eventid")).addContent(new Element("eventid"))).addContent(new Element("int").setAttribute("size", "1").addContent(new Element("name").addContent("Regular bit variable")).addContent(new Element("description").addContent("Demonstrate how a standard bit (boolean) variable can be shown"))).addContent(new Element("int").setAttribute("size", "1").addContent(new Element("name").addContent("Bit variable with named states")).addContent(new Element("description").addContent("Demonstrate how a map relabels the states of a bit (boolean) variable")).addContent(new Element("map").addContent(new Element("relation").addContent(new Element("property").addContent("1")).addContent(new Element("value").addContent("Lit"))).addContent(new Element("relation").addContent(new Element("property").addContent("0")).addContent(new Element("value").addContent("Not Lit"))))));
    root.addContent(new Element("segment").setAttribute("space", "1").setAttribute("origin", "128").addContent(new Element("name").addContent("Resets")).addContent(new Element("description").addContent("Memory locations controlling resets")).addContent(new Element("int").setAttribute("size", "1").addContent(new Element("name").addContent("Reset")).addContent(new Element("description").addContent("Controls reloading and clearing node memory. Board must be restarted for this to take effect.")).addContent(new Element("map").addContent(new Element("relation").addContent(new Element("property").addContent("85")).addContent(new Element("value").addContent("(No reset)"))).addContent(new Element("relation").addContent(new Element("property").addContent("0")).addContent(new Element("value").addContent("Reset all to defaults"))).addContent(new Element("relation").addContent(new Element("property").addContent("170")).addContent(new Element("value").addContent("Reset just EventIDs to defaults"))))));
    root.addContent(new Element("segment").setAttribute("space", "3").setAttribute("origin", "0").addContent(new Element("name").addContent("Demos")).addContent(new Element("description").addContent("Demonstrations of various CDI capabilities")).addContent(new Element("group").setAttribute("replication", "2").addContent(new Element("name").addContent("Outer Group")).addContent(new Element("description").addContent("The contents of this group are replicated by 2")).addContent(new Element("group").setAttribute("replication", "3").addContent(new Element("name").addContent("Inner Group")).addContent(new Element("repname").addContent("Inner Label")).addContent(new Element("description").addContent("The contents of this group are replicated by 3")).addContent(new Element("int").setAttribute("size", "1").addContent(new Element("name").addContent("Int inside groups")).addContent(new Element("description").addContent("This is inside a 2x3 group"))))));
    return root;
}
Also used : Element(org.jdom2.Element)

Example 5 with Content

use of org.jdom2.Content in project JMRI by JMRI.

the class DefaultCatalogTreeManagerXml method writeCatalogTrees.

/*
     *  Writes out tree values to a file in the user's preferences directory
     */
public void writeCatalogTrees() throws java.io.IOException {
    if (log.isDebugEnabled()) {
        log.debug("entered writeCatalogTreeValues");
    }
    CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
    List<String> trees = manager.getSystemNameList();
    boolean found = false;
    Iterator<String> iter = manager.getSystemNameList().iterator();
    while (iter.hasNext()) {
        String sname = iter.next();
        CatalogTree tree = manager.getBySystemName(sname);
        if (log.isDebugEnabled()) {
            log.debug("Tree: sysName= " + sname + ", userName= " + tree.getUserName());
            CatalogTreeNode root = tree.getRoot();
            log.debug("enumerateTree called for root= " + root.toString() + ", has " + root.getChildCount() + " children");
            // root.depthFirstEnumeration isn't fully typed in JDOM2
            @SuppressWarnings("unchecked") Enumeration<CatalogTreeNode> e = root.depthFirstEnumeration();
            while (e.hasMoreElements()) {
                CatalogTreeNode n = e.nextElement();
                log.debug("nodeName= " + n.getUserObject() + " has " + n.getLeaves().size() + " leaves and " + n.getChildCount() + " subnodes.");
            }
        }
        if (sname != null && sname.charAt(1) == CatalogTree.XML) {
            found = true;
            break;
        }
    }
    if (found) {
        // there are trees defined, create root element
        Element root = new Element("catalogTrees");
        Document doc = newDocument(root, dtdLocation + "catalogTree.dtd");
        // add XSLT processing instruction
        // <?xml-stylesheet type="text/xsl" href="XSLT/tree-values.xsl"?>
        java.util.Map<String, String> m = new java.util.HashMap<>();
        m.put("type", "text/xsl");
        m.put("href", xsltLocation + "panelfile.xsl");
        org.jdom2.ProcessingInstruction p = new org.jdom2.ProcessingInstruction("xml-stylesheet", m);
        doc.addContent(0, p);
        store(root, trees);
        try {
            if (!checkFile(DEFAULT_FILE_NAME)) {
                // file does not exist, create it
                File file = new File(DEFAULT_FILE_NAME);
                if (!file.createNewFile()) {
                    log.error("createNewFile failed");
                }
            }
            // write content to file
            writeXML(findFile(DEFAULT_FILE_NAME), doc);
            // memory consistent with file
            jmri.jmrit.catalog.ImageIndexEditor.indexChanged(false);
        } catch (java.io.IOException ioe) {
            log.error("IO Exception " + ioe);
            throw (ioe);
        }
    }
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) CatalogTreeManager(jmri.CatalogTreeManager) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode) CatalogTree(jmri.CatalogTree) File(java.io.File) XmlFile(jmri.jmrit.XmlFile)

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