Back to index

plone3  3.1.7
cookieauth.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 """Cookie crumbler xml adapters and setup handlers.
00014 
00015 $Id: cookieauth.py 77004 2007-06-24 08:57:54Z yuppie $
00016 """
00017 
00018 from zope.component import adapts
00019 
00020 from Products.GenericSetup.interfaces import ISetupEnviron
00021 from Products.GenericSetup.utils import exportObjects
00022 from Products.GenericSetup.utils import importObjects
00023 from Products.GenericSetup.utils import PropertyManagerHelpers
00024 from Products.GenericSetup.utils import XMLAdapterBase
00025 
00026 from Products.CMFCore.interfaces import ICookieCrumbler
00027 from Products.CMFCore.utils import getToolByName
00028 
00029 
00030 class CookieCrumblerXMLAdapter(XMLAdapterBase, PropertyManagerHelpers):
00031 
00032     """XML im- and exporter for CookieCrumbler.
00033     """
00034 
00035     adapts(ICookieCrumbler, ISetupEnviron)
00036 
00037     _LOGGER_ID = 'cookies'
00038 
00039     name = 'cookieauth'
00040 
00041     def _exportNode(self):
00042         """Export the object as a DOM node.
00043         """
00044         node = self._getObjectNode('object')
00045         node.appendChild(self._extractProperties())
00046 
00047         self._logger.info('Cookie crumbler exported.')
00048         return node
00049 
00050     def _importNode(self, node):
00051         """Import the object from the DOM node.
00052         """
00053         if self.environ.shouldPurge():
00054             self._purgeProperties()
00055 
00056         self._initProperties(node)
00057 
00058         self._logger.info('Cookie crumbler imported.')
00059 
00060 
00061 def importCookieCrumbler(context):
00062     """Import cookie crumbler settings from an XML file.
00063     """
00064     site = context.getSite()
00065     tool = getToolByName(site, 'cookie_authentication')
00066 
00067     importObjects(tool, '', context)
00068 
00069 def exportCookieCrumbler(context):
00070     """Export cookie crumbler settings as an XML file.
00071     """
00072     site = context.getSite()
00073     tool = getToolByName(site, 'cookie_authentication', None)
00074     if tool is None:
00075         logger = context.getLogger('cookies')
00076         logger.info('Nothing to export.')
00077         return
00078 
00079     exportObjects(tool, '', context)