2016-09-20 20:30:39 +02:00
|
|
|
import {Injectable} from "@angular/core";
|
|
|
|
import {Converter} from "./converter/converter";
|
|
|
|
import {Base64Encoder} from "./converter/base64encoder";
|
|
|
|
import {Base64Decoder} from "./converter/base64decoder";
|
2016-09-20 20:45:04 +02:00
|
|
|
import {URIEncoder} from "./converter/uriencoder";
|
|
|
|
import {URIDecoder} from "./converter/uridecoder";
|
|
|
|
import {URIComponentEncoder} from "./converter/uricomponentencoder";
|
|
|
|
import {URIComponentDecoder} from "./converter/uricomponentdecoder";
|
2016-09-20 21:12:13 +02:00
|
|
|
import {HTMLEntitiesEncoder} from "./converter/htmlentitiesencoder";
|
|
|
|
import {HTMLEntitiesDecoder} from "./converter/htmlentitiesdecoder";
|
|
|
|
import {DecToHexConverter} from "./converter/dectohexconverter";
|
|
|
|
import {HexToDecConverter} from "./converter/hextodecconverter";
|
|
|
|
import {DecToBinConverter} from "./converter/dectobinconverter";
|
|
|
|
import {BinToDecConverter} from "./converter/bintodecconverter";
|
2016-09-20 22:02:38 +02:00
|
|
|
import {QuotedPrintableDecoder} from "./converter/quotedprintabledecoder";
|
|
|
|
import {QuotedPrintableEncoder} from "./converter/quotedprintableencoder";
|
2016-09-20 22:34:31 +02:00
|
|
|
import {NativeLibraryWrapperService} from "./nativelibrarywrapper.service";
|
2016-09-27 23:50:52 +02:00
|
|
|
import {PunycodeEncoder} from "./converter/punycodeencoder";
|
|
|
|
import {PunycodeDecoder} from "./converter/punycodedecoder";
|
2016-09-28 13:53:05 +02:00
|
|
|
import {UTF8Encoder} from "./converter/utf8encoder";
|
|
|
|
import {UTF8Decoder} from "./converter/utf8decoder";
|
2016-09-15 20:43:37 +02:00
|
|
|
|
|
|
|
@Injectable()
|
2016-09-20 22:34:31 +02:00
|
|
|
export class ConverterRegistryService {
|
2017-04-15 18:51:22 +02:00
|
|
|
private converters: Converter[] = [];
|
2016-09-15 20:43:37 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
constructor(private wrapper: NativeLibraryWrapperService) {
|
|
|
|
this.init();
|
|
|
|
}
|
2016-09-15 20:43:37 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
public getAllConverters(): Converter[] {
|
|
|
|
return this.converters;
|
|
|
|
}
|
2016-09-15 20:43:37 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
public getConverter(id: string): Converter {
|
|
|
|
for (let i = 0; i < this.converters.length; i++) {
|
|
|
|
if (this.converters[i].getId() == id) {
|
|
|
|
return this.converters[i];
|
|
|
|
}
|
2016-09-15 20:43:37 +02:00
|
|
|
}
|
2017-04-15 18:51:22 +02:00
|
|
|
return undefined;
|
|
|
|
}
|
2016-09-15 20:43:37 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
private init(): void {
|
|
|
|
this.registerConverter(new Base64Encoder());
|
|
|
|
this.registerConverter(new Base64Decoder());
|
|
|
|
this.registerConverter(new URIEncoder());
|
|
|
|
this.registerConverter(new URIDecoder());
|
|
|
|
this.registerConverter(new URIComponentEncoder());
|
|
|
|
this.registerConverter(new URIComponentDecoder());
|
|
|
|
this.registerConverter(new HTMLEntitiesEncoder());
|
|
|
|
this.registerConverter(new HTMLEntitiesDecoder());
|
|
|
|
this.registerConverter(new QuotedPrintableEncoder(this.wrapper));
|
|
|
|
this.registerConverter(new QuotedPrintableDecoder(this.wrapper));
|
|
|
|
this.registerConverter(new DecToHexConverter());
|
|
|
|
this.registerConverter(new HexToDecConverter());
|
|
|
|
this.registerConverter(new DecToBinConverter());
|
|
|
|
this.registerConverter(new BinToDecConverter());
|
|
|
|
this.registerConverter(new PunycodeEncoder(this.wrapper));
|
|
|
|
this.registerConverter(new PunycodeDecoder(this.wrapper));
|
|
|
|
this.registerConverter(new UTF8Encoder(this.wrapper));
|
|
|
|
this.registerConverter(new UTF8Decoder(this.wrapper));
|
|
|
|
}
|
2016-09-15 20:43:37 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
private registerConverter(converter: Converter): void {
|
|
|
|
this.converters.forEach((c: Converter) => {
|
|
|
|
if (c.getId() == converter.getId()) {
|
|
|
|
throw new Error("Converter-ID " + converter.getId() + " is already registered!");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.converters.push(converter);
|
|
|
|
}
|
2016-09-15 20:43:37 +02:00
|
|
|
}
|