From: Antti Villberg Date: Fri, 5 Jan 2018 16:18:31 +0000 (+0200) Subject: CDATA support to Data/XML X-Git-Tag: v1.43.0~136^2~637 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F52%2F1352%2F2;p=simantics%2Fplatform.git CDATA support to Data/XML #7708 Change-Id: I6a2e9e05b4f79e83a11b4051658832053feadff9 --- 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; + } + }