Back to index

plone3  3.1.7
exportimport.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """MailHost export / import support.
00014 
00015 $Id: exportimport.py 71199 2006-11-20 11:03:29Z yuppie $
00016 """
00017 
00018 from zope.component import adapts
00019 
00020 from Products.GenericSetup.interfaces import ISetupEnviron
00021 from Products.GenericSetup.utils import XMLAdapterBase
00022 
00023 from Products.MailHost.interfaces import IMailHost
00024 
00025 
00026 class MailHostXMLAdapter(XMLAdapterBase):
00027 
00028     """XML im- and exporter for MailHost.
00029     """
00030 
00031     adapts(IMailHost, ISetupEnviron)
00032 
00033     _LOGGER_ID = 'mailhost'
00034 
00035     name = 'mailhost'
00036 
00037     def _exportNode(self):
00038         """Export the object as a DOM node.
00039         """
00040         node = self._getObjectNode('object')
00041         node.setAttribute('smtp_host', str(self.context.smtp_host))
00042         node.setAttribute('smtp_port', str(self.context.smtp_port))
00043         node.setAttribute('smtp_uid', self.context.smtp_uid)
00044         node.setAttribute('smtp_pwd', self.context.smtp_pwd)
00045 
00046         self._logger.info('Mailhost exported.')
00047         return node
00048 
00049     def _importNode(self, node):
00050         """Import the object from the DOM node.
00051         """
00052         self.context.smtp_host = str(node.getAttribute('smtp_host'))
00053         self.context.smtp_port = int(node.getAttribute('smtp_port'))
00054         self.context.smtp_uid = node.getAttribute('smtp_uid').encode('utf-8')
00055         self.context.smtp_pwd = node.getAttribute('smtp_pwd').encode('utf-8')
00056 
00057         self._logger.info('Mailhost imported.')