flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [25/37] git commit: [flex-asjs] [refs/heads/spark] - Added permanent storage option to Storage project.
Date Thu, 24 Mar 2016 19:59:46 GMT
Added permanent storage option to Storage project.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/1bc555d9
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/1bc555d9
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/1bc555d9

Branch: refs/heads/spark
Commit: 1bc555d93d756abdf804e39e0521df726d4f0dac
Parents: 6271091
Author: Peter Ent <pent@apache.org>
Authored: Wed Mar 9 11:12:28 2016 -0500
Committer: Peter Ent <pent@apache.org>
Committed: Wed Mar 9 11:12:28 2016 -0500

----------------------------------------------------------------------
 frameworks/projects/Storage/build.xml           |   3 +
 .../Storage/src/main/flex/StorageClasses.as     |   9 +
 .../apache/flex/storage/IPermanentStorage.as    |  63 +++++++
 .../org/apache/flex/storage/PermanentStorage.as |  97 +++++++++++
 .../apache/flex/storage/events/FileReadEvent.as |  70 ++++++++
 .../flex/storage/events/FileWriteEvent.as       |  60 +++++++
 .../org/apache/flex/storage/file/LocalFile.as   |  84 +++++++++
 .../storage/providers/AirStorageProvider.as     | 165 ++++++++++++++++++
 .../providers/IPermanentStorageProvider.as      |  74 ++++++++
 .../storage/providers/WebStorageProvider.as     | 169 +++++++++++++++++++
 .../src/main/resources/basic-manifest.xml       |   1 +
 .../Storage/src/main/resources/defaults.css     |  16 ++
 12 files changed, 811 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1bc555d9/frameworks/projects/Storage/build.xml
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/build.xml b/frameworks/projects/Storage/build.xml
index 0d5fd9a..6fc0ed5 100644
--- a/frameworks/projects/Storage/build.xml
+++ b/frameworks/projects/Storage/build.xml
@@ -30,6 +30,7 @@
     <property name="FALCONJX_HOME" value="${env.FALCONJX_HOME}"/>
     <property name="JS.SWC" value="${FALCONJX_HOME}/../externs/js/out/bin/js.swc" />
     <property name="GCL.SWC" value="${FALCONJX_HOME}/../externs/GCL/out/bin/GCL.swc" />
+    <property name="CORDOVA.SWC" value="${FALCONJX_HOME}/../externs/cordova/out/bin/cordova.swc"
/>
     <property name="target.name" value="Storage-${release.version}.swc" />
     <property name="target.name.no.version" value="Storage.swc" />
 
@@ -118,6 +119,7 @@
             <arg value="-external-library-path+=${JS.SWC}" />
             <!-- this is not on external-library path otherwise goog.requires are not
generated -->
             <arg value="-library-path+=${GCL.SWC}" />
+            <arg value="--external-library-path+=${CORDOVA.SWC}" />
             <arg value="-define=COMPILE::AS3,false" />
             <arg value="-define=COMPILE::JS,true" />
         </java>
@@ -155,6 +157,7 @@
             <arg value="-external-library-path+=${JS.SWC}" />
             <!-- this is not on external-library path otherwise goog.requires are not
generated -->
             <arg value="-library-path+=${GCL.SWC}" />
+            <arg value="--external-library-path+=${CORDOVA.SWC}" />
             <arg value="-define=COMPILE::AS3,false" />
             <arg value="-define=COMPILE::JS,true" />
         </compc>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1bc555d9/frameworks/projects/Storage/src/main/flex/StorageClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/src/main/flex/StorageClasses.as b/frameworks/projects/Storage/src/main/flex/StorageClasses.as
