Skip to content
Permalink
Browse files
- refactored to use a dynamic class for localization in Installer app;
- refactored to remove as many compiled URLs, names, version numbers etc. as possible, as these are subject to change. The only hard coded constants left are the URL for the Apache Flex project site and the name of the config file (in Constants.as, part of the 'common' library). All other settings are in the config file in the root of the project site;
- removed dependency on 'version.xml' on bigosmall's personal web space, moved the latest version number to the config xml file;
- implemented the custom ILog interface on MirrorURLUtil, to remove it's tight coupling to the localization classes;
- moved both InternetUtil and MirrorURLUtil to 'common' library for shared use by installer and badge;
- the Badge now uses the mirror url cgi to determine the download URL;
- minor adjustments to the Badge UI (strings and position);

git-svn-id: https://svn.apache.org/repos/asf/incubator/flex/utilities/trunk@1376073 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
erikdebruin committed Aug 22, 2012
1 parent d4758d4 commit 0a63644e065bc91bece12cc7acf0775d35d75931
Showing 20 changed files with 2,602 additions and 2,946 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -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.utilities.common
{

public class Constants
{

//--------------------------------------------------------------------------
//
// Class Constants
//
//--------------------------------------------------------------------------

public static const APACHE_FLEX_URL:String = "http://incubator.apache.org/flex/";

public static const APPLICATION_EXTENSION_MAC:String = ".dmg";
public static const APPLICATION_EXTENSION_WIN:String = ".exe";

public static const CONFIG_XML_NAME:String = "sdk-installer-config.xml";

public static const SDK_BINARY_FILE_NAME_PREFIX:String = "apache-flex-sdk-";

public static const URL_PREFIX:String = "http://";

//--------------------------------------------------------------------------
//
// Class properties
//
//--------------------------------------------------------------------------

//----------------------------------
// instance
//----------------------------------

private static var _instance:Constants;

public static function get instance():Constants
{
if (!_instance)
_instance = new Constants(new SE());

return _instance;
}

//--------------------------------------------------------------------------
//
// Constructor
//
//--------------------------------------------------------------------------

public function Constants(se:SE) {}

}
}

class SE {}
@@ -17,7 +17,7 @@
//
////////////////////////////////////////////////////////////////////////////////

