Back to index

plone3  3.1.7
ReferenceFactoriesTool.py
Go to the documentation of this file.
00001 #########################################################################
00002 # Copyright (c) 2005 Gregoire Weber. 
00003 # All Rights Reserved.
00004 # 
00005 # This file is part of CMFEditions.
00006 # 
00007 # CMFEditions is free software; you can redistribute it and/or modify
00008 # it under the terms of the GNU General Public License as published by
00009 # the Free Software Foundation; either version 2 of the License, or
00010 # (at your option) any later version.
00011 # 
00012 # CMFEditions is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 # GNU General Public License for more details.
00016 # 
00017 # You should have received a copy of the GNU General Public License
00018 # along with CMFEditions; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00020 #########################################################################
00021 """Manages Factories for diffrenet kinds of references.
00022 
00023 $Id: $
00024 """
00025 
00026 from Globals import InitializeClass
00027 from AccessControl import ClassSecurityInfo
00028 
00029 from Acquisition import aq_parent, aq_inner
00030 from OFS.OrderedFolder import OrderedFolder
00031 
00032 from Products.CMFCore.utils import UniqueObject, getToolByName
00033 
00034 from Products.CMFEditions.utilities import generateId
00035 
00036 from Products.CMFEditions.interfaces.IReferenceFactories \
00037     import IReferenceFactories
00038 
00039 class ReferenceFactoriesTool(UniqueObject, OrderedFolder):
00040     __doc__ = __doc__ # copy from module
00041 
00042     __implements__ = (
00043         IReferenceFactories,
00044         OrderedFolder.__implements__,   # hide underspecified interfaces :-(
00045     )
00046     
00047     id = 'portal_referencefactories'
00048     alternative_id = 'portal_referencefactoryregistry'
00049 
00050     meta_type = 'Reference Factory Registry'
00051     
00052     security = ClassSecurityInfo()
00053     
00054     # be aware that the tool implements also the OrderedObjectManager API
00055     
00056     # -------------------------------------------------------------------
00057     # methods implementing IFactories
00058     # -------------------------------------------------------------------
00059     
00060     security.declarePrivate('invokeFactory')
00061     def invokeFactory(self, repo_clone, source, selector=None):
00062         """See IReferenceFactories
00063         """
00064         # Just assuming ObjectManager behaviour for now
00065         portal_hidhandler = getToolByName(self, 'portal_historyidhandler')
00066         portal_archivist = getToolByName(self, 'portal_archivist')
00067         try:
00068             portal_type = repo_clone.getPortalTypeName()
00069         except AttributeError:
00070             # We attach the clone directly if the object has no portal type,
00071             # perhaps we should clone it.
00072             return repo_clone
00073         id = repo_clone.getId()
00074         if id in source.objectIds():
00075             id = generateId(source, prefix=id)
00076         # XXX: This makes a lot of changes outside the object scope we :(
00077         id = source.invokeFactory(portal_type, id)
00078         obj = getattr(source, id)
00079         try:
00080             history_id = portal_hidhandler.getUid(repo_clone)
00081             portal_hidhandler.setUid(obj, history_id)
00082         except portal_hidhandler.UniqueIdError:
00083             portal_hidhandler.register(obj)
00084         
00085         return obj
00086 
00087     security.declarePrivate('hasBeenMoved')
00088     def hasBeenMoved(self, obj, source):
00089         """See IReferenceFactories
00090         """
00091         # Check that the path of the object's parent (by path) is the same as the source
00092         return aq_parent(aq_inner(obj)).getPhysicalPath() != source.getPhysicalPath()
00093 
00094 InitializeClass(ReferenceFactoriesTool)