Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Private Attributes
zope.FCKeditorConnectorZope Class Reference
Inheritance diagram for zope.FCKeditorConnectorZope:
Inheritance graph
[legend]
Collaboration diagram for zope.FCKeditorConnectorZope:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getZopeRootContext
def getZopeUploadContext
def setHeader
def getFolders
def getZopeFoldersAndFiles
def getZopeFiles
def findZopeFolder
def createFolder
def uploadFile
def doResponse
def getFoldersAndFiles
def createServerFolder
def uploadFile
def setHttpHeaders
def createXmlHeader
def createXmlFooter
def sendError
def sendErrorNode
def sendUploadResults

Public Attributes

 context
 request
 zopeRootContext
 zopeUploadContext
 userFilesFolder
 webUserFilesFolder
 headers
 environ

Static Private Attributes

int __allow_access_to_unprotected_subobjects__ = 1

Detailed Description

Zope versiof FCKeditorConnector

Definition at line 36 of file zope.py.


Constructor & Destructor Documentation

def zope.FCKeditorConnectorZope.__init__ (   self,
  context = None 
)
Constructor

Reimplemented from fckconnector.FCKeditorConnectorBase.

Definition at line 43 of file zope.py.

00043 
00044        def __init__(self, context=None):
00045               """
00046               Constructor
00047               """
00048               FCKeditorConnector.__init__(self, environ=None) # call superclass constructor
00049               # Instance Attributes
00050               self.context = context
00051               self.request = FCKeditorRequest(context)


Member Function Documentation

def zope.FCKeditorConnectorZope.createFolder (   self,
  resourceType,
  currentFolder 
)
Purpose: command to create a new folder

Reimplemented from fckcommands.CreateFolderCommandMixin.

Definition at line 120 of file zope.py.

00120 
00121        def createFolder(self, resourceType, currentFolder):
00122               # Find out where we are
00123               zopeFolder = self.findZopeFolder(resourceType, currentFolder)
00124               errorNo = 0
00125               errorMsg = ""
00126               if self.request.has_key("NewFolderName"):
00127                      newFolder = self.request.get("NewFolderName", None)
00128                      zopeFolder.manage_addProduct["OFSP"].manage_addFolder(id=newFolder, title=newFolder)
00129               else:
00130                      errorNo = 102
00131               return self.sendErrorNode ( errorNo, errorMsg )

Here is the call graph for this function:

def fckcommands.CreateFolderCommandMixin.createServerFolder (   self,
  folderPath 
) [inherited]

Definition at line 114 of file fckcommands.py.

00114 
00115        def createServerFolder(self, folderPath):
00116               "Purpose: physically creates a folder on the server"
00117               # No need to check if the parent exists, just create all hierachy
00118 
00119               try:
00120                      permissions = Config.ChmodOnFolderCreate
00121                      if not permissions:
00122                             os.makedirs(folderPath)
00123               except AttributeError: #ChmodOnFolderCreate undefined
00124                      permissions = 0755
00125 
00126               if permissions:
00127                      oldumask = os.umask(0)
00128                      os.makedirs(folderPath,mode=0755)
00129                      os.umask( oldumask )

Here is the caller graph for this function:

def fckoutput.BaseXmlMixin.createXmlFooter (   self) [inherited]

Definition at line 85 of file fckoutput.py.

00085 
00086        def createXmlFooter(self):
00087               "Purpose: returns the xml footer"
00088               return """</Connector>"""

def fckoutput.BaseXmlMixin.createXmlHeader (   self,
  command,
  resourceType,
  currentFolder,
  url 
) [inherited]

Definition at line 68 of file fckoutput.py.

00068 
00069        def createXmlHeader(self, command, resourceType, currentFolder, url):
00070               "Purpose: returns the xml header"
00071               self.setHttpHeaders()
00072               # Create the XML document header
00073               s =  """<?xml version="1.0" encoding="utf-8" ?>"""
00074               # Create the main connector node
00075               s += """<Connector command="%s" resourceType="%s">""" % (
00076                             command,
00077                             resourceType
00078                             )
00079               # Add the current folder node
00080               s += """<CurrentFolder path="%s" url="%s" />""" % (
00081                             convertToXmlAttribute(currentFolder),
00082                             convertToXmlAttribute(url),
00083                             )
00084               return s

Here is the call graph for this function:

def connector.FCKeditorConnector.doResponse (   self) [inherited]

