module mod_vtm_helfer { /** * @author kcf */ function einrueckung(tiefe : int, zeichen : string = "\t") : string { return ((tiefe === 0) ? "" : (zeichen + einrueckung(tiefe-1))); } /** * @author kcf */ export interface schnittstelle_xmlknoten { /** * @author kcf */ darstellen(tiefe ?: int) : string; } /** * @author kcf */ export class klasse_xmlknoten_text implements schnittstelle_xmlknoten { /** * @author kcf */ private inhalt : string; /** * @author kcf */ public constructor(inhalt : string) { this.inhalt = inhalt; } /** * @author kcf * @implementation */ public darstellen(tiefe : int = 0) : string { return this.inhalt; } } /** * @author kcf */ export class klasse_xmlknoten_normal implements schnittstelle_xmlknoten { /** * @author kcf */ private name : string; /** * @author kcf */ private attribute : {[schluessel : string] : string} = {}; /** * @author kcf */ private kinder : Array = []; /** * @author kcf */ public constructor(name : string, attribute : {[schluessel : string] : string} = {}, kinder : Array = []) { this.name = name; this.attribute = attribute; this.kinder = kinder; } /** * @author kcf * @implementation */ public darstellen(tiefe : int = 0) : string { let str : string = ""; // anfang { let str_anfang : string = ""; str_anfang += this.name; // attribute { let str_attribute : string = ""; Object.keys(this.attribute).forEach ( schluessel => { let wert : string = this.attribute[schluessel]; str_attribute += (" " + schluessel + "=" + "\"" + wert + "\""); } ) ; str_anfang += str_attribute; } str_anfang = (einrueckung(tiefe) + "<" + str_anfang + ">" + "\n"); str += str_anfang; } // kinder { this.kinder.forEach(kind => (str += kind.darstellen(tiefe+1))); } // ende { let str_ende : string = ""; str_ende += this.name; str_ende = (einrueckung(tiefe) + "<" + "/" + str_ende + ">" + "\n"); str += str_ende; } return str; } } }