예제 #1
0
  def pt_upload(self, REQUEST, file=''):
    """Replace the document with the text in file."""
    if SUPPORTS_WEBDAV_LOCKS and self.wl_isLocked():
      raise ResourceLockedError, "File is locked via WebDAV"

    if type(file) is not StringType:
      if not file: raise ValueError, 'File not specified'
      file = file.read()

    if file.startswith("PK") : # FIXME: this condition is probably not enough
      # this is a OOo zip file, extract the content
      builder = OOoBuilder(file)
      attached_files_list = [n for n in builder.getNameList()
        if n.startswith(self._OLE_directory_prefix)
        or n.startswith('Pictures')
        or n == 'META-INF/manifest.xml' ]
      # destroy a possibly pre-existing OLE document set
      if self.OLE_documents_zipstring:
        self.OLE_documents_zipstring = None
      # create a zip archive and store it
      if attached_files_list:
        memory_file = StringIO()
        try:
          zf = ZipFile(memory_file, mode='w', compression=ZIP_DEFLATED)
        except RuntimeError:
          zf = ZipFile(memory_file, mode='w')
        for attached_file in attached_files_list:
            zf.writestr(attached_file, builder.extract(attached_file) )
        zf.close()
        memory_file.seek(0)
        self.OLE_documents_zipstring = memory_file.read()
      self.content_type = builder.getMimeType()
      file = builder.prepareContentXml(self.ooo_xml_file_id)
    return ZopePageTemplate.pt_upload(self, REQUEST, file)
예제 #2
0
    def pt_upload(self, REQUEST, file=''):
        """Replace the document with the text in file."""
        if SUPPORTS_WEBDAV_LOCKS and self.wl_isLocked():
            raise ResourceLockedError("File is locked via WebDAV")

        if not isinstance(file, basestring):
            if not file: raise ValueError('File not specified')
            file = file.read()

        if file.startswith(
                "PK"):  # FIXME: this condition is probably not enough
            # this is a OOo zip file, extract the content
            builder = OOoBuilder(file)
            attached_files_list = [
                n for n in builder.getNameList()
                if n.startswith(self._OLE_directory_prefix)
                or n.startswith('Pictures') or n == 'META-INF/manifest.xml'
            ]
            # destroy a possibly pre-existing OLE document set
            if self.OLE_documents_zipstring:
                self.OLE_documents_zipstring = None
            # create a zip archive and store it
            if attached_files_list:
                memory_file = StringIO()
                try:
                    zf = ZipFile(memory_file,
                                 mode='w',
                                 compression=ZIP_DEFLATED)
                except RuntimeError:
                    zf = ZipFile(memory_file, mode='w')
                for attached_file in attached_files_list:
                    zf.writestr(attached_file, builder.extract(attached_file))
                zf.close()
                memory_file.seek(0)
                self.OLE_documents_zipstring = memory_file.read()
            self.content_type = builder.getMimeType()
            file = builder.prepareContentXml(self.ooo_xml_file_id)
        return ZopePageTemplate.pt_upload(self, REQUEST, file)