- Timestamp:
- 15/09/08 10:41:44 (13 years ago)
- Location:
- exist/trunk/python/ndgUtils
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
exist/trunk/python/ndgUtils/ndgObject.py
r4187 r4196 6 6 (1) a downloadable xml representation from a repository, 7 7 (2) a printable xml representation ''' 8 8 9 9 # The various different document types: 10 10 MOLES_DOC_TYPE = 'NDG-B0' … … 19 19 ATOM_DOC_TYPE = 'ATOM' 20 20 ATOM_BACKUP_DOC_TYPE = 'ATOM-BACKUP' 21 22 # various namespaces used in the docs 23 ATOM_NS = 'http://www.w3.org/2005/Atom' 24 MOLES_NS = 'http://ndg.nerc.ac.uk/schema/moles2alpha' 25 GEOSS_NS = 'http://www.georss.org/georss' 26 GML_NS = 'http://www.opengis.net/gml' 21 27 22 28 # Group the doc types according to the source they should be retrieved from … … 26 32 NUMSIM_DOC_TYPE, ATOM_DOC_TYPE, \ 27 33 ATOM_BACKUP_DOC_TYPE] 28 34 29 35 def __init__(self,uri,config=None): 30 36 ''' Parse the uri and prepare for obtaining the actual content''' … … 145 151 #now, we'll build a stub-B url as well, in case that comes in handy 146 152 if self.schema!='NumSim' and self.gettable<>-1: 147 self.BURL=discoveryBASE.replace(self.schema,'NDG-B1') 153 if self.schema: 154 self.BURL=discoveryBASE.replace(self.schema,'NDG-B1') 148 155 if server: 149 156 self.BURL=self.BURL.replace(server,servicehost) -
exist/trunk/python/ndgUtils/ndgSearch.py
r4187 r4196 34 34 # 35 35 36 default_HostAndPort="http:// localhost:8080/axis2/services/DiscoveryService"36 default_HostAndPort="http://ndg.badc.rl.ac.uk:8080/axis2/services/DiscoveryService" 37 37 38 38 class ndgSearch: … … 98 98 etime=time.time()-itime 99 99 logging.debug('Search Request [%s] took [%ss]'%(term,etime)) 100 100 101 # NB, set default and only change this if response lists Hits - this 102 # can return 'None' - so isn't reliable var to set to without checking 103 self.hits = 0 104 if response.Hits: 105 self.hits = response.Hits 106 101 107 if response._status: 102 108 self.serverSessionID=response._resultId 103 self.hits=response.Hits104 109 self.documents=response.Documents.Document 105 else:106 self.hits=response.Hits107 110 108 111 logging.info("Search returned %s results: %s" %(self.hits, self.documents)) … … 225 228 #so we know that the following call is the problem ... 226 229 responses=self.getAllDocs(format) 230 227 231 i=len(self.documents) 228 232 j=len(responses) -
exist/trunk/python/ndgUtils/xmlHandler2.py
r4050 r4196 13 13 14 14 from xml.parsers.expat import ExpatError 15 import StringIO, re 15 import StringIO, re, logging 16 16 XMLHDR='<?xml version="1.0"' 17 17 from ETxmlView import subAI … … 24 24 - load up an element-tree 25 25 - collect a namespace map ''' 26 26 logging.info("Reading in XML file - to create an elementtree object") 27 27 self.cleanup=subAI() 28 28 … … 52 52 self.__getns() 53 53 54 55 54 self.tree=ET.XML(self.xmls) 56 55 self.__updatens() 56 logging.info("XML file read into elementtree object") 57 57 58 58 def __getns(self): … … 61 61 #ought to do this with a regular expression, but needs must 62 62 # or bettter yet, use iterparse in the first place, but that seemed slow. 63 64 65 63 self.defns=None 66 64 if self.xmls[0:19]==XMLHDR: … … 176 174 return h 177 175 178 def _distributens(self,xpathExpression): 179 ''' Actually we only support tag finding in this ''' 180 if self.defns is None: return xpathExpression 176 def _distributens(self, xpathExpression, alternativeNS=None): 177 ''' 178 Update xpath expression to include namespaces. NB, the 179 default doc NS is used if available and if the keyword, 'alternativeNS' 180 has not been set to specify a different namespace 181 @param xpathExpression: xpath expression to update with namespace 182 @type xpathExpression: str 183 @keyword alternativeNS: alternative namespace to decorate the xpath 184 expression with 185 @type alternativeNS: str 186 @return: xpath expression with name space decoration 187 ''' 188 logging.debug("Adding namespace to xpath expression, '%s'" \ 189 %xpathExpression) 190 if self.defns is None and not alternativeNS: 191 logging.debug("- no namespace specified - returning") 192 return xpathExpression 193 181 194 tags=xpathExpression.split('/') 182 195 new='' 196 ns = (alternativeNS or self.defns) 183 197 for t in tags: 184 198 if t[1]<>'{': 185 new+='{%s}%s/'%( self.defns,t)199 new+='{%s}%s/'%(ns, t) 186 200 else: 187 201 new+=t+'/' 188 202 new=new[0:-1] 203 logging.debug("- added namespace, '%s'" %ns) 204 logging.debug("- final xpath expression, '%s'" %new) 189 205 return new 190 206
Note: See TracChangeset
for help on using the changeset viewer.