source: mauRepo/CedaManager/trunk/ceda_markup/atom/entry.py @ 8369

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/CedaManager/trunk/ceda_markup/atom/entry.py@8369
Revision 8369, 5.1 KB checked in by mnagni, 7 years ago (diff)

CedaManager? contains python class definition for many markup languages used in ceda projects

  • Property svn:mime-type set to text/plain
Line 
1'''
2BSD Licence
3Copyright (c) 2012, Science & Technology Facilities Council (STFC)
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without modification,
7are permitted provided that the following conditions are met:
8
9    * Redistributions of source code must retain the above copyright notice,
10        this list of conditions and the following disclaimer.
11    * Redistributions in binary form must reproduce the above copyright notice,
12        this list of conditions and the following disclaimer in the documentation
13        and/or other materials provided with the distribution.
14    * Neither the name of the Science & Technology Facilities Council (STFC)
15        nor the names of its contributors may be used to endorse or promote
16        products derived from this software without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29Created on 24 May 2012
30
31@author: Maurizio Nagni
32'''
33from xml.etree.ElementTree import Element, SubElement
34
35class Entry(object):
36    '''
37    classdocs
38    '''
39
40
41    def __init__(self, iid, title, updated, \
42                 author = None, content = None, link = None, \
43                 summary = None, category = None, contributor = None, \
44                 published = None, source = None, rights = None):
45        '''
46            Constructor
47            @param id: a unique identifier, eventually an URI
48            @param title: an atom.Entry instance
49            @param updated: the last time the record was updated
50            @param author: one or more atom.Author instances
51            @param content: an atom.Content instance             
52            @param link: one or more atom.Link instances
53            @param summary: an atom.Summary instance                       
54            @param category:             
55            @param contributor: one or more atom.Contributor instances
56            @param published:                         
57            @param source:
58            @param rights: an atom.Rights instance                       
59        '''
60        self.id = iid
61        self.title = title
62        self.updated = updated       
63       
64        if author:
65            self.author = author
66       
67        if content is not None:
68            self.content = content
69                   
70        if link:
71            self.link = link
72           
73        if summary:
74            self.summary = summary
75           
76        if category:
77            self.category = category
78           
79        if contributor:
80            self.contributor = contributor                                   
81                       
82        if published:
83            self.published = published
84           
85        if source:
86            self.source = source                   
87           
88        if rights:
89            self.rights = rights
90                       
91    def buildElement(self):
92        entry = Element("entry")
93       
94        iid = SubElement(entry, 'id')
95        iid.text = self.id
96       
97        title = SubElement(entry, 'title')
98        title.text = self.title
99       
100        updated = SubElement(entry, 'updated')
101        updated.text = self.updated
102       
103        if hasattr(self, 'author'):
104            if isinstance(self.author, list):
105                entry.extend(self.author)
106            else:
107                entry.append(self.author)
108               
109        if hasattr(self, 'contributor'):
110            if isinstance(self.contributor, list):
111                entry.extend(self.contributor)
112            else:
113                entry.append(self.contributor)               
114               
115        if hasattr(self, 'content'):
116            entry.append(self.content)
117           
118        if hasattr(self, 'link'):
119            link = SubElement(entry, 'link')
120            link.text = self.link
121           
122        if hasattr(self, 'summary'):
123            summary = SubElement(entry, 'summary')
124            summary.text = self.summary
125
126        if hasattr(self, 'category'):
127            if isinstance(self.category, list):
128                entry.extend(self.category)
129            else:
130                entry.append(self.category)
131                                           
132        if hasattr(self, 'published'):
133            published = SubElement(entry, 'published')
134            published.text = self.published             
135           
136        if hasattr(self, 'source'):
137            source = SubElement(entry, 'source')
138            source.text = self.source         
139       
140        return entry 
Note: See TracBrowser for help on using the repository browser.