Package advene :: Package model :: Module annotation
[hide private]
[frames] | no frames]

Source Code for Module advene.model.annotation

  1  # 
  2  # Advene: Annotate Digital Videos, Exchange on the NEt 
  3  # Copyright (C) 2008 Olivier Aubert <olivier.aubert@liris.cnrs.fr> 
  4  # 
  5  # Advene is free software; you can redistribute it and/or modify 
  6  # it under the terms of the GNU General Public License as published by 
  7  # the Free Software Foundation; either version 2 of the License, or 
  8  # (at your option) any later version. 
  9  # 
 10  # Advene is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  # GNU General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU General Public License 
 16  # along with Advene; if not, write to the Free Software 
 17  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 18  # 
 19  import time 
 20   
 21  import util.uri 
 22   
 23  from util.auto_properties import auto_properties 
 24   
 25  import _impl 
 26  import bundle 
 27  import content 
 28  import modeled 
 29  import viewable 
 30   
 31  from advene.model.constants import adveneNS 
 32   
 33  from exception import AdveneException 
 34  from fragment import fragmentFactory, unknownFragment 
 35   
 36  from advene.model.util.defaultdict import DefaultDict 
 37   
38 -class Annotation(modeled.Importable, content.WithContent, 39 viewable.Viewable.withClass('annotation','_get_type_uri'), 40 _impl.Authored, _impl.Dated, _impl.Uried, _impl.Tagged):
41 42 __metaclass__ = auto_properties 43
44 - def getNamespaceUri(): return adveneNS
45 getNamespaceUri = staticmethod(getNamespaceUri) 46
47 - def getLocalName(): return "annotation"
48 getLocalName = staticmethod(getLocalName) 49
50 - def __init__(self, # mode 1 & 2 51 parent, # mode 1 & 2 52 element = None, # mode 1, required 53 type = None, # mode 2, required 54 fragment = None, # mode 2, required 55 ident = None, # mode 2, optional 56 date = None, # mode 2, optional 57 author = None, # mode 2, optional 58 authorUrl = None, # mode 2, optional 59 context = None, # mode 2, optional 60 content_data = None, # mode 2, optional 61 content_stream = None,# mode 2, optional 62 ):
63 """ 64 The constructor has two modes of calling 65 - giving it a DOM element (constructing from XML) 66 - giving it type,fragment,[ident],[date],[author],[authorUrl], 67 [context],[content_data|content_stream] (constructing from scratch) 68 """ 69 70 _impl.Uried.__init__(self, parent=parent) 71 self.__fragment = None 72 73 self._relations = [] # backrefs cache for relations 74 75 self._cached_type = type 76 77 if element is not None: 78 # should be mode 1, checking parameter consistency 79 if type is not None: 80 raise TypeError("incompatible parameter 'type'") 81 if fragment is not None: 82 raise TypeError("incompatible parameter 'fragment'") 83 if ident is not None: 84 raise TypeError("incompatible parameter 'ident'") 85 if date is not None: 86 raise TypeError("incompatible parameter 'date'") 87 if author is not None: 88 raise TypeError("incompatible parameter 'author'") 89 if authorUrl is not None: 90 raise TypeError("incompatible parameter 'authorUrl'") 91 if context is not None: 92 raise TypeError("incompatible parameter 'context'") 93 if content_data is not None: 94 raise TypeError("incompatible parameter 'content_data'") 95 if content_stream is not None: 96 raise TypeError("incompatible parameter 'content_stream'") 97 98 # mode 1 initialization 99 modeled.Importable.__init__(self, element, parent) 100 _impl.Uried.__init__(self, parent=self.getOwnerPackage()) 101 102 else: 103 # should be mode 2, checking parameter consistency 104 if type is None: 105 raise TypeError("parameter 'type' required") 106 if fragment is None: 107 raise TypeError("parameter 'fragment' required") 108 109 # mode 2 initialization 110 doc = parent._getDocument() 111 element = doc.createElementNS(Annotation.getNamespaceUri(), 112 Annotation.getLocalName()) 113 modeled.Importable.__init__(self, element, parent) 114 115 e = doc.createElementNS(None,"dummyFragment") 116 self._getModel().appendChild(e) 117 118 self.setType(type) 119 # TODO: check that type is referenced in package 120 self.setFragment(fragment) 121 122 if ident is None: 123 # FIXME: cf thread 124 # Weird use of hash() -- will this work? 125 # http://mail.python.org/pipermail/python-dev/2001-January/011794.html 126 ident = u"a" + unicode(id(self)) + unicode(time.clock()).replace('.','') 127 self.setId(ident) 128 129 if date is not None: self.setDate(date) 130 if