Repository: flex-asjs Updated Branches: refs/heads/develop d5ee78af8 -> 547945001
Added LocalStorage class via new 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/54794500 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/54794500 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/54794500 Branch: refs/heads/develop Commit: 54794500106b4023156cdfda39a363f947d26ad5 Parents: d5ee78a Author: Peter Ent <[email protected]> Authored: Mon Feb 22 14:34:28 2016 -0500 Committer: Peter Ent <[email protected]> Committed: Mon Feb 22 14:34:28 2016 -0500 ---------------------------------------------------------------------- frameworks/build.xml | 6 + frameworks/projects/Storage/build.xml | 172 ++++++++++++++++ .../Storage/src/main/flex/StorageClasses.as | 34 ++++ .../org/apache/flex/storage/LocalStorage.as | 197 +++++++++++++++++++ .../src/main/resources/basic-manifest.xml | 24 +++ .../src/main/resources/compile-asjs-config.xml | 78 ++++++++ .../src/main/resources/compile-config.xml | 77 ++++++++ 7 files changed, 588 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54794500/frameworks/build.xml ---------------------------------------------------------------------- diff --git a/frameworks/build.xml b/frameworks/build.xml index eebb204..8ba8f75 100644 --- a/frameworks/build.xml +++ b/frameworks/build.xml @@ -93,6 +93,7 @@ <antcall target="Mobile"/> <antcall target="Network"/> <antcall target="Reflection"/> + <antcall target="Storage"/> </target> <target name="fonts"> @@ -136,6 +137,7 @@ <ant dir="${basedir}/projects/Mobile" target="clean"/> <ant dir="${basedir}/projects/Network" target="clean"/> <ant dir="${basedir}/projects/Reflection" target="clean"/> + <ant dir="${basedir}/projects/Storage" target="clean"/> <ant dir="${basedir}/fontsrc" target="clean"/> <!-- delete the FlashBuilder executable directories --> @@ -224,6 +226,10 @@ <ant dir="${basedir}/projects/Reflection"/> </target> + <target name="Storage" description="Clean build of Storage.swc"> + <ant dir="${basedir}/projects/Storage"/> + </target> + <target name="flex-config" depends="playerglobal-setswfversion" description="Copy the flex config template to flex-config.xml and inject version numbers"> <copy file="${basedir}/flex-config-template.xml" tofile="${basedir}/flex-config.xml" overwrite="true"> <filterset> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54794500/frameworks/projects/Storage/build.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Storage/build.xml b/frameworks/projects/Storage/build.xml new file mode 100644 index 0000000..0d5fd9a --- /dev/null +++ b/frameworks/projects/Storage/build.xml @@ -0,0 +1,172 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> + + +<project name="Storage" default="main" basedir="."> + <property name="FLEXJS_HOME" location="../../.."/> + + <property file="${FLEXJS_HOME}/env.properties"/> + <property environment="env"/> + <property file="${FLEXJS_HOME}/build.properties"/> + <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> + <property name="FALCON_HOME" value="${env.FALCON_HOME}"/> + <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="target.name" value="Storage-${release.version}.swc" /> + <property name="target.name.no.version" value="Storage.swc" /> + + <target name="main" depends="clean,compile-asjs,compile-extern-swc,copy-js,compile,test" description="Full build of Storage.swc"> + </target> + + <target name="test" unless="is.jenkins"> + <!-- no tests yet + <ant dir="as/tests"/> + --> + </target> + + <target name="test-js" unless="is.jenkins"> + <!-- no tests yet + <ant dir="js/tests" /> + --> + </target> + + <target name="clean"> + <delete failonerror="false"> + <fileset dir="${FLEXJS_HOME}/frameworks/libs"> + <include name="${target.name.no.version}"/> + </fileset> + </delete> + <delete failonerror="false"> + <fileset dir="${basedir}/target"> + <include name="**/**"/> + </fileset> + </delete> + </target> + + <path id="lib.path"> + <fileset dir="${FALCON_HOME}/lib" includes="falcon-flexTasks.jar"/> + </path> + + <target name="compile" description="Compiles .as files into .swc"> + <echo message="Compiling target/${target.name}"/> + <echo message="FLEX_HOME: ${FLEX_HOME}"/> + <echo message="FALCON_HOME: ${FALCON_HOME}"/> + <!-- make JS output folder now so include-file doesn't error --> + <mkdir dir="${basedir}/target/generated-sources/flexjs"/> + + <!-- Load the <compc> task. We can't do this at the <project> level --> + <!-- because targets that run before flexTasks.jar gets built would fail. --> + <taskdef resource="flexTasks.tasks" classpathref="lib.path"/> + <!-- + Link in the classes (and their dependencies) for the MXML tags + listed in this project's manifest.xml. + Also link the additional classes (and their dependencies) + listed in StorageClasses.as, + because these aren't referenced by the manifest classes. + Keep the standard metadata when compiling. + Include the appropriate CSS files and assets in the SWC. + Don't include any resources in the SWC. + Write a bundle list of referenced resource bundles + into the file bundles.properties in this directory. + --> + <compc fork="true" + output="${basedir}/target/${target.name}"> + <jvmarg line="${compc.jvm.args}"/> + <load-config filename="${basedir}/src/main/resources/compile-config.xml" /> + <arg value="+playerglobal.version=${playerglobal.version}" /> + <arg value="+env.AIR_HOME=${env.AIR_HOME}" /> + <arg value="-define=COMPILE::AS3,true" /> + <arg value="-define=COMPILE::JS,false" /> + </compc> + <copy file="${basedir}/target/${target.name}" tofile="${FLEXJS_HOME}/frameworks/libs/${target.name.no.version}" /> + </target> + + <target name="compile-asjs"> + <echo message="Cross-compiling ${target.name}"/> + <echo message="FALCONJX_HOME: ${FALCONJX_HOME}"/> + <java jar="${FALCONJX_HOME}/lib/compc.jar" fork="true" > + <jvmarg value="-Xmx384m" /> + <jvmarg value="-Dsun.io.useCanonCaches=false" /> + <jvmarg value="-Dflexcompiler=${FALCONJX_HOME}/../compiler" /> + <jvmarg value="-Dflexlib=${FLEXJS_HOME}/frameworks" /> + <arg value="+flexlib=${FLEX_HOME}/frameworks" /> + <arg value="-js-output-type=FLEXJS" /> + <arg value="-keep-asdoc" /><!-- allows compiler to see @flexjsignorecoercion annotations --> + <arg value="-output=${basedir}/target/generated-sources/flexjs" /> + <arg value="-load-config=${basedir}/src/main/resources/compile-asjs-config.xml" /> + <arg value="+playerglobal.version=${playerglobal.version}" /> + <arg value="+env.PLAYERGLOBAL_HOME=${env.PLAYERGLOBAL_HOME}" /> + <arg value="+env.AIR_HOME=${env.AIR_HOME}" /> + <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="-define=COMPILE::AS3,false" /> + <arg value="-define=COMPILE::JS,true" /> + </java> + </target> + + <target name="compile-extern-swc" description="Compiles .as files into .swc used for cross-compiling other projects"> + <echo message="Compiling target/externs/${target.name}"/> + <echo message="FLEX_HOME: ${FLEX_HOME}"/> + <echo message="FALCON_HOME: ${FALCON_HOME}"/> + <!-- make JS output folder now so include-file doesn't error --> + <mkdir dir="${FLEXJS_HOME}/frameworks/externs"/> + <mkdir dir="${basedir}/target/externs"/> + + <!-- Load the <compc> task. We can't do this at the <project> level --> + <!-- because targets that run before flexTasks.jar gets built would fail. --> + <taskdef resource="flexTasks.tasks" classpathref="lib.path"/> + <!-- + Link in the classes (and their dependencies) for the MXML tags + listed in this project's manifest.xml. + Also link the additional classes (and their dependencies) + listed in CoreClasses.as, + because these aren't referenced by the manifest classes. + Keep the standard metadata when compiling. + Include the appropriate CSS files and assets in the SWC. + Don't include any resources in the SWC. + Write a bundle list of referenced resource bundles + into the file bundles.properties in this directory. + --> + <compc fork="true" + output="${basedir}/target/externs/${target.name}"> + <jvmarg line="${compc.jvm.args}"/> + <load-config filename="src/main/resources/compile-asjs-config.xml" /> + <arg value="+playerglobal.version=${playerglobal.version}" /> + <arg value="+env.AIR_HOME=${env.AIR_HOME}" /> + <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="-define=COMPILE::AS3,false" /> + <arg value="-define=COMPILE::JS,true" /> + </compc> + <copy file="${basedir}/target/externs/${target.name}" tofile="${FLEXJS_HOME}/frameworks/externs/${target.name.no.version}" /> + </target> + + <target name="copy-js"> + <copy todir="${FLEXJS_HOME}/frameworks/js/FlexJS/libs"> + <fileset dir="${basedir}/target/generated-sources/flexjs"> + <include name="**/**"/> + </fileset> + </copy> + </target> + +</project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54794500/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 new file mode 100644 index 0000000..1f6b80a --- /dev/null +++ b/frameworks/projects/Storage/src/main/flex/StorageClasses.as @@ -0,0 +1,34 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ + +/** + * @private + * This class is used to link additional classes into rpc.swc + * beyond those that are found by dependency analysis starting + * from the classes specified in manifest.xml. + */ +internal class StorageClasses +{ + import org.apache.flex.storage.LocalStorage; LocalStorage; +} + +} + http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54794500/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/LocalStorage.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/LocalStorage.as b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/LocalStorage.as new file mode 100644 index 0000000..a3a2b87 --- /dev/null +++ b/frameworks/projects/Storage/src/main/flex/org/apache/flex/storage/LocalStorage.as @@ -0,0 +1,197 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// 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 +{ +COMPILE::AS3 { + import flash.net.SharedObject; +} + +/** + * The LocalStorage class allows apps to store small amounts of data + * locally, in the browser's permitted storage area. This data will persist + * between browser invocations. The data is stored in key=value pairs. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignoreimport window + */ +public class LocalStorage +{ + + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignoreimport window + */ + public function LocalStorage() + { + COMPILE::AS3 { + try { + sharedObject = SharedObject.getLocal("flexjs","/",false); + } catch(e) { + sharedObject = null; + } + } + } + + COMPILE::AS3 + private var sharedObject:SharedObject; + + /** + * Returns true if the platform provides local storage. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignoreimport window + */ + public function storageAvailable():Boolean + { + var result:Boolean = false; + + COMPILE::AS3 { + result = (sharedObject != null); + } + + COMPILE::JS { + try { + result = 'localStorage' in window && window['localStorage'] !== null; + } catch(e) { + result = false; + } + } + + return result; + } + + /** + * Stores a value with a key. The value may be converted to a String, depending + * on the platform. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignoreimport window + */ + public function setValue(key:String, value:Object) : Boolean + { + if (!storageAvailable()) return false; + + COMPILE::AS3 { + sharedObject.data[key] = value; + sharedObject.flush(); + } + + COMPILE::JS { + window.localStorage[key] = value; + } + + return true; + } + + /** + * Returns the value associated with the key, or undefined if there is + * no value stored. Note that a String version of the value may have been + * stored, depending on the platform. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignoreimport window + */ + public function getValue(key:String) : Object + { + if (!storageAvailable()) return null; + + var result:Object = null; + + COMPILE::AS3 { + result = sharedObject.data[key]; + } + + COMPILE::JS { + result = window.localStorage[key]; + } + + return result; + } + + /** + * Removed the value and, possibly, the key from local storage. On some + * platforms, retriving the value after removing it will be an error, on + * others it may return undefined or null. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignoreimport window + */ + public function removeValue(key:String) : Boolean + { + if (!storageAvailable()) return null; + + COMPILE::AS3 { + delete sharedObject.data[key]; + sharedObject.flush(); + } + + COMPILE::JS { + window.localStorage[key] = null; + } + + return true; + } + + /** + * Returns true if there is a value stored for the key. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignoreimport window + */ + public function hasValue(key:String) : Boolean + { + if (!storageAvailable()) return false; + + var result:Boolean = false; + + COMPILE::AS3 { + result = sharedObject.data.hasOwnProperty(key); + } + + COMPILE::JS { + result = (window.localStorage[key] !== null); + } + + return result; + } +} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54794500/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 new file mode 100644 index 0000000..cd0f5b4 --- /dev/null +++ b/frameworks/projects/Storage/src/main/resources/basic-manifest.xml @@ -0,0 +1,24 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> + + +<componentPackage> + +</componentPackage> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54794500/frameworks/projects/Storage/src/main/resources/compile-asjs-config.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Storage/src/main/resources/compile-asjs-config.xml b/frameworks/projects/Storage/src/main/resources/compile-asjs-config.xml new file mode 100644 index 0000000..0d410aa --- /dev/null +++ b/frameworks/projects/Storage/src/main/resources/compile-asjs-config.xml @@ -0,0 +1,78 @@ +<!-- + + 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. + +--> +<flex-config> + + <compiler> + <accessible>false</accessible> + + <external-library-path> + </external-library-path> + + <mxml> + <children-as-data>true</children-as-data> + </mxml> + <binding-value-change-event>org.apache.flex.events.ValueChangeEvent</binding-value-change-event> + <binding-value-change-event-kind>org.apache.flex.events.ValueChangeEvent</binding-value-change-event-kind> + <binding-value-change-event-type>valueChange</binding-value-change-event-type> + + <keep-as3-metadata> + <name>Bindable</name> + <name>Managed</name> + <name>ChangeEvent</name> + <name>NonCommittingChangeEvent</name> + <name>Transient</name> + </keep-as3-metadata> + + <locale/> + + <library-path> + </library-path> + + <namespaces> + <namespace> + <uri>library://ns.apache.org/flexjs/basic</uri> + <manifest>basic-manifest.xml</manifest> + </namespace> + </namespaces> + + <source-path> + <path-element>../flex</path-element> + </source-path> + + <warn-no-constructor>false</warn-no-constructor> + </compiler> + + <include-file> + </include-file> + + <include-sources> + </include-sources> + + <include-classes> + <class>StorageClasses</class> + </include-classes> + + <include-namespaces> + <uri>library://ns.apache.org/flexjs/basic</uri> + </include-namespaces> + + <target-player>${playerglobal.version}</target-player> + + +</flex-config> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54794500/frameworks/projects/Storage/src/main/resources/compile-config.xml ---------------------------------------------------------------------- diff --git a/frameworks/projects/Storage/src/main/resources/compile-config.xml b/frameworks/projects/Storage/src/main/resources/compile-config.xml new file mode 100644 index 0000000..bdd4048 --- /dev/null +++ b/frameworks/projects/Storage/src/main/resources/compile-config.xml @@ -0,0 +1,77 @@ +<!-- + + 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. + +--> +<flex-config> + + <compiler> + <accessible>false</accessible> + + <external-library-path> + <path-element>${env.AIR_HOME}/frameworks/libs/air/airglobal.swc</path-element> + </external-library-path> + + <mxml> + <children-as-data>true</children-as-data> + </mxml> + <binding-value-change-event>org.apache.flex.events.ValueChangeEvent</binding-value-change-event> + <binding-value-change-event-kind>org.apache.flex.events.ValueChangeEvent</binding-value-change-event-kind> + <binding-value-change-event-type>valueChange</binding-value-change-event-type> + + <keep-as3-metadata> + <name>Bindable</name> + <name>Managed</name> + <name>ChangeEvent</name> + <name>NonCommittingChangeEvent</name> + <name>Transient</name> + </keep-as3-metadata> + + <locale/> + + <library-path/> + + <namespaces> + <namespace> + <uri>library://ns.apache.org/flexjs/basic</uri> + <manifest>basic-manifest.xml</manifest> + </namespace> + </namespaces> + + <source-path> + <path-element>../flex</path-element> + </source-path> + + <warn-no-constructor>false</warn-no-constructor> + </compiler> + + <include-file> + <name>js/out/*</name> + <path>../../../target/generated-sources/flexjs/*</path> + </include-file> + + <include-classes> + <class>StorageClasses</class> + </include-classes> + + <include-namespaces> + <uri>library://ns.apache.org/flexjs/basic</uri> + </include-namespaces> + + <target-player>${playerglobal.version}</target-player> + + +</flex-config>
