Search in sources :

Example 56 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project JMRI by JMRI.

the class DecoderIndexFileTest method setupDoc.

// provide a test document in the above static variables
void setupDoc() {
    // create a JDOM tree with just some elements
    root = new Element("decoderIndex-config");
    doc = new Document(root);
    doc.setDocType(new DocType("decoderIndex-config", "decoderIndex-config.dtd"));
    // add some elements
    root.addContent(decoderIndexElement = new Element("decoderIndex").addContent(new Element("mfgList").addContent(new Element("manufacturer").setAttribute("mfg", "NMRA")).addContent(new Element("manufacturer").setAttribute("mfg", "Digitrax").setAttribute("mfgID", "129"))).addContent(new Element("familyList").addContent(family1 = new Element("family").setAttribute("mfg", "NMRA").setAttribute("name", "NMRA S&RP definitions").setAttribute("file", "NMRA.xml").addContent(new Element("model").setAttribute("model", "full set").setAttribute("comment", "all CVs in RP 9.2.1")).addContent(new Element("model").setAttribute("model", "required set").setAttribute("comment", "required CVs in RP 9.2.1"))).addContent(family2 = new Element("family").setAttribute("mfg", "Digitrax").setAttribute("name", "FX2 family").setAttribute("file", "DH142.xml").addContent(new Element("model").setAttribute("model", "DH142").setAttribute("numFns", "4").setAttribute("numOuts", "2").setAttribute("lowVersionID", "21")).addContent(new Element("model").setAttribute("model", "DN142").setAttribute("numFns", "5").setAttribute("numOuts", "1").addContent(new Element("versionCV").setAttribute("lowVersionID", "22").setAttribute("highVersionID", "24"))))));
    return;
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) DocType(org.jdom2.DocType)

Example 57 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project JMRI by JMRI.

the class RouteManagerXml 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-routes.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-routes.xsl");
    // NOI18N
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    RouteManager.instance().store(root);
    writeXML(file, doc);
    // done - route file now stored, so can't be dirty
    setDirty(false);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Example 58 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project JMRI by JMRI.

the class StoreXmlVSDecoderAction method saveVSDecoderProfile.

public void saveVSDecoderProfile(java.io.File f) {
    try {
        Element root = new Element("VSDecoderConfig");
        Document doc = XmlFile.newDocument(root, XmlFile.getDefaultDtdLocation() + "vsdecoder-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);
        for (java.util.Iterator<VSDecoder> i = VSDecoderManager.instance().getVSDecoderList().iterator(); i.hasNext(); ) {
            VSDecoder vsd = i.next();
            children.add(vsd.getXml());
        }
        // Throttle-specific stuff below.  Kept for reference
        /*
             // 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);
             }
             */
        // End Throttle-specific stuff.
        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 VSDecoder xml: " + ex);
        } finally {
            o.close();
        }
    } catch (FileNotFoundException ex) {
        log.warn("Exception in storing VSDecoder xml: " + ex);
    } catch (IOException ex) {
        log.warn("Exception in storing VSDecoder xml: " + ex);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Element(org.jdom2.Element) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.jdom2.Document)

Example 59 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project JMRI by JMRI.

the class XmlFile method processOneInstruction.

Document processOneInstruction(ProcessingInstruction p, Document doc) throws org.jdom2.transform.XSLTransformException, org.jdom2.JDOMException, java.io.IOException {
    log.trace("handling ", p);
    // check target
    String target = p.getTarget();
    if (!target.equals("transform-xslt")) {
        return doc;
    }
    String href = p.getPseudoAttributeValue("href");
    // we expect this to start with http://jmri.org/ and refer to the JMRI file tree
    if (!href.startsWith("http://jmri.org/")) {
        return doc;
    }
    href = href.substring(16);
    // if starts with 'xml/' we remove that; findFile will put it back
    if (href.startsWith("xml/")) {
        href = href.substring(4);
    }
    // read the XSLT transform into a Document to get XInclude done
    SAXBuilder builder = getBuilder(Validate.None);
    Document xdoc = builder.build(new BufferedInputStream(new FileInputStream(findFile(href))));
    org.jdom2.transform.XSLTransformer transformer = new org.jdom2.transform.XSLTransformer(xdoc);
    return transformer.transform(doc);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) BufferedInputStream(java.io.BufferedInputStream) Document(org.jdom2.Document) FileInputStream(java.io.FileInputStream)

Example 60 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project JMRI by JMRI.

the class XmlFile method getRoot.

/**
     * Get the root element from an XML document in a stream.
     *
     * @param stream input containing the XML document
     * @return the root element of the XML document
     * @throws org.jdom2.JDOMException if the XML document is invalid
     * @throws java.io.IOException     if the input cannot be read
     */
protected Element getRoot(InputStream stream) throws JDOMException, IOException {
    log.trace("getRoot from stream");
    SAXBuilder builder = getBuilder(getValidate());
    Document doc = builder.build(new BufferedInputStream(stream));
    // handle any process instructions
    doc = processInstructions(doc);
    // find root
    return doc.getRootElement();
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) BufferedInputStream(java.io.BufferedInputStream) Document(org.jdom2.Document)

Aggregations

Document (org.jdom2.Document)391 Element (org.jdom2.Element)243 Test (org.junit.Test)104 SAXBuilder (org.jdom2.input.SAXBuilder)84 IOException (java.io.IOException)72 File (java.io.File)56 XMLOutputter (org.jdom2.output.XMLOutputter)56 JDOMException (org.jdom2.JDOMException)44 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)34 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)25 DocType (org.jdom2.DocType)24 ArrayList (java.util.ArrayList)22 MCRContent (org.mycore.common.content.MCRContent)22 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)22 MCRException (org.mycore.common.MCRException)21 Document (com.google.cloud.language.v1.Document)20 HashMap (java.util.HashMap)19 Attribute (org.jdom2.Attribute)19 MCRObject (org.mycore.datamodel.metadata.MCRObject)19 URL (java.net.URL)18