Tool to extract lotusscript from .ntf into text file for code line count

Hi,I need to count source lines of code (SLOC) for all our LN apps for app sizing, but the SLOC counting tool only works on text files, so reading .ntf files won’t do since they have embedded binary data.

Does anyone know of a tool, preferably stand alone, that can extract all LotusScript source code from .ntf files into plain text files? Doing this manually would just take too long.

Any help would be greatly appreciated.

-TR-

Subject: Tool to extract lotusscript from .ntf into text file for code line count

Here is code that exports lotusscript code from selected database to C:\REPORTSCode is not very clean and smart but it should work.

Dim dxldb As NotesDatabase

Dim domparser As NotesDOMParser

Dim dxlexporter As NotesDXLExporter

Dim dxlimporter As NotesDXLImporter

Dim dxlsession As NotesSession

Dim dxlws As NotesUIWorkspace

Dim searchdb As NotesDatabase

Dim DoTotal As Boolean

Dim DoChanges As Boolean

Dim objtype As String

Dim totalreport As String

Dim objlist As Variant

Dim objname As String

Dim propertylist As Variant

Dim proplist List As String

Dim txt As String

Sub Initialize

Set dxlsession = New NotesSession

Set dxldb = dxlsession.CurrentDatabase

Set dxlws = New NotesUIWorkspace

Dim ncol As NotesNoteCollection

Dim xmldoc As NotesDocument



If AskDatabase Then

	

	Dototal = True

	Set ncol = GetNoteCollection 'haetaan notecollection design-elementeistä

	

	Dim fil As Integer

	fil = Freefile()

	Dim filename As String	

	Dim nid As String	

	Dim i As Integer

	

	fileName = "C:\REPORTS"

	

	Open fileName For Output As fil

	

	nid = ncol.GetFirstNoteId

	

	For i =  1  To ncol.Count 'tehdään dxl-siirto yksi kerrallaan muistirajojen vuoksi

		

		Set xmldoc = searchdb.GetDocumentByID(nid)		

		If Not xmldoc Is Nothing Then

			

			Set domparser = dxlsession.CreateDOMParser

			Set dxlexporter = dxlsession.CreateDXLExporter

			dxlexporter.ExitOnFirstFatalError = True

			Call dxlexporter.setinput(xmldoc)

			Call domparser.setinput(dxlexporter)

			On Event PostDOMParse From domparser Call PlayWithDXLRoutine

			Call dxlexporter.process() 

			

			Print #fil, txt

			

		End If

		nid = ncol.GetNextNoteId(nid)

	Next

	

	If fil > 0 Then Close #fil

	End

	

End If

End Sub

Function AskDatabase() As Boolean

Dim askme As Variant	

Dim s As String

Dim ddoc As New NotesDocument(dxldb)

askme = dxlws.Prompt(13, 	"Database", "Choose the database you want to edit.")

If  Datatype(askme) = 0 Then

	Print "Cancelled"

	End 

End If



If Ubound(askme) > 0 Then

	On Error Resume Next

	Set searchdb  = dxlsession.GetDatabase(askme(0),askme(1),False)	

	If searchdb.IsOpen Then

		AskDatabase = True

	Else

		AskDatabase = False

		Msgbox("Could not open target database")

	End If

	

End If

End Function

Function GetNoteCollection() As NotesNoteCollection

Dim nc As NotesNoteCollection

Set nc = searchdb.CreateNoteCollection(False)



nc.SelectActions= True

nc.SelectAgents= True

nc.SelectDatabaseScript = True

nc.SelectFolders = True

nc.SelectForms = True

nc.SelectPages = True

nc.SelectScriptLibraries = True

nc.SelectSharedFields = True

nc.SelectSubforms = True

nc.SelectViews = True	



Call nc.BuildCollection

Set GetNoteCollection = nc

End Function

Sub PlayWithDXLRoutine(Source As NotesDOMParser)

Call CheckDaFields

End Sub

Sub CheckDaFields

Dim NodeList As NotesDOMNodeList

Dim objs As NotesDOMNodeList

Dim codes As NotesDOMNodeList

Dim codeEvent As NotesDOMElementNode

Dim codetype As String

Dim numChildren As Integer	

Dim child As NotesDOMNode

Dim i As Integer

Dim d As Integer

Dim Element As NotesDOMElementNode	

Dim attrs As notesdomnamednodemap

Dim a As notesdomattributenode



Dim domdoc As NotesDOMDocumentNode



Set domdoc = domparser.Document



Dim codex As String

Dim did As Boolean

Set objs = domparser.Document.GetElementsByTagName("lotusscript")

For i = 1 To objs.NumberOfEntries

	Set Element = objs.GetItem(i) 'form , view, page etc..	

	numChildren =  Element.NumberOfChildNodes 

	Set child = Element.FirstChild     

	If Not Isnull(child) Then

		codex = codex & Chr(10) & child.NodeValue

		did = True

	End If

Next

If did Then 

	txt = codex

Else

	txt = ""

End If



propertylist = proplist

Erase proplist

End Sub

if you have any questions please post here or mail directly to:

ollipk at gmail dot com

Subject: RE: Tool to extract lotusscript from .ntf into text file for code line count

Thanks for the script Olli.I was looking more for some external tool to rip all script from an ntf export file so it’s not reliant on LN users. Since we have lots of code in numerous languages being sized by one person in future, a separate tool would have been more useful.

All the same, your code will come in handy if I can’t find another alternative.

Regards and thanks again Olli - appreciated.

-TR-