Yesterday I was asking a way to get the content out of a Stylesheet Design element, see
previous post.
Thanks to Tim Tripcony I solved the problem.
SolutionFirst of all I downloaded the base64 class from
this website.
Then I created the function 'getStylesheet'
Dim nc As NotesNoteCollection
Dim domParser As NotesDOMParser
Dim docNode As NotesDOMDocumentNode
Dim base64 As New Base64()
Dim stream As NotesStream, stream1 As NotesStream
Dim exporter As NotesDXLExporter
Set nc = db.CreateNoteCollection(False)
nc.Selectstylesheetresources=True
Call nc.BuildCollection
Set stream = session.CreateStream
Set stream1 = session.CreateStream
Call stream1.Truncate
Set exporter = session.CreateDXLExporter(nc, stream)
Call exporter.Process
Set domParser=session.CreateDOMParser(stream, stream1)
Call domParser.Serialize
Call domParser.Process
'get the document node
Set docNode = domParser.Document
Call findFileData(domParser, docNode)
GetStylesheet = base64.decode(stream1.Readtext())
Call stream.Close()
Call stream1.Close()
End Function
And a function 'findFileData', to loop through the DOM Nodes and generate the content of the FileData Tag as DOMParser output.
Function findFileData ( domParser As NotesDOMParser, node As NotesDOMNode) As string
Dim child As NotesDOMNode
Dim elt As NotesDOMNode
Dim attrs As NotesDOMNamedNodeMap
Dim a As NotesDOMAttributeNode
Dim LF As String
LF = Chr(13)+Chr(10)
If Not node.IsNull Then
Select Case node.NodeType
Case DOMNODETYPE_DOCUMENT_NODE: ' If it is a Document node
Set child = node.FirstChild ' Get the first node
Dim numChildNodes As Integer
numChildNodes = node.NumberOfChildNodes
While numChildNodes > 0
Set child = child.NextSibling ' Get next node
numChildNodes = numChildNodes - 1
Call findFileData(domParser, child)
Wend
Case DOMNODETYPE_TEXT_NODE: ' Plain text node
If(node.Parentnode.Nodename="filedata")Then
domParser.Output(node.NodeValue+LF)
Exit function
End If
Case DOMNODETYPE_ELEMENT_NODE: ' Most nodes are Elements
Set elt = node
Dim numAttributes As Integer, numChildren As Integer
numAttributes = elt.attributes.numberofentries
Set attrs = elt.Attributes ' Get attributes
Dim i As Integer
For i = 1 To numAttributes ' Loop through them
Set a = attrs.GetItem(i)
Next
numChildren = elt.NumberOfChildNodes
Set child = elt.FirstChild ' Get child
While numChildren > 0
Call findFileData(domParser, child)
Set child = child.NextSibling ' Get next child
numChildren = numChildren - 1
Wend
Case Else:
End Select 'node.NodeType
End If 'Not node.IsNull
End Function
In the function 'getStylesheet' I run the code
GetStylesheet = base64.decode(stream1.Readtext())
to return the decoded text.