1 | /*** |
---|
2 | * |
---|
3 | * @param {object} annotation annotation object from webservice |
---|
4 | * @returns {annotationToOmObject.om_object} an object for Wired Marker |
---|
5 | */ |
---|
6 | function annotation2om_object(annotation){ |
---|
7 | var om_object = { |
---|
8 | oid :"", |
---|
9 | doc_title :"http://localhost/annotation/test/test-service.html", |
---|
10 | doc_url :"http://localhost/annotation/test/test-service.html", |
---|
11 | con_url :"http://localhost/annotation/test/test-service.html", |
---|
12 | bgn_dom :"", |
---|
13 | end_dom :"", |
---|
14 | oid_title :"http://localhost/annotation/test/test-service.html", |
---|
15 | oid_property :"<PROPERTY><HYPER_ANCHOR>http://localhost/annotation/test/test-service.html#hyperanchor1.3%3A%2Fhtml%5B1%5D%2Fbody%5B1%5D%2Fdiv%5B2%5D%2Fp%5B1%5D(0)(3)(Ane)%26%2Fhtml%5B1%5D%2Fbody%5B1%5D%2Fdiv%5B2%5D%2Fp%5B1%5D(45)(3)(ter)%26background-color%3A%20rgb(%2044%2C%20254%2C%20%2081)%3Bcolor%3Argb(0%2C0%2C0)%3B</HYPER_ANCHOR><NOTE>text om en författare</NOTE></PROPERTY>", |
---|
16 | oid_mode :"0", |
---|
17 | oid_type :"text", |
---|
18 | oid_txt :"An example text about Douglas Adams; a writer", |
---|
19 | oid_img :null, |
---|
20 | oid_date :"" |
---|
21 | }; |
---|
22 | |
---|
23 | //start xpath in xpointer: (?<=start-point\(string-range\()(.*\n?)(?=\,'') |
---|
24 | //end xpath in xpointer: (?<=range-to\(string-range\()(.*\n?)(?=\,'') |
---|
25 | |
---|
26 | |
---|
27 | om_object.oid = hashCode(annotation['xml:id']); |
---|
28 | console.log(annotation.targetSources.targetSource); |
---|
29 | om_object.oid_property = "<PROPERTY><HYPER_ANCHOR>"+annotation.targetSources.targetSource.id+"</HYPER_ANCHOR><NOTE>"+annotation.body+"</NOTE></PROPERTY>"; |
---|
30 | |
---|
31 | if(annotation.type.toLowerCase() === 'note'){ |
---|
32 | om_object.oid_txt = annotation.body; |
---|
33 | om_object.oid_type = 'text'; |
---|
34 | } |
---|
35 | var d = new Date(annotation.timeStamp); |
---|
36 | om_object.oid_date = (d.getMonth()+1)+'/'+d.getDate()+'/'+d.getFullYear()+' '+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds(); |
---|
37 | |
---|
38 | return om_object; |
---|
39 | } |
---|
40 | |
---|
41 | /** |
---|
42 | * converts wired marker annotations to dassish annotations |
---|
43 | * @param {object} om_object contains wired marker object for annotation |
---|
44 | * @returns {String} annotation in xml |
---|
45 | */ |
---|
46 | function om_object2annotation(om_object){ |
---|
47 | var note = om_object.oid_property.match(/<NOTE>(.+?)<\/NOTE>/)[1]; |
---|
48 | var hyperanchor = om_object.oid_property.match(/<HYPER_ANCHOR>(.+?)<\/HYPER_ANCHOR>/)[1]; |
---|
49 | var style=''; |
---|
50 | var timestamp = new Date(om_object.oid_date); |
---|
51 | |
---|
52 | hyperanchor = unescape(hyperanchor); |
---|
53 | |
---|
54 | hyperanchor.match(/^(.+\([0-9]+\)\([0-9]+\)\([\s\S]*\))&(.+\([0-9]+\)\([0-9]+\)\([\s\S]*\))&(.+)$/); |
---|
55 | |
---|
56 | style = RegExp.$3; |
---|
57 | |
---|
58 | var path = {}; |
---|
59 | |
---|
60 | om_object.bgn_dom.match(/(.+)\(([0-9]+)\)\(([0-9]+)\)/); |
---|
61 | path.start = RegExp.$1; |
---|
62 | path.startOffset = RegExp.$2; |
---|
63 | path.startType = RegExp.$3; |
---|
64 | |
---|
65 | om_object.end_dom.match(/(.+)\(([0-9]+)\)\(([0-9]+)\)/); |
---|
66 | path.end = RegExp.$1; |
---|
67 | path.endOffset = RegExp.$2; |
---|
68 | path.endType = RegExp.$3; |
---|
69 | |
---|
70 | var xpointer = ''; |
---|
71 | |
---|
72 | xpointer += "#xpointer(start-point(string-range("+path.start+"/text()[1],'',"+path.startOffset+"))"; |
---|
73 | xpointer += "/range-to(string-range("+path.end+"/text()[1],'',"+path.endOffset+")))"; |
---|
74 | |
---|
75 | var annotation = '<?xml version="1.0" encoding="UTF-8"?>\n\ |
---|
76 | <annotation xmlns="http://dasish.eu/ns/addit" \n\ |
---|
77 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n\ |
---|
78 | xmlns:xhtml="http://www.w3.org/1999/xhtml"\n\ |
---|
79 | xsi:schemaLocation="http://www.dasish.eu/ns/addit http://dasish.eu/DASISH-schema.xsd"\n\ |
---|
80 | URI="tempAIDgfgf" \n\ |
---|
81 | timeStamp="'+timestamp.toISOString()+'">\n\ |
---|
82 | <owner ref="http://dasish.eu/users/how_will_this_be_sent_from_the_client"/>\n\ |
---|
83 | <headline>'+om_object.oid_title+'</headline>\n\ |
---|
84 | <body type="Note" ref="tmp'+om_object.oid+'">\n\ |
---|
85 | <xhtml:span style="'+style+'">'+note+'</xhtml:span>\n\ |
---|
86 | </body>\n\ |
---|
87 | <targetSources>\n\\n\ |
---|
88 | <target>\n\ |
---|
89 | <newSource xml:id="tmp'+om_object.oid+'">\n\ |
---|
90 | <link>'+om_object.doc_url+xpointer+'</link>\n\ |
---|
91 | <version>'+timestamp.toISOString()+'</version>\n\ |
---|
92 | </newSource>\n\ |
---|
93 | </target>\n\ |
---|
94 | </targetSources>\n\ |
---|
95 | <readers>\n\ |
---|
96 | <reader ref="http://dasish.eu/users/user123"/>\n\ |
---|
97 | </readers>\n\ |
---|
98 | <writers>\n\ |
---|
99 | <writer ref="http://dasish.eu/users/user123"/>\n\ |
---|
100 | </writers>\n\ |
---|
101 | </annotation>'; |
---|
102 | return annotation; |
---|
103 | } |
---|
104 | |
---|
105 | function hashCode(str){ |
---|
106 | var hash = 0; |
---|
107 | if (str.length == 0) return hash; |
---|
108 | for (i = 0; i < str.length; i++) { |
---|
109 | char = str.charCodeAt(i); |
---|
110 | hash = ((hash<<5)-hash)+char; |
---|
111 | hash = hash & hash; // Convert to 32bit integer |
---|
112 | } |
---|
113 | return hash; |
---|
114 | } |
---|
115 | |
---|
116 | if (!Date.prototype.toISOString) { |
---|
117 | Date.prototype.toISOString = function() { |
---|
118 | function pad(n) { return n < 10 ? '0' + n : n } |
---|
119 | return this.getUTCFullYear() + '-' |
---|
120 | + pad(this.getUTCMonth() + 1) + '-' |
---|
121 | + pad(this.getUTCDate()) + 'T' |
---|
122 | + pad(this.getUTCHours()) + ':' |
---|
123 | + pad(this.getUTCMinutes()) + ':' |
---|
124 | + pad(this.getUTCSeconds()) + 'Z'; |
---|
125 | }; |
---|
126 | } |
---|
127 | |
---|
128 | /* |
---|
129 | From SQL-lite for wired-marker |
---|
130 | <PROPERTY> |
---|
131 | <HYPER_ANCHOR>http://localhost/annotation/test/test-service.html#hyperanchor1.3%3A%2Fhtml%5B1%5D%2Fbody%5B1%5D%2Fdiv%5B2%5D%2Fp%5B1%5D(0)(3)(Ane)%26%2Fhtml%5B1%5D%2Fbody%5B1%5D%2Fdiv%5B2%5D%2Fp%5B1%5D(45)(3)(ter)%26background-color%3A%20rgb(%2044%2C%20254%2C%20%2081)%3Bcolor%3Argb(0%2C0%2C0)%3B</HYPER_ANCHOR> |
---|
132 | <NOTE>text om en fï¿œrfattare</NOTE> |
---|
133 | </PROPERTY> |
---|
134 | unescaped: http://localhost/annotation/test/test-service.html#hyperanchor1.3:/html[1]/body[1]/div[2]/p[1](0)(3)(Ane)&/html[1]/body[1]/div[2]/p[1](45)(3)(ter)&background-color: rgb( 44, 254, 81);color:rgb(0,0,0);text om en fï¿œrfattare |
---|
135 | */ |
---|