Back to index

plone3  3.1.7
factorytool.py
Go to the documentation of this file.
00001 from Products.CMFPlone.interfaces import IFactoryTool
00002 from Products.GenericSetup.utils import XMLAdapterBase
00003 from Products.GenericSetup.utils import importObjects
00004 from Products.GenericSetup.utils import exportObjects
00005 from Products.CMFCore.utils import getToolByName
00006 
00007 try:
00008     set()
00009 except NameError:
00010     from sets import Set as set
00011 
00012 
00013 class PortalFactoryXMLAdapter(XMLAdapterBase):
00014     """In- and exporter for FactoryTool.
00015     """
00016 
00017     __used_for__ = IFactoryTool
00018 
00019     _LOGGER_ID = name = 'factorytool'
00020 
00021     def _exportNode(self):
00022         """Export the object as a DOM node.
00023         """
00024         node = self._getObjectNode("object")
00025         node.appendChild(self._extractFactoryToolSettings())
00026 
00027         self._logger.info("FactoryTool settings exported.")
00028         return node
00029 
00030     def _importNode(self, node):
00031         if self.environ.shouldPurge():
00032             self._purgeFactoryToolSettings()
00033 
00034         self._initFactoryToolSettings(node)
00035         self._logger.info("FactoryTool settings imported.")
00036 
00037     def _purgeFactoryToolSettings(self):
00038         self.context.manage_setPortalFactoryTypes(listOfTypeIds=[])
00039 
00040 
00041     def _initFactoryToolSettings(self, node):
00042         for child in node.childNodes:
00043             if child.nodeName=="factorytypes":
00044                 types=set(self.context.getFactoryTypes())
00045                 for type in child.getElementsByTagName("type"):
00046                     types.add(type.getAttribute("portal_type"))
00047                 self.context.manage_setPortalFactoryTypes(
00048                                     listOfTypeIds=list(types))
00049 
00050 
00051     def _extractFactoryToolSettings(self):
00052         node=self._doc.createElement("factorytypes")
00053         for type in self.context.getFactoryTypes():
00054             child=self._doc.createElement("type")
00055             child.setAttribute("portal_type", type)
00056             node.appendChild(child)
00057 
00058         return node
00059 
00060 
00061 def importFactoryTool(context):
00062     """Import Factory Tool configuration.
00063     """
00064     site = context.getSite()
00065     tool = getToolByName(site, 'portal_factory')
00066 
00067     importObjects(tool, '', context)
00068 
00069 
00070 def exportFactoryTool(context):
00071     """Export Factory Tool configuration.
00072     """
00073     site = context.getSite()
00074     tool = getToolByName(site, 'portal_factory', None)
00075     if tool is None:
00076         logger = context.getLogger("factorytool")
00077         logger.info("Nothing to export.")
00078         return
00079 
00080     exportObjects(tool, '', context)
00081