source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/retrieve.py @ 2643

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/retrieve.py@2643
Revision 2643, 3.9 KB checked in by lawrence, 12 years ago (diff)

Starting to put stubB handling into ows/browse.
Starting to add trackback support.

Line 
1
2from ows_server.lib.base import *
3from ows_server.models import ndgObject,  ndgRetrieve
4from paste.request import parse_querystring
5from ows_server.models import stubB
6
7#from ows_server.models import ndgRetrieve
8
9class RetrieveController(BaseController):
10    ''' Provides the pylons controller for retrieving NDG documents. The simple model
11    is now that an attempt to retrieve/uri will parse the uri, read the config file,
12    and if the local server name is not the same as the uri server name. '''
13   
14    def __setup(self,uri):
15        ''' Common setup stuff for all the actions on this controller '''
16        try:
17            self.uri=ndgObject.ndgObject(uri)
18        except ValueError,e:
19            return e
20        self.cf=request.environ['ndgConfig']
21        self.uri.setConfig(self.cf)
22        self.requestor=request.environ['REMOTE_ADDR']
23        self.logger=0
24        if logger: self.logger=logger
25        self.inputs=dict(parse_querystring(request.environ))
26        # it's kind of unfortunate that format=(xml,html) is what we expect in the
27        # url but at the retrieval level format is the schema ... oh well ...
28        self.format=''
29        if 'original' in self.inputs:
30            self.format={'0':'','1':'original'}[self.inputs['original']]
31        return 0
32       
33    def index(self,uri):
34        ''' Returns the document unadorned in anyway, i.e. the raw xml'''
35        status=self.__setup(uri)
36        if status: return Response(status)
37        status,x=ndgRetrieve.ndgRetrieve(
38                self.uri,self.cf,logger=self.logger,requestor=self.requestor,format=self.format)
39       
40        if status:
41            #(the return object x is an xmlHandler object)
42            xml=x.tohtml()
43            return Response(xml)
44        else:
45            return Response(xml)
46       
47    def view(self,uri):
48        ''' Returns either an html marked up version of the xml, or a properly laid
49        out version of the document '''
50        status=self.__setup(uri)
51        if status: return Response(status)
52        if 'ndgSec' in session:
53            securityTokens=session['ndgSec']
54        else: securityTokens=None
55        status,x=ndgRetrieve.ndgRetrieve(
56                self.uri,self.cf,logger=self.logger,requestor=self.requestor,format=self.format,
57                securityTokens=securityTokens)
58        c.title='Viewing [%s]'%self.uri
59       
60        if status:
61            #(the return object x is an xmlHandler object)
62            if self.uri.schema=='NDG-B1':
63                r='stubB'
64                c.doc=stubB.stubB(x.tree,self.cf)
65                c.tbinfo=self.__mytb()
66            elif self.uri.schema=='NDG-A0':
67                r='csml'
68            elif self.uri.schema=='DIF':
69                r='dif'
70            else:
71                c.xml=x.tohtml()
72                r='content'
73            if 'format' in self.inputs:
74                #override previous output choice if format is xml
75                if self.inputs['format']=='xml': 
76                    c.xml=x.tohtml()
77                    r='content'
78            f=file('debug.xml','w')
79            f.write(x.tohtml())
80            f.close()
81            g=file('debug2.xml','w')
82            g.write(str(x))
83            g.close()       
84        else: 
85            c.xml='<div class="error">%s</div>'%x
86            r='content'
87        return render_response(r)
88   
89   
90    def __mytb(self):
91        ''' Get the trackback info for this page
92        (can't do it in Kid because it doesn't do substutions in comments) '''
93        s='''<!--
94        <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
95             xmlns:dc="http://purl.org/dc/elements/1.1/"
96             xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
97        <rdf:Description
98            rdf:about="%s"
99            dc:identifier="%s"
100            dc:title="%s"
101            trackback:ping="%s" />
102        </rdf:RDF>
103        -->'''%(self.uri,g.server+h.url_for(),c.doc.name,g.server+h.url_for(controller="trackback"))
104        return s
Note: See TracBrowser for help on using the repository browser.