341babb0a2098dd5d11616d722f49d0683376ee4
[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 if not method_id or not hasattr(ob, method_id) :
57 meth = lambda:'Not implemented'
58 else :
59 path = list(ob.getPhysicalPath())
60 path.append(method_id)
61 app = context.restrictedTraverse('/')
62 meth = app.restrictedTraverse(tuple(path))
63
64 lines = []
65 pr = lines.append
66 pr('<info>')
67 # print info summary in a CDATA section
68 pr('<![CDATA[')
69 pr(meth())
70 pr(']]>')
71 # print the url link in a <link> tag
72 pr('<link>')
73 pr(linkFunction(ob))
74 pr('</link>')
75 pr('</info>')
76 print ''.join(lines)
77
78
79 context.REQUEST.RESPONSE.setHeader('content-type', 'text/xml; charset=utf-8')
80 return printed