version 1.6, 2006/09/09 00:10:01
|
version 1.9, 2006/09/10 22:57:38
|
Line 7 from ECHO_Nav import ECHO_pageTemplate
|
Line 7 from ECHO_Nav import ECHO_pageTemplate
|
from threading import Thread,Timer |
from threading import Thread,Timer |
import threading |
import threading |
from ECHO_helpers import * |
from ECHO_helpers import * |
|
import ECHO_language |
import sys |
import sys |
import urllib |
import urllib |
import urlparse |
import urlparse |
from Ft.Xml.Domlette import Print, PrettyPrint |
from Ft.Xml.Domlette import Print, PrettyPrint |
|
from StringIO import StringIO |
|
from types import * |
from Globals import package_home |
from Globals import package_home |
|
import transaction |
|
|
import os.path |
import os.path |
|
|
Line 60 class getXML(Implicit):
|
Line 61 class getXML(Implicit):
|
def run(self): |
def run(self): |
"""call it""" |
"""call it""" |
xml="" |
xml="" |
print "X",self._v_qs |
|
try: |
try: |
|
|
urlH=urllib.urlopen(self._v_qs) |
urlH=urllib.urlopen(self._v_qs) |
Line 93 class getXML(Implicit):
|
Line 94 class getXML(Implicit):
|
|
|
return self.result |
return self.result |
|
|
|
from ZODB import DB |
|
from ZODB.FileStorage import FileStorage |
|
class ECHO_cache: |
|
def __init__(self): |
|
"""init the storage""" |
|
self.storage=FileStorage("/var/tmp/echo_cache.fs") |
|
self.db=DB(self.storage) |
|
self.connection=self.db.open() |
|
self.root=self.connection.root() |
|
|
|
def deleteObject(self,name,pn=None): |
|
"""delete an object from cache""" |
|
fileStore=self.root.get(name,None) |
|
if fileStore: |
|
if not pn: |
|
del(self.root[name]) |
|
else: |
|
if self.root[name].get(pn,None): |
|
del(self.root[name][pn]) |
|
|
|
|
|
def storeObject(self,name,pn,object): |
|
"""store an object""" |
|
|
|
if not self.root.get(name,None): |
|
self.root[name]={} |
|
|
|
|
|
#following is necessary to make clear that object has really changed for ZODB |
|
tmp=self.root[name] |
|
tmp[pn]=object |
|
self.root[name]=tmp |
|
transaction.get().commit() |
|
return True |
|
|
|
def retrieveObject(self,name,pn): |
|
"""retrieve it""" |
|
|
|
fileStore=self.root.get(name,None) |
|
if not fileStore: |
|
return None |
|
else: |
|
return self.root[name].get(pn,None) |
|
|
|
|
class ECHO_xslt(ECHO_pageTemplate): |
class ECHO_xslt(ECHO_pageTemplate,ECHO_language.ECHO_language): |
"""ECHO_xslt classe""" |
"""ECHO_xslt classe""" |
|
|
meta_type="ECHO_xslt" |
meta_type="ECHO_xslt" |
|
|
|
cache=ECHO_cache() |
|
|
results={} |
results={} |
manage_options=ECHO_pageTemplate.manage_options+( |
manage_options=ECHO_pageTemplate.manage_options+( |
{'label':'Change xml-ressource','action':'change_ECHO_xsltForm'},) |
{'label':'Change xml-ressource','action':'change_ECHO_xsltForm'},) |
Line 172 class ECHO_xslt(ECHO_pageTemplate):
|
Line 218 class ECHO_xslt(ECHO_pageTemplate):
|
return self._v_xmltrans.getResult() |
return self._v_xmltrans.getResult() |
|
|
|
|
def getPage(self,pn): |
|
|
def deleteCache(self): |
|
"""deletefrom cache""" |
|
fn=self.REQUEST['fn'] |
|
self.cache.deleteObject(fn) |
|
|
|
def getPageLex(self,_pn="1",_caching="yes"): |
|
"""getpage mit lexikalischer analyse und xslt transform |
|
if _caching=yes dann wird die lwxikalisch analysierte seite in einem cache abgespeichert |
|
""" |
|
|
|
fn=self.REQUEST['fn'] |
|
|
|
|
|
fromCache=self.cache.retrieveObject(fn,_pn) |
|
|
|
if fromCache and _caching=="yes": |
|
print "retrieve",fn,_pn |
|
txt = fromCache |
|
else: |
|
txt=self.tagLex(nr=_pn) |
|
print "store",fn,_pn |
|
self.cache.storeObject(fn,_pn,txt[0:]) |
|
|
|
xsl=self.xslt() |
|
|
|
xsltproc=Processor() |
|
if type(txt)==UnicodeType: |
|
document = InputSource.DefaultFactory.fromString(txt.encode('utf-8')) |
|
else: |
|
document = InputSource.DefaultFactory.fromString(txt) |
|
stylesheet = InputSource.DefaultFactory.fromString(xsl) |
|
xsltproc.appendStylesheet(stylesheet) |
|
tmp=xsltproc.run(document) |
|
|
|
return tmp[0:] |
|
|
|
|
|
def getPage(self,_pn,REQUEST=None): |
"""get a page from an xml""" |
"""get a page from an xml""" |
pn=int(pn) |
pn=int(_pn)-1 |
|
if pn<0: |
|
if REQUEST: |
|
return "Sorry, pagenumbers have to be greater than 0" |
|
else: |
|
return None |
impl=xml.dom.getDOMImplementation() |
impl=xml.dom.getDOMImplementation() |
newDoc=impl.createDocument(EMPTY_NAMESPACE,None,None |
newDoc=impl.createDocument(EMPTY_NAMESPACE,None,None |
) |
) |
root=newDoc.createElement('page') |
root=newDoc.createElement('page') |
newDoc.appendChild(root) |
newDoc.appendChild(root) |
|
|
xmlt=urllib.urlopen("%s"%self.cgiUrl).read() |
|
|
qs="%s%s"%(self.cgiUrl,self.REQUEST['QUERY_STRING']) |
|
|
|
|
|
|
|
xmlt=urllib.urlopen(qs).read() |
dom=Parse(xmlt) |
dom=Parse(xmlt) |
|
|
pbs=dom.xpath("//pb") |
pbs=dom.xpath("//pb") |
|
if pn > len(pbs): |
|
if REQUEST: |
|
return "Sorry, pagenumber %s does not exit"%pn+1 |
|
else: |
|
return None |
|
|
beginNode=pbs[pn] #take the n'th pb |
beginNode=pbs[pn] #take the n'th pb |
|
|
|
if not (pn==len(pbs)-1): # nicht die letzte Seite |
endNode=pbs[pn+1] |
endNode=pbs[pn+1] |
follower=beginNode.xpath('following::node()') |
else: |
#root.appendChild(beginNode) |
endNode=None |
found=[] |
|
|
|
for node in endNode.xpath('preceding::node()'): |
# follower=beginNode.xpath('following::node()') |
if node in follower: |
# #root.appendChild(beginNode) |
found.append(node) |
# found=[] |
|
# |
|
# for node in endNode.xpath('preceding::node()'): |
|
# if node in follower: |
|
# found.append(node) |
|
# |
|
|
|
|
#rempove all children of parents which are also in the list |
#rempove all children of parents which are also in the list |
for x in found: |
# for x in found: |
for child in x.xpath(".//*"): |
# for child in x.xpath(".//*"): |
|
# try: |
|
# |
|
# nr=found.index(child) |
|
# |
|
# del(found[nr]) |
|
# except: |
|
# pass |
|
# |
|
# found.append(endNode) |
|
# |
|
deleteNodes=beginNode.xpath('preceding::node()') |
|
if endNode: |
|
deleteNodes+=endNode.xpath('following::node()') |
|
for node in deleteNodes: |
try: |
try: |
|
parent=node.xpath("..") |
|
|
nr=found.index(child) |
if parent: |
|
parent[0].removeChild(node) |
del(found[nr]) |
|
except: |
except: |
pass |
zLOG.LOG("ECHO_Resource (getAccessRightMD)", zLOG.INFO,"%s (%s)"%sys.exc_info()[0:2]) |
|
strio = StringIO() |
found.append(endNode) |
PrettyPrint(dom,strio) |
|
xmlstr = strio.getvalue() |
|
|
for x in found: |
return xmlstr |
PrettyPrint(x) |
|
|
|
|
|
|
|