def resolve(self, path):
        if path:
            imported_path = self._importer.getImportedPath(canonical_path(path))
            if imported_path is not None:
                path = map(str, imported_path.split('/'))
                try:
                    target = self._importer.root.unrestrictedTraverse(path)
                except (AttributeError, KeyError):
                    self.report(
                        'Could not traverse imported path {0}.'.format(path))
                self._contents.append(target)
            else:
                self.report(
                    'Could not resolve imported path {0}.'.format(path))
        else:
            self.report('Broken reference.')

        self._expected -= 1
        if not self._expected and self._callback is not None:
            if self._single:
                if self._contents:
                    if len(self._contents) != 1:
                        self.reportProblem(
                            'Found multiple paths where only one was expected.')
                    self._callback(self._contents[0])
            else:
                self._callback(self._contents)
Example #2
0
 def sax_excludes(self):
     self.startElementNS(NS_NEWS_URI, "excludes")
     exported = self.getExported()
     for item in self.context.get_excluded_items():
         if is_inside_container(exported.root, item):
             path = [exported.root.getId()] + relative_path(
                 exported.rootPath, item.getPhysicalPath())
             path = canonical_path('/'.join(path))
             self.startElementNS(
                 NS_NEWS_URI, 'exclude', {'target': path})
             self.endElementNS(NS_NEWS_URI, 'exclude')
         else:
             exported.reportProblem(
                 'Content excluded from the filter was not exported',
                 content=self.context)
     self.endElementNS(NS_NEWS_URI, "excludes")
Example #3
0
 def action():
     if path[0:5] == 'root:':
         imported_path = path[5:]
     else:
         imported_path = self.getImportedPath(canonical_path(path))
     if not imported_path:
         self.reportProblem(
             "Refering inexisting path {0} in the import.".format(path),
             content)
         return
     try:
         target = self.root.unrestrictedTraverse(
             map(str, imported_path.split('/')))
     except (KeyError, AttributeError):
         self.reportProblem(
             "Refered path {0} is not found in the import.".format(
                 imported_path),
             content)
     else:
         try:
             setter(target)
         except Error as error:
             self.reportProblem(error.reason, content)
 def serializeValue(self, field, value, producer):
     if not value:
         return
     handler = producer.getHandler()
     options = handler.getOptions()
     if options.external_rendering:
         return
     if not bool(field.get_value('multiple')):
         value = [value]
     exported = handler.getExported()
     producer.startPrefixMapping(None, NS_REFERENCES)
     for target in value:
         if value is not None:
             if is_inside_container(exported.root, target):
                 target_path = [exported.root.getId()] + relative_path(
                     exported.rootPath, target.getPhysicalPath())
                 producer.startElement('path')
                 producer.characters(canonical_path('/'.join(target_path)))
                 producer.endElement('path')
             else:
                 if options.external_references:
                     exported.reportProblem(
                         (u"A reference field '{0}' refers to an " +
                          u'content outside of the export ({1}).').format(
                             field.getId(),
                             '/'.join(relative_path(
                                     exported.rootPath,
                                     target.getPhysicalPath()))),
                         producer.context)
                     producer.startElement('path')
                     producer.endElement('path')
                 else:
                     raise ExternalReferenceError(
                         _(u"External reference"),
                         producer.context, target, exported.root)
     producer.endPrefixMapping(None)