Changeset 772
- Timestamp:
- 07/04/06 17:13:21 (15 years ago)
- Location:
- TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/browseCGI.py
r765 r772 33 33 #try: 34 34 self.xml=insecureGetDoc(uri) 35 #self.xml=uri 35 36 #except: 36 37 # raise 'NotFound' … … 49 50 50 51 def toHTML(self): 51 return doXSLT(self.xml,self.xsltMethod) 52 52 x=doXSLT(self.xml,xsltMethod=self.xsltMethod) 53 #return '<p>%s</p>'%x 54 return x 55 53 56 class CGIcontroller: 54 57 ''' Currently holds the cgi environment and controls ''' -
TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/insecure.py
r769 r772 8 8 # 9 9 10 import os, os.path, tmpfile 10 import os 11 import os.path 12 import tempfile 11 13 12 14 def jarLoc(jar): 13 15 #don't want the jar in the cgi directory ... not quite sure why, but 14 #it seems wrong ... 16 #it seems wrong ... having made that decision, we have to bugger 17 #around with relative paths depending on whether this is test code 18 #(outside the cgi environment) or in the cgi environment 15 19 cwd=os.getcwd() 16 20 return os.path.normpath(os.path.join(cwd,jar)) 17 21 18 def insecureGetDoc(uri): 22 def osCommand(cmd): 23 stdin,stdout,stderr=os.popen3(cmd) 24 error=stderr.readlines() 25 if error !=[]: 26 return 1,error 27 else: 28 s='' 29 for i in stdout.readlines():s+=i 30 return 0,s 31 32 def insecureGetDoc(uri,jar='./returnmoles.jar'): 19 33 ''' Use Kevin's code to get the document from exist ''' 20 34 #we assume the URI is of the form repository/localid … … 25 39 return 'Invalid URI' 26 40 else: 27 returnMolesJar=jarLoc( './returnmoles.jar')41 returnMolesJar=jarLoc(jar) 28 42 cmd='java -jar %s %s %s xmldb:exist://glue.badc.rl.ac.uk:8080/exist/xmlrpc'%( 29 43 returnMolesJar,repPath,localID) 30 try: 31 stdin,stdout,stderr=os.popen3(cmd) 32 except: 33 return 'Unable to Obtain Document' 34 error=stderr.readlines() 35 if error!=[]: 36 #return returnMolesJar 37 return error 38 else: 39 return stdout.readlines() 44 status,result=osCommand(cmd) 45 return result 40 46 41 def doXSLT (document, xsltMethod):47 def doXSLT (document,jar='./xalan-j_2_7_0/xalan.jar',xsltMethod=None): 42 48 ''' Handle a possibly external transformation to produce an html page ''' 43 44 49 #use temporary files for the moment, ugly, but it will work. 45 50 # consider using pyana or some other way of doing this later ... 46 51 #try: 47 fn=tmpfile('ndg-xml') 52 #return 'done' 53 fn=tempfile.mktemp('.ndg-xml') 48 54 f=file(fn,'wb') 49 55 f.write(document) 50 56 f.close() 51 on=tmpfile('ndg-xml') 52 xalanjar=jarLoc('./xalan=j_2_7_0/xalan.jar') 53 xslt=jarLoc('./xslt') 54 cmd='java -cp %s -IN %s -XSL %s -OUT %s'%(xalanjar,fn,xslt,on) 55 57 on=tempfile.mktemp('.ndg-xml') 58 xalanjar=jarLoc(jar) 59 xslt=jarLoc('./xslt/stubb_2_browse.xsl') 60 cmd='java -cp %s org.apache.xalan.xslt.Process -IN %s -XSL %s -OUT %s'%(xalanjar,fn,xslt,on) 61 status,result=osCommand(cmd) 62 if status: 63 return result 64 else: 65 f=file(on,'r') 66 result='' 67 for i in f.readlines(): result+=i 68 f.close() 69 r=os.remove(fn) 70 r=os.remove(on) 71 return result 56 72 57 73 if __name__=="__main__": 58 print insecureGetDoc('badc.nerc.ac.uk/dataent13') 74 d= insecureGetDoc('badc.nerc.ac.uk/dataent13',jar='../returnmoles.jar') 75 #print d 76 dd=doXSLT(d,jar='../xalan-j_2_7_0/xalan.jar') 77 print dd
Note: See TracChangeset
for help on using the changeset viewer.