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-15 20:43:37 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ConverterregistryService {
|
|
|
|
private converters:Converter[] = [];
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
2016-09-20 20:30:39 +02:00
|
|
|
public getAllConverters():Converter[] {
|
2016-09-15 20:43:37 +02:00
|
|
|
return this.converters;
|
|
|
|
}
|
|
|
|
|
|
|
|
public getConverter(id:string):Converter {
|
|
|
|
for (let i = 0; i < this.converters.length; i++) {
|
|
|
|
if (this.converters[i].getId() == id) {
|
|
|
|
return this.converters[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
private init():void {
|
|
|
|
this.registerConverter(new Base64Encoder());
|
|
|
|
this.registerConverter(new Base64Decoder());
|
2016-09-20 20:45:04 +02:00
|
|
|
this.registerConverter(new URIEncoder());
|
|
|
|
this.registerConverter(new URIDecoder());
|
|
|
|
this.registerConverter(new URIComponentEncoder());
|
|
|
|
this.registerConverter(new URIComponentDecoder());
|
2016-09-15 20:43:37 +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);
|
|
|
|
}
|
|
|
|
}
|