feat(Viewer): improve BPMN 2.0 XML parse error message

Related to #86
This commit is contained in:
Nico Rehwaldt 2014-06-30 19:04:40 +02:00
parent 88c5dcbb2f
commit 1aa431ca36
3 changed files with 49 additions and 0 deletions

View File

@ -26,6 +26,23 @@ function initListeners(diagram, listeners) {
});
}
function checkValidationError(err) {
// check if we can help the user by indicating wrong BPMN 2.0 xml
// (in case he or the exporting tool did not get that right)
var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
var match = pattern.exec(err.message);
if (match) {
err.message =
'unparsable content <' + match[1] + '> detected; ' +
'this may indicate an invalid BPMN 2.0 diagram file' + match[2];
}
return err;
}
/**
* @class
*
@ -87,7 +104,9 @@ Viewer.prototype.importXML = function(xml, done) {
var self = this;
BpmnModel.fromXML(xml, 'bpmn:Definitions', function(err, definitions) {
if (err) {
err = checkValidationError(err);
return done(err);
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1" targetNamespace="http://www.example.com">
<collaboration name="TEST">
<participant id="Participant_1" name="Participant Name"/>
</collaboration>
<bpmndi:BPMNDiagram id="BPMNDiagram_1" name="Default Collaboration Diagram">
<bpmndi:BPMNPlane id="BPMNPlane_1" >
<bpmndi:BPMNShape id="BPMNShape_Participant_1" bpmnElement="Participant_1" isHorizontal="true">
<dc:Bounds height="370.0" width="1571.0" x="30.0" y="70.0"/>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>

View File

@ -75,6 +75,23 @@ describe('viewer', function() {
});
});
it('should handle missing namespace', function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/error/missing-namespace.bpmn', 'utf8');
createViewer(xml, function(err) {
expect(err).toBeDefined();
expect(err.message).toEqual(
'unparsable content <collaboration> detected; this may indicate an invalid BPMN 2.0 diagram file\n' +
'\tline: 2\n' +
'\tcolumn: 29\n' +
'\tnested error: unrecognized element <collaboration>');
done();
});
});
});