Changeset 4592 for exist


Ignore:
Timestamp:
11/12/08 09:54:03 (11 years ago)
Author:
cbyrom
Message:

Extend the Author class with a hasValue method and implement usage
throughout - NB, treat the main author more specifically - not
including an initial dummy value so that schema validation will fail if
not specified. Fix atom id format - remove ':' from hostname since
this is a delimeter used by the id. Adjust 'content' content to
make schema compliant - xhtml content must be wrapped in div tags.
Adjust schemas accordingly - and update these to use sequences rather
than choices - to properly enforce checking for required elements (at
the marginal expense of enforcing an order on the atom contents).

Location:
exist/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgUtils/models/Atom.py

    r4582 r4592  
    5959            return self.name + " | " + self.uri + " | " + self.role 
    6060        return "" 
     61 
     62 
     63    def hasValue(self): 
     64        if self.name or self.uri or self.role: 
     65            return True 
     66        return False 
    6167     
    6268    def fromString(self, personString): 
     
    456462            if author.type == Person.AUTHOR_TYPE: 
    457463                self.author = author 
     464                     
    458465                if isFirstAuthor.has_key(author.type): 
    459466                    raise AtomError("Error: an atom can only have one author specified") 
     
    474481                isFirstAuthor[author.type] = 1 
    475482 
    476             if str(author) != "" and author not in authorArray: 
     483            if author.hasValue() and author not in authorArray: 
    477484                logging.debug("Adding author (type:'%s', name:'%s', uri:'%s', role:'%s')" \ 
    478485                              %(author.type, author.name, author.uri, author.role)) 
     
    564571        self._linksToXML(root) 
    565572 
    566         # NB, the author tag is mandatory for atoms - so if an explicit 
    567         # author has not been set, just take the author to be the provider 
    568         if not self.author: 
    569             author = Person() 
    570             author.name = self.ME.providerID 
    571             #author.uri = self.ME.providerID 
    572             self.author = author 
    573  
    574         root.append(self.author.toXML()) 
     573        if self.author.hasValue(): 
     574            root.append(self.author.toXML()) 
    575575             
    576576        for contributor in self.contributors: 
    577577            root.append(contributor.toXML()) 
    578  
    579         # add the moles entity section, if it is required 
    580         if self.ME: 
    581             root.append(self.ME.toXML()) 
    582578 
    583579        # add parameters data 
     
    600596            content.attrib["src"] = contentFile 
    601597        else: 
    602             content.text = self.Content 
    603598            content.attrib["type"] = "xhtml" 
     599            div = ET.SubElement(content, 'div') 
     600            div.attrib["xmlns"] = "http://www.w3.org/1999/xhtml" 
     601            div.text = self.Content 
    604602         
    605603        # if there's a published date already defined, assume we're doing an update now 
     
    616614        published = ET.SubElement(root, "published") 
    617615        published.text = self.publishedDate 
     616 
     617        # add the moles entity section, if it is required 
     618        if self.ME: 
     619            root.append(self.ME.toXML()) 
    618620 
    619621        # add temporal range data, if available 
     
    684686        xmlString = xmlString.replace('xmlns="http://www.w3.org/2005/Atom"', '') 
    685687        xmlString = xmlString.replace('default:', '') 
     688        xmlString = xmlString.replace('xs:', '') 
    686689 
    687690        # now create elementtree with the XML string 
     
    699702 
    700703        authorElement = tree.find('author') 
    701         logging.debug("Adding author data") 
    702         author = Person() 
    703         author.fromETElement(authorElement) 
    704         self.author = author 
     704        if authorElement: 
     705            logging.debug("Adding author data") 
     706            author = Person() 
     707            author.fromETElement(authorElement) 
     708            self.author = author 
    705709 
    706710        contributorElements = tree.findall('contributor') 
     
    736740            else: 
    737741                logging.debug("No file data - adding contents of element instead") 
    738                 self.Content = contentTag.text 
     742                div = contentTag.find('{http://www.w3.org/1999/xhtml}div') 
     743                self.Content = div.text 
    739744         
    740745        range = tree.findtext('temporalRange') 
     
    821826        urlBit = urlBit.replace('#', '') 
    822827        urlBits = urlBit.split('/') 
     828        host = urlBits[0].split(':')[0] # avoid the port colon - as this breaks the ID format 
    823829        dateBit = datetime.datetime.today().strftime("%Y-%m-%d") 
    824830         
    825         id = "tag:" + urlBits[0] + "," + dateBit + ":/" + "/".join(urlBits[1:]) 
     831        id = "tag:" + host + "," + dateBit + ":/" + "/".join(urlBits[1:]) 
    826832        logging.info("- unique ID created for atom") 
    827833        logging.debug(" - '%s'" %id) 
  • exist/trunk/xquery/atom1.0.xsd

    r4426 r4592  
    4545                        </xs:documentation> 
    4646                </xs:annotation> 
    47                 <xs:choice minOccurs="1" maxOccurs="unbounded"> 
     47                <xs:sequence minOccurs="1" maxOccurs="unbounded"> 
    4848                        <xs:element name="name" type="xs:string" minOccurs="1" maxOccurs="1" /> 
    4949                        <xs:element name="uri" type="atom:uriType" minOccurs="0" maxOccurs="1" /> 
    5050                        <xs:element name="email" type="atom:emailType" minOccurs="0" maxOccurs="1" /> 
    51                         <xs:any namespace="##other"/> 
    52                 </xs:choice> 
     51                        <xs:any minOccurs="0" namespace="##other"/> 
     52                </xs:sequence> 
    5353 
    5454                <xs:attributeGroup ref="atom:commonAttributes"/> 
     
    9898                        </xs:documentation> 
    9999                </xs:annotation> 
    100                 <xs:group ref="atom:entryGroup" maxOccurs="unbounded" /> 
    101                 <xs:attributeGroup ref="atom:commonAttributes"/> 
    102         </xs:complexType> 
    103  
    104         <xs:group name="entryGroup"> 
    105                 <xs:choice> 
     100                <xs:sequence> 
    106101                        <xs:element name="id" type="atom:idType" minOccurs="1" maxOccurs="1" /> 
    107102                        <xs:element name="title" type="atom:textType" minOccurs="1" maxOccurs="1" /> 
    108103                        <xs:element name="link" type="atom:linkType" minOccurs="0" maxOccurs="unbounded" /> 
    109                         <xs:element name="author" type="atom:personType" minOccurs="0" maxOccurs="unbounded" /> 
     104                        <xs:element name="author" type="atom:personType" minOccurs="1" maxOccurs="unbounded" /> 
    110105                        <xs:element name="contributor" type="atom:personType" minOccurs="0" maxOccurs="unbounded" /> 
    111106                        <xs:element name="category" type="atom:categoryType" minOccurs="0" maxOccurs="unbounded" /> 
    112                         <xs:element name="summary" type="atom:textType" minOccurs="0" maxOccurs="1" /> 
    113                         <xs:element name="content" type="atom:contentType" minOccurs="0" maxOccurs="1" /> 
     107                        <xs:element name="summary" type="atom:textType" minOccurs="1" maxOccurs="1" /> 
     108                        <xs:element name="content" type="atom:contentType" minOccurs="1" maxOccurs="1" /> 
    114109                        <xs:element name="updated" type="atom:dateTimeType" minOccurs="1" maxOccurs="1" /> 
    115110                        <xs:element name="published" type="atom:dateTimeType" minOccurs="0" maxOccurs="1" /> 
    116111                        <xs:element name="rights" type="atom:textType" minOccurs="0" maxOccurs="1" /> 
    117112                        <xs:element name="source" type="atom:textType" minOccurs="0" maxOccurs="1" /> 
    118                 </xs:choice> 
    119         </xs:group> 
     113                </xs:sequence> 
     114                <xs:attributeGroup ref="atom:commonAttributes"/> 
     115        </xs:complexType> 
    120116                 
    121117        <xs:complexType name="contentType" mixed="true"> 
     
    127123                </xs:annotation> 
    128124                <xs:sequence> 
    129                         <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" /> 
     125                        <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax"/> 
    130126                </xs:sequence> 
    131127                <xs:attribute name="type" type="xs:string"/> 
  • exist/trunk/xquery/molesAtom1.0.xsd

    r4510 r4592  
    1717        <!-- redefine the atom entry contents - to include the required additional data --> 
    1818    <xs:redefine schemaLocation="atom1.0.xsd"> 
    19         <xs:group name="entryGroup"> 
    20             <xs:choice> 
    21                 <xs:group ref="atom:entryGroup"/> 
    22                 <xs:element ref="moles:entity" minOccurs="1" maxOccurs="1"/> 
    23                 <xs:element ref="moles:temporalRange" minOccurs="1" maxOccurs="1"/> 
    24                 <xs:element ref="georss:where" minOccurs="0" maxOccurs="1"/> 
    25             </xs:choice> 
    26         </xs:group> 
     19        <xs:complexType name="entryType"> 
     20                        <xs:complexContent> 
     21                        <xs:extension base="atom:entryType"> 
     22                                <xs:sequence> 
     23                                <xs:element ref="moles:entity" minOccurs="1" maxOccurs="1"/> 
     24                                <xs:element ref="moles:temporalRange" minOccurs="1" maxOccurs="1"/> 
     25                                <xs:element ref="georss:where" minOccurs="0" maxOccurs="1"/> 
     26                            </xs:sequence> 
     27                        </xs:extension> 
     28                    </xs:complexContent> 
     29         </xs:complexType> 
    2730    </xs:redefine> 
    2831</xs:schema> 
Note: See TracChangeset for help on using the changeset viewer.