how can i display a text file in birt report?

marianemariane Junior Member
edited December 31, 1969 in Developing Analytics Applications
hi
I need to display content of a text file in my birt report (for example a discription ) but i can't found any solutions or advice
Can someone give me an advice or an example please?
thanks for all

Comments

  • mwilliamsmwilliams BIRT Guru
    edited December 31, 1969
    Hi mariane,

    You can read in a text file in javascript, using the java.io package. Then store the text in a global variable that you can then use to display the text anywhere.

    Hope this helps.

    Regards,

    Michael Williams

    eSignLive Evangelism & Community Manager | eSignLive by VASCO
     
    Find me on:
    Twitter
    Facebook
    Blog
    LinkedIn

    eSignLive Developer Community
     
    Email me:
    Google: [email protected]

  • marianemariane Junior Member
    edited December 31, 1969
    hi,
    thanks for help
    this is just what i try to do but i doesn't found a relation between my class java and the method onprepare of my eventhandler.
    this my java class:

    import java.io.*;

    import org.eclipse.birt.report.engine.api.script.eventadapter.TextItemEventAdapter;

    import org.eclipse.birt.report.engine.api.script.element.ITextItem;
    import org.eclipse.birt.report.engine.api.script.IReportContext;
    public class FileRead extends TextItemEventAdapter {
    public void onPrepare( ITextItem TextItem, IReportContext reportContext )
    {
    try
    {
    FileInputStream fstream = new FileInputStream("D:adresse.txt");
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    String content="";
    //Read File Line By Line
    while ((strLine = br.readLine()) != null) {
    // Print the content on the console
    content = content + strLine + "n";

    }

    //Close the input stream
    in.close();
    TextItem.setContent(content);

    } catch (Exception e ) {
    e.printStackTrace( );
    }

    }

    }
    thanks
  • marianemariane Junior Member
    edited December 31, 1969
    this the message error:
    Text (id = 32):
    - Unhandled exception when executing script.
    Error.UnhandledScriptError ( 4 time(s) )
    detail : org.eclipse.birt.report.engine.api.EngineException: Unhandled exception when executing script. at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.addException(ScriptExecutor.java:199) at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.addException(ScriptExecutor.java:176) at org.eclipse.birt.report.engine.script.internal.TextItemScriptExecutor.getEventHandler(TextItemScriptExecutor.java:178) at org.eclipse.birt.report.engine.script.internal.TextItemScriptExecutor.handleOnPrepare(TextItemScriptExecutor.java:38) at org.eclipse.birt.report.engine.api.impl.ScriptedDesignHandler.handleOnPrepare(ScriptedDesignHandler.java:169) at org.eclipse.birt.report.engine.api.impl.ScriptedDesignVisitor.visitTextItem(ScriptedDesignVisitor.java:426) at org.eclipse.birt.report.model.api.DesignVisitor$Forwarder.visitTextItem(DesignVisitor.java:1005) at org.eclipse.birt.report.model.elements.TextItem.apply(TextItem.java:58) at org.eclipse.birt.report.model.api.DesignVisitor.apply(DesignVisitor.java:123) at org.eclipse.birt.report.engine.api.impl.ScriptedDesignVisitor.visitReportDesign(ScriptedDesignVisitor.java:106) at org.eclipse.birt.report.model.api.DesignVisitor$Forwarder.visitReportDesign(DesignVisitor.java:1175) at org.eclipse.birt.report.model.elements.ReportDesign.apply(ReportDesign.java:89) at org.eclipse.birt.report.model.api.DesignVisitor.apply(DesignVisitor.java:123) at org.eclipse.birt.report.engine.api.impl.EngineTask.prepareDesign(EngineTask.java:1351) at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:88) at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:72) at org.eclipse.birt.report.service.ReportEngineService.runAndRenderReport(ReportEngineService.java:877) at org.eclipse.birt.report.service.BirtViewerReportService.runAndRenderReport(BirtViewerReportService.java:938) at org.eclipse.birt.report.service.actionhandler.BirtGetPageAllActionHandler.__execute(BirtGetPageAllActionHandler.java:131) at org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(AbstractBaseActionHandler.java:90) at org.eclipse.birt.report.soapengine.processor.AbstractBaseDocumentProcessor.__executeAction(AbstractBaseDocumentProcessor.java:47) at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.executeAction(AbstractBaseComponentProcessor.java:143) at org.eclipse.birt.report.soapengine.processor.BirtDocumentProcessor.handleGetPageAll(BirtDocumentProcessor.java:183) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.process(AbstractBaseComponentProcessor.java:112) at org.eclipse.birt.report.soapengine.endpoint.BirtSoapBindingImpl.getUpdatedObjects(BirtSoapBindingImpl.java:66) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397) at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186) at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323) at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454) at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281) at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699) at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doPost(BirtSoapMessageDispatcherServlet.java:265) at javax.servlet.http.HttpServlet.service(HttpServlet.java:616) at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.service(BirtSoapMessageDispatcherServlet.java:122) at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180) at org.eclipse.equinox.http.servlet.internal.ServletRegistration.handleRequest(ServletRegistration.java:90) at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:111) at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:59) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:269) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:428) at org.mortbay.jetty.servlet.ServletHandler.dispatch(ServletHandler.java:677) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568) at org.mortbay.http.HttpContext.handle(HttpContext.java:1530) at org.mortbay.http.HttpContext.handle(HttpContext.java:1482) at org.mortbay.http.HttpServer.service(HttpServer.java:909) at org.mortbay.http.HttpConnection.service(HttpConnection.java:820) at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:986) at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837) at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:245) at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357) at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)Caused by: org.eclipse.birt.report.engine.api.EngineException: IllegalAccessException when trying to load class FileRead. at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.getInstance(ScriptExecutor.java:139) at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.getInstance(ScriptExecutor.java:104) at org.eclipse.birt.report.engine.script.internal.TextItemScriptExecutor.getEventHandler(TextItemScriptExecutor.java:169) ... 62 moreCaused by: java.lang.IllegalAccessException: Class org.eclipse.birt.report.engine.script.internal.ScriptExecutor can not access a member of class FileRead with modifiers "" at sun.reflect.Reflection.ensureMemberAccess(Unknown Source) at java.lang.Class.newInstance0(Unknown Source) at java.lang.Class.newInstance(Unknown Source) at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.getInstance(ScriptExecutor.java:129) ... 64 more
  • marianemariane Junior Member
    edited December 31, 1969
    hi
    can someone tell me where is the mistake?
  • VirgilVirgil Administrator EM admin
    edited December 31, 1969
    Hi mariane,

    BIRT supports a Flat File Data Source that is really easy to use and you don't have to navigate the txt file yourself in Java. Otherwise, if you must walk over your data yourself in JAva, then have a look at the Scripted Data Source examples in the DevShare on BIRT Exchange.org. These allow you to write Java code to get your data... and then still use the BIRT designer to design the report.

    Virgil Dodson
    OpenText Analytics Developer Community
    https://forums.opentext.com/forums/categories/analytics

  • I need to read a txt file but I need to use it with a relative path and not the assolute path.
    Has someone the solution??

  • Create a flat file data source and select "Relative Path" for the home folder.

    Jeff F.
    Customer Support Engineer I
    OpenText
  • @jfranken said:
    Create a flat file data source and select "Relative Path" for the home folder.

    Thanks!!

Sign In or Register to comment.