summaryrefslogtreecommitdiff
path: root/external/libetonyek/0001-impl.-XML-format-detection.patch
blob: c4e1904b89d85e322618dd6cdcdf979f3d3adfae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
From 28a3b93cc8b0050582c54722df5ac372530ff0a4 Mon Sep 17 00:00:00 2001
From: David Tardon <dtardon@redhat.com>
Date: Fri, 1 Nov 2013 18:29:40 +0100
Subject: [PATCH] impl. XML format detection

---
 src/lib/KEYDocument.cpp | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/src/lib/KEYDocument.cpp b/src/lib/KEYDocument.cpp
index 8ca33ad..a1a5477 100644
--- a/src/lib/KEYDocument.cpp
+++ b/src/lib/KEYDocument.cpp
@@ -13,10 +13,12 @@
 #include <libetonyek/KEYDocument.h>
 
 #include "libetonyek_utils.h"
+#include "libetonyek_xml.h"
 #include "KEY1Defaults.h"
 #include "KEY1Parser.h"
 #include "KEY2Defaults.h"
 #include "KEY2Parser.h"
+#include "KEY2Token.h"
 #include "KEYContentCollector.h"
 #include "KEYDefaults.h"
 #include "KEYDictionary.h"
@@ -60,9 +62,32 @@ enum Source
 
 Version detectVersionFromInput(const WPXInputStreamPtr_t &input)
 {
-  // TODO: do a real detection
-  (void) input;
-  return VERSION_KEYNOTE_5;
+  if (input->atEOS())
+    return VERSION_UNKNOWN;
+
+  const KEY2Tokenizer tokenizer;
+  KEYXMLReader reader(input.get(), tokenizer);
+
+  if ((KEY2Token::NS_URI_KEY | KEY2Token::presentation) == getId(reader))
+  {
+    const std::string version = readOnlyAttribute(reader, KEY2Token::version, KEY2Token::NS_URI_KEY);
+
+    switch (tokenizer(version.c_str()))
+    {
+    case KEY2Token::VERSION_STR_2 :
+      return VERSION_KEYNOTE_2;
+    case KEY2Token::VERSION_STR_3 :
+      return VERSION_KEYNOTE_3;
+    case KEY2Token::VERSION_STR_4 :
+      return VERSION_KEYNOTE_4;
+    case KEY2Token::VERSION_STR_5 :
+      return VERSION_KEYNOTE_5;
+    }
+  }
+
+  // TODO: test for v.1 and v.6
+
+  return VERSION_UNKNOWN;
 }
 
 Version detectVersion(const WPXInputStreamPtr_t &input, Source &source)
-- 
1.8.3.1