Back to index

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

List of all members.

Static Public Attributes

string name = 'contentrules'

Private Member Functions

def _exportNode
def _importNode
def _purgeRules
def _initRules
def _extractRules

Static Private Attributes

string _LOGGER_ID = 'contentrules'

Detailed Description

In- and exporter for a local portlet configuration

Definition at line 169 of file rules.py.


Member Function Documentation

Export rules

Definition at line 178 of file rules.py.

00178 
00179     def _exportNode(self):
00180         """Export rules
00181         """
00182         node = self._doc.createElement('contentrules')
00183         child = self._extractRules()
00184         if child is not None:
00185             node.appendChild(child)
00186         self._logger.info('Content rules exported')
00187         return node

Here is the call graph for this function:

Here is the caller graph for this function:

Extract rules to a document fragment

Definition at line 328 of file rules.py.

00328 
00329     def _extractRules(self):
00330         """Extract rules to a document fragment
00331         """
00332         
00333         site = self.environ.getSite()
00334         storage = queryUtility(IRuleStorage)
00335         if storage is None:
00336             return
00337         fragment = self._doc.createDocumentFragment()
00338         
00339         assignment_paths = set()
00340         
00341         for name, rule in storage.items():
00342             rule_node = self._doc.createElement('rule')
00343             
00344             rule_node.setAttribute('name', name)
00345             rule_node.setAttribute('title', rule.title)
00346             rule_node.setAttribute('description', rule.description)
00347             rule_node.setAttribute('event',  _getDottedName(rule.event))
00348             rule_node.setAttribute('enabled', str(rule.enabled))
00349             rule_node.setAttribute('stop-after', str(rule.stop))
00350             
00351             # Aq-wrap so that exporting fields with clever getters or
00352             # vocabularies will work. We also aq-wrap conditions and
00353             # actions below.
00354 
00355             rule = rule.__of__(site)
00356             
00357             # Add conditions
00358             conditions_node = self._doc.createElement('conditions')
00359             for condition in rule.conditions:
00360                 condition_data = IRuleElementData(condition)
00361                 condition = condition.__of__(rule)
00362                 
00363                 condition_node = self._doc.createElement('condition')
00364                 condition_node.setAttribute('type', condition_data.element)
00365                 
00366                 handler = IRuleElementExportImportHandler(condition)
00367                 handler.export_element(self._doc, condition_node)
00368                 conditions_node.appendChild(condition_node)
00369             rule_node.appendChild(conditions_node)
00370             
00371             # Add actions
00372             actions_node = self._doc.createElement('actions')
00373             for action in rule.actions:
00374                 action_data = IRuleElementData(action)
00375                 action = action.__of__(rule)
00376                 
00377                 action_node = self._doc.createElement('action')
00378                 action_node.setAttribute('type', action_data.element)
00379                 
00380                 handler = IRuleElementExportImportHandler(action)
00381                 handler.export_element(self._doc, action_node)
00382                 actions_node.appendChild(action_node)
00383             rule_node.appendChild(actions_node)
00384             
00385             fragment.appendChild(rule_node)
00386             assignment_paths.update(get_assignments(rule))
00387             
00388         # Export assignments last - this is necessary to ensure they
00389         # are orderd properly
00390             
00391         site_path_length = len('/'.join(site.getPhysicalPath()))
00392         for path in assignment_paths:
00393             try:
00394                 container = site.unrestrictedTraverse(path)
00395             except KeyError:
00396                 continue
00397                 
00398             assignable = IRuleAssignmentManager(container, None)
00399             if assignable is None:
00400                 continue
00401             
00402             location = path[site_path_length:]
00403             for name, assignment in assignable.items():
00404                 assignment_node = self._doc.createElement('assignment')
00405                 assignment_node.setAttribute('location', location)
00406                 assignment_node.setAttribute('name', name)
00407                 assignment_node.setAttribute('enabled', str(assignment.enabled))
00408                 assignment_node.setAttribute('bubbles', str(assignment.bubbles))
00409                 fragment.appendChild(assignment_node)
00410 
00411         return fragment
00412 

Here is the call graph for this function:

Here is the caller graph for this function:

Import rules

Definition at line 188 of file rules.py.

00188 
00189     def _importNode(self, node):
00190         """Import rules
00191         """
00192         if self.environ.shouldPurge():
00193             self._purgeRules()
00194         self._initRules(node)
00195         self._logger.info('Content rules imported')

Here is the call graph for this function:

Here is the caller graph for this function:

Import rules from the given node

Definition at line 205 of file rules.py.

