summaryrefslogtreecommitdiffstats
path: root/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts')
-rw-r--r--cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts24
1 files changed, 23 insertions, 1 deletions
diff --git a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts
index 6cc62758e..d8607c764 100644
--- a/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts
+++ b/cds-ui/designer-client/src/app/modules/feature-modules/packages/package-creation/template-mapping/utils/ParserFactory/ParserFactory.ts
@@ -4,22 +4,35 @@ import { Parser } from './Parser';
import { VtlParser } from './VtlParser';
import { FileExtension } from '../TemplateType';
import { JinjaXMLParser } from './JinjaXML';
+import { VtlYMLParser } from './VtlYMLParser';
+import { JinjaYMLParser } from './JinjaYML';
export class ParserFactory {
getParser(fileContent: string, fileExtension: string): Parser {
let parser: Parser;
console.log('file extension =' + fileExtension);
+
if (fileExtension === FileExtension.Velocity) {
+
if (this.isXML(fileContent)) {
parser = new XmlParser();
- } else {
+ } else if (this.isJSON(fileContent)) {
parser = new VtlParser();
+ } else {
+ parser = new VtlYMLParser();
}
+
} else if (fileExtension === FileExtension.Jinja) {
+
if (this.isXML(fileContent)) {
parser = new JinjaXMLParser();
+ } else if (this.isJSON(fileContent)) {
+ // TODO: implement JSON parser
+ } else {
+ parser = new JinjaYMLParser();
}
+
} else if (fileExtension === FileExtension.XML) {
parser = new XmlParser();
}
@@ -29,4 +42,13 @@ export class ParserFactory {
private isXML(fileContent: string): boolean {
return fileContent.includes('<?xml version="1.0" encoding="UTF-8"?>');
}
+
+ private isJSON(fileContent: string): boolean {
+ try {
+ JSON.parse(fileContent);
+ } catch (e) {
+ return false;
+ }
+ return true;
+ }
}