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 | //example anchor: |
---|
24 | // http://snd.gu.se/#hyperanchor1.3://div[@id="node-170"]/div[1]/div[1]/div[1]/div[1]/p[1](294)(3)(sse)& |
---|
25 | // //div[@id="node-170"]/div[1]/div[1]/div[1]/div[1]/p[1](365)(3)(kav)& |
---|
26 | // border:thin dotted rgb(255,204,0);background-color:rgb(255,255,204);color:rgb(0,0,0); |
---|
27 | |
---|
28 | var title = $(annotation).find('headline').text().trim(); |
---|
29 | var body = $(annotation).find('body').text().trim(); |
---|
30 | var style = $(annotation).find('body').find('xhtml\\:span').attr('style'); |
---|
31 | var type = $(annotation).find('body').attr('type').toLowerCase(); |
---|
32 | var link = $(annotation).find('link').text(); |
---|
33 | var time = $(annotation).attr('timeStamp'); |
---|
34 | |
---|
35 | var urlParts = link.split("#xpointer"); |
---|
36 | |
---|
37 | om_object.doc_url = urlParts[0]; |
---|
38 | om_object.con_url = urlParts[0]; |
---|
39 | var xpointer = urlParts[1]; |
---|
40 | |
---|
41 | //start dom |
---|
42 | xpointer.match(/start-point\(string-range\((.+?)\)\)\/range-to\(/); |
---|
43 | var parts = RegExp.$1.split(','); |
---|
44 | om_object.bgn_dom = parts[0]+'('+parts[2]+')(3)'; |
---|
45 | |
---|
46 | //end dom |
---|
47 | xpointer.match(/range-to\(string-range\((.+?)\)\)\)/); |
---|
48 | var parts = RegExp.$1.split(','); |
---|
49 | om_object.end_dom = parts[0]+'('+parts[2]+')(3)'; |
---|
50 | |
---|
51 | //build hyperanchor |
---|
52 | var hyperanchor = '#hyperanchor1.3:'+om_object.bgn_dom+'&'+om_object.end_dom+'&'+style; |
---|
53 | |
---|
54 | om_object.doc_title = title; |
---|
55 | |
---|
56 | om_object.oid = hashCode($(annotation).attr('ref')); |
---|
57 | console.log(link); |
---|
58 | om_object.oid_property = "<PROPERTY><HYPER_ANCHOR>"+om_object.doc_url+hyperanchor+"</HYPER_ANCHOR><NOTE>"+body+"</NOTE></PROPERTY>"; |
---|
59 | |
---|
60 | if(type === 'note'){ |
---|
61 | om_object.oid_txt = body; |
---|
62 | om_object.oid_type = 'text'; |
---|
63 | } |
---|
64 | var d = new Date(time); |
---|
65 | om_object.oid_date = (d.getMonth()+1)+'/'+d.getDate()+'/'+d.getFullYear()+' '+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds(); |
---|
66 | |
---|
67 | return om_object; |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * converts wired marker annotations to dassish annotations |
---|
72 | * @param {object} om_object contains wired marker object for annotation |
---|
73 | * @returns {String} annotation in xml |
---|
74 | */ |
---|
75 | function om_object2annotation(om_object){ |
---|
76 | var note = om_object.oid_property.match(/<NOTE>(.+?)<\/NOTE>/)[1]; |
---|
77 | var hyperanchor = om_object.oid_property.match(/<HYPER_ANCHOR>(.+?)<\/HYPER_ANCHOR>/)[1]; |
---|
78 | var style=''; |
---|
79 | var timestamp = new Date(om_object.oid_date); |
---|
80 | |
---|
81 | hyperanchor = unescape(hyperanchor); |
---|
82 | |
---|
83 | hyperanchor.match(/^(.+\([0-9]+\)\([0-9]+\)\([\s\S]*\))&(.+\([0-9]+\)\([0-9]+\)\([\s\S]*\))&(.+)$/); |
---|
84 | |
---|
85 | style = RegExp.$3; |
---|
86 | |
---|
87 | var path = {}; |
---|
88 | |
---|
89 | om_object.bgn_dom.match(/(.+)\(([0-9]+)\)\(([0-9]+)\)/); |
---|
90 | path.start = RegExp.$1; |
---|
91 | path.startOffset = RegExp.$2; |
---|
92 | path.startType = RegExp.$3; |
---|
93 | |
---|
94 | om_object.end_dom.match(/(.+)\(([0-9]+)\)\(([0-9]+)\)/); |
---|
95 | path.end = RegExp.$1; |
---|
96 | path.endOffset = RegExp.$2; |
---|
97 | path.endType = RegExp.$3; |
---|
98 | |
---|
99 | var xpointer = ''; |
---|
100 | |
---|
101 | xpointer += "#xpointer(start-point(string-range("+path.start+"/text()[1],'',"+path.startOffset+"))"; |
---|
102 | xpointer += "/range-to(string-range("+path.end+"/text()[1],'',"+path.endOffset+")))"; |
---|
103 | |
---|
104 | var annotation = '<?xml version="1.0" encoding="UTF-8"?>\n\ |
---|
105 | <annotation xmlns="http://www.dasish.eu/ns/addit"\n\ |
---|
106 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\n\ |
---|
107 | xmlns:xhtml="http://www.w3.org/1999/xhtml"\n\ |
---|
108 | xsi:schemaLocation="http://www.dasish.eu/ns/addit http://dasish.eu/DASISH-schema.xsd"\n\ |
---|
109 | URI="tempAID'+om_object.oid+'"\n\ |
---|
110 | timeStamp="'+timestamp.toISOString()+'">\n\ |
---|
111 | <owner ref="http://dasish.eu/users/UIxyz/how_will_this_be_sent_from_the_client"/>\n\ |
---|
112 | <headline>'+om_object.oid_title+'</headline>\n\ |
---|
113 | <body type="Note" ref="tmp'+om_object.oid+'">\n\ |
---|
114 | <xhtml:span style="'+style+'">'+note+'</xhtml:span>\n\ |
---|
115 | </body>\n\ |
---|
116 | <targetSources>\n\ |
---|
117 | <target>\n\ |
---|
118 | <newSource xml:id="tmp'+om_object.oid+'">\n\ |
---|
119 | <link>'+om_object.doc_url+xpointer+'</link>\n\ |
---|
120 | <version>'+timestamp.toISOString()+'</version>\n\ |
---|
121 | </newSource>\n\ |
---|
122 | </target>\n\ |
---|
123 | </targetSources>\n\ |
---|
124 | <permissions ref="tmpPermissionsListID'+om_object.oid+'"/>\n\ |
---|
125 | </annotation>'; |
---|
126 | return annotation; |
---|
127 | } |
---|
128 | |
---|
129 | function hashCode(str){ |
---|
130 | var hash = 0; |
---|
131 | if (str == undefined || str.length == 0) return hash; |
---|
132 | for (i = 0; i < str.length; i++) { |
---|
133 | char = str.charCodeAt(i); |
---|
134 | hash = ((hash<<5)-hash)+char; |
---|
135 | hash = hash & hash; // Convert to 32bit integer |
---|
136 | } |
---|
137 | return hash; |
---|
138 | } |
---|
139 | |
---|
140 | if (!Date.prototype.toISOString) { |
---|
141 | Date.prototype.toISOString = function() { |
---|
142 | function pad(n) { return n < 10 ? '0' + n : n } |
---|
143 | return this.getUTCFullYear() + '-' |
---|
144 | + pad(this.getUTCMonth() + 1) + '-' |
---|
145 | + pad(this.getUTCDate()) + 'T' |
---|
146 | + pad(this.getUTCHours()) + ':' |
---|
147 | + pad(this.getUTCMinutes()) + ':' |
---|
148 | + pad(this.getUTCSeconds()) + 'Z'; |
---|
149 | }; |
---|
150 | } |
---|
151 | |
---|
152 | /* |
---|
153 | From SQL-lite for wired-marker |
---|
154 | <PROPERTY> |
---|
155 | <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> |
---|
156 | <NOTE>text om en fï¿œrfattare</NOTE> |
---|
157 | </PROPERTY> |
---|
158 | 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 |
---|
159 | */ |
---|