]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.data/scl/Data/XML.scl
CDATA support to Data/XML
[simantics/platform.git] / bundles / org.simantics.scl.data / scl / Data / XML.scl
1 import "OSGi"
2
3 importJava "org.jdom2.Document" where
4     data Document
5     
6     @JavaName "<init>"
7     createDocument :: Element -> <Proc> Document
8     
9     @JavaName getRootElement
10     rootElementOf :: Document -> <Proc> Element
11     
12     @JavaName setRootElement
13     setRootElement :: Document -> Element -> <Proc> ()
14     
15 importJava "org.jdom2.Element" where
16     data Element
17     
18     @JavaName "<init>"
19     createElement :: String -> <Proc> Element
20     
21     @JavaName getName
22     nameOf :: Element -> <Proc> String
23     
24     @JavaName getText
25     textOf :: Element -> <Proc> String
26     
27     @JavaName getParentElement
28     parentOf :: Element -> <Proc> Maybe Element
29     
30     @JavaName getChildren
31     childrenWithNameOf :: Element -> String -> <Proc> [Element]
32     
33     @JavaName getChildren
34     childrenOf :: Element -> <Proc> [Element]
35     
36     @JavaName getChild
37     childWithNameOf :: Element -> String -> <Proc> Maybe Element
38     
39     @JavaName getAttributeValue
40     attributeOf :: Element -> String -> <Proc> Maybe String
41     
42     @JavaName getAttributes
43     attributesOf :: Element -> <Proc> [Attribute]
44     
45     @JavaName addContent
46     addChild :: Element -> Element -> <Proc> ()
47     
48     setName :: Element -> String -> <Proc> ()
49     
50     setText :: Element -> String -> <Proc> ()
51     
52     setAttribute :: Element -> String -> String -> <Proc> ()
53     
54 importJava "org.jdom2.Attribute" where
55     data Attribute
56     
57     @JavaName getValue
58     valueOfAttribute :: Attribute -> <Proc> String
59     
60     @JavaName getName
61     nameOfAttribute :: Attribute -> <Proc> String
62
63 Element ?parentElement ?childName ?childElement :-
64     @ffb 1.0
65     ?childName = nameOf ?childElement
66     Optional ?parentElement (parentOf ?childElement)
67         
68     @bbf 10.0
69     ?childElement <- childrenWithNameOf ?parentElement ?childName
70
71     @bff 10.0
72     ?childElement <- childrenOf ?parentElement
73     ?childName = nameOf ?childElement
74     
75     @enforce
76     Execute (addNamedChild ?parentElement ?childName ?childElement)
77     
78 Attribute ?element ?attributeName ?attributeValue :-
79     @bbf 0.95
80     Optional ?attributeValue (attributeOf ?element ?attributeName)
81
82     @bff 4.0
83     ?attribute <- attributesOf ?element
84     ?attributeName = nameOfAttribute ?attribute
85     ?attributeValue = valueOfAttribute ?attribute
86
87     @enforce
88     Execute do
89         setAttribute ?element ?attributeName ?attributeValue
90
91 TextContent ?element ?textContent :-
92     @bf 1
93     ?textContent = textOf ?element
94     
95     @enforce
96     Execute do
97         setText ?element ?textContent
98
99 XPathElement ?parentElement ?xpathExpression ?childElement :-
100     @bbf 10
101     ?childElement <- elementsByXPath ?parentElement ?xpathExpression
102
103 importJava "org.simantics.scl.data.xml.JDomHelper" where
104     parseString :: String -> <Proc> Document
105     parseFile :: String -> <Proc> Document
106     outputString :: Document -> <Proc> String
107     
108     elementsByXPath :: Element -> String -> <Proc> [Element]
109     addNamedChild :: Element -> String -> Element -> <Proc> ()
110     setNamespace :: Document -> String -> <Proc> ()
111     setElementNamespace :: Element -> String -> <Proc> ()
112     clearNamespace :: Document -> <Proc> ()
113     clearElementNamespace :: Element -> <Proc> ()
114     sortChildrenWith :: (Element -> Element -> <e> Integer) -> Element -> <Proc,e> () 
115     
116     parseStringWithSchemaFile :: String -> String -> <Proc> Document
117     //parseStringWithSchemaURL  :: URL    -> String -> <Proc> Document
118     parseFileWithSchemaFile   :: String -> String -> <Proc> Document
119     //parseFileWithSchemaURL    :: URL    -> String -> <Proc> Document
120
121     addCDATA :: Element -> String -> <Proc> ()
122     getCDATAs :: Element -> <Proc> [String]
123
124
125 sortChildrenBy :: Ord a => (Element -> <e> a) -> Element -> <Proc,e> ()
126 sortChildrenBy f el = sortChildrenWith (\x y -> compare (f x) (f y)) el