123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167(*
* Copyright (c) 2010 Anil Madhavapeddy <anil@recoil.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*)(* Atom Syndication format output. Bare minimum for a reader to use, feel
free to extend from the full spec at:
http://www.atomenabled.org/developers/syndication/atom-format-spec.php
*)typeauthor={name:string;uri:stringoption;email:stringoption;}letstringo=functionNone->None|Somes->Some(Xml.strings)letxml_of_authora=Xml.(tag"name"(stringa.name)++tago"uri"(stringoa.uri)++tago"email"(stringoa.email))typedate=int*int*int*int*int(* year, month, day, hour, minute *)letxml_of_date(year,month,day,hour,min)=letstr=Printf.sprintf"%.4d-%.2d-%.2dT%.2d:%.2d:00Z"yearmonthdayhourmininXml.stringstrtypelink={rel:[`self|`alternate];href:Uri.t;typ:stringoption;}letmk_link?(rel=`self)?typhref={rel;typ;href}letdatabody:Xml.t=[`Databody]letempty:Xml.t=[]letxml_of_linkl=letattrs=[("rel",matchl.relwith`self->"self"|`alternate->"alternate");("href",Uri.to_stringl.href)]@matchl.typwith|None->[]|Somet->["type",t]inXml.tag"link"~attrsemptytypemeta={id:string;title:string;subtitle:stringoption;author:authoroption;rights:stringoption;updated:date;links:linklist;}letxml_of_metam=letopenXmlinletbody=[tag"id"(datam.id);tag"title"(datam.title);(matchm.subtitlewith|None->empty|Somes->tag"subtitle"(datas));(matchm.authorwith|None->empty|Somea->tag"author"(xml_of_authora));(matchm.rightswith|None->empty|Somer->tag"rights"(datar));tag"updated"(xml_of_datem.updated);]inList.concat(body@List.mapxml_of_linkm.links)typecontent=Xml.tletxml_of_contentbasec=letdiv=Xml.tag"content"~attrs:["type","xhtml"](Xml.tag"div"~attrs:["xmlns","http://www.w3.org/1999/xhtml"](c))inmatchbasewith|None->div|Somebase->beginmatchdivwith|[`El((("","content"),[("","type"),"xhtml"]),childs)]->[`El((("","content"),[(("","type"),"xhtml");(("","xml:base"),base)]),childs)]|_->assertfalseendtypesummary=stringoptionletxml_of_summary=function|None->Xml.empty|Somestr->Xml.(tag"summary"(stringstr))typeentry={entry:meta;summary:summary;content:content;base:stringoption;}letxml_of_entrye=Xml.(tag"entry"(xml_of_metae.entry++xml_of_summarye.summary++xml_of_contente.basee.content))letcontributorsentries=List.fold_left(funaccue->matche.entry.authorwith|None->accu|Somea->ifList.memaaccuthenaccuelsea::accu)[]entriesletxml_of_contributorc=Xml.tag"contributor"(xml_of_authorc)typefeed={feed:meta;entries:entrylist;}letxml_of_feed?selff=letself=matchselfwith|None->Xml.empty|Somes->Xml.tag"link"~attrs:["rel","self";"href",s]Xml.emptyinXml.(tag"feed"~attrs:["xmlns","http://www.w3.org/2005/Atom"](self++xml_of_metaf.feed++list(List.mapxml_of_contributor(contributorsf.entries))++list(List.mapxml_of_entryf.entries);))letcompare(yr1,mn1,da1,_,_)(yr2,mn2,da2,_,_)=matchyr1-yr2with|0->(matchmn1-mn2with0->da1-da2|n->n)|n->n