Back to index

plone3  3.1.7
Static Public Attributes | Private Member Functions | Static Private Attributes
plone.app.portlets.exportimport.portlets.PortletsXMLAdapter Class Reference
Inheritance diagram for plone.app.portlets.exportimport.portlets.PortletsXMLAdapter:
Inheritance graph
[legend]
Collaboration diagram for plone.app.portlets.exportimport.portlets.PortletsXMLAdapter:
Collaboration graph
[legend]

List of all members.

Static Public Attributes

string name = 'portlets'

Private Member Functions

def _exportNode
def _importNode
def _initProvider
def _purgePortlets
def _initPortlets
def _initPortletManagerNode
def _initPortletNode
def _initAssignmentNode
def _initBlacklistNode
def _extractPortlets
def _extractPortletManagerNode
def _extractPortletNode
def _checkBasicPortletNodeErrors
def _removePortlet
def _modifyForList
def _BBB_for

Static Private Attributes

string _LOGGER_ID = 'portlets'

Detailed Description

In- and exporter for a local portlet configuration

Definition at line 181 of file portlets.py.


Member Function Documentation

Definition at line 681 of file portlets.py.

00681 
00682     def _BBB_for(self, for_):
00683         if for_ is None:
00684             return [Interface]
00685         if type(for_) not in (tuple, list):
00686             return [for_]
00687         return for_

Here is the caller graph for this function:

def plone.app.portlets.exportimport.portlets.PortletsXMLAdapter._checkBasicPortletNodeErrors (   self,
  node,
  registeredPortletTypes 
) [private]

Definition at line 607 of file portlets.py.

00607 
00608     def _checkBasicPortletNodeErrors(self, node, registeredPortletTypes):
00609         addview = str(node.getAttribute('addview'))
00610         extend = node.hasAttribute('extend')
00611         purge = node.hasAttribute('purge')
00612         exists = addview in registeredPortletTypes
00613         
00614         if extend and purge:
00615             self._logger.warning('Cannot extend and purge the same ' \
00616               'portlet type %s!' % addview)
00617             return True
00618         if extend and not exists:
00619             self._logger.warning('Cannot extend portlet type ' \
00620               '%s because it is not registered.' % addview)
00621             return True
00622         if exists and not purge and not extend:
00623             self._logger.warning('Cannot register portlet type ' \
00624               '%s because it is already registered.' % addview)
00625             return True
00626         
00627         return False

Here is the caller graph for this function:

Export portlet managers and portlet types

Definition at line 194 of file portlets.py.

00194 
00195     def _exportNode(self):
00196         """Export portlet managers and portlet types
00197         """
00198         node = self._doc.createElement('portlets')
00199         node.appendChild(self._extractPortlets())
00200         self._logger.info('Portlets exported')
00201         return node

Here is the call graph for this function:

Here is the caller graph for this function:

def plone.app.portlets.exportimport.portlets.PortletsXMLAdapter._extractPortletManagerNode (   self,
  portletManagerRegistration 
) [private]

Definition at line 573 of file portlets.py.

00573 
00574     def _extractPortletManagerNode(self, portletManagerRegistration):
00575         r = portletManagerRegistration
00576         child = self._doc.createElement('portletmanager')
00577         if r.component.__class__ is not PortletManager:
00578             child.setAttribute('class', _getDottedName(r.component.__class__))
00579         child.setAttribute('name', r.name)
00580         
00581         specificInterface = providedBy(r.component).flattened().next()
00582         if specificInterface != IPortletManager:
00583             child.setAttribute('type', _getDottedName(specificInterface))
00584         
00585         return child
    

Here is the call graph for this function:

Here is the caller graph for this function:

def plone.app.portlets.exportimport.portlets.PortletsXMLAdapter._extractPortletNode (   self,
  name,
  portletType 
) [private]

Definition at line 586 of file portlets.py.

00586 
00587     def _extractPortletNode(self, name, portletType):
00588         child = self._doc.createElement('portlet')
00589         child.setAttribute('addview', portletType.addview)
00590         child.setAttribute('title', portletType.title)
00591         child.setAttribute('description', portletType.description)
00592         
00593         for_ = portletType.for_
00594         #BBB
00595         for_ = self._BBB_for(for_)
00596         
00597         if for_ and for_ != [Interface]:
00598             for i in for_:
00599                 subNode = self._doc.createElement('for')
00600                 subNode.setAttribute('interface', _getDottedName(i))
00601                 child.appendChild(subNode)
00602         return child
        

