2018-08-31 23:22:15 +02:00
|
|
|
import {Base64Decoder} from './converter/base64-decoder';
|
|
|
|
import {Base64Encoder} from './converter/base64-encoder';
|
2018-08-31 23:35:14 +02:00
|
|
|
import {BinToDecConverter} from './converter/bin-to-dec-converter';
|
2018-08-31 22:53:50 +02:00
|
|
|
import {Converter} from './converter/converter';
|
2018-08-31 23:38:22 +02:00
|
|
|
import {DecToBinConverter} from './converter/dec-to-bin-converter';
|
2018-08-31 23:40:47 +02:00
|
|
|
import {DecToHexConverter} from './converter/dec-to-hex-converter';
|
2018-08-31 23:59:52 +02:00
|
|
|
import {HexToDecConverter} from './converter/hex-to-dec-converter';
|
2018-09-01 00:08:37 +02:00
|
|
|
import {HTMLEntitiesDecoder} from './converter/htmlentities-decoder';
|
|
|
|
import {HTMLEntitiesEncoder} from './converter/htmlentities-encoder';
|
2018-08-31 22:53:50 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
2018-08-31 23:00:13 +02:00
|
|
|
import {NativeLibraryWrapperService} from './native-library-wrapper.service';
|
2018-09-01 00:26:35 +02:00
|
|
|
import {PunycodeDecoder} from './converter/punycode-decoder';
|
|
|
|
import {PunycodeEncoder} from './converter/punycode-encoder';
|
2018-09-01 00:38:42 +02:00
|
|
|
import {QuotedPrintableDecoder} from './converter/quoted-printable-decoder';
|
|
|
|
import {QuotedPrintableEncoder} from './converter/quoted-printable-encoder';
|
2018-09-01 00:44:24 +02:00
|
|
|
import {ROT13Converter} from './converter/rot13-converter';
|
2018-09-01 00:53:52 +02:00
|
|
|
import {URIComponentDecoder} from './converter/uricomponent-decoder';
|
|
|
|
import {URIComponentEncoder} from './converter/uricomponent-encoder';
|
2018-08-31 22:53:50 +02:00
|
|
|
import {URIDecoder} from './converter/uridecoder';
|
|
|
|
import {URIEncoder} from './converter/uriencoder';
|
|
|
|
import {UTF8Decoder} from './converter/utf8decoder';
|
|
|
|
import {UTF8Encoder} from './converter/utf8encoder';
|
2016-09-15 20:43:37 +02:00
|
|
|
|
2018-08-31 22:53:50 +02:00
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
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++) {
|
2017-04-15 19:04:49 +02:00
|
|
|
if (this.converters[i].getId() === id) {
|
2017-04-15 18:51:22 +02:00
|
|
|
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));
|
2018-08-31 21:47:18 +02:00
|
|
|
this.registerConverter(new ROT13Converter());
|
2017-04-15 18:51:22 +02:00
|
|
|
}
|
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) => {
|
2017-04-15 19:04:49 +02:00
|
|
|
if (c.getId() === converter.getId()) {
|
|
|
|
throw new Error('Converter-ID ' + converter.getId() + ' is already registered!');
|
2017-04-15 18:51:22 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.converters.push(converter);
|
|
|
|
}
|
2016-09-15 20:43:37 +02:00
|
|
|
}
|