9c0deb80ae1494d65ce7585ca63fe809f75cbf44
[ckeditor.git] / skins / ckeditor / plugins / plinn_image / connectors / plinn / connector.py
1 ##parameters=command, path, file='', Type='', redirUrl=''
2
3 from Products.CMFCore.utils import getToolByName
4
5 def replaceXMLEntities(text) :
6 for c, ent in (('<', '&lt;'), ('>', '&gt;'), ('&', '&amp;')) :
7 text = text.replace(c, ent)
8 return text
9
10 utool = getToolByName(context, 'portal_url')
11 atool = getToolByName(context, 'portal_attachment')
12
13 portal = utool.getPortalObject()
14
15 ob = portal
16 path = path.strip('/')
17
18 ob = portal
19 path = path.strip('/')
20
21 for name in path.split('/') :
22 ob = getattr(ob, name)
23
24 if command == 'ls':
25 attachments = atool.getAttachmentsFor(ob)
26 attachments = attachments.objectValues()
27
28 print '<ls>'
29 for o in attachments :
30 size = o.getThumbnailSize()
31 row = '<row previewUrl="%(previewUrl)s" url="%(url)s" meta_type="%(meta_type)s" width="%(width)d" height="%(height)d">%(title)s</row>' % {
32 'previewUrl' : '%s/getThumbnail' % o.absolute_url(),
33 'url' : 'attachments/%s' % o.getId(),
34 'meta_type' : o.meta_type,
35 'title' : replaceXMLEntities(o.title_or_id()),
36 'width' : size['width'],
37 'height' : size['height']
38 }
39 print row
40 print '</ls>'
41
42 if command == 'upload' :
43 atool.uploadAttachmentFor(ob, file, typeName=Type)
44 return context.REQUEST.RESPONSE.redirect(redirUrl);
45
46 if command == 'rm' :
47 ob = context.restrictedTraverse(path)
48 parent = ob.getParentNode()
49 parent.manage_delObjects(ob.getId())
50 print '<done/>'
51
52
53 context.REQUEST.RESPONSE.setHeader('content-type', 'text/xml; charset=utf-8')
54 return printed