Here is the call graph for this function:

Here is the caller graph for this function:

Write portlet managers and types to XML

Definition at line 491 of file portlets.py.

00491 
00492     def _extractPortlets(self):
00493         """Write portlet managers and types to XML
00494         """
00495         fragment = self._doc.createDocumentFragment()
00496         site = self.environ.getSite()
00497         
00498         registeredPortletTypes = [r.name for r in self.context.registeredUtilities()
00499                                             if r.provided == IPortletType]
00500         portletManagerRegistrations = [r for r in self.context.registeredUtilities()
00501                                             if r.provided.isOrExtends(IPortletManager)]
00502         
00503         portletSchemata = dict([(iface, name,) for name, iface in getUtilitiesFor(IPortletTypeInterface)])
00504         
00505         # Export portlet manager registrations
00506         
00507         for r in portletManagerRegistrations:
00508             fragment.appendChild(self._extractPortletManagerNode(r))
00509 
00510         # Export portlet type registrations
00511             
00512         for name, portletType in getUtilitiesFor(IPortletType):
00513             if name in registeredPortletTypes:
00514                 fragment.appendChild(self._extractPortletNode(name, portletType))
00515 
00516         def extractMapping(manager_name, category, key, mapping):
00517             for name, assignment in mapping.items():                        
00518                 type_ = None
00519                 for schema in providedBy(assignment).flattened():
00520                     type_ = portletSchemata.get(schema, None)
00521                     if type_ is not None:
00522                         break
00523                 
00524                 if type_ is not None:
00525                     child = self._doc.createElement('assignment')
00526                     child.setAttribute('manager', manager_name)
00527                     child.setAttribute('category', category)
00528                     child.setAttribute('key', key)
00529                     child.setAttribute('type', type_)
00530                     child.setAttribute('name', name)
00531                 
00532                     assignment = assignment.__of__(mapping)
00533                     handler = IPortletAssignmentExportImportHandler(assignment)
00534                     handler.export_assignment(schema, self._doc, child)
00535                     fragment.appendChild(child)
00536 
00537         # Export assignments in the global categories
00538         for category in (USER_CATEGORY, GROUP_CATEGORY, CONTENT_TYPE_CATEGORY,):
00539             for manager_name, manager in getUtilitiesFor(IPortletManager):
00540                 for key, mapping in manager.get(category, {}).items():
00541                     mapping = mapping.__of__(site)
00542                     extractMapping(manager_name, category, key, mapping)
00543                     
00544 
00545         # Export assignments at the root of the portal (only)
00546         for manager_name, manager in getUtilitiesFor(IPortletManager):
00547              mapping = queryMultiAdapter((site, manager), IPortletAssignmentMapping)
00548              mapping = mapping.__of__(site)
00549              extractMapping(manager_name, CONTEXT_CATEGORY, u"/", mapping)
00550 
00551         # Export blacklistings in the portal root        
00552         for manager_name, manager in getUtilitiesFor(IPortletManager):
00553             assignable = queryMultiAdapter((site, manager), ILocalPortletAssignmentManager)       
00554             if assignable is None:
00555                 continue
00556             for category in (USER_CATEGORY, GROUP_CATEGORY, CONTENT_TYPE_CATEGORY, CONTEXT_CATEGORY,):
00557                 child = self._doc.createElement('blacklist')
00558                 child.setAttribute('manager', manager_name)
00559                 child.setAttribute('category', category)
00560                 child.setAttribute('location', u"/")
00561             
00562                 status = assignable.getBlacklistStatus(category)
00563                 if status == True:
00564                     child.setAttribute('status', u'block')
00565                 elif status == False:
00566                     child.setAttribute('status', u'show')
00567                 else:
00568                     child.setAttribute('status', u'acquire')
00569                     
00570                 fragment.appendChild(child)
00571 
00572         return fragment
        

Here is the call graph for this function:

Here is the caller graph for this function:

Import portlet managers, portlet types and portlet assignments 

Definition at line 202 of file portlets.py.

00202 
00203     def _importNode(self, node):
00204         """Import portlet managers, portlet types and portlet assignments 
00205         """
00206         self._initProvider(node)
00207         self._logger.info('Portlets imported')

Here is the call graph for this function:

Here is the caller graph for this function:

Create an assignment from a node

Definition at line 385 of file portlets.py.

