Esempio n. 1
0
# -*- coding: utf-8 -*-
# Copyright (c) 2006-2013 Infrae. All rights reserved.
# See also LICENSE.txt

from five import grok
from silva.core import conf as silvaconf
from sprout.saxext.xmlimport import BaseHandler
from zope.component import getMultiAdapter

from silva.core.xml import handlers
from Products.SilvaFind.silvaxml import NS_FIND_URI
from Products.SilvaFind.interfaces import ICriterionData

silvaconf.namespace(NS_FIND_URI)


class CriterionField(BaseHandler):
    category = 'criterion'

    def __init__(self, *args, **kwargs):
        super(CriterionField, self).__init__(*args, **kwargs)
        self.fields = {}
        self.field = None

    def startElementNS(self, name, qname, attrs):
        if name == (NS_FIND_URI, 'field'):
            name = attrs[(None, 'name')].encode('utf-8')
            self.fields[name] = []
            self.field = name
        if name == (NS_FIND_URI, 'value'):
            assert self.field is not None
from silva.core.interfaces import IVersion, ISilvaXMLHandler
from silva.core.editor.transform.interfaces import ISilvaXMLImportFilter
from silva.core.editor.transform.base import TransformationFilter
from silva.core.xml import handlers
from zeam.component import getWrapper
from zeam.form.silva.interfaces import IXMLFormSerialization

from silva.core.xml import NS_SILVA_URI

from . import NS_SOURCE_URI
from ..interfaces import IExternalSourceManager, ISourceAsset
from ..errors import SourceError

logger = logging.getLogger('silva.core.xml')

silvaconf.namespace(NS_SOURCE_URI)


class ExternalSourceImportFilter(TransformationFilter):
    grok.adapts(IVersion, ISilvaXMLHandler)
    grok.provides(ISilvaXMLImportFilter)
    grok.order(15)

    def __init__(self, context, handler):
        self.context = context
        self.handler = handler

    def prepare(self, name, text):
        self.sources = getWrapper(self.context, IExternalSourceManager)

    def __call__(self, tree):
Esempio n. 3
0
# -*- coding: utf-8 -*-
# Copyright (c) 2012-2013 Infrae. All rights reserved.
# See also LICENSE.txt

from silva.core import conf as silvaconf
from silva.core.xml import NS_SILVA_URI, handlers
from silva.app.news.silvaxml import helpers
from silva.app.page.silvaxml import NS_PAGE_URI
from silva.core.contentlayout.silvaxml import NS_LAYOUT_URI
from silva.core.contentlayout.silvaxml.xmlimport import DesignHandler,\
    BlockHandler
from silva.app.page.news.blocks import NewsInfoBlock, AgendaInfoBlock


silvaconf.namespace(NS_PAGE_URI)


class PageHandler(handlers.SilvaHandler):
    silvaconf.name('page')

    def getOverrides(self):
        return {(NS_SILVA_URI, 'content'): PageVersionHandler}

    def _createContent(self, identifier):
        factory = self.parent().manage_addProduct['silva.app.page']
        factory.manage_addPage(identifier, '', no_default_version=True)

    def startElementNS(self, name, qname, attrs):
        if name == (NS_PAGE_URI, 'page'):
            self.createContent(attrs)
Esempio n. 4
0
# -*- coding: utf-8 -*-
# Copyright (c) 2002-2013 Infrae. All rights reserved.
# See also LICENSE.txt

import uuid

from Products.SilvaDocument.silvaxml import NS_DOCUMENT_URI
from Products.SilvaDocument.transform.base import LINK_REFERENCE_TAG

from zope.component import getUtility
from silva.core.xml import handlers, NS_SILVA_URI
from silva.core import conf as silvaconf
from silva.core.references.interfaces import IReferenceService

silvaconf.namespace(NS_SILVA_URI)


class DocumentHandler(handlers.SilvaHandler):
    silvaconf.name('document')

    def getOverrides(self):
        return {(NS_SILVA_URI, 'content'): DocumentVersionHandler}

    def startElementNS(self, name, qname, attrs):
        if name == (NS_SILVA_URI, 'document'):
            uid = self.generateIdentifier(attrs)
            factory = self.parent().manage_addProduct['SilvaDocument']
            factory.manage_addDocument(uid, '', no_default_version=True)
            self.setResultId(uid)

    def endElementNS(self, name, qname):
from silva.core import conf as silvaconf
from silva.core.editor.transform.silvaxml import NS_EDITOR_URI
from silva.core.editor.transform.silvaxml.xmlimport import TextHandler
from zeam.component import getWrapper

from . import NS_LAYOUT_URI
from ..designs.registry import registry
from ..interfaces import IBlockManager, IBlockController
from ..blocks.slot import BlockSlot
from ..blocks.text import TextBlock
from ..blocks.contents import ReferenceBlock
from ..blocks.source import SourceBlock
from ..slots import restrictions


silvaconf.namespace(NS_LAYOUT_URI)


