UNPKG

flysh

Version:

DOM Document Object Artifact Collector

331 lines 11.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InputMessage = void 0; const FlyshException_1 = require("../exception/FlyshException"); const NavPane_1 = require("../model/NavPane"); const SPC_1 = require("../model/SPC"); /** * 'InputMessage' I/O Class Definition */ class InputMessage { /** * Public class constants */ static EXCEPTION_ID_6500001100_MESSAGE_VALUE = "Another filter selector object has the same signature"; static EXCEPTION_ID_6500001200_MESSAGE_VALUE = "A 'Paginator' has already been set"; static EXCEPTION_ID_6500005100_MESSAGE_VALUE = "Invalid domain value"; /** * Private class constants */ DEFAULT_INSTANCE_TIMEOUT_VALUE = 1500; DOM_VALIDATION_NAVPANE_MIN_OCCURS_VALUE = 0; ID_GENERATED_FLOOR_FUNC_COMPLEXITY_VALUE = 100000000000; REGEX_FS_URI_VALIDATION_VALUE = /^(www|http:|https:)+[^\s]+[\w]$/; /** * Class properties */ _domain; _doms = new Array(); _fs = true; _id; _navpane = false; _pagepath; _timeout; /** * Constructor * * @param domain Defines the 'URI' domain * @param pagepath Contains the 'URI' path * @param timeout Optional parameter that defines the timeout value * */ constructor(domain, pagepath, timeout) { this._domain = this.domainValidator(domain); this._id = Math.floor(Math.random() * Math.floor(this.ID_GENERATED_FLOOR_FUNC_COMPLEXITY_VALUE)); this._pagepath = pagepath; this._timeout = timeout || this.DEFAULT_INSTANCE_TIMEOUT_VALUE; } /** * `domainValidator()` Method Validation * * Domain Validator Method Definition * * Validates if the domain is only locally based (filesytem) or from the network. If the domain is under an URL format * then the private filesystem property is set to 'false' * * @param domain Input 'string' parameter that contains the domain value * @returns A 'string' formatted value that contains the passed parameter */ domainValidator(domain) { let _retVal = domain; // Check if the domain/path is empty if ((domain.length === 0)) throw new FlyshException_1.FlyshException(6500005100, new TypeError(), InputMessage.EXCEPTION_ID_6500005100_MESSAGE_VALUE); // Check if the domain is a well formatted URL let regEx = new RegExp(this.REGEX_FS_URI_VALIDATION_VALUE); if (domain.match(regEx) !== null) this._fs = false; return _retVal; } /** * `domsValidate()` Method Definition * * Validates the content of the '_doms' class property * * - 'SPC' class instance, verifies that is no other instance(s) having the same 'filter selector' * - 'NavPane' ('Paginator') class instance, verifies that there is not more than one instance within the stack * * @param Class Parameter that contains the class name to validate */ domsValidate(Class) { switch (true) { case Class instanceof NavPane_1.NavPane: { if (this.findDOMElement(NavPane_1.NavPane).length > this.DOM_VALIDATION_NAVPANE_MIN_OCCURS_VALUE) throw new FlyshException_1.FlyshException(6500001200, new Error, InputMessage.EXCEPTION_ID_6500001200_MESSAGE_VALUE); break; } case Class instanceof SPC_1.SPC: { for (let elem of this.findDOMElement(SPC_1.SPC)) if (elem.getFilterSelector == Class.getFilterSelector) throw new FlyshException_1.FlyshException(6500001100, new Error, InputMessage.EXCEPTION_ID_6500001100_MESSAGE_VALUE); break; } } } /** * Getter 'ID' number property * * @return Returns the '_id' class property */ get ID() { return this._id; } /** * Getter 'doms' array property * * @return Returns the '_doms' class property */ get doms() { return this._doms; } /** * Getter 'hasNavpane' ('Paginator') boolean property * * @return Returns the '_navpane' class property */ get hasNavpane() { return this._navpane; } /** * Getter 'domain' string property * * @return Returns the '_domain' class property */ get domain() { return this._domain; } /** * Getter 'pagePath' string property * * @return Returns the '_pagepath' class property */ get pagepath() { return this._pagepath; } /** * Getter 'filesystem' boolean property * * @return Returns the '_filesystem' class property */ get filesystem() { return this._fs; } /** * Getter 'timeout' number property * * @return Returns the current class timeout value */ get timeout() { return this._timeout; } /** * Returns 'URI/URL' string properties ('_domain' + '_pagePath') * * @return Returns the complete 'URI' ('_domain' + '_pagePath') */ get URI() { return this._domain + this._pagepath; } /** * 'getDomsEntries()' Method Definition * * Returns the 'DOM' element(s) list under JSON format * * @return Returns all the 'DOM' element(s) contained within the '_dom' class property */ getDomsEntries() { let retVal = ""; this._doms.forEach((e) => { if ((e instanceof NavPane_1.NavPane)) retVal += ((e).getEntry + '\n'); if ((e instanceof SPC_1.SPC)) retVal += ((e).getEntry + '\n'); }); return retVal; } /** * `getDomsEntriesToJSON()` Method Definition * * Returns the 'DOM' element(s) list under JSON format * * @return Returns all the 'DOM' element(s) contained within the '_dom' class property */ getDomsEntriesToJSON() { let retVal; retVal = new Array(); this._doms.forEach((e) => { //if ((e instanceof NavPane)) retVal += ((<NavPane>(e)).getEntry + '\n'); //if ((e instanceof SPC)) retVal.push(JSON.stringify((<SPC>(e)).toJSON)); if ((e instanceof SPC_1.SPC)) retVal.push(JSON.stringify((e))); }); return retVal; } /** * `toString()` Method Definition * * 'Stringify' the object properties * * @return Returns a string that shows up all all the class properties */ get toString() { return 'ID : ' + this._id + '\n' + 'URI : ' + this.URI + '\n' + 'FS : ' + this._fs + '\n' + 'NavPane : ' + this._navpane + '\n' + 'TimeOut : ' + this._timeout + '\n' + 'Doms : ' + '\n' + this.getDomsEntries(); } /** * `toJSON()` Method Definition * * 'Stringify' the `InputMessage` class instance * * TODO : invoke the inner mapper */ static toJSON(instance) { return JSON.stringify(instance); } /** * `fromJSON()` Method Definition * * Converts a JavaScript Object Notation (JSON) string into an object * * TODO : invoke the inner mapper in order to send back a plain 'InputMessage' class instance * * @param inJson * @returns */ static fromJSON(inJson) { return JSON.parse(inJson); } /** * `fromJSON()` Method Definition * * Converts a JavaScript Object Notation (JSON) string into an object * * Set the '_navpane' property value * * @param flag Contains the boolean value that sets the '_navpane' class property */ set navPane(flag) { this._navpane = flag; } /** * `addNavPane()` Method Definition * * Returns the newly added 'NavPane' element [deprecated] * * @deprecated this method is now deprecated, please use 'addPaginator()' method instead * * @param filterSelector Defines the 'NavPane' filter selector * @param attrib Contains the attrib(ute) of the element/tag (i.e : 'href') * @returns Returns the 'NavPane' class instance itself */ addNavPane(filterSelector, attrib) { let newNavPane = new NavPane_1.NavPane(filterSelector, attrib); newNavPane.validate(); this.domsValidate(newNavPane); this.navPane = true; return this._doms.push(new NavPane_1.NavPane(filterSelector, attrib)); } /** * `addPaginator()` Method Definition * * Adds a Paginator and returns the newly added 'NavPane' element * * Note : For the sake of good reading and interpretation, this function has been publicly renamed ('addNavPane()') * * @param filterSelector Defines the 'Paginator' filter selector * @param attrib Contains the attrib(ute) of the element/tag (i.e : 'href') * @returns Returns the 'Paginator' ('NavPane') class instance itself */ addPaginator(filterSelector, attrib) { let newPaginator = new NavPane_1.NavPane(filterSelector, attrib); newPaginator.validate(); this.domsValidate(newPaginator); this.navPane = true; return this._doms.push(new NavPane_1.NavPane(filterSelector, attrib)); } /** * `addSPC()` Method Definition * * Returns the newly added 'SPC' type element [deprecated] * * TODO : (new SPC(filterSelector, new Array<Sibling>())).validate() : returns SPC (this) * * @deprecated this method is now deprecated, please use 'addFilterSelector()' method instead * * @param filterselector Contains the current class filter selector * @returns Returns the 'SPC' class instance itself */ addSPC(filterSelector) { let newSPC = new SPC_1.SPC(filterSelector, new Array()); newSPC.validate(); this.domsValidate(newSPC); return this._doms[this._doms.push(newSPC) - 1]; } /** * `addFilterSelector()` Method Definition * * Returns the newly added Filter Selector ('SPC' type element) * * Note : For the sake of good reading and interpretation, this function has been publicly renamed ('addSPC()') * * TODO : Implement validate() as (new SPC(filterSelector, new Array<Sibling>())).validate() : returns SPC (this) * * @param filterselector Contains the current class filter selector * @returns Returns the 'Filter Selector' ('SPC') class instance itself */ addFilterSelector(filterSelector) { let newFilterSelector = new SPC_1.SPC(filterSelector, new Array()); newFilterSelector.validate(); this.domsValidate(newFilterSelector); return this._doms[this._doms.push(newFilterSelector) - 1]; } /** * `findDOMElement()` Method Definition * * Returns all the inherited 'DOMElement' instance(s) from the '_doms' stack property that match the 'Class' parameter * * NOTE : The returned value in case of 'navpane'/'paginator' should always be 1 element * * @param Class Contains the class name to retrieve * @return Returns an array of 'DomElement' that contains the found occurrence(s) */ findDOMElement(Class) { return this._doms.filter(e => e instanceof Class); } } exports.InputMessage = InputMessage; //# sourceMappingURL=InputMessage.js.map