##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=TAB_LANGUAGES
##
from Products.zms import standard

request = container.REQUEST
RESPONSE = request.RESPONSE
langIds = context.getLangIds(sort=True)
xml = context.getMetaobjManager().exportMetaobjXml(ids=[context.meta_id])
rs = standard.distinct_list([
    x.split(',')[0] for x in standard.re_search('getLangStr\((.*?)\)', xml)
    if len(x.split(',')) == 2
])
rs = [
    x[1:-1] for x in rs if len(x) > 2 and x[0] in ["'", '"'] and x[0] == x[-1]
]
rs.sort()

prt = []
prt.append('<!DOCTYPE html>')
prt.append('<html lang="en">')
prt.append(context.zmi_html_head(context, request))
prt.append('<body class="%s">' % context.zmi_body_class(id='tab_languages'))
prt.append(context.zmi_body_header(context, request))
prt.append('<div id="zmi-tab">')
prt.append(context.zmi_breadcrumbs(context, request))
 def re_search(self, pattern, subject, ignorecase=False):
     warn(self, 're_search', 'Products.zms.standard.re_search')
     return standard.re_search(pattern, subject, ignorecase)
def manage_zcatalog_update_documents(self):
    msg = []
    request = self.REQUEST
    RESPONSE = request.RESPONSE
    zmscontext = self.getLinkObj(request.get('uid', '{$}'))
    home = zmscontext.getDocumentElement()
    home_id = home.getPhysicalPath()
    home_id = home_id[home_id.index('content') - 1]
    inst_home = zmscontext.Control_Panel.getINSTANCE_HOME()
    path = home_id
    node = home
    while True:
        node = node.getPortalMaster()
        if node is None: break
        path = node.getHome().getId() + '/' + path

    xmlpath = '%s/var/%s/sitemap.xml' % (inst_home, path)
    xml = standard.localfs_read(xmlpath, mode={
        'threshold': -1
    }).decode('utf-8')
    msg.append('%i xml-bytes read from %s' % (len(xml), xmlpath))

    def update(action, xml):
        solr_url = zmscontext.getConfProperty('solr.url',
                                              'http://*****:*****@@')
        if i >= 0:
            body = doc[i + len('">@@'):]
            body = body[:body.find('</field>')]
            id = standard.re_search('<field name="id"(.*?)>(.*?)<\/field>',
                                    doc)[1]
            bins.append({'id': id, 'body': body})
            doc = standard.re_sub(
                '<field name="(.*?)_t"(.*?)>@@(.*?)<\/field>',
                '<field name="\\1_t"\\2></field>', doc)
        buff.append(doc)
        docs.remove(docs[0])
    msg.append(update("commit", get_command_xml('commit')))
    for b in bins:
        body = b['body'].split(':')
        ids = body[0].split('/')[1:]
        attr_name = body[1]
        node = home
        while ids:
            node = getattr(node, ids.pop(0))
        d = {
            'literal.id': b['id'],
            'commit': 'true',
            'myfile': node.attr(attr_name).getData(request)
        }
        msg.append(update_extract("extract", d))
    msg.append(update("optimize", get_command_xml('optimize')))

    RESPONSE.setHeader('Content-Type', 'text/plain;charset=utf-8')
    msg.append("Done!")
    return '\n'.join(msg)


# --// /manage_zcatalog_update_documents //--