Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Iterating parameters to see what's there?
Iterating parameters to see what's there? [message #225395] Thu, 15 March 2007 13:40 Go to next message
Eclipse UserFriend
Originally posted by: dberman.tamaleresearch.com

Does anyone know how to iterate parameters (for debugging purposes)
within BIRTs scripting layer?

I made an object that lets me display output to the debugger like
MyConsole.say("Hello, World!");

Can I make a loop that does something like:
[pseudo code]

foreach (param in inputParams) {
MyConsole.say(param.name);
MyConsole.say(param.value);
}

?

It would also be able to do this for params[] to see what key value
pairs were passed into the report like you could normally do for an http
get query string.

Thanks.

David
Re: Iterating parameters to see what's there? [message #225639 is a reply to message #225395] Thu, 15 March 2007 20:30 Go to previous message
Eclipse UserFriend
Originally posted by: jasonweathersby.alltel.net

David Berman wrote:
> Does anyone know how to iterate parameters (for debugging purposes)
> within BIRTs scripting layer?
>
> I made an object that lets me display output to the debugger like
> MyConsole.say("Hello, World!");
>
> Can I make a loop that does something like:
> [pseudo code]
>
> foreach (param in inputParams) {
> MyConsole.say(param.name);
> MyConsole.say(param.value);
> }
>
> ?
>
> It would also be able to do this for params[] to see what key value
> pairs were passed into the report like you could normally do for an http
> get query string.
>
> Thanks.
>
> David
Here is an example that Scott wrote that displays information from
session including request parameters.


Also if you want specific report parameter values there is a call to get
each, but no call to get all parameters, unless you call the de api like
the following (done in the beforeFactory script).

importPackage(Packages.java.util);
importPackage(Packages.org.eclipse.birt.report.model.api);

par =
reportContext.getReportRunnable().designHandle.getDesignHand le().getAllParameters();
iter = par.iterator();
parmcount = 0;
while( iter.hasNext() ){
parm = iter.next();
if ( parm instanceof ParameterHandle ){
parmname = parm.getName();
parmval = reportContext.getParameterValue(parmname)
}
parmcount++;
}

Jason


