--- ECHO_content/vlp_xmlhelpers.py 2006/11/21 18:37:12 1.9
+++ ECHO_content/vlp_xmlhelpers.py 2007/12/11 17:00:01 1.13
@@ -1,6 +1,7 @@
from sys import argv
import string
+import logging
import xml.dom.minidom
import Ft.Xml.XLink.Processor
import Ft.Xml.XLink.XLinkElements
@@ -15,6 +16,7 @@ from Ft.Xml import EMPTY_NAMESPACE
from Ft.Lib import Uri
import urllib
import re
+from ECHO_collection import unicodify,utf8ify
patternTXT=r"<\s*txt.*?>(.*?)"
regexpTXT = re.compile(patternTXT, re.IGNORECASE + re.DOTALL)
@@ -175,7 +177,8 @@ def checkRef(self,ref):
'vl_people':'AND complete =\'yes\'',
'vl_sites':'AND complete =\'yes\'',
'vl_transcript':'AND complete =\'yes\'',
- 'vl_essays':'AND online =\'yes\''
+ 'vl_essays':'AND online =\'yes\'',
+ 'vl_categories':''
}
res=None
for db in dbs.keys():
@@ -184,11 +187,11 @@ def checkRef(self,ref):
return res
def link2html(self,str):
- """link2html liks in html wandeln"""
+ """link2html links in html wandeln"""
if str:
str=re.sub("\&","&",str)
- dom=xml.dom.minidom.parseString(""+str+"")
+ dom=xml.dom.minidom.parseString(""+utf8ify(str)+"")
links=dom.getElementsByTagName("link")
@@ -196,29 +199,33 @@ def link2html(self,str):
link.tagName="a"
ref=link.getAttribute("ref")
pn=link.getAttribute("page")
+ mk=link.getAttribute("mk")
if self.checkRef(ref):
- if pn:
- link.setAttribute("href",self.REQUEST['SERVER_URL']+"/references?id="+ref+"&page="+pn)
- else:
- link.setAttribute("href",self.REQUEST['SERVER_URL']+"/references?id="+ref)
-
+ more = ""
+ if pn:
+ more += "&page=%s"%pn
+
+ if mk:
+ more += "&mk=%s"%mk
+
+ link.setAttribute("href",self.REQUEST['SERVER_URL']+"/references?id="+ref+more)
newxml=dom.toxml('utf-8')
retStr=regexpTXT.search(newxml)
+ retStr = retStr.group(1)
- return retStr.group(1)
+ return retStr.decode('utf-8') # we return unicode
-
- return ""
+ return u""
def related2html(self,str):
- """related library items: xlinks in html wandeln / mb 21.11.2006"""
+ """related library items: xlinks in html wandeln / mb 22.11.2006"""
if str:
str=re.sub("\&","&",str)
- dom=xml.dom.minidom.parseString(""+str+"")
+ dom=xml.dom.minidom.parseString(""+utf8ify(str)+"")
links=dom.getElementsByTagName("link")
for link in links:
@@ -232,25 +239,37 @@ def related2html(self,str):
if res:
if res[0]['online'] == 1:
# item online verfuegbar
- link.setAttribute("title", "click to view")
if pn:
link.setAttribute("href",self.REQUEST['SERVER_URL']+"/references?id="+ref+"&page="+pn)
else:
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:
# item nur als bibliographische angabe vorhanden
- link.setAttribute("alt", res[0]['fullreference'].decode('utf-8'))
+ link.setAttribute("alt", unicodify(res[0]['fullreference']))
link.setAttribute("title", "click to expand")
link.setAttribute("onclick", "return toggle(this);")
link.setAttribute("class", "x_offline")
+
+ # prefix inside link text
+ link.firstChild.data = '+ ' + link.firstChild.data
+
newxml=dom.toxml('utf-8')
retStr=regexpTXT.search(newxml)
-
- return retStr.group(1)
-
- return ""
+ retStr = retStr.group(1)
+ #logging.debug("related2html out=%s"%repr(retStr))
+ return retStr.decode('utf-8') # we return unicode
+
+ return u""
@@ -297,7 +316,7 @@ def xml2html(self,str,quote="yes"):
retStr=regexpPage.search(str)
try: # hack warum fehtl manchmal page??
- return retStr.group(1)
+ return retStr.group(1).decode('utf-8')
except:
return str
return ""