Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Image from MIME encoded database record
Image from MIME encoded database record [message #804056] Wed, 22 February 2012 01:18 Go to next message
Guy Wittig is currently offline Guy Wittig
Messages: 2
Registered: February 2012
Junior Member
Hi

I am trying to create a report that includes an image that is pulled from a database as a mime encoded string (image/svg+xml)

It appears vaguely possible but I can't really find any way to do this on the BIRT report designer, e.g. I can add an image, bind it to the database column (as a string), but can't seem to find a way to set BIRT to interpret the string as a mime encoded image.

Can anyone point me in the right direction ?

Thanks

Guy
Re: Image from MIME encoded database record [message #804433 is a reply to message #804056] Wed, 22 February 2012 11:11 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

Can you post an example of what one of the strings looks like?
If it is base64 data you could set the image type to dynamic and then
use an oncreate script like:

importPackage(Packages.javax.imageio);
importPackage(Packages.java.io);
importPackage(Packages.sun.misc);
decoder = new BASE64Decoder();
decodedBytes =
decoder.decodeBuffer(this.getRowData().getColumnValue("Base64imagedata"));
this.data =decodedBytes;
bais = new ByteArrayInputStream( decodedBytes);
bufimg = ImageIO.read(bais);
this.setHeight(bufimg.getHeight() +"px");
this.setWidth(bufimg.getWidth() +"px");

Jason

On 2/22/2012 1:18 AM, Guy Wittig wrote:
> Hi
>
> I am trying to create a report that includes an image that is pulled
> from a database as a mime encoded string (image/svg+xml)
>
> It appears vaguely possible but I can't really find any way to do this
> on the BIRT report designer, e.g. I can add an image, bind it to the
> database column (as a string), but can't seem to find a way to set BIRT
> to interpret the string as a mime encoded image.
> Can anyone point me in the right direction ?
>
> Thanks
>
> Guy
Re: Image from MIME encoded database record [message #804802 is a reply to message #804433] Wed, 22 February 2012 21:29 Go to previous messageGo to next message
Guy Wittig is currently offline Guy Wittig
Messages: 2
Registered: February 2012
Junior Member
Jason,

thanks for your reply, good hint, do it in code ...

The string is of the form "H4sIAAAAAAAAC+y9aXMcSXIm/F ....... Thx+FOzZGV1hw0ozqLmEbrGs4WNaG" it is about 100kbytes long.

It appears to be "GZip + Base64" Mime encoded, and has a Mime type "image/svg+xml". That is what is stored in other database columns for this record.

The class BASE64Decoder() is in the sun.misc library. I have tried to get this working using the org.apache.commons.codec.binary.Base64 class as this is used in the deployment environment.
oncreate() is:

importPackage(Packages.javax.imageio);
importPackage(Packages.java.io);
importPackage(Packages.org.apache.commons.codec.binary);
decoder = new Base64();
decodedBytes = decoder.decode(this.getRowData().getColumnValue("MIME_DOCUMENT_CONTENTS"));
this.data =decodedBytes;



I can't seem to get it to run in the designer. Can't find the Base64 class as per error below.
I have tried adding the JAR into the project class path (Windows\Preferences\Report Design\Classpath and tried adding it into the BIRT script lib directory. Still does not seem to be able to find the class.

Any ideas?



>>>> Compiled Source: /report/body/image[@id="1947"]/method[@name="onCreate"]
importPackage(Packages.javax.imageio);
importPackage(Packages.java.io);
importPackage(Packages.org.apache.commons.codec.binary);

decoder = new Base64();
decodedBytes = decoder.decode(this.getRowData().getColumnValue("MIME_DOCUMENT_CONTENTS"));
this.data =decodedBytes;
>>>> end compilation.
>>>> Frame Source Name: /report/body/image[@id="1947"]/method[@name="onCreate"]
>>>> Frame Function Name:
>>>> Enter script. 1
>>>> Line changed to: 1
>>>> Line changed to: 2
>>>> Line changed to: 3
>>>> Line changed to: 5
>>>> Debugger exception occured:
org.mozilla.javascript.EcmaError: ReferenceError: "Base64" is not defined.



Re: Image from MIME encoded database record [message #805427 is a reply to message #804802] Thu, 23 February 2012 14:04 Go to previous message
Jason Weathersby is currently offline Jason Weathersby
Messages: 9167
Registered: July 2009
Senior Member

You should not have to include any additional jars for the
org.apache.commons.codec.binary package. It is included with birt by
default. Create a new blank report add a data value with a dummy
expression and try the following onCreate script:

importPackage(Packages.org.apache.commons.codec.binary)
importPackage(Packages.java.lang);
var jj = new String("Hello");
var tt = Base64.encodeBase64(jj.getBytes());
ggg = Base64.decodeBase64(tt);
this.setDisplayValue(new String(ggg));


Jason

On 2/22/2012 9:29 PM, Guy Wittig wrote:
> Jason,
>
> thanks for your reply, good hint, do it in code ...
>
> The string is of the form "H4sIAAAAAAAAC+y9aXMcSXIm/F .......
> Thx+FOzZGV1hw0ozqLmEbrGs4WNaG" it is about 100kbytes long.
>
> It appears to be "GZip + Base64" Mime encoded, and has a Mime type
> "image/svg+xml". That is what is stored in other database columns for
> this record.
>
> The class BASE64Decoder() is in the sun.misc library. I have tried to
> get this working using the org.apache.commons.codec.binary.Base64 class
> as this is used in the deployment environment.
> oncreate() is:
>
> importPackage(Packages.javax.imageio);
> importPackage(Packages.java.io);
> importPackage(Packages.org.apache.commons.codec.binary);
> decoder = new Base64();
> decodedBytes =
> decoder.decode(this.getRowData().getColumnValue("MIME_DOCUMENT_CONTENTS"));
> this.data =decodedBytes;
>
>
>
> I can't seem to get it to run in the designer. Can't find the Base64
> class as per error below. I have tried adding the JAR into the project
> class path (Windows\Preferences\Report Design\Classpath and tried adding
> it into the BIRT script lib directory. Still does not seem to be able to
> find the class.
>
> Any ideas?
>
>
>
>>>>> Compiled Source:
>>>>> /report/body/image[@id="1947"]/method[@name="onCreate"]
> importPackage(Packages.javax.imageio);
> importPackage(Packages.java.io);
> importPackage(Packages.org.apache.commons.codec.binary);
>
> decoder = new Base64();
> decodedBytes =
> decoder.decode(this.getRowData().getColumnValue("MIME_DOCUMENT_CONTENTS"));
> this.data =decodedBytes;
>>>>> end compilation.
>>>>> Frame Source Name:
>>>>> /report/body/image[@id="1947"]/method[@name="onCreate"]
>>>>> Frame Function Name: Enter script. 1
>>>>> Line changed to: 1
>>>>> Line changed to: 2
>>>>> Line changed to: 3
>>>>> Line changed to: 5
>>>>> Debugger exception occured:
> org.mozilla.javascript.EcmaError: ReferenceError: "Base64" is not defined.
>
>
>
Previous Topic:Can't format default date parameter as yyyy-MM-dd
Next Topic:BIRT bar chart report shutting down weblogic server
Goto Forum:
  


Current Time: Wed Aug 20 20:40:04 EDT 2014

Powered by FUDForum. Page generated in 0.01853 seconds