1 Components.utils.import("resource://stmodules/STRequests.jsm"); 2 Components.utils.import("resource://stmodules/Logger.jsm"); 3 Components.utils.import("resource://stmodules/Deserializer.jsm"); 4 Components.utils.import("resource://stmodules/stEvtMgr.jsm"); 5 6 Components.utils.import("resource://stmodules/Context.jsm"); 7 8 EXPORTED_SYMBOLS = [ "SemTurkeyHTTPLegacy", "STRequests" ]; 9 10 var service = STRequests.RangeAnnotation; 11 var serviceName = service.serviceName; 12 13 /** 14 * given page <code>urlPage</code>, this method tells if the page contains annotations 15 * 16 * @member STRequests.RangeAnnotation 17 * @param urlPage 18 * @return 19 */ 20 function chkAnnotation(urlPage) { 21 var urlPage="urlPage="+urlPage; 22 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 23 return SemTurkeyHTTPLegacy.GET(serviceName, service.chkAnnotationsRequest,urlPage, contextAsArray); 24 } 25 26 /** 27 * given page <code>urlPage</code>, it returns all annotations previously taken on that page 28 * 29 * @member STRequests.Annotation 30 * @param urlPage 31 * @return 32 */ 33 function getPageAnnotations(urlPage) { 34 var urlPage="urlPage="+urlPage; 35 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 36 var reponseXML = SemTurkeyHTTPLegacy.GET(serviceName, service.getPageAnnotationsRequest,urlPage,contextAsArray); 37 var annotations = []; 38 var annotationsXML = reponseXML.getElementsByTagName("RangeAnnotation"); 39 40 for (var i = 0 ; i < annotationsXML.length ; i++) { 41 var annXML = annotationsXML[i]; 42 43 annotations.push( 44 { 45 id : annXML.getAttribute("id"), 46 resource : annXML.getAttribute("resource"), 47 value : annXML.getAttribute("value"), 48 range : annXML.getAttribute("range") 49 } 50 ); 51 } 52 53 return annotations; 54 } 55 56 /** 57 * 58 * @member STRequests.RangeAnnotation 59 * @param resource 60 * @param lexicalization 61 * @param urlPage 62 * @param title 63 * @param range 64 * @return 65 */ 66 function addAnnotation(resource, lexicalization, urlPage, title, range) { 67 var resource_p = "resource=" + resource; 68 var lexicalization_p = "lexicalization=" + lexicalization; 69 var urlPage_p = "urlPage=" + urlPage; 70 var title_p = "title=" + title; 71 var range_p = "range=" + range; 72 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 73 var responseXML = SemTurkeyHTTPLegacy.GET(serviceName, service.addAnnotationRequest,resource_p, lexicalization_p, 74 urlPage_p, title_p, range_p, contextAsArray); 75 76 return responseXML; 77 } 78 79 /** 80 * 81 * @member STRequests.RangeAnnotation 82 * @param id 83 * @return 84 */ 85 function deleteAnnotation(id) { 86 var id_p = "id=" + id; 87 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 88 var responseXML = SemTurkeyHTTPLegacy.GET(serviceName, service.deleteAnnotationRequest, id_p, contextAsArray); 89 90 if (!responseXML.isFail()) { 91 var annotation; 92 93 evtMgr.fireEvent("annotationDeleted", { 94 getId : function(){return id;} 95 }); 96 } 97 98 return responseXML; 99 } 100 101 /** 102 * 103 * @member STRequests.RangeAnnotation 104 * @param resource 105 * @return 106 */ 107 function getAnnotatedContentResources(resource) { 108 var resource_p = "resource=" + resource; 109 110 var contextAsArray = this.context.getContextValuesForHTTPGetAsArray(); 111 var responseXML = SemTurkeyHTTPLegacy.GET(serviceName, service.getAnnotatedContentResourcesRequest, resource_p, 112 contextAsArray); 113 114 var response = []; 115 116 var urlElements = responseXML.getElementsByTagName("URL"); 117 118 for (var i = 0 ; i < urlElements.length ; i++) { 119 var obj = {}; 120 obj.title = urlElements[i].getAttribute("title"); 121 obj.value = urlElements[i].getAttribute("value"); 122 123 response.push(obj); 124 } 125 126 return response; 127 } 128 129 // Range Annotation SERVICE INITIALIZATION 130 //this return an implementation for Project with a specified context 131 service.prototype.getAPI = function(specifiedContext){ 132 var newObj = new service(); 133 newObj.context = specifiedContext; 134 return newObj; 135 } 136 service.prototype.chkAnnotation = chkAnnotation; 137 service.prototype.getPageAnnotations = getPageAnnotations; 138 service.prototype.addAnnotation = addAnnotation; 139 service.prototype.deleteAnnotation = deleteAnnotation; 140 service.prototype.getAnnotatedContentResources = getAnnotatedContentResources; 141 service.prototype.context = new Context(); // set the default context 142 service.constructor = service; 143 service.__proto__ = service.prototype; 144