use of org.activiti.bpmn.exceptions.XMLException in project Activiti by Activiti.
the class MapExceptionConverterTest method testMapExceptionWithInvalidHasChildren.
@Test
public void testMapExceptionWithInvalidHasChildren() throws Exception {
resourceName = "mapException/mapExceptionInvalidHasChildrenModel.bpmn";
try {
BpmnModel bpmnModel = readXMLFile();
fail("No exception is thrown for mapExecution with invalid boolean for hasChildren");
} catch (XMLException x) {
assertTrue(x.getMessage().indexOf("is not valid boolean") != -1);
} catch (Exception e) {
fail("wrong exception thrown. XmlException expected, " + e.getClass() + " thrown");
}
}
use of org.activiti.bpmn.exceptions.XMLException in project Activiti by Activiti.
the class MapExceptionConverterTest method testMapExceptionWithNoErrorCode.
@Test
public void testMapExceptionWithNoErrorCode() throws Exception {
resourceName = "mapException/mapExceptionNoErrorCode.bpmn";
try {
BpmnModel bpmnModel = readXMLFile();
fail("No exception is thrown for mapExecution with no Error Code");
} catch (XMLException x) {
assertTrue(x.getMessage().indexOf("No errorCode defined") != -1);
} catch (Exception e) {
fail("wrong exception thrown. XmlException expected, " + e.getClass() + " thrown");
}
}
use of org.activiti.bpmn.exceptions.XMLException in project Activiti by Activiti.
the class BpmnXMLConverter method createXML.
private void createXML(FlowElement flowElement, BpmnModel model, XMLStreamWriter xtw) throws Exception {
if (flowElement instanceof SubProcess) {
SubProcess subProcess = (SubProcess) flowElement;
if (flowElement instanceof Transaction) {
xtw.writeStartElement(ELEMENT_TRANSACTION);
} else {
xtw.writeStartElement(ELEMENT_SUBPROCESS);
}
xtw.writeAttribute(ATTRIBUTE_ID, subProcess.getId());
if (StringUtils.isNotEmpty(subProcess.getName())) {
xtw.writeAttribute(ATTRIBUTE_NAME, subProcess.getName());
} else {
xtw.writeAttribute(ATTRIBUTE_NAME, "subProcess");
}
if (subProcess instanceof EventSubProcess) {
xtw.writeAttribute(ATTRIBUTE_TRIGGERED_BY, ATTRIBUTE_VALUE_TRUE);
} else if (subProcess instanceof Transaction == false) {
if (subProcess.isAsynchronous()) {
BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
if (subProcess.isNotExclusive()) {
BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
}
}
}
if (StringUtils.isNotEmpty(subProcess.getDocumentation())) {
xtw.writeStartElement(ELEMENT_DOCUMENTATION);
xtw.writeCharacters(subProcess.getDocumentation());
xtw.writeEndElement();
}
boolean didWriteExtensionStartElement = ActivitiListenerExport.writeListeners(subProcess, false, xtw);
didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(subProcess, didWriteExtensionStartElement, model.getNamespaces(), xtw);
if (didWriteExtensionStartElement) {
// closing extensions element
xtw.writeEndElement();
}
MultiInstanceExport.writeMultiInstance(subProcess, xtw);
for (FlowElement subElement : subProcess.getFlowElements()) {
createXML(subElement, model, xtw);
}
for (Artifact artifact : subProcess.getArtifacts()) {
createXML(artifact, model, xtw);
}
xtw.writeEndElement();
} else {
BaseBpmnXMLConverter converter = convertersToXMLMap.get(flowElement.getClass());
if (converter == null) {
throw new XMLException("No converter for " + flowElement.getClass() + " found");
}
converter.convertToXML(xtw, flowElement, model);
}
}
use of org.activiti.bpmn.exceptions.XMLException in project Activiti by Activiti.
the class BpmnXMLConverter method convertToBpmnModel.
public BpmnModel convertToBpmnModel(InputStreamProvider inputStreamProvider, boolean validateSchema, boolean enableSafeBpmnXml, String encoding) {
XMLInputFactory xif = XMLInputFactory.newInstance();
if (xif.isPropertySupported(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES)) {
xif.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
}
if (xif.isPropertySupported(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES)) {
xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
}
if (xif.isPropertySupported(XMLInputFactory.SUPPORT_DTD)) {
xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
}
InputStreamReader in = null;
try {
in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding);
XMLStreamReader xtr = xif.createXMLStreamReader(in);
try {
if (validateSchema) {
if (!enableSafeBpmnXml) {
validateModel(inputStreamProvider);
} else {
validateModel(xtr);
}
// The input stream is closed after schema validation
in = new InputStreamReader(inputStreamProvider.getInputStream(), encoding);
xtr = xif.createXMLStreamReader(in);
}
} catch (Exception e) {
throw new XMLException(e.getMessage(), e);
}
// XML conversion
return convertToBpmnModel(xtr);
} catch (UnsupportedEncodingException e) {
throw new XMLException("The bpmn 2.0 xml is not UTF8 encoded", e);
} catch (XMLStreamException e) {
throw new XMLException("Error while reading the BPMN 2.0 XML", e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
LOGGER.debug("Problem closing BPMN input stream", e);
}
}
}
}
Aggregations