00385 
00386     def _initAssignmentNode(self, node):
00387         """Create an assignment from a node
00388         """
00389         site = self.environ.getSite()
00390         
00391         # 1. Determine the assignment mapping and the name
00392         manager = node.getAttribute('manager')
00393         category = node.getAttribute('category')
00394         key = node.getAttribute('key')
00395         #convert unicode to str as unicode paths are not allowed in restrictedTraverse called in assignment_mapping_from_key 
00396         key = key.encode()
00397         
00398         purge = False
00399         if node.hasAttribute('purge'):
00400             purge = self._convertToBoolean(node.getAttribute('purge'))
00401 
00402         mapping = assignment_mapping_from_key(site, manager, category, key, create=True)
00403         
00404         # 2. Either find or create the assignment
00405         
00406         assignment = None
00407         name = node.getAttribute('name')
00408         if name:
00409             assignment = mapping.get(name, None)
00410 
00411         if node.hasAttribute('remove'):
00412             if assignment is not None:
00413                 del mapping[name]
00414             return
00415 
00416         if purge:
00417             for portlet in mapping.keys():
00418                 del mapping[portlet]
00419             return
00420 
00421         type_ = node.getAttribute('type')
00422 
00423         if assignment is None:
00424             portlet_factory = getUtility(IFactory, name=type_)
00425             assignment = portlet_factory()
00426             
00427             if not name:
00428                 chooser = INameChooser(mapping)
00429                 name = chooser.chooseName(None, assignment)
00430             
00431             mapping[name] = assignment
00432 
00433         # aq-wrap it so that complex fields will work
00434         assignment = assignment.__of__(site)
00435 
00436         # 3. Use an adapter to update the portlet settings
00437         
00438         portlet_interface = getUtility(IPortletTypeInterface, name=type_)
00439         assignment_handler = IPortletAssignmentExportImportHandler(assignment)
00440         assignment_handler.import_assignment(portlet_interface, node)
00441 
00442         # 4. Handle ordering
00443         
00444         insert_before = node.getAttribute('insert-before')
00445         if insert_before:
00446             position = None
00447             keys = list(mapping.keys())
00448             
00449             if insert_before == "*":
00450                 position = 0
00451             elif insert_before in keys:
00452                 position = keys.index(insert_before)
00453             
00454             if position is not None:
00455                 keys.remove(name)
00456                 keys.insert(position, name)
00457                 mapping.updateOrder(keys)
        

Here is the call graph for this function:

Here is the caller graph for this function:

Create a blacklisting from a node

Definition at line 458 of file portlets.py.

00458 
00459     def _initBlacklistNode(self, node):
00460         """Create a blacklisting from a node
00461         """
00462         site = self.environ.getSite()
00463         
00464         manager = node.getAttribute('manager')
00465         category = node.getAttribute('category')
00466         location = str(node.getAttribute('location'))
00467         status = node.getAttribute('status')
00468         
00469         manager = getUtility(IPortletManager, name=manager)
00470         
00471         if location.startswith('/'):
00472             location = location[1:]
00473         
00474         item = site.unrestrictedTraverse(location, None)
00475         if item is None:
00476             return
00477             
00478         assignable = queryMultiAdapter((item, manager), ILocalPortletAssignmentManager)
00479         
00480         if status.lower() == 'block':
00481             assignable.setBlacklistStatus(category, True)
00482         elif status.lower() == 'show':
00483             assignable.setBlacklistStatus(category, False)
00484         elif status.lower() == 'acquire':
00485             assignable.setBlacklistStatus(category, None)
00486         

Here is the caller graph for this function:

Create a portlet manager from a node

Definition at line 282 of file portlets.py.

