'
- tag += ''
- return tag
+ if float(rot) < 0:
+ marksrc = circlesrc
+ if bt.isIEWin and bt.versIE > 5:
+ # IE/Win 5.5 has "feature" for PNG transparency
+ tag += ''%(id,marksrc,rot,marksrc,rot)
+ else:
+ # arrow image
+ tag += ''%(id,marksrc,rot)
+ elif ob.isTypeText():
+ # DOM - Text
+ tag += '
'
+ tag += ob.getText()
+ tag += '
'
+ else:
+ # DOM - Area
+ if bt.isIE:
+ # IE needs transparent img for area
+ tag += '"
+ else:
+ # empty div for area
+ tag += '
'
+ tag += ''
+ return tag
#ende der echo erweiterungen
@@ -316,10 +465,9 @@ def toList(field):
return field
def getText(nodelist):
-
rc = ""
for node in nodelist:
- if node.nodeType == node.TEXT_NODE:
+ if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
@@ -327,281 +475,302 @@ def getTextFromNode(nodename):
nodelist=nodename.childNodes
rc = ""
for node in nodelist:
- if node.nodeType == node.TEXT_NODE:
+ if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
def readFieldFromXML(meta_url,parent,field):
- """lesespezifisches metadatum"""
-
- try:
- dom=xml.dom.minidom.parse(meta_url)
-
- except:
- try:
- fh=urllib.urlopen(meta_url)
- dom=xml.dom.minidom.parse(fh)
- except:
- return None
- if not dom: return None
-
- parent=dom.getElementsByTagName(parent)
- if not parent: return None
-
- field=parent[0].getElementsByTagName(field)
-
- if not field: return None
-
- return getText(field[0].childNodes)
-
-
-
+ """lesespezifisches metadatum"""
+
+ try:
+ dom=xml.dom.minidom.parse(meta_url)
+
+ except:
+ try:
+ fh=urllib.urlopen(meta_url)
+ dom=xml.dom.minidom.parse(fh)
+ except:
+ return None
+ if not dom: return None
+
+ parent=dom.getElementsByTagName(parent)
+ if not parent: return None
+
+ field=parent[0].getElementsByTagName(field)
+
+ if not field: return None
+
+ return getText(field[0].childNodes)
+
+
+
def urlopen(url):
- """urlopen mit timeout"""
- socket.setdefaulttimeout(2)
- ret=urllib.urlopen(url)
- socket.setdefaulttimeout(5)
- return ret
-# urlopener = urllib.URLopener()
+ """urlopen mit timeout"""
+ socket.setdefaulttimeout(2)
+ ret=urllib.urlopen(url)
+ socket.setdefaulttimeout(5)
+ return ret
+# urlopener = urllib.URLopener()
#
-# try:
-# con = urlopener.open(url)
-# return con
-# except timeoutsocket.Timeout:
-# return None
+# try:
+# con = urlopener.open(url)
+# return con
+# except timeoutsocket.Timeout:
+# return None
def checkOnlyOneInGroup(object):
- """check if object is a group and if it containt only one element it return this element"""
- displayedObjects=object.ZopeFind(object,obj_metatypes=displayTypes)
- if len(displayedObjects)==1: # nur ein Object dann redirect auf dieses Object
-
- return displayedObjects[0][1]
- else: return object
-
-def getSubCols(self, sortfield="weight", subColTypes=displayTypes, sortFieldMD=None):
-
- def sortfnc(sortfield,x,y):
- xa=x[1].getMDValue(sortfield)
- ya=y[1].getMDValue(sortfield)
- print xa,ya
- return cmp(xa,ya)
-
- sortWithMD = lambda sortfield : (lambda x,y : sortfnc(sortfield,x,y))
+ """check if object is a group and if it containt only one element it return this element"""
+ displayedObjects=object.ZopeFind(object,obj_metatypes=displayTypes)
+ if len(displayedObjects)==1: # nur ein Object dann redirect auf dieses Object
+
+ return displayedObjects[0][1]
+ else: return object
+
+def getSubCols(self, sortfield=None, subColTypes=displayTypes, sortFieldMD=None,searchMD=None):
+
+
+ def sort(x,y):
+ return cmp(x[0],y[0])
+
+ def sortfnc(sortfield,x,y):
+ try:
+ xa=x[1].getMDValue(sortfield)
+ except:
+ xa=""
+ try:
+ ya=y[1].getMDValue(sortfield)
+ except:
+ ya=""
+ return cmp(xa,ya)
+
+ sortWithMD = lambda sortfield : (lambda x,y : sortfnc(sortfield,x,y))
ids=[]
- displayedObjects=self.ZopeFind(self,obj_metatypes=subColTypes)
-
-
- for entry in displayedObjects:
-
- object=entry[1]
- ids.append(object)
+ displayedObjects=self.ZopeFind(self,obj_metatypes=subColTypes)
+
+
+ for entry in displayedObjects:
+
+
+ object=entry[1]
+ if searchMD and hasattr(object,'getMDValue'):
+ flag=0
+ for field in searchMD.keys():
+ if object.getMDValue(field)==searchMD[field]:
+ flag=1
+ else:
+ flag=0
+ break
+ if flag==1:
+ ids.append(object)
+ else:
+ ids.append(object)
+
+ if not sortfield:
+ sortfield=getattr(self,'sortfield','weight')
- try:
- sortfield=self.sortfield
- except:
- """nothing"""
tmplist=[]
- for x in ids:
- if hasattr(x,sortfield):
- try:
- x=int(x)
- except:
- """nothing"""
- tmp=getattr(x,sortfield)
- else:
- tmp=10000000
- tmplist.append((tmp,x))
+ for x in ids:
+
+ if hasattr(x,sortfield):
+ try:
+ tmp=int(getattr(x,sortfield))
+ except:
+ tmp=getattr(x,sortfield)
+
+ else:
+ tmp=10000000
+
+ tmplist.append((tmp,x))
- if not sortFieldMD:
- tmplist.sort()
- else:
- tmplist.sort(sortWithMD(sortFieldMD))
-
+ if not sortFieldMD:
+ tmplist.sort(sort)
+ else:
+ tmplist.sort(sortWithMD(sortFieldMD))
+
return [x for (key,x) in tmplist]
def ECHO_rerenderLinksMD(self,obj=None,types=['title','label']):
"""Rerender all Links"""
- ret=""
-
+ ret=""
+
if not obj:
obj = self
entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource'],search_sub=1)
for entry in entries:
- if entry[1].meta_type == 'ECHO_resource':
- try:
- entry[1].ECHO_getResourceMD(template="no")
+ if entry[1].meta_type == 'ECHO_resource':
+ try:
+ entry[1].ECHO_getResourceMD(template="no")
if "title" in types:
entry[1].generate_title()
if "label" in types:
entry[1].generate_label()
- ret+="OK:"+entry[0]+"-- "+entry[1].getTitle().decode('utf-8')+"-- "+entry[1].getTitle().decode('utf-8')+" "
- except:
- ret+="Error:"+entry[0]+" "
+ ret+="OK:"+entry[0]+"-- "+entry[1].getTitle().decode('utf-8')+"-- "+entry[1].getTitle().decode('utf-8')+" "
+ except:
+ ret+="Error:"+entry[0]+" "
-
+
return ""+ret+"Rerenderd all links to resources in: "+self.title+""
def reloadMetaDataFromStorage(self,RESPONSE=None):
- """copy metadata from the storage to ECHO"""
- ret=""
- resources=self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1)
-
- for resource in resources:
- x=str(resource[1].copyIndex_meta2echo_resource())+" "
- ret+=x
- #print x
-
-
- if RESPONSE is not None:
- #RESPONSE.redirect('./manage_main')
- return ""+ret+""
+ """copy metadata from the storage to ECHO"""
+ ret=""
+ resources=self.ZopeFind(self,obj_metatypes=['ECHO_resource'],search_sub=1)
+
+ for resource in resources:
+ x=str(resource[1].copyIndex_meta2echo_resource())+" "
+ ret+=x
+
+ if RESPONSE is not None:
+ #RESPONSE.redirect('./manage_main')
+ return ""+ret+""
- return ret
+ return ret
def getRDFDescription(self,linkURL,urn=None,nameDef=None,typeName=None):
- """rdf"""
-
- ret=""
- about=""""""
- name="""%s"""
- link="""%s"""
- clickable="""%s"""
- #link=""""""
- type="""%s"""
- #xlink=""""""
- if not urn:
- #urn="urn:"+re.sub('/',':',self.absolute_url())
- urn=self.absolute_url()
- about2=about%urn
- if not nameDef:
- if hasattr(self,'label') and not (self.label==""):
- name2=name%self.label
- elif not self.title=="":
- name2=name%self.title
- else:
- name2=name%self.getId()
-
- name2=re.sub('&','&',name2)
- else:
- name2=name%nameDef
-
- linkURL=re.sub('http:','',linkURL)
- linkURL2=re.sub('&','&',linkURL)
- link2=link%(("http:"+linkURL2),("http:"+urllib.quote(linkURL)))
- clickable2=clickable%"true"
-
- if not typeName:
- type2=type%self.meta_type
- else:
- type2=type%typeName
-
- #ret=about2+"\n"+name2+"\n"+link2+"\n"+type2+"\n"+clickable2+"\n"
- ret=about2+"\n"+name2+"\n"+type2+"\n"+clickable2+"\n"
- return ret
+ """rdf"""
+
+ ret=""
+ about=""""""
+ name="""%s"""
+ link="""%s"""
+ clickable="""%s"""
+ #link=""""""
+ type="""%s"""
+ #xlink=""""""
+ if not urn:
+ #urn="urn:"+re.sub('/',':',self.absolute_url())
+ urn=self.absolute_url()
+ about2=about%urn
+ if not nameDef:
+ if hasattr(self,'label') and not (self.label==""):
+ name2=name%self.label
+ elif not self.title=="":
+ name2=name%self.title
+ else:
+ name2=name%self.getId()
+
+ name2=re.sub('&','&',name2)
+ else:
+ name2=name%nameDef
+
+ linkURL=re.sub('http:','',linkURL)
+ linkURL2=re.sub('&','&',linkURL)
+ link2=link%(("http:"+linkURL2),("http:"+urllib.quote(linkURL)))
+ clickable2=clickable%"true"
+
+ if not typeName:
+ type2=type%self.meta_type
+ else:
+ type2=type%typeName
+
+ #ret=about2+"\n"+name2+"\n"+link2+"\n"+type2+"\n"+clickable2+"\n"
+ ret=about2+"\n"+name2+"\n"+type2+"\n"+clickable2+"\n"
+ return ret
def getCopyrightsFromForm(self,argv):
- medias={}
- partners={}
- copyrights={}
-
- copyrightsFinal=[]
- for arg in argv.keys():
-
- if arg[0:5]=='media':
- nm=int(arg[5:])
- medias[nm]=argv[arg]
- elif arg[0:5]=='partn':
- nm=int(arg[5:])
- partners[nm]=argv[arg]
- elif arg[0:5]=='copyr':
- nm=int(arg[5:])
- copyrights[nm]=argv[arg]
+ medias={}
+ partners={}
+ copyrights={}
+
+ copyrightsFinal=[]
+ for arg in argv.keys():
+
+ if arg[0:5]=='media':
+ nm=int(arg[5:])
+ medias[nm]=argv[arg]
+ elif arg[0:5]=='partn':
+ nm=int(arg[5:])
+ partners[nm]=argv[arg]
+ elif arg[0:5]=='copyr':
+ nm=int(arg[5:])
+ copyrights[nm]=argv[arg]
- copyrightsList=[(medias[nm],partners[nm],copyrights[nm]) for nm in medias.keys()]
- for copyright in copyrightsList:
-
- if copyright[2]=='institution0000':
- copyrightsFinal.append((copyright[0],copyright[1],self.getPartnerCopyright(copyright[1],'')))
- else:
- if not copyright[0]=='':
- copyrightsFinal.append(copyright)
-
-
- return copyrightsFinal
+ copyrightsList=[(medias[nm],partners[nm],copyrights[nm]) for nm in medias.keys()]
+ for copyright in copyrightsList:
+
+ if copyright[2]=='institution0000':
+ copyrightsFinal.append((copyright[0],copyright[1],self.getPartnerCopyright(copyright[1],'')))
+ else:
+ if not copyright[0]=='':
+ copyrightsFinal.append(copyright)
+
+
+ return copyrightsFinal
#List of different types for the graphical linking viewer
viewClassificationListMaster=['view point','area']
def checkDiffs(self,metadict):
- """check differences"""
+ """check differences"""
+
+
-
+
+ def NoneToEmpty(obj):
+ if obj:
+ return obj
+ else:
+ return ""
+
+
+ diffs={}
+
+ tags=self.findTagsFromMapping(self.contentType)
+ self.referencetypes=tags[2]
+ self.fields=tags[3]
+
- def NoneToEmpty(obj):
- if obj:
- return obj
- else:
- return ""
-
-
-
- diffs={}
-
- tags=self.findTagsFromMapping(self.contentType)
- self.referencetypes=tags[2]
- self.fields=tags[3]
-
-
- for field in tags[1]:
- try:
- if (NoneToEmpty(self.getFieldValue(self.getFieldTag(tags,field)))==metadict[self.getFieldTag(tags,field)]):
- diffs[self.getFieldTag(tags,field)]=1
- else:
-
- diffs[self.getFieldTag(tags,field)]=0
- except:
- diffs[self.getFieldTag(tags,field)]=0
-
- return diffs
+ for field in tags[1]:
+ try:
+ if (NoneToEmpty(self.getFieldValue(self.getFieldTag(tags,field)))==metadict[self.getFieldTag(tags,field)]):
+ diffs[self.getFieldTag(tags,field)]=1
+ else:
+
+ diffs[self.getFieldTag(tags,field)]=0
+ except:
+ diffs[self.getFieldTag(tags,field)]=0
+
+ return diffs
def zptFile(self, path, orphaned=False):
"""returns a page template file from the product"""
if orphaned:
- # unusual case
- pt=PageTemplateFile(os.path.join(package_home(globals()), path))
+ # unusual case
+ pt=PageTemplateFile(os.path.join(package_home(globals()), path))
else:
- pt=PageTemplateFile(os.path.join(package_home(globals()), path)).__of__(self)
+ pt=PageTemplateFile(os.path.join(package_home(globals()), path)).__of__(self)
return pt
def findObjectPath(startobject, filename):
"""returns the object with the name filename starting at startobject"""
if startobject is None:
- return None
+ return None
paths = filename.split('/')
object = startobject
for path in paths:
+
if hasattr(object, path):
- object = getattr(object, path)
- else:
- object = None
- break
+ object = getattr(object, path)
+ else:
+ object = None
+ break
return object
@@ -611,8 +780,8 @@ def zptObjectOrFile(self, filename, loca
pt = findObjectPath(self, filename)
# the object should also not be a python function
if (pt is None) or isinstance(pt, types.FunctionType):
- # get a ZPT file
- pt = zptFile(self, localdir+'/'+filename, orphaned=orphaned)
+ # get a ZPT file
+ pt = zptFile(self, localdir+'/'+filename, orphaned=orphaned)
return pt
@@ -621,13 +790,13 @@ def sendFile(self, filename, type):
# look for an object called filename
object = findObjectPath(self, filename)
if object:
- # if the object exists then send it
- return object.index_html(self.REQUEST.REQUEST, self.REQUEST.RESPONSE)
+ # if the object exists then send it
+ return object.index_html(self.REQUEST.REQUEST, self.REQUEST.RESPONSE)
else:
- # send a local file with the given content-type
- fn = os.path.join(package_home(globals()), filename)
- self.REQUEST.RESPONSE.setHeader("Content-Type", type)
- self.REQUEST.RESPONSE.write(file(fn).read())
+ # send a local file with the given content-type
+ fn = os.path.join(package_home(globals()), filename)
+ self.REQUEST.RESPONSE.setHeader("Content-Type", type)
+ self.REQUEST.RESPONSE.write(file(fn).read())
return
@@ -636,135 +805,135 @@ class BrowserCheck:
def __init__(self, zope):
"""initialisiere"""
- self.ua = zope.REQUEST.get_header("HTTP_USER_AGENT")
- self.isN4 = False
- self.isIE = False
- if string.find(self.ua, 'MSIE') > -1:
- self.isIE = True
- else:
- self.isN4 = string.find(self.ua, 'Mozilla/4.') > -1
- try:
- self.nav = self.ua[string.find(self.ua, '('):]
- ie = string.split(self.nav, "; ")[1]
- if string.find(ie, "MSIE") > -1:
- self.versIE = string.split(ie, " ")[1]
- except: pass
- self.isMac = string.find(self.ua, 'Macintosh') > -1
- self.isWin = string.find(self.ua, 'Windows') > -1
- self.isIEWin = self.isIE and self.isWin
- self.isIEMac = self.isIE and self.isMac
+ self.ua = zope.REQUEST.get_header("HTTP_USER_AGENT")
+ self.isN4 = False
+ self.isIE = False
+ if string.find(self.ua, 'MSIE') > -1:
+ self.isIE = True
+ else:
+ self.isN4 = string.find(self.ua, 'Mozilla/4.') > -1
+ try:
+ self.nav = self.ua[string.find(self.ua, '('):]
+ ie = string.split(self.nav, "; ")[1]
+ if string.find(ie, "MSIE") > -1:
+ self.versIE = string.split(ie, " ")[1]
+ except: pass
+ self.isMac = string.find(self.ua, 'Macintosh') > -1
+ self.isWin = string.find(self.ua, 'Windows') > -1
+ self.isIEWin = self.isIE and self.isWin
+ self.isIEMac = self.isIE and self.isMac
-
+
def writeMetadata(url,metadict,project=None,startpage=None,xslt=None,thumbtemplate=None,topbar=None,digiLibTemplate=None,xmlfrag=None,digiliburlprefix=None):
- """Einlesen der Metadaten und und erstellen des geaenderten XML file"""
+ """Einlesen der Metadaten und und erstellen des geaenderten XML file"""
+
+ def updateTextToolNode(tag,value):
- def updateTextToolNode(tag,value):
- #print dom,tag,value
- metanode=dom.getElementsByTagName('texttool')[0]
- try:
- nodeOld=metanode.getElementsByTagName(tag)
- except:
- nodeOld=None
-
- if nodeOld:
- metanode.removeChild(nodeOld[0]).unlink()
-
- node=dom.createElement(tag)
- nodetext=dom.createTextNode(value)
- node.appendChild(nodetext)
- metanode.appendChild(node)
+ metanode=dom.getElementsByTagName('texttool')[0]
+ try:
+ nodeOld=metanode.getElementsByTagName(tag)
+ except:
+ nodeOld=None
+
+ if nodeOld:
+ metanode.removeChild(nodeOld[0]).unlink()
+
+ node=dom.createElement(tag)
+ nodetext=dom.createTextNode(value)
+ node.appendChild(nodetext)
+ metanode.appendChild(node)
- if xmlfrag:
- geturl="""
+ if xmlfrag:
+ geturl="""
-
-
-
-
- """
- dom=xml.dom.minidom.parseString(geturl)
- else:
- try:
- geturl=""
- for line in urlopen(url).readlines():
- geturl=geturl+line
-
-
- except:
- return (None,"XCannot open: "+url)
-
- try:
- dom=xml.dom.minidom.parseString(geturl)
- except:
- return (None,"Cannot parse: "+url+" "+geturl)
-
-
-
- metanodes=dom.getElementsByTagName('bib')
-
- if not metanodes:
- metanodes=dom.getElementsByTagName('archimedes')
-
- metanode=metanodes[0]
-
- for metaData in metadict.keys():
-
- try:
- nodeOld=metanode.getElementsByTagName(metaData)
- except:
- nodeOld=None
-
- if nodeOld:
- metanode.removeChild(nodeOld[0]).unlink()
- else:
- # try also old writing rule - instead of _:
- try:
- nodeOld=metanode.getElementsByTagName(re.sub('_','-',metaData))
- except:
- nodeOld=None
-
- if nodeOld:
- metanode.removeChild(nodeOld[0]).unlink()
+
+
+
+
+ """
+ dom=xml.dom.minidom.parseString(geturl)
+ else:
+ try:
+ geturl=""
+ for line in urlopen(url).readlines():
+ geturl=geturl+line
+
- metanodeneu=dom.createElement(metaData)
+ except:
+ return (None,"XCannot open: "+url)
+
+ try:
+ dom=xml.dom.minidom.parseString(geturl)
+ except:
+ return (None,"Cannot parse: "+url+" "+geturl)
+
+
+
+ metanodes=dom.getElementsByTagName('bib')
+
+ if not metanodes:
+ metanodes=dom.getElementsByTagName('archimedes')
+
+ metanode=metanodes[0]
+
+ for metaData in metadict.keys():
+
+ try:
+ nodeOld=metanode.getElementsByTagName(metaData)
+ except:
+ nodeOld=None
+
+ if nodeOld:
+ metanode.removeChild(nodeOld[0]).unlink()
+ else:
+ # try also old writing rule - instead of _:
+ try:
+ nodeOld=metanode.getElementsByTagName(re.sub('_','-',metaData))
+ except:
+ nodeOld=None
+
+ if nodeOld:
+ metanode.removeChild(nodeOld[0]).unlink()
+
+ metanodeneu=dom.createElement(metaData)
metanodetext=dom.createTextNode(metadict[metaData])
- #try:
- #metanodetext=dom.createTextNode(unicode(metadict[metaData],"utf-8"))
- #except:
- #metanodetext=dom.createTextNode(metadict[metaData].encode('utf-8'))
- metanodeneu.appendChild(metanodetext)
- metanode.appendChild(metanodeneu)
-
-
-
-
-
- if project:
- updateTextToolNode('project',project)
-
- if startpage:
- updateTextToolNode('startpage',startpage)
-
- if topbar:
- updateTextToolNode('toptemplate',topbar)
-
- if thumbtemplate:
- updateTextToolNode('thumbtemplate',thumbtemplate)
-
- if xslt:
- updateTextToolNode('xslt',xslt)
-
-
- if digiliburlprefix:
- updateTextToolNode('digiliburlprefix',digiliburlprefix)
-
- try:
- return dom.toxml().encode('utf-8')
- except:
- return dom.toxml('utf-8')
+ #try:
+ #metanodetext=dom.createTextNode(unicode(metadict[metaData],"utf-8"))
+ #except:
+ #metanodetext=dom.createTextNode(metadict[metaData].encode('utf-8'))
+ metanodeneu.appendChild(metanodetext)
+ metanode.appendChild(metanodeneu)
+
+
+
+
+
+ if project:
+ updateTextToolNode('project',project)
+
+ if startpage:
+ updateTextToolNode('startpage',startpage)
+
+ if topbar:
+ updateTextToolNode('toptemplate',topbar)
+
+ if thumbtemplate:
+ updateTextToolNode('thumbtemplate',thumbtemplate)
+
+ if xslt:
+ updateTextToolNode('xslt',xslt)
+
+
+ if digiliburlprefix:
+ updateTextToolNode('digiliburlprefix',digiliburlprefix)
+
+ try:
+ return dom.toxml().encode('utf-8')
+ except:
+ return dom.toxml('utf-8')
-
-
+
+
def readMetadata(url):
"""Methode zum Auslesen der Metadateninformation zu einer Resource
Vorerst noch Typ bib"""
@@ -783,7 +952,7 @@ def readMetadata(url):
try:
dom=xml.dom.minidom.parseString(geturl)
except:
- return (None,"Cannot parse: "+url+" "+geturl)
+ return (None,"Cannot parse: "+url+" "+geturl)
metanode=dom.getElementsByTagName('bib')
metadict['bib_type']='Book'
@@ -801,11 +970,13 @@ def readMetadata(url):
"""nothing"""
for node in metacontent:
- try:
- #print urllib.unquote(getText(node.childNodes)),getText(node.childNodes)
- metadict[re.sub('-','_',node.tagName.lower())]=urllib.unquote(getText(node.childNodes))
- except:
- """nothing"""
+ try:
+ #print urllib.unquote(getText(node.childNodes)),getText(node.childNodes)
+ #metadict[re.sub('-','_',node.tagName.lower())]=urllib.unquote(getText(node.childNodes))
+ metadict[re.sub('-','_',node.tagName.lower())]=getText(node.childNodes)
+
+ except:
+ """nothing"""
return metadict,""
@@ -821,101 +992,225 @@ class MapArea(SimpleItem):
# type constants
TYPE_AREA = 'area'
TYPE_ARROW = 'arrow'
-
- def __init__(self, id, coords, label=None, type=None, text=None):
- """init"""
- self.coords = coords[0:4]
- if len(coords) > 4:
- self.angle = coords[4]
- else:
- self.angle = 0
- self.id = id
- self.label = label
- self.setType(type)
- self.text = text
+ TYPE_TEXT = 'text'
+
+ def __init__(self, id, coords, label=None, type=None, tip=None, permanent=False):
+ """init"""
+ self.coords = coords[0:4]
+ if len(coords) > 4:
+ self.angle = coords[4]
+ else:
+ self.angle = 0
+ self.id = id
+ self.label = label
+ self.setType(type)
+ self.tip = tip
+ self.permanent = permanent
def setCoords(self, coords):
- """sets the coords"""
- self.coords = coords
+ """sets the coords"""
+ self.coords = coords
def getCoordString(self):
- """returns coordinates as a string"""
- return string.join(self.coords, ',')
+ """returns coordinates as a string"""
+ return string.join(self.coords, ',')
def setCoordString(self, coordstring):
- """sets coordinates from a string"""
- coords = string.split(coordstring, ',')
- self.coords = [c.strip() for c in coords]
+ """sets coordinates from a string"""
+ coords = string.split(coordstring, ',')
+ self.coords = [c.strip() for c in coords]
def getFullId(self, prefix=None):
- """returns the id with prefixed parent id"""
- if prefix is None:
- if hasattr(self, 'aq_parent'):
- prefix = self.aq_parent.id
- else:
- prefix = "id"
- fid = prefix + "." + self.id
- return fid
+ """returns the id with prefixed parent id"""
+ if prefix is None:
+ if hasattr(self, 'aq_parent'):
+ prefix = self.aq_parent.id
+ else:
+ prefix = "id"
+ fid = prefix + "." + self.id
+ return fid
def getType(self):
- """returns the type"""
- return self.type
+ """returns the type"""
+ return self.type
def setType(self, type):
- """sets the type"""
- if type == MapArea.TYPE_ARROW:
- self.type = MapArea.TYPE_ARROW
- elif type == MapArea.TYPE_AREA:
- self.type = MapArea.TYPE_AREA
- else:
- self.type = MapArea.TYPE_AREA
-
+ """sets the type"""
+ if type == MapArea.TYPE_ARROW:
+ self.type = MapArea.TYPE_ARROW
+ elif type == MapArea.TYPE_AREA:
+ self.type = MapArea.TYPE_AREA
+ elif type == MapArea.TYPE_TEXT:
+ self.type = MapArea.TYPE_TEXT
+ else:
+ self.type = MapArea.TYPE_AREA
+
def isTypeArea(self):
- """returns if the type is area"""
- return self.type == MapArea.TYPE_AREA
+ """returns if the type is area"""
+ return self.type == MapArea.TYPE_AREA
def isTypeArrow(self):
- """returns if the type is arrow"""
- return self.type == MapArea.TYPE_ARROW
+ """returns if the type is arrow"""
+ return self.type == MapArea.TYPE_ARROW
+
+ def isTypeText(self):
+ """returns if the type is text"""
+ return self.type == MapArea.TYPE_TEXT
def getAngle(self):
- """returns the angle"""
- return self.angle
+ """returns the angle"""
+ return self.angle
def setAngle(self, angle):
- """sets the angle"""
- self.angle = angle
+ """sets the angle"""
+ self.angle = angle
+
+ def getTip(self):
+ """returns the popup text"""
+ # patch old version
+ if not hasattr(self, 'tip'):
+ self.tip = self.text
+
+ if self.tip is None:
+ if hasattr(self, 'aq_parent'):
+ parent = self.aq_parent
+ if parent.contentType == 'text-popup':
+ return parent.description
+ return self.tip
+
+ def setTip(self, text):
+ """sets the text"""
+ self.tiptext = text
def getText(self):
- """returns the popup text"""
- if self.text is None:
- if hasattr(self, 'aq_parent'):
- parent = self.aq_parent
- if parent.contentType == 'text-popup':
- return parent.description
- return self.text
-
- def setText(self, text):
- """sets the text"""
- self.text = text
+ """returns the text fpr the area"""
+ if hasattr(self, 'aq_parent'):
+ parent = self.aq_parent
+ text = parent.getMapText()
+ if text is not None:
+ return text.document_src()
+ return ""
def getLabel(self):
- """returns the link label"""
- if self.label is None:
- if hasattr(self, 'aq_parent'):
- return self.aq_parent.label or self.aq_parent.id
- return self.label
+ """returns the link label"""
+ if self.label is None:
+ if hasattr(self, 'aq_parent'):
+ return self.aq_parent.label or self.aq_parent.id
+ return self.label
def setLabel(self, label):
- """sets the label"""
- self.label = label
+ """sets the label"""
+ self.label = label
- def getLinkId(self):
- if hasattr(self, 'aq_parent'):
- return self.aq_parent.id
- return self.id
+ def isPermanent(self):
+ """returns the permanent state"""
+ # patch old objects
+ if not hasattr(self, 'permanent'):
+ self.permanent = False
+ return self.permanent
+
+ def setPermanent(self, state):
+ """sets the permanent state"""
+ if state:
+ self.permanent = True
+ else:
+ self.permanent = False
+ def getLinkId(self):
+ if hasattr(self, 'aq_parent'):
+ return self.aq_parent.id
+ return self.id
# call this to initialize framework classes, which
# does the right thing with the security assertions.
Globals.InitializeClass(MapArea)
+
+
+class MapText(Folder,ZopePageTemplate):
+ """class to hold text for map areas"""
+
+ meta_type = 'ECHO_mapText'
+ # Create a SecurityInfo for this class.
+ security = ClassSecurityInfo()
+ security.setDefaultAccess("allow")
+
+
+ _default_content_fn = os.path.join(package_home(globals()),
+ 'html', 'ECHO_mapText_default.html')
+
+ def __init__(self, id, text=None, content_type=None):
+ self.id = str(id)
+ self.ZBindings_edit(self._default_bindings)
+ if text is None:
+ text = open(self._default_content_fn).read()
+ self.pt_edit(text, content_type)
+
+ def createLocale(self):
+ """create locale"""
+ return ECHO_collection.manage_addECHO_localeForm(self)
+
+ manage_main=ZopePageTemplate.pt_editForm
+
+ def manage_addECHO_locale(self,lang,title,label,text=None,content_type=None,RESPONSE=None):
+ """manage add echo locale in map"""
+ ECHO_collection.manage_addECHO_locale(self,lang,title,label,text,content_type)
+ if RESPONSE is not None:
+ RESPONSE.redirect('manage_main')
+
+
+ def changeLocale(self):
+ """change locale"""
+ return self.locale_en.change_ECHO_localeForm()
+
+ def change_ECHO_locale(self,lang,title,label,text=None,content_type=None,RESPONSE=None):
+ """change echo locale"""
+
+ obj= self.locale_en.change_ECHO_locale(lang,title,label,text,content_type,RESPONSE)
+
+
+
+ if RESPONSE is not None:
+ RESPONSE.redirect('manage_main')
+
+
+# Product registration and Add support
+manage_addMapTextForm = PageTemplateFile(
+ 'zpt/AddECHO_mapText', globals(), __name__='manage_addMapTextForm')
+
+def manage_addMapText(self, id, title=None, text=None,
+ REQUEST=None, submit=None):
+ "Add a Map Text with optional file content."
+
+ id = str(id)
+ if REQUEST is None:
+ self._setObject(id, MapText(id, text))
+ ob = getattr(self, id)
+ if title:
+ ob.pt_setTitle(title)
+ return ob
+ else:
+ file = REQUEST.form.get('file')
+ headers = getattr(file, 'headers', None)
+ if headers is None or not file.filename:
+ zpt = MapText(id, text)
+ else:
+ zpt = MapText(id, file, headers.get('content_type'))
+
+ self._setObject(id, zpt)
+ if title:
+ ob = getattr(self, id)
+ ob.pt_setTitle(title)
+
+ try:
+ u = self.DestinationURL()
+ except AttributeError:
+ u = REQUEST['URL1']
+
+ if submit == " Add and Edit ":
+ u = "%s/%s" % (u, urllib.quote(id))
+ REQUEST.RESPONSE.redirect(u+'/manage_main')
+ return ''
+
+# call this to initialize framework classes, which
+# does the right thing with the security assertions.
+Globals.InitializeClass(MapText)