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