00282 
00283     def _initPortletManagerNode(self, node):
00284         """Create a portlet manager from a node
00285         """
00286         name = str(node.getAttribute('name'))
00287         
00288         if node.hasAttribute('remove'):
00289             if self._convertToBoolean(node.getAttribute('remove')):
00290                 self.context.unregisterUtility(provided=IPortletManager,
00291                                                name=name)
00292                 return
00293 
00294         if node.hasAttribute('purge'):
00295             if self._convertToBoolean(node.getAttribute('purge')):
00296                 manager = getUtility(IPortletManager, name=name)
00297                 # remove global assignments
00298                 for category in manager.keys():
00299                     for portlet in manager[category].keys():
00300                         del manager[category][portlet]
00301                 # remove assignments from root
00302                 site = self.environ.getSite()
00303                 mapping = queryMultiAdapter((site, manager), IPortletAssignmentMapping)
00304                 for portlet in mapping.keys():
00305                     del mapping[portlet]
00306                 return
00307 
00308         registeredPortletManagers = [r.name for r in self.context.registeredUtilities()
00309                                         if r.provided.isOrExtends(IPortletManager)]
00310         if name not in registeredPortletManagers:
00311             managerClass = node.getAttribute('class')
00312             if managerClass:
00313                 manager = _resolveDottedName(managerClass)()
00314             else:
00315                 manager = PortletManager()
00316         
00317             managerType = node.getAttribute('type')
00318             if managerType:
00319                  alsoProvides(manager, _resolveDottedName(managerType))
00320         
00321             manager[USER_CATEGORY] = PortletCategoryMapping()
00322             manager[GROUP_CATEGORY] = PortletCategoryMapping()
00323             manager[CONTENT_TYPE_CATEGORY] = PortletCategoryMapping()
00324         
00325             self.context.registerUtility(component=manager,
00326                                          provided=IPortletManager,
00327                                          name=name)
    

Here is the call graph for this function:

Here is the caller graph for this function:

Create a portlet type from a node

Definition at line 328 of file portlets.py.

00328 
00329     def _initPortletNode(self, node):
00330         """Create a portlet type from a node
00331         """
00332         registeredPortletTypes = [
00333           r.name for r in self.context.registeredUtilities() \
00334           if r.provided == IPortletType
00335           ]
00336         addview = str(node.getAttribute('addview'))
00337         extend = node.hasAttribute('extend')
00338         purge = node.hasAttribute('purge')
00339         
00340         #In certain cases, continue to the next node
00341         if node.hasAttribute('remove'):
00342             self._removePortlet(name=addview)
00343             return
00344         if self._checkBasicPortletNodeErrors(node, registeredPortletTypes):
00345             return
00346 
00347         #Retrieve or create the portlet type and determine the current list
00348         #of associated portlet manager interfaces (for_)
00349         if extend:
00350             #To extend a portlet type that is registered, we modify the title
00351             #and description if provided by the profile.
00352             portlet = queryUtility(IPortletType, name = addview)
00353             if str(node.getAttribute('title')):
00354                  portlet.title = str(node.getAttribute('title'))
00355             if str(node.getAttribute('description')):
00356                  portlet.description = str(node.getAttribute('description'))
00357             for_ = portlet.for_
00358         else:
00359              #Otherwise, create a new portlet type with the correct attributes.
00360              portlet = PortletType()
00361              portlet.title = str(node.getAttribute('title'))
00362              portlet.description = str(node.getAttribute('description'))
00363              portlet.addview = addview
00364              for_ = []
00365 
00366         #BBB - to cover old-style for_ attributes that equal None or a
00367         #single interface
00368         for_ = self._BBB_for(for_)
00369 
00370         #Process the node's child "for" nodes to add or remove portlet
00371         #manager interface names to the for_ list
00372         for_ = self._modifyForList(node, for_)
00373         
00374         #Store the for_ attribute, with [Interface] as the default
00375         if for_ == []:
00376             for_ = [Interface]
00377         portlet.for_ = for_
00378         
00379         if purge:
00380             self._removePortlet(addview)
00381         if not extend:
00382             self.context.registerUtility(component=portlet,
00383                                          provided=IPortletType,
00384                                          name=addview)

Here is the call graph for this function:

Here is the caller graph for this function:

Actually import portlet data

Definition at line 257 of file portlets.py.

00257 
00258     def _initPortlets(self, node):
00259         """Actually import portlet data
00260         """
00261         
00262         site = self.environ.getSite()
00263         
00264         registeredPortletTypes = [r.name for r in self.context.registeredUtilities()
00265                                     if r.provided == IPortletType]
00266                                         
00267         registeredPortletManagers = [r.name for r in self.context.registeredUtilities()
00268                                         if r.provided.isOrExtends(IPortletManager)]
00269         
00270         for child in node.childNodes:
00271             # Portlet managers
00272             if child.nodeName.lower() == 'portletmanager':
00273                 self._initPortletManagerNode(child)
00274             elif child.nodeName.lower() == 'portlet':
00275                 self._initPortletNode(child)
00276             # Portlet assignments                                
00277             elif child.nodeName.lower() == 'assignment':
00278                 self._initAssignmentNode(child)
00279             # Blacklisting (portlet blocking/unblocking)
00280             elif child.nodeName.lower() == 'blacklist':
00281                 self._initBlacklistNode(child)
        

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 208 of file portlets.py.

