Changeset 4331
- Timestamp:
- 01/24/14 11:20:40 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DASISH/t5.6/client/trunk/chrome/markingcollection/content/markingcollection/annotator-service/conversion.utils.js
r4277 r4331 4 4 * @returns {annotationToOmObject.om_object} an object for Wired Marker 5 5 */ 6 function annotation2om_object(annotation) {6 function annotation2om_object(annotation) { 7 7 var om_object = { 8 oid :"",9 pfid :"0",10 doc_title :"",11 doc_url :"",12 con_url :"",13 bgn_dom :"",14 end_dom :"",15 oid_title :"Test test test",16 oid_property :"<PROPERTY><HYPER_ANCHOR></HYPER_ANCHOR><NOTE></NOTE></PROPERTY>",17 oid_mode :"0",18 oid_type :"text",19 oid_txt :"", //must be the marked text!20 oid_img :null,21 oid_date :"",22 pfid_order: 423 24 8 oid: "", 9 pfid: "0", 10 doc_title: "", 11 doc_url: "", 12 con_url: "", 13 bgn_dom: "", 14 end_dom: "", 15 oid_title: "Test test test", 16 oid_property: "<PROPERTY><HYPER_ANCHOR></HYPER_ANCHOR><NOTE></NOTE></PROPERTY>", 17 oid_mode: "0", 18 oid_type: "text", 19 oid_txt: "", //must be the marked text! 20 oid_img: null, 21 oid_date: "", 22 pfid_order: 4 23 }; 24 25 25 //example anchor: 26 26 // http://snd.gu.se/#hyperanchor1.3://div[@id="node-170"]/div[1]/div[1]/div[1]/div[1]/p[1](294)(3)(sse)& 27 27 // //div[@id="node-170"]/div[1]/div[1]/div[1]/div[1]/p[1](365)(3)(kav)& 28 28 // border:thin dotted rgb(255,204,0);background-color:rgb(255,255,204);color:rgb(0,0,0); 29 29 30 30 var title = $(annotation).find('headline').text().trim(); 31 31 var body = $(annotation).find('body').text().trim(); … … 34 34 var link = $(annotation).find('link').text(); 35 35 var time = $(annotation).attr('timeStamp'); 36 37 var urlParts = link.split("#xpointer"); 38 36 37 var urlParts = link.split("#xpointer"); 38 39 39 om_object.doc_url = urlParts[0]; 40 40 om_object.con_url = urlParts[0]; 41 41 var xpointer = urlParts[1]; 42 42 43 43 //start dom 44 44 xpointer.match(/start-point\(string-range\((.+?)\)\)\/range-to\(/); 45 45 var parts = RegExp.$1.split(','); 46 46 var parts0 = parts[0].replace('/text()[1]', ''); 47 om_object.bgn_dom = parts0 +'('+parts[2]+')(3)';48 47 om_object.bgn_dom = parts0 + '(' + parts[2] + ')(3)'; 48 49 49 //end dom 50 50 xpointer.match(/range-to\(string-range\((.+?)\)\)\)/); 51 51 var parts = RegExp.$1.split(','); 52 52 var parts0 = parts[0].replace('/text()[1]', ''); 53 om_object.end_dom = parts0 +'('+parts[2]+')(3)';54 53 om_object.end_dom = parts0 + '(' + parts[2] + ')(3)'; 54 55 55 //build hyperanchor 56 console.log('fragment: ' +om_object.bgn_dom+'&'+om_object.end_dom+'&'+style);57 var hyperanchor = '#hyperanchor1.3' +encodeURIComponent(':'+om_object.bgn_dom.replace(/"/g, '"')+'&'+om_object.end_dom.replace(/"/g, '"')+'&'+style);58 56 console.log('fragment: ' + om_object.bgn_dom + '&' + om_object.end_dom + '&' + style); 57 var hyperanchor = '#hyperanchor1.3' + encodeURIComponent(':' + om_object.bgn_dom.replace(/"/g, '"') + '&' + om_object.end_dom.replace(/"/g, '"') + '&' + style); 58 59 59 om_object.doc_title = title; 60 60 61 61 om_object.oid = hashCode($(annotation).attr('URI')); 62 if (om_object.oid < 0){62 if (om_object.oid < 0) { 63 63 om_object.oid = om_object.oid * -1; 64 64 } 65 65 console.log(link); 66 om_object.oid_property = "<PROPERTY><HYPER_ANCHOR>" +om_object.doc_url+hyperanchor+"</HYPER_ANCHOR><NOTE>"+body+"</NOTE></PROPERTY>";67 68 if (type === 'note'){66 om_object.oid_property = "<PROPERTY><HYPER_ANCHOR>" + om_object.doc_url + hyperanchor + "</HYPER_ANCHOR><NOTE>" + body + "</NOTE></PROPERTY>"; 67 68 if (type === 'note') { 69 69 om_object.oid_txt = body; 70 70 om_object.oid_type = 'text'; 71 71 } 72 72 var d = new Date(time); 73 om_object.oid_date = (d.getFullYear() +'/'+(parseInt(d.getMonth())+1))+'/'+d.getDate()+' '+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds();74 73 om_object.oid_date = (d.getFullYear() + '/' + (parseInt(d.getMonth()) + 1)) + '/' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds(); 74 75 75 return om_object; 76 76 } … … 81 81 * @returns {String} annotation in xml 82 82 */ 83 function om_object2annotation(om_object) {83 function om_object2annotation(om_object) { 84 84 var note = om_object.oid_property.match(/<NOTE>(.+?)<\/NOTE>/)[1]; 85 85 var hyperanchor = om_object.oid_property.match(/<HYPER_ANCHOR>(.+?)<\/HYPER_ANCHOR>/)[1]; 86 var style ='';86 var style = ''; 87 87 var timestamp = new Date(om_object.oid_date); 88 88 89 89 hyperanchor = unescape(hyperanchor); 90 90 91 91 hyperanchor.match(/^(.+\([0-9]+\)\([0-9]+\)\([\s\S]*\))&(.+\([0-9]+\)\([0-9]+\)\([\s\S]*\))&(.+)$/); 92 92 93 93 style = RegExp.$3; 94 94 95 95 var path = {}; 96 96 97 97 om_object.bgn_dom.match(/(.+)\(([0-9]+)\)\(([0-9]+)\)/); 98 98 path.start = RegExp.$1; … … 104 104 path.endOffset = RegExp.$2; 105 105 path.endType = RegExp.$3; 106 106 107 107 var xpointer = ''; 108 109 xpointer += "#xpointer(start-point(string-range(" +path.start+"/text()[1],'',"+path.startOffset+"))";110 xpointer += "/range-to(string-range(" +path.end+"/text()[1],'',"+path.endOffset+")))";111 108 109 xpointer += "#xpointer(start-point(string-range(" + path.start + "/text()[1],''," + path.startOffset + "))"; 110 xpointer += "/range-to(string-range(" + path.end + "/text()[1],''," + path.endOffset + ")))"; 111 112 112 var annotation = '<?xml version="1.0" encoding="UTF-8"?>\n\ 113 113 <annotation xmlns="http://www.dasish.eu/ns/addit"\n\ … … 115 115 xsi:schemaLocation="http://www.dasish.eu/ns/addit http://dasish.eu/DASISH-schema.xsd"\n\ 116 116 xmlns:xhtml="http://www.w3.org/1999/xhtml"\n\ 117 lastModified="'+timestamp.toISOString()+'"\n\118 URI="tempAID'+om_object.oid+'"\n\119 ownerRef="tempownerRef'+om_object.oid+'"\n\120 headline="'+om_object.oid_title+'">\n\117 URI="' + annotationFramework.getBackend() + '/api/annotations/00000000-0000-0000-' + om_object.oid.substring(0, 4) + '-' + om_object.oid.substring(4, 14) + '00"\n\ 118 ownerRef="' + annotationFramework.getBackend() + '/api/users/00000000-0000-0000-' + om_object.oid.substring(0, 4) + '-' + om_object.oid.substring(4, 14) + '00">\n\ 119 <headline>' + om_object.oid_title + '</headline>\n\ 120 <lastModified>' + timestamp.toISOString() + '</lastModified>\n\ 121 121 <body>\n\ 122 <xmlBody mimeType="application/xml+xhtml">\n\ 123 <xhtml:span style="'+style+'">'+note+'</xhtml:span>\n\ 122 <xmlBody>\n\ 123 <mimeType>application/xml+xhtml</mimeType>\n\ 124 <xhtml:span style="' + style + '">' + note + '</xhtml:span>\n\ 124 125 </xmlBody>\n\ 125 126 </body>\n\ 126 127 <targets>\n\ 127 <targetInfo ref="'+annotationFramework.getBackend()+'/api/targets/00000000-0000-0000-'+om_object.oid.substring(0,4)+'-'+om_object.oid.substring(4,14)+'"\n\ 128 link="'+om_object.doc_url/*+xpointer*/+'"\n\ 129 version="'+timestamp.toISOString()+'"/>\n\ 128 <targetInfo ref="' + annotationFramework.getBackend() + '/api/targets/00000000-0000-0000-' + om_object.oid.substring(0, 4) + '-' + om_object.oid.substring(4, 14) + '00">\n\ 129 <link>' + om_object.doc_url + xpointer + '</link>\n\ 130 <version>' + timestamp.toISOString() + '</version>\n\ 131 </targetInfo>\n\ 130 132 </targets>\n\ 131 133 <permissions>\n\ 132 <userWithPermission permission="owner" ref="tmpPermissionsListID'+om_object.oid+'"/>\n\ 134 <userWithPermission ref="' + annotationFramework.getBackend() + '/api/users/00000000-0000-0000-' + om_object.oid.substring(0, 4) + '-' + om_object.oid.substring(4, 14) + '00">\n\ 135 <permission>owner</permission>\n\ 136 </userWithPermission>\n\ 133 137 </permissions>\n\ 134 138 </annotation>'; … … 136 140 } 137 141 138 function hashCode(str){ 139 var hash = 0; 140 if (str == undefined || str.length == 0) return hash; 141 for (i = 0; i < str.length; i++) { 142 char = str.charCodeAt(i); 143 hash = ((hash<<5)-hash)+char; 144 hash = hash & hash; // Convert to 32bit integer 145 } 146 return hash; 142 function hashCode(str) { 143 var hash = 0; 144 if (str == undefined || str.length == 0) 145 return hash; 146 for (i = 0; i < str.length; i++) { 147 char = str.charCodeAt(i); 148 hash = ((hash << 5) - hash) + char; 149 hash = hash & hash; // Convert to 32bit integer 150 } 151 return hash; 147 152 } 148 153 149 154 if (!Date.prototype.toISOString) { 150 155 Date.prototype.toISOString = function() { 151 function pad(n) { return n < 10 ? '0' + n : n } 156 function pad(n) { 157 return n < 10 ? '0' + n : n 158 } 152 159 return this.getUTCFullYear() + '-' 153 + pad(this.getUTCMonth() + 1) + '-'154 + pad(this.getUTCDate()) + 'T'155 + pad(this.getUTCHours()) + ':'156 + pad(this.getUTCMinutes()) + ':'157 + pad(this.getUTCSeconds()) + 'Z';160 + pad(this.getUTCMonth() + 1) + '-' 161 + pad(this.getUTCDate()) + 'T' 162 + pad(this.getUTCHours()) + ':' 163 + pad(this.getUTCMinutes()) + ':' 164 + pad(this.getUTCSeconds()) + 'Z'; 158 165 }; 159 166 } 160 167 161 168 /* 162 From SQL-lite for wired-marker163 <PROPERTY>164 <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>165 <NOTE>text om en fï¿œrfattare</NOTE>166 </PROPERTY>167 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ï¿œrfattare168 */169 From SQL-lite for wired-marker 170 <PROPERTY> 171 <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> 172 <NOTE>text om en fï¿œrfattare</NOTE> 173 </PROPERTY> 174 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 175 */
Note: See TracChangeset
for help on using the changeset viewer.