///////////////////////////////////////////////////////////////////////////////// // Copyright © 2008 W. Kowarschick // // Permission is granted to copy, distribute and/or modify this document // under the terms of the WK License, Version 1.0 (WKL 1.0) or any later version // published by Wolfgang Kowarschick. ///////////////////////////////////////////////////////////////////////////////// package model { import flash.events.EventDispatcher; [Bindable] public class ModelURL extends EventDispatcher { ///////////////////////////////////////////////////////////////////////////// // Private Members ///////////////////////////////////////////////////////////////////////////// private var v_url: String; private var v_domain: String; private var v_protocol: String; private var v_port: uint = 80; private var v_path: String; private var v_file: String; private var v_type: String; private function m_update_url(p_domain: String): void { v_url = v_protocol + "://" + v_domain + ":" + v_port + v_path; } ///////////////////////////////////////////////////////////////////////////// // (Public) Attributes ///////////////////////////////////////////////////////////////////////////// public function set url(p_url: String): void { // trace("========> " + p_url); var l_url: String = p_url; var l_domain: String = v_domain; if (l_url.substr(0,9) == "external:") { this.external = true; l_url = l_url.substr(9); } else if (l_url.substr(0,9) == "internal:") { this.external = false; l_url = l_url.substr(9); } else this.external = false; ; var l_parts: Array = l_url.split("/"); var l_domain_parts: Array; if (String(l_parts[0]).substr(-1) == ":") { v_protocol = l_parts[0].substr(0, l_url.indexOf(":")); if (!v_protocol.match("[hH][tT][tT][pP][sS]?")) this.external = true; l_domain_parts = String(l_parts[2]).split(":"); if (l_domain_parts == null) { l_domain = l_parts[2]; v_port = 80; } else { l_domain = l_domain_parts[0]; if (l_domain_parts.length > 1) v_port = int(l_domain_parts[1]); else v_port = (v_protocol == "http") ? 80 : 443; }; v_path = l_url.substr(l_url.indexOf("/", l_url.indexOf(":")+3)); } else if (l_url.substr(0,1)=="/") v_path = l_url; // Absolute path else v_path += l_url; // Relative path var l_index_of_extension: int = v_path.indexOf(".", v_path.lastIndexOf("/")); if (l_index_of_extension == -1) { if (v_path.substr(-1) != "/") v_path += "/"; v_file = ""; v_type = "html"; } else { var l_file: Array = v_path.substr(v_path.lastIndexOf("/")+1).split("."); v_file = l_file[0]; v_type = l_file[1]; v_path = v_path.substr(0, v_path.lastIndexOf("/")+1); if (v_path == null) v_path = "/"; }; m_update_url(l_domain); if (v_file != "") { v_url += v_file + "." + v_type; this.external = true; }; this.domain = l_domain; // enforce event dispatching // trace(">>>>>>>>> " + this.url); // trace("external: " + this.external); // trace("protocol: " + v_protocol); // trace("domain: " + this.domain); // trace("port: " + v_port); // trace("path: " + v_path); // trace("file: " + v_file); // trace("type: " + v_type); } public function get url(): String { return v_url; } public function get domain(): String { return v_domain; } public function set domain(p_domain: String): void { v_domain = p_domain; m_update_url(v_domain); } public var external: Boolean; ///////////////////////////////////////////////////////////////////////////// // End of Class ///////////////////////////////////////////////////////////////////////////// } }