Search in sources :

Example 11 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project dq-easy-cloud by dq-open-cloud.

the class DqXMLUtils method getMapFromInputStream.

/**
 * <p>
 * 将xml流中的信息放入map中
 * </p>
 *
 * @param inputStream
 *            : InputStream : xml输入流
 * @param paramsMap
 *            : Map<String, Object> : xml结果容器
 * @return Map<String, Object>
 * @throws IOException
 * @author daiqi 创建时间 2018年2月23日 下午12:49:06
 */
public static Map<String, Object> getMapFromInputStream(InputStream inputStream, Map<String, Object> paramsMap) throws IOException {
    if (null == paramsMap) {
        paramsMap = new HashMap<>();
    }
    SAXBuilder builder = new SAXBuilder();
    try {
        Document doc = builder.build(inputStream);
        Element root = doc.getRootElement();
        List<Element> list = root.getChildren();
        Iterator<Element> it = list.iterator();
        while (it.hasNext()) {
            Element e = (Element) it.next();
            String k = e.getName();
            Object v = DqStringUtils.EMPTY;
            List<Element> children = e.getChildren();
            if (children.isEmpty()) {
                v = e.getTextNormalize();
            } else {
                v = getChildren(children);
            }
            paramsMap.put(k, v);
        }
    } catch (JDOMException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    return paramsMap;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 12 with Document

use of iso.std.iso._20022.tech.xsd.pain_001_001.Document in project dq-easy-cloud by dq-open-cloud.

the class XmlUtilsTest method main.

/**
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    // Document doc = builder.build(new File("src/test.xml"));
    // Document doc = builder.build(new FileInputStream("src/test.xml"));
    // Document doc = builder.build(new FileReader("src/test.xml"));
    // Document doc = builder.build(new URL("http://localhost:8080/jdomTest/test.xml"));
    Document doc = builder.build(DqSourceCodeRelativePath.RESOURCES + "\\test.xml");
    readXmlFile(doc);
// addXmlElement(doc);
// updateXmlElement(doc);
// deleteXmlElement(doc);
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Document(org.jdom2.Document)

Example 13 with Document

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

the class JDOMUtilsTests method testWrite2XMLFile.

@Test
public void testWrite2XMLFile() throws Exception {
    File tmpFile = TestUtils.createTempFile(".xml");
    Document doc = createDocument();
    JDOMUtils.write2XMLFile(doc, tmpFile);
    assertTrue(tmpFile.exists());
}
Also used : Document(org.jdom2.Document) File(java.io.File) Test(org.junit.Test)

Example 14 with Document

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

the class JDOMUtilsTests method testReadXMLFile_File.

@Test
public void testReadXMLFile_File() throws Exception {
    File file = new File(TESTDATA_FOLDER, "imsmanifest.xml");
    Document doc = JDOMUtils.readXMLFile(file);
    assertNotNull(doc);
    assertTrue(doc.hasRootElement());
}
Also used : Document(org.jdom2.Document) File(java.io.File) Test(org.junit.Test)

Example 15 with Document

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

the class SaveCanvasAsTemplateWizard method createManifest.

private String createManifest() throws IOException {
    Document doc = new Document();
    Element root = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_MANIFEST);
    doc.setRootElement(root);
    // Type
    root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE, CanvasModelTemplate.XML_CANVAS_TEMPLATE_ATTRIBUTE_TYPE_MODEL);
    // Timestamp
    root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TIMESTAMP, Long.toString(System.currentTimeMillis()));
    // Name
    Element elementName = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_NAME);
    elementName.setText(fTemplateName);
    root.addContent(elementName);
    // Description
    Element elementDescription = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_DESCRIPTION);
    elementDescription.setText(fTemplateDescription);
    root.addContent(elementDescription);
    // Thumbnail
    if (fIncludeThumbnail) {
        // $NON-NLS-1$
        String keyThumb = TemplateManager.ZIP_ENTRY_THUMBNAILS + "1.png";
        Element elementKeyThumb = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_KEY_THUMBNAIL);
        elementKeyThumb.setText(keyThumb);
        root.addContent(elementKeyThumb);
    }
    return JDOMUtils.write2XMLString(doc);
}
Also used : Element(org.jdom2.Element) 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