Diff for /ECHO_content/vlp_xmlhelpers.py between versions 1.13 and 1.16

version 1.13, 2007/12/11 17:00:01 version 1.16, 2009/06/09 14:05:20
Line 23  regexpTXT = re.compile(patternTXT, re.IG Line 23  regexpTXT = re.compile(patternTXT, re.IG
 patternPage=r"<\s*page.*?>(.*?)</page>"  patternPage=r"<\s*page.*?>(.*?)</page>"
 regexpPage = re.compile(patternPage, re.IGNORECASE + re.DOTALL)  regexpPage = re.compile(patternPage, re.IGNORECASE + re.DOTALL)
   
 xml2htmlArray={'WEB_normal':('<p>','</p>'),'Normal':('<p>','</p>'),'WEB_picture':('<p class=\"picture\">','</p>'),'WEB_figuretitle':('<p class=\"picturetitle\">','</p>'),'WEB_bibliography':('<p><i>','</i></p>'),'Web_kursiv':('<i>','</i>'),'WEB_kursiv':('<i>','</i>'),'WEB_hyperlink':('',''),'Hyperlink':('',''),'Picture':('<p class=\"picture\">','</p>'),'FigureTitle':('<p class=\"picturetitle\">','</p>')}  #xml2htmlArray={'WEB_normal':('<p>','</p>'),'Normal':('<p>','</p>'),'WEB_picture':('<p class=\"picture\">','</p>'),'WEB_figuretitle':('<p class=\"picturetitle\">','</p>'),'WEB_bibliography':('<p><i>','</i></p>'),'Web_kursiv':('<i>','</i>'),'WEB_kursiv':('<i>','</i>'),'WEB_hyperlink':('',''),'Hyperlink':('',''),'Picture':('<p class=\"picture\">','</p>'),'FigureTitle':('<p class=\"picturetitle\">','</p>')}
   #
 def addToDict(dict,name,value):  #def addToDict(dict,name,value):
     if name=="":  #    if name=="":
         return 0  #        return 0
     else:  #    else:
           #        
         if not dict.has_key(name):  #        if not dict.has_key(name):
             dict[name]=[] # als array anlegen  #            dict[name]=[] # als array anlegen
   #
         dict[name].append(value)  #        dict[name].append(value)
         return 1      #        return 1    
   #
 def proj2hash(self,xmlstring):  #def proj2hash(self,xmlstring):
     """wandelt xml-files fuer die projekte in ein hash"""  #    """wandelt xml-files fuer die projekte in ein hash"""
       #    
     dom=xml.dom.minidom.parseString(xmlstring)  #    dom=xml.dom.minidom.parseString(xmlstring)
       #    
           #        
     list={}  #    list={}
   #
     #gettitle  #    #gettitle
     pars=Evaluate('par',dom.getElementsByTagName('part')[0])  #    pars=Evaluate('par',dom.getElementsByTagName('part')[0])
     for par in pars:  #    for par in pars:
         className=par.getAttribute('class')  #        className=par.getAttribute('class')
         content=getText(self,par.childNodes)  #        content=getText(self,par.childNodes)
         addToDict(list,className,content)  #        addToDict(list,className,content)
                #             
   #
     sectionXPath="section"  #    sectionXPath="section"
   #
       #    
     sections=Evaluate(sectionXPath,dom.getElementsByTagName('part')[0])  #    sections=Evaluate(sectionXPath,dom.getElementsByTagName('part')[0])
       #    
     while sections:  #    while sections:
           #        
         for section in sections:  #        for section in sections:
               #            
             sec=parseSection(self,section)  #            sec=parseSection(self,section)
               #            
             if sec[0]=="WEB_project_header": # Sonderfall project  #            if sec[0]=="WEB_project_header": # Sonderfall project
                 addToDict(list,'WEB_project_header',sec[1]) # store title  #                addToDict(list,'WEB_project_header',sec[1]) # store title
                 addToDict(list,'WEB_project_description',sec[2]) #store description  #                addToDict(list,'WEB_project_description',sec[2]) #store description
             else: # no information in heading  #            else: # no information in heading
                 level=int(sec[3])+2  #                level=int(sec[3])+2
                 aTag="<h%i>"%level  #                aTag="<h%i>"%level
                 eTag="</h%i>"%level  #                eTag="</h%i>"%level
                 addToDict(list,"text",aTag+sec[1]+eTag)  #                addToDict(list,"text",aTag+sec[1]+eTag)
                 addToDict(list,"text",sec[2])  #                addToDict(list,"text",sec[2])
         sectionXPath+="/section"  #        sectionXPath+="/section"
         sections=Evaluate(sectionXPath,dom.getElementsByTagName('part')[0])  #        sections=Evaluate(sectionXPath,dom.getElementsByTagName('part')[0])
     return list  #    return list
   #
   #
 def parseSection(self,section):  #def parseSection(self,section):
     type=""  #    type=""
     header=""  #    header=""
     level=section.getAttribute('level')  #    level=section.getAttribute('level')
     for heading in section.childNodes:  #    for heading in section.childNodes:
         if getattr(heading,'tagName','')=="heading":  #        if getattr(heading,'tagName','')=="heading":
               #            
             type=heading.getAttribute('class')  #            type=heading.getAttribute('class')
             header=getText(self,heading.childNodes)  #            header=getText(self,heading.childNodes)
   #
     if type=="": # falls heading fehlt, pruefe ob erster par richtig  #    if type=="": # falls heading fehlt, pruefe ob erster par richtig
         par=section.getElementsByTagName('par')[0]  #        par=section.getElementsByTagName('par')[0]
         type=par.getAttribute('class')  #        type=par.getAttribute('class')
         header=getText(par.childNodes)  #        header=getText(par.childNodes)
   #
     #print section.childNodes  #    #print section.childNodes
     #pars=Evaluate('par',section)  #    #pars=Evaluate('par',section)
     pars=section.childNodes  #    pars=section.childNodes
     content=par2html(self,pars)  #    content=par2html(self,pars)
     #print "CONTENT",repr(content)  #    #print "CONTENT",repr(content)
     return (type,header,content,level)  #    return (type,header,content,level)
   #
 def parseTable(table):  #def parseTable(table):
     fields={}  #    fields={}
     rows=table.getElementsByTagName('html:tr')  #    rows=table.getElementsByTagName('html:tr')
     for row in rows:  #    for row in rows:
         #print "ROW"  #        #print "ROW"
         cols=row.getElementsByTagName('html:td')  #        cols=row.getElementsByTagName('html:td')
           #        
         #Name des Datenfeldes einlesen  #        #Name des Datenfeldes einlesen
         try:  #        try:
             field=cols[0].getElementsByTagName('par')[0].getAttribute('class')  #            field=cols[0].getElementsByTagName('par')[0].getAttribute('class')
             #print "field",field  #            #print "field",field
         except:  #        except:
             print "error"  #            print "error"
             field=""  #            field=""
   #
         #Wandeln der Eintrge in HTML  #        #Wandeln der Eintrge in HTML
   #
         #pars=cols[1].getElementsByTagName('par')  #        #pars=cols[1].getElementsByTagName('par')
         pars=cols[1].childNodes  #        pars=cols[1].childNodes
           #        
         html=par2html(self,pars,tags=("",";"))  #        html=par2html(self,pars,tags=("",";"))
           #        
         addToDict(fields,field,html)  #        addToDict(fields,field,html)
         #print fields  #        #print fields
     return fields  #    return fields
   #
 def par2html(self,pars,tags=None):  #def par2html(self,pars,tags=None):
     html=""  #    html=""
   #
     for par in pars:  #    for par in pars:
         tagName=getattr(par,'tagName','')  #        tagName=getattr(par,'tagName','')
         if tagName in ["par","inline"]:  #        if tagName in ["par","inline"]:
             #print repr(par.getAttribute('class')),xml2htmlArray.get(par.getAttribute('class'),'NOT FOUND')  #            #print repr(par.getAttribute('class')),xml2htmlArray.get(par.getAttribute('class'),'NOT FOUND')
             #print "par",par  #            #print "par",par
             if not tags:  #            if not tags:
                 try:  #                try:
                     tag=xml2htmlArray[par.getAttribute('class')]  #                    tag=xml2htmlArray[par.getAttribute('class')]
                 except:  #                except:
                     tag=('<p>','</p>')  #                    tag=('<p>','</p>')
             else:  #            else:
                 tag=tags  #                tag=tags
             #print "TAG",tag  #            #print "TAG",tag
             content=getText(self,par.childNodes,par.getAttribute('class'))  #            content=getText(self,par.childNodes,par.getAttribute('class'))
               #            
               #            
   #
             #print par.getAttribute('class'),node  #            #print par.getAttribute('class'),node
             try:  #            try:
                 html+=tag[0]+content+tag[1]  #                html+=tag[0]+content+tag[1]
             except:  #            except:
                 html=+tag[0]+content+tag[1]  #                html=+tag[0]+content+tag[1]
               #            
         elif tagName=="pb":  #        elif tagName=="pb":
             html+="<pb/>"  #            html+="<pb/>"
           #        
       #    
     try:  #    try:
   #
         return html  #        return html
     except:  #    except:
         return ""  #        return ""
   
 def getXlink(nodes):  def getXlink(nodes):
     """searches xlinks and gives them back as html"""      """searches xlinks and gives them back as html"""
Line 192  def link2html(self,str): Line 192  def link2html(self,str):
   
             str=re.sub("\&","&amp;",str)              str=re.sub("\&","&amp;",str)
             dom=xml.dom.minidom.parseString("<?xml version='1.0' encoding='utf-8'?><txt>"+utf8ify(str)+"</txt>")              dom=xml.dom.minidom.parseString("<?xml version='1.0' encoding='utf-8'?><txt>"+utf8ify(str)+"</txt>")
              
               
             links=dom.getElementsByTagName("link")              links=dom.getElementsByTagName("link")
                           
   
Line 200  def link2html(self,str): Line 202  def link2html(self,str):
                 ref=link.getAttribute("ref")                  ref=link.getAttribute("ref")
                 pn=link.getAttribute("page")                  pn=link.getAttribute("page")
                 mk=link.getAttribute("mk")                  mk=link.getAttribute("mk")
                   href= link.getAttribute("href")
                   if href:
                       link.setAttribute("class","external")
                                                   
                 if self.checkRef(ref):                  if self.checkRef(ref):
                     more = ""                      more = ""
Line 211  def link2html(self,str): Line 216  def link2html(self,str):
                                                   
                     link.setAttribute("href",self.REQUEST['SERVER_URL']+"/references?id="+ref+more)                      link.setAttribute("href",self.REQUEST['SERVER_URL']+"/references?id="+ref+more)
   
   
             newxml=dom.toxml('utf-8')              newxml=dom.toxml('utf-8')
                       
               
               
             retStr=regexpTXT.search(newxml)              retStr=regexpTXT.search(newxml)
             retStr = retStr.group(1)              retStr = retStr.group(1)
   
Line 232  def related2html(self,str): Line 240  def related2html(self,str):
             link.tagName = "a"              link.tagName = "a"
             ref = link.getAttribute("ref")              ref = link.getAttribute("ref")
             pn = link.getAttribute("page")              pn = link.getAttribute("page")
               obj = ref[0:3]
                                                   
               """erweiterung der related items von literatur auf weitere datenbankobjekte, mb 05.06.2009"""
               if obj == 'lit':            
             searchStr="select fullreference, online from vl_literature where reference =\'%s\' and authorized = 1"%(ref)              searchStr="select fullreference, online from vl_literature where reference =\'%s\' and authorized = 1"%(ref)
               elif obj == 'sit':
                   searchStr="select reference from vl_sites where reference =\'%s\' and complete = 'yes'"%(ref)
               elif obj == 'per':
                   searchStr="select reference from vl_people where reference =\'%s\' and complete = 'yes'"%(ref)
               elif obj == 'tec':
                   searchStr="select reference from vl_technology where reference =\'%s\' and complete = 'yes'"%(ref)
               elif obj == 'exp':
                   searchStr="select reference from vl_experiments where reference =\'%s\' and complete = 'yes'"%(ref)
                   
             res = self.search(var=searchStr)              res = self.search(var=searchStr)
                                                                                   
             if res:              if res:
                   if obj == 'lit':
                 if res[0]['online'] == 1:                   if res[0]['online'] == 1: 
                     # item online verfuegbar                          # literatur item online verfuegbar
                     if pn:                      if pn:
                         link.setAttribute("href",self.REQUEST['SERVER_URL']+"/references?id="+ref+"&page="+pn)                          link.setAttribute("href",self.REQUEST['SERVER_URL']+"/references?id="+ref+"&page="+pn)
                     else:                      else:
                         link.setAttribute("href",self.REQUEST['SERVER_URL']+"/references?id="+ref)                          link.setAttribute("href",self.REQUEST['SERVER_URL']+"/references?id="+ref)
                                                   
                     link.setAttribute("title", "click to view")                          link.setAttribute("title", "click to view!")
                     link.removeAttribute("ref")                      link.removeAttribute("ref")
                                           
                     # prefix preceding the link                      # prefix preceding the link
Line 252  def related2html(self,str): Line 273  def related2html(self,str):
                     dom.documentElement.insertBefore(prefix, link)                      dom.documentElement.insertBefore(prefix, link)
   
                 else:                  else:
                     # item nur als bibliographische angabe vorhanden                          # literatur item nur als bibliographische angabe vorhanden
                     link.setAttribute("alt", unicodify(res[0]['fullreference']))                      link.setAttribute("alt", unicodify(res[0]['fullreference']))
                     link.setAttribute("title", "click to expand")                      link.setAttribute("title", "click to expand")
                     link.setAttribute("onclick", "return toggle(this);")                      link.setAttribute("onclick", "return toggle(this);")
Line 260  def related2html(self,str): Line 281  def related2html(self,str):
                                           
                     # prefix inside link text                      # prefix inside link text
                     link.firstChild.data = '+ ' + link.firstChild.data                      link.firstChild.data = '+ ' + link.firstChild.data
                   else:
                       # links zu den anderen datenbankobjekten
                       link.setAttribute("href",self.REQUEST['SERVER_URL']+"/references?id="+ref)
                       link.setAttribute("title", "click to view")
                       link.removeAttribute("ref")
               
                       # prefix preceding the link
                       prefix = dom.createTextNode(U"\u2013\u0020") # = ndash + space
                       dom.documentElement.insertBefore(prefix, link)
               
               else:
                   # objekt nicht verfügbar/freigegeben oder (web)link mit href statt ref
                   
                   #if ref != '':
                   #    link.removeAttribute("ref")
                   #    link.setAttribute("title", ref)
                   
                   
                   # prefix preceding the link
                   prefix = dom.createTextNode(U"\u2013\u0020") # = ndash + space
                   dom.documentElement.insertBefore(prefix, link)
                                           
                           
         newxml=dom.toxml('utf-8')          newxml=dom.toxml('utf-8')

Removed from v.1.13  
changed lines
  Added in v.1.16


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>