blob: fb5ff493fda92f63885ac61c142544b9cb81f2c9 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.xtext.reportdsl.common;
import java.io.UnsupportedEncodingException;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;
import org.eclipse.birt.report.engine.api.IImage;
import org.eclipse.birt.report.model.api.elements.DesignChoiceConstants;
import org.eclipse.birt.report.model.api.elements.structures.EmbeddedImage;
public class HTMLServerEmbeddedImageHandler extends HTMLServerImageHandler{
protected String handleImage(IImage image, Object context,
String prefix, boolean needMap) {
String[] splittedID = image.getID().split("\\.");
String imageId = splittedID.length > 0 ? splittedID[0] : "";
if (imageId.equals(DesignChoiceConstants.IMAGE_REF_TYPE_EMBED)){
byte[] data = Base64.encodeBase64(image.getImageData());
String value = "";
if ( data != null )
try {
value = new String( data, EmbeddedImage.CHARSET );
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "data:" + image.getMimeType() + ";base64," + value;
}
return super.handleImage(image, context, prefix, needMap);
}
}