|
Re: Two question about javascript in birt [message #368831 is a reply to message #368828] |
Mon, 29 June 2009 21:37 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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 #368847 is a reply to message #368845] |
Tue, 30 June 2009 18:40 |
Eclipse User |
|
|
|
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 #368857 is a reply to message #368849] |
Wed, 01 July 2009 13:46 |
Eclipse User |
|
|
|
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 |
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>
>>>>
>>>>
>>
>>
|
|
|
|
Re: Two question about javascript in birt [message #368890 is a reply to message #368885] |
Thu, 02 July 2009 19:19 |
Eclipse User |
|
|
|
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
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05006 seconds