class SlotHandler(handlers.SilvaHandler):
    silvaconf.name('slot')

    def startElementNS(self, name, qname, attrs):
        if (NS_LAYOUT_URI, 'slot') == name:
            self.setResult(attrs[(None, 'id')])


class BlockHandler(handlers.SilvaHandler):
    grok.baseclass()

    def addBlock(self, block):
        slot_id = self.parent()
# -*- coding: utf-8 -*-
# Copyright (c) 2013  Infrae. All rights reserved.
# See also LICENSE.txt

from zope.publisher.browser import TestRequest
from zeam.component import getWrapper

from silva.app.mediacontent.block import SlideshowBlock
from silva.app.mediacontent.silvaxml import NS_MEDIACONTENT_URI
from silva.core import conf as silvaconf
from silva.core.contentlayout.silvaxml.xmlimport import BlockHandler
from silva.core.xml import NS_SILVA_URI, handlers
from silva.core.contentlayout.interfaces import IBlockController

silvaconf.namespace(NS_MEDIACONTENT_URI)


class MediaContentHandler(handlers.SilvaHandler):
    silvaconf.name('mediacontent')

    def getOverrides(self):
        return {(NS_SILVA_URI, 'content'): MediaContentVersionHandler}

    def _createContent(self, identifier):
        factory = self.parent().manage_addProduct['silva.app.mediacontent']
        factory.manage_addMediaContent(identifier, '', no_default_version=True)

    def startElementNS(self, name, qname, attrs):
        if name == (NS_MEDIACONTENT_URI, 'mediacontent'):
            self.createContent(attrs)
from silva.core.interfaces import IVersion, ISilvaXMLHandler
from silva.core.editor.transform.interfaces import ISilvaXMLImportFilter
from silva.core.editor.transform.base import TransformationFilter
from silva.core.xml import handlers
from zeam.component import getWrapper
from zeam.form.silva.interfaces import IXMLFormSerialization

from silva.core.xml import NS_SILVA_URI

from . import NS_SOURCE_URI
from ..interfaces import IExternalSourceManager, ISourceAsset
from ..errors import SourceError

logger = logging.getLogger('silva.core.xml')

silvaconf.namespace(NS_SOURCE_URI)


class ExternalSourceImportFilter(TransformationFilter):
    grok.adapts(IVersion, ISilvaXMLHandler)
    grok.provides(ISilvaXMLImportFilter)
    grok.order(15)

    def __init__(self, context, handler):
        self.context = context
        self.handler = handler

    def prepare(self, name, text):
        self.sources = getWrapper(self.context, IExternalSourceManager)

    def __call__(self, tree):
Esempio n. 8
0
# -*- coding: utf-8 -*-
# Copyright (c) 2010-2013 Infrae. All rights reserved.
# See also LICENSE.txt

from silva.app.document.silvaxml import NS_DOCUMENT_URI
from silva.core import conf as silvaconf
from silva.core.editor.transform.silvaxml import NS_EDITOR_URI
from silva.core.editor.transform.silvaxml.xmlimport import TextHandler
from silva.core.xml import handlers, NS_SILVA_URI

silvaconf.namespace(NS_DOCUMENT_URI)


class DocumentHandler(handlers.SilvaHandler):
    silvaconf.name('document')

    def getOverrides(self):
        return {(NS_SILVA_URI, 'content'): DocumentVersionHandler}

    def _createContent(self, identifier):
        factory = self.parent().manage_addProduct['silva.app.document']
        factory.manage_addDocument(identifier, '', no_default_version=True)

    def startElementNS(self, name, qname, attrs):
        if name == (NS_DOCUMENT_URI, 'document'):
            self.createContent(attrs)

    def endElementNS(self, name, qname):
        if name == (NS_DOCUMENT_URI, 'document'):
            self.notifyImport()
Esempio n. 9
0
# -*- coding: utf-8 -*-
# Copyright (c) 2013  Infrae. All rights reserved.
# See also LICENSE.txt

from five import grok
from silva.core import conf as silvaconf
from silva.core.xml import NS_SILVA_URI, handlers


silvaconf.namespace(NS_SILVA_URI)


class ProblemHandler(handlers.BaseHandler):
    """Collect a problem that is given in the XML.
    """
    _path = None
    _message = None

    def startElementNS(self, name, qname, attrs):
        if name == (NS_SILVA_URI, 'problem'):
            self._path = attrs.get((None, 'path'), '')
            self._message = []

    def characters(self, chars):
        if self._message is not None:
            self._message.append(chars)

    def endElementNS(self, name, qname):
        if name == (NS_SILVA_URI, 'problem'):
            imported = self.getExtra()
            message = ''.join(self._message).strip()
Esempio n. 10
0
from five import grok
from Products.SilvaSoftwarePackage.silvaxml import NS_PACKAGE_URI
from silva.core import conf as silvaconf
from silva.core.xml import handlers

silvaconf.namespace(NS_PACKAGE_URI)


class CenterHandler(handlers.SilvaHandler):
    grok.name('center')

    def _createContent(self, identifier):
        factory = self.parent().manage_addProduct['SilvaSoftwarePackage']
        factory.manage_addSilvaSoftwareCenter(identifier,
                                              '',
                                              no_default_content=True)

    def startElementNS(self, name, qname, attrs):
        if name == (NS_PACKAGE_URI, 'center'):
            self.createContent(attrs)

    def endElementNS(self, name, qname):
        if name == (NS_PACKAGE_URI, 'center'):
            self.storeMetadata()
            self.notifyImport()


class GroupHandler(handlers.SilvaHandler):
    grok.name('group')

    def _createContent(self, identifier):
Esempio n. 11
0
from silva.core.xml import handlers
from Products.Silva.silvaxml.xmlimport import NS_SILVA_URI as NS_URI
from Products.Silva import mangle
from silva.core import conf as silvaconf

from Products.SilvaNews.silvaxml.xmlexport import NS_SILVA_NEWS
from Products.SilvaNews.silvaxml import helpers
from Products.SilvaNews.NewsItem import (
    NewsItem, NewsItemVersion)
from Products.SilvaNews.AgendaItem import (
    AgendaItem, AgendaItemVersion)
from Products.SilvaDocument.silvaxml.xmlimport import DocXMLHandler
from Products.SilvaDocument.silvaxml import NS_DOCUMENT_URI as NS_SILVA_DOCUMENT

silvaconf.namespace(NS_SILVA_NEWS)


class SNNHandlerMixin(object):
    """ mixin class to handle shared attribute setting across
        many of the SNN objects """

    def set_attrs(self,attrs,obj):
        helpers.set_attribute_as_list(obj, 'target_audiences', attrs)
        helpers.set_attribute_as_list(obj, 'subjects', attrs)
        helpers.set_attribute_as_bool(obj, 'number_is_days', attrs)
        helpers.set_attribute_as_bool(obj, 'show_agenda_items', attrs)
        helpers.set_attribute_as_bool(obj, 'keep_to_path', attrs)
        helpers.set_attribute_as_int(obj, 'number_to_show', attrs)
        helpers.set_attribute_as_int(obj, 'number_to_show_archive', attrs)
        if attrs.has_key((None,'excluded_items')):
Esempio n. 12
0
# Copyright (c) 2002-2013 Infrae. All rights reserved.
# See also LICENSE.txt

from silva.core.xml import handlers
from Products.Silva.silvaxml.xmlimport import NS_SILVA_URI as NS_URI
from Products.Silva import mangle
from silva.core import conf as silvaconf

from Products.SilvaNews.silvaxml.xmlexport import NS_SILVA_NEWS
from Products.SilvaNews.silvaxml import helpers
from Products.SilvaNews.NewsItem import (NewsItem, NewsItemVersion)
from Products.SilvaNews.AgendaItem import (AgendaItem, AgendaItemVersion)
from Products.SilvaDocument.silvaxml.xmlimport import DocXMLHandler
from Products.SilvaDocument.silvaxml import NS_DOCUMENT_URI as NS_SILVA_DOCUMENT

silvaconf.namespace(NS_SILVA_NEWS)


class SNNHandlerMixin(object):
    """ mixin class to handle shared attribute setting across
        many of the SNN objects """
    def set_attrs(self, attrs, obj):
        helpers.set_attribute_as_list(obj, 'target_audiences', attrs)
        helpers.set_attribute_as_list(obj, 'subjects', attrs)
        helpers.set_attribute_as_bool(obj, 'number_is_days', attrs)
        helpers.set_attribute_as_bool(obj, 'show_agenda_items', attrs)
        helpers.set_attribute_as_bool(obj, 'keep_to_path', attrs)
        helpers.set_attribute_as_int(obj, 'number_to_show', attrs)
        helpers.set_attribute_as_int(obj, 'number_to_show_archive', attrs)
        if (None, 'excluded_items') in attrs:
            eis = attrs[(None, 'excluded_items')]
Esempio n. 13
0
# -*- coding: utf-8 -*-
# Copyright (c) 2006-2013 Infrae. All rights reserved.
# See also LICENSE.txt

from five import grok
from silva.core import conf as silvaconf
from sprout.saxext.xmlimport import BaseHandler
from zope.component import getMultiAdapter

from silva.core.xml import handlers
from Products.SilvaFind.silvaxml import NS_FIND_URI
from Products.SilvaFind.interfaces import ICriterionData

silvaconf.namespace(NS_FIND_URI)


class CriterionField(BaseHandler):
    category = 'criterion'

    def __init__(self, *args, **kwargs):
        super(CriterionField, self).__init__(*args, **kwargs)
        self.fields = {}
        self.field = None

    def startElementNS(self, name, qname, attrs):
        if name == (NS_FIND_URI, 'field'):
            name = attrs[(None, 'name')].encode('utf-8')
            self.fields[name] = []
            self.field = name
        if name == (NS_FIND_URI, 'value'):
            assert self.field is not None