source: DASISH/t5.6/client/trunk/chrome/markingcollection/content/markingcollection/annotator-service/test/mockjax/mockjax-xml.js @ 3418

Last change on this file since 3418 was 3418, checked in by sroth, 11 years ago

Update so that all available mock xml samples get called.

File size: 5.4 KB
Line 
1/*
2 * @content Mocking retrieval of annotations
3 * (see: https://trac.clarin.eu/wiki/DASISH/XSD%20and%20XML#RespondingGETapiannotationslinkhttp:en.wikipedia.orgwikiSagrada_FamC3ADliaaccessread;
4 * Scenario - visiting an annotated web page: https://trac.clarin.eu/wiki/DASISH/Scenario)
5 */
6
7var url = '/api/annotations?link="http://en.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"';
8
9// Mock for Responding GET api/annotations?link="URI"
10$.mockjax({
11    /* url: A string or regular expression specifying the url of the request that the data should be mocked for. */
12    // url: '/api/annotations?link="http://en.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"&access=read',
13    url: url,
14    // url: '/api/annotations?link="http://en.wikipedia.org/wiki/Sagrada_Fam%C3%ADlia"',
15    /* type: Specify what HTTP method to match, usually GET or POST. Case-insensitive, so get and post also work. */
16    type: 'GET',
17    /* dataType: Allowed data formats are Text, HTML, JSON, Script and XML. */
18    dataType: 'xml',
19    /* responseTime: An integer that specifies a simulated network and server latency (in milliseconds). */
20    responseTime: 750,
21    /* proxy: A string specifying a path to a file, from which the contents will be returned for the request. */
22    proxy: 'mocks/annotations-sagrada-GET.xml',
23});
24
25// Mock for Responding GET api/annotations/AID20130808114716 (annot-0001-GET.xml)
26$.mockjax({
27    url: '/api/annotations/AID20130808114716',
28    type: 'GET',
29    dataType: 'xml',
30    responseTime: 750,
31    proxy: 'mocks/annot-0001-GET.xml',
32});
33
34// Mock for Responding GET api/annotations/AID20130808124131 (annot-0002-GET.xml)
35$.mockjax({
36    url: '/api/annotations/AID20130808124131',
37    type: 'GET',
38    dataType: 'xml',
39    responseTime: 750,
40    proxy: 'mocks/annot-0002-GET.xml',
41});
42
43// Mock for Responding GET api/annotations/AID20130809151651 (annot-0003-GET.xml)
44$.mockjax({
45    url: '/api/annotations/AID20130809151651',
46    type: 'GET',
47    dataType: 'xml',
48    responseTime: 750,
49    proxy: 'mocks/annot-0003-GET.xml',
50});
51
52// Mock for Responding GET api/annotations/AID20130816145322 (annot-0004-GET.xml)
53$.mockjax({
54    url: '/api/annotations/AID20130816145322',
55    type: 'GET',
56    dataType: 'xml',
57    responseTime: 750,
58    proxy: 'mocks/annot-0004-GET.xml',
59});
60
61// Mock for Responding GET api/annotations/AID20130816170015 (annot-0005-GET.xml)
62$.mockjax({
63    url: '/api/annotations/AID20130816170015',
64    type: 'GET',
65    dataType: 'xml',
66    responseTime: 750,
67    proxy: 'mocks/annot-0005-GET.xml',
68});
69
70var XMLData = function() {
71    return {
72        getMockAnnotations: function(url) {
73            $.ajax({
74                url: url,
75                dataType: 'xml',
76                type: 'GET',
77                success: function(xml, textStatus, jqXHR) {
78                    // success: function(xml) {   
79                    // can be used if parameters textStatus and jqXHR are not required within the following code block
80
81                    $xml = $(xml);
82                   
83                    console.log('Data: ' + $xml);
84                    console.log($xml);
85                    console.log('Status: ' + textStatus);
86                    console.log('XMLHttpRequest object: ' + jqXHR);
87                    console.log(jqXHR);
88                   
89                    var aidArr = [];
90                    var aid_string = "";
91                   
92                    $xml.find('annotations annotation').each(function() {
93                        $aid_uri = $(this).attr('ref');
94                        aidArr.push($aid_uri.substr($aid_uri.lastIndexOf('/')+1)); // http://dasish.eu/annotations/ is erased
95                    });
96
97                    console.log(aidArr);
98
99                    for (var i in aidArr) {
100                        aid_string += '<br />' + aidArr[i];
101                        $('#xmlContents').html('<h4 style="margin-bottom: 0;">List of AIDs returned from REST service address<br />GET api/annotations?link="URI":</h4>' + aid_string);
102                        url = "";
103                        url = '/api/annotations/' + aidArr[i];
104                       
105                        $.ajax({
106                            url: url,
107                            dataType: 'xml',
108                            type: 'GET',
109                            success: function(xml) {
110                               
111                                $xml = $(xml);
112   
113                                var body = "";
114                                var aid = "";
115                               
116                                $xml.find('annotation').each(function() {
117                                    body = $(this).find('body').text();
118                                    aid = $(this).attr('URI').substr($(this).attr('URI').lastIndexOf('/')+1);
119 
120                                    $('#xmlContents').append("<br /><br /><strong>Body content of " + aid + ":</strong><br /><em>" + body + "</em>");
121                                   
122                                    var om_object = annotation2om_object(this);
123                                    $('#xmlContents').append("<br /><strong>converted to om_object:</strong><br/><textarea cols='130' rows='16'>"+JSON.stringify(om_object, null, '  ')+"</textarea>");
124                                });   
125                               
126                            }
127                        });
128
129                    }
130
131                }
132
133            });
134        }
135    }
136}();
137
138XMLData.getMockAnnotations(url);
Note: See TracBrowser for help on using the repository browser.