source: TI02-CSML/trunk/csml/csmllibs/csmlxlink.py @ 2741

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI02-CSML/trunk/csml/csmllibs/csmlxlink.py@2741
Revision 2741, 2.5 KB checked in by domlowe, 13 years ago (diff)

Changes to allow xlinking of timeposition lists. Changes to scanner and parser code. Now need to rescan coapec test data fully

Line 
1
2'''csmlxlink - contains functions used for processin xlinks in csml documents.
3created 23 01 2007 by Dominic Lowe, CCLRC, BADC
4'''
5
6import sys
7import csml
8
9def createXlinks(dataset):
10    '''returns a CSMLStorageDescriptor with any fileLists reduced to xlinks to other fileLists where possible.
11    e.g if 3 features share the same fileList, the fileList will be explicit in the first feature, and referenced only by xlink from the second 2 features.
12    This function compares the fileLists of all AggregatedArrays  in the CSMLStorageDescriptor and looks for matching fileLists'''
13    ds=dataset
14    if not hasattr(ds, 'storageDescriptor'):
15        return None
16    else:
17        #xlinkDictionary = {axislabel_axisspanned :(values, gmlid), .... }
18        #process:
19        #go through each ordinate in each domain for each feature.
20        #if ordinate (exact match with labels, span + value) is not in dictionary add it
21        #and create a new gml id.
22        #else if it is in the dictionary, get the gml id and replace the ordinate values with an xlink.
23        xlinkDictionary = {}
24        for descriptor in ds.storageDescriptor.descriptors:
25            if type(descriptor)==csml.parser.AggregatedArray:
26                for comp in descriptor.components:
27                    fID=comp.fileList.fileNames.CONTENT
28                    if fID in xlinkDictionary:
29                        #replace content with xlink
30                        gmlid=xlinkDictionary[fID][1]
31                        setattr(comp, 'fileListXLINK', csml.parser.csString())
32                        comp.fileListXLINK.href='#%s'%gmlid
33                        del comp.fileList
34                    else:
35                        #add to dictionary & set gml:id attribute
36                        newid=csml.csmllibs.csmlextra.getRandomID()
37                        xlinkDictionary[fID]=(fID, newid)
38                        comp.fileList.id=newid
39
40    return ds
41   
42def resolveXlink(csElement, csDocument):
43    '''takes a CSML element, containing Xlinks and resolves them within the csDocument'''
44    if hasattr(csElement, 'arcrole'):
45       usage=csElement.arcrole.split('#')[0]
46       elem=csElement.arcrole.split('#')[1]
47       #if usage=='http://ndg.nerc.ac.uk/xlinkUsage/insert':
48           #for child in csElement.CHILDREN:
49               ##print getattr(csElement, child).__class__
50               ##print csElement.CHILDREN
51               #if getattr(csElement, child).__class__ == elem:
52                   #print 'yes'
53   
54    return csDocument
Note: See TracBrowser for help on using the repository browser.