1 | package clarin.cmdi.componentregistry.services { |
---|
2 | import clarin.cmdi.componentregistry.common.ItemDescription; |
---|
3 | |
---|
4 | import com.adobe.net.URI; |
---|
5 | |
---|
6 | import flash.events.Event; |
---|
7 | import flash.events.EventDispatcher; |
---|
8 | |
---|
9 | [Event(name="userSpaceToggle", type="flash.events.Event")] |
---|
10 | public final class Config extends EventDispatcher { |
---|
11 | public static const USER_SPACE_TOGGLE_EVENT:String = "userSpaceToggle"; |
---|
12 | |
---|
13 | public static const CLARIN_REGISTER_URL:String = "http://www.clarin.eu/user/register"; |
---|
14 | public static const PARAM_USERSPACE:String = "userspace"; |
---|
15 | public static const REGISTRY_PARAM_VIEW:String = "view"; |
---|
16 | public static const REGISTRY_PARAM_ITEM:String = "item"; |
---|
17 | public static const REGISTRY_PARAM_SPACE:String = "space"; |
---|
18 | public static const REGISTRY_PARAM_DEBUG:String = "debug"; |
---|
19 | |
---|
20 | //Possible views to start with. |
---|
21 | public static const VIEW_BROWSE:String = "browse"; |
---|
22 | public static const VIEW_EDIT:String = "edit"; |
---|
23 | public static const VIEW_IMPORT:String = "import"; |
---|
24 | //Possible space to start with. |
---|
25 | public static const SPACE_USER:String = "user"; |
---|
26 | public static const SPACE_PUBLIC:String = "public"; |
---|
27 | |
---|
28 | private static const COMPONENT_LIST_URL:String = "/rest/registry/components"; |
---|
29 | private static const PROFILE_LIST_URL:String = "/rest/registry/profiles"; |
---|
30 | private static const UPLOAD_PROFILE_SERVICE_URL:String = "/rest/registry/profiles"; |
---|
31 | private static const UPLOAD_COMPONENT_SERVICE_URL:String = "/rest/registry/components"; |
---|
32 | private static const PROFILE_INFO_URL:String = "/rest/registry/profiles/"; |
---|
33 | private static const COMPONENT_INFO_URL:String = "/rest/registry/components/"; |
---|
34 | private static const PING_SESSION_URL:String = "/rest/registry/pingSession"; |
---|
35 | private static const ISOCAT_SERVLET:String = "/isocat"; |
---|
36 | |
---|
37 | |
---|
38 | private static var _instance:Config = new Config(); |
---|
39 | |
---|
40 | private var _startupItem:String; //item to be selected at startup, can be specified as a url parameter |
---|
41 | private var _serviceRootUrl:String = "http://localhost:8080/ComponentRegistry"; |
---|
42 | //Default _serviceRootUrl value can be useful for testing. Set the proper value in your (index.)html that embeds the flash object. |
---|
43 | //Like this: "FlashVars", "serviceRootUrl=http://localhost:8080/ComponentRegistry" |
---|
44 | |
---|
45 | private var _view:String = VIEW_BROWSE; |
---|
46 | private var _space:String = SPACE_PUBLIC; |
---|
47 | private var _userSpace:Boolean = false; |
---|
48 | private var _debug:Boolean = false; |
---|
49 | |
---|
50 | public function Config() { |
---|
51 | if (_instance != null) { |
---|
52 | throw new Error("Config can only be accessed through Config.instance"); |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | private function init(applicationParameters:Object):void { |
---|
57 | var serviceRootUrl:String = applicationParameters.serviceRootUrl; |
---|
58 | if (serviceRootUrl) { |
---|
59 | _serviceRootUrl = serviceRootUrl; |
---|
60 | } |
---|
61 | var item:String = applicationParameters.item; |
---|
62 | if (item) { |
---|
63 | _startupItem = item; |
---|
64 | } |
---|
65 | var view:String = applicationParameters.view; |
---|
66 | if (view) { |
---|
67 | _view = view; |
---|
68 | } |
---|
69 | var space:String = applicationParameters.space; |
---|
70 | if (space) { |
---|
71 | _space = space; |
---|
72 | } |
---|
73 | var debug:int = applicationParameters.debug; |
---|
74 | if(debug) { |
---|
75 | _debug = Boolean(debug); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | public static function create(applicationParameters:Object):void { |
---|
80 | _instance.init(applicationParameters); |
---|
81 | } |
---|
82 | |
---|
83 | public function get profileListUrl():String { |
---|
84 | return _serviceRootUrl + PROFILE_LIST_URL; |
---|
85 | } |
---|
86 | |
---|
87 | public function get componentListUrl():String { |
---|
88 | return _serviceRootUrl + COMPONENT_LIST_URL; |
---|
89 | } |
---|
90 | |
---|
91 | public function get profileInfoUrl():String { |
---|
92 | return _serviceRootUrl + PROFILE_INFO_URL; |
---|
93 | } |
---|
94 | |
---|
95 | public function get componentInfoUrl():String { |
---|
96 | return _serviceRootUrl + COMPONENT_INFO_URL; |
---|
97 | } |
---|
98 | |
---|
99 | public function get uploadProfileUrl():String { |
---|
100 | return _serviceRootUrl + UPLOAD_PROFILE_SERVICE_URL; |
---|
101 | } |
---|
102 | |
---|
103 | public function get uploadComponentUrl():String { |
---|
104 | return _serviceRootUrl + UPLOAD_COMPONENT_SERVICE_URL; |
---|
105 | } |
---|
106 | |
---|
107 | public function get isocatSearchUrl():String { |
---|
108 | return _serviceRootUrl + ISOCAT_SERVLET; |
---|
109 | } |
---|
110 | |
---|
111 | public function get serviceRootUrl():String { |
---|
112 | return _serviceRootUrl; |
---|
113 | } |
---|
114 | |
---|
115 | public function get pingSessionUrl():String { |
---|
116 | return _serviceRootUrl + PING_SESSION_URL; |
---|
117 | } |
---|
118 | |
---|
119 | public function set userSpace(userSpace:Boolean):void { |
---|
120 | if (_userSpace != userSpace) { |
---|
121 | _userSpace = userSpace; |
---|
122 | dispatchEvent(new Event(USER_SPACE_TOGGLE_EVENT)); |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | public function get userSpace():Boolean { |
---|
127 | return _userSpace; |
---|
128 | } |
---|
129 | |
---|
130 | public function get startupItem():String { |
---|
131 | return _startupItem; |
---|
132 | } |
---|
133 | |
---|
134 | public function get view():String { |
---|
135 | return _view; |
---|
136 | } |
---|
137 | |
---|
138 | public function get space():String { |
---|
139 | return _space; |
---|
140 | } |
---|
141 | |
---|
142 | public function get debug():Boolean { |
---|
143 | return _debug; |
---|
144 | } |
---|
145 | |
---|
146 | public static function getBookmarkUrl(item:ItemDescription):String { |
---|
147 | var uri:URI = new URI(Config.instance.serviceRootUrl); |
---|
148 | uri.setQueryValue(REGISTRY_PARAM_ITEM, item.id); |
---|
149 | if (item.isInUserSpace) { |
---|
150 | uri.setQueryValue(REGISTRY_PARAM_SPACE, SPACE_USER); |
---|
151 | } |
---|
152 | return uri.toString(); |
---|
153 | } |
---|
154 | |
---|
155 | public static function getXsdLink(item:ItemDescription):String { |
---|
156 | var uri:URI = new URI(item.dataUrl+"/xsd"); |
---|
157 | return uri.toString(); |
---|
158 | } |
---|
159 | |
---|
160 | public static function get instance():Config { |
---|
161 | return _instance; |
---|
162 | } |
---|
163 | |
---|
164 | } |
---|
165 | } |
---|