Definition at line 43 of file connector.py.

00043 
00044        def doResponse(self):
00045               "Main function. Process the request, set headers and return a string as response."
00046               s = ""
00047               # Check if this connector is disabled
00048               if not(Config.Enabled):
00049                      return self.sendError(1, "This connector is disabled.  Please check the connector configurations in \"editor/filemanager/connectors/py/config.py\" and try again.")
00050               # Make sure we have valid inputs
00051               for key in ("Command","Type","CurrentFolder"):
00052                      if not self.request.has_key (key):
00053                             return
00054               # Get command, resource type and current folder
00055               command = self.request.get("Command")
00056               resourceType = self.request.get("Type")
00057               currentFolder = getCurrentFolder(self.request.get("CurrentFolder"))
00058               # Check for invalid paths
00059               if currentFolder is None:
00060                      if (command == "FileUpload"):
00061                             return self.sendUploadResults( errorNo = 102, customMsg = "" )
00062                      else:
00063                             return self.sendError(102, "")
00064 
00065               # Check if it is an allowed command
00066               if ( not command in Config.ConfigAllowedCommands ):
00067                      return self.sendError( 1, 'The %s command isn\'t allowed' % command )
00068 
00069               if ( not resourceType in Config.ConfigAllowedTypes  ):
00070                      return self.sendError( 1, 'Invalid type specified' )
00071 
00072               # Setup paths
00073               if command == "QuickUpload":
00074                      self.userFilesFolder = Config.QuickUploadAbsolutePath[resourceType]
00075                      self.webUserFilesFolder =  Config.QuickUploadPath[resourceType]
00076               else:
00077                      self.userFilesFolder = Config.FileTypesAbsolutePath[resourceType]
00078                      self.webUserFilesFolder = Config.FileTypesPath[resourceType]
00079 
00080               if not self.userFilesFolder: # no absolute path given (dangerous...)
00081                      self.userFilesFolder = mapServerPath(self.environ,
00082                                                                self.webUserFilesFolder)
00083               # Ensure that the directory exists.
00084               if not os.path.exists(self.userFilesFolder):
00085                      try:
00086                             self.createServerFolder( self.userFilesFolder )
00087                      except:
00088                             return self.sendError(1, "This connector couldn\'t access to local user\'s files directories.  Please check the UserFilesAbsolutePath in \"editor/filemanager/connectors/py/config.py\" and try again. ")
00089 
00090               # File upload doesn't have to return XML, so intercept here
00091               if (command == "FileUpload"):
00092                      return self.uploadFile(resourceType, currentFolder)
00093 
00094               # Create Url
00095               url = combinePaths( self.webUserFilesFolder, currentFolder )
00096 
00097               # Begin XML
00098               s += self.createXmlHeader(command, resourceType, currentFolder, url)
00099               # Execute the command
00100               selector = {"GetFolders": self.getFolders,
00101                                    "GetFoldersAndFiles": self.getFoldersAndFiles,
00102                                    "CreateFolder": self.createFolder,
00103                                    }
00104               s += selector[command](resourceType, currentFolder)
00105               s += self.createXmlFooter()
00106               return s
00107 
# Running from command line (plain old CGI)

Here is the call graph for this function:

def zope.FCKeditorConnectorZope.findZopeFolder (   self,
  resourceType,
  folderName 
)

Definition at line 103 of file zope.py.

00103 
00104        def findZopeFolder(self, resourceType, folderName):
00105               # returns the context of the resource / folder
00106               zopeFolder = self.getZopeUploadContext()
00107               folderName = self.removeFromStart(folderName, "/")
00108               folderName = self.removeFromEnd(folderName, "/")
00109               if (resourceType <> ""):
00110                      try:
00111                             zopeFolder = zopeFolder[resourceType]
00112                      except:
00113                             zopeFolder.manage_addProduct["OFSP"].manage_addFolder(id=resourceType, title=resourceType)
00114                             zopeFolder = zopeFolder[resourceType]
00115               if (folderName <> ""):
00116                      folderNames = folderName.split("/")
00117                      for folderName in folderNames:
00118                             zopeFolder = zopeFolder[folderName]
00119               return zopeFolder

Here is the call graph for this function:

Here is the caller graph for this function:

def zope.FCKeditorConnectorZope.getFolders (   self,
  resourceType,
  currentFolder 
)
Purpose: command to recieve a list of folders

