Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Change the XML DataSource source data/file at runtime
kimgoodman
I am currently using an XML DataSource in my report. For a given report, I need to be able to set the underlying XML data for the DataSource once it is deployed (The same report is run for different XML input streams using the same schema).
I have been unable to find any examples of setting a DataSource's InputStream.
How should I go about doing this?
Thanks.
Kim
Find more posts tagged with
Comments
JasonW
Are you trying to change the file url?
If so use property binding or add a beforeOpen script:
here is an example propery binding expression on the data source:
//XML Data Source File Property Binding Expression
importPackage( Packages.java.io );
importPackage( Packages.javax.servlet.http );
if( reportContext.getHttpServletRequest().getAttribute("attributeBean").isDesigner() ){
"C:\\xfer\\company.xml";
}else{
var rp = reportContext.getHttpServletRequest().getSession().getServletContext().getRealPath("/Report");
"file:///"+rp+"/company.xml";
}
If you want to change the actual stream you can do this in a beforeOpen script on the data set like:
importPackage( Packages.java.io );
var mystr = "<?xml version=\"1.0\"?>";
mystr = mystr + "<library>";
mystr = mystr + "<book category=\"COOKING\">";
mystr = mystr + "<title lang=\"en\">The test3 Cook Book</title>";
mystr = mystr + "<author name=\"Miguel Ortiz\" country=\"es\"/>";
mystr = mystr + "<sold>10,312</sold>";
mystr = mystr + "<year>2005</year>";
mystr = mystr + "</book>";
mystr = mystr + "<book category=\"CHILDREN\">";
mystr = mystr + "<title lang=\"en\">Everyone is Super Special</title>";
mystr = mystr + "<author name=\"Sally Bush\" country=\"uk\"/>";
mystr = mystr + "<sold>8,222</sold>";
mystr = mystr + "<year>2005</year>";
mystr = mystr + "</book>";
mystr = mystr + "<book category=\"AUTOBIOGRAPHY\">";
mystr = mystr + "<title lang=\"en\">Japanese Greetings</title>";
mystr = mystr + "<author name=\"Taro Yamada\" country=\"uk\"/>";
mystr = mystr + "<sold>7,852</sold>";
mystr = mystr + "<year>2005</year>";
mystr = mystr + "</book>";
mystr = mystr + "<book category=\"WEB\">";
mystr = mystr + "<title lang=\"en\">Query Kick End</title>";
mystr = mystr + "<author name=\"James McGovern\" country=\"us\"/>";
mystr = mystr + "<sold>15,111</sold>";
mystr = mystr + "<year>2006</year>";
mystr = mystr + "</book>";
mystr = mystr + "<audio format=\"CD\" category=\"MUSIC\">";
mystr = mystr + "<title lang=\"en\">Feels Like Home</title>";
mystr = mystr + "<artist name=\"Norah Jones\" country=\"us\"/>";
mystr = mystr + "<sold>9,675</sold>";
mystr = mystr + "<year>2005</year>";
mystr = mystr + "</audio>";
mystr = mystr +"</library>";
JavaStr = new java.lang.String( mystr );
bais = new ByteArrayInputStream( JavaStr.getBytes());
appcon = reportContext.getAppContext();
appcon.put("org.eclipse.datatools.enablement.oda.xml.inputStream", bais);
Jason