Search in sources :

Example 1 with PNGTranscoder

use of org.apache.batik.transcoder.image.PNGTranscoder in project Activiti by Activiti.

the class ModelSaveRestResource method saveModel.

@RequestMapping(value = "/model/{modelId}/save", method = RequestMethod.PUT)
@ResponseStatus(value = HttpStatus.OK)
public void saveModel(@PathVariable String modelId, @RequestBody MultiValueMap<String, String> values) {
    try {
        Model model = repositoryService.getModel(modelId);
        ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
        modelJson.put(MODEL_NAME, values.getFirst("name"));
        modelJson.put(MODEL_DESCRIPTION, values.getFirst("description"));
        model.setMetaInfo(modelJson.toString());
        model.setName(values.getFirst("name"));
        repositoryService.saveModel(model);
        repositoryService.addModelEditorSource(model.getId(), values.getFirst("json_xml").getBytes("utf-8"));
        InputStream svgStream = new ByteArrayInputStream(values.getFirst("svg_xml").getBytes("utf-8"));
        TranscoderInput input = new TranscoderInput(svgStream);
        PNGTranscoder transcoder = new PNGTranscoder();
        // Setup output
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        TranscoderOutput output = new TranscoderOutput(outStream);
        // Do the transformation
        transcoder.transcode(input, output);
        final byte[] result = outStream.toByteArray();
        repositoryService.addModelEditorSourceExtra(model.getId(), result);
        outStream.close();
    } catch (Exception e) {
        LOGGER.error("Error saving model", e);
        throw new ActivitiException("Error saving model", e);
    }
}
Also used : PNGTranscoder(org.apache.batik.transcoder.image.PNGTranscoder) ActivitiException(org.activiti.engine.ActivitiException) TranscoderOutput(org.apache.batik.transcoder.TranscoderOutput) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ByteArrayInputStream(java.io.ByteArrayInputStream) TranscoderInput(org.apache.batik.transcoder.TranscoderInput) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Model(org.activiti.engine.repository.Model) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ActivitiException(org.activiti.engine.ActivitiException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with PNGTranscoder

use of org.apache.batik.transcoder.image.PNGTranscoder in project dhis2-core by dhis2.

the class SvgConversionController method convertToPng.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void convertToPng(String svg, OutputStream out) throws TranscoderException {
    svg = replaceUnsafeSvgText(svg);
    PNGTranscoder transcoder = new PNGTranscoder();
    transcoder.addTranscodingHint(ImageTranscoder.KEY_BACKGROUND_COLOR, Color.WHITE);
    TranscoderInput input = new TranscoderInput(new StringReader(svg));
    TranscoderOutput output = new TranscoderOutput(out);
    transcoder.transcode(input, output);
}
Also used : PNGTranscoder(org.apache.batik.transcoder.image.PNGTranscoder) TranscoderOutput(org.apache.batik.transcoder.TranscoderOutput) TranscoderInput(org.apache.batik.transcoder.TranscoderInput) StringReader(java.io.StringReader)

Aggregations

TranscoderInput (org.apache.batik.transcoder.TranscoderInput)2 TranscoderOutput (org.apache.batik.transcoder.TranscoderOutput)2 PNGTranscoder (org.apache.batik.transcoder.image.PNGTranscoder)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 ActivitiException (org.activiti.engine.ActivitiException)1 Model (org.activiti.engine.repository.Model)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)1