Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » GetXMLParams
GetXMLParams [message #810455] Thu, 01 March 2012 05:36 Go to next message
Sergey Syr is currently offline Sergey SyrFriend
Messages: 19
Registered: February 2012
Junior Member
Hello!

How to get list of parameters from XML file to JAVA?

I need set values of params, but I dont know names in XML.

Thank You!

//Sorry for my bad English.

[Updated on: Thu, 01 March 2012 05:41]

Report message to a moderator

Re: GetXMLParams [message #810855 is a reply to message #810455] Thu, 01 March 2012 16:05 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Do you mean report parameters? Can you give some more detail?

Jason

On 3/1/2012 12:36 AM, Sergey Syr wrote:
> Hello!
>
> How to get parameters from XML file to JAVA?
>
> I need set perameters, but I dont know names in XML.
>
> Thank You!
Re: GetXMLParams [message #811256 is a reply to message #810855] Fri, 02 March 2012 05:20 Go to previous messageGo to next message
Sergey Syr is currently offline Sergey SyrFriend
Messages: 19
Registered: February 2012
Junior Member
Ok!
preamble:
Managers want generate reports (xml file) independently, not programmers. I must generate universal remedy handling, - Class. For that, I must to get list of report parameters and theirs default values in JAVA.

I have 2 report parameters "NewParameter" and "NewParameter1".

- <scalar-parameter name="NewParameter" id="10">
  <property name="valueType">static</property> 
  <property name="dataType">string</property> 
  <property name="distinct">true</property> 
- <simple-property-list name="defaultValue">
  <value type="constant">0</value> 


How to get in JAVA list of parameters and theirs defaults?
I think in getParameterValues(), but d'nt know how use it.




This is my xml report
<?xml version="1.0" encoding="UTF-8" ?> 
- <report xmlns=".eclipse.org/birt/2005/design" version="3.2.22" id="1">
  <property name="createdBy">Eclipse BIRT Designer Version 3.7.1.v20110905 Build <3.7.1.v20110913-1734></property> 
  <property name="units">in</property> 
  <property name="iconFile">/templates/blank_report.gif</property> 
  <property name="bidiLayoutOrientation">ltr</property> 
  <property name="imageDPI">96</property> 
- <parameters>
- <scalar-parameter name="NewParameter" id="10">
  <property name="valueType">static</property> 
  <property name="dataType">string</property> 
  <property name="distinct">true</property> 
- <simple-property-list name="defaultValue">
  <value type="constant">0</value> 
  </simple-property-list>
  <list-property name="selectionList" /> 
  <property name="paramType">simple</property> 
  <property name="controlType">text-box</property> 
- <structure name="format">
  <property name="category">Unformatted</property> 
  </structure>
  </scalar-parameter>
- <scalar-parameter name="NewParameter1" id="11">
  <property name="valueType">static</property> 
  <property name="dataType">string</property> 
  <property name="distinct">true</property> 
- <simple-property-list name="defaultValue">
  <value type="constant">1</value> 
  </simple-property-list>
  <list-property name="selectionList" /> 
  <property name="paramType">simple</property> 
  <property name="controlType">text-box</property> 
- <structure name="format">
  <property name="category">Unformatted</property> 
  </structure>
  </scalar-parameter>
  </parameters>
- <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>
- <label id="7">
  <text-property name="text">Test Report</text-property> 
  </label>
- <label id="8">
  <text-property name="text">test</text-property> 
  </label>
- <label id="9">
  <text-property name="text">test test</text-property> 
  </label>
  </body>
  </report>


[Updated on: Fri, 02 March 2012 06:11]

Report message to a moderator

Re: GetXMLParams [message #811754 is a reply to message #811256] Fri, 02 March 2012 19:31 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Here is a sample that gets most of the parameter information:




import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.logging.Level;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;
import org.eclipse.birt.report.engine.api.IParameterDefnBase;
import org.eclipse.birt.report.engine.api.IParameterGroupDefn;
import org.eclipse.birt.report.engine.api.IParameterSelectionChoice;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IScalarParameterDefn;
import org.eclipse.birt.report.model.api.CascadingParameterGroupHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;

public class ReportParameters {

@SuppressWarnings("unchecked")
static void executeReport() throws EngineException
{
HashMap parmDetails = new HashMap();
IReportEngine engine=null;
EngineConfig config = null;
try{

config = new EngineConfig( );

config.setBIRTHome("C:\\birt\\birt-runtime-2_6_2\\birt-runtime-2_6_2\\ReportEngine");
config.setLogConfig(null, Level.OFF);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
}catch( Exception ex){
ex.printStackTrace();
}


//Open a report design
IReportRunnable design =
engine.openReportDesign("reports/parameters.rptdesign");

IGetParameterDefinitionTask task =
engine.createGetParameterDefinitionTask( design );
Collection params = task.getParameterDefns( true );


//task.getSelectionListForCascadingGroup();
Iterator iter = params.iterator( );
while ( iter.hasNext( ) )
{
IParameterDefnBase param = (IParameterDefnBase) iter.next( );

if ( param instanceof IParameterGroupDefn )
{
IParameterGroupDefn group = (IParameterGroupDefn) param;
System.out.println( "Parameter Group: " + group.getName( ) );


// Do something with the parameter group.
// Iterate over group contents.

Iterator i2 = group.getContents( ).iterator( );
while ( i2.hasNext( ) )
{
IScalarParameterDefn scalar = (IScalarParameterDefn) i2.next( );
//System.out.println("\t" + scalar.getName());
parmDetails.put( scalar.getName(), loadParameterDetails( task,
scalar, design, group));
}

}
else
{

IScalarParameterDefn scalar = (IScalarParameterDefn) param;
//System.out.println(param.getName());
parmDetails.put( scalar.getName(),loadParameterDetails( task,
scalar, design, null));


}
}

task.close();
engine.destroy();
Platform.shutdown();
System.out.println("Finished");
}

private static HashMap loadParameterDetails(IGetParameterDefinitionTask
task, IScalarParameterDefn scalar, IReportRunnable report,
IParameterGroupDefn group){



HashMap parameter = new HashMap();

if( group == null){
parameter.put("Parameter Group", "Default");
}else{
parameter.put("Parameter Group", group.getName());
}
parameter.put("Name", scalar.getName());
parameter.put("Help Text", scalar.getHelpText());
parameter.put("Display Name", scalar.getDisplayName());
//this is a format code such as > for UPPERCASE
parameter.put("Display Format", scalar.getDisplayFormat());

if( scalar.isHidden() ){
parameter.put("Hidden", "Yes");
}else{
parameter.put("Hidden", "No");
}
if( scalar.isHidden() ){
parameter.put("Hidden", "Yes");
}else{
parameter.put("Hidded", "No");
}
if( scalar.isRequired() ){
parameter.put("Is Required", "Yes");
}else{
parameter.put("Is Required", "No");
}
if( scalar.isValueConcealed() ){
parameter.put("Conceal Entry", "Yes"); //ie passwords etc
}else{
parameter.put("Conceal Entry", "No");
}


switch (scalar.getControlType()) {
case IScalarParameterDefn.TEXT_BOX: parameter.put("Type", "Text
Box"); break;
case IScalarParameterDefn.LIST_BOX: parameter.put("Type", "List
Box"); break;
case IScalarParameterDefn.RADIO_BUTTON: parameter.put("Type", "List
Box"); break;
case IScalarParameterDefn.CHECK_BOX: parameter.put("Type", "List
Box"); break;
default: parameter.put("Type", "Text Box");break;
}


switch (scalar.getDataType()) {
case IScalarParameterDefn.TYPE_STRING: parameter.put("Data Type",
"String"); break;
case IScalarParameterDefn.TYPE_FLOAT: parameter.put("Data Type",
"Float"); break;
case IScalarParameterDefn.TYPE_DECIMAL: parameter.put("Data Type",
"Decimal"); break;
case IScalarParameterDefn.TYPE_DATE_TIME: parameter.put("Data Type",
"Date Time"); break;
case IScalarParameterDefn.TYPE_BOOLEAN: parameter.put("Data Type",
"Boolean"); break;
default: parameter.put("Data Type", "Any"); break;
}


ScalarParameterHandle parameterHandle = ( ScalarParameterHandle )
scalar.getHandle();

parameter.put("Default Value", scalar.getDefaultValue());
parameter.put("Prompt Text", scalar.getPromptText());
parameter.put("Data Set Expression", parameterHandle.getValueExpr());

if(scalar.getControlType() != IScalarParameterDefn.TEXT_BOX)
{
//System.out.println("dynamic parameter");

if ( parameterHandle.getContainer( ) instanceof
CascadingParameterGroupHandle ){
Collection sList = Collections.EMPTY_LIST;
if ( parameterHandle.getContainer( ) instanceof
CascadingParameterGroupHandle )
{

String groupName = parameterHandle.getContainer( ).getName( );
//used for Cascading parms see IGetParameterDefinitionTask.java
code for comments
//task.evaluateQuery( groupName );

//Need to load this for calls to get next level.
//This just gets the first level
Object [] keyValueTmp = new Object[1];
sList = task.getSelectionListForCascadingGroup( groupName,
keyValueTmp );


for ( Iterator sl = sList.iterator( ); sl.hasNext( ); )
{
IParameterSelectionChoice sI = (IParameterSelectionChoice) sl.next( );


Object value = sI.getValue( );
Object label = sI.getLabel( );
System.out.println( label + "--" + value);

}

}
}else{
Collection selectionList = task.getSelectionList( scalar.getName() );

if ( selectionList != null )
{
HashMap dynamicList = new HashMap();

for ( Iterator sliter = selectionList.iterator( ); sliter.hasNext( ); )
{
IParameterSelectionChoice selectionItem =
(IParameterSelectionChoice) sliter.next( );

Object value = selectionItem.getValue( );
String label = selectionItem.getLabel( );

//System.out.println( label + "--" + value);
//Display label unless null then display value. Value is the what
should get passed to the report.
dynamicList.put(value,label);

}
parameter.put("Selection List", dynamicList);
}
}

}



Iterator iter = parameter.keySet().iterator();
System.out.println("======================Parameter =" +
scalar.getName());
while (iter.hasNext()) {
String name = (String) iter.next();
if( name.equals("Selection List")){
HashMap selList = (HashMap)parameter.get(name);
Iterator selIter = selList.keySet().iterator();
while (selIter.hasNext()) {
Object lbl = selIter.next();
System.out.println( "Selection List Entry ===== Key = " + lbl + "
Value = " + selList.get(lbl));
}

}else{
System.out.println( name + " = " + parameter.get(name));
}
}
return parameter;

}

/**
* @param args
*/
public static void main(String[] args) {
try
{
executeReport( );
}
catch ( Exception e )
{
e.printStackTrace();
}
}

}



You will see the getDefaultValue() call to get the default value.
You will also notice this uses a IGetParameterDefinitionTask.

Jason


On 3/2/2012 12:20 AM, Sergey Syr wrote:
> Ok!
> preamble:
> Managers want generate reports (xml file) independently, not programmers. I must generate universal remedy handling, - Class. For that, I must to get list of report parameters and theirs default values in JAVA.
>
> I have 2 report parameters "NewParameter" and "NewParameter1".
> It was String parameters, as though.
> -<scalar-parameter name="NewParameter" id="10">
> <property name="valueType">static</property>
> <property name="dataType">string</property>
> <property name="distinct">true</property>
> -<simple-property-list name="defaultValue">
> <value type="constant">0</value>
>
>
> How to get in JAVA list of parameters and theirs defaults?
> I think in getParameterValues(), but did no how use it.
>
>
>
>
> This is my xml report
> <?xml version="1.0" encoding="UTF-8" ?>
> -<report xmlns=".eclipse.org/birt/2005/design" version="3.2.22" id="1">
> <property name="createdBy">Eclipse BIRT Designer Version 3.7.1.v20110905 Build<3.7.1.v20110913-1734></property>
> <property name="units">in</property>
> <property name="iconFile">/templates/blank_report.gif</property>
> <property name="bidiLayoutOrientation">ltr</property>
> <property name="imageDPI">96</property>
> -<parameters>
> -<scalar-parameter name="NewParameter" id="10">
> <property name="valueType">static</property>
> <property name="dataType">string</property>
> <property name="distinct">true</property>
> -<simple-property-list name="defaultValue">
> <value type="constant">0</value>
> </simple-property-list>
> <list-property name="selectionList" />
> <property name="paramType">simple</property>
> <property name="controlType">text-box</property>
> -<structure name="format">
> <property name="category">Unformatted</property>
> </structure>
> </scalar-parameter>
> -<scalar-parameter name="NewParameter1" id="11">
> <property name="valueType">static</property>
> <property name="dataType">string</property>
> <property name="distinct">true</property>
> -<simple-property-list name="defaultValue">
> <value type="constant">1</value>
> </simple-property-list>
> <list-property name="selectionList" />
> <property name="paramType">simple</property>
> <property name="controlType">text-box</property>
> -<structure name="format">
> <property name="category">Unformatted</property>
> </structure>
> </scalar-parameter>
> </parameters>
> -<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>
> -<label id="7">
> <text-property name="text">Test Report</text-property>
> </label>
> -<label id="8">
> <text-property name="text">test</text-property>
> </label>
> -<label id="9">
> <text-property name="text">test test</text-property>
> </label>
> </body>
> </report>
>
>
Re: GetXMLParams [message #813302 is a reply to message #811754] Mon, 05 March 2012 04:34 Go to previous message
Sergey Syr is currently offline Sergey SyrFriend
Messages: 19
Registered: February 2012
Junior Member
Thank You, Jason! This example I investigate in friday. It match.
Previous Topic:BIRT Excel export, Office 2007, warning
Next Topic:Text Formatting while rendering in Excel
Goto Forum:
  


Current Time: Wed Dec 01 22:18:39 GMT 2021

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

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

Back to the top