Importing/Reading text file in DXL script?

I am looking for a solution which helps to import a text file in the code, I am doing this to remove the hard coded values which do the mapping .

Instead, I would want to call a text file and read values, which does the mapping. Making the code independent of projects. Any Idea how to do it ?

I want to remove the mechanism of hard coding and substitute it with reading values from a text file.

    OleAutoObj createWrapperObj(Object obj) {
    OleAutoArgs args = create
    OleAutoObj wrapper = null
    print oleMethod(d2e, "CreateObjectWrapper", args, wrapper)
    
    olePut(wrapper, "ModuleName", name(m))
    olePut(wrapper, "aObjectType", unicodeString(obj."aObjectType"))
    olePut(wrapper, "TestDescription", unicodeString(obj."Object Short Text"))
    olePut(wrapper, "TestPictureName", unicodeString(obj."ID"))
    olePut(wrapper, "TestFocus", unicodeString(obj."Test_Focus"))
    
    return wrapper }

I have read a thread which helps in reading a file, but i am completely new to DXL and do not know what that question tries to explain.


struggleisreal - Mon Apr 10 09:26:00 EDT 2017

Re: Importing/Reading text file in DXL script?
Mathias Mamsch - Mon Apr 10 16:11:25 EDT 2017

The code you posted is the part, where you want to remove the hardcoded values? You need to perform the following steps:

1. Read a file line by line (see DXL manual "Files and Streams" in the example of the end(Stream) function

2. Split the String using a separator -> There are multiple split implementations on the forum use the search

3. Build a Skip list containing the mapped values

4 Use the skip list inside your OLE code in a loop.

Regards, Mathias

 

Re: Importing/Reading text file in DXL script?
struggleisreal - Mon Apr 24 05:58:02 EDT 2017

Mathias Mamsch - Mon Apr 10 16:11:25 EDT 2017

The code you posted is the part, where you want to remove the hardcoded values? You need to perform the following steps:

1. Read a file line by line (see DXL manual "Files and Streams" in the example of the end(Stream) function

2. Split the String using a separator -> There are multiple split implementations on the forum use the search

3. Build a Skip list containing the mapped values

4 Use the skip list inside your OLE code in a loop.

Regards, Mathias

 

Thank you for your answer :)
I was successfull in getting my output with a similar approach, In the linked code I have mapped the static values of A,B,C... to the values I read from the txt file, which works fine.

OleAutoObj createWrapperObj(Object obj) {
    OleAutoArgs args = create
    OleAutoObj wrapper = null
    print oleMethod(d2e, "CreateObjectWrapper", args, wrapper)
    
        string myFileName = get fieldFilePath
        Stream input      = null
        Buffer oneLine    = create
        string attributes[] = {"A", "B", "C"}
        int index = 1
        int    iLine      = 0

        if (canOpenFile(myFileName, false))
        {
         // print "open file: \"" myFileName "\" was successul \n"
          // Valid filename
          input = read(myFileName)
        
          olePut(wrapper, attributes[0], name(m))
          index = 1
                
          while (!end input) 
          {
                // Read file line by line
                input >= oneLine
                // print "\n" (++iLine) ": " (tempStringOf oneLine)
                
                string attributeName = tempStringOf(oneLine)
                        if (exists(attribute(attributeName)))
                        {
                                string value = obj.attributeName
                                //print "attribute name: " attributeName ", Value: " value "\n"
                                string attrList = attributes[index]
                                olePut(wrapper, attrList, (value))
                                index++
                        }
                        else
                        {
                                string attrList = attributes[index]
                                olePut(wrapper, attrList, (""))
                                index++
                        }
                }
                
                if (index > 5)
                {
                        break
                }
                
                
          }
          // Read file line by line
          close input
        }
        // Valid filename
        else
        {
                string buttons[] = {"OK"}
                messageBox("Unable to read file", buttons, msgError)
        }
        delete oneLine
        
    return wrapper
}

Now I have another problem, I have nothing static in my code now (i.e string attributes[] is null ). My problem now is to map dynamically.

Example:

My Current text file looks like this:

  • ID, RequirementID
  • Process, Action

Previous Text file looked like this:

  • RequirementID
  • Action

I want to modify the current script such that ID is mapped to RequirementID (ID is the attribute from some other tool, RequirementID is the attribute name from DOORS)

Is there any simple method I can do this with ?

Regards,

StruggleisReal :)

Re: Importing/Reading text file in DXL script?
Mathias Mamsch - Mon Apr 24 06:39:20 EDT 2017

struggleisreal - Mon Apr 24 05:58:02 EDT 2017

Thank you for your answer :)
I was successfull in getting my output with a similar approach, In the linked code I have mapped the static values of A,B,C... to the values I read from the txt file, which works fine.

OleAutoObj createWrapperObj(Object obj) {
    OleAutoArgs args = create
    OleAutoObj wrapper = null
    print oleMethod(d2e, "CreateObjectWrapper", args, wrapper)
    
        string myFileName = get fieldFilePath
        Stream input      = null
        Buffer oneLine    = create
        string attributes[] = {"A", "B", "C"}
        int index = 1
        int    iLine      = 0

        if (canOpenFile(myFileName, false))
        {
         // print "open file: \"" myFileName "\" was successul \n"
          // Valid filename
          input = read(myFileName)
        
          olePut(wrapper, attributes[0], name(m))
          index = 1
                
          while (!end input) 
          {
                // Read file line by line
                input >= oneLine
                // print "\n" (++iLine) ": " (tempStringOf oneLine)
                
                string attributeName = tempStringOf(oneLine)
                        if (exists(attribute(attributeName)))
                        {
                                string value = obj.attributeName
                                //print "attribute name: " attributeName ", Value: " value "\n"
                                string attrList = attributes[index]
                                olePut(wrapper, attrList, (value))
                                index++
                        }
                        else
                        {
                                string attrList = attributes[index]
                                olePut(wrapper, attrList, (""))
                                index++
                        }
                }
                
                if (index > 5)
                {
                        break
                }
                
                
          }
          // Read file line by line
          close input
        }
        // Valid filename
        else
        {
                string buttons[] = {"OK"}
                messageBox("Unable to read file", buttons, msgError)
        }
        delete oneLine
        
    return wrapper
}

Now I have another problem, I have nothing static in my code now (i.e string attributes[] is null ). My problem now is to map dynamically.

Example:

My Current text file looks like this:

  • ID, RequirementID
  • Process, Action

Previous Text file looked like this:

  • RequirementID
  • Action

I want to modify the current script such that ID is mapped to RequirementID (ID is the attribute from some other tool, RequirementID is the attribute name from DOORS)

Is there any simple method I can do this with ?

Regards,

StruggleisReal :)

As I said, find yourself a "split" function implementation (on the forum). Put in your textfile stuff like this: 

ID->Requirement ID
Attr->My Attr

Read the file, line by line, split the line by the separator to get both values. Regards, Mathias