From a5a1c8cd3203e8e5743073060b2f2ea430cef86c Mon Sep 17 00:00:00 2001 From: Antti Villberg Date: Fri, 5 Jan 2018 18:18:31 +0200 Subject: [PATCH] CDATA support to Data/XML #7708 Change-Id: I6a2e9e05b4f79e83a11b4051658832053feadff9 --- .../org.simantics.scl.data/scl/Data/XML.scl | 4 ++++ .../org/simantics/scl/data/xml/JDomHelper.java | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/bundles/org.simantics.scl.data/scl/Data/XML.scl b/bundles/org.simantics.scl.data/scl/Data/XML.scl index 3f78b5ab5..7f836aaa4 100644 --- a/bundles/org.simantics.scl.data/scl/Data/XML.scl +++ b/bundles/org.simantics.scl.data/scl/Data/XML.scl @@ -118,5 +118,9 @@ importJava "org.simantics.scl.data.xml.JDomHelper" where parseFileWithSchemaFile :: String -> String -> Document //parseFileWithSchemaURL :: URL -> String -> Document + addCDATA :: Element -> String -> () + getCDATAs :: Element -> [String] + + sortChildrenBy :: Ord a => (Element -> a) -> Element -> () sortChildrenBy f el = sortChildrenWith (\x y -> compare (f x) (f y)) el \ No newline at end of file diff --git a/bundles/org.simantics.scl.data/src/org/simantics/scl/data/xml/JDomHelper.java b/bundles/org.simantics.scl.data/src/org/simantics/scl/data/xml/JDomHelper.java index 897af542a..78a54410c 100644 --- a/bundles/org.simantics.scl.data/src/org/simantics/scl/data/xml/JDomHelper.java +++ b/bundles/org.simantics.scl.data/src/org/simantics/scl/data/xml/JDomHelper.java @@ -5,12 +5,17 @@ import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.net.URL; +import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ArrayBlockingQueue; +import org.jdom2.CDATA; +import org.jdom2.Content; +import org.jdom2.Content.CType; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.IllegalAddException; @@ -169,4 +174,17 @@ public class JDomHelper { } }); } + + public static void addCDATA(Element element, String cdata) { + element.addContent(new CDATA(cdata)); + } + + public static List getCDATAs(Element element) { + ArrayList result = new ArrayList<>(); + for(Content c : element.getContent()) { + if(CType.CDATA.equals(c.getCType())) result.add(c.getValue()); + } + return result; + } + } -- 2.47.1