Changeset 4738


Ignore:
Timestamp:
03/18/14 10:45:07 (10 years ago)
Author:
olof.olsson@snd.gu.se
Message:

send cache as multipart/mixed fixed

Location:
DASISH/t5.6/client/trunk/chrome/markingcollection/content/markingcollection/annotator-service
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/client/trunk/chrome/markingcollection/content/markingcollection/annotator-service/annotation-service.js

    r4721 r4738  
    180180            });
    181181        },
    182         postCache: function(targetURL, cacheMetadata, cache){
    183             var data = new FormData();
    184             data.append('metadata', cacheMetadata);
    185             data.append('cache', cache);
    186             annotationProxy.log('POST cache to '+targetURL);
    187             annotationProxy.log(data);
    188            
    189             $.ajax({
    190                 type: "POST",
    191                 url: targetURL,
    192                 data: data,
    193                 async: false,
    194                 cache: false,
    195                 contentType: "application/xml",
    196                 processData: false,             
    197                 success: function(xml, textStatus, jqXHR) {
    198                     annotationProxy.log('RESULT FROM CACHE STUFF');
    199                     annotationProxy.log("Status Code POST request: " + jqXHR.status);
    200                     annotationProxy.log("Response Body: " + jqXHR.responseText);
    201                 },
    202                 error: function(jqXHR, status, thrownError) {
    203                     // Handle any errors
    204                    
    205                     annotationProxy.log("+ + + + + + + + + + + + + + + + + + + + + + + +");
    206                     annotationProxy.log("Faild to POST cache for : " + targetURL);
    207                     annotationProxy.log("Status Code: " + jqXHR.status);
    208                     annotationProxy.log("Error : " + thrownError);
    209                    
    210                 }
    211             });
     182        postCache: function(targetURL, cacheMetadata, cache, cacheMimeType){
     183            var xhr = new XMLHttpRequest();
     184            xhr.onload = function() {
     185                annotationProxy.log("Cache POST status: "+xhr.status);
     186            };
     187            xhr.open("POST", targetURL, true);
     188           
     189            xhr.setRequestHeader("Content-Type","multipart/mixed; boundary="+boundary);
     190           
     191            //build the multipart body
     192            var boundary = '---------------------------'+Date.now();
     193            var postBody = '--'+boundary+'\n' +
     194                           'Content-Type:application/xml\n\n' +
     195                           cacheMetadata+'\n\n' +
     196                           '--'+boundary+'\n' +
     197                           'Content-Type:'+cacheMimeType+'\n\n' +
     198                           cache+'\n\n' +
     199                           '--'+boundary+'--';
     200            xhr.send(postBody);
    212201        },
    213202        getTargets : function(aid, callback){
  • DASISH/t5.6/client/trunk/chrome/markingcollection/content/markingcollection/annotator-service/annotations.wired.marker.js

    r4721 r4738  
    2020                    callback.call(undefined, jqXHR.status);
    2121                }
    22                
    2322            });
    2423           
     
    3635
    3736            annotationFramework.getAnnotations(url,
    38                     function(annotations) {
    39                         annotationProxy.log('got annotations ');
    40                         annotationProxy.log(annotations);
     37                function(annotations) {
     38                    annotationProxy.log('got annotations ');
     39                    annotationProxy.log(annotations);
    4140
    42                         $.each(annotations, function(index, annotationURL) {
    43                             annotationFramework.getAnnotation(annotationURL, function(result) {
    44                                 annotationProxy.log('checking if annotation exist in DB:');
    45                                 annotationProxy.log(result);
    46                                
    47                                 //check if this annotation is already in the one of the local databases
    48                                 if (bitsObjectMng.Database._dasish_aid_exists(annotationProxy.defaltDatabase, result.dasish_aid, true)) {
    49                                     annotationProxy.log('AID already in database '+annotationProxy.defaltDatabase+': ' + result.dasish_aid);
    50                                 }else if(bitsObjectMng.Database._dasish_aid_exists('_uncategorized', result.dasish_aid, true)){
    51                                     annotationProxy.log('AID already in database _uncategorized: ' + result.dasish_aid);
    52                                 } else {
    53                                     annotationProxy.log('Adding annotation to database : ' + result.dasish_aid);
    54                                     bitsObjectMng.Database.addObject(result, annotationProxy.defaltDatabase, undefined);
    55                                 }
    56                             });
     41                    $.each(annotations, function(index, annotationURL) {
     42                        annotationFramework.getAnnotation(annotationURL, function(result) {
     43                            annotationProxy.log('checking if annotation exist in DB:');
     44                            annotationProxy.log(result);
     45
     46                            //check if this annotation is already in the one of the local databases
     47                            if (bitsObjectMng.Database._dasish_aid_exists(annotationProxy.defaltDatabase, result.dasish_aid, true)) {
     48                                annotationProxy.log('AID already in database '+annotationProxy.defaltDatabase+': ' + result.dasish_aid);
     49                            }else if(bitsObjectMng.Database._dasish_aid_exists('_uncategorized', result.dasish_aid, true)){
     50                                annotationProxy.log('AID already in database _uncategorized: ' + result.dasish_aid);
     51                            } else {
     52                                annotationProxy.log('Adding annotation to database : ' + result.dasish_aid);
     53                                bitsObjectMng.Database.addObject(result, annotationProxy.defaltDatabase, undefined);
     54                            }
    5755                        });
    58                     }
     56                    });
     57                }
    5958            );
    6059        },
     
    6766                    annotationFramework.getTargets(aid,
    6867                        function(targets){
     68                            //POST cache representation for HTML
    6969                            var htmlDump = annotationProxy.getCurrentHtmlDocument();
    70                             var cacheMetadata = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n\
    71                                                  <cashedRepresentationInfo xmlns="http://www.dasish.eu/ns/addit" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" URI="https://lux17.mpi.nl/ds/webannotator/api/cached/00000000-0000-0000-0000-000000000051" xsi:schemaLocation="http://www.dasish.eu/ns/addit https://svn.clarin.eu/DASISH/t5.6/schema/trunk/annotator-schema/src/main/resources/DASISH-schema.xsd">\n\
    72                                                     <mimeType>text/plain</mimeType>\n\
    73                                                     <tool>DWAN</tool>\n\
    74                                                     <type>html</type>\n\
    75                                                  </cashedRepresentationInfo>';
    76                             annotationProxy.log(cacheMetadata);
     70                            var cacheMetadata = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'+
     71                                                '<cashedRepresentationInfo xmlns="http://www.dasish.eu/ns/addit" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \n'+
     72                                                '    URI="tmpNewCacheURI" xsi:schemaLocation="http://www.dasish.eu/ns/addit https://svn.clarin.eu/DASISH/t5.6/schema/trunk/annotator-schema/src/main/resources/DASISH-schema.xsd">\n'+
     73                                                '    <mimeType>text/html</mimeType>\n'+
     74                                                '    <tool>DWAN</tool>\n'+
     75                                                '    <type>html</type>\n'+
     76                                                '</cashedRepresentationInfo>';
     77                            var cacheMimeType = 'text/html';
    7778                            $.each(targets, function(index, targetURL){
    7879                                var xpointer = encodeURIComponent(om_object_xpointer(om_object));
    79                                 targetURL += '/fragment/placeholderForFragment/cached';
    8080                               
    81                                 annotationFramework.postCache(targetURL, htmlDump, cacheMetadata);
     81                                var xpointer = xpointer.replace(/%/g,'--');
     82                                annotationProxy.log(xpointer);
     83                                targetURL += '/fragment/'+xpointer+'/cached';
     84                               
     85                                annotationFramework.postCache(targetURL, cacheMetadata, htmlDump, cacheMimeType);
    8286                            });
    8387                    });
     
    110114            var temp = xmlS.serializeToString(document);
    111115            return temp;
    112            
    113116        },
    114117        log: function(message) {
Note: See TracChangeset for help on using the changeset viewer.