blob: 9a3e8d51feb4dccba19ce11abe55ef2242f7cff7 [file] [log] [blame]
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:components="org.apache.flex.installApacheFlexBadge.components.*"
creationComplete="creationCompleteHandler(event)">
<fx:Style source="/org/apache/flex/installApacheFlexBadge/styles/ApacheFlexBadgeStyle.css" />
<fx:Script><![CDATA[
import mx.controls.Alert;
import mx.core.FlexGlobals;
import mx.events.FlexEvent;
import org.apache.flex.installApacheFlexBadge.resources.EmbeddedMedia;
import org.apache.flex.utilities.common.Constants;
import org.apache.flex.utilities.common.InternetUtil;
import org.apache.flex.utilities.common.MirrorURLUtil;
import org.apache.flex.utilities.common.Tools;
//----------------------------------------------------------------------
//
// Constants
//
//----------------------------------------------------------------------
private const INFO_ERROR_OPERATING_SYSTEM:String = "The Apache Flex SDK Installer application\nis not supported on your operating system.";
private const INFO_ERROR_RETRIEVE_CONFIG:String = "The application was unable to retrieve\nthe configuration file.";
private const LABEL_DOWNLOAD:String = "DOWNLOAD";
private const TITLE_ERROR_INTERNET:String = "Internet Error";
private const TITLE_ERROR_PLATFORM:String = "Platform Error";
//----------------------------------------------------------------------
//
// Variables
//
//----------------------------------------------------------------------
private var _applicationExtension:String;
private var _sdkBinaryFileName:String;
private var _installerDownloadPath:String;
private var _installerFileName:String;
private var _internetUtil:InternetUtil = InternetUtil.instance;
private var _mirrorURLUtil:MirrorURLUtil = MirrorURLUtil.instance;
private var _serviceURL:String;
[Bindable]
private var _sdkVersionString:String = "";
//----------------------------------------------------------------------
//
// Methods
//
//----------------------------------------------------------------------
//----------------------------------
// btnDownload_clickHandler
//----------------------------------
private function btnDownload_clickHandler(event:MouseEvent):void
{
try
{
_applicationExtension = Tools.getApplicationExtension();
var request:URLRequest = new URLRequest(
_installerDownloadPath + _installerFileName + _applicationExtension);
navigateToURL(request, "_blank");
}
catch (error:Error)
{
Alert.show(INFO_ERROR_OPERATING_SYSTEM, TITLE_ERROR_PLATFORM);
}
}
//----------------------------------
// creationCompleteHandler
//----------------------------------
private function creationCompleteHandler(event:FlexEvent):void
{
_serviceURL = FlexGlobals.topLevelApplication.parameters.serviceURL;
var displayType:String = ExternalInterface.call("displayType");
var newStateName:String;
switch (displayType)
{
case "afSDKInstallBadgeSmall" :
{
newStateName = "small";
break;
}
case "afSDKInstallBadgeRegular" :
default :
{
newStateName = "regular";
break;
}
}
currentState = newStateName;
var url:String = _serviceURL + Constants.CONFIG_XML_NAME;
if (useCURL())
_internetUtil.fetch("badgeConfigService.php", internetFetchResultHandler, "url=" + escape(url));
else
_internetUtil.fetch(url, internetFetchResultHandler);
}
//----------------------------------
// getMirrorURLResultHandler
//----------------------------------
private function getMirrorURLResultHandler():void
{
_installerDownloadPath = _mirrorURLUtil.mirrorURL + _installerDownloadPath;
parseSDKVersionNumber();
}
//----------------------------------
// internetFetchResultHandler
//----------------------------------
private function internetFetchResultHandler():void
{
if (!_internetUtil.errorOccurred)
{
var configXML:XML = XML(_internetUtil.result);
var flexSDKNode:XMLList = configXML.products.ApacheFlexSDK;
var defaultFlexVersion:String = configXML.products.ApacheFlexSDK.@latestVersion.toString();
_sdkBinaryFileName = flexSDKNode.versions.children().(@id == defaultFlexVersion).@file.toString();
_installerFileName = configXML.installer.(@name == 'SDKInstallerApp').@file.toString();
_installerDownloadPath = configXML.installer.(@name == 'SDKInstallerApp').@path.toString();
if (_installerDownloadPath.substr(0, Constants.URL_PREFIX.length) != Constants.URL_PREFIX)
{
var mirrorURLCGI:String = configXML.mirror.(@name == 'MirrorURLCGI').@file.toString();
_mirrorURLUtil.getMirrorURL(_serviceURL + mirrorURLCGI, getMirrorURLResultHandler);
}
else
{
parseSDKVersionNumber();
}
}
else
{
Alert.show(INFO_ERROR_RETRIEVE_CONFIG, TITLE_ERROR_INTERNET);
}
}
//----------------------------------
// parseSDKVersionNumber
//----------------------------------
private function parseSDKVersionNumber():void
{
_sdkVersionString = _sdkBinaryFileName.substr(Constants.SDK_BINARY_FILE_NAME_PREFIX.length).split("-")[0];
btnDownload.enabled = true;
}
//----------------------------------
// showDislaimer
//----------------------------------
private function showDisclaimer():void
{
var request:URLRequest = new URLRequest(
"disclaimer.html");
navigateToURL(request, "_blank");
}
//----------------------------------
// useCURL
//----------------------------------
private function useCURL():Boolean
{
/*
Using a simple webservice (PHP + cUrl) to bypass cross domain
and security sandbox restrictions while developing.
*/
var localDomain:String = InternetUtil.getTLDFromURL(
ExternalInterface.call("function () { return window.location.hostname; }"));
var remoteDomain:String = InternetUtil.getTLDFromURL(_serviceURL);
return (localDomain) && (localDomain != remoteDomain);
}
]]></fx:Script>
<fx:Declarations />
<s:states>
<s:State name="regular" />
<s:State name="small" />
</s:states>
<s:Image id="imgBackgroundRegular" source="{EmbeddedMedia.backgroundRegular}" includeIn="regular"/>
<s:Group height="15" width="60"
left="188" top="230"
buttonMode="true"
click="showDisclaimer()"
includeIn="regular" />
<s:Image id="imgBackgroundSmall" source="{EmbeddedMedia.backgroundSmall}" includeIn="small"/>
<s:Group height="15" width="60"
left="146" top="57"
buttonMode="true"
click="showDisclaimer()"
includeIn="small" />
<s:Group height="15" width="60"
left="188" top="230"
buttonMode="true"
click="showDisclaimer()"
includeIn="small" />
<s:Group height="37" width="250"
left="75" left.small="95"
top.regular="185" top.small="15">
<s:Label text="{_sdkVersionString}"
fontFamily="openSansBold"
color="0x162545" fontSize="32"
trackingLeft="-1" trackingRight="-1"
left="87" top="9" />
</s:Group>
<s:Button id="btnDownload" label="{LABEL_DOWNLOAD}"
height="30"
bottom="10" bottom.small="12"
right.small="27"
horizontalCenter.regular="0"
enabled="false"
buttonMode="true"
useHandCursor="true"
click="btnDownload_clickHandler(event)"
styleName="mainBtnStyle"/>
</s:Application>