All files / src/web/flowable/roundTrip xmlBuilders.ts

80.85% Statements 38/47
60.71% Branches 17/28
100% Functions 7/7
80.85% Lines 38/47

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100                        4x 4x       2x 2x       1x       2x 2x 2x   2x     2x 2x       3x 3x 3x   3x 1x     3x   1x 1x   2x 2x                             3x       3x 3x 3x   3x     3x       2x 2x 2x   2x 2x     2x 2x 1x   2x 1x     2x  
import type {
	FlowableEventListener,
	FlowableFieldExtension,
	FlowableFormProperty,
	FlowableIOParameter,
	FlowableListener,
	FlowableLocalization,
	FlowableMultiInstance,
} from '../types';
import { escapeXml } from './xmlUtils';
 
export function buildFieldExtensionNode(fieldExtension: FlowableFieldExtension): string {
	const tagName = fieldExtension.valueType === 'expression' ? 'activiti:expression' : 'activiti:string';
	return `<activiti:field name="${escapeXml(fieldExtension.name)}"><${tagName}>${escapeXml(fieldExtension.value)}</${tagName}></activiti:field>`;
}
 
export function buildListenerNode(tagName: 'activiti:taskListener' | 'activiti:executionListener', listener: FlowableListener): string {
	const implementationAttribute = `activiti:${listener.implementationType}`;
	return `<${tagName} event="${escapeXml(listener.event)}" ${implementationAttribute}="${escapeXml(listener.implementation)}"></${tagName}>`;
}
 
export function buildFormPropertyNode(formProperty: FlowableFormProperty): string {
	return `<activiti:formProperty id="${escapeXml(formProperty.id)}" name="${escapeXml(formProperty.name)}" type="${escapeXml(formProperty.type)}" required="${formProperty.required}" readable="${formProperty.readable}" writable="${formProperty.writable}" default="${escapeXml(formProperty.defaultValue)}"></activiti:formProperty>`;
}
 
export function buildIOParameterNode(tagName: string, param: FlowableIOParameter): string {
	const attrs: string[] = [];
	Eif (param.source) {
		attrs.push(`source="${escapeXml(param.source)}"`);
	}
	Iif (param.sourceExpression) {
		attrs.push(`sourceExpression="${escapeXml(param.sourceExpression)}"`);
	}
	attrs.push(`target="${escapeXml(param.target)}"`);
	return `<${tagName} ${attrs.join(' ')}/>`;
}
 
export function buildEventListenerNode(listener: FlowableEventListener): string {
	const attrs: string[] = [];
	Eif (listener.events) {
		attrs.push(`events="${escapeXml(listener.events)}"`);
	}
	if (listener.entityType) {
		attrs.push(`entityType="${escapeXml(listener.entityType)}"`);
	}
 
	switch (listener.implementationType) {
		case 'class':
			attrs.push(`class="${escapeXml(listener.implementation)}"`);
			break;
		case 'delegateExpression':
			attrs.push(`delegateExpression="${escapeXml(listener.implementation)}"`);
			break;
		case 'throwSignalEvent':
			attrs.push(`signalName="${escapeXml(listener.implementation)}"`);
			break;
		case 'throwGlobalSignalEvent':
			attrs.push(`signalName="${escapeXml(listener.implementation)}" throwGlobalEvent="true"`);
			break;
		case 'throwMessageEvent':
			attrs.push(`messageName="${escapeXml(listener.implementation)}"`);
			break;
		case 'throwErrorEvent':
			attrs.push(`errorCode="${escapeXml(listener.implementation)}"`);
			break;
	}
 
	return `<activiti:eventListener ${attrs.join(' ')}/>`;
}
 
export function buildLocalizationNode(localization: FlowableLocalization): string {
	const attrs = [`locale="${escapeXml(localization.locale)}"`];
	Eif (localization.name) {
		attrs.push(`name="${escapeXml(localization.name)}"`);
	}
	const inner = localization.description
		? `<activiti:documentation>${escapeXml(localization.description)}</activiti:documentation>`
		: '';
	return `<activiti:localization ${attrs.join(' ')}>${inner}</activiti:localization>`;
}
 
export function buildMultiInstanceNode(mi: FlowableMultiInstance): string {
	const attrs: string[] = [`isSequential="${mi.sequential}"`];
	Eif (mi.collection) {
		attrs.push(`activiti:collection="${escapeXml(mi.collection)}"`);
	}
	Eif (mi.elementVariable) {
		attrs.push(`activiti:elementVariable="${escapeXml(mi.elementVariable)}"`);
	}
 
	let inner = '';
	if (mi.loopCardinality) {
		inner += `<loopCardinality>${escapeXml(mi.loopCardinality)}</loopCardinality>`;
	}
	if (mi.completionCondition) {
		inner += `<completionCondition>${escapeXml(mi.completionCondition)}</completionCondition>`;
	}
 
	return `<multiInstanceLoopCharacteristics ${attrs.join(' ')}>${inner}</multiInstanceLoopCharacteristics>`;
}