index db34477..92d9bd4 100644
--- a/frameworks/projects/Storage/src/main/flex/StorageClasses.as
+++ b/frameworks/projects/Storage/src/main/flex/StorageClasses.as
@@ -29,6 +29,15 @@ internal class StorageClasses
 {
     import org.apache.flex.storage.LocalStorage; LocalStorage;
     import org.apache.flex.storage.providers.LocalStorageProvider; LocalStorageProvider;
+
+	import org.apache.flex.storage.PermanentStorage; PermanentStorage;
+	import org.apache.flex.storage.events.FileReadEvent; FileReadEvent;
+	import org.apache.flex.storage.events.FileWriteEvent; FileWriteEvent;
+
+	import org.apache.flex.storage.providers.AirStorageProvider; AirStorageProvider;
+
+	import org.apache.flex.storage.providers.WebStorageProvider; WebStorageProvider;
+
 }
 
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1bc555d9/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/IPermanentStorage.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/IPermanentStorage.as
b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/IPermanentStorage.as
new file mode 100644
index 0000000..d47866b
--- /dev/null
+++ b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/IPermanentStorage.as
@@ -0,0 +1,63 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.storage
+{
+	import org.apache.flex.events.IEventDispatcher;
+	
+	/**
+	 * The IPermanentStorage interface provides the template for creating
+	 * an interface to a device's native file system.
+	 *
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion FlexJS 0.0
+	 */
+	public interface IPermanentStorage extends IEventDispatcher
+	{	
+		/**
+		 * A convenience function to read an entire file as a single 
+		 * string of text. The file is storaged in the application's
+		 * data storage directory. 
+		 * 
+		 *  @param fileName The name of the file.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		function readTextFromDataFile( fileName:String ) : void;
+		
+		/**
+		 * A convenience function write a string into a file that resides in the
+		 * application's data storage directory. If the file already exists it is 
+		 * replaced with the string.
+		 * 
+		 *  @param fileName The name of file.
+		 *  @param text The string to be stored.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		function writeTextToDataFile( fileName:String, text:String ) : void;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1bc555d9/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/PermanentStorage.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/PermanentStorage.as
b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/PermanentStorage.as
new file mode 100644
index 0000000..d1e8887
--- /dev/null
+++ b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/PermanentStorage.as
@@ -0,0 +1,97 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.storage
+{
+	import org.apache.flex.events.EventDispatcher;
+	import org.apache.flex.events.IEventDispatcher;
+	import org.apache.flex.core.ValuesManager;
+
+	import org.apache.flex.storage.providers.AirStorageProvider;
+	import org.apache.flex.storage.providers.IPermanentStorageProvider;
+
+	/**
+	 * The PermanentStorage class provides the interface to the native
+	 * file system. This classes uses the FlexJS ValuesManager to provide
+	 * the actual implementation using the iStorage style.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+	 */
+	public class PermanentStorage extends EventDispatcher implements IPermanentStorage
+	{
+		/**
+		 * Constructor.
+	     *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function PermanentStorage()
+		{
+			super();
+			_storageProvider = ValuesManager.valuesImpl.newInstance(this, "iStorageProvider") as IPermanentStorageProvider;
+			_storageProvider.target = this;
+		}
+
+		/**
+		 * @private
+		 */
+		private var _storageProvider:IPermanentStorageProvider;
+
+		/**
+		 * A convenience function to read an entire file as a single 
+		 * string of text. The file is storaged in the application's
+		 * data storage directory. Dispatches a FileRead event once
+		 * the data is available.
+		 * 
+		 *  @param fileName The name of the file.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function readTextFromDataFile( fileName:String ) : void
+		{
+			_storageProvider.readTextFromDataFile( fileName );
+		}
+		
+		/**
+		 * A convenience function write a string into a file that resides in the
+		 * application's data storage directory. If the file already exists it is 
+		 * replaced with the string. Dispatches a FileWrite event once the file
+		 * has been written.
+		 * 
+		 *  @param fileName The name of file.
+		 *  @param text The string to be stored.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function writeTextToDataFile( fileName:String, text:String ) : void
+		{
+			_storageProvider.writeTextToDataFile( fileName, text );
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1bc555d9/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/events/FileReadEvent.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/events/FileReadEvent.as
b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/events/FileReadEvent.as
new file mode 100644
index 0000000..528c36b
--- /dev/null
+++ b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/events/FileReadEvent.as
@@ -0,0 +1,70 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.storage.events
+{
+	import org.apache.flex.events.Event;
+	
+	/**
+	 * The FileReadEvent class is used to signal varies events in the life and
+	 * use of permanent files. 
+	 * 
+	 * COMPLETE - The file has been completely read.
+	 * ERROR    - An error occurred reading or opening the file.
+	 *
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion FlexJS 0.0
+	 */
+	public class FileReadEvent extends Event
+	{
+		/**
+		 * Constructor.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function FileReadEvent(type:String)
+		{
+			super(type);
+		}
+		
+		/**
+		 * The data read from the file.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public var data:String;
+		
+		/**
+		 * If not null, the error that occurred opening or reading the file.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public var errorMessage:String;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1bc555d9/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/events/FileWriteEvent.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/events/FileWriteEvent.as
b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/events/FileWriteEvent.as
new file mode 100644
index 0000000..fea4542
--- /dev/null
+++ b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/events/FileWriteEvent.as
@@ -0,0 +1,60 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.storage.events
+{
+	import org.apache.flex.events.Event;
+	
+	/**
+	 * The FileWriteEvent class is used to signal varies events in the life and
+	 * use of permanent files. 
+	 * 
+	 * COMPLETE - The file has been successfully written.
+	 * ERROR    - An error occurred writing or opening the file.
+	 *
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion FlexJS 0.0
+	 */
+	public class FileWriteEvent extends Event
+	{
+		/**
+		 * Constructor.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function FileWriteEvent(type:String)
+		{
+			super(type);
+		}
+		
+		/**
+		 * If not null, the error that occurred opening or writing the file.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public var errorMessage:String;
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1bc555d9/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/file/LocalFile.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/file/LocalFile.as
b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/file/LocalFile.as
new file mode 100644
index 0000000..47b8333
--- /dev/null
+++ b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/file/LocalFile.as
@@ -0,0 +1,84 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.storage.file
+{
+COMPILE::AS3 {
+	import flash.filesystem.File;
+}
+COMPILE::JS {
+}
+
+/**
+ * The File class provides access to a specific file on the device.
+ */
+COMPILE::AS3
+public class LocalFile
+{
+	public static const documentsDirectory:String = "documentsDirectory";
+	public static const dataDirectory:String = "dataDirectory";
+
+	public function LocalFile(handle:Object=null)
+	{
+		_handle = handle as flash.filesystem.File;
+	}
+
+	private var _handle::flash.filesystem.File;
+
+	public function get handle():flash.filesystem.File {
+		return _handle;
+	}
+
+	static public function resolvePath(directory:String, filename:String):LocalFile {
+		var root:File;
+		if (directory == LocalFile.documentsDirectory) {
+			root = File.documentsDirectory;
+		}
+		else if (directory == LocalFile.dataDirectory) {
+			root = File.applicationStorageDirectory;
+		}
+		var result:LocalFile = new LocalFile(root.resolvePath(filename));
+		return result;
+	}
+}
+
+COMPILE::JS
+public class LocalFile
+{
+	public static const documentsDirectory:String = cordova.file.documentsDirectory;
+	public static const dataDirectory:String = cordova.file.dataDirectory;
+
+	private var _handle:cordova.File;
+
+	public function get handle():cordova.File {
+		return _handle;
+	}
+
+	static public function resolvePath(directory:String, filename:String):LocalFile {
+		var pathToFile = directory + filename;
+		var result:File = new File();
+		window.resolveLocalFileSystemURL(pathToFile, function(fileEntry) {
+			fileEntry.file(function (file) {
+				this.result._handle = file;
+			})
+		});
+		return result;
+	}
+}
+
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1bc555d9/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/providers/AirStorageProvider.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/providers/AirStorageProvider.as
b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/providers/AirStorageProvider.as
new file mode 100644
index 0000000..185b6a3
--- /dev/null
+++ b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/providers/AirStorageProvider.as
@@ -0,0 +1,165 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.storage.providers
+{
+	import org.apache.flex.events.EventDispatcher;
+	import org.apache.flex.events.IEventDispatcher;
+	
+	COMPILE::AS3 {
+		import flash.filesystem.File;
+		import flash.filesystem.FileMode;
+		import flash.filesystem.FileStream;
+		import flash.utils.ByteArray;
+		import flash.errors.IOError;
+	}
+
+	import org.apache.flex.storage.events.FileReadEvent;
+	import org.apache.flex.storage.events.FileWriteEvent;
+
+	/**
+	 * The AirStorageProvider class implements the IPermanentStorageProvider
+	 * interface for saving files to a mobile device using the Adobe(tm) AIR platform. 
+	 * 
+	 * @flexjsignorecoercion FileEntry
+	 * @flexjsignorecoercion FileWriter
+	 * @flexjsignorecoercion window
+	 * @flexjsignorecoercion Blob
+	 */
+	public class AirStorageProvider extends EventDispatcher implements IPermanentStorageProvider
+	{
+		/**
+		 * Constructor.
+		 * 
+		 * @param target The target dispatcher for events as files are read and written.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function AirStorageProvider(target:IEventDispatcher=null)
+		{
+			super();
+			_target = target;
+		}
+
+		/**
+		 * The target dispatcher for events as files are read and written.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function get target():IEventDispatcher
+		{
+			return _target;
+		}
+		public function set target(value:IEventDispatcher):void
+		{
+			_target = value;
+		}
+
+		/**
+		 * @private
+		 */
+		private var _target:IEventDispatcher;
+		
+		/**
+		 * A convenience function to read an entire file as a single 
+		 * string of text. The file is storaged in the application's
+		 * data storage directory. Dispatches a FileRead event once
+		 * the data is available.
+		 * 
+		 *  @param fileName The name of the file.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function readTextFromDataFile( fileName:String ) : void
+		{
+			COMPILE::AS3 {
+				var file:File = File.applicationStorageDirectory.resolvePath(fileName);
+				
+				if (!file.exists) {
+					var errEvent:FileReadEvent = new FileReadEvent("ERROR");
+					errEvent.errorMessage = "File does not exist.";
+					_target.dispatchEvent(errEvent);
+					return;
+				}
+				
+				var stream:FileStream = new FileStream();
+				
+				stream.open(file, FileMode.READ);
+				var bytes:ByteArray = new ByteArray();
+				stream.readBytes(bytes);
+				stream.close();
+				
+				var text:String = new String(bytes);
+				
+				var newEvent:FileReadEvent = new FileReadEvent("COMPLETE");
+				newEvent.data = text;
+				_target.dispatchEvent(newEvent);
+			}
+		}
+		
+		/**
+		 * A convenience function write a string into a file that resides in the
+		 * application's data storage directory. If the file already exists it is 
+		 * replaced with the string. Dispatches a FileWrite event once the file
+		 * has been written.
+		 * 
+		 *  @param fileName The name of file.
+		 *  @param text The string to be stored.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function writeTextToDataFile( fileName:String, text:String ) : void
+		{
+			COMPILE::AS3 {
+				var file:File = File.applicationStorageDirectory.resolvePath(fileName);
+				var stream:FileStream = new FileStream();
+				
+				try {
+					stream.open(file, FileMode.WRITE);
+					stream.writeUTFBytes(text);
+					stream.close();
+				} catch(ioerror:IOError) {
+					var ioEvent:FileWriteEvent = new FileWriteEvent("ERROR");
+					ioEvent.errorMessage = "I/O Error";
+					_target.dispatchEvent(ioEvent);
+					return;
+				} catch(secerror:SecurityError) {
+					var secEvent:FileWriteEvent = new FileWriteEvent("ERROR");
+					secEvent.errorMessage = "Security Error";
+					_target.dispatchEvent(secEvent);
+					return;
+				}
+				
+				var newEvent:FileWriteEvent = new FileWriteEvent("COMPLETE");
+				_target.dispatchEvent(newEvent);
+			}
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1bc555d9/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/providers/IPermanentStorageProvider.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/providers/IPermanentStorageProvider.as
b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/providers/IPermanentStorageProvider.as
new file mode 100644
index 0000000..023b1a7
--- /dev/null
+++ b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/providers/IPermanentStorageProvider.as
@@ -0,0 +1,74 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.storage.providers
+{
+	import org.apache.flex.events.IEventDispatcher;
+
+	/**
+	 * This interface provides the template for creating classes the work
+	 * with the permanent storages API of the native system.
+     *
+     *  @langversion 3.0
+     *  @playerversion Flash 10.2
+     *  @playerversion AIR 2.6
+     *  @productversion FlexJS 0.0
+	 */
+	public interface IPermanentStorageProvider
+	{
+		/**
+		 * The target dispatcher for events.
+	     *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		function get target():IEventDispatcher;
+		function set target(value:IEventDispatcher):void;
+
+		/**
+		 * A convenience function to read an entire file as a single 
+		 * string of text. The file is storaged in the application's
+		 * data storage directory.
+		 * 
+		 *  @param fileName The name of the file.
+	     *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		function readTextFromDataFile( fileName:String ) : void;
+		
+		/**
+		 * A convenience function write a string into a file that resides in the
+		 * application's data storage directory. If the file already exists it is 
+		 * replaced with the string.
+		 * 
+		 *  @param fileName The name of file.
+		 *  @param text The string to be stored.
+	     *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		function writeTextToDataFile( fileName:String, text:String ) : void;
+	}
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1bc555d9/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/providers/WebStorageProvider.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/providers/WebStorageProvider.as
b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/providers/WebStorageProvider.as
new file mode 100644
index 0000000..557b591
--- /dev/null
+++ b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/providers/WebStorageProvider.as
@@ -0,0 +1,169 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.flex.storage.providers
+{
+	import org.apache.flex.events.EventDispatcher;
+	import org.apache.flex.events.IEventDispatcher;
+
+	import org.apache.flex.storage.events.FileReadEvent;
+    import org.apache.flex.storage.events.FileWriteEvent;
+
+	/**
+	 * The WebStorageProvider class implements the IPermanentStorageProvider
+	 * interface for saving files to a mobile device. 
+	 * 
+	 * @flexjsignorecoercion FileEntry
+	 * @flexjsignorecoercion FileWriter
+	 * @flexjsignorecoercion window
+     * @flexjsignorecoercion Blob
+	 */
+	public class WebStorageProvider extends EventDispatcher implements IPermanentStorageProvider
+	{
+		/**
+		 * Constructor.
+		 * 
+		 * @param target The target dispatcher for events as files are read and written.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function WebStorageProvider(target:IEventDispatcher=null)
+		{
+			super();
+			_target = target;
+		}
+
+		/**
+		 * @private
+		 */
+		private var _target:IEventDispatcher;
+
+		/**
+		 * The target dispatcher for events as files are read and written.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function get target():IEventDispatcher
+		{
+			return _target;
+		}
+		public function set target(value:IEventDispatcher):void
+		{
+			_target = value;
+		}
+		
+		/**
+		 * A convenience function to read an entire file as a single 
+		 * string of text. The file is storaged in the application's
+		 * data storage directory. Dispatches a FileRead event once
+		 * the data is available.
+		 * 
+		 *  @param fileName The name of the file.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function readTextFromDataFile( fileName:String ) : void
+		{
+			COMPILE::JS {
+				var fullPath:String = String(cordova["file"]["dataDirectory"]) + fileName;
+				
+				window.resolveLocalFileSystemURL(fullPath, function (fileEntry):void {
+					fileEntry.file(function (file):void {
+						var reader:FileReader = new FileReader();
+						reader.onloadend = function (e):void {
+							var newEvent:FileReadEvent = new FileReadEvent("COMPLETE");
+							newEvent.data = this.result;
+							_target.dispatchEvent(newEvent);
+						};
+						reader.readAsText(file);
+					}, function (e):void {
+						var errEvent:FileReadEvent = new FileReadEvent("ERROR");
+						errEvent.errorMessage = "Cannot open file for reading";
+						_target.dispatchEvent(errEvent);
+					});
+				}, function (e):void {
+					var errEvent:FileReadEvent = new FileReadEvent("ERROR");
+					errEvent.errorMessage = "File does not exist";
+					_target.dispatchEvent(errEvent);
+				});
+			}
+		}
+		
+		/**
+		 * A convenience function write a string into a file that resides in the
+		 * application's data storage directory. If the file already exists it is 
+		 * replaced with the string. Dispatches a FileWrite event once the file
+		 * has been written.
+		 * 
+		 *  @param fileName The name of file.
+		 *  @param text The string to be stored.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion FlexJS 0.0
+		 */
+		public function writeTextToDataFile( fileName:String, text:String ) : void
+		{
+			COMPILE::JS {
+				var fullPath:String = String(cordova["file"]["dataDirectory"]) + fileName;
+		
+				window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function (directoryEntry):void
{
+					directoryEntry.getFile(fileName, { 'create': true }, function (fileEntry):void {
+						fileEntry.createWriter(function (fileWriter):void {
+							fileWriter.onwriteend = function (e):void {
+								var newEvent:FileWriteEvent = new FileWriteEvent("COMPLETE");
+								_target.dispatchEvent(newEvent);
+							};
+							
+							fileWriter.onerror = function (e):void {
+								var newEvent:FileWriteEvent = new FileWriteEvent("ERROR");
+								newEvent.errorMessage = "Failed to write the file.";
+								_target.dispatchEvent(newEvent);
+							};
+							
+							var blob:Blob = new Blob([text], { type: 'text/plain' });
+							fileWriter.write(blob);
+						}, function(e):void {
+							var errEvent:FileWriteEvent = new FileWriteEvent("ERROR");
+							errEvent.errorMessage = "Cannot open file for writing.";
+							_target.dispatchEvent(errEvent);
+						});
+					}, function(e):void {
+						var errEvent:FileWriteEvent = new FileWriteEvent("ERROR");
+						errEvent.errorMessage = "Cannot create file.";
+						_target.dispatchEvent(errEvent);
+					});
+				}, function(e):void {
+					var errEvent:FileWriteEvent = new FileWriteEvent("ERROR");
+					errEvent.errorMessage = "Cannot create file.";
+					_target.dispatchEvent(errEvent);
+				});
+			}
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1bc555d9/frameworks/projects/Storage/src/main/resources/basic-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/src/main/resources/basic-manifest.xml b/frameworks/projects/Storage/src/main/resources/basic-manifest.xml
index b502203..b82c859 100644
--- a/frameworks/projects/Storage/src/main/resources/basic-manifest.xml
+++ b/frameworks/projects/Storage/src/main/resources/basic-manifest.xml
@@ -21,4 +21,5 @@
 
 <componentPackage>
 	<component id="LocalStorage" class="org.apache.flex.storage.LocalStorage"/>
+	<component id="PermanentStorage" class="org.apache.flex.storage.PermanentStorage"/>
 </componentPackage>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/1bc555d9/frameworks/projects/Storage/src/main/resources/defaults.css
----------------------------------------------------------------------
diff --git a/frameworks/projects/Storage/src/main/resources/defaults.css b/frameworks/projects/Storage/src/main/resources/defaults.css
index 9d82e6f..dd88207 100644
--- a/frameworks/projects/Storage/src/main/resources/defaults.css
+++ b/frameworks/projects/Storage/src/main/resources/defaults.css
@@ -23,4 +23,20 @@
 LocalStorage
 {
     IStorageProvider: ClassReference("org.apache.flex.storage.providers.LocalStorageProvider");
+}
+
+PermanentStorage
+{
+	IStorageProvider: ClassReference("org.apache.flex.storage.providers.WebStorageProvider");
+}
+
+@media -flex-flash
+{
+/**
+ * StorageProvider for AIR platform
+ */
+PermanentStorage
+{
+	IStorageProvider: ClassReference("org.apache.flex.storage.providers.AirStorageProvider");
+}	
 }
\ No newline at end of file


Mime
View raw message