Reimplemented from fckcommands.GetFoldersCommandMixin.

Definition at line 70 of file zope.py.

00070 
00071        def getFolders(self, resourceType, currentFolder):
00072               # Open the folders node
00073               s = ""
00074               s += """<Folders>"""
00075               zopeFolder = self.findZopeFolder(resourceType, currentFolder)
00076               for (name, o) in zopeFolder.objectItems(["Folder"]):
00077                      s += """<Folder name="%s" />""" % (
00078                                    convertToXmlAttribute(name)
00079                                    )
00080               # Close the folders node
00081               s += """</Folders>"""
00082               return s

Here is the call graph for this function:

def fckcommands.GetFoldersAndFilesCommandMixin.getFoldersAndFiles (   self,
  resourceType,
  currentFolder 
) [inherited]
Purpose: command to recieve a list of folders and files

Definition at line 57 of file fckcommands.py.

00057 
00058        def getFoldersAndFiles(self, resourceType, currentFolder):
00059               """
00060               Purpose: command to recieve a list of folders and files
00061               """
00062               # Map the virtual path to our local server
00063               serverPath = mapServerFolder(self.userFilesFolder,currentFolder)
00064               # Open the folders / files node
00065               folders = """<Folders>"""
00066               files = """<Files>"""
00067               for someObject in os.listdir(serverPath):
00068                      someObjectPath = mapServerFolder(serverPath, someObject)
00069                      if os.path.isdir(someObjectPath):
00070                             folders += """<Folder name="%s" />""" % (
00071                                           convertToXmlAttribute(someObject)
00072                                           )
00073                      elif os.path.isfile(someObjectPath):
00074                             size = os.path.getsize(someObjectPath)
00075                             if size > 0:
00076                                    size = round(size/1024)
00077                                    if size < 1:
00078                                           size = 1
00079                             files += """<File name="%s" size="%d" />""" % (
00080                                           convertToXmlAttribute(someObject),
00081                                           size
00082                                           )
00083               # Close the folders / files node
00084               folders += """</Folders>"""
00085               files += """</Files>"""
00086               return folders + files

Here is the call graph for this function:

def zope.FCKeditorConnectorZope.getZopeFiles (   self,
  resourceType,
  currentFolder 
)

Definition at line 89 of file zope.py.

00089 
00090        def getZopeFiles(self, resourceType, currentFolder):
00091               # Open the files node
00092               s = ""
00093               s += """<Files>"""
00094               zopeFolder = self.findZopeFolder(resourceType, currentFolder)
00095               for (name, o) in zopeFolder.objectItems(["File","Image"]):
00096                      s += """<File name="%s" size="%s" />""" % (
00097                                    convertToXmlAttribute(name),
00098                                    ((o.get_size() / 1024) + 1)
00099                                    )
00100               # Close the files node
00101               s += """</Files>"""
00102               return s

Here is the call graph for this function:

Here is the caller graph for this function:

def zope.FCKeditorConnectorZope.getZopeFoldersAndFiles (   self,
  resourceType,
  currentFolder 
)

Definition at line 83 of file zope.py.

00083 
00084        def getZopeFoldersAndFiles(self, resourceType, currentFolder):
00085               folders = self.getZopeFolders(resourceType, currentFolder)
00086               files = self.getZopeFiles(resourceType, currentFolder)
00087               s = folders + files
00088               return s

Here is the call graph for this function:

Definition at line 52 of file zope.py.

00052 
00053        def getZopeRootContext(self):
00054               if self.zopeRootContext is None:
00055                      self.zopeRootContext = self.context.getPhysicalRoot()
00056               return self.zopeRootContext

Here is the caller graph for this function:

Definition at line 57 of file zope.py.

00057 
00058        def getZopeUploadContext(self):
00059               if self.zopeUploadContext is None:
00060                      folderNames = self.userFilesFolder.split("/")
00061                      c = self.getZopeRootContext()
00062                      for folderName in folderNames:
00063                             if (folderName <> ""):
00064                                    c = c[folderName]
00065                      self.zopeUploadContext = c
00066               return self.zopeUploadContext

Here is the call graph for this function:

Here is the caller graph for this function:

def fckoutput.BaseXmlMixin.sendError (   self,
  number,
  text 
) [inherited]

Definition at line 89 of file fckoutput.py.

