UNPKG

dl

Version:

DreamLab Libs

66 lines (49 loc) 1.87 kB
//http://ocdn.eu/resources/appmicrosite/microsite.template-engine/resource/2dc7d813f5844ca2b2db2b7b6bfc9a90/1.0/accordion.css" var Class = require('core').Class; var OcdnUrl = require('./OcdnUrl.js').OcdnUrl; var URL_PATTERN = /.*\/\/(.*)\/resources\/([a-zA-Z0-9\.\-\_]*)\/([a-zA-Z0-9\.\-\_]*)\/resource\/([a-zA-Z0-9\.\-\_]*)\/([0-9a-z\.]*)\/([a-zA-Z0-9\.\-\_]*)/; var OcdnResourcesUrl = function () { this.Extends = OcdnUrl; this.initialize = function (key, url) { if (arguments.length == 1) { url = key; key = undefined; } this.appName = null; this.generator = null; this.paramsId = null; this.resourceVersion = null; this.resourceName = null; this.parent(key, url, true); this.init(url); }; this.init = function (url) { if (url) { this.parent(url); this.parse(url); } else { this.setPlugin('resources'); } }; this.parse = function (url) { this.parent(url); var parts = url.match(URL_PATTERN); if (parts.length != 7) { throw OcdnResourcesUrl.Error.INCORRECT_URL; } this.appName = parts[2]; this.generator = parts[3]; this.paramsId = parts[4]; this.resourceVersion = parts[5]; this.resourceName = parts[6]; } this.toString = function () { var paramsId = this.paramsId || OcdnResourcesUrl.NONE; return this.parent() + "/" + this.appName + "/" + this.generator + "/resource/" + paramsId + "/" + this.resourceVersion + "/" + this.resourceName; }; }; OcdnResourcesUrl = new Class(new OcdnResourcesUrl()); OcdnResourcesUrl.NONE = "none"; OcdnResourcesUrl.Error = {}; OcdnResourcesUrl.Error.INCORRECT_URL = "incorrect url"; exports.OcdnResourcesUrl = OcdnResourcesUrl;