PageRenderTime 39ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/yolk-syndication.ads

http://github.com/ThomasLocke/yolk
Ada | 554 lines | 328 code | 59 blank | 167 comment | 0 complexity | 971f044abf7ee74ed08d97050bad8002 MD5 | raw file
Possible License(s): AGPL-1.0
  1. -------------------------------------------------------------------------------
  2. -- --
  3. -- Copyright (C) 2010-, Thomas ¸cke --
  4. -- --
  5. -- This library is free software; you can redistribute it and/or modify --
  6. -- it under terms of the GNU General Public License as published by the --
  7. -- Free Software Foundation; either version 3, or (at your option) any --
  8. -- later version. This library is distributed in the hope that it will be --
  9. -- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of --
  10. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
  11. -- --
  12. -- As a special exception under Section 7 of GPL version 3, you are --
  13. -- granted additional permissions described in the GCC Runtime Library --
  14. -- Exception, version 3.1, as published by the Free Software Foundation. --
  15. -- --
  16. -- You should have received a copy of the GNU General Public License and --
  17. -- a copy of the GCC Runtime Library Exception along with this program; --
  18. -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
  19. -- <http://www.gnu.org/licenses/>. --
  20. -- --
  21. -------------------------------------------------------------------------------
  22. with Ada.Calendar;
  23. with Ada.Characters.Latin_1;
  24. private with Ada.Containers.Doubly_Linked_Lists;
  25. private with Ada.Strings.Unbounded;
  26. with DOM.Core;
  27. package Yolk.Syndication is
  28. Not_Valid_XML : exception;
  29. -- Is raised when some Xhtml content is not valid XML. This exception
  30. -- can be raised by all procedures that can take Xhtml as content.
  31. type Content_Kinds is (Text, Html, Xhtml, InlineOther, OutOfLineOther);
  32. -- This type is common for a lot of Atom feed XML elements. It identifies
  33. -- the kind of data found in the element.
  34. -- Text:
  35. -- The content of the Text construct MUST NOT contain child elements.
  36. -- Such text is intended to be presented to humans in a readable fashion.
  37. -- Thus, Atom Processors MAY collapse white space (including line breaks)
  38. -- and display the text using typographic techniques such as
  39. -- justification and proportional fonts.
  40. -- Html:
  41. -- The content of the Text construct MUST NOT contain child elements and
  42. -- SHOULD be suitable for handling as HTML [HTML]. Any markup within is
  43. -- escaped; for example, "<br>" as "&lt;br>". Atom Processors that
  44. -- display such content MAY use that markup to aid in its display.
  45. -- Xhtml:
  46. -- The content SHOULD be suitable for handling as XHTML. The content is
  47. -- wrapped in a <div> element. The XHTML <div> element itself MUST NOT be
  48. -- considered part of the content. Atom Processors that display the
  49. -- content MAY use the markup to aid in displaying it. The escaped
  50. -- versions of characters such as "&" and ">" represent those characters,
  51. -- not markup.
  52. -- InlineOther:
  53. -- For inline content that is not Text, Html or Xhtml.
  54. -- OutOfLineOther:
  55. -- For content that is fetched from a given IRI reference.
  56. subtype Text_Kinds is Content_Kinds range Text .. Xhtml;
  57. -- Text:
  58. -- The content of the Text construct MUST NOT contain child elements.
  59. -- Such text is intended to be presented to humans in a readable fashion.
  60. -- Thus, Atom Processors MAY collapse white space (including line breaks)
  61. -- and display the text using typographic techniques such as
  62. -- justification and proportional fonts.
  63. -- Html:
  64. -- The content of the Text construct MUST NOT contain child elements and
  65. -- SHOULD be suitable for handling as HTML [HTML]. Any markup within is
  66. -- escaped; for example, "<br>" as "&lt;br>". Atom Processors that
  67. -- display such content MAY use that markup to aid in its display.
  68. -- Xhtml:
  69. -- The content SHOULD be suitable for handling as XHTML. The content is
  70. -- wrapped in a <div> element. The XHTML <div> element itself MUST NOT be
  71. -- considered part of the content. Atom Processors that display the
  72. -- content MAY use the markup to aid in displaying it. The escaped
  73. -- versions of characters such as "&" and ">" represent those characters,
  74. -- not markup.
  75. type Relation_Kinds is (Alternate, Related, Self, Enclosure, Via);
  76. -- There are five values for the Registry of Link Relations:
  77. --
  78. -- Alternate:
  79. -- Signifies that the IRI in the value of the href attribute
  80. -- identifies an alternate version of the resource described by the
  81. -- containing element.
  82. -- Related:
  83. -- Signifies that the IRI in the value of the href attribute
  84. -- identifies a resource related to the resource described by the
  85. -- containing element. For example, the feed for a site that
  86. -- discusses the performance of the search engine at
  87. -- "http://search.example.com" might contain, as a child of atom :
  88. -- feed : <link rel="related" href="http://search.example.com/"/>
  89. -- An identical link might appear as a child of any atom:entry whose
  90. -- content contains a discussion of that same search engine.
  91. -- Self:
  92. -- Signifies that the IRI in the value of the href attribute
  93. -- identifies a resource equivalent to the containing element.
  94. -- Enclosure:
  95. -- Signifies that the IRI in the value of the href attribute
  96. -- identifies a related resource that is potentially large in size and
  97. -- might require special handling. For atom : link elements with
  98. -- rel = "enclosure", the length attribute SHOULD be provided.
  99. -- Via:
  100. -- Signifies that the IRI in the value of the href attribute
  101. -- identifies a resource that is the source of the information
  102. -- provided in the containing element.
  103. type Atom_Entry is private;
  104. -- The atom:entry object. This type is _not_ thread safe.
  105. type Atom_Entry_Source is private;
  106. -- The atom:source object. This type is _not_ thread safe.
  107. type Atom_Feed is limited private;
  108. -- The atom:feed object. This type is thread safe.
  109. Q : Character renames Ada.Characters.Latin_1.Quotation;
  110. None : constant String := "";
  111. PI : constant String := "<?xml version="
  112. & Q & "1.0" & Q & " encoding=" & Q & "utf-8" & Q & "?>"
  113. & Ada.Characters.Latin_1.LF;
  114. XHTMLNS : constant String := "http://www.w3.org/1999/xhtml";
  115. XMLNS : constant String := "http://www.w3.org/2005/Atom";
  116. DIVNS : constant String := "xmlns=" & Q & XHTMLNS & Q;
  117. function New_Atom_Entry
  118. (Base_URI : in String := None;
  119. Language : in String := None)
  120. return Atom_Entry;
  121. -- Initialize an Atom entry object, as per the Atom specification RFC4287:
  122. -- http://tools.ietf.org/html/rfc4287
  123. --
  124. -- NOTE: All data is expected to be UTF-8 encoded. Yolk.Syndication does
  125. -- not do any kind of encoding.
  126. --
  127. -- Base_URI:
  128. -- Establishes a base URI for resolving relative references in the entry.
  129. -- Is overruled by Base_URI parameters for individual entry elements.
  130. -- Language:
  131. -- Indicates the natural language for the atom:entry element and its
  132. -- descendents.
  133. function New_Atom_Entry_Source
  134. (Base_URI : in String := None;
  135. Language : in String := None)
  136. return Atom_Entry_Source;
  137. -- Initialize an Atom source object. This is for those occassions where
  138. -- the entry is copied from one feed into another. The atom:source
  139. -- may contain all the metadata from the originating feed.
  140. --
  141. -- NOTE: All data is expected to be UTF-8 encoded. Yolk.Syndication does
  142. -- not do any kind of encoding.
  143. --
  144. -- Base_URI:
  145. -- Establishes a base URI for resolving relative references in the entry.
  146. -- Is overruled by Base_URI parameters for individual entry elements.
  147. -- Language:
  148. -- Indicates the natural language for the atom:entry element and its
  149. -- descendents.
  150. function New_Atom_Feed
  151. (Base_URI : in String := None;
  152. Language : in String := None;
  153. Max_Age : in Duration := 5_616_000.0;
  154. Max_Entries : in Positive := 100;
  155. Min_Entries : in Positive := 10)
  156. return Atom_Feed;
  157. -- Initialize an Atom object, as per the Atom specification RFC4287:
  158. -- http://tools.ietf.org/html/rfc4287
  159. --
  160. -- NOTE: All data is expected to be UTF-8 encoded. Yolk.Syndication does
  161. -- not do any kind of encoding.
  162. --
  163. -- Base_URI:
  164. -- Establishes a base URI for resolving relative references in the feed.
  165. -- Is overruled by Base_URI parameters for individual feed child
  166. -- elements.
  167. -- Language:
  168. -- Indicates the natural language for the atom:feed element and its
  169. -- descendents.
  170. -- Max_Age:
  171. -- If an entries Updated value is older than Max_Age, and there are more
  172. -- than Min_Entries in the list, then the entry is deleted. This is done
  173. -- in the Add_Entry procedure. Max_Age is given in seconds.
  174. -- Max_Entries:
  175. -- This is the max amount of entries we keep in the list. If there are
  176. -- more than Max_Entries entries in the list, then the oldest entries are
  177. -- deleted until the list is Max_Entries long.
  178. -- Min_Entries:
  179. -- The is the minimum amount of entries that must be in the list before
  180. -- we bother with deleting old entries. If there are less than
  181. -- Min_Entries in the list, then even a 100 year old entry is kept.
  182. private
  183. use Ada.Containers;
  184. use Ada.Strings.Unbounded;
  185. function U
  186. (S : in String)
  187. return Unbounded_String
  188. renames To_Unbounded_String;
  189. type Atom_Common is
  190. record
  191. Base_URI : Unbounded_String;
  192. Language : Unbounded_String;
  193. end record;
  194. type Atom_Category is
  195. record
  196. Common : Atom_Common;
  197. Label : Unbounded_String;
  198. Scheme : Unbounded_String;
  199. Term : Unbounded_String;
  200. end record;
  201. type Atom_Date is
  202. record
  203. Common : Atom_Common;
  204. Is_Set : Boolean;
  205. Time_Stamp : Ada.Calendar.Time;
  206. end record;
  207. type Atom_Entry_Content is
  208. record
  209. Common : Atom_Common;
  210. Content : Unbounded_String;
  211. Content_Kind : Content_Kinds;
  212. Mime_Type : Unbounded_String;
  213. Source : Unbounded_String;
  214. end record;
  215. type Atom_Generator is
  216. record
  217. Agent : Unbounded_String;
  218. Common : Atom_Common;
  219. URI : Unbounded_String;
  220. Version : Unbounded_String;
  221. end record;
  222. type Atom_Icon is
  223. record
  224. Common : Atom_Common;
  225. URI : Unbounded_String;
  226. end record;
  227. type Atom_Id is
  228. record
  229. Common : Atom_Common;
  230. URI : Unbounded_String;
  231. end record;
  232. type Atom_Link is
  233. record
  234. Common : Atom_Common;
  235. Href : Unbounded_String;
  236. Hreflang : Unbounded_String;
  237. Length : Natural;
  238. Mime_Type : Unbounded_String;
  239. Rel : Relation_Kinds;
  240. Title : Unbounded_String;
  241. end record;
  242. type Atom_Logo is
  243. record
  244. Common : Atom_Common;
  245. URI : Unbounded_String;
  246. end record;
  247. type Atom_Person is
  248. record
  249. Common : Atom_Common;
  250. Email : Unbounded_String;
  251. Name : Unbounded_String;
  252. URI : Unbounded_String;
  253. end record;
  254. type Atom_Text is
  255. record
  256. Common : Atom_Common;
  257. Text_Content : Unbounded_String;
  258. Text_Kind : Text_Kinds;
  259. end record;
  260. package Category_List is new Doubly_Linked_Lists (Atom_Category);
  261. package Link_List is new Doubly_Linked_Lists (Atom_Link);
  262. package Person_List is new Doubly_Linked_Lists (Atom_Person);
  263. type Atom_Entry_Source is
  264. record
  265. Authors : Person_List.List;
  266. Categories : Category_List.List;
  267. Common : Atom_Common;
  268. Contributors : Person_List.List;
  269. Generator : Atom_Generator;
  270. Icon : Atom_Icon;
  271. Id : Atom_Id;
  272. Links : Link_List.List;
  273. Logo : Atom_Logo;
  274. Rights : Atom_Text;
  275. Subtitle : Atom_Text;
  276. Title : Atom_Text;
  277. Updated : Atom_Date;
  278. end record;
  279. Null_Atom_Entry_Source : constant Atom_Entry_Source
  280. := (Authors => Person_List.Empty_List,
  281. Categories => Category_List.Empty_List,
  282. Common => Atom_Common'(Base_URI => Null_Unbounded_String,
  283. Language => Null_Unbounded_String),
  284. Contributors => Person_List.Empty_List,
  285. Generator =>
  286. Atom_Generator'(Agent => Null_Unbounded_String,
  287. Common =>
  288. Atom_Common'(Base_URI => Null_Unbounded_String,
  289. Language => Null_Unbounded_String),
  290. URI => Null_Unbounded_String,
  291. Version => Null_Unbounded_String),
  292. Icon =>
  293. Atom_Icon'(Common =>
  294. Atom_Common'(Base_URI => Null_Unbounded_String,
  295. Language => Null_Unbounded_String),
  296. URI => Null_Unbounded_String),
  297. Id => Atom_Id'(Common =>
  298. Atom_Common'(Base_URI =>
  299. Null_Unbounded_String,
  300. Language =>
  301. Null_Unbounded_String),
  302. URI => Null_Unbounded_String),
  303. Links => Link_List.Empty_List,
  304. Logo => Atom_Logo'(Common => Atom_Common'
  305. (Base_URI => Null_Unbounded_String,
  306. Language => Null_Unbounded_String),
  307. URI => Null_Unbounded_String),
  308. Rights => Atom_Text'(Common => Atom_Common'
  309. (Base_URI => Null_Unbounded_String,
  310. Language => Null_Unbounded_String),
  311. Text_Content => Null_Unbounded_String,
  312. Text_Kind => Text),
  313. Subtitle => Atom_Text'(Common => Atom_Common'
  314. (Base_URI => Null_Unbounded_String,
  315. Language => Null_Unbounded_String),
  316. Text_Content => Null_Unbounded_String,
  317. Text_Kind => Text),
  318. Title => Atom_Text'(Common => Atom_Common'
  319. (Base_URI => Null_Unbounded_String,
  320. Language => Null_Unbounded_String),
  321. Text_Content => Null_Unbounded_String,
  322. Text_Kind => Text),
  323. Updated => Atom_Date'(Common => Atom_Common'
  324. (Base_URI => Null_Unbounded_String,
  325. Language => Null_Unbounded_String),
  326. Is_Set => False,
  327. Time_Stamp => Ada.Calendar.Clock));
  328. type Atom_Entry is
  329. record
  330. Authors : Person_List.List;
  331. Categories : Category_List.List;
  332. Common : Atom_Common;
  333. Content : Atom_Entry_Content;
  334. Contributors : Person_List.List;
  335. Id : Atom_Id;
  336. Links : Link_List.List;
  337. Published : Atom_Date;
  338. Rights : Atom_Text;
  339. Source : Atom_Entry_Source;
  340. Summary : Atom_Text;
  341. Title : Atom_Text;
  342. Updated : Atom_Date;
  343. end record;
  344. Null_Atom_Entry : constant Atom_Entry
  345. := (Authors => Person_List.Empty_List,
  346. Categories => Category_List.Empty_List,
  347. Common => Atom_Common'(Base_URI => Null_Unbounded_String,
  348. Language => Null_Unbounded_String),
  349. Content =>
  350. Atom_Entry_Content'(Common =>
  351. Atom_Common'(Base_URI =>
  352. Null_Unbounded_String,
  353. Language =>
  354. Null_Unbounded_String),
  355. Content => Null_Unbounded_String,
  356. Content_Kind => Text,
  357. Mime_Type => Null_Unbounded_String,
  358. Source => Null_Unbounded_String),
  359. Contributors => Person_List.Empty_List,
  360. Id => Atom_Id'(Common =>
  361. Atom_Common'(Base_URI =>
  362. Null_Unbounded_String,
  363. Language =>
  364. Null_Unbounded_String),
  365. URI => Null_Unbounded_String),
  366. Links => Link_List.Empty_List,
  367. Published => Atom_Date'(Common =>
  368. Atom_Common'(Base_URI =>
  369. Null_Unbounded_String,
  370. Language =>
  371. Null_Unbounded_String),
  372. Is_Set => False,
  373. Time_Stamp => Ada.Calendar.Clock),
  374. Rights => Atom_Text'(Common =>
  375. Atom_Common'(Base_URI =>
  376. Null_Unbounded_String,
  377. Language =>
  378. Null_Unbounded_String),
  379. Text_Content => Null_Unbounded_String,
  380. Text_Kind => Text),
  381. Source => Null_Atom_Entry_Source,
  382. Summary => Atom_Text'(Common =>
  383. Atom_Common'(Base_URI =>
  384. Null_Unbounded_String,
  385. Language =>
  386. Null_Unbounded_String),
  387. Text_Content => Null_Unbounded_String,
  388. Text_Kind => Text),
  389. Title => Atom_Text'(Common =>
  390. Atom_Common'(Base_URI =>
  391. Null_Unbounded_String,
  392. Language =>
  393. Null_Unbounded_String),
  394. Text_Content => Null_Unbounded_String,
  395. Text_Kind => Text),
  396. Updated => Atom_Date'(Common =>
  397. Atom_Common'(Base_URI =>
  398. Null_Unbounded_String,
  399. Language =>
  400. Null_Unbounded_String),
  401. Is_Set => False,
  402. Time_Stamp => Ada.Calendar.Clock));
  403. function Equal_Entry
  404. (Left, Right : in Atom_Entry)
  405. return Boolean;
  406. package Entry_List is new Doubly_Linked_Lists (Atom_Entry, Equal_Entry);
  407. protected type Protected_Atom_Feed is
  408. procedure Add_Author
  409. (Value : in Atom_Person);
  410. -- ????
  411. procedure Add_Category
  412. (Value : in Atom_Category);
  413. -- ????
  414. procedure Add_Contributor
  415. (Value : in Atom_Person);
  416. -- ????
  417. procedure Add_Entry
  418. (Value : in Yolk.Syndication.Atom_Entry);
  419. -- ????
  420. procedure Add_Link
  421. (Value : in Atom_Link);
  422. -- ????
  423. function Amount_Of_Entries return Natural;
  424. -- ????
  425. procedure Clear_Entry_List;
  426. -- ????
  427. procedure Delete_Entry
  428. (Id : in String);
  429. -- ????
  430. function Get_DOM return DOM.Core.Document;
  431. -- ????
  432. function Get_String
  433. (Pretty_Print : in Boolean := False)
  434. return String;
  435. -- ????
  436. procedure Set_Common
  437. (Value : in Atom_Common);
  438. -- ????
  439. procedure Set_Generator
  440. (Value : in Atom_Generator);
  441. -- ????
  442. procedure Set_Icon
  443. (Value : in Atom_Icon);
  444. -- ????
  445. procedure Set_Id
  446. (Value : in Atom_Id);
  447. -- ????
  448. procedure Set_Logo
  449. (Value : in Atom_Logo);
  450. -- ????
  451. procedure Set_Max_Age
  452. (Value : in Duration);
  453. -- ????
  454. procedure Set_Max_Entries
  455. (Value : in Positive);
  456. -- ????
  457. procedure Set_Min_Entries
  458. (Value : in Positive);
  459. -- ????
  460. procedure Set_Rights
  461. (Value : in Atom_Text);
  462. -- ????
  463. procedure Set_Subtitle
  464. (Value : in Atom_Text);
  465. -- ????
  466. procedure Set_Title
  467. (Value : in Atom_Text);
  468. -- ????
  469. procedure Set_Updated_Time
  470. (Value : in Atom_Date);
  471. -- ????
  472. private
  473. Authors : Person_List.List;
  474. Categories : Category_List.List;
  475. Common : Atom_Common;
  476. Contributors : Person_List.List;
  477. Entries : Entry_List.List;
  478. Generator : Atom_Generator;
  479. Icon : Atom_Icon;
  480. Id : Atom_Id;
  481. Links : Link_List.List;
  482. Logo : Atom_Logo;
  483. Max_Entry_Age : Duration;
  484. Max_Entries : Positive;
  485. Min_Entries : Positive;
  486. Rights : Atom_Text;
  487. Subtitle : Atom_Text;
  488. Title : Atom_Text;
  489. Updated : Atom_Date;
  490. end Protected_Atom_Feed;
  491. type Atom_Feed is
  492. record
  493. PAF : Protected_Atom_Feed;
  494. end record;
  495. end Yolk.Syndication;