Changeset 322
- Timestamp:
- 04/08/10 14:58:57 (14 years ago)
- Location:
- ComponentRegistry/trunk/ComponentBrowserGui
- Files:
-
- 7 added
- 2 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentBrowserGui/libs/maveninstalllib.txt
r206 r322 1 mvn install:install-file -DgroupId=org.httpclient -DartifactId=as3httpclientlib -Dversion=1.0.6 -Dpackaging=swc -Dfile=as3httpclientlib-1_0_6.swc -DgeneratePom=true2 1 mvn install:install-file -DgroupId=com.adobe -DartifactId=as3corelib -Dversion=0.92.1 -Dpackaging=swc -Dfile=as3corelib-0.92.1.swc -DgeneratePom=true 3 mvn install:install-file -DgroupId=com.hurlant -DartifactId=as3crypto -Dversion=1.3 -Dpackaging=swc -Dfile=as3crypto-1.3.swc -DgeneratePom=true -
ComponentRegistry/trunk/ComponentBrowserGui/pom.xml
r224 r322 36 36 </dependency> 37 37 <dependency> 38 <groupId>org.httpclient</groupId>39 <artifactId>as3httpclientlib</artifactId>40 <version>1.0.6</version>41 <type>swc</type>42 </dependency>43 <dependency>44 38 <groupId>com.adobe</groupId> 45 39 <artifactId>as3corelib</artifactId> 46 40 <version>0.92.1</version> 47 <type>swc</type>48 </dependency>49 <dependency>50 <groupId>com.hurlant</groupId>51 <artifactId>as3crypto</artifactId>52 <version>1.3</version>53 41 <type>swc</type> 54 42 </dependency> -
ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/editor/EditorAS.as
r281 r322 77 77 } 78 78 79 //private var ref:FileReference = new FileReference();80 81 79 private function saveSpec():void { 82 80 // Alert.show(xmlEditor.cmdSpec.toXml()); 83 //ref.save(xmlEditor.cmdSpec.toXml(), "test.xml");84 85 81 var item:ItemDescription = new ItemDescription(); 86 82 item.description = xmlEditor.cmdSpec.headerDescription; -
ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/importer/Importer.mxml
r206 r322 8 8 <mx:Script> 9 9 <![CDATA[ 10 import clarin.cmdi.componentregistry.common.Credentials; 11 import mx.core.Application; 10 12 import clarin.cmdi.componentregistry.common.ItemDescription; 11 13 … … 22 24 item.description = description.text; 23 25 item.name = nameInput.text; 26 item.groupName = groupName.text; 24 27 item.isProfile = isProfile; 25 28 if (isProfile) { 26 29 uploadSrv.submitProfile(item); 27 30 } else { 28 item.groupName = groupName.text;29 31 uploadSrv.submitComponent(item); 30 32 } … … 77 79 </mx:FormItem> 78 80 <mx:FormItem label="Creator Name"> 79 <mx:Text id="creatorName" text=" loginName"/>81 <mx:Text id="creatorName" text="{Credentials.instance.userName}"/> 80 82 </mx:FormItem> 81 83 <mx:FormItem label="Group Name" -
ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/Config.as
r281 r322 9 9 private static const PROFILE_INFO_URL:String = "/rest/registry/profiles/"; 10 10 private static const COMPONENT_INFO_URL:String = "/rest/registry/components/"; 11 private static const ISOCAT_SERVLET:String = "/isocat"; 11 12 12 13 private static var _instance:Config = new Config(); … … 16 17 //Like this: "FlashVars", "serviceRootUrl=http://localhost:8080/ComponentRegistry" 17 18 18 private var _isocatSearchUrl:String = "http://www.isocat.org/rest/user/guest/search";19 //Default _isocatSearchUrl value can be useful for testing. Set the proper value in your (index.)html that embeds the flash object.20 //Like this: "FlashVars", "isocatSearchUrl=http://www.isocat.org/rest/user/guest/search"21 22 // private var _sessionId:String = "";23 24 19 public function Config() { 25 20 if (_instance != null) { 26 21 throw new Error("Config can only be accessed through Config.instance"); 27 22 } 28 var serviceRootUrl:String = Application.application.parameters.serviceRootUrl; 23 } 24 25 private function init(applicationParameters:Object):void { 26 var serviceRootUrl:String = applicationParameters.serviceRootUrl; 29 27 if (serviceRootUrl != null) { 30 28 _serviceRootUrl = serviceRootUrl; 31 29 } 32 var isocatSearchUrl:String = Application.application.parameters.isocatSearchUrl; 33 if (isocatSearchUrl != null) { 34 _isocatSearchUrl = isocatSearchUrl; 35 } 36 // var sessionId:String = Application.application.parameters.jsessionid; 37 // if (sessionId != null) { 38 // _sessionId = sessionId; 39 // } 30 } 31 32 public static function create(applicationParameters:Object):void { 33 _instance.init(applicationParameters); 40 34 } 41 35 … … 65 59 66 60 public function get isocatSearchUrl():String { 67 return _ isocatSearchUrl;61 return _serviceRootUrl + ISOCAT_SERVLET; 68 62 } 69 70 // public function get sessionId():String {71 // return _sessionId;72 // }73 63 74 64 public function get serviceRootUrl():String { -
ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/DeleteService.as
r291 r322 2 2 import clarin.cmdi.componentregistry.common.ItemDescription; 3 3 4 import com.adobe.net.URI;5 import com.hurlant.util.Base64;6 7 import flash.events.ErrorEvent;8 4 import flash.events.Event; 9 5 import flash.events.EventDispatcher; … … 11 7 import mx.controls.Alert; 12 8 import mx.managers.CursorManager; 9 import mx.messaging.messages.HTTPRequestMessage; 10 import mx.rpc.events.FaultEvent; 11 import mx.rpc.events.ResultEvent; 12 import mx.rpc.http.HTTPService; 13 13 import mx.utils.StringUtil; 14 15 import org.httpclient.HttpClient;16 import org.httpclient.events.HttpResponseEvent;17 import org.httpclient.http.Delete;18 14 19 15 [Event(name="itemDeleted", type="flash.events.Event")] … … 21 17 public class DeleteService extends EventDispatcher { 22 18 public static const ITEM_DELETED:String = "itemDeleted"; 23 private var service:HttpClient; 24 25 private static var _instance:DeleteService = new DeleteService(); 19 private var service:HTTPService; 20 private static const DELETE_METHOD:Object = {"method": "delete"}; 21 22 private static var _instance:DeleteService = new DeleteService(); 26 23 27 24 public function DeleteService() { 28 25 if (_instance != null) { 29 26 throw new Error("DeleteService should only be accessed through DeleteService.instance"); 30 27 } 31 service = new HttpClient(); 32 service.listener.onComplete = handleResult; 33 service.listener.onError = handleError; 34 } 35 36 private function getCredentials():String { 37 return Base64.encode("tomcat:tomcat"); 28 service = new HTTPService(); 29 service.addEventListener(FaultEvent.FAULT, handleError); 30 service.addEventListener(ResultEvent.RESULT, handleResult); 31 service.method = HTTPRequestMessage.POST_METHOD; 38 32 } 39 33 40 34 public function deleteItem(item:ItemDescription):void { 41 35 CursorManager.setBusyCursor(); 42 var uri:URI = new URI(item.dataUrl);//+";JSESSIONID="+Config.instance.sessionId 43 var httpDelete:Delete = new Delete(); 44 httpDelete.addHeader("Authorization", "BASIC " + getCredentials()); 45 service.request(uri, httpDelete); 36 service.url = item.dataUrl; 37 service.send(DELETE_METHOD); 46 38 } 47 39 48 private function handleResult(resultEvent: HttpResponseEvent):void {40 private function handleResult(resultEvent:ResultEvent):void { 49 41 CursorManager.removeBusyCursor(); 50 if (resultEvent. response.isSuccess) {42 if (resultEvent.statusCode >= 200 && resultEvent.statusCode < 300) { 51 43 dispatchEvent(new Event(ITEM_DELETED)); 52 } else if (resultEvent.response.isClientError) { 53 Alert.show("Unauthorized to delete item, you are not the creator."); 54 } else if (resultEvent.response.isServerError) { 55 Alert.show("Unexpected error, server returned status: " + resultEvent.response.code); 44 } else { 45 Alert.show("Unexpected error, server returned status: " + resultEvent.statusCode + "\n Message = "); 56 46 } 57 47 } 58 48 59 public function handleError(faultEvent: ErrorEvent):void {49 public function handleError(faultEvent:FaultEvent):void { 60 50 CursorManager.removeBusyCursor(); 61 var errorMessage:String = StringUtil.substitute("Error in {0}: {1}", this, faultEvent.text); 62 Alert.show(errorMessage); 51 if (faultEvent.statusCode == 401) { 52 Alert.show("Unauthorized to delete item, you are not the creator."); 53 } else { 54 var errorMessage:String = StringUtil.substitute("Error in {0} status {1}: {2}", this, faultEvent.statusCode, faultEvent.fault.faultString); 55 Alert.show(errorMessage); 56 } 63 57 } 64 58 -
ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/IsocatService.as
r238 r322 1 1 package clarin.cmdi.componentregistry.services { 2 2 import com.adobe.net.URI; 3 4 import flash.events.ErrorEvent; 3 5 4 import flash.events.EventDispatcher; 6 5 7 6 import mx.controls.Alert; 8 7 import mx.managers.CursorManager; 8 import mx.messaging.messages.HTTPRequestMessage; 9 import mx.rpc.events.FaultEvent; 10 import mx.rpc.events.ResultEvent; 11 import mx.rpc.http.HTTPService; 9 12 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 13 16 14 public class IsocatService extends EventDispatcher { … … 19 17 20 18 21 private var service:H ttpClient;19 private var service:HTTPService; 22 20 23 21 [Bindable] … … 33 31 var uri:URI = new URI(Config.instance.isocatSearchUrl); 34 32 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); 33 service.url = uri.toString(); 34 service.send(); 40 35 } 41 36 } … … 43 38 public function close():void { 44 39 if (service) { 45 service.c lose();40 service.cancel(); 46 41 } 47 42 CursorManager.removeBusyCursor(); … … 49 44 50 45 private function createClient():void { 51 service = new HttpClient(); 52 service.listener.onComplete = handleResult; 53 service.listener.onError = handleError; 54 service.listener.onData = handleData; 46 service = new HTTPService(); 47 service.method = HTTPRequestMessage.GET_METHOD; 48 service.resultFormat = HTTPService.RESULT_FORMAT_E4X; 49 service.addEventListener(ResultEvent.RESULT, handleResult); 50 service.addEventListener(FaultEvent.FAULT, handleError); 55 51 } 56 52 57 private function handleData(event:HttpDataEvent):void {58 var data:XML = new XML(event.bytes);59 searchResults = data.dcif::dataCategory;60 }61 53 62 private function handleResult(resultEvent: HttpResponseEvent):void {54 private function handleResult(resultEvent:ResultEvent):void { 63 55 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); 56 if (resultEvent.statusCode >= 200 && resultEvent.statusCode < 300) { 57 var data:XML = new XML(resultEvent.result); 58 searchResults = data.dcif::dataCategory; 59 } else { 60 Alert.show("Unexpected error, server returned status: " + resultEvent.statusCode + "\n Message = "); 68 61 } 69 62 } 70 63 71 private function handleError(faultEvent: ErrorEvent):void {64 private function handleError(faultEvent:FaultEvent):void { 72 65 CursorManager.removeBusyCursor(); 73 var errorMessage:String = StringUtil.substitute("Error in {0} : {1}", this, faultEvent.text);66 var errorMessage:String = StringUtil.substitute("Error in {0} status {1}: {2}", this, faultEvent.statusCode, faultEvent.fault.faultString); 74 67 Alert.show(errorMessage); 75 68 } -
ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/clarin/cmdi/componentregistry/services/UploadService.as
r268 r322 2 2 import clarin.cmdi.componentregistry.common.ItemDescription; 3 3 import clarin.cmdi.componentregistry.importer.UploadCompleteEvent; 4 4 5 5 import com.adobe.net.URI; 6 import com.hurlant.util.Base64; 7 8 import flash.events.DataEvent; 9 import flash.events.ErrorEvent; 6 10 7 import flash.events.Event; 8 import flash.events.HTTPStatusEvent; 11 9 import flash.events.IOErrorEvent; 12 10 import flash.events.ProgressEvent; … … 14 12 import flash.net.FileFilter; 15 13 import flash.net.FileReference; 16 14 import flash.net.URLVariables; 15 import flash.utils.ByteArray; 16 17 17 import mx.controls.ProgressBar; 18 18 import mx.managers.CursorManager; 19 20 import org.httpclient.HttpClient; 21 import org.httpclient.events.HttpDataEvent; 22 import org.httpclient.events.HttpResponseEvent; 23 import org.httpclient.http.Post; 24 import org.httpclient.http.multipart.Multipart; 25 import org.httpclient.http.multipart.Part; 19 20 import ru.inspirit.net.MultipartURLLoader; 26 21 27 22 [Event(name="uploadComplete", type="clarin.cmdi.componentregistry.importer.UploadCompleteEvent")] … … 37 32 38 33 private var fileRef:FileReference; 39 private var httpClient:HttpClient;40 34 private var pb:ProgressBar; 35 private var ml:MultipartURLLoader; 41 36 42 37 public function init(progressBar:ProgressBar):void { … … 46 41 private function createAndInitRequest():void { 47 42 CursorManager.setBusyCursor(); 48 httpClient = new HttpClient(); 49 httpClient.listener.onError = httpclientErrorHandler; 50 httpClient.listener.onData = httpclientDataHandler; 51 httpClient.listener.onComplete = httpclientCompleteHandler; 43 ml = new MultipartURLLoader(); 44 ml.addEventListener(Event.COMPLETE, completeHandler); 45 ml.addEventListener(ProgressEvent.PROGRESS, progressHandler); 46 ml.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); 47 ml.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler); 48 ml.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); 52 49 } 53 50 … … 55 52 fileRef = new FileReference(); 56 53 fileRef.addEventListener(Event.SELECT, selectHandler); 57 fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, responseHandler); 54 //no uploads are done through FileRef only loads so this UPLOAD_COMPLETE_DATA event will not be thrown 55 //fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, responseHandler); 58 56 fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler); 59 57 fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); … … 66 64 public function submitProfile(description:ItemDescription, data:String = null):void { 67 65 createAndInitRequest(); 68 submit(description, data, new URI(Config.instance.uploadProfileUrl));66 submit(description, createByteArray(data), new URI(Config.instance.uploadProfileUrl)); 69 67 } 70 68 … … 74 72 public function submitComponent(description:ItemDescription, data:String = null):void { 75 73 createAndInitRequest(); 76 submit(description, data, new URI(Config.instance.uploadComponentUrl));74 submit(description, createByteArray(data), new URI(Config.instance.uploadComponentUrl)); 77 75 } 78 76 79 private function getCredentials():String { 80 return Base64.encode("tomcat:tomcat"); 77 private function createByteArray(data:String):ByteArray { 78 var result:ByteArray = null; 79 if (data != null) { 80 result = new ByteArray(); 81 result.writeUTFBytes(data); 82 result.position = 0; 83 } 84 return result 81 85 } 82 86 83 private function submit(description:ItemDescription, data: String, uri:URI):void {87 private function submit(description:ItemDescription, data:ByteArray, uri:URI):void { 84 88 message = ""; 85 89 try { 86 90 if (data != null) { 87 var parts:Array = new Array(); 88 parts.push(new Part("description", description.description)); 89 parts.push(new Part("name", description.name)); 90 parts.push(new Part("group", description.groupName)); 91 parts.push(new Part("data", data, "application/octet-stream", [{name: "filename", value: description.name + ".xml"}])); 92 93 var multipart:Multipart = new Multipart(parts); 94 startUploadHandler(); 95 var post:Post = new Post(); 96 post.addHeader("Authorization", "BASIC " + getCredentials()); 97 post.setMultipart(multipart); 98 httpClient.request(uri, post); 91 var params:URLVariables = new URLVariables(); 92 ml.addVariable("description", description.description); 93 ml.addVariable("name", description.name); 94 ml.addVariable("group", description.groupName); 95 ml.addFile(data, description.name + ".xml", "data"); 96 ml.load(uri.toString()); 99 97 } else { 100 // Cannot sent credentials with FileReference.upload so just load the data and then submit through HttpClient 98 // Cannot sent data that is not a file with FileReference.upload so just load the data and then submit through HttpClient. 99 // FileReference also does not handle authentication tokens. 101 100 startUploadHandler(); 102 101 if (fileRef.data == null) { 103 102 //only load if not loaded before otherwise sent the already loaded file. You can only force a reload of the file by selecting it again (it is a flash thingy). 104 103 fileRef.addEventListener(Event.COMPLETE, function(event:Event):void { 105 submit(description, new String(fileRef.data), uri);104 submit(description, fileRef.data, uri); 106 105 }); 107 106 fileRef.load(); 108 107 } else { 109 submit(description, new String(fileRef.data), uri);108 submit(description, fileRef.data, uri); 110 109 } 111 110 } … … 129 128 } 130 129 131 private function httpclientCompleteHandler(event:HttpResponseEvent):void { 132 if (!event.response.isSuccess) { 133 addToMessage("Server Failed to handle registration. Unexpected error, try again later. (httpstatus code was: " + event.response.code + ")\n"); 134 } 135 CursorManager.removeBusyCursor(); 136 httpClient.close(); 137 } 138 139 private function httpclientDataHandler(event:HttpDataEvent):void { 130 private function completeHandler(event:Event):void { 140 131 uploadComplete(); 141 var response:XML = new XML( event.bytes);132 var response:XML = new XML(ml.loader.data); 142 133 handleResponse(response); 143 134 } 144 135 145 private function httpclientErrorHandler(event:ErrorEvent):void { 146 addToMessage("Server Failed to handle registration. Unexpected error, try again later. (error: " + event.text + ")\n"); 136 private function httpStatusHandler(event:HTTPStatusEvent):void { 137 if (event.status != 200) { 138 addToMessage("Server Failed to handle registration. Unexpected error, try again later. (httpstatus code was: " + event.status + ")\n"); 139 } 140 CursorManager.removeBusyCursor(); 147 141 } 148 142 149 143 private function securityErrorHandler(event:SecurityErrorEvent):void { 150 144 addToMessage("Server Failed to handle registration. Unexpected error, try again later. (error: " + event.text + ")\n"); 145 CursorManager.removeBusyCursor(); 151 146 } 152 147 153 148 private function ioErrorHandler(event:IOErrorEvent):void { 154 149 addToMessage("Unable to load file. (error: " + event.text + ")\n"); 150 CursorManager.removeBusyCursor(); 155 151 } 156 152 … … 158 154 trace("Uploading: " + event.bytesLoaded + "/" + event.bytesTotal); 159 155 pb.setProgress(event.bytesLoaded, event.bytesTotal); 160 }161 162 163 private function responseHandler(event:DataEvent):void {164 uploadComplete();165 var response:XML = new XML(event.data);166 handleResponse(response);167 156 } 168 157 … … 186 175 createErrorMessage(response); 187 176 } 188 189 177 } 190 178 … … 192 180 pb.label = "Upload complete"; 193 181 pb.setProgress(100, 100); 182 CursorManager.removeBusyCursor(); 194 183 } 195 184 -
ComponentRegistry/trunk/ComponentBrowserGui/src/main/flex/main.mxml
r281 r322 3 3 xmlns:common="clarin.cmdi.componentregistry.common.components.*" 4 4 layout="absolute" 5 preinitialize="initializeInstances();" 5 6 applicationComplete="init();" 6 7 backgroundColor="#DDE3EF"> … … 9 10 <![CDATA[ 10 11 import clarin.cmdi.componentregistry.services.Config; 12 import clarin.cmdi.componentregistry.common.Credentials; 11 13 import flash.net.navigateToURL; 12 14 import mx.managers.PopUpManager; 13 import clarin.cmdi.componentregistry.services.UploadService;14 15 import org.hasseg.externalMouseWheel.ExternalMouseWheelSupport; 15 16 17 private function initializeInstances():void { 18 Config.create(Application.application.parameters); 19 Credentials.create(Application.application.parameters); 20 } 21 16 22 private function init():void { 17 23 ExternalMouseWheelSupport.getInstance(stage); 18 //var sessionId:String = Application.application.parameters.jsessionid;19 //trace("JSession=" + sessionId);20 // var urltext:String = "/webapp/ChartXML.do;JSESSIONID="+JSESSIONID;21 // trace ("Requested URL:",urltext);22 // httpService.url= urltext;23 // httpService.send();24 // trace("httpService sent");25 24 } 26 25 27 private function handleLogin(event:MouseEvent):void { 28 var req:URLRequest = new URLRequest(); 29 req.url = Config.instance.serviceRootUrl + "?shhaaDo=lI"; 30 navigateToURL(req, "_top"); 31 } 32 33 [Bindable] 34 private var userName:String = ""; 35 36 private function checkUser():void { 37 userName = Application.application.parameters.userName; 38 trace("user = " + userName); 39 } 26 // private function handleLogin(event:MouseEvent):void { 27 // var req:URLRequest = new URLRequest(); 28 // req.url = Config.instance.serviceRootUrl + "?shhaaDo=lI"; 29 // navigateToURL(req, "_top"); 30 // } 40 31 ]]> 41 32 </mx:Script> … … 50 41 <mx:VBox height="100%" 51 42 width="100%"> 52 <mx:HBox borderStyle="none"> 43 <mx:HBox borderStyle="none" 44 width="100%"> 53 45 <mx:ToggleButtonBar id="toggleBar" 54 dataProvider="{viewStack}" 55 initialize="checkUser();"/> 56 <mx:Button id="login" 57 label="login {userName}" 58 click="handleLogin(event)"/> 46 dataProvider="{viewStack}"/> 47 <mx:Spacer width="90%"/> 48 <mx:Label text="User: {Credentials.instance.userName}"/> 49 <!-- <mx:Button id="login" 50 label="login {userName}" 51 click="handleLogin(event)"/>--> 59 52 </mx:HBox> 60 53 <common:RegistryViewStack id="viewStack"
Note: See TracChangeset
for help on using the changeset viewer.