Back to index

plone3  3.1.7
adobens.py
Go to the documentation of this file.
00001 ##################################################################
00002 # Marshall: A framework for pluggable marshalling policies
00003 # Copyright (C) 2004 EnfoldSystems, LLC
00004 # Copyright (C) 2004 ObjectRealms, LLC
00005 #
00006 # This program is free software; you can redistribute it and/or modify
00007 # it under the terms of the GNU General Public License as published by
00008 # the Free Software Foundation; either version 2 of the License, or
00009 # (at your option) any later version.
00010 #
00011 # This program is distributed in the hope that it will be useful,
00012 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 # GNU General Public License for more details.
00015 #
00016 # You should have received a copy of the GNU General Public License
00017 # along with this program; if not, write to the Free Software
00018 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ##################################################################
00020 
00021 """
00022 $Id: $
00023 """
00024 
00025 from DateTime import DateTime
00026 
00027 from Products.Marshall.handlers.atxml import XmlNamespace
00028 from Products.Marshall.handlers.atxml import SchemaAttribute
00029 
00030 
00031 RNGSchemaFragment = '''
00032   <define name="DateInfo"
00033           xmlns:xmp="adobe:ns:meta"
00034           datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
00035           xmlns="http://relaxng.org/ns/structure/1.0">
00036         <zeroOrMore>
00037           <element name="xmp:CreateDate"><data type="dateTime" /></element>
00038         </zeroOrMore>
00039         <zeroOrMore>
00040           <element name="xmp:ModifyDate"><data type="dateTime" /></element>
00041         </zeroOrMore>
00042   </define>
00043 '''
00044 
00045 class XMPDate(SchemaAttribute):
00046 
00047     def get(self, instance):
00048         return getattr(instance, self.field_id)
00049 
00050     def deserialize(self, instance, ns_data):
00051         value = ns_data.get( self.name )
00052         if not value:
00053             return
00054         value = DateTime( value )
00055         setattr(instance, self.field_id, value )        
00056 
00057     def serialize(self, dom, parent_node, instance):
00058         value = self.get( instance )
00059         if isinstance( value, DateTime):
00060             value = value.HTML4()
00061         elname = "%s:%s"%(self.namespace.prefix, self.name)
00062         node = dom.createElementNS( self.namespace.xmlns,
00063                                     elname )
00064         value_node = dom.createTextNode( value )
00065         node.appendChild( value_node )
00066         node.normalize()
00067         parent_node.appendChild( node )
00068     
00069 
00070 class AdobeXMP(XmlNamespace):
00071     
00072     xmlns = 'adobe:ns:meta'
00073     prefix = 'xmp'
00074     
00075     uses_at_fields = True
00076     
00077     attributes = (
00078         XMPDate('CreateDate', 'creation_date'),
00079         XMPDate('ModifyDate', 'modification_date'),
00080         )
00081 
00082     def getATFields(self):
00083         return ('creation_date', 'modification_date')
00084 
00085     def getSchemaInfo(self):
00086         return (
00087             ("DateInfo", "zeroOrMore", RNGSchemaFragment),
00088             )
00089         
00090