revisitNodeNames(def);
// get the xml from Definitions
ResourceSet rSet = new ResourceSetImpl();
rSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn2", new JBPMBpmn2ResourceFactoryImpl());
JBPMBpmn2ResourceImpl bpmn2resource = (JBPMBpmn2ResourceImpl) rSet.createResource(URI.createURI("virtual.bpmn2"));
rSet.getResources().add(bpmn2resource);
bpmn2resource.getContents().add(def);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bpmn2resource.save(outputStream, new HashMap<Object, Object>());
String fullXmlModel = outputStream.toString();
// convert to json and write response
String json = profile.createUnmarshaller().parseModel(fullXmlModel, profile, pp);
resp.setContentType("application/json");
resp.getWriter().print(json);
} catch(Exception e) {
_logger.error(e.getMessage());
resp.setContentType("application/json");
resp.getWriter().print("{}");
}
} else if (transformto != null && transformto.equals(BPMN2_TO_JSON)) {
try {
if(convertServiceTasks != null && convertServiceTasks.equals("true")) {
bpmn2in = bpmn2in.replaceAll("drools:taskName=\".*?\"", "drools:taskName=\"ReadOnlyService\"");
bpmn2in = bpmn2in.replaceAll("tns:taskName=\".*?\"", "tns:taskName=\"ReadOnlyService\"");
}
Definitions def = ((JbpmProfileImpl) profile).getDefinitions(bpmn2in);
def.setTargetNamespace("http://www.omg.org/bpmn20");
if(convertServiceTasks != null && convertServiceTasks.equals("true")) {
// fix the data input associations for converted tasks
List<RootElement> rootElements = def.getRootElements();
for(RootElement root : rootElements) {
if(root instanceof Process) {
updateTaskDataInputs((Process) root, def);
}
}
}
// get the xml from Definitions
ResourceSet rSet = new ResourceSetImpl();
rSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn2", new JBPMBpmn2ResourceFactoryImpl());
JBPMBpmn2ResourceImpl bpmn2resource = (JBPMBpmn2ResourceImpl) rSet.createResource(URI.createURI("virtual.bpmn2"));
bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_ENCODING, "UTF-8");
bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_DEFER_IDREF_RESOLUTION, true);
bpmn2resource.getDefaultLoadOptions().put( JBPMBpmn2ResourceImpl.OPTION_DISABLE_NOTIFY, true );
bpmn2resource.getDefaultLoadOptions().put(JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF, JBPMBpmn2ResourceImpl.OPTION_PROCESS_DANGLING_HREF_RECORD);
bpmn2resource.setEncoding("UTF-8");
rSet.getResources().add(bpmn2resource);
bpmn2resource.getContents().add(def);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bpmn2resource.save(outputStream, new HashMap<Object, Object>());
String revisedXmlModel = outputStream.toString();
String json = profile.createUnmarshaller().parseModel(revisedXmlModel, profile, pp);
resp.setContentType("application/json");
resp.getWriter().print(json);
} catch(Exception e) {