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

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

resolving conflicts

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    return ds
40   
41def resolveXlink(csElement, csDocument):
42    '''takes a CSML element, containing Xlinks and resolves them within the csDocument'''
43    if hasattr(csElement, 'arcrole'):
44       usage=csElement.arcrole.split('#')[0]
45       elem=csElement.arcrole.split('#')[1]
46       #if usage=='http://ndg.nerc.ac.uk/xlinkUsage/insert':
47           #for child in csElement.CHILDREN:
48               ##print getattr(csElement, child).__class__
49               ##print csElement.CHILDREN
50               #if getattr(csElement, child).__class__ == elem:
51                   #print 'yes'
52   
53    return csDocument
Note: See TracBrowser for help on using the repository browser.