1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """The class CSMLdocBuild handles the construction of a CSMLdocument.at a higher level than direct parser interaction |
---|
4 | """ |
---|
5 | |
---|
6 | from cElementTree import * |
---|
7 | from Parser import * |
---|
8 | import elementtree.ElementTree as etree |
---|
9 | import sys |
---|
10 | import urlparse |
---|
11 | import string |
---|
12 | |
---|
13 | |
---|
14 | def isURI(uri): |
---|
15 | """ a very simple function to test if a string is a uri |
---|
16 | if ;// appears in the first 12 characters it is probably a uri """ |
---|
17 | #TODO - a decent uri check! |
---|
18 | result = False |
---|
19 | if string.find(uri[:12], '://') != -1: |
---|
20 | result = True |
---|
21 | return result |
---|
22 | |
---|
23 | |
---|
24 | ###################################################### |
---|
25 | ## The class CSMLdocBuild handles the construction of a CSMLdocument.at a higher level than direct parser interaction. |
---|
26 | ###################################################### |
---|
27 | |
---|
28 | class CSMLdocBuild: |
---|
29 | def __init__(docID, docMetaDataProperty): |
---|
30 | #initialise a new document |
---|
31 | #Create an Empty Dataset |
---|
32 | self.ds = Dataset() |
---|
33 | #Set objects as attributes of dataset |
---|
34 | |
---|
35 | #if docMetaDataProperty is a URI, set it as href attribute if MetaDataProperty instance, |
---|
36 | #else set it as a text attribute of a MetaDataProperty instance. |
---|
37 | mdp=MetaDataProperty() |
---|
38 | if isURI(docMetaDataProperty): |
---|
39 | mdp.href=docMetaDataProperty |
---|
40 | else: |
---|
41 | mdp.text = docMetaDataProperty |
---|
42 | self.ds.metaDataProperty= [mdp] |
---|
43 | #set the id |
---|
44 | self.ds.id=docID |
---|
45 | self.dm=[] #empty list to hold definition members (e.g. UnitDefinitions) |
---|
46 | self.fm=[] #empty list to hold feature members (e.g. GridFeatures, PointFeatures) |
---|
47 | self.ad=[] #empty list to hold array descriptors (e.g. NetCDFExtract) |
---|
48 | #the dataset is now initialised. now you can add features/defintions/arraydescriptors |
---|
49 | #using the methods supplied. |
---|
50 | #when finished building CSML objects call the consolidate method to return the document. |
---|
51 | |
---|
52 | #separate build classes for each feature type |
---|
53 | def buildPointFeature(self): |
---|
54 | pass |
---|
55 | return feat |
---|
56 | |
---|
57 | def buildProfileFeature(self): |
---|
58 | pass |
---|
59 | return feat |
---|
60 | |
---|
61 | def buildGridFeature(self): |
---|
62 | pass |
---|
63 | return feat |
---|
64 | |
---|
65 | def buildPointSeriesFeature(self): |
---|
66 | pass |
---|
67 | return feat |
---|
68 | |
---|
69 | def buildProfileSeriesFeature(self): |
---|
70 | pass |
---|
71 | return feat |
---|
72 | |
---|
73 | def buildGridSeriesFeature(self): |
---|
74 | pass |
---|
75 | return feat |
---|
76 | |
---|
77 | def buildTrajectoryFeature(self): |
---|
78 | pass |
---|
79 | return feat |
---|
80 | |
---|
81 | def addFeature(self,featureID): |
---|
82 | #Pass a feature and have it appended to the feature collection. |
---|
83 | pass |
---|
84 | |
---|
85 | def addFileExtract(self): |
---|
86 | #handles the addition of file extract classes (can probably get away with one method for all types of extracts) |
---|
87 | pass |
---|
88 | |
---|
89 | def removeFileExtract(self): |
---|
90 | #not implemented yet |
---|
91 | pass |
---|
92 | |
---|
93 | def removeFeature(self,featureID): |
---|
94 | #not implemented yet. |
---|
95 | pass |
---|
96 | def addDefintion(self): |
---|
97 | #not implemented yet. - may need separate methods for different defintion types? |
---|
98 | pass |
---|
99 | |
---|
100 | def removeDefintion(self): |
---|
101 | #not implemented yet. |
---|
102 | pass |
---|
103 | def consolidate(self): |
---|
104 | #when you have finished building the document, need to consolidate it and return a CSML document. |
---|
105 | return csmldoc |
---|