Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Two question about javascript in birt
Two question about javascript in birt [message #368828] Mon, 29 June 2009 20:21 Go to next message
Larry Li is currently offline Larry LiFriend
Messages: 32
Registered: July 2009
Member
Hello,

I have two questions about javascript in birt.
First, can I make a global javascript function that can be reused by many
reports?
Second, is there an XML parser in BIRT javascript?
Thank you very much.


Larry
Re: Two question about javascript in birt [message #368831 is a reply to message #368828] Mon, 29 June 2009 21:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.windstream.net

Larry,

If you want to reuse a global JavaScript function you have basically two
choices. 1 - put it in a .js file in your resource folder and include
it in every report. 2 - Create a plugin that implement script function
extension. This is pretty simple and it has the side effect of making
the function appear the expression builder. See this post:

http://birtworld.blogspot.com/2008/09/birt-231-adding-functi ons-to-expression.html

Jason

Larry Li wrote:
> Hello,
>
> I have two questions about javascript in birt.
> First, can I make a global javascript function that can be reused by
> many reports?
> Second, is there an XML parser in BIRT javascript?
> Thank you very much.
>
>
> Larry
>
>
Re: Two question about javascript in birt [message #368832 is a reply to message #368828] Mon, 29 June 2009 21:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.windstream.net

You can also call Java to parse the xml like:

importPackage( Packages.javax.xml.parsers);
importPackage( Packages.org.xml.sax);
importPackage( Packages.org.w3c.dom);
importPackage( Packages.java.io);



function getTagValue(file, tagName) {

factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
document = builder.parse( new InputSource( new FileInputStream( file ))
);
nlist = document.getElementsByTagName(tagName);
return nlist.item(0).getFirstChild().getNodeValue();
}

mydatavalue = getTagValue("c:/test/parms.xml", "parm1");

Jason

Larry Li wrote:
> Hello,
>
> I have two questions about javascript in birt.
> First, can I make a global javascript function that can be reused by
> many reports?
> Second, is there an XML parser in BIRT javascript?
> Thank you very much.
>
>
> Larry
>
>
Re: Two question about javascript in birt [message #368833 is a reply to message #368832] Mon, 29 June 2009 21:56 Go to previous messageGo to next message
Larry Li is currently offline Larry LiFriend
Messages: 32
Registered: July 2009
Member
This is great!
Thanks a lot for replying.

Larry


> You can also call Java to parse the xml like:

> importPackage( Packages.javax.xml.parsers);
> importPackage( Packages.org.xml.sax);
> importPackage( Packages.org.w3c.dom);
> importPackage( Packages.java.io);



> function getTagValue(file, tagName) {

> factory = DocumentBuilderFactory.newInstance();
> builder = factory.newDocumentBuilder();
> document = builder.parse( new InputSource( new FileInputStream( file ))
> );
> nlist = document.getElementsByTagName(tagName);
> return nlist.item(0).getFirstChild().getNodeValue();
> }

> mydatavalue = getTagValue("c:/test/parms.xml", "parm1");

> Jason

> Larry Li wrote:
>> Hello,
>>
>> I have two questions about javascript in birt.
>> First, can I make a global javascript function that can be reused by
>> many reports?
>> Second, is there an XML parser in BIRT javascript?
>> Thank you very much.
>>
>>
>> Larry
>>
>>
Re: Two question about javascript in birt [message #368844 is a reply to message #368831] Tue, 30 June 2009 18:12 Go to previous messageGo to next message
Larry Li is currently offline Larry LiFriend
Messages: 32
Registered: July 2009
Member
Jason,

I exported the plugin project to a .jar file.
Where do I put this jar file? for both my eclipse environment and birt
server (i.e. WebViewerExample).
Thanks.


LArry


> Larry,

> If you want to reuse a global JavaScript function you have basically two
> choices. 1 - put it in a .js file in your resource folder and include
> it in every report. 2 - Create a plugin that implement script function
> extension. This is pretty simple and it has the side effect of making
> the function appear the expression builder. See this post:

>
http://birtworld.blogspot.com/2008/09/birt-231-adding-functi ons-to-expression.html

> Jason

> Larry Li wrote:
>> Hello,
>>
>> I have two questions about javascript in birt.
>> First, can I make a global javascript function that can be reused by
>> many reports?
>> Second, is there an XML parser in BIRT javascript?
>> Thank you very much.
>>
>>
>> Larry
>>
>>
Re: Two question about javascript in birt [message #368845 is a reply to message #368844] Tue, 30 June 2009 18:24 Go to previous messageGo to next message
Larry Li is currently offline Larry LiFriend
Messages: 32
Registered: July 2009
Member
Larry Li wrote:

> Jason,

> I exported the plugin project to a .jar file.
> Where do I put this jar file? for both my eclipse environment and birt
> server (i.e. WebViewerExample).
> Thanks.


> LArry


I also got this error when I exported the plugin project:
JAR creation failed. See details for additional information.
Resource is out of sync with the file system: '/plugin/plugin.xml'.
plugin/META-INF/MANIFEST.MF was replaced by the generated MANIFEST.MF
and is no longer in the JAR.
Exported with compile warnings:
plugin/src/plugin/actions/KashrusFuncExecutor.java

This is my plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

<extension
id="MyScriptFunctions"
name="MyScriptFuncitons"
point="org.eclipse.birt.core.ScriptFunctionService">
<Category
factoryclass="plugin.actions.KashrusFuncFactory"
name="KashrusFuncExecutor">
<Function
name="TestFunction">
<DataType
value="String">
</DataType>
<Argument
name="source">
<DataType
value="String">
</DataType>
</Argument>
</Function>
</Category>
</extension>
</plugin>
Re: Two question about javascript in birt [message #368847 is a reply to message #368845] Tue, 30 June 2009 18:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.windstream.net

Larry,

For design time should be in your eclipse/plugins directory.
for all in one it will be in this dir.
birt-report-designer-all-in-one-verion\eclipse\plugins

on the WebViewerExample put it in:
WebViewerExample/WEB-INF/platform/plugins

Jason

Larry Li wrote:
> Larry Li wrote:
>
>> Jason,
>
>> I exported the plugin project to a .jar file.
>> Where do I put this jar file? for both my eclipse environment and birt
>> server (i.e. WebViewerExample).
>> Thanks.
>
>
>> LArry
>
>
> I also got this error when I exported the plugin project:
> JAR creation failed. See details for additional information.
> Resource is out of sync with the file system: '/plugin/plugin.xml'.
> plugin/META-INF/MANIFEST.MF was replaced by the generated MANIFEST.MF
> and is no longer in the JAR.
> Exported with compile warnings:
> plugin/src/plugin/actions/KashrusFuncExecutor.java
>
> This is my plugin.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <?eclipse version="3.4"?>
> <plugin>
>
> <extension
> id="MyScriptFunctions"
> name="MyScriptFuncitons"
> point="org.eclipse.birt.core.ScriptFunctionService">
> <Category
> factoryclass="plugin.actions.KashrusFuncFactory"
> name="KashrusFuncExecutor">
> <Function
> name="TestFunction">
> <DataType
> value="String">
> </DataType>
> <Argument
> name="source">
> <DataType
> value="String">
> </DataType>
> </Argument>
> </Function>
> </Category>
> </extension>
> </plugin>
>
>
Re: Two question about javascript in birt [message #368849 is a reply to message #368847] Tue, 30 June 2009 19:24 Go to previous messageGo to next message
Larry Li is currently offline Larry LiFriend
Messages: 32
Registered: July 2009
Member
This does not work. This is what I do:
1. Create a plugin project, testplugin.
2. copy these files (from the zip file provided in your link) to
testplugin:
/jslibs
/META-INF
/src
build.properties
plugin.xml

3. Eclipse says there is error in MyCategory.execute
It says the method needs one more argument, so it becomes this:
execute(Object[] args, IScriptFunctionContext arg1)

4. I export the project to a jar file, and put this jar to eclipse/plugins

But I still cannot see MyCategory.TestFunction in Report Design.
Is anything wrong or I miss anything?

Thanks.

Larry

> Larry,

> For design time should be in your eclipse/plugins directory.
> for all in one it will be in this dir.
> birt-report-designer-all-in-one-verioneclipseplugins

> on the WebViewerExample put it in:
> WebViewerExample/WEB-INF/platform/plugins

> Jason

> Larry Li wrote:
>> Larry Li wrote:
>>
>>> Jason,
>>
>>> I exported the plugin project to a .jar file.
>>> Where do I put this jar file? for both my eclipse environment and birt
>>> server (i.e. WebViewerExample).
>>> Thanks.
>>
>>
>>> LArry
>>
>>
>> I also got this error when I exported the plugin project:
>> JAR creation failed. See details for additional information.
>> Resource is out of sync with the file system: '/plugin/plugin.xml'.
>> plugin/META-INF/MANIFEST.MF was replaced by the generated MANIFEST.MF
>> and is no longer in the JAR.
>> Exported with compile warnings:
>> plugin/src/plugin/actions/KashrusFuncExecutor.java
>>
>> This is my plugin.xml
>> <?xml version="1.0" encoding="UTF-8"?>
>> <?eclipse version="3.4"?>
>> <plugin>
>>
>> <extension
>> id="MyScriptFunctions"
>> name="MyScriptFuncitons"
>> point="org.eclipse.birt.core.ScriptFunctionService">
>> <Category
>> factoryclass="plugin.actions.KashrusFuncFactory"
>> name="KashrusFuncExecutor">
>> <Function
>> name="TestFunction">
>> <DataType
>> value="String">
>> </DataType>
>> <Argument
>> name="source">
>> <DataType
>> value="String">
>> </DataType>
>> </Argument>
>> </Function>
>> </Category>
>> </extension>
>> </plugin>
>>
>>
Re: Two question about javascript in birt [message #368857 is a reply to message #368849] Wed, 01 July 2009 13:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.windstream.net

Larry,

Sorry for asking the obvious but are you looking in the expression builder?

Jason

Larry Li wrote:
>
> This does not work. This is what I do:
> 1. Create a plugin project, testplugin.
> 2. copy these files (from the zip file provided in your link) to
> testplugin:
> /jslibs
> /META-INF
> /src
> build.properties
> plugin.xml
>
> 3. Eclipse says there is error in MyCategory.execute
> It says the method needs one more argument, so it becomes this:
> execute(Object[] args, IScriptFunctionContext arg1)
>
> 4. I export the project to a jar file, and put this jar to eclipse/plugins
>
> But I still cannot see MyCategory.TestFunction in Report Design.
> Is anything wrong or I miss anything?
>
> Thanks.
>
> Larry
>
>> Larry,
>
>> For design time should be in your eclipse/plugins directory.
>> for all in one it will be in this dir.
>> birt-report-designer-all-in-one-verioneclipseplugins
>
>> on the WebViewerExample put it in:
>> WebViewerExample/WEB-INF/platform/plugins
>
>> Jason
>
>> Larry Li wrote:
>>> Larry Li wrote:
>>>
>>>> Jason,
>>>
>>>> I exported the plugin project to a .jar file.
>>>> Where do I put this jar file? for both my eclipse environment and
>>>> birt server (i.e. WebViewerExample).
>>>> Thanks.
>>>
>>>
>>>> LArry
>>>
>>>
>>> I also got this error when I exported the plugin project:
>>> JAR creation failed. See details for additional information.
>>> Resource is out of sync with the file system: '/plugin/plugin.xml'.
>>> plugin/META-INF/MANIFEST.MF was replaced by the generated
>>> MANIFEST.MF and is no longer in the JAR.
>>> Exported with compile warnings:
>>> plugin/src/plugin/actions/KashrusFuncExecutor.java
>>>
>>> This is my plugin.xml
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <?eclipse version="3.4"?>
>>> <plugin>
>>>
>>> <extension
>>> id="MyScriptFunctions"
>>> name="MyScriptFuncitons"
>>> point="org.eclipse.birt.core.ScriptFunctionService">
>>> <Category
>>> factoryclass="plugin.actions.KashrusFuncFactory"
>>> name="KashrusFuncExecutor">
>>> <Function
>>> name="TestFunction">
>>> <DataType
>>> value="String">
>>> </DataType>
>>> <Argument
>>> name="source">
>>> <DataType
>>> value="String">
>>> </DataType>
>>> </Argument>
>>> </Function>
>>> </Category>
>>> </extension>
>>> </plugin>
>>>
>>>
>
>
Re: Two question about javascript in birt [message #368859 is a reply to message #368857] Wed, 01 July 2009 14:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.windstream.net

Larry,

It looks like the script context was added after I wrote the blog. Here
is the updated MyCategory file. Also in the expression builder look at
Birt Functions and MyCategory should show up underneath.

Jason

package my.expression.functions;

import org.eclipse.birt.core.exception.BirtException;
import org.eclipse.birt.core.script.functionservice.IScriptFunction Context;
import org.eclipse.birt.core.script.functionservice.IScriptFunction Executor;

/**
* String functions.
*/
class MyCategory implements IScriptFunctionExecutor
{

/**
*
*/
private static final long serialVersionUID = 1L;

private IScriptFunctionExecutor executor;

MyCategory( String functionName ) throws BirtException
{
if ( "TestFunction".equals( functionName ) )
this.executor = new TestFunction( );
else
throw new BirtException( "my.expression.funcitons",
null,
"invalid.function.name" + "MyCategory." + functionName );
}


private class TestFunction implements IScriptFunctionExecutor
{

/**
*
*/
private static final long serialVersionUID = 1L;

public Object execute( Object[] args, IScriptFunctionContext arg1)
throws BirtException
{
if ( args == null || args.length != 1 )
throw new IllegalArgumentException( "The number of arguement is
incorrect." );
if( args[0] == null){
return null;
}else{
StringBuffer sb = new StringBuffer( (String)args[0]);
return sb.reverse().toString();
}
}
}
public Object execute( Object[] arguments, IScriptFunctionContext arg1
) throws BirtException
{
return this.executor.execute( arguments, arg1 );
}

}

Jason Weathersby wrote:
> Larry,
>
> Sorry for asking the obvious but are you looking in the expression builder?
>
> Jason
>
> Larry Li wrote:
>>
>> This does not work. This is what I do:
>> 1. Create a plugin project, testplugin.
>> 2. copy these files (from the zip file provided in your link) to
>> testplugin:
>> /jslibs
>> /META-INF
>> /src
>> build.properties
>> plugin.xml
>>
>> 3. Eclipse says there is error in MyCategory.execute
>> It says the method needs one more argument, so it becomes this:
>> execute(Object[] args, IScriptFunctionContext arg1)
>>
>> 4. I export the project to a jar file, and put this jar to
>> eclipse/plugins
>>
>> But I still cannot see MyCategory.TestFunction in Report Design.
>> Is anything wrong or I miss anything?
>>
>> Thanks.
>>
>> Larry
>>
>>> Larry,
>>
>>> For design time should be in your eclipse/plugins directory.
>>> for all in one it will be in this dir.
>>> birt-report-designer-all-in-one-verioneclipseplugins
>>
>>> on the WebViewerExample put it in:
>>> WebViewerExample/WEB-INF/platform/plugins
>>
>>> Jason
>>
>>> Larry Li wrote:
>>>> Larry Li wrote:
>>>>
>>>>> Jason,
>>>>
>>>>> I exported the plugin project to a .jar file.
>>>>> Where do I put this jar file? for both my eclipse environment and
>>>>> birt server (i.e. WebViewerExample).
>>>>> Thanks.
>>>>
>>>>
>>>>> LArry
>>>>
>>>>
>>>> I also got this error when I exported the plugin project:
>>>> JAR creation failed. See details for additional information.
>>>> Resource is out of sync with the file system: '/plugin/plugin.xml'.
>>>> plugin/META-INF/MANIFEST.MF was replaced by the generated
>>>> MANIFEST.MF and is no longer in the JAR.
>>>> Exported with compile warnings:
>>>> plugin/src/plugin/actions/KashrusFuncExecutor.java
>>>>
>>>> This is my plugin.xml
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <?eclipse version="3.4"?>
>>>> <plugin>
>>>>
>>>> <extension
>>>> id="MyScriptFunctions"
>>>> name="MyScriptFuncitons"
>>>> point="org.eclipse.birt.core.ScriptFunctionService">
>>>> <Category
>>>> factoryclass="plugin.actions.KashrusFuncFactory"
>>>> name="KashrusFuncExecutor">
>>>> <Function
>>>> name="TestFunction">
>>>> <DataType
>>>> value="String">
>>>> </DataType>
>>>> <Argument
>>>> name="source">
>>>> <DataType
>>>> value="String">
>>>> </DataType>
>>>> </Argument>
>>>> </Function>
>>>> </Category>
>>>> </extension>
>>>> </plugin>
>>>>
>>>>
>>
>>
Re: Two question about javascript in birt [message #368885 is a reply to message #368859] Thu, 02 July 2009 16:00 Go to previous messageGo to next message
Larry Li is currently offline Larry LiFriend
Messages: 32
Registered: July 2009
Member
Jason,

I made it! Thanks a lot.
My mistake was that I export the project by using: Export --> Java --> JAR
file.

Actually, it has to be exported to a "Deployable plug-ins and fragments."
Then it works.


Larry
Re: Two question about javascript in birt [message #368890 is a reply to message #368885] Thu, 02 July 2009 19:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jasonweathersby.windstream.net

Do you mind adding a comment to the blog entry for clarification for
future users?

Thanks

Jason

Larry Li wrote:
>
> Jason,
>
> I made it! Thanks a lot.
> My mistake was that I export the project by using: Export --> Java -->
> JAR file.
>
> Actually, it has to be exported to a "Deployable plug-ins and fragments."
> Then it works.
>
>
> Larry
>
Re: Two question about javascript in birt [message #368910 is a reply to message #368890] Mon, 06 July 2009 14:15 Go to previous messageGo to next message
Larry Li is currently offline Larry LiFriend
Messages: 32
Registered: July 2009
Member
Sure!
But where and how do I add it?

Larry

> Do you mind adding a comment to the blog entry for clarification for
> future users?

> Thanks

> Jason

> Larry Li wrote:
>>
>> Jason,
>>
>> I made it! Thanks a lot.
>> My mistake was that I export the project by using: Export --> Java -->
>> JAR file.
>>
>> Actually, it has to be exported to a "Deployable plug-ins and fragments."
>> Then it works.
>>
>>
>> Larry
>>
Re: Two question about javascript in birt [message #368911 is a reply to message #368910] Mon, 06 July 2009 14:22 Go to previous message
Larry Li is currently offline Larry LiFriend
Messages: 32
Registered: July 2009
Member
Forget about this. I added the comment.

> Sure!
> But where and how do I add it?

> Larry

>> Do you mind adding a comment to the blog entry for clarification for
>> future users?

>> Thanks

>> Jason
Previous Topic:row minimum height in ppt
Next Topic:Integrating BIRT into RAP applications
Goto Forum:
  


Current Time: Fri Sep 20 09:10:35 GMT 2024

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

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

Back to the top