version 1.37, 2005/01/31 11:15:50
|
version 1.50, 2005/06/09 08:34:49
|
Line 6 import string
|
Line 6 import string
|
import xml.dom.minidom |
import xml.dom.minidom |
import types |
import types |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
|
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
from OFS.SimpleItem import SimpleItem |
from OFS.SimpleItem import SimpleItem |
from Globals import package_home |
from Globals import package_home |
import Globals |
import Globals |
from AccessControl import ClassSecurityInfo |
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','ECHO_movie'] |
|
|
def content_html(self,type): |
def content_html(self,type): |
"""template fuer content""" |
"""template fuer content""" |
Line 25 def content_html(self,type):
|
Line 26 def content_html(self,type):
|
obj=getattr(self,type+"_template") |
obj=getattr(self,type+"_template") |
return obj() |
return obj() |
else: |
else: |
pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_%s_template_standard.zpt'%type).__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','ECHO_%s_template_standard.zpt'%type)).__of__(self) |
pt.content_type="text/html" |
pt.content_type="text/html" |
return pt() |
return pt() |
|
|
Line 33 def content_html(self,type):
|
Line 34 def content_html(self,type):
|
|
|
class ECHO_basis: |
class ECHO_basis: |
"""basis eigenschaften fuer echo objekte""" |
"""basis eigenschaften fuer echo objekte""" |
|
security=ClassSecurityInfo() |
|
security.declarePublic('getImageTag') |
|
def getImageTag(self): |
|
"""sollte uerberschrieben werden, falls von der Klasse eine imagetag zurueckkommt""" |
|
|
|
return "" |
|
|
def showRDF(self): |
def showRDF(self): |
"""showrdf""" |
"""showrdf""" |
self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') |
self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml') |
Line 45 class ECHO_basis:
|
Line 53 class ECHO_basis:
|
return ret |
return ret |
|
|
|
|
|
def RDF(self): |
|
"""showrdf""" |
|
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+=self.getRDF(urn=self.absolute_url())+"\n" |
|
|
|
|
|
ret+="""</RDF:RDF>""" |
|
return ret |
|
|
|
|
def createSubElementRDF(self,urn=None): |
def createSubElementRDF(self,urn=None): |
"""rdf list""" |
"""rdf list""" |
Line 106 class ECHO_basis:
|
Line 125 class ECHO_basis:
|
|
|
def getLabel(self): |
def getLabel(self): |
"""title""" |
"""title""" |
|
if not hasattr(self,'label'): |
|
self.label="" |
|
|
|
if self.label=="": |
|
ret=self.getTitle() |
|
if ret=="": |
|
ret=self.getId() |
|
return ret |
|
|
return self.decode(self.label) |
return self.decode(self.label) |
try: |
try: |
Line 159 class ECHO_basis:
|
Line 186 class ECHO_basis:
|
"""add a map area to this object""" |
"""add a map area to this object""" |
if (newarea.id is None): |
if (newarea.id is None): |
# create new id |
# create new id |
areas = self.getMapAreas() |
ids = [a.id for a in self.getMapAreas()] |
newarea.id = "a%02d"%len(areas) |
i = len(ids) |
|
while ("a%02d"%i in ids): |
|
# if it exists, try the next one |
|
i += 1 |
|
newarea.id = "a%02d"%i |
self._setObject(newarea.id, newarea) |
self._setObject(newarea.id, newarea) |
|
|
|
def getMapText(self): |
|
"""returns the MapText""" |
|
# get (the first) contained MapText |
|
res = self.ZopeFind(self, obj_metatypes=('ECHO_mapText')) |
|
if len(res) > 0: |
|
text = res[0][1] |
|
return text |
|
return None |
|
|
def ECHO_graphicEntry(self): |
def ECHO_graphicEntry(self): |
"""change map coordinates""" |
"""change map coordinates""" |
if self.hasParentOverview(): |
if self.hasParentOverview(): |
Line 211 class ECHO_basis:
|
Line 251 class ECHO_basis:
|
"""create area calls for JavaScript""" |
"""create area calls for JavaScript""" |
dynamical="\n" |
dynamical="\n" |
for ob in areas: |
for ob in areas: |
if ob.isTypeArrow(): |
dynamical+="""addArea('%s', 'overview', %s, '%s');\n"""%(ob.getFullId(),ob.getCoordString(),ob.getType()) |
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 |
return dynamical |
|
|
def createMapHead(self): |
def createMapHead(self): |
Line 239 class ECHO_basis:
|
Line 276 class ECHO_basis:
|
"""generate img-tag for map of parent""" |
"""generate img-tag for map of parent""" |
return self.aq_parent.createMapImg() |
return self.aq_parent.createMapImg() |
|
|
def createMapLink(self, ob, text=None): |
def createMapLink(self, ob, text=None, target="_blank"): |
"""generate map link""" |
"""generate map link""" |
bt = BrowserCheck(self) |
bt = BrowserCheck(self) |
id = ob.getFullId() |
id = ob.getFullId() |
Line 248 class ECHO_basis:
|
Line 285 class ECHO_basis:
|
text = ob.getLabel() |
text = ob.getLabel() |
if text is None: |
if text is None: |
text = "link" |
text = "link" |
tiptext = ob.getText() |
tiptext = ob.getTip() |
tag = "" |
tag = "" |
if bt.isN4: |
if bt.isN4: |
# N4 needs layer for highlighting |
# 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 += '<ilayer id="a.%s"><a onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="%s"'%(id,id,id,link,target) |
tag += ">" + text + "</a></ilayer>" |
tag += ">" + text + "</a></ilayer>" |
else: |
else: |
# a-element |
# a-element |
tag = '<a id="a.%s" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="_blank"'%(id,id,id,link) |
tag = '<a id="a.%s" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="%s"'%(id,id,id,link,target) |
if tiptext: |
if tiptext: |
tag += ' title="%s"'%tiptext |
tag += ' title="%s"'%tiptext |
tag += ">" + text + "</a>" |
tag += ">" + text + "</a>" |
return tag |
return tag |
|
|
def createMapAux(self, ob, arrowsrc="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?dw=15&fn=icons/pfeil"): |
def createMapAux(self, ob, arrowsrc="http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler/?dw=15&fn=icons/pfeil",target="_blank"): |
"""generate map link image, text and other stuff""" |
"""generate map link image, text and other stuff""" |
bt = BrowserCheck(self) |
bt = BrowserCheck(self) |
id = ob.getFullId() |
id = ob.getFullId() |
link = ob.getLinkId() |
link = ob.getLinkId() |
tiptext = ob.getText() |
tiptext = ob.getTip() |
tag = "" |
tag = "" |
|
|
if bt.isN4: |
if bt.isN4: |
Line 284 class ECHO_basis:
|
Line 321 class ECHO_basis:
|
tag += '</layer>' |
tag += '</layer>' |
else: |
else: |
# create a-element |
# create a-element |
tag = '<a id="b.%s" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="_blank">'%(id,id,id,link) |
tag = '<a id="b.%s" onmouseover="highlightPair(\'%s\', true)" onmouseout="highlightPair(\'%s\', false)" href="%s" target="%s">'%(id,id,id,link,target) |
if ob.isTypeArrow(): |
if ob.isTypeArrow(): |
rot = ob.angle |
rot = ob.angle |
if bt.isIEWin and bt.versIE > 5: |
if bt.isIEWin and bt.versIE > 5: |
Line 293 class ECHO_basis:
|
Line 330 class ECHO_basis:
|
else: |
else: |
# arrow image |
# 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) |
tag += '<img id="i.%s" src="%s&rot=%s" border="1" style="position:absolute; top:-100px; left:-100px; border-style:none;" />'%(id,arrowsrc,rot) |
|
elif ob.isTypeText(): |
|
# div for area |
|
tag += '<div id="i.%s" style="position:absolute; top:-100px; left:-100px;"'%(id) |
|
if tiptext: |
|
tag += ' title="%s"'%tiptext |
|
tag += '><div id="t.%s" class="maptext">'%(id) |
|
tag += ob.getText() |
|
tag += '</div></div>' |
else: |
else: |
if bt.isIE: |
if bt.isIE: |
# IE needs transparent img for area |
# IE needs transparent img for area |
Line 301 class ECHO_basis:
|
Line 346 class ECHO_basis:
|
tag += ' title="%s"'%tiptext |
tag += ' title="%s"'%tiptext |
tag += " />" |
tag += " />" |
else: |
else: |
# div for area |
# empty div for area |
tag += '<div id="i.%s" style="position:absolute; top:-100px; left:-100px;"'%(id) |
tag += '<div id="i.%s" style="position:absolute; top:-100px; left:-100px;"'%(id) |
if tiptext: |
if tiptext: |
tag += ' title="%s"'%tiptext |
tag += ' title="%s"'%tiptext |
Line 321 def toList(field):
|
Line 366 def toList(field):
|
return field |
return field |
|
|
def getText(nodelist): |
def getText(nodelist): |
|
|
rc = "" |
rc = "" |
for node in nodelist: |
for node in nodelist: |
if node.nodeType == node.TEXT_NODE: |
if node.nodeType == node.TEXT_NODE: |
Line 388 def checkOnlyOneInGroup(object):
|
Line 432 def checkOnlyOneInGroup(object):
|
return displayedObjects[0][1] |
return displayedObjects[0][1] |
else: return object |
else: return object |
|
|
def getSubCols(self, sortfield="weight", subColTypes=displayTypes, sortFieldMD=None): |
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): |
def sortfnc(sortfield,x,y): |
|
try: |
xa=x[1].getMDValue(sortfield) |
xa=x[1].getMDValue(sortfield) |
|
except: |
|
xa="" |
|
try: |
ya=y[1].getMDValue(sortfield) |
ya=y[1].getMDValue(sortfield) |
#print xa,ya |
except: |
|
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 403 def getSubCols(self, sortfield="weight",
|
Line 456 def getSubCols(self, sortfield="weight",
|
|
|
for entry in displayedObjects: |
for entry in displayedObjects: |
|
|
|
|
object=entry[1] |
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) |
ids.append(object) |
|
|
try: |
if not sortfield: |
sortfield=self.sortfield |
sortfield=getattr(self,'sortfield','weight') |
except: |
|
"""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)) |
tmp=int(getattr(x,sortfield)) |
Line 426 def getSubCols(self, sortfield="weight",
|
Line 491 def getSubCols(self, sortfield="weight",
|
tmplist.append((tmp,x)) |
tmplist.append((tmp,x)) |
|
|
if not sortFieldMD: |
if not sortFieldMD: |
tmplist.sort() |
tmplist.sort(sort) |
else: |
else: |
tmplist.sort(sortWithMD(sortFieldMD)) |
tmplist.sort(sortWithMD(sortFieldMD)) |
|
|
Line 466 def reloadMetaDataFromStorage(self,RESPO
|
Line 531 def reloadMetaDataFromStorage(self,RESPO
|
for resource in resources: |
for resource in resources: |
x=str(resource[1].copyIndex_meta2echo_resource())+"<br>" |
x=str(resource[1].copyIndex_meta2echo_resource())+"<br>" |
ret+=x |
ret+=x |
#print x |
|
|
|
|
|
if RESPONSE is not None: |
if RESPONSE is not None: |
#RESPONSE.redirect('./manage_main') |
#RESPONSE.redirect('./manage_main') |
Line 603 def findObjectPath(startobject, filename
|
Line 666 def findObjectPath(startobject, filename
|
paths = filename.split('/') |
paths = filename.split('/') |
object = startobject |
object = startobject |
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: |
Line 665 def writeMetadata(url,metadict,project=N
|
Line 729 def writeMetadata(url,metadict,project=N
|
"""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] |
metanode=dom.getElementsByTagName('texttool')[0] |
try: |
try: |
nodeOld=metanode.getElementsByTagName(tag) |
nodeOld=metanode.getElementsByTagName(tag) |
Line 809 def readMetadata(url):
|
Line 873 def readMetadata(url):
|
for node in metacontent: |
for node in metacontent: |
try: |
try: |
#print urllib.unquote(getText(node.childNodes)),getText(node.childNodes) |
#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())]=urllib.unquote(getText(node.childNodes)) |
|
metadict[re.sub('-','_',node.tagName.lower())]=getText(node.childNodes) |
|
|
except: |
except: |
"""nothing""" |
"""nothing""" |
|
|
Line 827 class MapArea(SimpleItem):
|
Line 893 class MapArea(SimpleItem):
|
# type constants |
# type constants |
TYPE_AREA = 'area' |
TYPE_AREA = 'area' |
TYPE_ARROW = 'arrow' |
TYPE_ARROW = 'arrow' |
|
TYPE_TEXT = 'text' |
|
|
def __init__(self, id, coords, label=None, type=None, text=None): |
def __init__(self, id, coords, label=None, type=None, tip=None, volatile=True): |
"""init""" |
"""init""" |
self.coords = coords[0:4] |
self.coords = coords[0:4] |
if len(coords) > 4: |
if len(coords) > 4: |
Line 838 class MapArea(SimpleItem):
|
Line 905 class MapArea(SimpleItem):
|
self.id = id |
self.id = id |
self.label = label |
self.label = label |
self.setType(type) |
self.setType(type) |
self.text = text |
self.tip = tip |
|
self.volatile = volatile |
|
|
def setCoords(self, coords): |
def setCoords(self, coords): |
"""sets the coords""" |
"""sets the coords""" |
Line 873 class MapArea(SimpleItem):
|
Line 941 class MapArea(SimpleItem):
|
self.type = MapArea.TYPE_ARROW |
self.type = MapArea.TYPE_ARROW |
elif type == MapArea.TYPE_AREA: |
elif type == MapArea.TYPE_AREA: |
self.type = MapArea.TYPE_AREA |
self.type = MapArea.TYPE_AREA |
|
elif type == MapArea.TYPE_TEXT: |
|
self.type = MapArea.TYPE_TEXT |
else: |
else: |
self.type = MapArea.TYPE_AREA |
self.type = MapArea.TYPE_AREA |
|
|
Line 884 class MapArea(SimpleItem):
|
Line 954 class MapArea(SimpleItem):
|
"""returns if the type is arrow""" |
"""returns if the type is arrow""" |
return self.type == MapArea.TYPE_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): |
def getAngle(self): |
"""returns the angle""" |
"""returns the angle""" |
return self.angle |
return self.angle |
Line 892 class MapArea(SimpleItem):
|
Line 966 class MapArea(SimpleItem):
|
"""sets the angle""" |
"""sets the angle""" |
self.angle = angle |
self.angle = angle |
|
|
def getText(self): |
def getTip(self): |
"""returns the popup text""" |
"""returns the popup text""" |
if self.text is None: |
# patch old version |
|
if not hasattr(self, 'tip'): |
|
self.tip = self.text |
|
|
|
if self.tip is None: |
if hasattr(self, 'aq_parent'): |
if hasattr(self, 'aq_parent'): |
parent = self.aq_parent |
parent = self.aq_parent |
if parent.contentType == 'text-popup': |
if parent.contentType == 'text-popup': |
return parent.description |
return parent.description |
return self.text |
return self.tip |
|
|
def setText(self, text): |
def setTip(self, text): |
"""sets the text""" |
"""sets the text""" |
self.text = text |
self.tiptext = text |
|
|
|
def getText(self): |
|
"""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): |
def getLabel(self): |
"""returns the link label""" |
"""returns the link label""" |
Line 921 class MapArea(SimpleItem):
|
Line 1008 class MapArea(SimpleItem):
|
return self.aq_parent.id |
return self.aq_parent.id |
return self.id |
return self.id |
|
|
|
|
# call this to initialize framework classes, which |
# call this to initialize framework classes, which |
# does the right thing with the security assertions. |
# does the right thing with the security assertions. |
Globals.InitializeClass(MapArea) |
Globals.InitializeClass(MapArea) |
|
|
|
|
|
class MapText(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) |
|
|
|
# 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) |