Book a Demo

Author Topic: RTF Template multiple sections  (Read 4475 times)

Xavier

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
RTF Template multiple sections
« on: October 30, 2013, 02:25:44 am »
Hello,

I'm stuck with a problem on RTF Templates and cannot figure out how to fix it.

Quite simply, i'd like to write a RTF template that would write for each method : its name, all of its parameters (and their types) between parenthesis (repdoduicing the methods appearance in the code), the methods notes and then a list of the parameters and their notes.

Basically, it would generate a portion of RTF looking like :

"public void doSomething(int anInt, int anotherOne) : Does Something

- int anInt : the first parameter
- int anotherOne : the second parameter"

Problem is, once the parameters are written, and the section "parameter >" is closed, it cannot be re-opened, so this cannot be done as simply as i would like, or expect :


"method >
{Meth.Scope} {Meth.Name} (parameter > {MethParameter.Type} {MethParameter.Name}, < parameter) : {Meth.Notes}

parameter >- {MethParameter.Type} {MethParameter.Name}< parameter
< method"

So I tried with a fragment Template, but it didn't work either, since the fragment template call seems to make every other field within the same section fail.

Example :

"
method >
{Meth.Scope} {Meth.Static} {Meth.Const} {Meth.Pure} {Meth.Type} {Meth.Name} (parameter > {MethParameter.Type} {MethParameter.Name}, < parameter) : {Meth.Notes}

{Template - Fragment}
< method"

The Template Fragment is ok and its content is correctly written, but what i put first is simply re-written as if it was plain text in my RTF document. It gives, in the RTF document :

"
{Meth.Scope} {Meth.Static} {Meth.Const} {Meth.Pure} {Meth.Type} {Meth.Name} (parameter > {MethParameter.Type} {MethParameter.Name}, < parameter) : {Meth.Notes}


- int anInt : the first parameter
- int anotherOne : the second parameter"

Even worse, the description of the method is just written once, followed by every parameters of every method of this element, instead of once for every method followed by its parameters. But this - i guess - should be fixed by solving my original problem.

Thanks in advance for any piece of advice/solution you could give me.

Regards,

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: RTF Template multiple sections
« Reply #1 on: October 30, 2013, 11:48:44 pm »
Hello,

you can insert a fragment template in the method section. The fragment template calls an fragment script. The fragment script is called with the operationID and simply returns the text you want to print.

You find an example in the EAExample.eap:
- Template Main (calls Fragment Template)
- Fragment Template: DocProperties  
- FragmentScript: DocProperties

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Xavier

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: RTF Template multiple sections
« Reply #2 on: November 04, 2013, 08:52:07 pm »
Okay, I tried.

- My main template is basically (with other stuff, but that gets written correctly) :

package >
element >
method >
{Template - Fragment}
< method
child element >
< child element
< element
child package >
< child package
< package

- The template fragment :

custom >
{Method_Name}
< custom

- With settings :
Template Fragment checked.
Custom Query : Custom script checked, the script i created choosed in the list, and in the text field :

PrintMethod(#operationID#);

- The script :

function PrintMethod(operationID)
{
      var xmlDOM = new ActiveXObject( "MSXML2.DOMDocument.4.0" );
      xmlDOM.validateOnParse = false;
       xmlDOM.async = false;
      
      var node = xmlDOM.createProcessingInstruction("xml", "version='1.0'");
       xmlDOM.appendChild(node);

      var xmlRoot = xmlDOM.createElement( "EADATA" );
       xmlDOM.appendChild(xmlRoot);

       var xmlDataSet = xmlDOM.createElement( "Dataset_0" );
      xmlRoot.appendChild(xmlDataSet);
        
      var xmlData = xmlDOM.createElement( "Data" );
      xmlDataSet.appendChild(xmlData);
      
      var xmlRow = xmlDOM.createElement( "Row" );
      xmlData.appendChild(xmlRow);
      
      var theMethod as EA.Method;
      theMethod = Repository.GetMethodByID(operationID);
      
      if ( theMethod != null && theMethod.ObjectType == otMethod )
      {
            var xmlName = xmlDOM.createElement( "Method_Name" );
            xmlName.text = theMethod.Name;
            xmlRow.appendChild(xmlName);
       }
      return xmlDOM.xml;
};

I havent't tried to go any further yet, since this doesn't work at all, but eventually, i'd like to have more informations about the method in my XML and my RTF, including the method's parameters.

But this doesn't work, error while generating, the method name, or anything i put in my xml elements is never written in the RTF file.
I tried a plain text directly in my field Method_Name, didn't work, i tried any syntax for operationID (operationID, OperationID, OPERATIONID, ObjectID, OBJECTID, objectID), didn't work, I tried to remove any call to the operationID in the script, and just writing plain text in xmlName.text, didn't work either. I tried to find any kind of documentation, explanation or tutoriel on how this works, on your website or anywhere in the web, I only found unapplicable examples.

EDIT :

If I remove the parameter operationID from the script's method, and from its call, and only put plain text in my xml, it works. Problem is, it only prints plain text, because i can't access to my method's information this way.
« Last Edit: November 04, 2013, 09:09:17 pm by Xavier »

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: RTF Template multiple sections
« Reply #3 on: November 04, 2013, 09:16:01 pm »
Hello Xavier,

the example from the Example.eap file and my one works. I only tried it with elements (class, activity, etc.).

I don't know if this works only with elements (#OBJECTID#) or with things like operations/attributes or so.

I would try:
- Set a breakpoint in your script/output the operationID

Be aware:
In the current implementation of SPARX is a bug. On some PC's it works fine and on other mysterious things happens. You also find an entry in the forum to this behavior.
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Xavier

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: RTF Template multiple sections
« Reply #4 on: November 04, 2013, 09:33:54 pm »
Hello,

The problem is clearly in the parameter of my function. I can pass objectID, and use it, it's the elements ID.

I don't understand why operationID doesn't work, why objectID is not simply called elementID, or why i have to put it in the method section (if i put it in the element section, i cannot use the attributes section, since inserting a template fragment brakes every other section on its level).

I will try it with the elementID i have now, but a true and complete documentation on this would be really appreciable.


EDIT :

Actually it doesn't seem possible using the elementID, since there is an undefined number of methods and I can't find a way to create and use an undefined number of XML elements. If i use the same name for all the template fragment only recognizes the last one, and in the template fragment I can only use the custom fields with a defined (and known before generation) name.

So we're back to the original problem. Maybe there's a way to pass the method's ID as parameter to my script function - which would solve it , but I can't find it.

And even worse, each method has an undefined number of parameter, and so on, back to the elementID problem.

Looks like there's no way in Enterprise Architect to do this quite simple thing.
« Last Edit: November 04, 2013, 10:35:40 pm by Xavier »