<?xml version="1.0" encoding="UTF-8"?>
<!-- Written by Eclipse BIRT 2.0 -->
<report xmlns="http://www.eclipse.org/birt/2005/design" version="3.2.6"
id="1">
<property name="createdBy">Eclipse BIRT Designer Version 2.0.1
Build &lt;20060222-1204></property>
<property name="units">in</property>
<property name="comments">Copyright (c) 2006 Innovent Solutions,
Inc.</property>
<method name="beforeFactory"><![CDATA[// INITIALIZE THE LOGGER WITH
A FILE BASED LOGGER


importPackage(Packages.java.util);
// Create a hash table which will contain lists of other lists
var topMap = new Packages.java.util.Hashtable();


// Request Attributes
var request = reportContext.getHttpServletRequest();
var requestAttrMap = new Hashtable();
var attrNames = request.getAttributeNames();
do {
var aName = attrNames.nextElement();
requestAttrMap.put(aName, request.getAttribute(aName).toString());
} while (attrNames.hasMoreElements())
topMap.put("requestAttributes", requestAttrMap);

// Request Parameters
var requestParamMap = new Hashtable();
var paramIter = request.getParameterMap().entrySet().iterator();
do{
var entry = paramIter.next();
requestParamMap.put(entry.getKey(), (entry.getValue()[0]));
} while (paramIter.hasNext())
topMap.put("requestParameters",requestParamMap);


// Session Attributes
var sessionAttrMap = new Hashtable();
var session = request.getSession();
// Insert a variable on the session
session.setAttribute("ReportAttribute", "arbitrary value to pass to
container");
var sessionAttrNames = session.getAttributeNames();
var i = 0;
do {
i ++;

var aaa = sessionAttrNames.nextElement();
sessionAttrMap.put(aaa, session.getAttribute(aaa));
} while (sessionAttrNames.hasMoreElements())
topMap.put("sessionAttributes", sessionAttrMap);


// Get the system properties
topMap.put("systemProps", Packages.java.lang.System.getProperties());

// Store top map as a global
reportContext.setPersistentGlobalVariable("topMap", topMap);]]></method>
<method name="afterFactory"><![CDATA[// Clean up logger code

log("after factory");

var hdls = Logger.getLogger("").getHandlers();
for (i = 0; i < hdls.length; i++)
{
Logger.getLogger("").removeHandler(hdls[i]);
hdls[i].close();
}]]></method>
<data-sources>
<script-data-source name="setScript" id="4"/>
</data-sources>
<data-sets>
<script-data-set name="setEnvironmentVars" id="5">
<list-property name="resultSetHints">
<structure>
<property name="position">1</property>
<property name="name">propName</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">propValue</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">propType</property>
<property name="dataType">string</property>
</structure>
</list-property>
<list-property name="columnHints">
<structure>
<property name="columnName">propName</property>
</structure>
<structure>
<property name="columnName">propValue</property>
</structure>
<structure>
<property name="columnName">propType</property>
</structure>
</list-property>
<structure name="cachedMetaData">
<list-property name="resultSet">
<structure>
<property name="position">1</property>
<property name="name">propName</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">2</property>
<property name="name">propValue</property>
<property name="dataType">string</property>
</structure>
<structure>
<property name="position">3</property>
<property name="name">propType</property>
<property name="dataType">string</property>
</structure>
</list-property>
</structure>
<property name="dataSource">setScript</property>
<method name="open"><![CDATA[aMap =
reportContext.getPersistentGlobalVariable("topMap");
topIter = aMap.entrySet().iterator();
if (topIter == null)
{
topIterator = new Packages.java.util.Iterator();
Packages.java.util.logging.Logger.getLogger("").info("OPEN NULL " );
}
innerIter = null;]]></method>
<method name="fetch"><![CDATA[do
{ // find an innerIter that has a new value
if (innerIter == null || innerIter.hasNext() == false)
{ // no value in the inner iterator, get the next Hashtable out of the
toHashtable
if (topIter.hasNext())
{
outerObject = topIter.next();
innerIter = outerObject.getValue().entrySet().iterator();
}
else
{ // no more top hash tables. close things up
return false;
}
}
}
while (innerIter.hasNext() == false)

// we must have another innerIter
innerObject = innerIter.next();

row["propName"] = innerObject.getKey();
row["propValue"] = innerObject.getValue().toString();
row["propType"] = outerObject.getKey();
return true;



/*
Iterator i = topMap.entrySet().iterator();
while (i.hasNext()) {
Entry entry = (Entry) i.next();
logger.info(entry.getKey() + " " + entry.getValue() );
}
*/]]></method>
</script-data-set>
</data-sets>
<page-setup>
<simple-master-page name="Simple MasterPage" id="2">
<property name="orientation">landscape</property>
<property name="topMargin">0.5in</property>
<property name="leftMargin">0.5in</property>
<property name="bottomMargin">0.5in</property>
<property name="rightMargin">0.5in</property>
</simple-master-page>
</page-setup>
<body>
<table id="6">
<property name="width">100%</property>
<property name="dataSet">setEnvironmentVars</property>
<list-property name="boundDataColumns">
<structure>
<property name="name">propName</property>
<expression
name="expression">dataSetRow["propName"]</expression>
</structure>
<structure>
<property name="name">propValue</property>
<expression
name="expression">dataSetRow["propValue"]</expression>
</structure>
<structure>
<property name="name">propType</property>
<expression
name="expression">dataSetRow["propType"]</expression>
<property name="aggregateOn">propType</property>
</structure>
</list-property>
<column id="16"/>
<column id="17"/>
<header>
<row id="7">
<cell id="8">
<label id="18">
<text-property
name="text">propName</text-property>
</label>
</cell>
<cell id="9">
<label id="20">
<text-property
name="text">propValue</text-property>
</label>
</cell>
</row>
</header>
<group id="22">
<property name="groupName">propType</property>
<property name="interval">none</property>
<property name="sortDirection">asc</property>
<expression name="keyExpr">row["propType"]</expression>
<header>
<row id="23">
<property name="backgroundColor">#FFFF80</property>
<cell id="24">
<data id="29">
<property name="fontWeight">bold</property>
<property
name="resultSetColumn">propType</property>
</data>
</cell>
<cell id="25"/>
</row>
<row id="33">
<property name="height">2pt</property>
<property name="backgroundColor">#000000</property>
<cell id="34"/>
<cell id="35"/>
</row>
</header>
<footer>
<row id="26">
<cell id="27"/>
<cell id="28"/>
</row>
</footer>
</group>
<detail>
<row id="10">
<cell id="11">
<data id="19">
<property name="fontSize">small</property>
<property
name="resultSetColumn">propName</property>
</data>
</cell>
<cell id="12">
<data id="21">
<property name="fontSize">small</property>
<property
name="resultSetColumn">propValue</property>
</data>
</cell>
</row>
<row id="30">
<property name="height">2pt</property>
<property name="backgroundColor">#C0C0C0</property>
<cell id="31"/>
<cell id="32"/>
</row>
</detail>
<footer>
<row id="13">
<cell id="14"/>
<cell id="15"/>
</row>
</footer>
</table>
</body>
</report>
Previous Topic:Blog post about Birt & Spring
Next Topic:How to set date parameter as today
Goto Forum:
  


Current Time: Sat Apr 27 03:03:32 GMT 2024

Powered by FUDForum. Page generated in 0.02822 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top