package com.zehfernando.data.assets { /** * @author Zeh */ public class AssetType { // Constants public static const CSS:String = "css"; public static const XML:String = "xml"; public static const IMAGE:String = "image"; public static const SWF:String = "swf"; // ================================================================================================================ // STATIC functions ----------------------------------------------------------------------------------------------- public static function getTypes(): Vector. { var types:Vector. = new Vector.(); types.push(AssetType.CSS); types.push(AssetType.IMAGE); types.push(AssetType.XML); return types; } public static function getExtensions(__type:String): Vector. { // TODO: use dictionaries/vectors of info classes/something that makes more sense var vv:Vector. = new Vector.(); switch (__type) { case AssetType.XML: vv.push("xml"); break; case AssetType.CSS: vv.push("css"); break; case AssetType.SWF: vv.push("swf"); case AssetType.IMAGE: vv.push("jpg"); vv.push("jpeg"); vv.push("gif"); vv.push("png"); break; } return vv; } public static function getFromURL(__url:String): String { // Based on the extension of an URL file, return the type // TODO: must test for querystrings! // TODO: must test for other URLs with dots on them! var extSearch:RegExp = /\.([A-Za-z0-9]+)(\?*|)/i; var result:Object = extSearch.exec(__url); //trace ("search [" + __url + "] = " + result + " @ " + (Boolean(result) ? result.index : null)); var extension:String; extension = Boolean(result) ? result[1] : ""; var types:Vector. = getTypes(); var i:int; for (i = 0; i < types.length; i++) { if (getExtensions(types[i]).indexOf(extension) > -1) { return types[i]; } } return ""; } } }