public static void WriteLanes(Process process, XMLStreamWriter xtw) { if (process.Lanes.Count > 0) { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_LANESET, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, "laneSet_" + process.Id); foreach (Lane lane in process.Lanes) { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_LANE, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, lane.Id); if (!string.IsNullOrWhiteSpace(lane.Name)) { xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, lane.Name); } bool didWriteExtensionStartElement = BpmnXMLUtil.WriteExtensionElements(lane, false, xtw); if (didWriteExtensionStartElement) { xtw.WriteEndElement(); } foreach (string flowNodeRef in lane.FlowReferences) { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_FLOWNODE_REF, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteCharacters(flowNodeRef); xtw.WriteEndElement(); } xtw.WriteEndElement(); } xtw.WriteEndElement(); } }
/// <summary> /// write attributes to xtw (except blacklisted) /// </summary> /// <param name="attributes"> </param> /// <param name="xtw"> </param> /// <param name="blackLists"> </param> public static void WriteCustomAttributes(ICollection <IList <ExtensionAttribute> > attributes, XMLStreamWriter xtw, IDictionary <string, string> namespaceMap, params IList <ExtensionAttribute>[] blackLists) { foreach (IList <ExtensionAttribute> attributeList in attributes) { if (attributeList != null && attributeList.Count > 0) { foreach (ExtensionAttribute attribute in attributeList) { if (!IsBlacklisted(attribute, blackLists)) { if (attribute.NamespacePrefix == null) { if (attribute.Namespace == null) { xtw.WriteAttribute(attribute.Name, attribute.Value); } else { xtw.WriteAttribute(attribute.Namespace, attribute.Name, attribute.Value); } } else { if (!namespaceMap.ContainsKey(attribute.Name)) { namespaceMap[attribute.Name] = attribute.Namespace; xtw.WriteNamespace(attribute.NamespacePrefix, attribute.Namespace); } xtw.WriteAttribute(attribute.NamespacePrefix, attribute.Namespace, attribute.Name, attribute.Value); } } } } } }
public static void WriteRootElement(BpmnModel model, XMLStreamWriter xtw, string encoding) { xtw.WriteStartDocument(encoding, "1.0"); // start definitions root element xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_DEFINITIONS, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.DefaultNamespace = BpmnXMLConstants.BPMN2_NAMESPACE; xtw.WriteDefaultNamespace(BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteNamespace(BpmnXMLConstants.XSI_PREFIX, BpmnXMLConstants.XSI_NAMESPACE); xtw.WriteNamespace(BpmnXMLConstants.XSD_PREFIX, BpmnXMLConstants.SCHEMA_NAMESPACE); xtw.WriteNamespace(BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX, BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE); xtw.WriteNamespace(BpmnXMLConstants.BPMNDI_PREFIX, BpmnXMLConstants.BPMNDI_NAMESPACE); xtw.WriteNamespace(BpmnXMLConstants.OMGDC_PREFIX, BpmnXMLConstants.OMGDC_NAMESPACE); xtw.WriteNamespace(BpmnXMLConstants.OMGDI_PREFIX, BpmnXMLConstants.OMGDI_NAMESPACE); foreach (string prefix in model.Namespaces.Keys) { if (!defaultNamespaces.Contains(prefix) && !string.IsNullOrWhiteSpace(prefix)) { xtw.WriteNamespace(prefix, model.Namespaces[prefix]); } } xtw.WriteAttribute(BpmnXMLConstants.TYPE_LANGUAGE_ATTRIBUTE, BpmnXMLConstants.SCHEMA_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.EXPRESSION_LANGUAGE_ATTRIBUTE, BpmnXMLConstants.XPATH_NAMESPACE); if (!string.IsNullOrWhiteSpace(model.TargetNamespace)) { xtw.WriteAttribute(BpmnXMLConstants.TARGET_NAMESPACE_ATTRIBUTE, model.TargetNamespace); } else { xtw.WriteAttribute(BpmnXMLConstants.TARGET_NAMESPACE_ATTRIBUTE, BpmnXMLConstants.PROCESS_NAMESPACE); } //BpmnXMLUtil.WriteCustomAttributes(model.DefinitionsAttributes.Values, xtw, model.Namespaces, defaultAttributes); }
public static void WriteQualifiedAttribute(string attributeName, string value, XMLStreamWriter xtw) { if (!string.IsNullOrWhiteSpace(value)) { xtw.WriteAttribute(BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX, BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE, attributeName, value); } }
public static void WriteDefaultAttribute(string attributeName, string value, XMLStreamWriter xtw) { if (!string.IsNullOrWhiteSpace(value) && !"null".Equals(value, StringComparison.CurrentCultureIgnoreCase)) { xtw.WriteAttribute(attributeName, value); } }
public static void WriteProcess(Process process, XMLStreamWriter xtw) { // start process element xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_PROCESS, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, process.Id); if (!string.IsNullOrWhiteSpace(process.Name)) { xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, process.Name); } xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_PROCESS_EXECUTABLE, process.Executable ? "true" : "false"); if (process.CandidateStarterUsers.Count > 0) { xtw.WriteAttribute(BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX, BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE, BpmnXMLConstants.ATTRIBUTE_PROCESS_CANDIDATE_USERS, BpmnXMLUtil.ConvertToDelimitedString(process.CandidateStarterUsers)); } if (process.CandidateStarterGroups.Count > 0) { xtw.WriteAttribute(BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX, BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE, BpmnXMLConstants.ATTRIBUTE_PROCESS_CANDIDATE_GROUPS, BpmnXMLUtil.ConvertToDelimitedString(process.CandidateStarterGroups)); } // write custom attributes BpmnXMLUtil.WriteCustomAttributes(process.Attributes.Values, xtw, defaultProcessAttributes); if (!string.IsNullOrWhiteSpace(process.Documentation)) { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_DOCUMENTATION, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteCharacters(process.Documentation); xtw.WriteEndElement(); } bool didWriteExtensionStartElement = ActivitiListenerExport.WriteListeners(process, false, xtw); didWriteExtensionStartElement = BpmnXMLUtil.WriteExtensionElements(process, didWriteExtensionStartElement, xtw); if (didWriteExtensionStartElement) { // closing extensions element xtw.WriteEndElement(); } LaneExport.WriteLanes(process, xtw); }
public static void WritePools(BpmnModel model, XMLStreamWriter xtw) { if ((model.Pools?.Count).GetValueOrDefault() > 0) { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_COLLABORATION, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, "Collaboration"); foreach (Pool pool in model.Pools) { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_PARTICIPANT, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, pool.Id); if (!string.IsNullOrWhiteSpace(pool.Name)) { xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, pool.Name); } if (!string.IsNullOrWhiteSpace(pool.ProcessRef)) { xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_PROCESS_REF, pool.ProcessRef); } xtw.WriteEndElement(); } foreach (MessageFlow messageFlow in model.MessageFlows.Values) { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_MESSAGE_FLOW, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, messageFlow.Id); if (!string.IsNullOrWhiteSpace(messageFlow.Name)) { xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, messageFlow.Name); } if (!string.IsNullOrWhiteSpace(messageFlow.SourceRef)) { xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_FLOW_SOURCE_REF, messageFlow.SourceRef); } if (!string.IsNullOrWhiteSpace(messageFlow.TargetRef)) { xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_FLOW_TARGET_REF, messageFlow.TargetRef); } if (!string.IsNullOrWhiteSpace(messageFlow.MessageRef)) { xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_MESSAGE_REF, messageFlow.MessageRef); } xtw.WriteEndElement(); } xtw.WriteEndElement(); } }
public static void WriteDataStores(BpmnModel model, XMLStreamWriter xtw) { foreach (DataStore dataStore in model.DataStores.Values) { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_DATA_STORE, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, dataStore.Id); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, dataStore.Name); if (!string.IsNullOrWhiteSpace(dataStore.ItemSubjectRef)) { xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ITEM_SUBJECT_REF, dataStore.ItemSubjectRef); } if (!string.IsNullOrWhiteSpace(dataStore.DataState)) { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_DATA_STATE, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteCharacters(dataStore.DataState); xtw.WriteEndElement(); } xtw.WriteEndElement(); } }
public static void WriteSignalsAndMessages(BpmnModel model, XMLStreamWriter xtw) { foreach (Process process in model.Processes) { foreach (FlowElement flowElement in process.FindFlowElementsOfType <Event>()) { Event @event = (Event)flowElement; if (@event.EventDefinitions.Count > 0) { EventDefinition eventDefinition = @event.EventDefinitions[0]; if (eventDefinition is SignalEventDefinition signalEvent) { if (!string.IsNullOrWhiteSpace(signalEvent.SignalRef)) { if (!model.ContainsSignalId(signalEvent.SignalRef)) { Signal signal = new Signal(signalEvent.SignalRef, signalEvent.SignalRef); model.AddSignal(signal); } } } else if (eventDefinition is MessageEventDefinition messageEvent) { if (!string.IsNullOrWhiteSpace(messageEvent.MessageRef)) { if (!model.ContainsMessageId(messageEvent.MessageRef)) { Message message = new Message(messageEvent.MessageRef, messageEvent.MessageRef, null); model.AddMessage(message); } } } } } } foreach (Signal signal in model.Signals) { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_SIGNAL, BpmnXMLConstants.BPMN2_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, signal.Id); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, signal.Name); if (signal.Scope != null) { xtw.WriteAttribute(BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE, BpmnXMLConstants.ATTRIBUTE_SCOPE, signal.Scope); } xtw.WriteEndElement(); } foreach (Message message in model.Messages) { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, BpmnXMLConstants.ELEMENT_MESSAGE, BpmnXMLConstants.BPMN2_NAMESPACE); string messageId = message.Id; // remove the namespace from the message id if set if (model.TargetNamespace != null && messageId.StartsWith(model.TargetNamespace, StringComparison.Ordinal)) { messageId = messageId.Replace(model.TargetNamespace, ""); messageId = messageId.ReplaceFirst(":", ""); } else { foreach (string prefix in model.Namespaces.Keys) { string @namespace = model.GetNamespace(prefix); if (messageId.StartsWith(@namespace, StringComparison.Ordinal)) { messageId = messageId.Replace(model.TargetNamespace, ""); messageId = prefix + messageId; } } } xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, messageId); if (!string.IsNullOrWhiteSpace(message.Name)) { xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_NAME, message.Name); } if (!string.IsNullOrWhiteSpace(message.ItemRef)) { // replace the namespace by the right prefix string itemRef = message.ItemRef; foreach (string prefix in model.Namespaces.Keys) { string @namespace = model.GetNamespace(prefix); if (itemRef.StartsWith(@namespace, StringComparison.Ordinal)) { if (prefix.Length == 0) { itemRef = itemRef.Replace(@namespace + ":", ""); } else { itemRef = itemRef.Replace(@namespace, prefix); } break; } } xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ITEM_REF, itemRef); } xtw.WriteEndElement(); } }
public static void WriteBPMNDI(BpmnModel model, XMLStreamWriter xtw) { // BPMN DI information xtw.WriteStartElement(BpmnXMLConstants.BPMNDI_PREFIX, BpmnXMLConstants.ELEMENT_DI_DIAGRAM, BpmnXMLConstants.BPMNDI_NAMESPACE); string processId; if ((model.Pools?.Count).GetValueOrDefault() > 0) { processId = "Collaboration"; } else { processId = model.MainProcess.Id; } xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, "BPMNDiagram_" + processId); xtw.WriteStartElement(BpmnXMLConstants.BPMNDI_PREFIX, BpmnXMLConstants.ELEMENT_DI_PLANE, BpmnXMLConstants.BPMNDI_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_BPMNELEMENT, processId); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, "BPMNPlane_" + processId); foreach (string elementId in model.LocationMap.Keys) { if (model.GetFlowElement(elementId) != null || model.GetArtifact(elementId) != null || model.GetPool(elementId) != null || model.GetLane(elementId) != null) { xtw.WriteStartElement(BpmnXMLConstants.BPMNDI_PREFIX, BpmnXMLConstants.ELEMENT_DI_SHAPE, BpmnXMLConstants.BPMNDI_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_BPMNELEMENT, elementId); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, "BPMNShape_" + elementId); GraphicInfo graphicInfo = model.GetGraphicInfo(elementId); FlowElement flowElement = model.GetFlowElement(elementId); if (flowElement is SubProcess && graphicInfo.Expanded != null) { xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_IS_EXPANDED, graphicInfo.Expanded.ToString()); } xtw.WriteStartElement(BpmnXMLConstants.OMGDC_PREFIX, BpmnXMLConstants.ELEMENT_DI_BOUNDS, BpmnXMLConstants.OMGDC_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_HEIGHT, "" + graphicInfo.Height); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_WIDTH, "" + graphicInfo.Width); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_X, "" + graphicInfo.X); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_Y, "" + graphicInfo.Y); xtw.WriteEndElement(); xtw.WriteEndElement(); } } foreach (string elementId in model.FlowLocationMap.Keys) { if (model.GetFlowElement(elementId) != null || model.GetArtifact(elementId) != null || model.GetMessageFlow(elementId) != null) { xtw.WriteStartElement(BpmnXMLConstants.BPMNDI_PREFIX, BpmnXMLConstants.ELEMENT_DI_EDGE, BpmnXMLConstants.BPMNDI_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_BPMNELEMENT, elementId); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_ID, "BPMNEdge_" + elementId); IList <GraphicInfo> graphicInfoList = model.GetFlowLocationGraphicInfo(elementId) ?? new List <GraphicInfo>(); foreach (GraphicInfo graphicInfo in graphicInfoList) { xtw.WriteStartElement(BpmnXMLConstants.OMGDI_PREFIX, BpmnXMLConstants.ELEMENT_DI_WAYPOINT, BpmnXMLConstants.OMGDI_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_X, "" + graphicInfo.X); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_Y, "" + graphicInfo.Y); xtw.WriteEndElement(); } GraphicInfo labelGraphicInfo = model.GetLabelGraphicInfo(elementId); if (labelGraphicInfo != null) { FlowElement flowElement = model.GetFlowElement(elementId); MessageFlow messageFlow = null; if (flowElement == null) { messageFlow = model.GetMessageFlow(elementId); } bool hasName = false; if (flowElement != null && !string.IsNullOrWhiteSpace(flowElement.Name)) { hasName = true; } else if (messageFlow != null && !string.IsNullOrWhiteSpace(messageFlow.Name)) { hasName = true; } if (labelGraphicInfo != null && hasName) { xtw.WriteStartElement(BpmnXMLConstants.BPMNDI_PREFIX, BpmnXMLConstants.ELEMENT_DI_LABEL, BpmnXMLConstants.BPMNDI_NAMESPACE); xtw.WriteStartElement(BpmnXMLConstants.OMGDC_PREFIX, BpmnXMLConstants.ELEMENT_DI_BOUNDS, BpmnXMLConstants.OMGDC_NAMESPACE); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_HEIGHT, "" + labelGraphicInfo.Height); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_WIDTH, "" + labelGraphicInfo.Width); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_X, "" + labelGraphicInfo.X); xtw.WriteAttribute(BpmnXMLConstants.ATTRIBUTE_DI_Y, "" + labelGraphicInfo.Y); xtw.WriteEndElement(); xtw.WriteEndElement(); } } xtw.WriteEndElement(); } } // end BPMN DI elements xtw.WriteEndElement(); xtw.WriteEndElement(); }
protected internal static void WriteExtensionElement(ExtensionElement extensionElement, IDictionary <string, string> namespaceMap, XMLStreamWriter xtw) { if (!string.IsNullOrWhiteSpace(extensionElement.Name)) { IDictionary <string, string> localNamespaceMap = new Dictionary <string, string>(); if (!string.IsNullOrWhiteSpace(extensionElement.Namespace)) { if (!string.IsNullOrWhiteSpace(extensionElement.NamespacePrefix)) { xtw.WriteStartElement(extensionElement.NamespacePrefix, extensionElement.Name, extensionElement.Namespace); if (!namespaceMap.ContainsKey(extensionElement.NamespacePrefix) || !namespaceMap[extensionElement.NamespacePrefix].Equals(extensionElement.Namespace)) { xtw.WriteNamespace(extensionElement.NamespacePrefix, extensionElement.Namespace); namespaceMap[extensionElement.NamespacePrefix] = extensionElement.Namespace; localNamespaceMap[extensionElement.NamespacePrefix] = extensionElement.Namespace; } } else { xtw.WriteStartElement(extensionElement.Namespace, extensionElement.Name); } } else { xtw.WriteStartElement(BpmnXMLConstants.BPMN_PREFIX, extensionElement.Name, BpmnXMLConstants.BPMN2_NAMESPACE); } foreach (IList <ExtensionAttribute> attributes in extensionElement.Attributes.Values) { foreach (ExtensionAttribute attribute in attributes) { if (!string.IsNullOrWhiteSpace(attribute.Name) && attribute.Value != null) { if (!string.IsNullOrWhiteSpace(attribute.Namespace)) { if (!string.IsNullOrWhiteSpace(attribute.NamespacePrefix)) { if (!namespaceMap.ContainsKey(attribute.NamespacePrefix) || !namespaceMap[attribute.NamespacePrefix].Equals(attribute.Namespace)) { xtw.WriteNamespace(attribute.NamespacePrefix, attribute.Namespace); namespaceMap[attribute.NamespacePrefix] = attribute.Namespace; } xtw.WriteAttribute(attribute.NamespacePrefix, attribute.Namespace, attribute.Name, attribute.Value); } else { xtw.WriteAttribute(attribute.Namespace, attribute.Name, attribute.Value); } } else { xtw.WriteAttribute(attribute.Name, attribute.Value); } } } } if (extensionElement.ElementText != null) { xtw.WriteCData(extensionElement.ElementText); } else { foreach (IList <ExtensionElement> childElements in extensionElement.ChildElements.Values) { foreach (ExtensionElement childElement in childElements) { WriteExtensionElement(childElement, namespaceMap, xtw); } } } foreach (string prefix in localNamespaceMap.Keys) { namespaceMap.Remove(prefix); } xtw.WriteEndElement(); } }