00208 
00209     def _initProvider(self, node):
00210         purge = self.environ.shouldPurge()
00211         if node.hasAttribute('purge'):
00212             purge = self._convertToBoolean(node.getAttribute('purge'))
00213         if purge:
00214             self._purgePortlets()
00215         self._initPortlets(node)
    

Here is the call graph for this function:

Here is the caller graph for this function:

Examine the "for_" nodes within a "portlet" node to populate,
extend, and/or remove interface names from an existing list for_

Definition at line 637 of file portlets.py.

00637 
00638     def _modifyForList(self, node, for_):
00639         """Examine the "for_" nodes within a "portlet" node to populate,
00640         extend, and/or remove interface names from an existing list for_
00641         """
00642         modified_for = [_getDottedName(i) for i in for_]
00643          
00644         for subNode in node.childNodes:
00645             if subNode.nodeName.lower() == 'for':
00646                 interface_name = str(
00647                   subNode.getAttribute('interface')
00648                   )
00649                 if subNode.hasAttribute('remove'):
00650                     if interface_name in modified_for:
00651                         modified_for.remove(interface_name)
00652                     else:
00653                         addview = str(node.getAttribute('addview'))
00654                         self._logger.warning('Portlet type %s ' % addview + \
00655                           'is already not registered as addable to ' + \
00656                           'portlet managers with interface ' + \
00657                           '%s.' % interface_name)
00658                 elif interface_name not in modified_for:
00659                     modified_for.append(interface_name)
00660                 else:
00661                     addview = str(node.getAttribute('addview'))
00662                     self._logger.warning('Portlet type %s is ' % addview + \
00663                       'already registered as addable to portlet managers ' \
00664                       'with interface %s.' % interface_name)
00665         
00666         #BBB
00667         interface_name = str(node.getAttribute('for'))
00668         if interface_name:
00669             self._logger.warning('Deprecation Warning The "for" ' + \
00670               'attribute of the portlet node in portlets.xml is ' + \
00671               'deprecated and will be removed in Plone 4.0. Use children ' \
00672               'nodes of the form <for interface="foo.BarInterface" /> ' + \
00673               'instead.')
00674             modified_for.append(interface_name)
00675         
00676         modified_for = [_resolveDottedName(name) for name in modified_for \
00677           if _resolveDottedName(name) is not None] 
00678         
00679         return modified_for
    

Here is the call graph for this function:

Here is the caller graph for this function:

Unregister all portlet managers and portlet types, and remove
portlets assigned to the site root

Definition at line 220 of file portlets.py.

00220 
00221     def _purgePortlets(self):
00222         """Unregister all portlet managers and portlet types, and remove
00223         portlets assigned to the site root
00224         """
00225         
00226         # Purge portlet types
00227         
00228         registeredPortletTypes = [r.name for r in self.context.registeredUtilities()
00229                                         if r.provided == IPortletType]
00230                                     
00231         for name, portletType in getUtilitiesFor(IPortletType):
00232             if name in registeredPortletTypes:
00233                 self.context.unregisterUtility(provided=IPortletType, name=name)
00234         
00235         # Purge portlets assigned to the site root
00236         site = self.environ.getSite()
00237         
00238         for name, portletManager in getUtilitiesFor(IPortletManager):
00239             assignable = queryMultiAdapter((site, portletManager), IPortletAssignmentMapping)
00240             if assignable is not None:
00241                 for key in list(assignable.keys()):
00242                     del assignable[key]
00243 
00244         # Purge portlet manager registrations - this will also get rid of
00245         # global portlet registrations, since these utilities disappear
00246         
00247         portletManagerRegistrations = [r for r in self.context.registeredUtilities()
00248                                         if r.provided.isOrExtends(IPortletManager)]
00249         
00250         for registration in portletManagerRegistrations:
00251             self.context.unregisterUtility(provided=registration.provided,
00252                                            name=registration.name)
        

Here is the caller graph for this function:

Definition at line 628 of file portlets.py.

00628 
00629     def _removePortlet(self, name):
00630         if queryUtility(IPortletType, name=name):
00631             self.context.unregisterUtility(provided=IPortletType, name=name)
00632             return True
00633         else:
00634             self._logger.warning('Unable to unregister portlet type ' \
00635               '%s because it is not registered.' % name)
00636             return False

Here is the caller graph for this function:


Member Data Documentation

Definition at line 188 of file portlets.py.

Definition at line 187 of file portlets.py.


The documentation for this class was generated from the following file: