//rawSvg = URLDecoder.decode(rawSvg, "UTF-8");
if(sourceEnc != null && sourceEnc.equals("true")) {
bpmn2in = new String(Base64.decodeBase64(bpmn2in), "UTF-8");
}
IDiagramProfile profile = _profileService.findProfile(req, profileName);
DroolsFactoryImpl.init();
BpsimFactoryImpl.init();
Repository repository = profile.getRepository();
if (transformto != null && transformto.equals(TO_PDF)) {
try {
if(respaction != null && respaction.equals(RESPACTION_SHOWURL)) {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PDFTranscoder t = new PDFTranscoder();
TranscoderInput input = new TranscoderInput(new StringReader(formattedSvg));
TranscoderOutput output = new TranscoderOutput(bout);
t.transcode(input, output);
resp.setCharacterEncoding("UTF-8");
resp.setContentType("text/plain");
resp.getWriter().write("<object data=\"data:application/pdf;base64," + Base64.encodeBase64(bout.toByteArray()) + "\" type=\"application/pdf\"></object>");
} else {
storeInRepository(uuid, rawSvg, transformto, processid, repository);
resp.setContentType("application/pdf");
if (processid != null) {
resp.setHeader("Content-Disposition",
"attachment; filename=\"" + processid + ".pdf\"");
} else {
resp.setHeader("Content-Disposition",
"attachment; filename=\"" + uuid + ".pdf\"");
}
PDFTranscoder t = new PDFTranscoder();
TranscoderInput input = new TranscoderInput(new StringReader(formattedSvg));
TranscoderOutput output = new TranscoderOutput(resp.getOutputStream());
t.transcode(input, output);
}
} catch (TranscoderException e) {
resp.sendError(500, e.getMessage());
}
} else if (transformto != null && transformto.equals(TO_PNG)) {
try {
if(respaction != null && respaction.equals(RESPACTION_SHOWURL)) {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PNGTranscoder t = new PNGTranscoder();
t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen");
TranscoderInput input = new TranscoderInput(new StringReader(formattedSvg));
TranscoderOutput output = new TranscoderOutput(bout);
t.transcode(input, output);
resp.setCharacterEncoding("UTF-8");
resp.setContentType("text/plain");
resp.getWriter().write("<img src=\"data:image/png;base64," + Base64.encodeBase64(bout.toByteArray()) + "\">");
} else {
storeInRepository(uuid, rawSvg, transformto, processid, repository);
resp.setContentType("image/png");
if (processid != null) {
resp.setHeader("Content-Disposition", "attachment; filename=\"" + processid + ".png\"");
} else {
resp.setHeader("Content-Disposition", "attachment; filename=\"" + uuid + ".png\"");
}
PNGTranscoder t = new PNGTranscoder();
t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen");
TranscoderInput input = new TranscoderInput(new StringReader(
formattedSvg));
TranscoderOutput output = new TranscoderOutput(
resp.getOutputStream());
t.transcode(input, output);
}
} catch (TranscoderException e) {
resp.sendError(500, e.getMessage());
}
} else if (transformto != null && transformto.equals(TO_SVG)) {
storeInRepository(uuid, rawSvg, transformto, processid, repository);
} else if (transformto != null && transformto.equals(JPDL_TO_BPMN2)) {
try {
String bpmn2 = JbpmMigration.transform(jpdl);
Definitions def = ((JbpmProfileImpl) profile).getDefinitions(bpmn2);
// add bpmndi info to Definitions with help of gpd
addBpmnDiInfo(def, gpd);
// hack for now
revisitSequenceFlows(def, bpmn2);
// another hack if id == name
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) {
e.printStackTrace();
_logger.error(e.getMessage());