version 1.28, 2004/11/29 17:18:13
|
version 1.37, 2005/01/31 11:15:50
|
Line 1
|
Line 1
|
|
import re |
import string |
import string |
import socket |
import socket |
import urllib |
import urllib |
|
import string |
import xml.dom.minidom |
import xml.dom.minidom |
from types import * |
import types |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
|
from OFS.SimpleItem import SimpleItem |
from Globals import package_home |
from Globals import package_home |
|
import Globals |
|
from AccessControl import ClassSecurityInfo |
import os.path |
import os.path |
|
|
displayTypes = ['ZSQLExtendFolder','ZSQLBibliography','ECHO_group','ECHO_collection','ECHO_resource','ECHO_link','ECHO_sqlElement','ECHO_pageTemplate','ECHO_externalLink','ImageCollectionIFrame','VLP_resource','VLP_essay','ECHO_ZCatalogElement','ImageCollection','versionedFileFolder'] |
displayTypes = ['ZSQLExtendFolder','ZSQLBibliography','ECHO_group','ECHO_collection','ECHO_resource','ECHO_link','ECHO_sqlElement','ECHO_pageTemplate','ECHO_externalLink','ImageCollectionIFrame','VLP_resource','VLP_essay','ECHO_ZCatalogElement','ImageCollection','versionedFileFolder'] |
Line 32 class ECHO_basis:
|
Line 37 class ECHO_basis:
|
"""showrdf""" |
"""showrdf""" |
self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') |
self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') |
ret="""<?xml version="1.0" encoding="utf-8"?>\n<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ECHONAVIGATION="http://www.echo.eu/rdf#">\n""" |
ret="""<?xml version="1.0" encoding="utf-8"?>\n<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ECHONAVIGATION="http://www.echo.eu/rdf#">\n""" |
ret+=self.getRDF(urn="echo:colllectionroot")+"\n" |
|
|
ret+=self.getRDF(urn="echo:collectionroot")+"\n" |
|
|
|
|
ret+="""</RDF:RDF>""" |
ret+="""</RDF:RDF>""" |
return ret |
return ret |
Line 90 class ECHO_basis:
|
Line 97 class ECHO_basis:
|
|
|
def getTitle(self): |
def getTitle(self): |
"""title""" |
"""title""" |
|
return self.decode(self.title) |
try: |
try: |
return self.title.encode('utf-8','ignore') |
return self.title.encode('utf-8','ignore') |
except: |
except: |
Line 98 class ECHO_basis:
|
Line 106 class ECHO_basis:
|
|
|
def getLabel(self): |
def getLabel(self): |
"""title""" |
"""title""" |
|
|
|
return self.decode(self.label) |
try: |
try: |
return self.label.encode('utf-8','ignore') |
return self.label.encode('utf-8','ignore') |
except: |
except: |
Line 123 class ECHO_basis:
|
Line 133 class ECHO_basis:
|
|
|
manage_options=({'label':'change ECHO Navigation Entries','action':'changeECHOEntriesForm'},) |
manage_options=({'label':'change ECHO Navigation Entries','action':'changeECHOEntriesForm'},) |
|
|
|
|
|
def hasOverview(self): |
|
"""returns if there is an overview graphics""" |
|
return hasattr(self, 'overview') |
|
|
|
def hasParentOverview(self): |
|
"""returns if the parent has an overview graphics""" |
|
return hasattr(self.aq_parent, 'overview') |
|
|
|
def getOverview(self): |
|
"""map overview graphics""" |
|
#return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1] |
|
if self.hasOverview(): |
|
return getattr(self, 'overview') |
|
return None |
|
|
|
def getMapAreas(self): |
|
"""returns the list of MapAreas""" |
|
# get all contained MapAreas |
|
areas = [res[1] for res in self.ZopeFind(self, obj_metatypes=('MapArea'))] |
|
return areas |
|
|
|
def addMapArea(self, newarea): |
|
"""add a map area to this object""" |
|
if (newarea.id is None): |
|
# create new id |
|
areas = self.getMapAreas() |
|
newarea.id = "a%02d"%len(areas) |
|
self._setObject(newarea.id, newarea) |
|
|
|
def ECHO_graphicEntry(self): |
|
"""change map coordinates""" |
|
if self.hasParentOverview(): |
|
pt=zptFile(self, 'zpt/ECHO_draw.zpt') |
|
return pt() |
|
else: |
|
return "NO OVERVIEW GRAPHICS" |
|
|
|
def ECHO_addCoords(self,RESPONSE=None): |
|
"""change or add MapArea""" |
|
#return self.REQUEST |
|
# change existing areas |
|
for area in self.getMapAreas(): |
|
id = area.getId() |
|
if self.REQUEST.has_key('del.'+id): |
|
# delete this area |
|
self._delObject(id) |
|
# return to same menu |
|
if RESPONSE is not None: |
|
RESPONSE.redirect('ECHO_graphicEntry') |
|
return |
|
# modify this area |
|
coordstring = self.REQUEST.get('coords.'+id, '') |
|
coords = string.split(coordstring, ',') |
|
angle = self.REQUEST.get('angle.'+id, '0') |
|
type = self.REQUEST.get('type.'+id, 'area') |
|
if len(coords) == 4: |
|
area.setCoordString(coordstring) |
|
area.setAngle(angle) |
|
area.setType(type) |
|
# add new area |
|
if self.REQUEST.has_key('add'): |
|
coordstring = self.REQUEST.get('coords.new', '') |
|
coords = string.split(coordstring, ',') |
|
angle = self.REQUEST.get('angle.new', '0') |
|
type = self.REQUEST.get('type.new', 'area') |
|
if len(coords) == 4: |
|
coords.append(angle) |
|
area = MapArea(None, coords, type=type) |
|
self.addMapArea(area) |
|
# return to edit area menu |
|
if RESPONSE is not None: |
|
RESPONSE.redirect('ECHO_graphicEntry') |
|
|
|
def createJSAreas(self, areas): |
|
"""create area calls for JavaScript""" |
|
dynamical="\n" |
|
for ob in areas: |
|
if ob.isTypeArrow(): |
|
dynamical+="""addArea('%s', 'overview', %s, 'arrow');\n"""%(ob.getFullId(),ob.getCoordString()) |
|
else: |
|
dynamical+="""addArea('%s', 'overview', %s, 'area');\n"""%(ob.getFullId(),ob.getCoordString()) |
|
return dynamical |
|
|
|
def createMapHead(self): |
|
"""create javascript include and script tags for head""" |
|
pt=zptFile(self, 'zpt/ECHO_content_map_frag_js') |
|
return pt() |
|
|
|
def createMapImg(self): |
|
"""generate img-tag for map""" |
|
bt = BrowserCheck(self) |
|
tag = "" |
|
src = self.getOverview().absolute_url() |
|
if bt.isN4: |
|
# N4 needs ilayer to create an id |
|
tag += '<ilayer id="overview" visibility="show"><img src="%s"></ilayer>'%src |
|
else: |
|
# img with id |
|
tag += '<img id="overview" src="%s" />'%src |
|
return tag |
|
|
|
def createParentMapImg(self): |
|
"""generate img-tag for map of parent""" |
|
return self.aq_parent.createMapImg() |
|
|
|
def createMapLink(self, ob, text=None): |
|
"""generate map link""" |
|
bt = BrowserCheck(self) |
|
id = ob.getFullId() |
|
link = ob.getLinkId() |
|
if text is None: |
|
text = ob.getLabel() |
|
if text is None: |
|
text = "link" |
|
tiptext = ob.getText() |
|
tag = "" |
|
if bt.isN4: |
|
# N4 needs layer for highlighting |
|
tag += '<ilayer id="a.%s"><a onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="_blank"'%(id,id,id,link) |
|
tag += ">" + text + "</a></ilayer>" |
|
else: |
|
# a-element |
|
tag = '<a id="a.%s" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="_blank"'%(id,id,id,link) |
|
if tiptext: |
|
tag += ' title="%s"'%tiptext |
|
tag += ">" + text + "</a>" |
|
return tag |
|
|
|
def createMapAux(self, ob, arrowsrc="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?dw=15&fn=icons/pfeil"): |
|
"""generate map link image, text and other stuff""" |
|
bt = BrowserCheck(self) |
|
id = ob.getFullId() |
|
link = ob.getLinkId() |
|
tiptext = ob.getText() |
|
tag = "" |
|
|
|
if bt.isN4: |
|
# N4 needs layer and img elements |
|
tag += '<layer id="i.%s" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)">'%(id,id,id) |
|
if ob.isTypeArrow(): |
|
rot = ob.angle |
|
tag += '<a href="%s"><img border="0" src="%s&rot=%s" /></a>'%(link,arrowsrc,rot) |
|
else: |
|
tag += '<a href="%s"><img border="0" width="1000" height="1000" src="trans_img"'%(link) |
|
if tiptext: |
|
tag += ' alt="%s"'%tiptext |
|
tag += ' /></a>' |
|
tag += '</layer>' |
|
else: |
|
# create a-element |
|
tag = '<a id="b.%s" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="_blank">'%(id,id,id,link) |
|
if ob.isTypeArrow(): |
|
rot = ob.angle |
|
if bt.isIEWin and bt.versIE > 5: |
|
# IE/Win 5.5 has "feature" for PNG transparency |
|
tag += '<span id="i.%s" style="position:absolute; top:-100px; left:-100px; border-style:none; border-width=1px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'%s&rot=%s\');"><img style="visibility:hidden" src="%s&rot=%s" /></span>'%(id,arrowsrc,rot,arrowsrc,rot) |
|
else: |
|
# arrow image |
|
tag += '<img id="i.%s" src="%s&rot=%s" border="1" style="position:absolute; top:-100px; left:-100px; border-style:none;" />'%(id,arrowsrc,rot) |
|
else: |
|
if bt.isIE: |
|
# IE needs transparent img for area |
|
tag += '<img id="i.%s" border="0" style="position:absolute; top:-100px; left:-100px;" src="trans_img"'%(id) |
|
if tiptext: |
|
tag += ' title="%s"'%tiptext |
|
tag += " />" |
|
else: |
|
# div for area |
|
tag += '<div id="i.%s" style="position:absolute; top:-100px; left:-100px;"'%(id) |
|
if tiptext: |
|
tag += ' title="%s"'%tiptext |
|
tag += '> </div>' |
|
tag += '</a>' |
|
return tag |
|
|
|
|
#ende der echo erweiterungen |
#ende der echo erweiterungen |
|
|
|
|
def toList(field): |
def toList(field): |
"""Einzelfeld in Liste umwandeln""" |
"""Einzelfeld in Liste umwandeln""" |
if type(field)==StringType: |
if type(field)==types.StringType: |
return [field] |
return [field] |
else: |
else: |
return field |
return field |
Line 206 def getSubCols(self,sortfield="weight",s
|
Line 393 def getSubCols(self,sortfield="weight",s
|
def sortfnc(sortfield,x,y): |
def sortfnc(sortfield,x,y): |
xa=x[1].getMDValue(sortfield) |
xa=x[1].getMDValue(sortfield) |
ya=y[1].getMDValue(sortfield) |
ya=y[1].getMDValue(sortfield) |
print xa,ya |
#print xa,ya |
return cmp(xa,ya) |
return cmp(xa,ya) |
|
|
sortWithMD = lambda sortfield : (lambda x,y : sortfnc(sortfield,x,y)) |
sortWithMD = lambda sortfield : (lambda x,y : sortfnc(sortfield,x,y)) |
Line 225 def getSubCols(self,sortfield="weight",s
|
Line 412 def getSubCols(self,sortfield="weight",s
|
"""nothing""" |
"""nothing""" |
|
|
tmplist=[] |
tmplist=[] |
|
|
for x in ids: |
for x in ids: |
if hasattr(x,sortfield): |
if hasattr(x,sortfield): |
try: |
try: |
|
tmp=int(getattr(x,sortfield)) |
x=int(x) |
|
except: |
except: |
"""nothing""" |
|
tmp=getattr(x,sortfield) |
tmp=getattr(x,sortfield) |
|
|
else: |
else: |
tmp=10000000 |
tmp=10000000 |
|
|
tmplist.append((tmp,x)) |
tmplist.append((tmp,x)) |
|
|
if not sortFieldMD: |
if not sortFieldMD: |
Line 398 def checkDiffs(self,metadict):
|
Line 586 def checkDiffs(self,metadict):
|
return diffs |
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)) |
|
else: |
|
pt=PageTemplateFile(os.path.join(package_home(globals()), path)).__of__(self) |
|
return pt |
|
|
|
|
def sendFile(self, filename, type): |
def findObjectPath(startobject, filename): |
"""sends an object or a local file (in the product) as response""" |
"""returns the object with the name filename starting at startobject""" |
|
if startobject is None: |
|
return None |
paths = filename.split('/') |
paths = filename.split('/') |
object = self |
object = startobject |
# look for an object called filename |
|
for path in paths: |
for path in paths: |
if hasattr(object, path): |
if hasattr(object, path): |
object = getattr(object, path) |
object = getattr(object, path) |
else: |
else: |
object = None |
object = None |
break |
break |
|
return object |
|
|
|
|
|
def zptObjectOrFile(self, filename, localdir='zpt', orphaned=False): |
|
"""returns a page template instance or a file from the product""" |
|
# look for an object called path |
|
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) |
|
return pt |
|
|
|
|
|
def sendFile(self, filename, type): |
|
"""sends an object or a local file (in the product) as response""" |
|
# look for an object called filename |
|
object = findObjectPath(self, filename) |
if object: |
if object: |
# if the object exists then send it |
# if the object exists then send it |
return object.index_html(self.REQUEST.REQUEST, self.REQUEST.RESPONSE) |
return object.index_html(self.REQUEST.REQUEST, self.REQUEST.RESPONSE) |
Line 421 def sendFile(self, filename, type):
|
Line 636 def sendFile(self, filename, type):
|
self.REQUEST.RESPONSE.write(file(fn).read()) |
self.REQUEST.RESPONSE.write(file(fn).read()) |
return |
return |
|
|
|
|
class BrowserCheck: |
class BrowserCheck: |
"""check the browsers request to find out the browser type""" |
"""check the browsers request to find out the browser type""" |
|
|
def __init__(self, zope): |
def __init__(self, zope): |
"""initialisiere""" |
"""initialisiere""" |
self.ua = zope.REQUEST.get_header("HTTP_USER_AGENT") |
self.ua = zope.REQUEST.get_header("HTTP_USER_AGENT") |
self.isN4 = (string.find(self.ua, 'Mozilla/4.') > -1) and (string.find(self.ua, 'MSIE') < 0) |
self.isN4 = False |
self.isIE = string.find(self.ua, 'MSIE') > -1 |
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, '('):] |
self.nav = self.ua[string.find(self.ua, '('):] |
ie = string.split(self.nav, "; ")[1] |
ie = string.split(self.nav, "; ")[1] |
if string.find(ie, "MSIE") > -1: |
if string.find(ie, "MSIE") > -1: |
self.versIE = string.split(ie, " ")[1] |
self.versIE = string.split(ie, " ")[1] |
|
except: pass |
self.isMac = string.find(self.ua, 'Macintosh') > -1 |
self.isMac = string.find(self.ua, 'Macintosh') > -1 |
self.isWin = string.find(self.ua, 'Windows') > -1 |
self.isWin = string.find(self.ua, 'Windows') > -1 |
self.isIEWin = self.isIE and self.isWin |
self.isIEWin = self.isIE and self.isWin |
self.isIEMac = self.isIE and self.isMac |
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): |
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""" |
|
|
Line 471 def writeMetadata(url,metadict,project=N
|
Line 692 def writeMetadata(url,metadict,project=N
|
else: |
else: |
try: |
try: |
geturl="" |
geturl="" |
for line in ECHO_helpers.urlopen(url).readlines(): |
for line in urlopen(url).readlines(): |
geturl=geturl+line |
geturl=geturl+line |
|
|
|
|
except: |
except: |
return (None,"Cannot open: "+url) |
return (None,"XCannot open: "+url) |
|
|
try: |
try: |
dom=xml.dom.minidom.parseString(geturl) |
dom=xml.dom.minidom.parseString(geturl) |
Line 555 def readMetadata(url):
|
Line 776 def readMetadata(url):
|
Vorerst noch Typ bib""" |
Vorerst noch Typ bib""" |
|
|
metadict={} |
metadict={} |
|
|
try: |
try: |
geturl="" |
geturl="" |
for line in ECHO_helpers.urlopen(url).readlines(): |
for line in urlopen(url).readlines(): |
geturl=geturl+line |
geturl=geturl+line |
|
|
|
|
Line 594 def readMetadata(url):
|
Line 816 def readMetadata(url):
|
|
|
return metadict,"" |
return metadict,"" |
|
|
|
|
|
class MapArea(SimpleItem): |
|
"""simple class to hold coordinates""" |
|
|
|
meta_type = 'MapArea' |
|
# Create a SecurityInfo for this class. |
|
security = ClassSecurityInfo() |
|
security.setDefaultAccess("allow") |
|
# 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 |
|
|
|
def setCoords(self, coords): |
|
"""sets the coords""" |
|
self.coords = coords |
|
|
|
def getCoordString(self): |
|
"""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] |
|
|
|
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 |
|
|
|
def getType(self): |
|
"""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 |
|
|
|
def isTypeArea(self): |
|
"""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 |
|
|
|
def getAngle(self): |
|
"""returns the angle""" |
|
return self.angle |
|
|
|
def setAngle(self, angle): |
|
"""sets the angle""" |
|
self.angle = angle |
|
|
|
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 |
|
|
|
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 |
|
|
|
def setLabel(self, label): |
|
"""sets the label""" |
|
self.label = label |
|
|
|
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) |