Display of Image Using Scripted Data Source [message #553825] |
Thu, 19 August 2010 05:36 |
N kumar Messages: 5 Registered: August 2010 |
Junior Member |
|
|
Hi,
I am creating a scripted data source and the scripted data set.and writing a java class in which i am writing a method which is returning the BLOB object as
class Abc
{
Blob getBlob()
{
//getting th blob object from data base....
}
}
now in data set i m creating a data coulmn as BlobImage whose data type is Blob.
in open method i m just creating a object of the abc class by importing as
importPackage (Packages.com.abc.test); //according to package
obj =new Abc();
on fetch method
I m calling the method .as
row["BlobImage"]=obj.getBlob();
and all condition's are right and when i m seeing the peview in data set of outputcoulmn it's showing some binary data as of blob in data base.
and when i m binding this coulmn to Image dynamically it's not displaying the Image.As by dragging the image contoll on rptdesign and then by assigning a image dynamically to image control.
Please reply for this as soon as posible.
Thanks in Advance..
[Updated on: Thu, 19 August 2010 09:41] Report message to a moderator
|
|
|
Re: Display of Image Using Scripted Data Source [message #553990 is a reply to message #553825] |
Thu, 19 August 2010 15:15 |
|
Can you try changing this line:
row["BlobImage"]=obj.getBlob();
to
row["BlobImage"]=obj.getBlob().getBytes();
I am attaching one I did in script.
Jason
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.21"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version
2.5.2.v20100208 Build <2.5.2.v20100210-0630></property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<property name="bidiLayoutOrientation">ltr</property>
<property name="imageDPI">96</property>
<data-sources>
<script-data-source name="Data Source" id="8"/>
</data-sources>
<data-sets>
<script-data-set name="Data Set" id="9">
<list-property name="resultSetHints">
<structure>
<property name="position">0</property>
<property name="name">col1</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">1</property>
<property name="name">col2</property>
<property name="dataType">blob</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">col1</property>
</structure>
<structure>
<property name="columnName">col2</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">col1</property>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">col2</property>
<property name="dataType">blob</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<method name="open"><![CDATA[i=0;]]></method>
<method name="fetch"><![CDATA[if( i > 0 ){
return false;
}
i++;
importPackage(Packages.java.io);
importPackage(Packages.java.lang);
var file = new File("C:/work/oldblogs/highlightstyle.PNG");
var ist = new FileInputStream(file);
var lengthi = file.length();
bytesa = new ByteArrayOutputStream( lengthi);
var c;
while((c=ist.read()) != -1){
bytesa.write(c);
}
ist.close();
var myblob = bytesa.toByteArray();
row["col1"] = i;
row["col2"] = myblob;
return true;
]]></method>
</script-data-set>
</data-sets>
<styles>
<style name="report" id="4">
<property name="fontFamily">sans-serif</property>
<property name="fontSize">10pt</property>
</style>
<style name="crosstab-cell" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab" id="6">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property
name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<image id="10">
<property name="dataSet">Data Set</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">col1</property>
<expression name="expression"
type="javascript">dataSetRow["col1"]</expression>
<property name="dataType">integer</property>
</structure>
<structure>
<property name="name">col2</property>
<expression name="expression"
type="javascript">dataSetRow["col2"]</expression>
<property name="dataType">blob</property>
</structure>
</list-property>
<property name="source">expr</property>
<expression name="valueExpr">row["col2"]</expression>
</image>
</body>
</report>
On 8/19/2010 1:36 AM, N kumar wrote:
> Hi,
> I am creating a scripted data source and the scripted data set.and
> writing a java class in which i am writing a method which is returning
> the BLOB object as
>
> class Abc
> {
> Blob getBlob()
> {
> //getting th blob object from data base....
> }
>
> }
>
> now in data set i m creating a data coulmn as BlobImage whose data type
> is Blob. in open method i m just creating a object of the abc class by
> importing as
> importPackage (Packages.com.abc.test); //according to package
>
> obj =new Abc();
>
>
> on fetch method
> I m calling the method .as
> row["BlobImage"]=obj.getBlob();
>
> and all condition's are right and when i m seeing the peview in data set
> of outputcoulmn it's showing some binary data as of blob in data base.
> and when i m binding this coulmn to Image dynamically it's not
> displaying the Image.As by dragging the image contoll on rptdesign and
> then by assigning a image dynamically to image control.
>
> Please reply for this as soon as posible.
> Thanks in Advance..
|
|
|
|
Re: Display of Image Using Scripted Data Source [message #554237 is a reply to message #554082] |
Fri, 20 August 2010 17:14 |
|
Did you try my sample? Did you get it to work?
What full package name is the Blob type?
Jason
On 8/20/2010 2:02 AM, N kumar wrote:
> HI Jason,
> Thanks for ur reply.I had tried in both way.
> But still it's not working.
> As first way.
>
>
> public byte[] getBlobImage()
> { // code for getting BLob Image converting into bytes as:
> BlobImage.getBytes(1,(int) BlobImage.length());
> }
> for
> this i wrote in fetch method as
>
> row["BlobImage"]= readerClass.getBlobImage();
>
> in 2nd way also:
>
> public Blob getBlobImage()
> {
> // code for fetching the blob image......
> }
>
> in the fetch method of data set i m writing this code:
> var blob =readerClass.getBlobImage();
> row["BlobImage"]= blob.getBytes(1,(int) BlobImage.length());
>
>
> in preview of data set its showing binary values but when i n preview of
> rptdesign it's showing BIRT Exception.
>
>
> Root Cause of that exception is NULL POINTER Exception
> at this line Caused by: org.eclipse.birt.data.engine.core.DataException:
> data.engine.BadFetchScriptReturnType at
> org.eclipse.birt.report.engine.script.internal.ScriptDataSet
> ScriptExecutor.handleFetch(ScriptDataSetScriptExecutor.java: 129) ... 99
> more
>
>
>
> full exception as:
>
> Caused by: org.eclipse.birt.data.engine.core.DataException: A BIRT
> exception occurred: There are errors evaluating script
> "__bm_FETCH()":Wrapped java.lang.NullPointerException (<inline>#26)..
> See next exception for more information.There are errors evaluating
> script "__bm_FETCH()":Wrapped java.lang.NullPointerException
> (<inline>#26). at
> org.eclipse.birt.data.engine.core.DataException.wrap(DataExc
> eption.java:118) at
> org.eclipse.birt.data.engine.script.ScriptEvalUtil.evaluateJ
> SAsExpr(ScriptEvalUtil.java:717) at
> org.eclipse.birt.data.engine.script.JSMethodRunner.runScript
> (JSMethodRunner.java:76) at
> org.eclipse.birt.report.engine.script.internal.DtEScriptExec
> utor.handleJS(DtEScriptExecutor.java:71) ... 101 moreCaused by:
> org.eclipse.birt.core.exception.CoreException: There are errors
> evaluating script "__bm_FETCH()":Wrapped java.lang.NullPointerException
> (<inline>#26). at
> org.eclipse.birt.core.script.ScriptContext.eval(ScriptContex t.java:307)
> at org.eclipse.birt.core.script.ScriptContext.eval(ScriptContex
> t.java:268) at
> org.eclipse.birt.data.engine.script.ScriptEvalUtil.evaluateJ
> SAsExpr(ScriptEvalUtil.java:713) ... 103 moreCaused by:
> org.mozilla.javascript.WrappedException: Wrapped
> java.lang.NullPointerException (<inline>#26) at
> org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Contex
> t.java:1757) at
> org.mozilla.javascript.MemberBox.invoke(MemberBox.java:170) at
> org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMetho d.java:243)
> at org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRun
> time.java:119) at org.mozilla.javascript.gen.c195._c1(<inline>:26) at
> org.mozilla.javascript.gen.c195.call(<inline>) at
> org.mozilla.javascript.optimizer.OptRuntime.callName0(OptRun
> time.java:108) at org.mozilla.javascript.gen.c196._c0(<inline>:1) at
> org.mozilla.javascript.gen.c196.call(<inline>) at
> org.mozilla.javascript.ContextFactory.doTopCall(ContextFacto
> ry.java:393) at
> org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime .java:2834)
> at org.mozilla.javascript.gen.c196.call(<inline>) at
> org.mozilla.javascript.gen.c196.exec(<inline>) at
> org.eclipse.birt.core.script.ScriptContext.eval(ScriptContex t.java:302)
> ... 105 moreCaused by: java.lang.NullPointerException at
> com.vue.birt.data.ItemDetailsDataSource.getBlobImage(ItemDet
> ailsDataSource.java:276) at
> sun.reflect.GeneratedMethodAccessor42.invoke(Unknown Source) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe
> thodAccessorImpl.java:25) at
> java.lang.reflect.Method.invoke(Method.java:597) at
> org.mozilla.javascript.MemberBox.invoke(MemberBox.java:155) ... 117 more
>
> please reply me.......
> it's bug or my code fault to fetch the blob object from MSSQL server i m
> using this
>
> DRIVER net.sourceforge.jtds.jdbc.Driver
>
> Regards,
> N Kumar
|
|
|
|
Re: Display of Image Using Scripted Data Source [message #554603 is a reply to message #554478] |
Mon, 23 August 2010 16:34 |
|
can you send me your code? I know the default image control has no
problem with a blob type. The classic models db has a blob image in it.
Take a look at this report.
Jason
<?xml version="1.0" encoding="UTF-8"?>
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.16"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version
2.3.0.v20080606 Build <2.3.0.v20080618-0630></property>
<property name="units">in</property>
<property name="iconFile">/templates/blank_report.gif</property>
<data-sources>
<oda-data-source
extensionID="org.eclipse.birt.report.data.oda.jdbc" name="Data Source"
id="6">
<property
name="odaDriverClass">org.eclipse.birt.report.data.oda.sampledb.Driver </property>
<property name="odaURL">jdbc:classicmodels:sampledb</property>
<property name="odaUser">ClassicModels</property>
<property name="OdaConnProfileName"></property>
</oda-data-source>
</data-sources>
<data-sets>
<oda-data-set
extensionID="org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet "
name="Data Set" id="7">
<list-property name="columnHints">
<structure>
<property name="columnName">PRODUCTLINE</property>
<property name="displayName">PRODUCTLINE</property>
</structure>
<structure>
<property name="columnName">TEXTDESCRIPTION</property>
<property name="displayName">TEXTDESCRIPTION</property>
</structure>
<structure>
<property name="columnName">HTMLDESCRIPTION</property>
<property name="displayName">HTMLDESCRIPTION</property>
</structure>
<structure>
<property name="columnName">IMAGE</property>
<property name="displayName">IMAGE</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">PRODUCTLINE</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">TEXTDESCRIPTION</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">HTMLDESCRIPTION</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">IMAGE</property>
<property name="dataType">blob</property>
</structure>
</list-property>
</structure>
<property name="dataSource">Data Source</property>
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">PRODUCTLINE</property>
<property name="nativeName">PRODUCTLINE</property>
<property name="dataType">string</property>
<property name="nativeDataType">12</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">TEXTDESCRIPTION</property>
<property name="nativeName">TEXTDESCRIPTION</property>
<property name="dataType">string</property>
<property name="nativeDataType">12</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">HTMLDESCRIPTION</property>
<property name="nativeName">HTMLDESCRIPTION</property>
<property name="dataType">string</property>
<property name="nativeDataType">2005</property>
</structure>
<structure>
<property name="position">4</property>
<property name="name">IMAGE</property>
<property name="nativeName">IMAGE</property>
<property name="dataType">blob</property>
<property name="nativeDataType">2004</property>
</structure>
</list-property>
<property name="queryText">select *
from productlines</property>
<xml-property name="designerValues"><![CDATA[<?xml
version="1.0" encoding="UTF-8"?>
<model:DesignValues
xmlns:design="http://www.eclipse.org/datatools/connectivity/oda/design"
xmlns:model="http://www.eclipse.org/birt/report/model/adapter/odaModel">
<Version>1.0</Version>
<design:ResultSets derivedMetaData="true">
<design:resultSetDefinitions>
<design:resultSetColumns>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>PRODUCTLINE</design:name>
<design:position>1</design:position>
<design:nativeDataTypeCode>12</design:nativeDataTypeCode>
<design:precision>50</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>PRODUCTLINE</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>PRODUCTLINE</design:label>
<design:formattingHints>
<design:displaySize>50</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>TEXTDESCRIPTION</design:name>
<design:position>2</design:position>
<design:nativeDataTypeCode>12</design:nativeDataTypeCode>
<design:precision>4000</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>TEXTDESCRIPTION</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>TEXTDESCRIPTION</design:label>
<design:formattingHints>
<design:displaySize>4000</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>HTMLDESCRIPTION</design:name>
<design:position>3</design:position>
<design:nativeDataTypeCode>2005</design:nativeDataTypeCode >
<design:precision>2147483647</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>HTMLDESCRIPTION</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>HTMLDESCRIPTION</design:label>
<design:formattingHints>
<design:displaySize>2147483647</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
<design:resultColumnDefinitions>
<design:attributes>
<design:name>IMAGE</design:name>
<design:position>4</design:position>
<design:nativeDataTypeCode>2004</design:nativeDataTypeCode >
<design:precision>2147483647</design:precision>
<design:scale>0</design:scale>
<design:nullability>Nullable</design:nullability>
<design:uiHints>
<design:displayName>IMAGE</design:displayName>
</design:uiHints>
</design:attributes>
<design:usageHints>
<design:label>IMAGE</design:label>
<design:formattingHints>
<design:displaySize>2147483647</design:displaySize>
</design:formattingHints>
</design:usageHints>
</design:resultColumnDefinitions>
</design:resultSetColumns>
</design:resultSetDefinitions>
</design:ResultSets>
</model:DesignValues>]]></xml-property>
</oda-data-set>
</data-sets>
<styles>
<style name="crosstab" id="4">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="crosstab-cell" id="5">
<property name="borderBottomColor">#CCCCCC</property>
<property name="borderBottomStyle">solid</property>
<property name="borderBottomWidth">1pt</property>
<property name="borderLeftColor">#CCCCCC</property>
<property name="borderLeftStyle">solid</property>
<property name="borderLeftWidth">1pt</property>
<property name="borderRightColor">#CCCCCC</property>
<property name="borderRightStyle">solid</property>
<property name="borderRightWidth">1pt</property>
<property name="borderTopColor">#CCCCCC</property>
<property name="borderTopStyle">solid</property>
<property name="borderTopWidth">1pt</property>
</style>
<style name="table-header" id="38">
<property name="backgroundColor">#6078BF</property>
<property name="fontFamily">"Arial"</property>
<property name="fontSize">small</property>
<property name="fontWeight">bold</property>
<property name="color">#FFFFFF</property>
<property name="paddingTop">0px</property>
<property name="paddingLeft">0px</property>
<property name="paddingBottom">0px</property>
<property name="paddingRight">0px</property>
</style>
<style name="table-footer" id="39">
<property name="backgroundColor">#6078BF</property>
<property name="fontFamily">"Arial"</property>
<property name="fontSize">small</property>
<property name="fontWeight">bold</property>
<property name="color">#FFFFFF</property>
<property name="paddingTop">0px</property>
<property name="paddingLeft">0px</property>
<property name="paddingBottom">0px</property>
<property name="paddingRight">0px</property>
</style>
<style name="table-detail" id="40">
<property name="backgroundColor">#E6ECFF</property>
<property name="fontFamily">"Arial"</property>
<property name="fontSize">x-small</property>
<property name="fontWeight">bold</property>
<property name="color">#000080</property>
<property name="paddingTop">0px</property>
<property name="paddingLeft">0px</property>
<property name="paddingBottom">0px</property>
<property name="paddingRight">0px</property>
</style>
<style name="table-group-header-1" id="41">
<property name="backgroundColor">#809FFF</property>
<property name="fontFamily">"Arial"</property>
<property name="fontSize">small</property>
<property name="fontWeight">bold</property>
<property name="color">#FFFFFF</property>
<property name="paddingTop">0px</property>
<property name="paddingLeft">0px</property>
<property name="paddingBottom">0px</property>
<property name="paddingRight">0px</property>
</style>
<style name="table-group-footer-1" id="42">
<property name="backgroundColor">#809FFF</property>
<property name="fontFamily">"Arial"</property>
<property name="fontSize">small</property>
<property name="fontWeight">bold</property>
<property name="color">#FFFFFF</property>
<property name="paddingTop">0px</property>
<property name="paddingLeft">0px</property>
<property name="paddingBottom">0px</property>
<property name="paddingRight">0px</property>
</style>
<style name="special-header" id="43">
<property name="backgroundColor">#6078BF</property>
<property name="fontFamily">"Arial"</property>
<property name="fontSize">medium</property>
<property name="fontWeight">bold</property>
<property name="color">#FFFFFF</property>
<property name="paddingTop">0px</property>
<property name="paddingLeft">0px</property>
<property name="paddingBottom">0px</property>
<property name="paddingRight">0px</property>
</style>
</styles>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<page-header>
<image id="48">
<property name="source">file</property>
<expression name="uri">"cmlogo.png"</expression>
</image>
</page-header>
<page-footer>
<text id="3">
<property name="contentType">html</property>
<text-property
name="content"><![CDATA[<value-of>new Date()</value-of>]]></text-property>
</text>
</page-footer>
</simple-master-page>
</page-setup>
<body>
<table id="8">
<property name="width">7in</property>
<property name="dataSet">Data Set</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">PRODUCTLINE</property>
<property name="displayName">PRODUCTLINE</property>
<expression
name="expression">dataSetRow["PRODUCTLINE"]</expression >
<property name="dataType">string</property>
</structure>
<structure>
<property name="name">TEXTDESCRIPTION</property>
<property name="displayName">TEXTDESCRIPTION</property>
<expression
name="expression">dataSetRow["TEXTDESCRIPTION"]</expression >
<property name="dataType">string</property>
</structure>
<structure>
<property name="name">HTMLDESCRIPTION</property>
<property name="displayName">HTMLDESCRIPTION</property>
<expression
name="expression">dataSetRow["HTMLDESCRIPTION"]</expression >
<property name="dataType">string</property>
</structure>
<structure>
<property name="name">IMAGE</property>
<property name="displayName">IMAGE</property>
<expression
name="expression">dataSetRow["IMAGE"]</expression>
<property name="dataType">blob</property>
</structure>
</list-property>
<column id="34"/>
<column id="35"/>
<header>
<row id="44">
<cell id="45">
<property name="colSpan">2</property>
<property name="rowSpan">1</property>
<label id="47">
<property name="fontSize">x-large</property>
<property name="textAlign">center</property>
<text-property name="text">Product
LInes</text-property>
</label>
</cell>
</row>
</header>
<detail>
<row id="18">
<list-property name="highlightRules">
<structure>
<property name="operator">eq</property>
<property
name="backgroundColor">#FFFFFF</property>
<expression
name="testExpr">row.__rownum%2</expression>
<simple-property-list name="value1">
<value>0</value>
</simple-property-list>
</structure>
</list-property>
<cell id="23">
<text-data id="36">
<expression
name="bookmark">row["PRODUCTLINE"]</expression>
<expression
name="valueExpr">row["HTMLDESCRIPTION"]</expression>
<property name="contentType">html</property>
</text-data>
</cell>
<cell id="25">
<property name="textAlign">center</property>
<image id="37">
<property
name="borderBottomColor">#004080</property>
<property
name="borderBottomStyle">solid</property>
<property
name="borderBottomWidth">medium</property>
<property
name="borderLeftColor">#004080</property>
<property
name="borderLeftStyle">solid</property>
<property
name="borderLeftWidth">medium</property>
<property
name="borderRightColor">#004080</property>
<property
name="borderRightStyle">solid</property>
<property
name="borderRightWidth">medium</property>
<property
name="borderTopColor">#004080</property>
<property
name="borderTopStyle">solid</property>
<property
name="borderTopWidth">medium</property>
<property name="source">expr</property>
<expression
name="valueExpr">row["IMAGE"]</expression>
</image>
</cell>
</row>
</detail>
<footer>
<row id="27">
<cell id="30"/>
<cell id="31"/>
</row>
</footer>
</table>
</body>
</report>
On 8/23/2010 7:12 AM, N kumar wrote:
> Sorry For Late reply.
> i was on leave....
> I had tried that also..
> That is working fine.
>
> All Code is for same image.
>
> But from DB it's not working i donot know y it's not working.
>
> This is the format in preview of dataset i am gettinng from ur code
>
> col1 col2
> 1 FFFFFF89 50 4E 47 D A 1A A ...
>
>
> and preview of dataset i am gettinng from DB is.......
>
> BlobImage
> FFFFFF89 50 4E 47 D A 1A A ...
>
> NOW i tried ur Code by writing into my class
> as
>
> Class Test
> {
> public byte[] getBlobImageFromFile()
> {
> File file = new File("D:/desktop/images/00339370354254.PNG");
> FileInputStream ist=null;
> try {
> ist = new FileInputStream(file);
> } catch (FileNotFoundException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
> int lengthi = (int) file.length();
>
> ByteArrayOutputStream bytesa = new ByteArrayOutputStream( lengthi);
> int c;
> try {
> while((c=ist.read()) != -1){
> bytesa.write(c);
> }
> } catch (IOException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> } try {
> ist.close();
> } catch (IOException e1) {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
> byte [] myblob = bytesa.toByteArray();
>
>
> return myblob;
> }
> }
>
>
> in java class
> ro
> in fetch method row["BlobImage"]= readerClass.getBlobImageFromFile();
> in this way i m getting the result preview also i m getting.
>
> but from DB i m not getting any preview.
> No error i am getting. in the preview of Report.
> Can u try it..............
|
|
|
|
Re: Display of Image Using Scripted Data Source [message #555183 is a reply to message #555135] |
Wed, 25 August 2010 18:09 |
|
In the sample report you posted here you need to delete the bindings you
have on the image. Select the image, then the binding tab and select
none from the drop down. Leave the binding on the table. I did this
with your sample and it worked.
Jason
On 8/25/2010 10:34 AM, N kumar wrote:
> Hi Jason,
> Thanks for ur reply.
> i am copying the rptdesign and java class both for scripted data
> source.........
> ///////////////////////////////
> RPTDESIGN
> ////////////////////////////////////////////////////////////
> //////////////////////////////////////////////
> <?xml version="1.0" encoding="UTF-8"?>
> <report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.17"
> id="1">
> <property name="createdBy">Eclipse BIRT Designer Version
> 2.3.2.r232_v20090521 Build <2.3.2.v20090601-0700></property>
> <property name="units">in</property>
> <property name="iconFile">/templates/blank_report.gif</property>
> <data-sources>
> <script-data-source name="Scripted Data Source" id="49"/>
> </data-sources>
> <data-sets>
> <script-data-set name="Data Set1" id="50">
> <list-property name="resultSetHints">
> <structure>
> <property name="position">1</property>
> <property name="name">IMAGE</property>
> <property name="dataType">blob</property>
> </structure>
> <structure>
> <property name="position">2</property>
> <property name="name">HTMLDESCRIPTION</property>
> <property name="dataType">string</property>
> </structure>
> <structure>
> <property name="position">3</property>
> <property name="name">PRODUCTLINE</property>
> <property name="dataType">string</property>
> </structure>
> <structure>
> <property name="position">4</property>
> <property name="name">TEXTDESCRIPTION</property>
> <property name="dataType">string</property>
> </structure>
> </list-property>
> <list-property name="columnHints">
> <structure>
> <property name="columnName">IMAGE</property>
> </structure>
> <structure>
> <property name="columnName">HTMLDESCRIPTION</property>
> </structure>
> <structure>
> <property name="columnName">PRODUCTLINE</property>
> </structure>
> <structure>
> <property name="columnName">TEXTDESCRIPTION</property>
> </structure>
> </list-property>
> <structure name="cachedMetaData">
> <list-property name="resultSet">
> <structure>
> <property name="position">1</property>
> <property name="name">IMAGE</property>
> <property name="dataType">blob</property>
> </structure>
> <structure>
> <property name="position">2</property>
> <property name="name">HTMLDESCRIPTION</property>
> <property name="dataType">string</property>
> </structure>
> <structure>
> <property name="position">3</property>
> <property name="name">PRODUCTLINE</property>
> <property name="dataType">string</property>
> </structure>
> <structure>
> <property name="position">4</property>
> <property name="name">TEXTDESCRIPTION</property>
> <property name="dataType">string</property>
> </structure>
> </list-property>
> </structure>
> <property name="dataSource">Scripted Data Source</property>
> <method name="open"><![CDATA[
> importPackage (Packages.test);
> readerClass = new Abc();
> readerClass.populateFromDB("D:/projects/test");
> ]]></method>
> <method name="fetch"><![CDATA[
> // Set field values for the current row
>
> if( readerClass.hasnext() == false)
> return false;
> row["HTMLDESCRIPTION"]= readerClass.getData(readerClass.HTML_INDEX);
> row["IMAGE"]=readerClass.getImage();
> row["TEXTDESCRIPTION"]=readerClass.getData(readerClass.TEXT_INDEX);
> row["PRODUCTLINE"]=readerClass.getData(readerClass.PRODUCT_INDEX);
>
>
>
>
>
> return true;
> ]]></method>
> <method name="close"><![CDATA[readerClass=null;]]></method>
> </script-data-set>
> </data-sets>
> <styles>
> <style name="crosstab" id="4">
> <property name="borderBottomColor">#CCCCCC</property>
> <property name="borderBottomStyle">solid</property>
> <property name="borderBottomWidth">1pt</property>
> <property name="borderLeftColor">#CCCCCC</property>
> <property name="borderLeftStyle">solid</property>
> <property name="borderLeftWidth">1pt</property>
> <property name="borderRightColor">#CCCCCC</property>
> <property name="borderRightStyle">solid</property>
> <property name="borderRightWidth">1pt</property>
> <property name="borderTopColor">#CCCCCC</property>
> <property name="borderTopStyle">solid</property>
> <property name="borderTopWidth">1pt</property>
> </style>
> <style name="crosstab-cell" id="5">
> <property name="borderBottomColor">#CCCCCC</property>
> <property name="borderBottomStyle">solid</property>
> <property name="borderBottomWidth">1pt</property>
> <property name="borderLeftColor">#CCCCCC</property>
> <property name="borderLeftStyle">solid</property>
> <property name="borderLeftWidth">1pt</property>
> <property name="borderRightColor">#CCCCCC</property>
> <property name="borderRightStyle">solid</property>
> <property name="borderRightWidth">1pt</property>
> <property name="borderTopColor">#CCCCCC</property>
> <property name="borderTopStyle">solid</property>
> <property name="borderTopWidth">1pt</property>
> </style>
> <style name="table-header" id="38">
> <property name="backgroundColor">#6078BF</property>
> <property name="fontFamily">"Arial"</property>
> <property name="fontSize">small</property>
> <property name="fontWeight">bold</property>
> <property name="color">#FFFFFF</property>
> <property name="paddingTop">0px</property>
> <property name="paddingLeft">0px</property>
> <property name="paddingBottom">0px</property>
> <property name="paddingRight">0px</property>
> </style>
> <style name="table-footer" id="39">
> <property name="backgroundColor">#6078BF</property>
> <property name="fontFamily">"Arial"</property>
> <property name="fontSize">small</property>
> <property name="fontWeight">bold</property>
> <property name="color">#FFFFFF</property>
> <property name="paddingTop">0px</property>
> <property name="paddingLeft">0px</property>
> <property name="paddingBottom">0px</property>
> <property name="paddingRight">0px</property>
> </style>
> <style name="table-detail" id="40">
> <property name="backgroundColor">#E6ECFF</property>
> <property name="fontFamily">"Arial"</property>
> <property name="fontSize">x-small</property>
> <property name="fontWeight">bold</property>
> <property name="color">#000080</property>
> <property name="paddingTop">0px</property>
> <property name="paddingLeft">0px</property>
> <property name="paddingBottom">0px</property>
> <property name="paddingRight">0px</property>
> </style>
> <style name="table-group-header-1" id="41">
> <property name="backgroundColor">#809FFF</property>
> <property name="fontFamily">"Arial"</property>
> <property name="fontSize">small</property>
> <property name="fontWeight">bold</property>
> <property name="color">#FFFFFF</property>
> <property name="paddingTop">0px</property>
> <property name="paddingLeft">0px</property>
> <property name="paddingBottom">0px</property>
> <property name="paddingRight">0px</property>
> </style>
> <style name="table-group-footer-1" id="42">
> <property name="backgroundColor">#809FFF</property>
> <property name="fontFamily">"Arial"</property>
> <property name="fontSize">small</property>
> <property name="fontWeight">bold</property>
> <property name="color">#FFFFFF</property>
> <property name="paddingTop">0px</property>
> <property name="paddingLeft">0px</property>
> <property name="paddingBottom">0px</property>
> <property name="paddingRight">0px</property>
> </style>
> <style name="special-header" id="43">
> <property name="backgroundColor">#6078BF</property>
> <property name="fontFamily">"Arial"</property>
> <property name="fontSize">medium</property>
> <property name="fontWeight">bold</property>
> <property name="color">#FFFFFF</property>
> <property name="paddingTop">0px</property>
> <property name="paddingLeft">0px</property>
> <property name="paddingBottom">0px</property>
> <property name="paddingRight">0px</property>
> </style>
> </styles>
> <page-setup>
> <simple-master-page name="Simple MasterPage" id="2">
> <page-header>
> <image id="48">
> <property name="source">file</property>
> <expression name="uri">"cmlogo.png"</expression>
> </image>
> </page-header>
> <page-footer>
> <text id="3">
> <property name="contentType">html</property>
> <text-property name="content"><![CDATA[<value-of>new
> Date()</value-of>]]></text-property>
> </text>
> </page-footer>
> </simple-master-page>
> </page-setup>
> <body>
> <table id="8">
> <property name="height">1.0833333333333333in</property>
> <property name="width">6in</property>
> <property name="dataSet">Data Set1</property>
> <list-property name="boundDataColumns">
> <structure>
> <property name="name">IMAGE</property>
> <expression name="expression">dataSetRow["IMAGE"]</expression>
> <property name="dataType">blob</property>
> </structure>
> <structure>
> <property name="name">HTMLDESCRIPTION</property>
> <expression name="expression">dataSetRow["HTMLDESCRIPTION"]</expression >
> <property name="dataType">string</property>
> </structure>
> </list-property>
> <column id="34"/>
> <column id="35">
> <property name="width">2.5in</property>
> </column>
> <header>
> <row id="44">
> <cell id="45">
> <property name="colSpan">2</property>
> <property name="rowSpan">1</property>
> <label id="47">
> <property name="fontSize">x-large</property>
> <property name="textAlign">center</property>
> <text-property name="text">Product LInes</text-property>
> </label>
> </cell>
> </row>
> </header>
> <detail>
> <row id="18">
> <list-property name="highlightRules">
> <structure>
> <property name="operator">eq</property>
> <property name="backgroundColor">#FFFFFF</property>
> <expression name="testExpr">row.__rownum%2</expression>
> <simple-property-list name="value1">
> <value>0</value>
> </simple-property-list>
> </structure>
> </list-property>
> <cell id="23">
> <text-data id="36">
> <expression name="bookmark">row["PRODUCTLINE"]</expression>
> <expression name="valueExpr">row["HTMLDESCRIPTION"]</expression>
> <property name="contentType">html</property>
> </text-data>
> </cell>
> <cell id="25">
> <property name="textAlign">center</property>
> <image id="37">
> <property name="borderBottomColor">#004080</property>
> <property name="borderBottomStyle">solid</property>
> <property name="borderBottomWidth">medium</property>
> <property name="borderLeftColor">#004080</property>
> <property name="borderLeftStyle">solid</property>
> <property name="borderLeftWidth">medium</property>
> <property name="borderRightColor">#004080</property>
> <property name="borderRightStyle">solid</property>
> <property name="borderRightWidth">medium</property>
> <property name="borderTopColor">#004080</property>
> <property name="borderTopStyle">solid</property>
> <property name="borderTopWidth">medium</property>
> <property name="dataSet">Data Set1</property>
> <list-property name="boundDataColumns">
> <structure>
> <property name="name">IMAGE</property>
> <expression name="expression">dataSetRow["IMAGE"]</expression>
> <property name="dataType">blob</property>
> </structure>
> <structure>
> <property name="name">HTMLDESCRIPTION</property>
> <expression name="expression">dataSetRow["HTMLDESCRIPTION"]</expression >
> <property name="dataType">string</property>
> </structure>
> </list-property>
> <property name="source">expr</property>
> <expression name="valueExpr">row["IMAGE"]</expression>
> </image>
> </cell>
> </row>
> </detail>
> <footer>
> <row id="27">
> <cell id="30"/>
> <cell id="31"/>
> </row>
> </footer>
> </table>
> </body>
> </report>
> ////////////////////////////////////////////////////////////
> ////////////////////////////////////////////////////////////
> /////////////////////////
> JAVA class
> /////////////////////////////////////
>
> package test;
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.ResultSet;
> import java.sql.Statement;
> import java.util.ArrayList;
> import java.util.Iterator;
> import java.util.List;
> import java.util.ListIterator;
> import java.util.Vector;
>
> public class Abc {
> private List<String[]> data;
> private List<byte[]> image;
> protected int index;
> protected int maxrow;
> public static final int PRODUCT_INDEX=0;
> public static final int TEXT_INDEX=1;
> public static final int HTML_INDEX=2;
> private ListIterator<String[]> data_iterator=null;
> private ListIterator<byte[]> image_iterator=null;
> private String [] dataRow=null;
> private byte[] imageRow=null;
> public void populateFromDB(String projectpath)
> {
> data=new ArrayList<String[]>();
> image=new ArrayList<byte[]>();
> Connection con = null;
> String url = "jdbc:derby:"+projectpath+"
> /.metadata/.plugins/org.eclipse.birt.report.data.oda.jdbc.db
> profile.sampledb/db/BirtSample ";
> String driver = "org.apache.derby.jdbc.EmbeddedDriver";
> String user = "ClassicModels";
> String pass = "";
> byte[] BlobImage =null;
> try { Class.forName(driver);
> DriverManager.setLoginTimeout(10);
> //System.out.println("Connection Login Timeout : "
> +DriverManager.getLoginTimeout()+" Sec");
> con = DriverManager.getConnection(url, user, pass);
> System.out.println("Connection is created....");
> Statement stmt = con.createStatement();
> ResultSet rs = stmt.executeQuery("select * from
> ClassicModels.productlines");
> while( rs.next())
> { System.out.println("ok1");
> String []datarow=new String[3];
> datarow[PRODUCT_INDEX]=rs.getString("PRODUCTLINE");
> datarow[TEXT_INDEX]=rs.getString("TEXTDESCRIPTION");
> datarow[HTML_INDEX]=rs.getString("HTMLDESCRIPTION");
> data.add(datarow);
> image.add(rs.getBytes("IMAGE"));
> System.out.println("ok2");
> }
> rs.close();
> con.close();
> data_iterator=data.listIterator();
> image_iterator=image.listIterator();
> }
> catch (Exception e) {
> System.out.println(e);
> }
> }
> public static void main(String[] args) {
> Abc a =new Abc();
> a.populateFromDB("D:/projects/test"); ////////Project workspace
> path..............
> System.out.println("okmain");
> if(a.hasnext())
> {
> System.out.println("Data: "+ a.getData(PRODUCT_INDEX));
> }
> }
> public String getData(int rowindex)
> {
> if(null!=dataRow)
> return dataRow[rowindex];
>
> return "";
>
> }
> public byte[] getImage()
> {
> return imageRow;
> }
> public boolean hasnext()
> {
> if(null!=data && null !=image)
> {
> if(data_iterator.hasNext() && image_iterator.hasNext())
> { System.out.println("oknext");
> dataRow= data_iterator.next();
> imageRow= image_iterator.next();
> System.out.println("oknext");
> return true;
> }
> }
> return false;
> }
> }
> ////////////////////////////////////////////////////////////
> ////////////////////////////
>
> Here I am using Scripted data source and on Fetch method i am calling
> the method of java class. which is internally connecting to DB....
>
> Please try it. and then tell me what is happening..
> It will take your litle time...
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04114 seconds