2017 R1

Generating the Source XMLPermanent link for this heading

The following example describes how to generate easily XML data within Fabasoft app.ducx Expressions. Alternatively, Java standard functionality can be used to generate XML data in a convenient way.

First create some demo data. A logbook management is needed that contains some logbooks containing some trips. Edit the trips’ properties and insert dates and miles.

The master plan is to put the data in a dictionary and generate the XML structure with the  FSCEXPEXT@1.1001:Value2XML() action. Replace the use case file as used in chapter “Getting Started” with the following use case file.

Example

app.ducx Use Case Language

usecases BIRT@1.506
{
  import COOSYSTEM@1.1;
  import FSCVAPP@1.1001;
  import FSCVENV@1.1001;
  import FSCVIEW@1.1001;
  import FSCEXPEXT@1.1001;
  import COOMAPI@1.1;
  import FSCACROBAT@1.1;

  

  // gets exectued when calling the context menu command
  menu usecase CreateBirtReport on selected {
    variant Object {
      impl = expression {
        // GenerateData() collects the meta data of a logbook management
        // the implementation can be found below

        dictionary data = cooobj.GenerateData();
        // creates XML from the data dictionary
        string xmlstr = cooobj.Value2XML(data);
        content xmlcont = coort.CreateContent();
        xmlcont.SetContent(cootx, 1, 65001, xmlstr);            

        // a BIRT PDF report is generated based on the XML data and
        // the #BirtReport defined in the object model language
  
        content result = coouser.FSCBIRT@1.1001:CreateReport
          (xmlcont, #BirtReport)[3];

        

        // contains the PDF report
        FSCACROBAT@1.1:PDFObject pdf =
          #FSCACROBAT@1.1:PDFObject.ObjectCreate()[2];

        pdf.content = result;
        pdf.content.contextension = "pdf";
        pdf.objname = "Report " + coort.GetCurrentDateTime(cooobj);
        // put the report on the desk of the user
        cooroot.ObjectLock(true, true);
        cooroot.objchildren += pdf;    
      }
    }
  }

  

  // collects the meta data of a logbook management and returns a dictionary
  usecase GenerateData(retval dictionary result) {
    // use case implementation for the LogbookManagement
    variant LogbookManagement {
      impl = expression {
        result = {
          // the generated XML will contain a tag "objname" with the
          // computed value of cooobj.objname

          objname: cooobj.objname
        };
        dictionary[] logbooks;
        dictionary[] logbookids;
        // for all logbooks in the logbook management
        for (Logbook logbook: cooobj.vmlogbooks) {
          logbooks += logbook.GenerateData();
          // IDs are necessary to be able to filter the rows with XPath
          // expressions in the report design (more information can be found

          // in chapter
Creating a Report With Eclipse BIRT Report Designer
          logbookids += { id: logbook.objaddress };
        }
        result.SetEntry("logbook", logbooks);
        result.SetEntry("@logbook", logbookids);
      }
    }

    // use case implementation for the LogbookManagement
    variant Logbook {
      impl = expression {
        result = {
          objname: cooobj.objname,
          logdescription: cooobj.logdescription
        };
        dictionary[] logtriplogs;
        for (TripLog triplog: cooobj.logtriplogs) {
          logtriplogs += triplog.GenerateData();
        }
        result.SetEntry("logtriplog", logtriplogs);
      }
    }

    // use case implementation for the TripLog
    variant TripLog {
      impl = expression {
        result = {
          objname: cooobj.objname,
          trlfrom: cooobj.trlfrom,
          trluntil: cooobj.trluntil,
          trlmiles: cooobj.trlmiles
        };
      }
    }
  }
}

As result the report is generated based on the data provided in the Folio objects. The last step is to improve the demo report with the Eclipse BIRT Report Designer.