package org.apache.flex.packageflexsdk.util
package org.apache.flex.utilities.common
{

import flash.events.Event;
@@ -17,13 +17,15 @@
//
////////////////////////////////////////////////////////////////////////////////

package org.apache.flex.packageflexsdk.util
package org.apache.flex.utilities.common
{

import mx.collections.ArrayCollection;

import org.apache.flex.packageflexsdk.resource.ViewResourceConstants;
import org.apache.flex.utilities.common.vo.LogMessagesVO;
import org.apache.flex.utilities.common.interfaces.ILog;

public class MirrorURLUtil
public class MirrorURLUtil implements ILog
{

//--------------------------------------------------------------------------
@@ -55,8 +57,6 @@ public class MirrorURLUtil
public function MirrorURLUtil(se:SE)
{
_internetUtil = InternetUtil.instance;

_constants = ViewResourceConstants.getInstance();
}

//--------------------------------------------------------------------------
@@ -65,8 +65,9 @@ public class MirrorURLUtil
//
//--------------------------------------------------------------------------

private const FIRST:String = "first";
private const SECOND:String = "second";
private const ACTION:String = "action";
private const ERROR:String = "error";
private const SUCCESS:String = "success";

//--------------------------------------------------------------------------
//
@@ -76,9 +77,7 @@ public class MirrorURLUtil

private var _callback:Function;
private var _internetUtil:InternetUtil;
private var _log:ArrayCollection;
private var _mirrorFetchStep:String;
private var _constants:ViewResourceConstants;
private var _userCountryCode:String;

//--------------------------------------------------------------------------
@@ -88,95 +87,92 @@ public class MirrorURLUtil
//--------------------------------------------------------------------------

//----------------------------------
// url
// errorOccurred
//----------------------------------

private var _url:String;

public function get url():String
private var _errorOccurred:Boolean;
public function get errorOccurred():Boolean
{
return _url;
return _errorOccurred;
}

//--------------------------------------------------------------------------
//
// Methods
//
//--------------------------------------------------------------------------

private function addLogLine(line:String):void
{
_log.addItem(line);
//----------------------------------
// log
//----------------------------------

private var _log:ArrayCollection;

public function get log():ArrayCollection
{
return _log;
}

//----------------------------------
// logMessages
//----------------------------------

private var _logMessages:LogMessagesVO;

public function get logMessages():LogMessagesVO
{
return _logMessages;
}

public function set logMessages(value:LogMessagesVO):void
{
_logMessages = value;
}

//----------------------------------
// fetchGeoIPResult
// mirrorURL
//----------------------------------

private function fetchGeoIPResult():void
private var _mirrorURL:String;

public function get mirrorURL():String
{
if (!_internetUtil.errorOccurred)
{
addLogLine(_constants.FETCH_GEO_IP_DONE);

_userCountryCode = _internetUtil.result.toLowerCase();

addLogLine(_constants.FETCH_MIRROR_LIST);

_internetUtil.fetch(ViewResourceConstants.URL_FETCH_MIRROR_LIST, fetchMirrorListResult);
}
else
{
addLogLine(_constants.FETCH_GEO_IP_ERROR);

addLogLine(_constants.ERROR_MIRROR_FETCH + _internetUtil.errorMessage);

_callback(true, _log);
}
return _mirrorURL;
}

//--------------------------------------------------------------------------
//
// Methods
//
//--------------------------------------------------------------------------

//----------------------------------
// fetchMirrorListResult
// addLogItem
//----------------------------------

private function fetchMirrorListResult():void
private function addLogItem(messageType:String):void
{
var abort:Boolean;

if (!_internetUtil.errorOccurred)
if (_logMessages)
{
addLogLine(_constants.FETCH_MIRROR_LIST_DONE);

var mirrorListArrayFiltered:Array = [];
var mirrorListArrayRaw:Array = _internetUtil.result.split("\n");

var i:int;
var n:int = mirrorListArrayRaw.length;
var mirrorArray:Array;
for (i = n - 1; i > -1; i--)
switch (messageType)
{
mirrorArray = mirrorListArrayRaw[i].split(" ");
if (mirrorArray[0] == "http" && mirrorArray[1] == _userCountryCode)
case ACTION :
{
_log.addItem(_logMessages.action);

break;
}

case ERROR :
{
_log.addItem(_logMessages.error);

break;
}

case SUCCESS :
{
mirrorListArrayFiltered.push(mirrorArray[2]);
_log.addItem(_logMessages.success);

break;
}
}

n = mirrorListArrayFiltered.length;
i = Math.floor(Math.random() * n);

_url = mirrorListArrayFiltered[i];

addLogLine(_constants.FETCH_MIRROR_LIST_PARSED + "'" + _url + "'");
}
else
{
addLogLine(_constants.ERROR_MIRROR_FETCH + _internetUtil.errorMessage);

abort = true;
}

_callback(abort, _log);
}

//----------------------------------
@@ -185,43 +181,39 @@ public class MirrorURLUtil

private function fetchMirrorFromCGIResult():void
{
if (!_internetUtil.errorOccurred)
_errorOccurred = _internetUtil.errorOccurred;

if (!_errorOccurred)
{
addLogLine(_constants.FETCH_MIRROR_CGI_DONE);
addLogItem(SUCCESS);

var result:String = _internetUtil.result;
if(result.search("<p>") != -1)
{
result = result.substring(3,result.length-4);
}

_url = result;

_callback(false, _log);
_mirrorURL = (result.search("<p>") != -1) ?
result.substring(3, result.length - 4) :
result;
}
else
{
addLogLine(_constants.FETCH_MIRROR_CGI_ERROR);

addLogLine(_constants.FETCH_GEO_IP);

_internetUtil.fetch(ViewResourceConstants.URL_FETCH_GEO_IP, fetchGeoIPResult);
addLogItem(ERROR);
}

_callback();
}

//----------------------------------
// getMirrorURL
//----------------------------------

public function getMirrorURL(callback:Function):void
public function getMirrorURL(fetchURL:String, callback:Function):void
{
_callback = callback;

_log = new ArrayCollection();

addLogLine(_constants.FETCH_MIRROR_CGI);
_log.addItem(ACTION);

_internetUtil.fetch(ViewResourceConstants.URL_FETCH_MIRROR_CGI, fetchMirrorFromCGIResult);
_internetUtil.fetch(fetchURL, fetchMirrorFromCGIResult);
}

}

0 comments on commit 0a63644

Please sign in to comment.