00205 
00206     def _initRules(self, node):
00207         """Import rules from the given node
00208         """
00209 
00210         site = self.environ.getSite()
00211         storage = queryUtility(IRuleStorage)
00212         if storage is None:
00213             return
00214 
00215         for child in node.childNodes:
00216             if child.nodeName == 'rule':
00217                 
00218                 rule = None
00219                 name = child.getAttribute('name')
00220                 if name:
00221                     rule = storage.get(name, None)
00222                 
00223                 if rule is None:                    
00224                     rule = Rule()
00225                     
00226                     if not name:
00227                         chooser = INameChooser(storage)
00228                         name = chooser.chooseName(None, rule)
00229                     
00230                     storage[name] = rule
00231                 else:
00232                     # Clear out conditions and actions since we're expecting new ones
00233                     del rule.conditions[:]
00234                     del rule.actions[:]
00235                 
00236                 rule.title = child.getAttribute('title')
00237                 rule.description = child.getAttribute('description')
00238                 rule.event = _resolveDottedName(child.getAttribute('event'))
00239                 
00240                 rule.enabled = as_bool(child.getAttribute('enabled'), True)
00241                 rule.stop = as_bool(child.getAttribute('stop-after'))
00242                 
00243                 # Aq-wrap to enable complex setters for elements below
00244                 # to work
00245                 
00246                 rule = rule.__of__(site)
00247                 
00248                 for rule_config_node in child.childNodes:
00249                     if rule_config_node.nodeName == 'conditions':
00250                         for condition_node in rule_config_node.childNodes:
00251                             if not condition_node.nodeName == 'condition':
00252                                 continue
00253 
00254                             type_ = condition_node.getAttribute('type')
00255                             element_type = getUtility(IRuleCondition, name=type_)
00256                             if element_type.factory is None:
00257                                 continue
00258                             
00259                             condition = element_type.factory()
00260                             
00261                             # Aq-wrap in case of complex setters
00262                             condition = condition.__of__(rule)
00263                             
00264                             handler = IRuleElementExportImportHandler(condition)
00265                             handler.import_element(condition_node)
00266                             
00267                             rule.conditions.append(aq_base(condition))
00268                             
00269                     elif rule_config_node.nodeName == 'actions':
00270                         for action_node in rule_config_node.childNodes:
00271                             if not action_node.nodeName == 'action':
00272                                 continue
00273                             
00274                             type_ = action_node.getAttribute('type')
00275                             element_type = getUtility(IRuleAction, name=type_)
00276                             if element_type.factory is None:
00277                                 continue
00278                             
00279                             action = element_type.factory()
00280                             
00281                             # Aq-wrap in case of complex setters
00282                             action = action.__of__(rule)
00283                             
00284                             handler = IRuleElementExportImportHandler(action)
00285                             handler.import_element(action_node)
00286                             
00287                             rule.actions.append(aq_base(action))
00288                 
00289             elif child.nodeName == 'assignment':
00290                 location = child.getAttribute('location')
00291                 if location.startswith("/"):
00292                     location = location[1:]
00293 
00294                 try:
00295                     container = site.unrestrictedTraverse(str(location))
00296                 except KeyError:
00297                     continue
00298                 
00299                 assignable = IRuleAssignmentManager(container, None)
00300                 if assignable is None:
00301                     continue
00302                     
00303                 name = child.getAttribute('name')
00304                 assignment = assignable.get(name, None)
00305                 if assignment is None:
00306                     assignment = assignable[name] = RuleAssignment(name)
00307                 
00308                 assignment.enabled = as_bool(child.getAttribute('enabled'))
00309                 assignment.bubbles = as_bool(child.getAttribute('bubbles'))
00310                 
00311                 insert_before = child.getAttribute('insert-before')
00312                 if insert_before:
00313                     position = None
00314                     keys = list(assignable.keys())
00315                     
00316                     if insert_before == "*":
00317                         position = 0
00318                     elif insert_before in keys:
00319                         position = keys.index(insert_before)
00320                     
00321                     if position is not None:
00322                         keys.remove(name)
00323                         keys.insert(position, name)
00324                         assignable.updateOrder(keys)
00325                         
00326                 path = '/'.join(container.getPhysicalPath())
00327                 get_assignments(storage[name]).insert(path)
                        

Here is the call graph for this function:

Here is the caller graph for this function:

Purge all registered rules

Definition at line 196 of file rules.py.

00196 
00197     def _purgeRules(self):
00198         """Purge all registered rules
00199         """
00200         storage = queryUtility(IRuleStorage)
00201         if storage is not None:
00202             # If we delete a rule, assignments will be removed as well
00203             for k in list(storage.keys()):
00204                 del storage[k]

Here is the caller graph for this function:


Member Data Documentation

Definition at line 176 of file rules.py.

Definition at line 175 of file rules.py.


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