61d0eaee8a18b9b3646c8c5d31d108686710a450
[ckeditor.git] / skins / ckeditor / filemanager / browser / mac_finder / connectors / plinn / connector.py
1 ##parameters=command, path, Type=None
2 from Products.CMFCore.utils import getToolByName
3 from Products.CMFCore.permissions import View
4 mtool = getToolByName(context, 'portal_membership')
5 checkView = lambda o : mtool.checkPermission(View, o)
6 utool = getToolByName(context, 'portal_url')
7 portal = utool.getPortalObject()
8
9 def replaceXMLEntities(text) :
10 for c, ent in (('<', '&lt;'), ('>', '&gt;'), ('&', '&amp;')) :
11 text = text.replace(c, ent)
12 return text
13
14 ob = portal
15 path = path.replace('\\', '/')
16 path = path.strip('/')
17
18 if path :
19 for name in path.split('/') :
20 ob = getattr(ob, name)
21
22 if command == 'ls' :
23 objects = []
24 if ob.isPrincipiaFolderish :
25 if Type == 'Image' : filter = {'portal_type' : ['Plinn Folder', 'Portfolio', 'Photo']}
26 else : filter = {}
27 objects = ob.listNearestFolderContents(contentFilter = filter)
28 objects = sequence.sort( objects, (('title_or_id', 'nocase', 'asc'),) )
29
30 # xml printing
31 print '<ls>'
32 for o in objects :
33 path = o.getPhysicalPath()
34 encodedPath = ''
35 partObject = portal
36 for name in path[1:] :
37 partObject = getattr(partObject, name)
38 sep = checkView(partObject) and '/' or '\\'
39 encodedPath += sep+name
40
41 row = '<row path="%(path)s" folderish="%(folderish)s" icon="%(icon)s" link="%(link)s">%(title)s</row>' % {
42 'path' : encodedPath,
43 'folderish' : o.isPrincipiaFolderish,
44 'icon' : o.getIcon(),
45 'title' : replaceXMLEntities(o.title_or_id()),
46 'link' : o.absolute_url()
47 }
48 print row
49 print '</ls>'
50
51 elif command == 'info':
52 #linkFunction = (Type == 'Image') and (lambda o : o.absolute_url() + '/index_html') or (lambda o : o.absolute_url())
53 linkFunction = lambda o : o.absolute_url()
54 ti = ob.getTypeInfo()
55 method_id = ti.queryMethodID('info')
56 meth = method_id and getattr(ob, method_id) or (lambda:'Not implemented')
57 lines = []
58 pr = lines.append
59 pr('<info>')
60 # print info summary in a CDATA section
61 pr('<![CDATA[')
62 pr(meth())
63 pr(']]>')
64 # print the url link in a <link> tag
65 pr('<link>')
66 pr(linkFunction(ob))
67 pr('</link>')
68 pr('</info>')
69 print ''.join(lines)
70
71
72 context.REQUEST.RESPONSE.setHeader('content-type', 'text/xml; charset=utf-8')
73 return printed