00089 
00090        def sendError(self, number, text):
00091               "Purpose: in the event of an error, return an xml based error"
00092               self.setHttpHeaders()
00093               return ("""<?xml version="1.0" encoding="utf-8" ?>""" +
00094                             """<Connector>""" +
00095                             self.sendErrorNode (number, text) +
00096                             """</Connector>""" )

Here is the call graph for this function:

Here is the caller graph for this function:

def fckoutput.BaseXmlMixin.sendErrorNode (   self,
  number,
  text 
) [inherited]

Definition at line 97 of file fckoutput.py.

00097 
00098        def sendErrorNode(self, number, text):
00099               if number != 1:
00100                      return """<Error number="%s" />""" % (number)
00101               else:
00102                      return """<Error number="%s" text="%s" />""" % (number, convertToXmlAttribute(text))

Here is the call graph for this function:

Here is the caller graph for this function:

def fckoutput.BaseHtmlMixin.sendUploadResults (   self,
  errorNo = 0,
  fileUrl = '',
  fileName = '',
  customMsg = '' 
) [inherited]

Definition at line 104 of file fckoutput.py.

00104 
00105        def sendUploadResults( self, errorNo = 0, fileUrl = '', fileName = '', customMsg = '' ):
00106               self.setHttpHeaders("text/html")
00107               "This is the function that sends the results of the uploading process"
00108 
00109               "Minified version of the document.domain automatic fix script (#1919)."
00110               "The original script can be found at _dev/domain_fix_template.js"
00111               return """<script type="text/javascript">
00112                      (function(){var d=document.domain;while (true){try{var A=window.parent.document.domain;break;}catch(e) {};d=d.replace(/.*?(?:\.|$)/,'');if (d.length==0) break;try{document.domain=d;}catch (e){break;}}})();
00113 
00114                      window.parent.OnUploadCompleted(%(errorNumber)s,"%(fileUrl)s","%(fileName)s","%(customMsg)s");
00115                      </script>""" % {
00116                      'errorNumber': errorNo,
00117                      'fileUrl': fileUrl.replace ('"', '\\"'),
00118                      'fileName': fileName.replace ( '"', '\\"' ) ,
00119                      'customMsg': customMsg.replace ( '"', '\\"' ),
00120                      }

Here is the call graph for this function:

Here is the caller graph for this function:

def zope.FCKeditorConnectorZope.setHeader (   self,
  key,
  value 
)

Reimplemented from fckconnector.FCKeditorConnectorBase.

Definition at line 67 of file zope.py.

00067 
00068        def setHeader(self, key, value):
00069               self.context.REQUEST.RESPONSE.setHeader(key, value)

Here is the caller graph for this function:

def fckoutput.BaseHttpMixin.setHttpHeaders (   self,
  content_type = 'text/xml' 
) [inherited]

Definition at line 50 of file fckoutput.py.

00050 
00051        def setHttpHeaders(self, content_type='text/xml'):
00052               "Purpose: to prepare the headers for the xml to return"
00053               # Prevent the browser from caching the result.
00054               # Date in the past
00055               self.setHeader('Expires','Mon, 26 Jul 1997 05:00:00 GMT')
00056               # always modified
00057               self.setHeader('Last-Modified',strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime()))
00058               # HTTP/1.1
00059               self.setHeader('Cache-Control','no-store, no-cache, must-revalidate')
00060               self.setHeader('Cache-Control','post-check=0, pre-check=0')
00061               # HTTP/1.0
00062               self.setHeader('Pragma','no-cache')
00063 
00064               # Set the response format.
00065               self.setHeader( 'Content-Type', content_type + '; charset=utf-8' )
00066               return

Here is the call graph for this function:

Here is the caller graph for this function:

def fckcommands.UploadFileCommandMixin.uploadFile (   self,
  resourceType,
  currentFolder 
) [inherited]
Purpose: command to upload files to server (same as FileUpload)

Definition at line 131 of file fckcommands.py.

