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