Two question about javascript in birt [message #368828] |
Mon, 29 June 2009 16:21  |
Eclipse User |
|
|
|
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 #368859 is a reply to message #368857] |
Wed, 01 July 2009 10:08   |
Eclipse User |
|
|
|
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>
>>>>
>>>>
>>
>>
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.19899 seconds