00131 
00132        def uploadFile(self, resourceType, currentFolder):
00133               """
00134               Purpose: command to upload files to server (same as FileUpload)
00135               """
00136               errorNo = 0
00137               if self.request.has_key("NewFile"):
00138                      # newFile has all the contents we need
00139                      newFile = self.request.get("NewFile", "")
00140                      # Get the file name
00141                      newFileName = newFile.filename
00142                      newFileName = sanitizeFileName( newFileName )
00143                      newFileNameOnly = removeExtension(newFileName)
00144                      newFileExtension = getExtension(newFileName).lower()
00145                      allowedExtensions = Config.AllowedExtensions[resourceType]
00146                      deniedExtensions = Config.DeniedExtensions[resourceType]
00147 
00148                      if (allowedExtensions):
00149                             # Check for allowed
00150                             isAllowed = False
00151                             if (newFileExtension in allowedExtensions):
00152                                    isAllowed = True
00153                      elif (deniedExtensions):
00154                             # Check for denied
00155                             isAllowed = True
00156                             if (newFileExtension in deniedExtensions):
00157                                    isAllowed = False
00158                      else:
00159                             # No extension limitations
00160                             isAllowed = True
00161 
00162                      if (isAllowed):
00163                             # Upload to operating system
00164                             # Map the virtual path to the local server path
00165                             currentFolderPath = mapServerFolder(self.userFilesFolder, currentFolder)
00166                             i = 0
00167                             while (True):
00168                                    newFilePath = os.path.join (currentFolderPath,newFileName)
00169                                    if os.path.exists(newFilePath):
00170                                           i += 1
00171                                           newFileName = "%s(%d).%s" % (
00172                                                         newFileNameOnly, i, newFileExtension
00173                                                         )
00174                                           errorNo= 201 # file renamed
00175                                    else:
00176                                           # Read file contents and write to the desired path (similar to php's move_uploaded_file)
00177                                           fout = file(newFilePath, 'wb')
00178                                           while (True):
00179                                                  chunk = newFile.file.read(100000)
00180                                                  if not chunk: break
00181                                                  fout.write (chunk)
00182                                           fout.close()
00183 
00184                                           if os.path.exists ( newFilePath ):
00185                                                  doChmod = False
00186                                                  try:
00187                                                         doChmod = Config.ChmodOnUpload
00188                                                         permissions = Config.ChmodOnUpload
00189                                                  except AttributeError: #ChmodOnUpload undefined
00190                                                         doChmod = True
00191                                                         permissions = 0755
00192                                                  if ( doChmod ):
00193                                                         oldumask = os.umask(0)
00194                                                         os.chmod( newFilePath, permissions )
00195                                                         os.umask( oldumask )
00196 
00197                                           newFileUrl = combinePaths(self.webUserFilesFolder, currentFolder) + newFileName
00198 
00199                                           return self.sendUploadResults( errorNo , newFileUrl, newFileName )
00200                      else:
00201                             return self.sendUploadResults( errorNo = 202, customMsg = "" )
00202               else:
00203                      return self.sendUploadResults( errorNo = 202, customMsg = "No File" )

Here is the call graph for this function:

def zope.FCKeditorConnectorZope.uploadFile (   self,
  resourceType,
  currentFolder,
  count = None 
)

Definition at line 132 of file zope.py.

00132 
00133        def uploadFile(self, resourceType, currentFolder, count=None):
00134               zopeFolder = self.findZopeFolder(resourceType, currentFolder)
00135               file = self.request.get("NewFile", None)
00136               fileName = self.getFileName(file.filename)
00137               fileNameOnly = self.removeExtension(fileName)
00138               fileExtension = self.getExtension(fileName).lower()
00139               if (count):
00140                      nid = "%s.%s.%s" % (fileNameOnly, count, fileExtension)
00141               else:
00142                      nid = fileName
00143               title = nid
00144               try:
00145                      zopeFolder.manage_addProduct['OFSP'].manage_addFile(
00146                                    id=nid,
00147                                    title=title,
00148                                    file=file.read()
00149                                    )
00150               except:
00151                      if (count):
00152                             count += 1
00153                      else:
00154                             count = 1
00155                      return self.zopeFileUpload(resourceType, currentFolder, count)
00156               return self.sendUploadResults( 0 )

Here is the call graph for this function:


Member Data Documentation

Definition at line 41 of file zope.py.

Definition at line 49 of file zope.py.

Definition at line 43 of file fckconnector.py.

Definition at line 41 of file fckconnector.py.

Reimplemented from fckconnector.FCKeditorConnectorBase.

Definition at line 50 of file zope.py.

Definition at line 73 of file connector.py.

Definition at line 74 of file connector.py.

Definition at line 54 of file zope.py.

Definition at line 64 of file zope.py.


The documentation for this class was generated from the following file: