Esempio n. 1
0
    def singleBranchTree(self, root=''):
        #print "singleBranchTree"
        result = ''
        oldItem = self.context
        # -----------------------------------
        subItems = []
        try:
            oldItemNav = INavigation(oldItem)
            objList = oldItemNav.getContextObjList()
            #print "ddd4: ", objList
            for obj in objList:
                if type(obj) is tuple:  # obj is a special view
                    #print "uuuuu: ", obj
                    (navView, viewTitle, contextObj) = obj
                    (xml_title, name, item_ppath, iklen,
                     stateIconUrl, stateValue,
                     stateOverview, additionalAttributes) = \
                        self.getCollectionAttributes(contextObj)
                    subItems.append(
                        xmlEscapeWithCData(
                            u'<collection title=%s name=%s iklen=%s rem="2.1.1.2" '
                            u'icon_url=%s expable="" navparam=%s state_url=%s path=%s '
                            u'>%s</collection>', viewTitle, item_ppath + name,
                            '1', 'generic',
                            xmlEscapeWithCData('view=%s', navView), 'generic',
                            '/', 'result'))
#                    subItems.append(xmlEscapeWithCData(
#                        u'<collection title=%s name=%s iklen=%s rem="2.1.1.2" '
#                        u'icon_url=%s expable="" state_url=%s path=%s '
#                        u'>%s</collection>',
#                        viewTitle, 'Interfaces/15eaa7b86bf9ec0217f9b6d0fe084fd1b', '1', '',
#                        'stateIconUrl', '/',
#                        'result'))
                else:
                    (xml_title, name, item_ppath, iklen,
                     stateIconUrl, stateValue,
                     stateOverview, additionalAttributes) = \
                        self.getCollectionAttributes(obj)
                    subItems.append(
                        xmlEscapeWithCData(
                            u'<collection title=%s name=%s iklen=%s rem="2.1.1.2" '
                            u'icon_url=%s isopen="" expable="" state_url=%s path=%s '
                            u'state_val=%s>%s</collection>', xml_title, name,
                            iklen, stateIconUrl, stateIconUrl, item_ppath,
                            stateOverview, result))
#            try:
#                subItems.append(xmlEscapeWithCData(
#                    u'<collection title=%s name=%s iklen=%s rem="2.1.1.2" '
#                    u'icon_url=%s expable="" state_url=%s path=%s '
#                    u'>%s</collection>',
#                    'Addresses2', 'Interfaces/15eaa7b86bf9ec0217f9b6d0fe084fd1b', '1', '',
#                    'stateIconUrl', '/',
#                    'result'))
#            except Exception, errText:
#                print "errText: ", errText
#            subItems.append('<collection title="Addresses" name="Addresses" iklen="1" icon_url="" rem="1.1.2" state_url="generic" expable="" path="/"/>')
        except TypeError, errText:
            print "lange Nase gezogen: ", errText
            return self.singleBranchTree2(root)
Esempio n. 2
0
 def getViewList(self, container):
     """Return an XML document that contains the children of an object."""
     subItems = []
     try:
         itemNav = INavigation(self.context)
         view_name = self.request.get('view', None)
         if itemNav is not None and view_name is not None:
             objList = itemNav.getViewObjList(view_name)
             #print "ooooooooooooooo: ", objList
         #print "ddd4: ", objList
         for obj in objList:
             (xml_title, name, item_ppath, iklen,
              stateIconUrl, stateValue,
              stateOverview, additionalAttributes) = \
                 self.getCollectionAttributes(obj)
             subItems.append(
                 xmlEscapeWithCData(
                     u'<collection title=%s name=%s iklen=%s rem="2.1.1.2.1" '
                     u'icon_url=%s isopen="" expable="" state_url=%s path=%s '
                     u'state_val=%s>%s</collection>', xml_title, name,
                     iklen, stateIconUrl, stateIconUrl, u'/' + item_ppath,
                     stateOverview, 'result'))
         #for obj in objList:
     except TypeError:
         pass
     return u' '.join(subItems)
Esempio n. 3
0
    def singleBranchTree(self, root=''):
        """Return an XML document with the siblings and parents of an object.

        There is only one branch expanded, in other words, the tree is
        filled with the object, its siblings and its parents with
        their respective siblings.

        """
        result = ''
        oldItem = self.context
        try:
            oldItemOid = self.context.getObjectId()
        except:
            oldItemOid = "+++"

        vh = self.request.getVirtualHostRoot()
        if vh:
            print "vh: ", vh
            vhrootView = zapi.getMultiAdapter(
                    (vh, self.request), name='absolute_url')
            baseURL = vhrootView() + '/'
            try:
                rootName = '[' + vh.__name__ + ']'
            except:
                # we got the containment root itself as the virtual host
                # and there is no name.
                rootName = _('[top]')
            parents = getParentsFromContextToObject(self.context, vh)
        else:
            rootName = _('[top]')
            baseURL = self.request.getApplicationURL() + '/'
            parents = getParents(self.context)
        rootName = translate(rootName, context=self.request,
                             default=rootName)
        for item in parents:
            # skip skin if present
            if item == oldItem:
                continue
            if item is None:
                continue
            subItems = []
            if IReadContainer.providedBy(item):
                keys = list(item.keys())
            else:
                keys = []
            # include the site manager
            keys.append(u'++etc++site')
            for name in keys:
                # Only include items we can traverse to
                subItem = traverse(item, name, None)
                if subItem is None:
                    continue
                if name == u'++etc++site' and \
                   not checkPermission(\
                       'org.ict_ok.ikadmin_utils.usermanagement.Edit',
                       subItem):
                    continue
                iconUrl = self.getIconUrl(subItem)
                subitem_len = self.getLengthOf(subItem)
                dcAdapter = IGeneralDublinCore(subItem)
                xml_title = name
                if dcAdapter:
                    if dcAdapter.title:
                        xml_title = dcAdapter.title
                stateIconUrl = self.getStateIconUrl(subItem)
                if zapi.getParent(subItem):
                    item_ppath = zapi.canonicalPath(zapi.getParent(subItem)) \
                               + u'/'
                    item_ppath = item_ppath.replace('//', '/')
                else:
                    item_ppath = "/"
                try:
                    subItemOid = subItem.getObjectId()
                except:
                    subItemOid = "---"
                stateOverview = self.getStateOverview(item)
                if subitem_len > 0:
                    # the test below seems to be broken
                    # with the ++etc++site case
                    if subItem == oldItem:
                        if oldItemOid == subItemOid: # focussed
                            subItems.append(xmlEscapeWithCData(
                                u'<collection isfocus="" title=%s name=%s '
                                u'iklen=%s '
                                u'icon_url=%s expable="" state_url=%s '
                                u'path=%s state_val=%s>%s</collection>', 
                                xml_title, name, subitem_len, iconUrl,
                                stateIconUrl, item_ppath, stateOverview,
                                result))
                        else:
                            subItems.append(xmlEscapeWithCData(
                                u'<collection title=%s name=%s iklen=%s '
                                u'icon_url=%s state_url=%s path=%s '
                                u'state_val=%s>%s</collection>', 
                                xml_title, name, subitem_len, iconUrl,
                                stateIconUrl, item_ppath, stateOverview,
                                result))
                    else:
                        subItems.append(xmlEscape(
                            u'<collection title=%s name=%s iklen=%s '
                            u'icon_url=%s expable="" state_url=%s path=%s/>',
                            xml_title, name, subitem_len, iconUrl,
                            stateIconUrl, item_ppath))
                else:
                    if subItem == oldItem:
                        if oldItemOid == subItemOid: # focussed
                            subItems.append(xmlEscapeWithCData(
                                u'<collection isfocus="" title=%s '
                                u'name=%s iklen=%s '
                                u'icon_url=%s state_url=%s path=%s '
                                u'state_val=%s>%s</collection>', 
                                xml_title, name, subitem_len, iconUrl,
                                stateIconUrl, item_ppath, stateOverview,
                                result))
                        else:
                            subItems.append(xmlEscapeWithCData(
                                u'<collection title=%s name=%s iklen=%s '
                                u'icon_url=%s state_url=%s path=%s '
                                u'state_val=%s>%s</collection>', 
                                xml_title, name, subitem_len, iconUrl,
                                stateIconUrl, item_ppath, stateOverview,
                                result))
                    else:
                        subItems.append(xmlEscape(
                            u'<collection title=%s name=%s iklen=%s '
                            u'icon_url=%s state_url=%s path=%s/>',
                            xml_title, name, subitem_len, iconUrl,
                            stateIconUrl, item_ppath))

            result = u' '.join(subItems)
            oldItem = item

        # do not forget root folder
        iconUrl = self.getIconUrl(oldItem)
        xml_title = "ICT_Ok"
        rootName =  "."
        
        if len(result) > 0: # collection has content
            result = xmlEscapeWithCData(
                      u'<collection title=%s name=%s baseURL=%s iklen=%s '
                      u'icon_url=%s path=%s isroot="">%s</collection>',
                      xml_title, rootName, baseURL, len(oldItem), iconUrl,
                      "/", result)
        else:
            result = xmlEscapeWithCData(
                      u'<collection title=%s name=%s baseURL=%s iklen=%s '
                      u'icon_url=%s path=%s expable="" '
                      u'isroot="">%s</collection>',
                      xml_title, rootName, baseURL, len(oldItem), iconUrl,
                      "/", result)

        self.request.response.setHeader('Content-Type', 'text/xml')
        setNoCacheHeaders(self.request.response)
        title = translate(titleTemplate,
                          context=self.request, default=titleTemplate)
        loading = translate(loadingMsg,
                          context=self.request, default=loadingMsg)
        return xmlEscapeWithCData(
                u'<?xml version="1.0" encoding="ISO-8859-1"?>'
                u'<children title_tpl=%s title=%s '
                u'loading_msg=%s>%s</children>',
                title, title, loading, result)
Esempio n. 4
0
    def singleBranchTree3(self, root=''):
        result = ''
        oldItem = self.context
        xml_title = '11111'
        name = '22222'
        subitem_len = 0
        #oldItem = []
        iconUrl = ''
        stateIconUrl = ''
        item_ppath = ''
        stateOverview = ''
        rootName = '8888'
        baseURL = ''
        subItems = []
        #        subItems.append(xmlEscapeWithCData(
        #            u'<collection isfocused="" title=%s '
        #            u'name=%s iklen=%s rem="2.2.1.1" '
        #            u'icon_url=%s state_url=%s path=%s '
        #            u'state_val=%s>%s</collection>',
        #            xml_title, name, subitem_len, iconUrl,
        #            stateIconUrl, item_ppath, stateOverview,
        #            result))
        result = u' '.join(subItems)

        #        dcAdapter = IGeneralDublinCore(oldItem)
        xml_title = oldItem.getDcTitle()
        #        if dcAdapter:
        #            if dcAdapter.title:
        #                xml_title = dcAdapter.title
        iconUrl = self.getIconUrl(oldItem)
        url2 = urlparse(zapi.absoluteURL(oldItem, self.request))
        name = url2[2].split('/')[-1]
        parentItem = zapi.getParent(oldItem)
        #parentItem.keys()[parentItem.values().index(oldItem)]
        stateIconUrl = self.getStateIconUrl(oldItem)
        #stateValue = self.getStateValue(oldItem)
        stateOverview = self.getStateOverview(oldItem)
        try:
            item_len = len(IContentList(oldItem).getContentList())
        except TypeError:
            item_len = self.getLengthOf(oldItem)
#            item_ppath = zapi.canonicalPath(zapi.getParent(item)) + u'/'
        url = urlparse(zapi.absoluteURL(zapi.getParent(oldItem), self.request))
        item_ppath = url.path + u'/'
        item_ppath = item_ppath.replace('//', '/')

        if len(result) > 0:  # collection has content
            result = xmlEscapeWithCData(
                u'<collection title=%s name=%s iklen=%s rem="3.1" '
                u'icon_url=%s path=%s isopen="" isroot="">%s</collection>',
                xml_title, name, len(oldItem), iconUrl, item_ppath, result)
        else:
            result = xmlEscapeWithCData(
                u'<collection title=%s name=%s iklen=%s rem="3.2" '
                u'icon_url=%s path=%s expable="" '
                u'isroot="">%s</collection>', xml_title, name, len(oldItem),
                iconUrl, item_ppath, result)
        self.request.response.setHeader('Content-Type', 'text/xml')
        setNoCacheHeaders(self.request.response)
        title = translate(titleTemplate,
                          context=self.request,
                          default=titleTemplate)
        loading = translate(loadingMsg,
                            context=self.request,
                            default=loadingMsg)
        return xmlEscapeWithCData(
            u'<?xml version="1.0" encoding="ISO-8859-1"?>'
            u'<children title_tpl=%s title=%s '
            u'loading_msg=%s>%s</children>', title, title, loading, result)
Esempio n. 5
0
#                result))
#        except TypeError:
#            pass
# -----------------------------------

        result = u' '.join(subItems)

        # -----------------------------------
        (xml_title, name, item_ppath, iklen,
         stateIconUrl, stateValue, stateOverview,
         additionalAttributes) = \
            self.getCollectionAttributes(oldItem)
        if len(result) > 0:  # collection has content
            result = xmlEscapeWithCData(
                u'<collection isfocused2="" title=%s name=%s iklen=%s rem="3.1" '
                u'icon_url=%s state_url=%s navparam="children5.xml" path=%s isopen="" isroot="">%s</collection>',
                xml_title, name, iklen, stateIconUrl, stateIconUrl, item_ppath,
                result)
        else:
            result = xmlEscapeWithCData(
                u'<collection isfocused2="" title=%s name=%s iklen=%s rem="3.2" '
                u'icon_url=%s state_url=%s navparam="children6.xml" path=%s expable="" '
                u'isroot="">%s</collection>', xml_title, name, iklen,
                stateIconUrl, stateIconUrl, item_ppath, result)
        self.request.response.setHeader('Content-Type', 'text/xml')
        setNoCacheHeaders(self.request.response)
        title = translate(titleTemplate,
                          context=self.request,
                          default=titleTemplate)
        loading = translate(loadingMsg,
                            context=self.request,