use of org.activiti.bpmn.model.ExtensionAttribute in project Activiti by Activiti.
the class CustomNamespaceAttributeConverterTest method validateModel.
private void validateModel(BpmnModel model) {
Process process = model.getMainProcess();
assertNotNull(process.getAttributes());
assertEquals(1, process.getAttributes().size());
List<ExtensionAttribute> attributes = process.getAttributes().get("version");
assertNotNull(attributes);
assertEquals(1, attributes.size());
ExtensionAttribute attribute = attributes.get(0);
//custom:version = "9"
assertNotNull(attribute);
assertEquals("http://custom.org/bpmn", attribute.getNamespace());
assertEquals("custom", attribute.getNamespacePrefix());
assertEquals("version", attribute.getName());
assertEquals("9", attribute.getValue());
FlowElement flowElement = model.getMainProcess().getFlowElement("usertask");
assertNotNull(flowElement);
assertTrue(flowElement instanceof UserTask);
assertEquals("usertask", flowElement.getId());
UserTask userTask = (UserTask) flowElement;
assertEquals("usertask", userTask.getId());
assertEquals("User Task", userTask.getName());
Map<String, List<ExtensionAttribute>> attributesMap = userTask.getAttributes();
assertNotNull(attributesMap);
assertEquals(2, attributesMap.size());
attributes = attributesMap.get("id");
assertNotNull(attributes);
assertEquals(1, attributes.size());
ExtensionAttribute a = attributes.get(0);
assertNotNull(a);
assertEquals("id", a.getName());
assertEquals("test", a.getValue());
assertEquals("custom2", a.getNamespacePrefix());
assertEquals("http://custom2.org/bpmn", a.getNamespace());
attributes = attributesMap.get("attr");
assertNotNull(attributes);
assertEquals(1, attributes.size());
a = attributes.get(0);
assertNotNull(a);
assertEquals("attr", a.getName());
assertEquals("attrValue", a.getValue());
assertEquals("custom2", a.getNamespacePrefix());
assertEquals("http://custom2.org/bpmn", a.getNamespace());
}
use of org.activiti.bpmn.model.ExtensionAttribute in project Activiti by Activiti.
the class DefinitionsParser method parse.
@SuppressWarnings("unchecked")
public void parse(XMLStreamReader xtr, BpmnModel model) throws Exception {
model.setTargetNamespace(xtr.getAttributeValue(null, TARGET_NAMESPACE_ATTRIBUTE));
for (int i = 0; i < xtr.getNamespaceCount(); i++) {
String prefix = xtr.getNamespacePrefix(i);
if (StringUtils.isNotEmpty(prefix)) {
model.addNamespace(prefix, xtr.getNamespaceURI(i));
}
}
for (int i = 0; i < xtr.getAttributeCount(); i++) {
ExtensionAttribute extensionAttribute = new ExtensionAttribute();
extensionAttribute.setName(xtr.getAttributeLocalName(i));
extensionAttribute.setValue(xtr.getAttributeValue(i));
if (StringUtils.isNotEmpty(xtr.getAttributeNamespace(i))) {
extensionAttribute.setNamespace(xtr.getAttributeNamespace(i));
}
if (StringUtils.isNotEmpty(xtr.getAttributePrefix(i))) {
extensionAttribute.setNamespacePrefix(xtr.getAttributePrefix(i));
}
if (!BpmnXMLUtil.isBlacklisted(extensionAttribute, defaultAttributes)) {
model.addDefinitionsAttribute(extensionAttribute);
}
}
}
use of org.activiti.bpmn.model.ExtensionAttribute in project Activiti by Activiti.
the class BpmnXMLUtil method writeCustomAttributes.
/**
* write attributes to xtw (except blacklisted)
* @param attributes
* @param xtw
* @param blackList
*/
public static void writeCustomAttributes(Collection<List<ExtensionAttribute>> attributes, XMLStreamWriter xtw, Map<String, String> namespaceMap, List<ExtensionAttribute>... blackLists) throws XMLStreamException {
for (List<ExtensionAttribute> attributeList : attributes) {
if (attributeList != null && !attributeList.isEmpty()) {
for (ExtensionAttribute attribute : attributeList) {
if (!isBlacklisted(attribute, blackLists)) {
if (attribute.getNamespacePrefix() == null) {
if (attribute.getNamespace() == null)
xtw.writeAttribute(attribute.getName(), attribute.getValue());
else {
xtw.writeAttribute(attribute.getNamespace(), attribute.getName(), attribute.getValue());
}
} else {
if (!namespaceMap.containsKey(attribute.getNamespacePrefix())) {
namespaceMap.put(attribute.getNamespacePrefix(), attribute.getNamespace());
xtw.writeNamespace(attribute.getNamespacePrefix(), attribute.getNamespace());
}
xtw.writeAttribute(attribute.getNamespacePrefix(), attribute.getNamespace(), attribute.getName(), attribute.getValue());
}
}
}
}
}
}
use of org.activiti.bpmn.model.ExtensionAttribute in project Activiti by Activiti.
the class BpmnXMLUtil method addCustomAttributes.
/**
* add all attributes from XML to element extensionAttributes (except blackListed).
*
* @param xtr
* @param element
* @param blackList
*/
public static void addCustomAttributes(XMLStreamReader xtr, BaseElement element, List<ExtensionAttribute>... blackLists) {
for (int i = 0; i < xtr.getAttributeCount(); i++) {
ExtensionAttribute extensionAttribute = new ExtensionAttribute();
extensionAttribute.setName(xtr.getAttributeLocalName(i));
extensionAttribute.setValue(xtr.getAttributeValue(i));
if (StringUtils.isNotEmpty(xtr.getAttributeNamespace(i))) {
extensionAttribute.setNamespace(xtr.getAttributeNamespace(i));
}
if (StringUtils.isNotEmpty(xtr.getAttributePrefix(i))) {
extensionAttribute.setNamespacePrefix(xtr.getAttributePrefix(i));
}
if (!isBlacklisted(extensionAttribute, blackLists)) {
element.addAttribute(extensionAttribute);
}
}
}
Aggregations