source: ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/IsocatService.as @ 238

Last change on this file since 238 was 238, checked in by patdui, 14 years ago
File size: 2.2 KB
Line 
1package clarin.cmdi.componentregistry.services {
2        import com.adobe.net.URI;
3
4        import flash.events.ErrorEvent;
5        import flash.events.EventDispatcher;
6
7        import mx.controls.Alert;
8        import mx.managers.CursorManager;
9        import mx.utils.StringUtil;
10
11        import org.httpclient.HttpClient;
12        import org.httpclient.events.HttpDataEvent;
13        import org.httpclient.events.HttpResponseEvent;
14        import org.httpclient.http.Get;
15
16        public class IsocatService extends EventDispatcher {
17                public static const PROFILE_LOADED:String = "ProfileLoaded";
18                namespace dcif = "http://www.isocat.org/ns/dcif";
19
20
21                private var service:HttpClient;
22
23                [Bindable]
24                public var searchResults:XMLList;
25
26                public function IsocatService() {
27                }
28
29                public function load(keyword:String):void {
30                        if (keyword) {
31                                createClient();
32                                CursorManager.setBusyCursor();
33                                var uri:URI = new URI(Config.instance.isocatSearchUrl);
34                                uri.setQueryValue("keywords", keyword);
35                                uri.setQueryValue("dcif-mode", "list");
36
37                                var httpGet:Get = new Get();
38                                httpGet.addHeader("Accept", "application/dcif+xml");
39                                service.request(uri, httpGet);
40                        }
41                }
42
43                public function close():void {
44                        if (service) {
45                                service.close();
46                        }
47                        CursorManager.removeBusyCursor();
48                }
49
50                private function createClient():void {
51                        service = new HttpClient();
52                        service.listener.onComplete = handleResult;
53                        service.listener.onError = handleError;
54                        service.listener.onData = handleData;
55                }
56
57                private function handleData(event:HttpDataEvent):void {
58                        var data:XML = new XML(event.bytes);
59                        searchResults = data.dcif::dataCategory;
60                }
61
62                private function handleResult(resultEvent:HttpResponseEvent):void {
63                        CursorManager.removeBusyCursor();
64                        if (resultEvent.response.isClientError) {
65                                Alert.show("Unauthorized search, server return status:" + resultEvent.response.code);
66                        } else if (resultEvent.response.isServerError) {
67                                Alert.show("Unexpected error, server returned status: " + resultEvent.response.code);
68                        }
69                }
70
71                private function handleError(faultEvent:ErrorEvent):void {
72                        CursorManager.removeBusyCursor();
73                        var errorMessage:String = StringUtil.substitute("Error in {0}: {1}", this, faultEvent.text);
74                        Alert.show(errorMessage);
75                }
76
77
78        }
79}
80
Note: See TracBrowser for help on using the repository browser.