DOORS Project reporting V1.0
GSTCS445V2.0_doxyfile.dxl
Go to the documentation of this file.
00001 
00002 /* ******************************************
00003 Function: ()
00004 *************************************************/
00005 void setRowFontNormal () {
00006    clear objArgBlock
00007    put (objArgBlock, "MacroName", "setRowFontNormal")
00008    checkRes (oleMethod (objWord, "Run", objArgBlock))
00009 }
00010 void setRowBorder() {
00011    clear objArgBlock
00012    put (objArgBlock, "MacroName", "setRowBorder")
00013    checkRes (oleMethod (objWord, "Run", objArgBlock))
00014 }
00015 
00016 void setRowFormatBoldGray () {
00017    clear objArgBlock
00018    put (objArgBlock, "MacroName", "setRowFormatBoldGray")
00019    checkRes (oleMethod (objWord, "Run", objArgBlock))
00020 }
00021 
00022 void setRowFontNormalNextRow () {
00023    clear objArgBlock
00024    put (objArgBlock, "MacroName", "setRowFontNormalNextRow")
00025    checkRes (oleMethod (objWord, "Run", objArgBlock))
00026 }
00027 void setRowFormatNormal() {
00028    clear objArgBlock
00029    put (objArgBlock, "MacroName", "setRowFormatNormal")
00030    checkRes (oleMethod (objWord, "Run", objArgBlock))
00031 }
00032 
00033 int str2int(string s){
00034     int         r = 0
00035     int         l = length(s)
00036     int         c
00037     for (i = l - 1; i > -1; i--){
00038         c = intOf(s[i])
00039         if (c > 57 or c < 48) return -1
00040         r = r + (c - 48) * intOf((real 10.0) ^ realOf(l - i - 1))
00041     }
00042     return r
00043 } // 
00044 
00045 /* ****************************************Excel related functions*************************
00046 
00047 ******************************************************************************************/
00048 string new_col_group( string s1, string s2)
00049 {
00050         string strResult
00051 
00052         if (s1 == "")
00053         {
00054                 strResult = s2
00055         }
00056         else
00057         {
00058                 strResult = s1 "\n" s2
00059         }
00060 
00061         return strResult
00062 } // new_col_group
00063 
00064 string ExcelAlphaCol(int col)
00065 {
00066         string strResult
00067 
00068         if (col < 1)
00069         {
00070                 strResult = "A"
00071         }
00072         else if ( col <= 26 )
00073         {
00074                 strResult = charOf( intOf( 'A' ) + col - 1)""
00075         }
00076         else
00077         {
00078                 strResult = ExcelAlphaCol(col/26) ExcelAlphaCol(col%26)
00079         }
00080         return strResult
00081 } // ExcelAlphaCol
00082 
00083 
00084 string ExcelAddress( int col, int row )
00085 {
00086         string strResult
00087 
00088         strResult = ExcelAlphaCol(col)"" row ""
00089 
00090         return strResult
00091 } //ExcelAddress
00092 
00093 
00094 string ExcelRowAddress( int rowStart, int rowEnd ) {
00095    return "$" rowStart ":" "$" rowEnd ""
00096 }
00097 
00098 string ExcelColAddress( int colStart, int colEnd ) {
00099    return "$" ExcelAlphaCol(colStart) ":" "$" ExcelAlphaCol(colEnd) ""
00100 }
00101 /* **************************************************************************
00102 Function : ExcelAvailable()
00103 description:  to check the availability of the excel file
00104 *********************************************************************************/
00105 bool ExcelAvailable()
00106 {
00107         bool is_available = false
00108 
00109         if ( null objExcel)
00110         {
00111                 is_available = false
00112         }
00113         else
00114         {
00115                 is_available = true
00116         }
00117 
00118         return is_available
00119 } 
00120 /* **************************************************************************
00121 Function : ExcelSetVisible()
00122 description:  to make the excel file visible only if it exists
00123 *********************************************************************************/
00124 void ExcelSetVisible( bool bVisible )
00125 {
00126   if (ExcelAvailable())
00127   {
00128         olePut( objExcel, "Visible", bVisible )
00129   }
00130 } // ExcelSetVisible
00131 
00132 /* **************************************************************************
00133 Function : ExcelInit()
00134 description:  Initialize the excel application, get the workbook, worksheet and make it active
00135 *********************************************************************************/
00136 void ExcelInit(bool bVisible)
00137 {
00138 
00139         OleAutoArgs objArgBlock = create
00140         OleAutoObj objExcelCell = null
00141 
00142         objExcel = oleCreateAutoObject( "Excel.Application" )
00143 
00144     if (null objExcel) {
00145         ack "Unable to communicate with Excel!\nIs it installed?"
00146     }
00147     else
00148     {
00149         ExcelSetVisible( bVisible)
00150         oleGet( objExcel, "Workbooks", objWorkbooks )
00151 
00152     if (null objWorkbooks) {
00153         ack "Unable to get workbooks !"
00154     }
00155 
00156 
00157         oleMethod( objWorkbooks, "Add" )
00158         oleGet( objExcel, "ActiveWorkbook", objWorkbook )
00159         if (null objWorkbook) {
00160                 ack "Unable to get workbook !"
00161         }
00162 
00163 
00164         clear( objArgBlock )
00165         put( objArgBlock, 1 )   // 1st sheet
00166         oleGet( objWorkbook, "Sheets", objArgBlock, objSheet)
00167     if (null objSheet) {
00168         ack "Unable to get sheet !"
00169     }
00170         oleMethod( objSheet, "Activate" )
00171 
00172         delete objArgBlock
00173     }
00174 } // ExcelInit
00175 
00176 
00177 OleAutoObj ExcelNewSheet(string sSheetName){
00178     OleAutoArgs objArgBlock = create
00179     OleAutoObj  objWorksheets
00180     oleGet(objWorkbook, "Sheets", objWorksheets)
00181     oleMethod(objWorksheets, "Add")
00182     clear objArgBlock
00183     put (objArgBlock, 1)
00184     oleGet( objWorkbook, "Sheets", objArgBlock, objSheet)
00185     olePut(objSheet, "Name", sSheetName)
00186     delete objArgBlock
00187     return objSheet
00188 }
00189 void ExcelColAutoFit(int colStart, int colEnd )
00190 {
00191   OleAutoArgs objArgBlock = create
00192   OleAutoObj objExcelCell = null
00193   OleAutoObj objRange = null
00194   OleAutoObj objColumns = null
00195 
00196   put( objArgBlock, ExcelColAddress(colStart, colEnd) )
00197   oleGet( objSheet, "Range", objArgBlock, objRange )
00198   oleGet( objRange, "Columns",  objColumns )
00199   olePut( objColumns, "AutoFit",true)
00200 }
00201 
00202 void ExcelColShrinkToFit(int colStart, int colEnd )
00203 {
00204   OleAutoArgs objArgBlock = create
00205   OleAutoObj objExcelCell = null
00206   OleAutoObj objRange = null
00207   OleAutoObj objColumns = null
00208 
00209   put( objArgBlock, ExcelColAddress(colStart, colEnd) )
00210   oleGet( objSheet, "Range", objArgBlock, objRange )
00211   olePut( objRange, "ShrinkToFit",true )
00212 }
00213 
00214 
00215 
00216 void ExcelSelectCol(int colStart, int colEnd )
00217 {
00218   OleAutoArgs objArgBlock = create
00219   OleAutoObj objExcelCell = null
00220   OleAutoObj objRange = null
00221   OleAutoObj objColumns = null
00222 
00223   put( objArgBlock, ExcelColAddress(colStart, colEnd) )
00224   oleGet( objSheet, "Range", objArgBlock, objRange )
00225   oleGet( objRange, "Columns",  objColumns )
00226   //oleMethod( objRange, "Select" )
00227   //olePut( objRange, "ShrinkToFit",true )
00228   olePut( objColumns, "AutoFit",true)
00229     //Selection.Columns.AutoFit
00230 } 
00231 
00232 void ExcelPut( int col, int row, string content )
00233 {
00234   OleAutoArgs objArgBlock = create
00235   OleAutoObj objExcelCell = null
00236   int l=length(content)
00237 
00238   if (ExcelAvailable())
00239   {
00240         clear( objArgBlock )
00241         put( objArgBlock, ExcelAddress(col,row) )
00242         oleGet( objSheet, "Range", objArgBlock, objExcelCell )
00243         if (null objExcelCell)
00244         {
00245                 ack "NULL cell ("col","row")"
00246         }
00247         else
00248         {
00249                 //enclose string in " if value starts with =, - or a digit
00250                 if ( null content)
00251                 {
00252                         // do nothing
00253                 }
00254                 else if (l < 20 && matches("^[=0-9.,e-]+$", content))
00255                 {
00256                         olePut( objExcelCell, "value", "=\""content"\"" )
00257                 }
00258                 else if (content[0] == '\'')
00259                 {
00260                         olePut( objExcelCell, "value", "'"content )
00261                 }
00262                 else
00263                 {
00264                         olePut( objExcelCell, "value", content )
00265                 }
00266         }
00267         delete objArgBlock
00268   }
00269 } // ExcelPut
00270 
00271 
00272 /* **************************************************************************
00273 Function : clearWordState()
00274 description:  
00275 *********************************************************************************/
00276 void wordMergeRowVBA(){
00277 
00278     OleAutoObj          Cells_ole
00279     OleAutoObj          Selection_ole
00280 
00281 
00282     oleMethod(objSel, "SelectRow")
00283     oleGet(objSel, "Cells", Cells_ole)
00284     oleMethod(Cells_ole, "Merge")
00285 }
00286 /* **************************************************************************
00287 Function : clearWordState()
00288 description:  
00289 *********************************************************************************/
00290 void clearWordState() 
00291 {
00292     exportEndProgress
00293     checkRes(olePut(objWord,cPropertyScreenUpdating,true))
00294         halt
00295 }
00296 /* **************************************************************************
00297 Function : logError()
00298 description:  error logging is captured
00299 *********************************************************************************/
00300 void logError(string errDescription, string errMessage, Object o) 
00301 {
00302     errorLogBuffer += errDescription
00303     errorLogBuffer += " failed with error message: '"
00304     errorLogBuffer += errMessage
00305     errorLogBuffer += "' for object "
00306     errorLogBuffer += (identifier o)
00307     errorLogBuffer += "\n\n"
00308 }
00309 /* **************************************************************************
00310 Function : vbaCheckRes()
00311 description:  verification method used for OLE methods
00312 *********************************************************************************/
00313 void vbaCheckRes(string res) 
00314 {
00315     if (res != "") 
00316     {
00317 
00318         ack "OLE method failed: " res
00319         clearWordState
00320     }
00321 }
00322 
00323 /* **************************************************************************
00324 Function : collapseSelection()
00325 description: 
00326 *********************************************************************************/
00327 void collapseSelection() 
00328 {
00329     clear objArgBlock
00330     put(objArgBlock, cParamDirection, wdCollapseEnd)
00331     vbaCheckRes(oleMethod(objSel, cMethodCollapse, objArgBlock))
00332 }
00333 /* **************************************************************************
00334 Function : collapseSelectionBackwards()
00335 description: 
00336 *********************************************************************************/
00337 void collapseSelectionBackwards() 
00338 {
00339     clear objArgBlock
00340     put(objArgBlock, cParamDirection, wdCollapseStart)
00341     vbaCheckRes(oleMethod(objSel, cMethodCollapse, objArgBlock))
00342 }
00343 
00344 /* **************************************************************************
00345 Function : vbaGetStyleName()
00346 description:  takes style number as input, resolves the styles, style, style name and returns the same
00347 *********************************************************************************/
00348 string vbaGetStyleName(OleAutoObj objDoc, int styleNumber) 
00349 {
00350     OleAutoObj objStyles = null
00351     OleAutoObj objStyle = null
00352     string styleName = null
00353 
00354     vbaCheckRes(oleGet(objDoc, cPropertyStyles, objStyles)) // styles is a collection of all style
00355 
00356     if (null objStyles) 
00357     {
00358         ack "Unable to get handle on styles collection"
00359         clearWordState
00360     }
00361 
00362     clear objArgBlock
00363     put(objArgBlock, styleNumber)
00364         
00365     vbaCheckRes(oleMethod(objStyles, cMethodItem, objArgBlock, objStyle)) // fetch the style number
00366     
00367     if (null objStyle) 
00368     {
00369         ack "Unable to get handle on style"
00370         clearWordState
00371     }
00372 
00373     vbaCheckRes(oleGet(objStyle, cPropertyNameLocal, styleName))// fetch the style name
00374     
00375     if (null styleName) 
00376     {
00377         ack "Unable to get style name"
00378         clearWordState
00379     }
00380 
00381     closeIfNonNull objStyle
00382     closeIfNonNull objStyles
00383     
00384     return styleName
00385 }
00386 /* **************************************************************************
00387 Function : wordCheckVersion ()
00388 description: get the word document's version, either by takingthe existing word, or by creating a new one
00389 *********************************************************************************/
00390 string wordCheckVersion() 
00391 {
00392     objArgBlock = create
00393 
00394     if (null objArgBlock) 
00395     {
00396         ack "Unable to create argument block.  Low memory?"
00397         return ""
00398     }
00399     // Get Word object
00400     objWord = oleGetAutoObject(cObjWordApplication) // get the word application
00401     
00402     if (null objWord) 
00403     {
00404         objWord = oleCreateAutoObject(cObjWordApplication) // else create a new word object
00405         }
00406   
00407         string versionString
00408         vbaCheckRes(oleGet(objWord,cPropertyVersion, versionString)) //version of the word document
00409         return versionString
00410         
00411 }
00412 
00413 /* **************************************************************************
00414 Function : wordPreChecksVBA ()
00415 description: to make the word document visible, active and set the control
00416 *********************************************************************************/
00417 bool wordPreChecksVBA() 
00418 {
00419     Object curro = current Object
00420     m = current Module
00421 
00422     // Make Word visible
00423     if (!doStyleMapping)
00424     {
00425         makeVisible objWord
00426     }
00427 
00428     // Get documents collection
00429     checkRes(oleGet(objWord,cPropertyDocuments,objDocs)) //get the document
00430     
00431     if (null objDocs) 
00432     {
00433         ack "Unable to get Documents collection"
00434         return false
00435     }
00436         
00437     clear objArgBlock
00438     put(objArgBlock,TemplateFileName_s)
00439     checkRes(oleMethod(objDocs,cMethodAdd,objArgBlock))
00440   
00441    // Get a handle on the document
00442     checkRes(oleGet(objWord,cPropertyActiveDocument,objDoc)) //activate the document
00443     if (null objDoc) 
00444     {
00445         ack "Unable to get active document"
00446         halt
00447     }
00448 
00449     // Get a handle on the selection object
00450     checkRes(oleGet(objWord,cPropertySelection,objSel)) //select the object in the document
00451     
00452     if (null objSel) 
00453     {
00454         ack "Unable to get selection object"
00455         halt
00456     }
00457     // Get a handle on the tables collection
00458     checkRes(oleGet(objDoc,cPropertyTables,objTables)) //defines the set of all tables defined in the document
00459     
00460     if (null objTables) 
00461     {
00462         ack "Unable to get tables collection"
00463         halt
00464     }
00465 
00466     return true
00467 }
00468 /* **************************************************************************
00469 Function : getWordStyleNames ()
00470 description: to get the Fontname, style name etc
00471 *********************************************************************************/
00472 void getWordStyleNames(OleAutoObj objDoc) 
00473 {
00474     OleAutoObj objStyles = null
00475     OleAutoObj objStyle = null
00476     OleAutoObj objFont = null
00477     OleAutoObj objParaFormat = null
00478     OleAutoObj objListTemplate = null
00479         
00480     string styleName = null
00481     string fontName = null
00482         
00483     int styleType = 0
00484     int leftIndent = 0
00485         int count, stylesToCheck
00486     
00487         wordStyleNames = create
00488     wordStyleFonts = create
00489     
00490     vbaCheckRes(oleGet(objDoc, cPropertyStyles, objStyles))
00491 
00492     if (null objStyles) 
00493     {
00494         ack "Unable to get handle on styles collection"
00495         clearWordState
00496     }
00497 
00498     vbaCheckRes(oleGet(objStyles, cPropertyCount, stylesToCheck))
00499 
00500     for (count = 1; count <= stylesToCheck; count++) 
00501     {
00502         clear objArgBlock
00503         put(objArgBlock, count)
00504 
00505         vbaCheckRes(oleMethod(objStyles, cMethodItem, objArgBlock, objStyle))
00506     
00507         if (null objStyle) 
00508         {
00509             ack "Unable to get handle on style"
00510             clearWordState
00511         }
00512 
00513         // Don't use character styles
00514         vbaCheckRes(oleGet(objStyle, cPropertyType, styleType))
00515         
00516         if (styleType != wdStyleTypeParagraph) 
00517         {
00518             closeIfNonNull objStyle
00519             continue
00520         }
00521 
00522         styleName = ""
00523         fontName = ""
00524         leftIndent = 0
00525 
00526         vbaCheckRes(oleGet(objStyle, cPropertyNameLocal, styleName))
00527 
00528         if (null styleName) 
00529         {
00530             ack "Unable to get style name"
00531             clearWordState
00532         }
00533         put(wordStyleNames,noWordStyles,styleName)
00534                 
00535                 oleGet(objStyle, cPropertyListTemplate, objListTemplate)
00536     
00537         oleGet(objStyle, cPropertyParagraphFormat, objParaFormat)
00538         closeIfNonNull objParaFormat
00539 
00540         // get font name so we can set the correct default font
00541         vbaCheckRes(oleGet(objStyle, cPropertyFont, objFont))
00542 
00543         if (null objFont) 
00544         {
00545             ack "Unable to get handle on font"
00546             clearWordState
00547         }
00548 
00549         vbaCheckRes(oleGet(objFont, cPropertyName, fontName))
00550 
00551         if (null fontName) 
00552         {
00553             ack "Unable to get font name"
00554             clearWordState
00555         }
00556         
00557         closeIfNonNull objFont
00558         closeIfNonNull objStyle
00559 
00560         put(wordStyleFonts,styleName,fontName)
00561 
00562         noWordStyles++
00563     }
00564 
00565     closeIfNonNull objStyles
00566 
00567     string tempWordStyles[noWordStyles]
00568 
00569     for (count = 0; count < noWordStyles; count++) 
00570     {
00571         find(wordStyleNames, count, tempWordStyles[count])
00572     }
00573     
00574     sort tempWordStyles
00575     delete wordStyleNames
00576     wordStyleNames = create
00577     
00578     for (count = 0; count < noWordStyles; count++) 
00579     {
00580         put(wordStyleNames, count, tempWordStyles[count])
00581     }
00582 }
00583 
00584 /* **************************************************************************
00585 Function : fillStyleNameArrays ()
00586 description: headingstyle and bodystyle are set in string of arrays
00587 *********************************************************************************/
00588 void fillStyleNameArrays() 
00589 {
00590     int count
00591     string styleName
00592 
00593     for (count = 0; count < maxWordLevel; count++) 
00594     {
00595         styleName = vbaGetStyleName(objDoc,wordHeadingStyles[count])
00596         headingStyleNames[count] = styleName
00597     }
00598     
00599     styleName = vbaGetStyleName(objDoc,wdStyleNormal)
00600     
00601     for (count = 0; count < maxWordLevel; count++) 
00602     {
00603         bodyStyleNames[count] = styleName
00604     }
00605 }
00606 
00607 /* **************************************************************************
00608 Function : InitWord ()
00609 description: initialize the word document
00610 *********************************************************************************/
00611 void InitWord()
00612 {
00613         string wordVersion = wordCheckVersion ()
00614     if (wordVersion =="")
00615         {
00616       return
00617     }
00618         wordPreChecksVBA ()
00619         fillStyleNameArrays()
00620         getWordStyleNames objDoc
00621         sStyleNormal = vbaGetStyleName(objDoc, wdStyleNormal)
00622 } 
00623 /* **************************************************************************
00624 Function : UpdateTOC ()
00625 description: To update the table of contents.
00626 *********************************************************************************/
00627 void UpdateTOC(){
00628     
00629     OleAutoObj              Fields_ole
00630     OleAutoArgs             autoArgs        = create
00631     int                     i
00632     
00633         oleGet(objDoc, "Fields", Fields_ole)
00634     oleMethod(Fields_ole, "Update", autoArgs, i)   
00635 }
00636 
00637 
00638 /* **************************************************************************
00639 Function : makeFontTableFromStyle ()
00640 description: get the font name from font skiplist using stylename as key and generate a font table
00641 *********************************************************************************/
00642 
00643 string makeFontTableFromStyle(string styleName)
00644 {
00645 // build a font table with the appropriate default font for the style
00646     string fontName = ""
00647     string defaultFontEntry 
00648     string fontTable
00649 
00650     find(wordStyleFonts, styleName, fontName)
00651 
00652     defaultFontEntry = "{\\f0\\fnil " fontName ";}"
00653     fontTable = fontTableBeginning defaultFontEntry fontTableEnd
00654 
00655     return fontTable
00656 }
00657 
00658 /* **************************************************************************
00659 Function : pasteAndApplyStyle ()
00660 description: pasting of the data (richtext) from doors to word 
00661 *********************************************************************************/
00662 string pasteAndApplyStyle(OleAutoObj objSelection, RTF_string__ s, string styleName)
00663 {
00664         //styleName = vbaGetStyleName(objDoc,wdStyleNormal)
00665         string fontTable = makeFontTableFromStyle(styleName)
00666     setRichClip(s, styleName,fontTable )
00667     return oleMethod(objSelection, cMethodPaste)
00668     
00669 }
00670 
00671 /* **************************************************************************
00672 Function : pasteAndApplyStyle ()
00673 description: pasting of the data (buffer) from doors to word 
00674 *********************************************************************************/
00675 string pasteAndApplyStyle(OleAutoObj objSelection, Buffer b, string styleName)
00676 {
00677         //styleName = vbaGetStyleName(objDoc,wdStyleNormal)
00678         string fontTable = makeFontTableFromStyle(styleName)
00679     setRichClip(b, styleName,fontTable)
00680     return oleMethod(objSelection, cMethodPaste)
00681 }
00682 /* **************************************************************************
00683 Function : endKey ()
00684 description: table of contents will be stored in the begining
00685 without this it will be at the end of the document
00686 *********************************************************************************/
00687 void endKey() 
00688 {
00689     // move past the object
00690     clear objArgBlock
00691     put(objArgBlock, wdStory)
00692     vbaCheckRes(oleMethod(objSel,cMethodEndKey,objArgBlock))
00693 }
00694 
00695 /* **************************************************************************
00696 Function : MakeSection ()
00697 description: make different sections in the document (like headlines, text etc)
00698 *********************************************************************************/
00699 void MakeSection(string Headline_s, string Text_s, string SectionStructure_s, int SectionStructureLevel_i){
00700         /* local declaration */
00701         string              TitleText_s = ""
00702         OleAutoObj          TableOfContents_ole
00703         OleAutoObj          Range_ole
00704         OleAutoArgs         autoArgs                = create
00705         int                 SelStart_i              = 0
00706         int                 SelEnd_i                = 0
00707         string styleName = vbaGetStyleName(objDoc,wdStyleNormal) 
00708         oleGet(objDoc, "TablesOfContents", TableOfContents_ole) 
00709         
00710         /* make Section Headline */
00711         if (Headline_s != ""){
00712         TitleText_s = Headline_s
00713         pasteAndApplyStyle(objSel, richText Headline_s, styleName)
00714     }
00715     oleMethod(objSel, "TypeParagraph")
00716         oleGet(objSel, "Range", Range_ole)
00717     clear autoArgs
00718     put (autoArgs, "Range", Range_ole)
00719     put (autoArgs, "Level", SectionStructureLevel_i + 1)
00720     put (autoArgs, "Entry", TitleText_s)
00721     oleMethod(TableOfContents_ole, "MarkEntry", autoArgs)         
00722     endKey()
00723         if (Text_s != ""){
00724         pasteAndApplyStyle(objSel, richText Text_s, bodyStyleNames[0])
00725         oleMethod(objSel, "TypeParagraph")        
00726     }
00727     
00728 }
00729 
00730 
00731 string appName ="VBScript.RegExp"
00732 OleAutoObj RegExpObj = oleCreateAutoObject(appName)
00733 if (null (RegExpObj)) error "Cannot connect to OLE Application >"appName"<!"
00734 
00735 OleAutoObj MatchesColl
00736 OleAutoObj MatchObj
00737 OleAutoObj SubMatchesColl
00738 OleAutoArgs args = create
00739 Regexp Escapes = regexp "(\"|\\(|\\)|\\[|\\]|\\.|\\^|\\||\\$|\\+|\\*|\\\\|?)"
00740 
00741 void addEscapesForRegexp(string &txt) {
00742         if ( txt == "" ) return
00743         
00744         Buffer b = create
00745         int i = 0
00746 
00747         while ( Escapes txt[i:] ) {
00748                 b += txt[i:i+start(0)-1]
00749                 if( txt[i+start(0):i+end(0)] =="\\\\") b += "\\\\\\\\"
00750                 elseif ( txt[i+start(0):i+end(0)] == txt[i:][match 0] ) b += "\\" txt[i+start(0):i+end(0)]
00751                 else b += txt[i+start(0):i+end(0)]
00752                 i += (end 0)+1
00753         }
00754         b += txt[i:]
00755         txt = stringOf b
00756         delete(b)
00757 }
00758 
00759 string VBReplace(string inStr, FindStr, RepStr, bool IgnoreCase) {
00760         string Str=""
00761         clear args
00762         addEscapesForRegexp(FindStr)
00763         olePut(RegExpObj,"Pattern",FindStr)
00764         olePut(RegExpObj,"IgnoreCase",IgnoreCase)
00765         put(args, inStr)
00766         put(args, RepStr)
00767         oleMethod(RegExpObj,"Replace",args,Str)
00768         return Str
00769 }
00770 
00771 void ReturnSubMatches( Skip PassedSkip, string inStr, FindPattern, int SubMatchNum, bool IgnoreCase) {
00772         string SubMatch
00773         clear args
00774         olePut(RegExpObj,"IgnoreCase",IgnoreCase)
00775         olePut(RegExpObj,"Global",true)
00776         int NumOfMatches=0,i,j=0
00777 
00778         olePut(RegExpObj,"Pattern",FindPattern)
00779         put(args, inStr)
00780         oleMethod(RegExpObj,"Execute",args,MatchesColl)
00781         oleGet(MatchesColl,"Count",NumOfMatches)
00782         
00783         if(NumOfMatches==0) return
00784         
00785         for(i=0;i<NumOfMatches;i++) {
00786                 clear args; put(args,i)
00787             oleGet(MatchesColl,"Item",args,MatchObj)
00788             
00789             oleGet(MatchObj,"SubMatches",SubMatchesColl)
00790             clear args; put(args,SubMatchNum)
00791             oleGet(SubMatchesColl,"Item",args,SubMatch)
00792             
00793             if(!null SubMatch) {
00794                 if(!find(PassedSkip,SubMatch)) {
00795                                 put(PassedSkip,SubMatch,SubMatch)
00796                         }
00797                 }
00798         }
00799         MatchesColl =null
00800         MatchObj =null     
00801         SubMatchesColl=null
00802 }
00803 
00804 string ReturnFirstSubMatch( string inStr, FindPattern, int SubMatchNum, bool IgnoreCase) {
00805         string SubMatch
00806         clear args
00807         olePut(RegExpObj,"IgnoreCase",IgnoreCase)
00808         olePut(RegExpObj,"Global",false)
00809         int NumOfMatches=0,i,j=0
00810 
00811         olePut(RegExpObj,"Pattern",FindPattern)
00812         put(args, inStr)
00813         oleMethod(RegExpObj,"Execute",args,MatchesColl)
00814         oleGet(MatchesColl,"Count",NumOfMatches)
00815         if(NumOfMatches==0) return ""
00816         clear args; put(args,0)
00817     oleGet(MatchesColl,"Item",args,MatchObj)
00818     
00819     oleGet(MatchObj,"SubMatches",SubMatchesColl)
00820     clear args; put(args,SubMatchNum)
00821     oleGet(SubMatchesColl,"Item",args,SubMatch)
00822     
00823     if(null SubMatch) return ""
00824         
00825         MatchesColl =null
00826         MatchObj =null     
00827         SubMatchesColl=null
00828         return SubMatch
00829 }
00830 
00831 string ReturnFirstMatch( string inStr, FindPattern, bool IgnoreCase) {
00832         string MatchStr
00833         clear args
00834         olePut(RegExpObj,"IgnoreCase",IgnoreCase)
00835         olePut(RegExpObj,"Global",false)
00836         int NumOfMatches=0,i,j=0
00837 
00838         olePut(RegExpObj,"Pattern",FindPattern)
00839         put(args, inStr)
00840         oleMethod(RegExpObj,"Execute",args,MatchesColl)
00841         oleGet(MatchesColl,"Count",NumOfMatches)
00842         if(NumOfMatches==0) return ""
00843         
00844         clear args; put(args,0)
00845     oleGet(MatchesColl,"Item",args,MatchObj)
00846     oleGet(MatchObj,"Value",MatchStr)
00847         if(null MatchStr) return ""
00848 
00849         MatchesColl =null
00850         MatchObj =null     
00851         return MatchStr
00852 } 
00853 
00854 
00855 void ReturnMatches( Skip PassedSkip, string inStr, FindPattern, bool IgnoreCase) {
00856         string MatchStr
00857         clear args
00858         olePut(RegExpObj,"IgnoreCase",IgnoreCase)
00859         olePut(RegExpObj,"Global",true)
00860         int NumOfMatches=0,i,j=0
00861 
00862         olePut(RegExpObj,"Pattern",FindPattern)
00863         put(args, inStr)
00864         oleMethod(RegExpObj,"Execute",args,MatchesColl)
00865         oleGet(MatchesColl,"Count",NumOfMatches)
00866         
00867         if(NumOfMatches==0) return
00868         
00869         for(i=0;i<NumOfMatches;i++) {
00870                 clear args; put(args,i)
00871             oleGet(MatchesColl,"Item",args,MatchObj)
00872             
00873             oleGet(MatchObj,"Value",MatchStr)
00874             if(!null MatchStr) {
00875                 if(!find(PassedSkip,MatchStr)) {
00876                                 put(PassedSkip,MatchStr,MatchStr)
00877                         }
00878                 }
00879         }
00880         MatchesColl =null
00881         MatchObj =null     
00882 }
00883 
00884 void printFilterError (string input, string err){
00885         ack "ERROR on parsing filter string '"input"' (please redo your filter): \n"err"\n"
00886         FilterError = true
00887 }
00888 
00889 
00890 void DeTokenizeString(string &inp) {
00891         string Tok, OrigStr
00892         for OrigStr in TokenSkip do {
00893                 Tok = (string key TokenSkip)
00894                 inp = VBReplace(inp, Tok, OrigStr,false)
00895         }
00896 }
00897 
00898 
00899 // function to parse a "simple" Filter, that means, which is not combined of other Filters
00900 Filter parseSimpleFilter (string input){
00901         if(ProcessTokens) DeTokenizeString(input)
00902         
00903         if (REcolumnFilter input){ // any type of "Column" filters
00904                 string params  = input[match 3]
00905                 string colName = input[match 1]
00906                 string val       = input[match 2]
00907                 if (null params)                                                                                 return column (colName, val, false, false)
00908                 else if (params == " (with regexps and case sensitive)") return column (colName, val, true, true)
00909                 else if (params == " (with regexps)")                                   return column (colName, val, false, true)
00910                 else if (params == " (case sensitive)")                           return column (colName, val, true, false)
00911                 else{
00912                         printFilterError (input,  "unrecognized parameter to Column Filter >>"params"<<\n"//-
00913                                   "possible values are : '(with regexps)', '(case sensitive)', '(with regexps and case sensitive)' or nothing")
00914                 }
00915         }
00916         else if (REcontainsFilter input){ // any type of Attribute contains filter
00917                 if (input[match 4] == "[with regexps]") return contains (attribute input[match 1], input[match 3])
00918                 else if (null input[match 4])
00919                                 return contains (attribute input[match 1], input[match 3], input[match 2] == "Contains")
00920                 else{
00921                         printFilterError (input, "unrecognized parameter to Contains Filter >>"input[match 4]"<<\n"//-
00922                                   "possible values are : '[with regexps]' or nothing")
00923                 }
00924         }
00925         else if (REcontentsFilter input){ // any type of "Any Text Attribute" contains filter
00926                 if (input[match 3]  == " [with regexps]") return contents (input[match 2])
00927                 else if (null input[match 3])                   return contents (input[match 2], input[match 1] == "Contains")
00928                 else{
00929                         printFilterError (input, "unrecognized parameter to Contains in any Text Attribute Filter >>"input[match 3]"<<\n"//-
00930                                   "possible values are : '[with regexps]' or nothing")
00931                 }
00932         }
00933         else if (REmultiValueFilter input){ // both types of filter for multivalued attributes
00934                 if (input[match 2] == "excludes")
00935                   return excludes (attribute input[match 1], input[match 3])
00936                 else return includes (attribute input[match 1], input[match 3])
00937         }
00938         else if (REemptyFilter input){ // is Empty and is not Empty filters
00939                 if (null input[match 2])
00940                   return isNull (attribute input[match 1])
00941                 else return notNull (attribute input[match 1])
00942         }
00943         else if (REcompareFilter input){ // any type of comarison filters
00944                 string cmd = input[match 2]
00945                 string thisAtt = input[match 1]
00946                 if (thisAtt == "Object Number" or exists attribute thisAtt) {
00947                         if        (cmd == ">=") return (attribute input[match 1] >= input[match 3])
00948                         else if (cmd == ">")  return (attribute input[match 1] >  input[match 3])
00949                         else if (cmd == "<=") return (attribute input[match 1] <= input[match 3])
00950                         else if (cmd == "<")  return (attribute input[match 1] <  input[match 3])
00951                         else if (cmd == "!=") return (attribute input[match 1] != input[match 3])
00952                         else if (cmd == "==") return (attribute input[match 1] == input[match 3])
00953                 }
00954                 else {
00955                         printFilterError (input, "Attribute '" thisAtt "' does not exist")
00956                 }
00957         }
00958         else if (REcurrentObjectFilter input){ // filter that includes/excludes current Object  respectively any Object
00959                 Object ThisObj =object (intOf (input[match 2]))
00960                 if (null ThisObj) {
00961                         printFilterError (input, "Object " input[match 2] " no longer exists.")
00962                 }
00963                 current = ThisObj
00964                 if (input[match 1] == "Exclude") return excludeCurrent
00965                 else return includeCurrent
00966         }
00967         else if (REleavesFilter input){ // filter to show only leaves
00968                 if (null input[match 1]) return includeLeaves
00969                 else return excludeLeaves
00970         }
00971         else if (RElinksFilter input){ // any Link related filters
00972                 LinkFilter lf
00973                 if (input[match 2] == "in-") lf = linkFilterIncoming
00974                 else if(input[match 2] == "out-") lf = linkFilterOutgoing
00975                 else lf = linkFilterBoth
00976                 if (null input[match 1]) return hasLinks (lf, input[match 3])
00977                 else return hasNoLinks (lf, input[match 3])
00978         }
00979         else printFilterError (input, "unrecognized Filter string")
00980         return null
00981 }
00982 
00983 
00984 Filter ProcessFilterParts() {
00985         int i,j,k, temp
00986         string str, FiltString
00987         bool b
00988         int ParentArray[FilterCount]
00989 //      Stream out = write "C:\\Temp\\Debug.tsv"
00990 //      out << "String\tOperator\tParent\tID\tSimple\tLevel\n"
00991         for(i=0;i<FilterCount;i++) {
00992 //      str = (string get(FilterArray,i,STRING))  // cast get as string
00993 //      out << str "\t"
00994 //              temp = (int get(FilterArray,i,OPERATOR))
00995 //              out << Ops[temp] "\t"
00996                 temp = (int get(FilterArray,i,PARENT))
00997                 ParentArray[i]=temp
00998 //              out << temp "\t" i "\t"
00999 //              b =     (bool get(FilterArray,i,SIMPLE))
01000 //              out << b "\t"
01001 //              temp =(int get(FilterArray,i,LEVEL))
01002 //              out << temp "\n"
01003         }
01004 //      close out
01005         
01006         int ThisLev, ThisOp, ThisPar, ParOp
01007         bool IsItSimple
01008         Filter ThisFilt
01009         
01010         //check for simplest case
01011         IsItSimple = (bool get(FilterArray,0,SIMPLE))
01012         if (IsItSimple) return parseSimpleFilter(WholeThing)
01013         
01014         //make all the simple filters on the first pass
01015         for(i=DeepestLevel;i>0;i--) {
01016                 for(j=0;j<FilterCount;j++) {
01017                         ThisLev = (int get(FilterArray,j,LEVEL))
01018                         if(ThisLev ==i) {
01019                                 IsItSimple = (bool get(FilterArray,j,SIMPLE))
01020                                 //look for simple filters and make them
01021                                 if(IsItSimple) {
01022                                         FiltString =(string get(FilterArray,j,STRING))
01023                                         ThisFilt =parseSimpleFilter(FiltString)
01024                                         put(FilterArray, ThisFilt, ParentArray[j], FILTER)
01025                                 }
01026                         }
01027                 }
01028         }
01029 
01030 
01031         //combine the simple filters on the second pass
01032         Filter FirstPart, SecondPart
01033         for(k=DeepestLevel;k>0;k--) {
01034                 for(i=0;i<FilterCount;i++) {
01035                         ThisLev = (int get(FilterArray,i,LEVEL))
01036                         if(ThisLev ==k) {
01037                                 ThisOp = (int get(FilterArray,i,OPERATOR))
01038                                 //look for AND find object with same parent and combine
01039                                 //object with same parent will always be below object with operator
01040                                 j=i+1
01041                                 FirstPart=(Filter get(FilterArray,i,FILTER))
01042                                 //cope with meaningless brackets by looking for a filter at the next level down
01043                                 //the following is a semi frig
01044                                 if(null FirstPart and ThisOp>0) {
01045                                         FirstPart =(Filter get(FilterArray,i+1,FILTER))
01046                                         int TempLev= (int get(FilterArray,i+1,LEVEL))
01047                                         if((null FirstPart) or (TempLev-1!=ThisLev)) {
01048                                                 ack "null filter passed can't recover"
01049                                                 halt
01050                                         }
01051                                 }
01052                                 if(ThisOp == ANDop or ThisOp == ORop) {
01053                                         while(j<FilterCount) {
01054                                                 if(ParentArray[i]==ParentArray[j]) {
01055                                                         SecondPart =(Filter get(FilterArray,j,FILTER))
01056                                                         break
01057                                                 }
01058                                                 j++
01059                                         }
01060                                         //cope with meaningless brackets by looking for a filter at the next level down
01061                                         //the following is a semi frig
01062                                         if(null SecondPart) {
01063                                                 SecondPart =(Filter get(FilterArray,j+1,FILTER))
01064                                                 int TempLev= (int get(FilterArray,j+1,LEVEL))
01065                                                 if((null SecondPart) or (TempLev-1!=ThisLev)) {
01066                                                         ack "null filter passed can't recover"
01067                                                         halt
01068                                                 }
01069                                         }
01070                                         
01071                                         if(ThisOp == ANDop) ThisFilt = FirstPart && SecondPart
01072                                         else ThisFilt = FirstPart || SecondPart
01073                                         if(ParentArray[i]==-1) put(FilterArray, ThisFilt, 0, FILTER)
01074                                         else put(FilterArray, ThisFilt, ParentArray[i], FILTER)
01075                                         
01076                                 }
01077                                 elseif(ThisOp == NOTop) {
01078                                         ThisFilt = ! FirstPart
01079                                         if(ParentArray[i]==-1) put(FilterArray, ThisFilt, 0, FILTER)
01080                                         else put(FilterArray, ThisFilt, ParentArray[i], FILTER)
01081 
01082                                 }
01083                                 elseif(ThisOp == NONE) {
01084                                 //do nothing except for the mental case of two sets of meaningless brackets
01085 //                                      if(ParentArray[i]!=-1) {
01086 //                                              ParOp =(int get(FilterArray,ParentArray[i],OPERATOR))
01087 //                                              if(ParOp == NONE) put(FilterArray, ThisFilt, ParentArray[i], FILTER)
01088 //                                      }
01089                                 }
01090                                 else {
01091                                         ack "error in operator part"
01092                                         halt
01093                                 }
01094 
01095                         }
01096                 }
01097         }
01098         //Final filter will or should! rise to the top element
01099         ThisFilt =(Filter get(FilterArray,0,FILTER))
01100         return ThisFilt
01101 }
01102 
01103 
01104 //attributes and enumerations can have brackets in which buggers things up totally
01105 void TokenizeString(string &input) {
01106         string Str = input
01107         bool Changed, dummy=false
01108         AttrDef ad
01109         AttrType at
01110         AttrBaseType abt
01111         int j,i
01112         string s, ThisToken, AtName
01113         char c
01114 
01115         for ad in current Module do {
01116                 at = ad.type
01117                 abt = at.type
01118                 if(ad.system) continue
01119                 
01120                 //process attribute names (they can have brackets)
01121                 AtName= ad.name
01122                 if (DodgyChars AtName) {
01123                         Changed=false
01124                         ThisToken = "FCU" NumberOfTokens "K"
01125                         NumberOfTokens++
01126                         //need to do a simple replace but DOORS is shit at regexps it just won't work
01127                         //hence call a vbs script what an ass!
01128                         input = VBReplace(input, AtName, ThisToken, false)
01129 
01130                         //add to skip with token key
01131                         if (Str!=input) {
01132                                 ProcessTokens=true
01133                                 put(TokenSkip,ThisToken, AtName)
01134                         }
01135                 }
01136 
01137                 if (abt == attrEnumeration) {
01138                         //process attribute enumerations (the main culprits)
01139                         for (j=0; j<(at.size); j++){
01140                                 s=at.strings[j]
01141                                 if (DodgyChars s) {
01142                                         Changed=false
01143                                         ThisToken = "FCU" NumberOfTokens "K"
01144                                         NumberOfTokens++
01145                                         //need to do a simple replace but DOORS can't do regexps with escape chars in the middle
01146                                         //it just won't work, hence call a vb script: what an ass!
01147                                         input = VBReplace(input, s, ThisToken, false)
01148 
01149                                         //add to skip with token key
01150                                         if (Str!=input) {
01151                                                 ProcessTokens=true
01152                                                 put(TokenSkip,ThisToken, s)
01153                                         }
01154                                 }
01155                         }
01156                 }
01157         }
01158 }
01159 
01160 void ProcessFilter (string b, int Thelevel, int Parent){
01161         int bCount = 0, i=0
01162         bool isInString = false
01163         Filter leftFilter = null
01164         int stopAt = length b
01165         bool NoBrackets=true
01166         int StartAt
01167         
01168         while (i < stopAt){
01169                 if (b[i] == '\'' && (i == 0 || b[i-1] != '\\')) isInString = !isInString
01170                 if (isInString == false){
01171                         if (b[i] == '('){ // found brackets
01172                                 StartAt =i
01173                                 NoBrackets=false
01174                                 bCount++
01175                                 i = i+1
01176                                 
01177                                 while (bCount>0 && i < stopAt){
01178                                         if (b[i] == '\'' && (i == 0 || b[i-1] != '\\')) isInString = !isInString
01179                                         if (!isInString){
01180                                                 if (b[i] == '(') bCount++
01181                                                 if (b[i] == ')') bCount--
01182                                         }
01183                                         i++
01184                                 }
01185                                 //add the string to the array
01186                                 put(FilterArray, Thelevel, FilterCount, LEVEL)
01187                                 put(FilterArray, b[StartAt+1:i-2], FilterCount, STRING)
01188                                 put(FilterArray, false, FilterCount, SIMPLE)
01189                                 put(FilterArray, Parent, FilterCount, PARENT)
01190                                 put(FilterArray, null, FilterCount, FILTER)
01191                                 
01192                                 //look for NOT this is only relevant at the start of the string
01193                                 if (b[0:2] == "NOT") {
01194                                         put(FilterArray, NOTop, FilterCount, OPERATOR)
01195                                 }
01196                                 //look for an AND/OR after the brackets
01197                                 elseif (i < stopAt-2 && (b[i:i+2]== "AND" or b[i+1:i+3] == "AND")){
01198                                         put(FilterArray, ANDop, FilterCount, OPERATOR)
01199                                 }
01200                                 elseif (i < stopAt-2 && (b[i:i+1] == "OR" or b[i+1:i+2] == "OR")){ // priority 4
01201                                         put(FilterArray, ORop, FilterCount, OPERATOR)
01202                                 }
01203                                 else {
01204                                         put(FilterArray, NONE, FilterCount, OPERATOR)
01205                                 }
01206                                 FilterCount++
01207                                 
01208                                 //recurse to next level
01209                                 ProcessFilter(b[StartAt+1:i-2],Thelevel+1, FilterCount-1)
01210                         }
01211                         else i++
01212                 }
01213                 else i++
01214         }
01215 
01216         if (NoBrackets){
01217                 //Simple filter
01218                 put(FilterArray, NONE, FilterCount, OPERATOR)
01219                 put(FilterArray, b, FilterCount, STRING)
01220                 put(FilterArray, Thelevel, FilterCount, LEVEL)
01221                 put(FilterArray, Parent, FilterCount, PARENT)
01222                 put(FilterArray, true, FilterCount, SIMPLE)
01223                 put(FilterArray, null, FilterCount, FILTER)
01224                 FilterCount++
01225         }
01226         if(Thelevel>DeepestLevel) DeepestLevel = Thelevel
01227 }
01228 
01229 Filter parseFilter (string input){
01230         FilterCount=0
01231         DeepestLevel=0
01232         FilterArray = create(1,1)
01233         WholeThing = input
01234         TokenSkip = createString
01235         NumberOfTokens=0
01236         ProcessTokens=false
01237         TokenizeString(input)
01238         //print input
01239         ProcessFilter (input, 1, -1)
01240         Filter F = ProcessFilterParts
01241         delete TokenSkip
01242         delete FilterArray
01243         return F
01244 }
01245 
01246 // END   INCLUDE 
01247 
01248   /* **************************************************************************
01249 end of section for filtering processing
01250 * **************************************************************************/
01251 /* **************************************************************************
01252 Function: CheckModuleOpen ()
01253 Description: to verify the module selected is opened or not
01254 * **************************************************************************/
01255 bool CheckModuleOpen(string ModuleName_s)
01256 {      
01257     ModName_ ModuleName_mn = module(ModuleName_s)
01258     if (open module ModuleName_s){
01259         m = data(moduleVersion(ModuleName_mn))
01260         current = m 
01261         /*print "Module " ModuleName_s " is already open.\n"*/
01262         return true
01263     }
01264     else{
01265         m = read(ModuleName_s, false)
01266         put(OpenModules_sk, ModuleName_s, m)
01267         if (null m){
01268             return false
01269         }
01270         else{
01271             current = m
01272             return true
01273         }
01274     }
01275 }
01276 
01277 /* **************************************************************************
01278 Function: getRange ()
01279 Description: portion of a document that's contained in the specified object
01280 * **************************************************************************/
01281 OleAutoObj getRange(OleAutoObj obj) 
01282 {
01283     OleAutoObj objRange = null
01284     vbaCheckRes(oleGet(obj,cPropertyRange,objRange))//Range object that represents the portion of a document that's contained in the specified object
01285 
01286     if (null objRange) 
01287     {
01288         ack "Unable to get range object"
01289         clearWordState
01290     }
01291     
01292     return objRange
01293 }
01294 /* **************************************************************************
01295 Function: wordMakeSizedTableVBA ()
01296 Description: create table with no.of rows and columns
01297 * **************************************************************************/
01298 OleAutoObj wordMakeSizedTableVBA(int noRows, int noCols,string TableBookMarking_b) 
01299 {
01300 
01301     OleAutoObj objTable = null
01302     OleAutoObj objRange = null
01303         string s_Bookmarking = null
01304         
01305         // make a table maxCols,rows
01306     collapseSelection
01307 
01308     if (noRows == 0 || noCols == 0) 
01309     { 
01310         return
01311     }
01312 
01313     objRange = getRange objSel
01314 
01315     clear objArgBlock
01316     put(objArgBlock, objRange)
01317     put(objArgBlock, noRows)
01318     put(objArgBlock, noCols)
01319         if (noRows!=null && noCols!=null)
01320         {
01321                 vbaCheckRes(oleMethod(objTables, cMethodAdd, objArgBlock,objTable))
01322         }
01323   
01324     if (null objTable) 
01325     {
01326         ack "Failed to make table"
01327         clearWordState
01328     }
01329         
01330         i_Count1++
01331         /* table book-marking created */
01332         //if(TableBookMarking_b == true)
01333         
01334         if(TableBookMarking_b != ""|| TableBookMarking_b!= null)
01335         {
01336                 
01337                 OleAutoObj objBookMarks = null
01338                 oleGet(objDoc, "Bookmarks", objBookmarks)    
01339                 clear objArgBlock
01340                 //insert the bookmark
01341                 string s_Bookmarking = "Table""_"i_Count1 TableBookMarking_b""
01342                 
01343                 s_Tablename=s_Bookmarking
01344                 put(objArgBlock, s_Bookmarking)
01345                 vbaCheckRes(oleMethod(objBookmarks, cMethodAdd, objArgBlock))
01346         }
01347         else
01348         s_Tablename = null
01349         
01350 
01351     closeIfNonNull objRange
01352     collapseSelection
01353 
01354     return objTable
01355 }
01356 /* **************************************************************************
01357 Function: styleIndex ()
01358 Description: 
01359 * **************************************************************************/
01360 
01361 int styleIndex(Object o) 
01362 {
01363     int styleLevel = (level o)
01364 
01365     if (styleLevel > maxWordLevel)
01366     {
01367         styleLevel = maxWordLevel
01368     }
01369     
01370     styleLevel--
01371     
01372     return styleLevel
01373 }
01374 /* **********************************************************************************************
01375 function: wordGetNumberedCellVBA()
01376 description: Heading style and body styles are defined and assigned for attributes in different levels
01377 **********************************************************************************************/
01378 OleAutoObj wordGetNumberedCellVBA(OleAutoObj objTable, int rowNo, int cellNo) 
01379 {
01380     OleAutoObj objCell = null
01381     clear objArgBlock
01382     put(objArgBlock, rowNo)
01383     put(objArgBlock, cellNo)
01384 
01385     vbaCheckRes(oleMethod(objTable, cMethodCell, objArgBlock, objCell))
01386 
01387     if (null objCell) 
01388     {
01389         ack "Failed to get cell handle"
01390         clearWordState
01391     }
01392     
01393     return objCell
01394 }
01395 /* **********************************************************************************************
01396 function: getStyleForAttribute()
01397 description: Heading style and body styles are defined and assigned for attributes in different levels (currently the default style is taken for all)
01398 **********************************************************************************************/
01399 string getStyleForAttribute(Object o, string aName) 
01400 {
01401         //string styleName = paraStyleGetAttributeMap_(o, aName)
01402     if (null o) 
01403     {
01404         return bodyStyleNames[0]
01405     }
01406         string styleName = paraStyleGetAttributeMap_(o, aName)
01407     if (!null styleName) 
01408         {
01409                 return styleName
01410         }
01411     int styleLevel 
01412     if (cell o) 
01413     {
01414         styleLevel = cellHeadingLevel - 1
01415     } 
01416     else 
01417     {
01418         styleLevel = styleIndex o
01419     }
01420     
01421     if (aName == AHeading) 
01422     {
01423         return headingStyleNames[styleLevel]
01424     } 
01425     else 
01426     {
01427         return bodyStyleNames[styleLevel]
01428     } 
01429 
01430 }
01431 
01432 /* ***********************************************************************
01433 function: wordSetCellContentsVBA()
01434 Description: sets the table cells with the data from the selected object attribute from the selected module and the view.
01435 **********************************************************************************/
01436 
01437 void wordSetCellContentsVBA(OleAutoObj objCell, Object o, string s) 
01438 {
01439     if (null s) 
01440     {
01441         return
01442     }
01443 
01444     int styleLevel
01445     
01446     if (null o) 
01447     {
01448         styleLevel = 0
01449     }
01450     else 
01451     {
01452         styleLevel = styleIndex o
01453     }
01454 
01455     vbaCheckRes(oleMethod(objCell, cMethodSelect))
01456     collapseSelectionBackwards
01457 
01458     pasteAndApplyStyle(objSel, richText s, getStyleForAttribute(o,""))
01459     
01460     //This removes a carriage return from the table cell
01461     collapseSelection                                                    
01462     vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace))        
01463 }
01464 
01465 /* ***********************************************************************
01466 function: nextCellVBA()
01467 Description: rows will be inserted in table format one after the other
01468 **********************************************************************************/
01469 OleAutoObj nextCellVBA(OleAutoObj objTable, objCell) 
01470 {
01471     OleAutoObj nextCell = null
01472 
01473     if (null objCell) 
01474     {
01475        
01476                 nextCell = wordGetNumberedCellVBA(objTable,1,1)
01477                 
01478     } 
01479     else 
01480     {
01481         vbaCheckRes(oleGet(objCell, cPropertyNext, nextCell))
01482     }
01483     
01484     if (null nextCell) 
01485     {
01486         ack "Unable to get handle on next cell"
01487         clearWordState
01488     }
01489     
01490     closeIfNonNull objCell
01491     
01492     return nextCell
01493 }
01494 /* ***********************************************************************
01495 function: insertBlankRow()
01496 Description: rows will be inserted in table format one after the other
01497 **********************************************************************************/
01498 OleAutoObj insertBlankRow(OleAutoObj objTable, OleAutoObj objCell)
01499 {
01500 
01501         Column c
01502 
01503         for c in m do
01504     {
01505         objCell = nextCellVBA(objTable,objCell) 
01506             vbaCheckRes(oleMethod(objCell, cMethodSelect))
01507     }
01508     
01509     return objCell
01510 }
01511 
01512 /* ***********************************************************************
01513 function: pasteHeading()
01514 Description: 
01515 **********************************************************************************/
01516 string pasteHeading(OleAutoObj objSelection, Object o, bool doNumbers)
01517 {
01518     string styleName = getStyleForAttribute(o,AHeading)
01519         string errmess = null
01520     if (doNumbers) 
01521     {
01522         string s = (number o) "  "
01523         errmess = pasteAndApplyStyle(objSelection, richText s, styleName)
01524         if (null errmess)
01525         {
01526             collapseSelection
01527             vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace))
01528             vbaCheckRes(olePut(objSel, cPropertyStyle, wdStyleNormal))
01529             errmess = pasteAndApplyStyle(objSelection, richTextWithOle o.AHeading, styleName)
01530         }
01531         return errmess
01532     } 
01533     else 
01534     {
01535       
01536         return pasteAndApplyStyle(objSelection, richTextWithOle o.AHeading, styleName)
01537     }
01538 }
01539 /* ***********************************************************************
01540 function: wordDumpBodyVBA()
01541 Description: 
01542 **********************************************************************************/
01543 void wordDumpBodyVBA(Object o, string ObjValue) 
01544 {
01545     string errMess
01546 
01547     if (!hasCopyableText o) 
01548     {
01549         return
01550     }
01551 
01552     collapseSelection
01553 
01554     Buffer textBuffer = create
01555     if (issueWarnings && containsUnregisteredOle(o.ALongText)) {
01556         warningBox "Object " (identifier o) " contains one or more unregistered OLE objects in '" ALongText "'.\n\nThese OLE objects will be exported as pictures."
01557     }
01558         
01559         if (ObjValue!=null)
01560         {
01561                 textBuffer = ObjValue
01562                 errMess = pasteAndApplyStyle(objSel, textBuffer, getStyleForAttribute(o, ""))
01563 
01564         }
01565         else
01566         {
01567                 textBuffer = richTextWithOle o.ALongText
01568                 errMess = pasteAndApplyStyle(objSel, textBuffer, getStyleForAttribute(o, ALongText))
01569         }
01570 
01571     delete(textBuffer)
01572     if (!null errMess)
01573     {
01574         logError("Error pasting object text", errMess, o)
01575     }
01576     
01577     collapseSelection
01578 }
01579 void wordDumpTableAttributeVBA(Object o)
01580 {
01581     string errMess = ""
01582     if (!hasCopyableTableAttributes(o))
01583     {
01584         return
01585     }
01586     string attribName = o.(reserved AMainColumnAttribute)
01587     Buffer textBuffer = create
01588     textBuffer = richTextWithOle o.attribName
01589     if (0 < length textBuffer) {
01590         if (issueWarnings && containsUnregisteredOle(o.attribName)) {
01591                 warningBox "Object " (identifier o) " contains one or more unregistered OLE objects in '" attribName "'.\n\nThese OLE objects will be exported as pictures."
01592         }
01593         errMess = pasteAndApplyStyle(objSel, textBuffer, getStyleForAttribute(o, attribName))
01594     }
01595     delete(textBuffer)
01596     if (!null errMess)
01597     {
01598         logError("Error pasting "attribName" of cell", errMess, o)
01599     }
01600     collapseSelection
01601     vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace))
01602 }
01603 
01604 void wordDumpTableCellMarkerVBA(OleAutoObj objCell, Object o)
01605 {
01606     vbaCheckRes(oleMethod(objCell, cMethodSelect))
01607     collapseSelectionBackwards
01608 
01609     pasteAndApplyStyle(objSel, richText cTableMarkerString,
01610             getStyleForAttribute(o, AHeading))
01611 
01612     collapseSelection
01613     vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace))
01614 }
01615 /* ***********************************************************************
01616 function: wordDumpCellVBA()
01617 Description: 
01618 **********************************************************************************/
01619 void wordDumpCellVBA(OleAutoObj objCell, Object o, bool doNumber,string ObjValue) 
01620 {
01621     string errMess = ""
01622     //Check cell access
01623     if (!canRead(o))
01624     {
01625         return
01626     }
01627     vbaCheckRes(oleMethod(objCell, cMethodSelect))
01628     collapseSelectionBackwards
01629     
01630     //Get the attribute associated with the table (main column attribute)
01631     string attributeName = o.(reserved AMainColumnAttribute)
01632     if (null attributeName)
01633     {
01634         bool isPicture = hasPicture o
01635         bool hasText = hasCopyableText o
01636         bool hasHead = hasCopyableHeading o
01637      
01638         if (isPicture) 
01639         {
01640             hasText = false
01641         }
01642 
01643         if (!hasText && !hasHead && !isPicture)
01644         {
01645             if (doNumber) 
01646             {
01647                 string s = number o
01648 
01649                 pasteAndApplyStyle(objSel, richText s,
01650                       getStyleForAttribute(o,AHeading))
01651                 collapseSelection
01652                 vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace))
01653             }
01654 
01655             return
01656         }
01657 
01658 
01659         if (hasHead) 
01660         {
01661             errMess = pasteHeading(objSel, o, doNumber)    
01662 
01663             if (!null errMess)
01664             {
01665                 logError("Error pasting object heading of cell", errMess, o)
01666             }
01667         
01668             collapseSelection
01669         
01670             if (!hasText) 
01671             {
01672                 vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace))    
01673             }
01674         }
01675                 if (isPicture)
01676         {
01677             /* picture objects cannot have text */
01678             if (hasCopyablePicture o)
01679             {
01680               //  wordDumpPictureVBA(o,objSel,false)
01681                 return
01682             }
01683         }
01684         if (hasText) 
01685         {
01686                         if (ObjValue!=null)
01687                         {
01688                                 wordDumpBodyVBA(o, ObjValue)
01689                         }
01690                         else
01691                         {
01692                                 wordDumpBodyVBA(o,null)
01693                         }
01694             vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace))            
01695         }
01696     }
01697         else
01698     {
01699         wordDumpTableAttributeVBA(o)
01700     }
01701    
01702 }
01703 
01704 /* ***********************************************************************
01705 function: wordDumpNamedCellVBA()
01706 Description: 
01707 **********************************************************************************/
01708 void wordDumpNamedCellVBA(OleAutoObj objCell, Object o, string attrInCell, string ObjValue) 
01709 {
01710         Buffer textBuffer = create
01711     if (!canRead(o.attrInCell)) 
01712     {   
01713         return
01714     }
01715 
01716     if (null (richTextWithOle o.attrInCell)) 
01717     {
01718         return
01719     }
01720 
01721     string errMess
01722 
01723     vbaCheckRes(oleMethod(objCell, cMethodSelect))
01724     collapseSelectionBackwards
01725         if (ObjValue==null)
01726         {
01727                 
01728                 fullAttributeValueWithOle_(o,attrInCell,true,textBuffer)
01729                 errMess = pasteAndApplyStyle(objSel, textBuffer, getStyleForAttribute(o,attrInCell))
01730         }
01731         else
01732         {
01733                 textBuffer =ObjValue
01734                 errMess = pasteAndApplyStyle(objSel, textBuffer, getStyleForAttribute(o,attrInCell))
01735                 
01736         }
01737     delete(textBuffer)
01738     if (!null errMess)
01739     {
01740         logError("Error pasting column attribute into table cell", errMess, o)
01741     }
01742 
01743     collapseSelection
01744     vbaCheckRes(oleMethod(objSel, cMethodTypeBackspace))
01745 }
01746 /* ***********************************************************************
01747 function: GetValue()
01748 Description: to fetch the value from the selected object and with the attribute name
01749 **********************************************************************************/
01750 string GetValue(Object obj,string AttributeName_s, string s_Scriptpath)
01751 {
01752         string tsSub2 = null
01753         string tsSub = null
01754 
01755         if(AttributeName_s == "Main")
01756         {
01757                 if( obj."Object Heading""" == null)
01758                 {
01759                         tsSub2 = richTextWithOle obj."Object Text"""
01760                 }
01761                 else
01762                 {
01763                         tsSub2 = richTextWithOle obj."Object Heading"""
01764                 }
01765                 
01766         }
01767         else if(AttributeName_s == "Object ID" || AttributeName_s == "Object Identifier")
01768         {
01769                 tsSub2 = identifier(obj)
01770         }       
01771         else 
01772         {
01773                 AttrDef ad = find(current Module, AttributeName_s)
01774                 if(ad != null)
01775                 {
01776                         tsSub2  =  obj.AttributeName_s""
01777                 }
01778         }       
01779         if (s_Scriptpath!=null)
01780         {
01781 
01782                 tsSub2 = identifier(obj)
01783                 s_Scriptpath = "\nattrDXLName3="tsSub2"" s_Scriptpath
01784                 tsSub2 = eval_(s_Scriptpath)
01785         }
01786                 
01787         return  tsSub2  
01788 }
01789 /* ***********************************************************************
01790 function: exportTableLayoutRowHeader()
01791 Description: 
01792 **********************************************************************************/
01793 OleAutoObj exportTableLayoutRowHeader(Object o, OleAutoObj objTable, objCell) 
01794 {
01795     Column c
01796     string s
01797 
01798     for c in m do
01799     {
01800         objCell = nextCellVBA(objTable, objCell)
01801 
01802         if (main c)
01803         {
01804             if (!canRead o)
01805             {
01806                  // insert read locked string, as per DOORS display
01807                 wordSetCellContentsVBA(objCell,o,cReadLockedDataMarker)
01808             }
01809             else
01810             {
01811                 if (table o)
01812                 {
01813                     wordDumpTableCellMarkerVBA(objCell, o)
01814                 }
01815                 else
01816                 {
01817                     wordDumpCellVBA(objCell,o,includeHeadingNumbers && (!cell o),null)
01818                 }
01819             }
01820         }
01821         else
01822         {
01823             string attrInCol = attrName c
01824 
01825             if (isDumpableAttribute attrInCol)
01826             {
01827                 wordDumpNamedCellVBA(objCell,o,attrInCol,null)
01828             }
01829             else
01830             {
01831                 if (attrInCol == "Object Identifier")
01832                 {
01833                     s = text(c,o)
01834                 }
01835                 else
01836                 {
01837                     if (issueWarnings && containsUnregisteredOle(c, o)) {
01838                             warningBox "Object " (identifier o) " contains one or more unregistered OLE objects.\n\nThese OLE objects will be exported as pictures."
01839                     }
01840                     s = richTextWithOle(c,o)
01841                 }
01842 
01843                 if (null s)
01844                 {
01845                     continue
01846                 }
01847 
01848                 wordSetCellContentsVBA(objCell,o,s)
01849             }
01850         }
01851     }
01852 
01853     return objCell
01854 }
01855 /* ***********************************************************************
01856 function: exportTableLayoutRow()
01857 Description: 
01858 **********************************************************************************/
01859 OleAutoObj exportTableLayoutRow(Object o, OleAutoObj objTable, objCell, string StrColumnBookMarking_s[],int NumOfColumns_i,string StrColumn_s1[],bool b_FPresent) 
01860 {
01861     Column                      c
01862     string                      s
01863         string                  ObjValue 
01864         string                  colName_s
01865     string                      s_ParamsValue
01866     int                         i = 0
01867         
01868     for c in m do 
01869     {
01870         ObjValue =""
01871                 string s_Bookmarking1 = ""
01872         if(StrColumnBookMarking_s[i] == "true" || StrColumnBookMarking_s[i] == "True")
01873         {
01874                 for s_ParamsValue in BookMarking do
01875                         {
01876                         
01877                                 if (main c) 
01878                         {
01879                                 colName_s = "Main"
01880                         }
01881                         else
01882                         {
01883                                 if (StrColumn_s1[i]!=null) 
01884                                         {
01885                                         
01886                                                 colName_s = StrColumn_s1[i]
01887                                         }
01888                                         else
01889                                         {
01890                                                 colName_s = attrName c
01891                                         }
01892                         }
01893                                 
01894                                 string s_key = key(BookMarking)
01895                                 bool keyMatches_b=  matches(colName_s,s_key) 
01896                                 if(keyMatches_b ==  true)
01897                                 {
01898                         
01899                                         if(reg2 s_ParamsValue)
01900                                         {
01901                                                 string s_ParamsValue1 = s_ParamsValue[match 1]
01902                                                 s_ParamsValue = GetValue(o,s_ParamsValue1,null)
01903                                         }       
01904                                         if (StrColumn_s1[i]==null)
01905                                         {                                               
01906                                                 if(s_Bookmarking1 != null)
01907                                                 {
01908                                                         s_Bookmarking1 = s_Bookmarking1"_"s_ParamsValue
01909                                                 }
01910                                                 else
01911                                                 {
01912                                                         s_Bookmarking1 = s_ParamsValue
01913                                                 }
01914                                         }
01915                                         else
01916                                         {
01917                                                 // the bookmark has to be created by taking the field name for bookmark name
01918                                                 s_Bookmarking= StrColumn_s1[i]
01919                                                 if(s_Bookmarking != null)
01920                                                 {
01921                                                         
01922                                                         s_Bookmarking1 = s_Bookmarking1"_"s_ParamsValue
01923                                                 }
01924                                                 else
01925                                                 {
01926                                                         s_Bookmarking1 = s_ParamsValue
01927                                                 }
01928                                         
01929                                         }
01930                                 }
01931                         }
01932                         
01933         } 
01934         i++
01935                 
01936                 objCell = nextCellVBA(objTable, objCell)
01937                 string  FunctionList_s
01938                 if (b_FPresent ==true)
01939                 {
01940                         string s_FunctionList1 = null
01941                         string attrInCol = attrName c
01942                         for FunctionList_s in FunctionList do
01943                         {
01944                                 string AttributeName_s = key(FunctionList)
01945                                 if(attrInCol== AttributeName_s)
01946                                 {
01947                                         s_FunctionList1 = FunctionList_s
01948                                         ObjValue = GetValue(o,AttributeName_s,s_FunctionList1)
01949                                         break
01950                                 }
01951                 
01952                         }
01953                 
01954                 }
01955         if (main c) 
01956         {
01957             if (!canRead o) 
01958             {
01959                                 wordSetCellContentsVBA(objCell,o,cReadLockedDataMarker)
01960                                 
01961             } 
01962                         if (table o)
01963                         {
01964                                 wordDumpTableCellMarkerVBA(objCell, o)
01965                         }
01966                         else
01967                         {
01968                                 wordDumpCellVBA(objCell,o,includeHeadingNumbers && (!cell o),ObjValue)
01969                         }
01970             else 
01971             {
01972                                 if (ObjValue!=null)
01973                                 {
01974                                         wordDumpCellVBA(objCell,o,includeHeadingNumbers && (!cell o),ObjValue)
01975                                 }
01976                                 wordDumpCellVBA(objCell,o,includeHeadingNumbers && (!cell o),null)
01977             }
01978         } 
01979         else 
01980         {
01981             string attrInCol = attrName c
01982                         if (isDumpableAttribute attrInCol) 
01983             {
01984                                 if (ObjValue!=null)
01985                                 {
01986                                         wordDumpNamedCellVBA(objCell,o,attrInCol,ObjValue)
01987                                 }
01988                                 else
01989                                 {
01990                                         wordDumpNamedCellVBA(objCell,o,attrInCol,null)
01991                                 }
01992                         }
01993             else 
01994             {
01995                 if (attrInCol == "Object Identifier")
01996                 {
01997                     s = text(c,o)
01998                 }
01999                 else
02000                 {
02001                     if (issueWarnings && containsUnregisteredOle(c, o)) {
02002                             warningBox "Object " (identifier o) " contains one or more unregistered OLE objects.\n\nThese OLE objects will be exported as pictures."
02003                     }
02004                     s = richTextWithOle(c,o)
02005                 }
02006             
02007                if (null s) 
02008               {
02009                    continue
02010                }
02011 
02012                 wordSetCellContentsVBA(objCell,o,s)
02013             }
02014         }
02015                 if(s_Bookmarking1 != "")
02016                 {
02017                         
02018                         vbaCheckRes(oleMethod(objCell, cMethodSelect))
02019                         vbaCheckRes(oleGet(objCell, "Range", objCellRange))
02020                         OleAutoObj objBookMarks = null
02021                         oleGet(objDoc, "Bookmarks", objBookmarks)    
02022                         clear objArgBlock
02023                         put(objArgBlock, s_Bookmarking1)
02024                         vbaCheckRes(oleMethod(objBookmarks, cMethodAdd, objArgBlock))
02025                 }
02026     }
02027 
02028     return objCell
02029 }
02030 /* **************************************************************************************************************
02031 function : convertMillimetersToPoints ()
02032 Description: conversion of data 
02033 ****************************************************************** ******************************************************/  
02034 int convertMillimetersToPoints( int milliMeters ) {
02035    // points = mm * ( 72.0 Points per Inch ) / ( 25.4 mm per Inch )
02036    return intOf( realOf( milliMeters ) * ( 72.0 / 25.4 ) )
02037 }
02038 /* **************************************************************************************************************
02039 function : SetColumnWidth ()
02040 Description: to set the column width as defined by the user in the XML configuration file
02041 ****************************************************************** ******************************************************/  
02042 void SetColumnWidth(OleAutoObj objColumn, int ColumnWidth_i){
02043     clear objArgBlock
02044     put (objArgBlock, ColumnWidth_i)
02045     put (objArgBlock, 0)
02046     oleMethod(objColumn, "SetWidth", objArgBlock) // setwidth is a method used to set the column or cell width in a table
02047 }
02048 /* **************************************************************************************************************
02049 function : AutoFitBehavior ()
02050 Description: based on table cells contents or based on width of the document window, it resizes the table
02051 ****************************************************************** ******************************************************/ 
02052 void AutoFitBehavior(OleAutoObj Table_ole){
02053     clear objArgBlock
02054     put (objArgBlock, 1)
02055     checkRes (oleMethod (Table_ole, "AutoFitBehavior", objArgBlock))
02056 }
02057 
02058 /* **************************************************************************************************************
02059 function : create_View ()
02060 Description: if the Type=view this function is called and it will export the columns /attribute data into the word document
02061 ****************************************************************** ******************************************************/  
02062 void create_View(string StrColumn_s[],string StrColumn_s1[], string TableBookMarking_b,int ColWidth_i[], int NumOfColumns_i, bool AutoWidth_b, string StrColumnBookMarking_s[], string StrColHyperLinking_s[], bool b_FPresent){
02063     
02064     /* local Declarations */
02065     int                 i                                   //iterator
02066     string              sErrorMessage               = ""    //Error Message
02067         string                  currObjType
02068         string              nextObjType
02069     Column              c                                   //Column
02070     int                 NumberOfColumns_i                   //Number of Columns in Module
02071     int                 NumOfRows_i                 = 1     //Number of Rows
02072     int                 n                           = 0     //actual number of columns in view    
02073  
02074     int                 CountObjects_i              = 0
02075     bool                IsResetFormat_b                     
02076     OleAutoObj          ViewTable_ole                       //OLE Object of ViewTable
02077     OleAutoObj          Rows_ole                            //OLE Object of Rows
02078     OleAutoObj          ActualCell_ole                      //OLE Object of actual cell
02079     OleAutoObj          Columns_ole                         //OLE Object of Columns
02080     OleAutoObj          Column_ole                          //OLE Object of Column
02081         
02082     OleAutoArgs         autoArgs                 =create    //create autoArgs
02083         string                          StrColumn_s2[100]
02084         string                  s_FunctionList1
02085         string                          FunctionList_s
02086         string                          ObjValue
02087         
02088         Object o = current Object
02089     m = current Module 
02090         
02091     if (NumOfColumns_i < 1){
02092             return "No Column match!"
02093     }
02094     for (i=0; i< NumOfColumns_i; i++) {
02095         if (StrColumn_s[i] != "Main" and StrColumn_s[i] != "Object Identifier" )
02096         {
02097           if ( (exists attribute (StrColumn_s[i])) == false ){
02098             sErrorMessage = sErrorMessage "Attribute " (StrColumn_s[i])" not exists!\n"
02099           }
02100         }
02101     }
02102         
02103         
02104         
02105     if ( sErrorMessage != ""){
02106         ack sErrorMessage   
02107         halt
02108     }
02109     
02110     /* delete all Columns in Moduleview */
02111     for c in current Module do{
02112         n++ 
02113     }
02114     for i in 0:n do{
02115         delete(column 0)
02116     }
02117     
02118     /* Show selected Columns */
02119     for (i = 0; i < NumOfColumns_i; i++){
02120         c = insert(column i)        
02121         if (StrColumn_s[i] != "Main")
02122                 {  
02123             attribute(c, StrColumn_s[i])
02124                         // GSTCS 442 implementation
02125                         if (StrColumn_s1[i]!= null)                             
02126                         {
02127                                 StrColumn_s2[i] = StrColumn_s1[i]
02128                         }
02129                         
02130                         else
02131                         {
02132                                 StrColumn_s2[i] = StrColumn_s[i]
02133                         }
02134                 
02135         }
02136         else
02137                 {
02138                         main(c)
02139                         StrColumn_s2[i] = "Main"
02140                       
02141         }
02142     }
02143    
02144    
02145     /* Create Table with x Colums an y rows */
02146     ViewTable_ole = wordMakeSizedTableVBA(1, NumOfColumns_i,TableBookMarking_b)
02147    
02148     oleGet(ViewTable_ole, cPropertyRows, Rows_ole)
02149     oleGet(ViewTable_ole, cPropertyColumns, Columns_ole)
02150  
02151     ActualCell_ole = wordGetNumberedCellVBA (ViewTable_ole, 1, 1)
02152     
02153     if ( bMultipleHeader == false)
02154         {
02155         /* Add new Row */
02156         oleMethod (Rows_ole, cMethodAdd)
02157         NumOfRows_i++
02158             
02159         /* Generate Title Row */      
02160             for (i = 0; i < NumOfColumns_i; i++){
02161                 ActualCell_ole = wordGetNumberedCellVBA(ViewTable_ole, 1, i+1)
02162                 wordSetCellContentsVBA(ActualCell_ole, null, StrColumn_s2[i])
02163                         if(StrColHyperLinking_s[i] == "true")
02164                 {
02165                         
02166                         vbaCheckRes(oleMethod(ActualCell_ole, cMethodSelect))
02167                                 collapseSelectionBackwards       
02168                         //This removes a carriage return from the table cell
02169                                 collapseSelection     
02170                         OleAutoObj objCellRange = null
02171                                 vbaCheckRes(oleGet(ActualCell_ole, "Range", objCellRange))
02172                                 //delete(autoArgs)
02173                                 //Retrieve the bookmarks collection
02174                                 OleAutoObj objBookMarks = null
02175                                 oleGet(objDoc, "Bookmarks", objBookmarks)    
02176                                 clear objArgBlock
02177                                 //insert the bookmark, with a specified tablebookmark name and the column count concatenated 
02178                                 string s_Bookmarking=s_Tablename"Column"i_Count""
02179                                 put(objArgBlock, s_Bookmarking)
02180                                 vbaCheckRes(oleMethod(objBookmarks, cMethodAdd, objArgBlock))
02181                                 i_Count++
02182                                 
02183                 }
02184         }  
02185                 setRowBorder()
02186                 setRowFormatBoldGray()
02187             IsResetFormat_b = true
02188     }
02189     for o in m do{
02190         CountObjects_i++
02191     }
02192    
02193     if (CountObjects_i == 0)
02194         {
02195                 oleMethod(objSel,"MoveRight")
02196                 oleMethod(objSel,"MoveDown")                  
02197                 return
02198     }
02199     /* reset CountObject */
02200     CountObjects_i = 0
02201     
02202   
02203     for o in m do
02204         {
02205         /* increase CountObject */
02206         CountObjects_i++
02207                 
02208         if (CountObjects_i > MAXROWNUMBER)
02209                 {           
02210             break
02211             }           
02212         
02213                 if (exportCheckProgress)
02214                 {
02215             break
02216         }  
02217         exportStepProgress
02218                 
02219                 if (row o)
02220                 {
02221                         continue
02222                 }
02223                 if (tableContents m)
02224                 {
02225                         if (table o)
02226                         {
02227                                 continue
02228                         }
02229                 } 
02230                 else 
02231                 {
02232                         if (cell o)
02233                         {
02234                                 continue
02235                         }
02236                 }
02237                 if ( (exists attribute ("ObjType")) == false)
02238                 {
02239                         currObjType = "R"
02240                         nextObjType = "X"
02241 
02242                         if ((!null next o) and (level(o) < level(next o)))
02243                         {
02244                                 currObjType = "H"
02245                                 if (!null next next o)
02246                                 {
02247                                         nextObjType = "H"
02248                                 }
02249                         }
02250                 }
02251            else
02252            {
02253                         currObjType = o."ObjType"""
02254                         if (!null next o)
02255                         {
02256                                 nextObjType = (next o)."ObjType"""
02257                         }
02258                         else
02259                         {
02260                                 nextObjType = "X"
02261                         }
02262                 }
02263                         // Check if current object is a Header
02264                 if (currObjType == "H")
02265                 {
02266                         //ActualCell_ole = exportTableLayoutRowHeader(o, ViewTable_ole, ActualCell_ole)
02267                         ActualCell_ole =  exportTableLayoutRowHeader(o, ViewTable_ole, ActualCell_ole)                  
02268                         if (IsResetFormat_b)
02269                         {
02270                                 setRowFormatNormal()
02271                         }
02272                                 setRowBorder()
02273         if ((!null next o) and (nextObjType != "H"))
02274                 IsResetFormat_b = true
02275                 }
02276                 else
02277                 {
02278                         // export the cell contents
02279                         if (b_FPresent == true)
02280                         {
02281                                 ActualCell_ole = exportTableLayoutRow(o, ViewTable_ole, ActualCell_ole,StrColumnBookMarking_s,NumOfColumns_i,StrColumn_s1,b_FPresent)
02282                         }
02283                         
02284                         else
02285                         {
02286                                 ActualCell_ole = exportTableLayoutRow(o, ViewTable_ole, ActualCell_ole,StrColumnBookMarking_s,NumOfColumns_i,StrColumn_s1,null)
02287                         }
02288                         if (IsResetFormat_b)
02289                         {
02290                                 setRowFormatNormal()
02291                         }
02292                                 setRowBorder()
02293                 }
02294                 if ((!null next o) and (nextObjType == "H") and (level(next(o)) == 1))
02295                 {
02296                         
02297                         oleMethod (Rows_ole, cMethodAdd)
02298                         NumOfRows_i++
02299                         ActualCell_ole = insertBlankRow(ViewTable_ole, ActualCell_ole)
02300                         setRowFontNormal()
02301                 
02302                 }
02303                  // Add new Row (Do not add row if last object (of the current set))
02304                 if (!null next o)
02305                 {
02306                         oleMethod (Rows_ole, cMethodAdd)
02307                         NumOfRows_i++
02308                         if ((next o)."Object Text""" != "")
02309                         {
02310                 setRowFontNormalNextRow()
02311                         }
02312                 }
02313                         
02314                     
02315     } // End loop over all objects of current Module
02316     
02317         if (AutoWidth_b==true)
02318         {
02319                 clear autoArgs
02320                 put (autoArgs, 1)
02321                 oleMethod(ViewTable_ole, "AutoFitBehavior", autoArgs)   
02322     }
02323         else
02324         {
02325            for (i = NumOfColumns_i-1 ; i >= 0; i--)
02326                 {
02327                         clear autoArgs
02328                         put(autoArgs, i+1)        
02329                         oleMethod(Columns_ole, cMethodItem, autoArgs, Column_ole)                              
02330                         if (ColWidth_i[i] > 0)
02331                         {                
02332                                 /* Convert Millimeters input to points */
02333                                 //ColWidth_i[i] = convertMillimetersToPoints(ColWidth_i[i]) 
02334                                 SetColumnWidth(Column_ole, ColWidth_i[i])      
02335                                 
02336                         }
02337                         else 
02338                         {                
02339                                 clear autoArgs
02340                                 put(autoArgs, 1)
02341                                 oleMethod(Column_ole, "AutoFit")          
02342                         }        
02343                 }
02344     }
02345         
02346             /* if MAXROWNUMBER is reached print Hint */
02347     if (CountObjects_i > MAXROWNUMBER){
02348             //oleMethod (Rows_ole, cMethodAdd)
02349             NumOfRows_i++
02350             ActualCell_ole = insertBlankRow(ViewTable_ole, ActualCell_ole)
02351             setRowFontNormal()
02352             wordSetCellContentsVBA(ActualCell_ole, null, "View exceeds max Numbers of Rows, only " MAXROWNUMBER " are displayed.")
02353             wordMergeRowVBA()
02354             oleGet(objSel, "Font", Font_ole)
02355             olePut(Font_ole, "Bold", true)
02356             setRowBorder()
02357             }
02358 
02359    
02360 
02361         oleMethod(objSel,"MoveRight")
02362     oleMethod(objSel,"MoveDown")           
02363     
02364   // To close the tables array
02365   closeIfNonNull ViewTable_ole
02366 }
02367 /* *******************************************************
02368 *function : FunctionforParam ()
02369 *Description: the function to read the parameters mentioned for the function evocation(function post processing node) 
02370 ************************************************************/  
02371 string FunctionforParam(OleAutoObj FParamList_ole, int NumOfParams_i)
02372 {
02373         OleAutoObj Params_ole=null
02374         int ParamIterator_i =0 
02375 
02376         string Param_s=""
02377         string sParameters =""
02378         Buffer bParam= create
02379         
02380         
02381         if(NumOfParams_i != null)
02382         {
02383                 for (ParamIterator_i = 0; ParamIterator_i < NumOfParams_i; ParamIterator_i++)
02384                 {
02385                         clear autoArgs
02386                         put(autoArgs, ParamIterator_i)
02387                         oleMethod(FParamList_ole, "Item", autoArgs, Params_ole)
02388                         clear autoArgs
02389                         put(autoArgs, "Param")        
02390                         oleMethod(Params_ole, "getAttribute", autoArgs, Param_s)
02391                         
02392                         if(bParam ""!=null)
02393                         {
02394                                 bParam = bParam"@#$%"Param_s
02395                         }
02396                         
02397                         else
02398                         {
02399                         
02400                                 bParam =Param_s
02401                         }
02402                         sParameters = stringOf bParam
02403                         
02404                 }
02405                 delete bParam   
02406         }
02407         
02408         return sParameters
02409                 
02410 }
02411 /* *****************************************************************
02412 function : ProcessTable ()
02413 Description: the table attribute and the elements init will be processed like column text, width etc
02414 ******************************************************************/    
02415 
02416 void ProcessTable(OleAutoObj Table_ole)
02417 {
02418     /* local declarations */
02419     string              ModuleName_s
02420     string              Filtertext_s    
02421    
02422     string              Type_s
02423     string              StrColumn_s[100]
02424         string                          StrColumn_s1[100]
02425 
02426         string                          TableStyle_s
02427         string              Module_s
02428     string              Filter_s    
02429     string              AutoWidth_s
02430     string              Ancestors_s
02431     string              Descendants_s
02432     OleAutoObj          Columns_ole
02433     OleAutoObj          ColumnList_ole
02434     OleAutoObj          Column_ole    
02435         string                  PrintTableInfo_s 
02436         OleAutoObj                      FParamList_ole
02437     int                 NumOfColumns_i
02438     int                 ColWidth_i[100]
02439     bool                AutoWidth_b
02440         int                             ColumnsIterator_i
02441         string                          Columnwidth_s   //GSTCS 442
02442         int                             Columnwidth_i   //GSTCS 442
02443         int                             NumOfParams_i
02444         string                          Attrname_s
02445         string                          Fieldname_s
02446         string                          ColHyperLinking_s
02447         string                          StrColHyperLinking_s[100]
02448         string                          ParamValue_s
02449         OleAutoObj                      BookMarkingAttr_ole
02450         OleAutoObj                      ParamList_ole
02451         int                             Param_i =0
02452         int                             ParamsIterator_i
02453         OleAutoObj                      Params_ole
02454         string                          Param_s
02455         string                          ColBookMarking[100]
02456         string                          TableBookMarking_s= null
02457 //      bool                            TableBookMarking_b = false
02458         string                          TableBookMarking_b
02459         OleAutoObj              FileList_ole
02460         OleAutoObj                      FunctionList_ole
02461         string                          sParamstr
02462         string                          FilePath_s =""
02463         string                          FunctionList_s
02464         string                          s_FunctionList
02465         string                          ObjValue
02466         bool                            b_Tablebookmark = false
02467         
02468         styleName = vbaGetStyleName(objDoc,wdStyleNormal)
02469  
02470     /* get Path of Module */
02471     clear autoArgs
02472     put( autoArgs, "Module")
02473     oleMethod(Table_ole, "getAttribute", autoArgs, ModuleName_s)
02474         clear autoArgs
02475     put( autoArgs, "Filtertext")
02476     oleMethod(Table_ole, "getAttribute", autoArgs, Filtertext_s)
02477     clear autoArgs
02478     put( autoArgs, "Ancestors")
02479     oleMethod(Table_ole, "getAttribute", autoArgs, Ancestors_s)
02480         
02481     clear autoArgs
02482     put( autoArgs, "Descendants")
02483     oleMethod(Table_ole, "getAttribute", autoArgs, Descendants_s)
02484     clear autoArgs
02485     put( autoArgs, "Description")
02486     oleMethod(Table_ole, "getAttribute", autoArgs, Description_s)
02487     clear autoArgs
02488     put( autoArgs, "Type")
02489     oleMethod(Table_ole, "getAttribute", autoArgs, Type_s)
02490     
02491         
02492         clear autoArgs
02493         put( autoArgs, "PrintTableInfo")
02494     oleMethod(Table_ole, "getAttribute", autoArgs, PrintTableInfo_s)
02495         
02496         clear autoArgs
02497         put( autoArgs, "TableBookmarking")
02498     oleMethod(Table_ole, "getAttribute", autoArgs, TableBookMarking_s)
02499         
02500         /*currently the tablestyle is not used*/
02501         clear autoArgs
02502     put(autoArgs, "Style")
02503     oleMethod(Table_ole, "getAttribute", autoArgs, TableStyle_s)
02504     
02505         if (TableBookMarking_s!=null || TableBookMarking_s!="")
02506         {
02507                  b_Tablebookmark =true
02508                  TableBookMarking_b = TableBookMarking_s
02509                  
02510         }
02511           
02512         else
02513         {
02514                 b_Tablebookmark =false
02515                                 
02516         }
02517 
02518     /* get autoStyle for table */
02519      
02520     clear autoArgs
02521     put(autoArgs, "Columns")
02522     oleMethod(Table_ole, "selectSingleNode", autoArgs, Columns_ole)
02523     
02524         clear autoArgs
02525     put (autoArgs, "Autowidth")
02526     oleMethod(Columns_ole, "getAttribute", autoArgs, AutoWidth_s)
02527 
02528    
02529         clear autoArgs
02530     put(autoArgs, "Column")
02531     oleMethod(Columns_ole, "selectNodes", autoArgs, ColumnList_ole)
02532     
02533         oleGet(ColumnList_ole, "Length", NumOfColumns_i)
02534  
02535         
02536     if (!CheckModuleOpen(ModuleName_s))
02537         {
02538         print "Can not open Module " ModuleName_s ".\n"
02539         return    
02540     }
02541        
02542    
02543     filtering off
02544      
02545     /* get Filter */   
02546     if (!null Filtertext_s || Filtertext_s != "")
02547         {  
02548         f = parseFilter(Filtertext_s) 
02549         if ((Ancestors_s == "true") || (Ancestors_s == "True") || (Ancestors_s == "1"))
02550                 {
02551             ancestors(true)
02552         }
02553         else
02554                 {
02555             ancestors(false)
02556         }
02557         if ((Descendants_s == "true") || (Descendants_s == "True") || (Descendants_s == "1"))
02558                 {
02559             descendants(true)
02560         }
02561         else
02562                 {
02563             descendants(false)
02564         }
02565         /* activate Filter */
02566         set (m,f,accepted,rejected)
02567         filtering on
02568     }
02569     else
02570         {
02571         Filtertext_s = "No Filter defined"
02572     }
02573     if ( PrintTableInfo_s =="true")
02574         {
02575                 /* print Modulename */
02576                 Module_s = "Module: " ModuleName_s "\n"
02577                 pasteAndApplyStyle(objSel, richText Module_s, bodyStyleNames[0])
02578                 /* print Filtername */
02579                 Filter_s = "Filter: " Filtertext_s "\t Ancestors: " Ancestors_s "\t Descendants: " Descendants_s "\n"
02580                 pasteAndApplyStyle(objSel, richText Filter_s, bodyStyleNames[0])
02581                 
02582         }
02583         else
02584         {
02585                 string s_errmess = "PrintTableinfo is false \n"
02586                 pasteAndApplyStyle(objSel, richText s_errmess, bodyStyleNames[0])
02587         }
02588    
02589     if ((!null AutoWidth_s) and ((AutoWidth_s == "true") or (AutoWidth_s == "True") or (AutoWidth_s == "1"))){
02590         AutoWidth_b = true
02591     }
02592     else{
02593         AutoWidth_b = false    
02594     }
02595     /* get Columns */
02596     for (ColumnsIterator_i = 0; ColumnsIterator_i < NumOfColumns_i; ColumnsIterator_i++)
02597         {        
02598         clear autoArgs
02599         put(autoArgs, ColumnsIterator_i)
02600         oleMethod(ColumnList_ole, "Item", autoArgs, Column_ole)
02601         clear autoArgs
02602     
02603                 put(autoArgs, "Attributename")        
02604         oleMethod(Column_ole, "getAttribute", autoArgs,Attrname_s)
02605             StrColumn_s[ColumnsIterator_i] = Attrname_s
02606                 
02607                 clear autoArgs
02608                 put(autoArgs, "FieldName")        
02609                 oleMethod(Column_ole, "getAttribute", autoArgs, Fieldname_s)  //GSTCS 442
02610         StrColumn_s1[ColumnsIterator_i] = Fieldname_s
02611                 
02612                 clear autoArgs
02613                 put(autoArgs, "Columnwidth")        
02614                 oleMethod(Column_ole, "getAttribute", autoArgs, Columnwidth_s)  //GSTCS 442
02615                 if (Columnwidth_s!=null)
02616                 {
02617                         Columnwidth_i = intOf(Columnwidth_s)
02618                         ColWidth_i[ColumnsIterator_i] = Columnwidth_i
02619                 }
02620                 
02621                 clear autoArgs
02622         put(autoArgs, "ColHyperLinking")        
02623         oleMethod(Column_ole, "getAttribute", autoArgs, ColHyperLinking_s)
02624                                 
02625                 clear autoArgs
02626                 put(autoArgs, "Function_Post_Processing")
02627                 oleMethod(Column_ole, "selectSingleNode", autoArgs, FunctionList_ole)           
02628                 
02629                 if (FunctionList_ole != null)
02630                 {
02631                 
02632                         b_FPresent = true
02633                         clear autoArgs
02634                         put(autoArgs, "Params")
02635                         oleMethod(FunctionList_ole, "selectNodes", autoArgs, FParamList_ole)
02636                 if(FParamList_ole != null)
02637                 {
02638                                 
02639                         oleGet(FParamList_ole, "Length", NumOfParams_i)
02640                                 sParamstr= FunctionforParam(FParamList_ole,NumOfParams_i)
02641                 }
02642                         
02643                 
02644                         clear autoArgs
02645                         put(autoArgs, "Filepath")
02646                         oleMethod(FunctionList_ole, "selectSingleNode", autoArgs, FileList_ole)
02647                         oleGet(FileList_ole, "text", FilePath_s)
02648                         FunctionList_s = "\nattrDXLName1 = \"" sParamstr "\"\nattrDXLName2 = \"" Attrname_s "\" \n#include  <"FilePath_s">"
02649                         put(FunctionList,Attrname_s,FunctionList_s)
02650                         
02651                 }
02652         if(!null ColHyperLinking_s)
02653         {
02654                 StrColHyperLinking_s[ColumnsIterator_i] = ColHyperLinking_s
02655         }
02656         else
02657         {
02658                 StrColHyperLinking_s[ColumnsIterator_i] = "false"
02659         }
02660                 
02661                 clear autoArgs
02662         put(autoArgs, "BookMarkingAttr")
02663         oleMethod(Column_ole, "selectSingleNode", autoArgs, BookMarkingAttr_ole)
02664         if(BookMarkingAttr_ole != null)
02665         {
02666                 
02667                         clear autoArgs
02668                         put(autoArgs, "Params")
02669                         oleMethod(BookMarkingAttr_ole, "selectNodes", autoArgs, ParamList_ole)
02670                 if(ParamList_ole != null)
02671                 {
02672                                 
02673                         oleGet(ParamList_ole, "Length", Param_i)
02674                 }
02675         
02676         
02677                         if(Param_i != 0)
02678                         {
02679                                 for (ParamsIterator_i = 0; ParamsIterator_i < Param_i; ParamsIterator_i++)      
02680                                 {
02681                                 
02682                                         clear autoArgs
02683                                         put(autoArgs, ParamsIterator_i)
02684                                         oleMethod(ParamList_ole, "Item", autoArgs, Params_ole)
02685                                         clear autoArgs
02686                                         put(autoArgs, "Param")        
02687                                         oleMethod(Params_ole, "getAttribute", autoArgs, Param_s)
02688                                         if (Fieldname_s != null)
02689                                         {
02690                                                 //put(BookMarking,Fieldname_s"_"ParamsIterator_i"",Param_s)
02691                                                 put(BookMarking,Fieldname_s"_"ParamsIterator_i"",Param_s)
02692                                         }
02693                                         else
02694                                         {
02695                                                 //put(BookMarking,Attrname_s"_"ParamsIterator_i"",Param_s)
02696                                                 put(BookMarking,Attrname_s"_"ParamsIterator_i"",Param_s)
02697                                         }
02698                                         
02699                                 }
02700                                 ColBookMarking[ColumnsIterator_i] = "true"
02701                         }
02702                 }
02703                 else
02704                 {
02705                         ColBookMarking[ColumnsIterator_i] = "false"
02706                 }
02707                                 
02708     }
02709     if ((Type_s == "View") || (Type_s == "V") || (Type_s == "v"))
02710         {
02711                 if (b_Tablebookmark==true )
02712         {
02713                         create_View(StrColumn_s,StrColumn_s1,TableBookMarking_b,ColWidth_i,NumOfColumns_i,AutoWidth_b,ColBookMarking,StrColHyperLinking_s,b_FPresent)
02714                 } 
02715                 else 
02716                 {
02717                         
02718                         create_View(StrColumn_s,StrColumn_s1,null,ColWidth_i,NumOfColumns_i,AutoWidth_b,ColBookMarking,StrColHyperLinking_s,b_FPresent)
02719                 }
02720         }
02721 }
02722 bool process_leaves( int deep, Object oLeaf, Column col, int Ycoord, Skip refList, string colGroup, string Attribute_s[], string Heading_s[], Array &arrResult)
02723 {
02724         string s, strValue, strNewGroup
02725         int refIdx
02726         Regexp matchHeading = regexp Heading_s[deep-1]        // Note: array started by 0, but from user point ov view we start by 1
02727         Regexp matchAttribute = regexp Attribute_s[deep-1]    // Note: array started by 0, but from user point ov view we start by 1
02728 
02729         if (debug == 1)
02730         {
02731                 print "process_leaves:\t"Ycoord"\t"colGroup"\n"
02732         }
02733 
02734         while ( ! null oLeaf)
02735         {
02736                 if (leaf oLeaf)
02737                 {
02738                         s = oLeaf."Object Heading"
02739                         if ( s == "")   // if heading is empty use text as value
02740                         {
02741                                 s = oLeaf."Object Text"
02742                         }
02743 
02744                         if ((length(Attribute_s[deep-1]) > 1 ) && matchAttribute  s )
02745                         {
02746                         strNewGroup=new_col_group(colGroup, s)
02747 
02748                         strValue = oLeaf.(attrName col)""
02749 
02750                         if (debug == 1)
02751                         {
02752                                 print "\t\t"s"\t"strValue"\n"
02753                         }
02754 
02755                         // check if heading is already known.
02756                         // If yes, print value in same column as before
02757                         // otherwise append column
02758                         if (find(refList,strNewGroup,refIdx))
02759                         {
02760                                 put(arrResult,strValue, refIdx, Ycoord)
02761                         }
02762                         else
02763                         {
02764                                 if (arrResultX_size >= 255)
02765                                 {
02766                                         strError = "Sorry, but the script supports no more than 255 columns (attributes).\nPlease add an appropriate filter!"
02767                                         return false
02768                                 }
02769                                 put(refList,strNewGroup,arrResultX_size)
02770                                 if (! null colGroup)    // fill first row
02771                                 {
02772                                         put(arrResult,colGroup,arrResultX_size+0,0)
02773                                 }
02774                                 put(arrResult,s,arrResultX_size+0,1) // add title to 2nd row
02775                                 put(arrResult,strValue, arrResultX_size++, Ycoord) // and finally the value
02776                         }
02777                         }
02778                 }
02779                 else
02780                 {
02781                         s = oLeaf."Object Heading"
02782                         strNewGroup=new_col_group(colGroup, s)
02783                         if ((length(Heading_s[deep-1]) > 1 ) && matchHeading  s )
02784                         {
02785                                 if (!process_leaves( deep+1, first oLeaf, col, Ycoord,  refList, strNewGroup, Attribute_s, Heading_s, arrResult ))
02786                                 {
02787                                         return false
02788                                 }
02789                         }
02790                 }
02791                 oLeaf =  next sibling oLeaf
02792         } // while
02793         return true
02794 } // process_leaves
02795 
02796 void Transpose(string Value_s, string Attribute_s[], string Heading_s[], Object oFather, Array &arrResult)
02797 {
02798     Module mSource = current
02799     Column c
02800     string s, s1, s2
02801     string strMasterHeading = oFather."Object Heading"
02802     const string strEmpty = ""
02803     string strError
02804     Object oChild = first oFather
02805     Object oGrandChild
02806     Object oRoot
02807     Object oLeaf
02808 
02809     bool mainSeen = false
02810     int NoOfValueColumns = 0
02811     bool PrintValueTitle = true
02812     bool OnlyOneValueColumn = true
02813 
02814     arrResultX = 0;
02815     arrResultY = 0;
02816     arrResultX_size = 0;
02817     arrResultY_size = 0;
02818 
02819 
02820     //
02821     // now get some values from the GUI
02822     strMatchValues = Value_s
02823 
02824     //
02825     // Before we start with the real work, it must be ensured
02826     // that at least two sub chapter levels exist
02827     if (null oChild)
02828     {
02829       strError = "Current object has no children.\n"
02830     }
02831     // else if (null first oChild)
02832     // {
02833     //   strError = "Current object has no grand children.\n"
02834     // }
02835     else
02836     {
02837         Skip refList = create
02838         string strTitle
02839         oRoot = oChild          // oRoot is the first child and we have to start here for each value
02840         arrResultY = 0
02841         int deep = 0;
02842 
02843         // If we have to print the column header of the values field in the first column,
02844         // we have to start in column 2 with the chapter titles, otherwise in column 1
02845         if (PrintValueTitle)
02846         {
02847                 arrResultX_size = 2;
02848         }
02849         else
02850         {
02851                 arrResultX_size = 1;
02852         }
02853 
02854         for c in mSource do     // Loop over all columns
02855         {
02856                 oChild = oRoot
02857                 deep = 2
02858                 // as long as we do not see the main column all columns are skipped
02859                 // after the main column has been processed, all further columns are treaded as value columns
02860 
02861                 if (main c)             // print table headers
02862                 {
02863                     mainSeen = true
02864                     arrResultY = 2      // 1st row group, 2nd row title
02865                     continue
02866                 }
02867 
02868                 if ( !mainSeen)
02869                 {
02870                         continue
02871                 }
02872 
02873                 strTitle = (title c)
02874                 if ( ! matches(strMatchValues, strTitle))
02875                 {
02876                         continue;
02877                 }
02878 
02879                 NoOfValueColumns++
02880 
02881                         while ( ! null oChild)
02882                         {
02883                                 arrResultX=0
02884                                 if (PrintValueTitle)
02885                                 {
02886                                         put(arrResult,strTitle, arrResultX++, arrResultY)
02887                                 }
02888                                 s = oChild."Object Heading"
02889                                 if(s == "")
02890                                 {
02891                                         s = oChild."Object Text"
02892 
02893                                 }
02894                                 put(arrResult,s, arrResultX++, arrResultY)
02895                                 oGrandChild = first oChild
02896 
02897                                 if (!process_leaves(deep+1,oGrandChild, c, arrResultY, refList, strMasterHeading, Attribute_s, Heading_s, arrResult))
02898                                 {
02899                                         break;
02900                                 }
02901 
02902                                 oChild =  next sibling oChild
02903                                 arrResultY++
02904                         }// while child
02905 
02906                         if (OnlyOneValueColumn )
02907                         {
02908                                 break
02909                         }
02910         } // column
02911 
02912             arrResultY_size = arrResultY
02913     }
02914 } //DoApply
02915 void ProcessTranspose(OleAutoObj Transpose_ole){
02916     OleAutoObj          Heading_ole
02917     OleAutoObj          Attribute_ole
02918     OleAutoObj          RegexpList_ole
02919     OleAutoObj          Regexp_ole
02920     OleAutoObj          Value_ole
02921     string              ModuleName_s
02922     string              Filtertext_s
02923     string              Ancestors_s
02924     string              Descendants_s
02925     string              Description_s
02926     string              Regexp_s
02927     string              Level_s
02928     string              Value_s
02929     string              ObjectNo_s
02930     string              sLastValue
02931     string              SheetName_s
02932     int                 NumberOfRegexp_i
02933     int                 Iterator_i
02934     int                 Iterator_x
02935     int                 Iterator_y
02936     int                 ObjectNo_i
02937     string              Heading_s[10]             = {".*",".*",".*",".*",".*",".*",".*",".*",".*",".*"}
02938     string              Attribute_s[10]           = {".*",".*",".*",".*",".*",".*",".*",".*",".*",".*"}
02939     Object              EntryObject_o
02940     Array               arrResult                 = create(1,1)
02941 
02942     clear autoArgs
02943     put( autoArgs, "Module")
02944     oleMethod(Transpose_ole, "getAttribute", autoArgs, ModuleName_s)
02945     clear autoArgs
02946     put( autoArgs, "Filtertext")
02947     oleMethod(Transpose_ole, "getAttribute", autoArgs, Filtertext_s)
02948     clear autoArgs
02949     put( autoArgs, "Ancestors")
02950     oleMethod(Transpose_ole, "getAttribute", autoArgs, Ancestors_s)
02951     clear autoArgs
02952     put( autoArgs, "Descendants")
02953     oleMethod(Transpose_ole, "getAttribute", autoArgs, Descendants_s)
02954     clear autoArgs
02955     put( autoArgs, "Description")
02956     oleMethod(Transpose_ole, "getAttribute", autoArgs, Description_s)
02957     clear autoArgs
02958     put( autoArgs, "ObjectNo")
02959     oleMethod(Transpose_ole, "getAttribute", autoArgs, ObjectNo_s)
02960     clear autoArgs
02961     put( autoArgs, "SheetName")
02962     oleMethod(Transpose_ole, "getAttribute", autoArgs, SheetName_s)
02963     ObjectNo_i = str2int(ObjectNo_s)
02964     clear autoArgs
02965     put(autoArgs, "Heading")
02966     oleMethod(Transpose_ole, "selectSingleNode", autoArgs, Heading_ole)
02967     clear autoArgs
02968     put(autoArgs, "Regexp")
02969     oleMethod(Heading_ole, "selectNodes", autoArgs, RegexpList_ole)
02970     oleGet(RegexpList_ole, "Length", NumberOfRegexp_i)
02971     for (Iterator_i = 0; Iterator_i < NumberOfRegexp_i; Iterator_i++){
02972         clear autoArgs
02973         put(autoArgs, Iterator_i)
02974         oleMethod(RegexpList_ole, "Item", autoArgs, Regexp_ole)
02975         clear autoArgs
02976         put (autoArgs, "Text")
02977         oleMethod(Regexp_ole, "getAttribute", autoArgs, Regexp_s)
02978         clear autoArgs
02979         put (autoArgs, "Level")
02980         oleMethod(Regexp_ole, "getAttribute", autoArgs, Level_s)
02981         Level_i = str2int(Level_s)-1
02982         Heading_s[Level_i] = Regexp_s
02983     }
02984     clear autoArgs
02985     put(autoArgs, "Attribute")
02986     oleMethod(Transpose_ole, "selectSingleNode", autoArgs, Attribute_ole)
02987     clear autoArgs
02988     put(autoArgs, "Regexp")
02989     oleMethod(Attribute_ole, "selectNodes", autoArgs, RegexpList_ole)
02990     oleGet(RegexpList_ole, "Length", NumberOfRegexp_i)
02991     for (Iterator_i = 0; Iterator_i < NumberOfRegexp_i; Iterator_i++){
02992         clear autoArgs
02993         put(autoArgs, Iterator_i)
02994         oleMethod(RegexpList_ole, "Item", autoArgs, Regexp_ole)
02995         clear autoArgs
02996         put (autoArgs, "Text")
02997         oleMethod(Regexp_ole, "getAttribute", autoArgs, Regexp_s)
02998         clear autoArgs
02999         put (autoArgs, "Level")
03000         oleMethod(Regexp_ole, "getAttribute", autoArgs, Level_s)
03001         Level_i = str2int(Level_s)-1
03002         Attribute_s[Level_i] = Regexp_s
03003     }
03004     clear autoArgs
03005     put(autoArgs, "Value")
03006     oleMethod(Transpose_ole, "selectSingleNode", autoArgs, Value_ole)
03007     clear autoArgs
03008     put(autoArgs, "Attribute")
03009     oleMethod(Value_ole, "getAttribute", autoArgs, Value_s)
03010 
03011     /* open module */
03012     if (!CheckModuleOpen(ModuleName_s)){
03013         print "Can not open Module " ModuleName_s ".\n"
03014         return
03015     }
03016     if (!exists attribute Value_s){
03017         ack ("Attribute " Value_s " doesn't exists, Skip this Transpose.")
03018         return
03019     }
03020 
03021     /* set filter */
03022     filtering off
03023     if (!null Filtertext_s || Filtertext_s != ""){
03024         f = parseFilter(Filtertext_s)
03025         if ((Ancestors_s == "true") || (Ancestors_s == "True") || (Ancestors_s == "1")){
03026             ancestors(true)
03027         }
03028         else{
03029             ancestors(false)
03030         }
03031         if ((Descendants_s == "true") || (Descendants_s == "True") || (Descendants_s == "1")){
03032             descendants(true)
03033         }
03034         else{
03035             descendants(false)
03036         }
03037         /* activate Filter */
03038         set (m,f,accepted,rejected)
03039         filtering on
03040     }
03041     else{
03042         Filtertext_s = "No Filter defined"
03043     }
03044     EntryObject_o = object(ObjectNo_i, m)
03045     if (!null EntryObject_o){
03046         /* call transpose */
03047         Transpose(Value_s, Attribute_s, Heading_s, EntryObject_o, arrResult)
03048         /* new Worksheet in Excel */
03049         if (!null SheetName_s){
03050             ExcelNewSheet(SheetName_s)
03051         }
03052         else{
03053             ExcelNewSheet("")
03054         }
03055         /* Print in Excel Sheet */
03056         for arrResultY in 1:arrResultY_size do{
03057                 sLastValue = ""
03058                 for arrResultX in 1:arrResultX_size do{
03059                         string s = get(arrResult, arrResultX-1, arrResultY-1)
03060 
03061                         // In case only one Value column is porcessed, we do
03062                         // not print the title of the Value column in the first column
03063 
03064                                 if (arrResultX > 1)
03065                                 {
03066                                         // for the first (group) line print only a value if it
03067                                         // differs from the previuos column
03068                                         if ((s != sLastValue) || (arrResultY > 1))
03069                                         {
03070                                                 ExcelPut(arrResultX-1,arrResultY,s)
03071                                                 sLastValue = s
03072                                         }
03073                                 }
03074                                 else if (arrResultY == 3)
03075                                 {
03076                                         ExcelPut(1,1,s)
03077                                 }
03078                 }
03079         }
03080     }
03081     else{
03082         ack("Object not found!")
03083         return
03084     }
03085     delete arrResult
03086 } // ProcessTranspose
03087 
03088 /* *****************************************************************
03089 function : HandleSection ()
03090 Description: XMl file reading for looping of sections information and table etc
03091 ******************************************************************/
03092 void HandleSection(OleAutoObj Section_ole, int SectionStructureLevel_i){
03093     /* SectionStructureLevel denotes the Level of the Section. Example: 3.2.1 has Level 3 */
03094     int             NumOfTables_i                           //Number of Tables defines in XML
03095     int             NumOfSections_i                         //Number of Sections in this Section
03096     int             Iterator_i    
03097     string          Headline_s                              //Headline for Chapter/Section
03098         string          Text_s                                  //Plaintext
03099         Buffer          SectionStructure_s          = create    //String of Sections Structure
03100     OleAutoObj      TableList_ole                           //List of Tables
03101     OleAutoObj      SectionList_ole                         //List of Section in Chapter
03102     OleAutoObj      Table_ole                               //Table
03103   //  SectionStructureLevel_i      =0
03104         int SectionIterator_i
03105         OleAutoObj      TransposeList_ole
03106         OleAutoObj              Transpose_ole
03107         int                     NumOfTranspose_i
03108         
03109         bool            InitExcel_b                 = false
03110         clear autoArgs
03111         put(autoArgs,"Headline")
03112         oleMethod(Section_ole, "getAttribute", autoArgs, Headline_s)
03113         /* Get Text */
03114         clear autoArgs
03115         put(autoArgs,"Text")
03116         oleMethod(Section_ole, "getAttribute", autoArgs, Text_s)
03117         /* Get Table List */
03118         clear autoArgs
03119         put(autoArgs,"Table")
03120         oleMethod(Section_ole, "selectNodes", autoArgs, TableList_ole)
03121         /* get Section List */
03122         clear autoArgs
03123         put(autoArgs,"Section")
03124         oleMethod(Section_ole, "selectNodes", autoArgs, SectionList_ole)
03125         
03126         clear autoArgs
03127         put(autoArgs,"Transpose")
03128         oleMethod(Section_ole, "selectNodes", autoArgs, TransposeList_ole)
03129         
03130         if (!InitWord_b){ 
03131             /* Init Word */
03132             InitWord()
03133             InitWord_b = true
03134     }
03135         
03136         MakeSection(Headline_s, Text_s, stringOf(SectionStructure_s),SectionStructureLevel_i)
03137         
03138         /* get Numbers of Tables in Section */
03139         oleGet(TableList_ole, "Length", NumOfTables_i)
03140         if (NumOfTables_i > 0){
03141         for (Iterator_i = 0; Iterator_i < NumOfTables_i; Iterator_i++){
03142                 clear autoArgs
03143                 put(autoArgs, Iterator_i )
03144                 oleMethod(TableList_ole, "Item", autoArgs, Table_ole)
03145                 ProcessTable(Table_ole)
03146         }
03147         }
03148         
03149         /* get Number of Transpose in Section */
03150         oleGet(TransposeList_ole, "Length", NumOfTranspose_i)
03151         if (NumOfTranspose_i > 0){
03152         if (!InitExcel_b){
03153             ExcelInit(true)
03154             InitExcel_b=true
03155         }
03156         for (Iterator_i = 0; Iterator_i < NumOfTranspose_i; Iterator_i++){
03157                 clear autoArgs
03158                 put(autoArgs, Iterator_i )
03159                 oleMethod(TransposeList_ole, "Item", autoArgs, Transpose_ole)
03160                 ProcessTranspose(Transpose_ole)
03161         }
03162         }
03163         /* get Number of Sections */
03164         oleGet(SectionList_ole, "Length", NumOfSections_i)
03165         if (NumOfSections_i > 0){
03166         for (SectionIterator_i = 0; SectionIterator_i < NumOfSections_i; SectionIterator_i++){
03167                 clear autoArgs
03168             put(autoArgs, SectionIterator_i )
03169             oleMethod(SectionList_ole, "Item", autoArgs, Section_ole)               
03170             HandleSection(Section_ole, SectionStructureLevel_i + 1)
03171             }
03172     }
03173 }
03174 /* *****************************************************************
03175 function : GetFilterFromXML ()
03176 Description: XMl file reading for fetching the filters, section information
03177 ******************************************************************/
03178 void GetFilterFromXML(){
03179         /* local declaration */
03180                      
03181         int             NumOfSections_i                         //Number of all Sections in Chapter
03182         int             IterateSection_i                       //Section iterator       
03183         OleAutoObj      SectionList_ole                         //List of Section in Chapter
03184         OleAutoObj      Section_ole                                                     //actual Section
03185 
03186         int                     MacroIterator_i
03187         int                     NumOfMacros_i
03188         OleAutoObj              Macronames_ole
03189         OleAutoObj              Macros_ole      
03190         OleAutoObj              MacrosList_ole
03191         string                  Macroname_s
03192 
03193 
03194         
03195         
03196     /* Get List of Sections */
03197         clear autoArgs
03198         put(autoArgs, "Section")
03199         oleMethod(Root_ole, "selectNodes", autoArgs, SectionList_ole)
03200         
03201         /* Get Number of Sections */
03202         oleGet(SectionList_ole, "length", NumOfSections_i)
03203         
03204         /* iterate over all Sections */
03205         for (IterateSection_i = 0; IterateSection_i < NumOfSections_i; IterateSection_i++)
03206         {
03207         clear autoArgs
03208         put(autoArgs,IterateSection_i)
03209         oleMethod(SectionList_ole, "Item", autoArgs, Section_ole)
03210                 
03211                 HandleSection(Section_ole,0)
03212         }
03213         //GSTCS-445 implementation for call back hook of macros
03214         clear autoArgs
03215         put(autoArgs, "Macros")
03216         oleMethod(Root_ole, "selectSingleNode", autoArgs, Macros_ole)
03217         if (Macros_ole!=null)
03218         {
03219         
03220                 clear autoArgs
03221                 put(autoArgs, "macronames")
03222                 oleMethod(Macros_ole, "selectNodes", autoArgs, MacrosList_ole)
03223                 if (MacrosList_ole!=null)
03224                 {
03225                         oleGet(MacrosList_ole, "Length", NumOfMacros_i)
03226         
03227                         for (MacroIterator_i = 0; MacroIterator_i < NumOfMacros_i;MacroIterator_i++)
03228                         {
03229                                 clear autoArgs
03230                                 put(autoArgs, MacroIterator_i)
03231                                 oleMethod(MacrosList_ole, "Item", autoArgs, Macronames_ole)
03232                                 clear autoArgs
03233                                 put(autoArgs, "macroname")
03234                                 oleMethod(Macronames_ole, "getAttribute", autoArgs, Macroname_s)
03235                                 
03236                                 if (Macroname_s!="" || Macroname_s!=null)
03237                                 {
03238                                         clear objArgBlock
03239                                         put (objArgBlock, "MacroName", Macroname_s)
03240                                         checkRes (oleMethod (objWord, "Run", objArgBlock))
03241                                 
03242                                 }
03243                         }
03244                 }
03245         }
03246         //clear objArgBlock
03247         //put (objArgBlock, "MacroName", "CreateHyperlinK")
03248         //checkRes (oleMethod (objWord, "Run", objArgBlock))
03249         
03250         UpdateTOC()
03251 }
03252 
03253 /* *****************************************************************
03254 function : initXML ()
03255 Description: XMl file reading
03256 ******************************************************************/
03257 bool initXML(){
03258   
03259     string          Template_s     
03260         
03261         /* Load XML with filter description */  
03262         clear autoArgs
03263         put(autoArgs,ConfigFileName_s)
03264         oleMethod(xmldoc, "Load", autoArgs)
03265     
03266     /* Get root element from xmldoc */
03267         oleGet(xmldoc, "documentElement", Root_ole)
03268 
03269    if (null Root_ole)
03270    {
03271                 ack "Can not get root element in XML configuration file.\n\nConfig file: "ConfigFileName_s"\n\nPlease check wellformess of XML file and validate it with an XML Editor!"
03272                 return false
03273    }
03274         
03275     /* get Template File */
03276         clear autoArgs
03277         put(autoArgs, "Template")
03278         oleMethod(Root_ole, "getAttribute", autoArgs, TemplateFileName_s)
03279         /* check Template */
03280         if ((TemplateFileName_s != "") and (canOpenFile(TemplateFileName_s, false)))
03281         {
03282             TemplateFileName_s = TemplateFileName_s
03283     }      
03284     else
03285         {
03286         ack("Template should be in openable mode\n" )   
03287                  halt
03288                  return false;
03289                 
03290     }  
03291         
03292         clear autoArgs
03293     put(autoArgs, "Target")
03294     oleMethod(Root_ole, "getAttribute", autoArgs, Target_s)
03295    return true
03296  }  
03297 
03298 /* ***********************************************************************
03299 Function:  Export () 
03300 Description: Export function triggered when click on "export to word" internally calls different functions to expoprt the object into word and finally gives the message for the user.
03301  ************************************************************************/
03302 void Export(DB db){
03303     Module      OpenModule_m    
03304     Module      CurrentModule_m = current
03305     bool        bSaved          = false
03306     View        View_vw
03307     string      info_s
03308  
03309     istart = getTickCount_ ()   
03310 
03311         /* save current view */
03312     View_vw = view(currentView(current Module))
03313     /* get configuration file*/
03314     ConfigFileName_s = get(dbeConfigFileList)
03315         if (!matches("(xml|XML)$", ConfigFileName_s))
03316         {
03317             infoBox("Please select a valid XMl configuration file.")        
03318             return
03319     }
03320         
03321         /* hide GUI */
03322         //hide dbProjectReportGUI
03323         /* Load XML and Template */
03324 
03325   if (initXML())
03326   {
03327         //templateName = TemplateFileName_s
03328         
03329 
03330         GetFilterFromXML()      
03331         /* open current view in Module */
03332         if (!null Target_s)
03333         {
03334             /* Save Word Document */
03335             clear autoArgs
03336             put(autoArgs, Target_s)
03337             oleMethod(objDoc, "SaveAs", autoArgs)       
03338             /*Check if Save was successful */
03339             oleGet(objDoc, "Saved", bSaved)
03340         if (!bSaved)
03341                 {
03342            info_s=Target_s " is write protected. Document not saved.\n"         
03343             }
03344     }
03345         current = CurrentModule_m       
03346         load(View_vw)
03347         delete autoArgs
03348         int iend = getTickCount_()
03349         //iend = dateOf(intOf(today()))
03350         
03351 int iDiff = (iend)-(istart)
03352 ack ("The timespent to generate the report " iDiff  "miliseconds\n")
03353         infoBox  "Project Report successfully generated.\n"
03354   }
03355 }
03356 
03357 /* *****************************************************************************************
03358 function : GetConfigFile()
03359 description: for testing purpose set the module attribute and the value to be populated on DBE
03360 **************************************************************************** */ 
03361 void GetConfigFile(){
03362     Module Mod = current
03363     if (exists attribute XML_CONFIG_ATTRIBUTE){
03364         string XmlConfig_s = Mod.XML_CONFIG_ATTRIBUTE
03365         if (! null XmlConfig_s){
03366             set(dbeConfigFileList, XmlConfig_s)
03367         }
03368     }
03369 }
03370 /* ********************************************************
03371 Function :initGUI
03372 description: Initial GUI to fetch the config file
03373 *********************************************************** */
03374 void initGUI()
03375 {
03376         dbProjectReportGUI      = create ("Export Sample Project Report", styleCentered | styleFixed) //empty dialogbox creation
03377         
03378         dbeConfigFileList   = fileName(dbProjectReportGUI, "XML-Configuration-File: ","", "*.xml", "Extended Markup Language", true) //dialog box for capturing a file name
03379         GetConfigFile()
03380         
03381         msgDBE              = label(dbProjectReportGUI," ") //label in the DB
03382         ok(dbProjectReportGUI, "Export to Word", Export)        //Ok button
03383  
03384         show(dbProjectReportGUI)        //enable the DB, suspend the dxl
03385         
03386 }
03387 /* end of functions */
03388 
03389 /**************************************************************/
03390 /* Start of the script */
03391 /**************************************************************/
03392 
03393 //istart = intOf(dateAndTime(today))
03394 
03395  
03396 
03397 
03398 /* Create OLE-Object xmldoc - the XML properties are used to initialize the OLE object */
03399 xmldoc = oleCreateAutoObject("Msxml2.DOMDocument") 
03400 olePut(xmldoc, "async", false) //Specifies whether asynchronous download is permitted.
03401 olePut(xmldoc, "resolveExternals", true) //Indicates whether external definitions, resolvable namespaces, document type definition (DTD) external subsets, and external entity references, are to be resolved at parse time, independent of validation.
03402 
03403 /*GUI initialization to fetch the configuration file*/
03404 initGUI()