Back to index

plone3  3.1.7
UniqueIdHandlerTool.py
Go to the documentation of this file.
00001 #########################################################################
00002 # Copyright (c) 2004, 2005 Alberto Berti, 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 """Unique Id Handler Tool
00022 
00023 Provides support for accessing unique ids on content object.
00024 
00025 $Id: UniqueIdHandlerTool.py,v 1.2 2005/01/06 14:25:44 gregweb Exp $
00026 """
00027 
00028 from zope.interface import implements
00029 
00030 from Globals import InitializeClass
00031 from AccessControl import ClassSecurityInfo
00032 
00033 from OFS.SimpleItem import SimpleItem
00034 
00035 from Products.CMFCore.utils import getToolByName, UniqueObject
00036 from Products.CMFCore.permissions import ManagePortal
00037 
00038 from Products.CMFUid.interfaces import IUniqueIdHandler
00039 from Products.CMFUid.interfaces import IUniqueIdBrainQuery
00040 from Products.CMFUid.interfaces import UniqueIdError
00041 
00042 UID_ATTRIBUTE_NAME = 'cmf_uid'
00043 
00044 class UniqueIdHandlerTool(UniqueObject, SimpleItem):
00045     __doc__ = __doc__ # copy from module
00046 
00047     implements(IUniqueIdHandler, IUniqueIdBrainQuery)
00048     __implements__ = (SimpleItem.__implements__,)
00049 
00050     id = 'portal_historyidhandler'
00051     alternative_id = "portal_editions_uidhandler"
00052     meta_type = 'Unique Id Handler Tool'
00053     
00054     # make the uid attribute name available for the unit tests
00055     # not meant to be altered as long you don't know what you do!!!
00056     UID_ATTRIBUTE_NAME = UID_ATTRIBUTE_NAME
00057     
00058     # make the exception class available through the tool
00059     UniqueIdError = UniqueIdError
00060     
00061     security = ClassSecurityInfo()
00062     
00063     # ----------------------------------------------------------------
00064     # The following methods have to be made location_id aware to allow
00065     # applications beeing version_id aware also.
00066     # ----------------------------------------------------------------
00067     
00068     security.declarePublic('register')
00069     def register(self, obj):
00070         """See IUniqueIdSet.
00071         """
00072         histid_handler = getToolByName(self, 'portal_historyidhandler', None)
00073         if histid_handler is not None:
00074             return histid_handler.register(obj)
00075     
00076     security.declareProtected(ManagePortal, 'unregister')
00077     def unregister(self, obj):
00078         """See IUniqueIdSet.
00079         """
00080         histid_handler = getToolByName(self, 'portal_historyidhandler', None)
00081         if histid_handler is not None:
00082             histid_handler.unregister(obj)
00083     
00084     security.declarePublic('queryUid')
00085     def queryUid(self, obj, default=None):
00086         """See IUniqueIdQuery.
00087         """
00088         histid_handler = getToolByName(self, 'portal_historyidhandler', None)
00089         if histid_handler is not None:
00090             return histid_handler.queryUid(obj, default)
00091     
00092     security.declarePublic('getUid')
00093     def getUid(self, obj):
00094         """See IUniqueIdQuery.
00095         """
00096         histid_handler = getToolByName(self, 'portal_historyidhandler', None)
00097         if histid_handler is not None:
00098             return histid_handler.getUid(obj)
00099     
00100     security.declarePrivate('setUid')
00101     def setUid(self, obj, uid, check_uniqueness=True):
00102         """See IUniqueIdSet.
00103         """
00104         histid_handler = getToolByName(self, 'portal_historyidhandler', None)
00105         if histid_handler is not None:
00106             return histid_handler.setUid(obj, uid, check_uniqueness)
00107     
00108     security.declarePublic('queryBrain')
00109     def queryBrain(self, uid, default=None):
00110         """See IUniqueIdBrainQuery.
00111         """
00112         histid_handler = getToolByName(self, 'portal_historyidhandler', None)
00113         if histid_handler is not None:
00114             return histid_handler.queryBrain(uid, default)
00115     
00116     security.declarePublic('getBrain')
00117     def getBrain(self, uid):
00118         """See IUniqueIdBrainQuery.
00119         """
00120         histid_handler = getToolByName(self, 'portal_historyidhandler', None)
00121         if histid_handler is not None:
00122             return histid_handler.getBrain(uid)
00123     
00124     security.declarePublic('getObject')
00125     def getObject(self, uid):
00126         """See IUniqueIdQuery.
00127         """
00128         histid_handler = getToolByName(self, 'portal_historyidhandler', None)
00129         if histid_handler is not None:
00130             return histid_handler.getObject(uid)
00131     
00132     security.declarePublic('queryObject')
00133     def queryObject(self, uid, default=None):
00134         """See IUniqueIdQuery.
00135         """
00136         histid_handler = getToolByName(self, 'portal_historyidhandler', None)
00137         if histid_handler is not None:
00138             return histid_handler.queryObject(uid, default)
00139     
00140 InitializeClass(UniqueIdHandlerTool)