1: ### XSLT Class ###
2: ### setzt 4 suite vorraus ###
3: from Acquisition import Implicit
4: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
5: from Globals import DTMLFile
6: from ECHO_Nav import ECHO_pageTemplate
7: from threading import Thread,Timer
8: import threading
9: from ECHO_helpers import *
10: try:
11: from ECHO_language import *
12: except:
13: print "no echo language"
14: class ECHO_language:
15: """leere Klasse"""
16: pass
17: import sys
18: import urllib
19: import urlparse
20: from Ft.Xml.Domlette import Print, PrettyPrint
21: from StringIO import StringIO
22: from types import *
23: from Globals import package_home
24: import transaction
25:
26: import os.path
27:
28: import urllib,cgi
29: import logging
30: try:
31: from Ft.Xml.Xslt.Processor import Processor
32: from Ft.Xml import InputSource, EMPTY_NAMESPACE,Parse
33: from Ft.Xml.Domlette import NonvalidatingReader
34: except:
35: print "4suite has to be installed"
36:
37:
38: class getXML(Thread):
39: """get XML thread"""
40:
41: def set(self,qs,xsl,result):
42: """set"""
43:
44: self._v_qs=qs
45: self.xsl=xsl
46: self.result=None
47:
48: # def acquireLock(self):
49: #
50: # lock=getattr(self, "_v_lock", None)
51: # if not lock:
52: # self._v_lock=threading.Lock()
53: # lock=self._v_lock
54: # lock.acquire()
55: #
56: # def releaseLock(self):
57: # # acquire() should have been called
58: # # about one second before. This means the volatile lock
59: # # should still be there
60: #
61: # self._v_lock.release()
62: #
63:
64: def __call__(self):
65: """wait"""
66: self.run()
67: return True
68:
69: def run(self):
70: """call it"""
71: xml=""
72:
73: try:
74:
75: #urlH=urllib.urlopen(self._v_qs)
76: #xml=urlH.read()
77: #urlH.close()
78: xsltproc=Processor()
79: logging.debug("start XML")
80: document = InputSource.DefaultFactory.fromUri(self._v_qs)
81:
82: stylesheet = InputSource.DefaultFactory.fromUri(self.xsl)
83: logging.debug("got all files XML")
84: xsltproc.appendStylesheet(stylesheet)
85: logging.debug("got all files do the transform")
86:
87: #print self.xsl
88: #< xsltproc.run(document)
89: tmp=xsltproc.run(document)
90:
91: self.result=tmp[0:]
92:
93:
94: except:
95:
96: self.result="<html>error: %s %s<br>"%sys.exc_info()[0:2]
97: self.result+=xml
98: self.result+="</html>"
99:
100:
101:
102: def getResult(self):
103:
104: return self.result
105:
106: from ZODB import DB
107: from ZODB.FileStorage import FileStorage
108: class ECHO_cache:
109: def __init__(self):
110: """init the storage"""
111: try:
112: self.storage=FileStorage(os.path.join(INSTANCE_HOME,"var/echo_cache.fs"))
113:
114: self.db=DB(self.storage)
115: self.connection=self.db.open()
116: self.root=self.connection.root()
117: except:
118: pass
119: def deleteObject(self,name,pn=None):
120: """delete an object from cache"""
121: fileStore=self.root.get(name,None)
122: if fileStore:
123: if not pn:
124: del(self.root[name])
125: else:
126: if self.root[name].get(pn,None):
127: del(self.root[name][pn])
128:
129:
130: def storeObject(self,name,pn,object):
131: """store an object"""
132:
133: if not self.root.get(name,None):
134: self.root[name]={}
135:
136:
137: #following is necessary to make clear that object has really changed for ZODB
138: tmp=self.root[name]
139: tmp[pn]=object
140: self.root[name]=tmp
141: transaction.get().commit()
142: return True
143:
144: def retrieveObject(self,name,pn):
145: """retrieve it"""
146:
147: fileStore=self.root.get(name,None)
148: if not fileStore:
149: return None
150: else:
151:
152: return self.root[name].get(pn,None)
153:
154:
155: class ECHO_xslt(ECHO_pageTemplate,ECHO_language):
156: """ECHO_xslt classe"""
157:
158: meta_type="ECHO_xslt"
159:
160: cache=ECHO_cache() # cache for analysed pages
161: caching="yes"
162:
163: appendQueryString=True # add query string to the cgiUrl can be changed with addChanges
164:
165: passURL=False #use url from querystring parameter fn to retrieve the text and not the url in cgi-url can be changed with addChanges
166:
167:
168: results={}
169: manage_options=ECHO_pageTemplate.manage_options+(
170: {'label':'Change xml-ressource','action':'change_ECHO_xsltForm'},)
171:
172: def refreshTxt(self):
173: """txt fuer refresh"""
174: return """ 2;url=%s?repeat=%s """%(self.absolute_url(),self.threadName)
175:
176: def xslt(self):
177: """xslt"""
178:
179: return self.document_src()
180:
181: def change_ECHO_xsltForm(self):
182: """change form"""
183: pt=zptFile(self, 'zpt/ChangeECHO_xsltForm.zpt')
184: return pt()
185:
186: def addChanges(self,cgiUrl,appendQueryString=False,passURL=False,caching=False,RESPONSE=None):
187: """change the xslt, ueberschriebt addChanges in ECHO_PageTemplate"""
188:
189: if urlparse.urlparse(cgiUrl)[0]=="":#relative url in absolute
190: self.cgiUrl=urlparse.urljoin(self.absolute_url(), cgiUrl)
191: else:
192: self.cgiUrl=cgiUrl
193:
194: if appendQueryString:
195: self.appendQueryString=True
196: else:
197: self.appendQueryString=False
198:
199: if passURL:
200: self.passURL=True
201: else:
202: self.passURL=False
203:
204: if caching:
205: self.caching="yes"
206: else:
207: self.caching="No"
208:
209:
210: if RESPONSE:
211: RESPONSE.redirect("manage_main")
212:
213: def index_html(self,repeat=None):
214: """standard ausgabe"""
215:
216: threadName=repeat
217:
218: if not threadName or threadName=="":
219:
220: #abwaertskompatibilitt mit altem nivht konfigurierbaren prototypen
221:
222: if getattr(self,'cgiUrl','')=='':
223: self.cgiUrl="http://medea.mpiwg-berlin.mpg.de/cgi-bin/search/q1"
224:
225: qs="%s%s"%(self.cgiUrl,self.REQUEST['QUERY_STRING'])
226: xsl=self.absolute_url()+"/xslt"
227: #self._v_xmltrans=getXML().__of__(self)
228: self._v_xmltrans=getXML()
229: #self._xmltrans.start()
230: #thread=Thread(target=self._v_xmltrans)
231: #thread.start()
232: logging.debug("Thread prepared")
233: self._v_xmltrans.set(qs,xsl,None)
234: self._v_xmltrans.start()
235: logging.debug("Thread started")
236:
237: #self.threadName=thread.getName()[0:]
238: self.threadName=self._v_xmltrans.getName()[0:]
239: wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['wait_template'])
240: if wait_template:
241: return wait_template[0][1]()
242: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','xsltWait.zpt')).__of__(self)
243: return pt()
244: #_v_xmltrans.run()
245:
246: else:
247:
248: if (self._v_xmltrans.getResult()==None):
249:
250: wait_template=self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['wait_template'])
251: if wait_template:
252: return wait_template[0][1]()
253:
254: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','xsltWait.zpt')).__of__(self)
255: return pt()
256: else:
257: return self._v_xmltrans.getResult()
258:
259:
260: def getText(self):
261: """print nur den text"""
262: qs,baseUri=self.getTextInput()
263: self.REQUEST.RESPONSE.redirect(qs)
264:
265: def deleteCache(self):
266: """deletefrom cache"""
267: fn=self.REQUEST['fn']
268: self.cache.deleteObject(fn)
269:
270:
271: def createLinkNode(self,url,dom):
272: """createa a link node"""
273: txt=dom.createTextNode("<XMLLink>")
274: node=dom.createElementNS("http://test.de","a")
275: node.setAttributeNS("http://test.de","href",url)
276: node.appendChild(txt)
277: return node
278:
279: def forwardLink(self,linkid,url,type="target",RESPONSE=None):
280: """forward to link"""
281: if RESPONSE:
282: RESPONSE.redirect(self.getLink(linkid,url,type=type))
283:
284: else:
285: return self.getLink(linkid,url,type=type)
286: def getLink(self,linkid,url,type="target"):
287: """get target for linkid"""
288: dom=NonvalidatingReader.parseUri(url)
289:
290: masterurl=dom.xpath("//mpiwg:masterurl/@ref",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
291: slaveurl=dom.xpath("//mpiwg:slaveurl/@ref",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
292:
293: #check now if there are in the link file
294:
295: xp="//mpiwg:link[@id='%s']"%linkid
296:
297: if type=="target":
298: for link in dom.xpath(xp,explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'}):
299: fn=link.xpath("mpiwg:target/@filename",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
300:
301: if urlparse.urlparse(urllib.unquote(fn))[0]=="http": # fn ist eine url
302: return urllib.unquote(fn) # dann gibt diese zurueck
303:
304: ref=link.xpath("mpiwg:target/@refid",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
305:
306: ref2=link.xpath("mpiwg:target/mpiwg:pagelink/@refid",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
307: selectionNodeIndex=link.xpath("mpiwg:target/mpiwg:pagelink/@selectionNodeIndex",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
308:
309:
310:
311: lstr=slaveurl+'fn='+fn+'&_id='+ref+'&_pagelink=%s///%s/%s/%s'%(ref2,selectionNodeIndex,linkid,'target')
312: lstr+="&_links="+urllib.quote(url)
313:
314: else:
315: for link in dom.xpath(xp,explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'}):
316: fn=link.xpath("mpiwg:source/@filename",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
317: if urlparse.urlparse(urllib.unquote(fn))[0]=="http": # fn ist eine url
318: return urllib.unquote(fn) # dann gibt diese zurueck
319:
320: ref=link.xpath("mpiwg:source/@refid",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
321:
322: ref2=link.xpath("mpiwg:source/mpiwg:pagelink/@refid",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
323: selectionNodeIndex=link.xpath("mpiwg:source/mpiwg:pagelink/@selectionNodeIndex",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
324:
325: lstr=masterurl+'fn='+fn+'&_id='+ref+'&_pagelink=%s///%s/%s/%s'%(ref2,selectionNodeIndex,linkid,'source')
326: lstr+="&_links="+urllib.quote(url)
327: return lstr
328:
329: def addLinksUrl(self,txt,url):
330: """add reference to links to url"""
331: ret=[]
332: dom=NonvalidatingReader.parseUri(url)
333: textDom=NonvalidatingReader.parseString(txt)
334:
335: #find ids in txt
336: ids=textDom.xpath("//*[@id]")
337:
338: for textid in ids:
339: xp="//mpiwg:link[mpiwg:source/@refid='%s']"%textid.xpath("@id")[0].value
340: for link in dom.xpath(xp,explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'}):
341: ref2=link.xpath("mpiwg:source/mpiwg:pagelink/@refid",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
342: selectionNodeIndex=link.xpath("mpiwg:source/mpiwg:pagelink/@selectionNodeIndex",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
343: linkid=link.xpath("@id")[0].value
344: ret.append('%s///%s/%s/%s'%(ref2,selectionNodeIndex,linkid,'source'))
345:
346: xp="//mpiwg:link[mpiwg:target/@refid='%s']"%textid.xpath("@id")[0].value
347: for link in dom.xpath(xp,explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'}):
348: ref2=link.xpath("mpiwg:target/mpiwg:pagelink/@refid",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
349: selectionNodeIndex=link.xpath("mpiwg:target/mpiwg:pagelink/@selectionNodeIndex",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
350: linkid=link.xpath("@id")[0].value
351: ret.append('%s///%s/%s/%s'%(ref2,selectionNodeIndex,linkid,'target'))
352:
353:
354: return ret
355:
356: def addLinks(self,txt,url="http://127.0.0.1:8080/HFQP/linkCreator/getCollectionXML?collection=commentary2"):
357: """add links to a page from xml linkfile"""
358:
359: dom=NonvalidatingReader.parseUri(url)
360: textDom=NonvalidatingReader.parseString(txt)
361:
362: #find ids in txt
363: ids=textDom.xpath("//*[@id]")
364: masterurl=dom.xpath("//mpiwg:masterurl/@ref",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
365: slaveurl=dom.xpath("//mpiwg:slaveurl/@ref",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
366:
367: #check now if there are in the link file
368: for textid in ids:
369: xp="//mpiwg:link[mpiwg:source/@refid='%s']"%textid.xpath("@id")[0].value
370: for link in dom.xpath(xp,explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'}):
371: fn=link.xpath("mpiwg:target/@filename",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
372: print fn
373: if urlparse.urlparse(urllib.unquote(fn))[0]=="http": # fn ist eine url
374: lstr=urllib.unquote(fn) # dann gibt diese zurueck
375: else:
376: try:
377: ref=link.xpath("mpiwg:target/@refid",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
378:
379: ref2=link.xpath("mpiwg:target/mpiwg:pagelink/@refid",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
380: selectionNodeIndex=link.xpath("mpiwg:target/mpiwg:pagelink/@selectionNodeIndex",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
381: linkid=link.xpath("@id")[0].value
382: lstr=slaveurl+'fn='+fn+'&_id='+ref+'&_pagelink=%s///%s/%s/%s'%(ref2,selectionNodeIndex,linkid,'target')
383: lstr+="&_links="+urllib.quote(url)
384: except:
385: lstr=""
386: node=self.createLinkNode(lstr,textDom)
387: textid.parentNode.insertBefore(node,textid)
388:
389:
390: xp="//mpiwg:link[mpiwg:target/@refid='%s']"%textid.xpath("@id")[0].value
391: for link in dom.xpath(xp,explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'}):
392: fn=link.xpath("mpiwg:source/@filename",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
393: if urlparse.urlparse(urllib.unquote(fn))[0]=="http": # fn ist eine url
394: lstr=urllib.unquote(fn) # dann gibt diese zurueck
395: else:
396:
397: ref=link.xpath("mpiwg:source/@refid",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
398:
399: ref2=link.xpath("mpiwg:source/mpiwg:pagelink/@refid",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
400: selectionNodeIndex=link.xpath("mpiwg:source/mpiwg:pagelink/@selectionNodeIndex",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})[0].value
401: linkid=link.xpath("@id")[0].value
402: lstr=masterurl+'fn='+fn+'&_id='+ref+'&_pagelink=%s///%s/%s/%s'%(ref2,selectionNodeIndex,linkid,"source")
403: lstr+="&_links="+urllib.quote(url)
404:
405: node=self.createLinkNode(lstr,textDom)
406: textid.parentNode.insertBefore(node,textid)
407:
408:
409:
410: strio = StringIO()
411: PrettyPrint(textDom,strio)
412: xmlstr = strio.getvalue()
413:
414: return xmlstr
415:
416:
417:
418: def getPageLex(self,_pn="1",_id=None,_caching=None,_links=None,_showall="no",_displaylinks="yes"):
419: """getpage mit lexikalischer analyse und xslt transform
420: if _caching=yes dann wird die lwxikalisch analysierte seite in einem cache abgespeichert
421: """
422: def encode(hash):
423: ret=[]
424: for x in hash.keys():
425: value=hash[x]
426:
427: if type(value) is ListType:
428: for z in value:
429: ret.append("%s=%s"%(x,z))
430: else:
431: ret.append("%s=%s"%(x,value))
432: return "&".join(ret)
433:
434:
435:
436: if not _caching:
437: _caching=self.caching
438:
439: fn=self.REQUEST['fn']
440:
441: if not _id:
442:
443: fromCache=self.cache.retrieveObject(fn,_pn)
444:
445: if fromCache and _caching=="yes":
446:
447: txt = fromCache
448: else:
449: txt=self.tagLex(nr=_pn)
450:
451: self.cache.storeObject(fn,_pn,txt[0:])
452:
453: else:
454: txt=self.tagLex(id=_id)
455:
456: if _showall=="yes":
457: params=cgi.parse_qs(self.REQUEST['QUERY_STRING'])
458:
459: params['_pagelink']=self.addLinksUrl(txt,url=_links)
460: params['_showall']='no'
461:
462: print self.absolute_url()+"?"+encode(params)
463: self.REQUEST.RESPONSE.redirect(self.absolute_url()+"/getPageLex?"+encode(params))
464:
465:
466: xsl=self.xslt()
467:
468: xsltproc=Processor()
469: if type(txt)==UnicodeType:
470: document = InputSource.DefaultFactory.fromString(txt.encode('utf-8'))
471: else:
472: document = InputSource.DefaultFactory.fromString(txt)
473: stylesheet = InputSource.DefaultFactory.fromString(xsl)
474: xsltproc.appendStylesheet(stylesheet)
475: tmp=xsltproc.run(document)
476:
477: if _links and (_displaylinks=='yes'):
478: _links=urllib.unquote(_links)
479: tmp=self.addLinks(tmp,url=_links)
480:
481: #bugfix for digilib images which doesn't accept &
482: tmp=tmp.replace("&","&")
483:
484:
485: return tmp[0:]
486:
487: def getTextInput(self):
488: """get the text
489: wie der text geholt wird liegt an der konfiguration,
490: is appendQueryString gesetzt, dann wir jeweils der Querystring an vorgebenen url gesetzt, erwartet wird fn=
491: fr den Pfad, is passURL gesetzt, dann wird falls fn= eine vollstndige url enthlt, diese anstelle der in cgiurl definierten genommen.
492: """
493:
494: if getattr(self,'passURL',False) and self.REQUEST.has_key('fn') and (urlparse.urlparse(self.REQUEST['fn'])[0]=='http'):
495: qs=self.REQUEST['fn']
496: baseUri=qs
497: elif getattr(self,'pappendQueryString',True):
498: qs="%s%s"%(self.cgiUrl,self.REQUEST['QUERY_STRING'])
499: baseUri=self.cgiUrl
500: else:
501: qs="%s"%(self.cgiUrl)
502: baseUri=self.cgiUrl
503:
504: #fact= InputSource.DefaultFactory.fromUri(qs)
505: return qs,baseUri
506: #return InputSource.InputSource(fact)
507: #xmlt=urllib.urlopen(qs).read()
508:
509: def getPage(self,_pn="-1",_id=None,REQUEST=None,_caching=None):
510: """get a page from an xml"""
511:
512: if not _caching:
513: _caching=self.caching
514:
515: pn=int(_pn)-1
516: if pn<0 and (not _id):
517: if REQUEST:
518: return "Sorry, pagenumbers have to be greater than 0"
519: else:
520: return None
521:
522: xmlt,self.baseUri=self.getTextInput()
523:
524: #get the text from cache, if existing
525: try:
526: fromCache=self.cache.retrieveObject(self.baseUri,"-1")
527: except:
528: fromCache=None
529: if fromCache and _caching=="yes":
530:
531: txt = fromCache
532: else:
533:
534: txt=urllib.urlopen(xmlt).read()
535:
536: self.cache.storeObject(self.baseUri,"-1",txt)
537:
538:
539: dom=NonvalidatingReader.parseString(txt,self.baseUri)
540:
541: #pb should have a namespache
542:
543: pbs=dom.xpath("//mpiwg:pb",explicitNss={'mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})
544:
545: if len(pbs)==0: # versuche nochmal ohne
546: pbs=dom.xpath("//pb")
547:
548: if _id:
549: #suche wieviele pb for der id
550:
551:
552: idpb=dom.xpath("//*[@id='%s']/preceding::node()/mpiwg:pb"%_id,explicitNss={'html':'http://www.w3.org/1999/xhtml','mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'})
553: if len(idpb)==0:
554: idpb=dom.xpath("//*[@id='%s']/preceding::node()/pb"%_id)
555:
556: if len(idpb)==0:
557: k=0
558: for node in dom.xpath("//*[@id='%s']//preceding::node()"%_id,explicitNss={'html':'http://www.w3.org/1999/xhtml','mpiwg':'http://www.mpiwg-berlin.mpg.de/namespace'}):
559: if getattr(node,'tagName',"")=="mpiwg:pb":
560: k+=1
561: else:
562: k=len(idpb)
563: #pn=k-1 #-1 wegen Seitenzahlzaehlung startet mit 0
564: pn=k-1 #-1 wegen Seitenzahlzaehlung startet mit 0
565: if pn > len(pbs):
566: if REQUEST:
567: return "Sorry, pagenumber %s does not exit"%(pn+1)
568: else:
569: return None
570:
571: beginNode=pbs[pn] #take the n'th pb
572:
573: if not (pn==len(pbs)-1): # nicht die letzte Seite
574: endNode=pbs[pn+1]
575: else:
576: endNode=None
577:
578: deleteNodes=beginNode.xpath('preceding::node()')
579: if endNode:
580: deleteNodes+=endNode.xpath('following::node()')
581: for node in deleteNodes:
582: try:
583: parent=node.xpath("..")
584:
585: if parent:
586: parent[0].removeChild(node)
587: except:
588: logger("ECHO_Resource (getAccessRightMD)", logging.INFO,"%s (%s)"%sys.exc_info()[0:2])
589: strio = StringIO()
590: PrettyPrint(dom,strio)
591: xmlstr = strio.getvalue()
592:
593: return xmlstr
594:
595:
596:
597: def manage_addECHO_xsltForm(self):
598: """Form for adding"""
599: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','AddECHO_xslt.zpt')).__of__(self)
600: return pt()
601:
602: from urllib import quote
603:
604:
605: def manage_addECHO_xslt(self, id, label, weight= 0,contentType=0,title=None, text=None, cgiUrl=None,
606: REQUEST=None, submit=None):
607: "Add a Page Template with optional file content."
608:
609:
610: id = str(id)
611: if REQUEST is None:
612: self._setObject(id, ECHO_xslt(id, text))
613: ob = getattr(self, id)
614: setattr(ob,'weight',weight)
615: setattr(ob,'label',label)
616: setattr(ob,'contentType',contentType)
617: if title:
618: ob.pt_setTitle(title)
619: return ob
620: setattr(ob,'cgiUrl',cgiUrl)
621: else:
622: file = REQUEST.form.get('file')
623: headers = getattr(file, 'headers', None)
624: if headers is None or not file.filename:
625: zpt = ECHO_xslt(id)
626: else:
627: zpt = ECHO_xslt(id, file, headers.get('contentType'))
628:
629: self._setObject(id, zpt)
630: ob = getattr(self, id)
631: setattr(ob,'weight',weight)
632: setattr(ob,'label',label)
633: setattr(ob,'cgiUrl',cgiUrl)
634: if title:
635: ob.pt_setTitle(title)
636:
637: try:
638: u = self.DestinationURL()
639: except AttributeError:
640: u = REQUEST['URL1']
641:
642: if submit == " Add and Edit ":
643: u = "%s/%s" % (u, quote(id))
644: REQUEST.RESPONSE.redirect(u+'/manage_main')
645: return ''
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>