Copie de MosaicDocument à partir de :
[MosaicDocument.git] / skins / xml_nav_tree.py
1 ##parameters=filter=''
2
3 def replaceXMLEntities(text) :
4 for c, ent in (('<', '&lt;'), ('>', '&gt;'), ('&', '&amp;')) :
5 text = text.replace(c, ent)
6 return text
7
8 from string import maketrans
9 rmBadAttrChars = maketrans('<&"', ' ')
10
11 filter = filter.split(',')
12
13 root = context
14 context.REQUEST.RESPONSE.setHeader('content-type', 'text/xml; charset=utf-8')
15 print '<xml>'
16 for ob in context.listNearestFolderContents(contentFilter={'portal_type':filter}) :
17 icon = context.restrictedTraverse(ob.getIcon())
18 state = 0
19 if not getattr(ob, 'isPortalContent', False) :
20 state = ob.listNearestFolderContents(contentFilter={'portal_type':filter}) and "-1" or "0"
21 row = '<row id="%(id)s" url="%(url)s" icon="%(icon)s" height="%(height)d" width="%(width)d" state="%(state)s" description="%(description)s">%(title)s</row>' % {
22 'id' : ob.getId(),
23 'url' : ob.absolute_url(),
24 'title' : ' '+replaceXMLEntities(ob.title_or_id()),
25 'description' : ob.Description().translate(rmBadAttrChars),
26 'icon' : icon.absolute_url(),
27 'height' : icon.height,
28 'width' : icon.width,
29 'state' : state
30 }
31 print row
32
33
34 print '</xml>'
35
36 return printed