version 1.28, 2004/06/22 13:35:50
|
version 1.36, 2004/07/22 17:30:21
|
Line 1
|
Line 1
|
|
|
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
from Products.PageTemplates.PageTemplate import PageTemplate |
from Products.PageTemplates.PageTemplate import PageTemplate |
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate |
Line 7 from webdav.common import rfc1123_date
|
Line 6 from webdav.common import rfc1123_date
|
|
|
import xml.dom.minidom |
import xml.dom.minidom |
from OFS.Folder import Folder |
from OFS.Folder import Folder |
from xml_helpers import getText |
from xml_helpers import getUniqueElementText,getText |
import os |
import os |
import re |
import re |
import string |
import string |
Line 15 import urllib
|
Line 14 import urllib
|
import types |
import types |
from Globals import package_home |
from Globals import package_home |
|
|
ZOGIVERSION = "0.9.4 ROC:22.6.2004" |
ZOGIVERSION = "0.9.7 ROC:21.7.2004" |
|
|
|
def cropf(f): |
|
"""returns a float with reduced precision""" |
|
return float(int(f * 10000)/10000.0) |
|
|
|
|
def sendFile(self, filename, type): |
def sendFile(self, filename, type): |
"""sends an object or a local file (in the product) as response""" |
"""sends an object or a local file (in the product) as response""" |
Line 57 def browserCheck(self):
|
Line 61 def browserCheck(self):
|
|
|
return bt |
return bt |
|
|
def manage_addZogiLibMainTemplateForm(self): |
|
"""Form for adding""" |
|
#FIXME:??? |
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/AddOSAS_thumbTemplate.zpt')).__of__(self) |
|
return pt() |
|
|
|
|
|
|
|
|
|
def manage_addZogiLibMainTemplate(self, id,title=None, text=None, |
|
REQUEST=None, submit=None): |
|
"Add a Page Template with optional file content." |
|
#FIXME:??? |
|
id = str(id) |
|
if REQUEST is None: |
|
self._setObject(id, zogiLib_mainTemplate(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 = zogiLib_mainTemplate(id) |
|
else: |
|
zpt = zogiLib_mainTemplate(id, file, headers.get('content_type')) |
|
|
|
self._setObject(id, zpt) |
|
ob = getattr(self, id) |
|
|
|
|
|
try: |
|
u = self.DestinationURL() |
|
except AttributeError: |
|
u = REQUEST['URL1'] |
|
|
|
if submit == " Add and Edit ": |
|
u = "%s/%s" % (u, quote(id)) |
|
REQUEST.RESPONSE.redirect(u+'/manage_main') |
|
return '' |
|
|
|
|
|
class zogiImage(Image): |
class zogiImage(Image): |
"""einzelnes Image""" |
"""einzelnes Image""" |
Line 421 class zogiLib(Folder):
|
Line 382 class zogiLib(Folder):
|
"""StandardElement""" |
"""StandardElement""" |
|
|
meta_type="zogiLib" |
meta_type="zogiLib" |
|
#xxxx |
|
|
manage_options = Folder.manage_options+( |
manage_options = Folder.manage_options+( |
{'label':'Main Config','action':'changeZogiLibForm'}, |
{'label':'Main Config','action':'changeZogiLibForm'}, |
) |
) |
|
|
def __init__(self, id, title, digilibBaseUrl, localFileBase, version="book", basePath="", dlTarget=None): |
def __init__(self, id, title, dlServerURL,localFileBase, version="book", basePath="", dlTarget=None): |
"""init""" |
"""init""" |
|
|
self.id=id |
self.id=id |
self.title=title |
self.title=title |
self.digilibBaseUrl=digilibBaseUrl |
self.dlServerURL = dlServerURL |
|
|
self.localFileBase=localFileBase |
self.localFileBase=localFileBase |
self.basePath=basePath |
self.basePath=basePath |
self.layout=version |
self.layout=version |
Line 444 class zogiLib(Folder):
|
Line 407 class zogiLib(Folder):
|
"""version information""" |
"""version information""" |
return ZOGIVERSION |
return ZOGIVERSION |
|
|
|
def getContextStatic(self): |
|
"""get all the contexts which go to static pages""" |
|
|
|
try: |
|
dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName())) |
|
contexts=dom.getElementsByTagName("context") |
|
|
|
ret=[] |
|
for context in contexts: |
|
name=getUniqueElementText(context.getElementsByTagName("name")) |
|
|
|
link=getUniqueElementText(context.getElementsByTagName("link")) |
|
if name or link: |
|
ret.append((name,link)) |
|
return ret |
|
except: |
|
return [] |
|
|
|
def getContextDatabases(self): |
|
"""get all dynamic contexts""" |
|
try: |
|
dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName())) |
|
contexts=dom.getElementsByTagName("context") |
|
ret=[] |
|
for context in contexts: |
|
metaDataLinks=context.getElementsByTagName("meta-datalink") |
|
for metaDataLink in metaDataLinks: |
|
db=metaDataLink.getAttribute("db") |
|
link=self.REQUEST['URL1']+"/dl_db?db=%s"%db |
|
if db: |
|
ret.append((db,link)) |
|
metaDataLinks=context.getElementsByTagName("meta-baselink") |
|
|
|
for metaDataLink in metaDataLinks: |
|
db=metaDataLink.getAttribute("db") |
|
link=self.REQUEST['URL1']+"/dl_db?db=%s"%db |
|
if db: |
|
ret.append((db,link)) |
|
|
|
return ret |
|
except: |
|
return ret |
|
|
|
def formatHTML(self,url,label=None,viewUrl=None): |
|
|
|
|
|
sets=xml.dom.minidom.parse(urllib.urlopen(url)).getElementsByTagName('dataset') |
|
ret="" |
|
print label |
|
if label: |
|
ret+="""<a href="%s">%s</a>"""%(viewUrl,label) |
|
for set in sets: |
|
ret+="<table>" |
|
for node in set.childNodes: |
|
if hasattr(node,'tagName'): |
|
tag=node.tagName |
|
label=node.getAttribute("label") |
|
if not label: |
|
label=tag |
|
text=getText(node.childNodes) |
|
ret+="""<tr><td><b>%s:</b></td><td>%s</td></tr>"""%(label,text) |
|
ret+="</table>" |
|
return ret |
|
|
|
def getMetaData(self): |
|
"""getMetaData""" |
|
try: |
|
dom=xml.dom.minidom.parse(urllib.urlopen(self.getMetaFileName())) |
|
except: |
|
return "error metadata" |
|
|
|
contexts=dom.getElementsByTagName("context") |
|
ret=[] |
|
db=self.getDLParam("db") |
|
ob=self.getDLParam("object") |
|
|
|
fn=self.getDLParam("fn") |
|
pn=self.getDLParam("pn") |
|
if not fn: |
|
fn="" |
|
if not pn: |
|
pn="" |
|
if not ob: |
|
ob="" |
|
|
|
for context in contexts: |
|
metaDataLinks=context.getElementsByTagName("meta-datalink") |
|
for metaDataLink in metaDataLinks: |
|
|
|
if (db==metaDataLink.getAttribute("db")) or (len(metaDataLinks)==1): |
|
|
|
link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url")) |
|
label=getUniqueElementText(metaDataLink.getElementsByTagName("label")) |
|
url=getUniqueElementText(metaDataLink.getElementsByTagName("url")) |
|
|
|
return self.formatHTML(link,label,url) |
|
|
|
metaDataLinks=context.getElementsByTagName("meta-baselink") |
|
|
|
for metaDataLink in metaDataLinks: |
|
|
|
if db==metaDataLink.getAttribute("db") or (len(metaDataLinks)==1): |
|
|
|
link=getUniqueElementText(metaDataLink.getElementsByTagName("metadata-url")) |
|
label=getUniqueElementText(metaDataLink.getElementsByTagName("label")) |
|
url=getUniqueElementText(metaDataLink.getElementsByTagName("url")) |
|
|
|
return self.formatHTML(link+'fn=%s&pn=%s&object=%s'%(fn,pn,ob),label,url) |
|
return ret |
|
|
def getDLInfo(self): |
def getDLInfo(self): |
"""get DLInfo from digilib server""" |
"""get DLInfo from digilib server""" |
paramH={} |
paramH={} |
baseUrl=re.sub("servlet/Scaler","dlInfo-xml.jsp",self.digilibBaseUrl) |
baseUrl=self.dlServerURL+"/dlInfo-xml.jsp" |
try: |
try: |
url=urllib.urlopen(baseUrl+self.REQUEST['QUERY_STRING']) |
url=urllib.urlopen(baseUrl+self.REQUEST['QUERY_STRING']) |
dom=xml.dom.minidom.parse(url) |
dom=xml.dom.minidom.parse(url) |
Line 456 class zogiLib(Folder):
|
Line 529 class zogiLib(Folder):
|
paramH[param.getAttribute('name')]=param.getAttribute('value') |
paramH[param.getAttribute('name')]=param.getAttribute('value') |
return paramH |
return paramH |
except: |
except: |
return null |
return {} |
|
|
|
|
def createHeadJS(self): |
def createHeadJS(self): |
Line 490 class zogiLib(Folder):
|
Line 563 class zogiLib(Folder):
|
# if not explicitly defined take normal request |
# if not explicitly defined take normal request |
if not requestString: |
if not requestString: |
requestString = self.getAllDLParams() |
requestString = self.getAllDLParams() |
url = self.digilibBaseUrl+requestString |
url = self.dlServerURL+'/servlet/Scaler?'+requestString |
# construct bottom and side insets |
# construct bottom and side insets |
b_par = "" |
b_par = "" |
s_par = "" |
s_par = "" |
Line 550 class zogiLib(Folder):
|
Line 623 class zogiLib(Folder):
|
|
|
def dl_lib_js(self): |
def dl_lib_js(self): |
"""javascript""" |
"""javascript""" |
return sendFile(self, 'js/dl_lib.js', 'text/plain') |
return sendFile(self, 'js/dllib.js', 'text/plain') |
|
|
def js_lib_js(self): |
def js_lib_js(self): |
"""javascript""" |
"""javascript""" |
return sendFile(self, 'js/js_lib.js', 'text/plain') |
return sendFile(self, 'js/baselib.js', 'text/plain') |
|
|
def optionwindow(self): |
def optionwindow(self): |
"""showoptions""" |
"""showoptions""" |
self.checkQuery() |
self.checkQuery() |
|
if self.REQUEST.has_key('frametarget'): |
|
self.dlTarget = self.REQUEST['frametarget'] |
|
print "current dltarget: ", self.dlTarget |
bt = self.REQUEST.SESSION['browserType'] |
bt = self.REQUEST.SESSION['browserType'] |
if bt['staticHTML']: |
if bt['staticHTML']: |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow_static.zpt')).__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow_static.zpt')).__of__(self) |
else: |
else: |
|
finds=self.ZopeFind(self,obj_ids=['viewingTools.zpt']) |
|
if finds: |
|
|
|
return finds[0][1]() |
|
else: |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/optionwindow.zpt')).__of__(self) |
return pt() |
return pt() |
|
|
Line 637 class zogiLib(Folder):
|
Line 718 class zogiLib(Folder):
|
self.checkQuery() |
self.checkQuery() |
bt = self.REQUEST.SESSION['browserType'] |
bt = self.REQUEST.SESSION['browserType'] |
tp = "zogiLibMainTemplate" |
tp = "zogiLibMainTemplate" |
|
|
if hasattr(self, tp): |
if hasattr(self, tp): |
pt = getattr(self, tp) |
pt = getattr(self, tp) |
else: |
else: |
tpt = self.layout |
tpt = self.layout |
|
|
if bt['staticHTML']: |
if bt['staticHTML']: |
tpt = "static" |
tpt = "static" |
|
|
Line 722 class zogiLib(Folder):
|
Line 805 class zogiLib(Folder):
|
# assemble query string |
# assemble query string |
ret = "" |
ret = "" |
for param in dlParams.keys(): |
for param in dlParams.keys(): |
if dlParams[param] == None: continue |
if dlParams[param] is None: continue |
val = str(dlParams[param]) |
val = str(dlParams[param]) |
if val != "": |
if val != "": |
ret += param + "=" + val + "&" |
ret += param + "=" + val + "&" |
Line 755 class zogiLib(Folder):
|
Line 838 class zogiLib(Folder):
|
else: |
else: |
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params) |
self.REQUEST.RESPONSE.redirect(self.REQUEST['URL1']+'?'+params) |
|
|
|
def getMetaFileName(self): |
|
url=self.dlServerURL+'/dlContext-xml.jsp?'+self.getAllDLParams() |
|
return urlbase |
|
|
|
def getToolbarPageURL(self): |
|
"""returns a toolbar-enabled page URL""" |
|
url=self.dlServerURL+'/digimage.jsp?'+self.getAllDLParams() |
|
return url |
|
|
|
def getDLTarget(self): |
|
"""returns dlTarget""" |
|
self.checkQuery() |
|
s = self.dlTarget |
|
# s = 'dl' |
|
# if self.getDLParam('fn'): |
|
# s += "_" + self.getDLParam('fn') |
|
# if self.getDLParam('pn'): |
|
# s += "_" + self.getDLParam('pn') |
|
return s |
|
|
def setStaticHTML(self, static=True): |
def setStaticHTML(self, static=True): |
"""sets the preference to static HTML""" |
"""sets the preference to static HTML""" |
Line 883 class zogiLib(Folder):
|
Line 985 class zogiLib(Folder):
|
wh2 = max(min(wh2, 1), 0) |
wh2 = max(min(wh2, 1), 0) |
wx = max(min(wx, 1), 0) |
wx = max(min(wx, 1), 0) |
wy = max(min(wy, 1), 0) |
wy = max(min(wy, 1), 0) |
self.setDLParam('ww', ww2) |
self.setDLParam('ww', cropf(ww2)) |
self.setDLParam('wh', wh2) |
self.setDLParam('wh', cropf(wh2)) |
self.setDLParam('wx', wx) |
self.setDLParam('wx', cropf(wx)) |
self.setDLParam('wy', wy) |
self.setDLParam('wy', cropf(wy)) |
return self.display() |
return self.display() |
|
|
def dl_ZoomIn(self): |
def dl_ZoomIn(self): |
Line 909 class zogiLib(Folder):
|
Line 1011 class zogiLib(Folder):
|
wy += dy * 0.5 * wh |
wy += dy * 0.5 * wh |
wx = max(min(wx, 1), 0) |
wx = max(min(wx, 1), 0) |
wy = max(min(wy, 1), 0) |
wy = max(min(wy, 1), 0) |
self.setDLParam('wx', wx) |
self.setDLParam('wx', cropf(wx)) |
self.setDLParam('wy', wy) |
self.setDLParam('wy', cropf(wy)) |
return self.display() |
return self.display() |
|
|
def dl_MoveLeft(self): |
def dl_MoveLeft(self): |
Line 982 class zogiLib(Folder):
|
Line 1084 class zogiLib(Folder):
|
self.setDLParam('mk', mk) |
self.setDLParam('mk', mk) |
return self.display() |
return self.display() |
|
|
|
def dl_db(self,db): |
|
"""set db""" |
|
self.setDLParam('db',db) |
|
self.display() |
|
|
def changeZogiLibForm(self): |
def changeZogiLibForm(self): |
"""Main configuration""" |
"""Main configuration""" |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/changeZogiLibForm.zpt')).__of__(self) |
return pt() |
return pt() |
|
|
def changeZogiLib(self,title,digilibBaseUrl, localFileBase, version, basePath, dlTarget, RESPONSE=None): |
def changeZogiLib(self,title,dlServerURL, localFileBase, version, basePath, dlTarget, RESPONSE=None): |
"""change it""" |
"""change it""" |
self.title=title |
self.title=title |
self.digilibBaseUrl=digilibBaseUrl |
self.dlServerURL=dlServerURL |
self.localFileBase=localFileBase |
self.localFileBase=localFileBase |
self.basePath = basePath |
self.basePath = basePath |
self.layout=version |
self.layout=version |
Line 1005 class zogiLib(Folder):
|
Line 1110 class zogiLib(Folder):
|
RESPONSE.redirect('manage_main') |
RESPONSE.redirect('manage_main') |
|
|
|
|
|
|
|
## |
|
## odd stuff |
|
## |
|
|
|
def repairZogilib(self, obj=None): |
|
"""change stuff that broke on upgrading""" |
|
|
|
msg = "" |
|
|
|
if not obj: |
|
obj = self.getPhysicalRoot() |
|
|
|
print "starting in ", obj |
|
|
|
entries=obj.ZopeFind(obj,obj_metatypes=['zogiLib'],search_sub=1) |
|
|
|
for entry in entries: |
|
print " found ", entry |
|
if hasattr(entry[1], 'digilibBaseUrl'): |
|
msg += " fixing "+entry[0]+"\n" |
|
entry[1].dlServerURL = re.sub('/servlet/Scaler\?','',entry[1].digilibBaseUrl) |
|
del entry[1].digilibBaseUrl |
|
|
|
return msg+"\n\nfixed all zogilib instances in: "+obj.title |
|
|
|
|
def manage_addZogiLibForm(self): |
def manage_addZogiLibForm(self): |
"""interface for adding zogilib""" |
"""interface for adding zogilib""" |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self) |
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibForm')).__of__(self) |
return pt() |
return pt() |
|
|
def manage_addZogiLib(self,id,title,digilibBaseUrl, localFileBase,version="book",basePath="",dlTarget="digilib",RESPONSE=None): |
def manage_addZogiLib(self,id,title,dlServerURL, localFileBase,version="book",basePath="",dlTarget="digilib",RESPONSE=None): |
"""add dgilib""" |
"""add dgilib""" |
newObj=zogiLib(id,title,digilibBaseUrl, localFileBase, version, basePath, dlTarget) |
newObj=zogiLib(id,title,dlServerURL, localFileBase, version, basePath, dlTarget) |
self.Destination()._setObject(id,newObj) |
self.Destination()._setObject(id,newObj) |
if RESPONSE is not None: |
if RESPONSE is not None: |
RESPONSE.redirect('manage_main') |
RESPONSE.redirect('manage_main') |
|
|
|
|
|
class zogiLibPageTemplate(ZopePageTemplate): |
|
"""pageTemplate Objekt""" |
|
meta_type="zogiLib_pageTemplate" |
|
|
|
|
|
## def __init__(self, id, text=None, contentType=None): |
|
## self.id = str(id) |
|
## self.ZBindings_edit(self._default_bindings) |
|
## if text is None: |
|
## text = open(self._default_cont).read() |
|
## self.pt_edit(text, contentType) |
|
|
|
def manage_addZogiLibPageTemplateForm(self): |
|
"""Form for adding""" |
|
pt=PageTemplateFile(os.path.join(package_home(globals()), 'zpt/addZogiLibPageTemplateForm')).__of__(self) |
|
return pt() |
|
|
|
def manage_addZogiLibPageTemplate(self, id='zogiLibMainTemplate', title=None, layout=None, text=None, |
|
REQUEST=None, submit=None): |
|
"Add a Page Template with optional file content." |
|
|
|
id = str(id) |
|
self._setObject(id, zogiLibPageTemplate(id)) |
|
ob = getattr(self, id) |
|
if not layout: layout = "book" |
|
ob.pt_edit(open(os.path.join(package_home(globals()),'zpt/zogiLibMain_%s.zpt'%layout)).read(),None) |
|
if title: |
|
ob.pt_setTitle(title) |
|
try: |
|
u = self.DestinationURL() |
|
except AttributeError: |
|
u = REQUEST['URL1'] |
|
|
|
u = "%s/%s" % (u, urllib.quote(id)) |
|
REQUEST.RESPONSE.redirect(u+'/manage_main') |
|
return '' |
|
|