forked from SolidOS/solid-panes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RDFXMLPane.js
50 lines (43 loc) · 1.51 KB
/
RDFXMLPane.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* RDF/XML content Pane
**
** This pane shows the content of a particular RDF resource
** or at least the RDF semantics we attribute to that resource,
** in generated N3 syntax.
*/
var UI = require('solid-ui')
module.exports = {
icon: UI.icons.originalIconBase + '22-text-xml4.png',
name: 'RDFXML',
label: function (subject) {
if ('http://www.w3.org/2007/ont/link#ProtocolEvent' in UI.store.findTypeURIs(subject)) return null
var n = UI.store.statementsMatching(
undefined, undefined, undefined, subject).length
if (n === 0) return null
return 'As RDF/XML (' + n + ')'
},
render: function (subject, myDocument) {
var kb = UI.store
var div = myDocument.createElement('div')
div.setAttribute('class', 'RDFXMLPane')
// Because of smushing etc, this will not be a copy of the original source
// We could instead either fetch and re-parse the source,
// or we could keep all the pre-smushed triples.
var sts = kb.statementsMatching(undefined, undefined, undefined, subject) // @@ slow with current store!
/*
var kludge = kb.formula([]) // No features
for (var i=0; i< sts.length; i++) {
s = sts[i]
kludge.add(s.subject, s.predicate, s.object)
}
*/
var sz = UI.rdf.Serializer(kb)
sz.suggestNamespaces(kb.namespaces)
sz.setBase(subject.uri)
var str = sz.statementsToXML(sts)
var pre = myDocument.createElement('PRE')
pre.appendChild(myDocument.createTextNode(str))
div.appendChild(pre)
return div
}
}
// ends