Public DXLobj As DXLprocessing
Private ses As NotesSession
Private wks As NotesUIWorkspace
Private db As NotesDatabase
Private Const LIST_SEP={:}
Private Const attachBody={attachBody}
Private Const htmlTransform={HTMLTransform}
Private Const RT_FIELDS={attachBody:htmlTransform}
Private rtFields As Variant
'************************************************
'************************************************
Class DXLprocessingBase As ErrorHandler
Private DOM_off As Boolean
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub New(transformOnly As Boolean)
DOM_off=transformOnly
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function ApplyXSLT(doc As NotesDocument, ss As String) As NotesStream
On Error Goto ErrH
Dim lsTimer As New LsTimer()
Call lsTimer.StartTimer()
Dim XML_in As NotesStream
Dim XML_out As NotesStream ' output file
Dim out_obj As NotesXMLProcessor
'удаляем все "вспомогательные" РТ поля и вложения
Forall m In rtFields
If doc.HasItem(Cstr(m)) Then doc.RemoveItem(Cstr(m)):Print {Remove} & Cstr(m):Call doc.Save(True,False)
End Forall
Set XML_in=ses.CreateStream
Set XML_out=ses.CreateStream
XML_out.Truncate
Dim transformer As NotesXSLTransformer
On Error lsERR_NOTES_XSLT_INPUT_OBJECT Goto err_IN
On Error lsERR_NOTES_XSLT_OUTPUT_OBJECT Goto err_OUT
On Error lsERR_NOTES_XSLT_STYLESHEET_OBJECT Goto err_SS
On Error lsERR_NOTES_DXLEXPORTER_INPUT_OBJECT Goto err_DXLIN
Set transformer=ses.CreateXSLTransformer
Dim xslt As NotesStream
Set xslt = ses.CreateStream
Call xslt.Truncate
Call xslt.WriteText(ss) 'экономит время, но непредсказуемое форматирование вывода
'убираем все переносы строк, чтобы форматирование XSL не накладывалось на результат
'Call xslt.WriteText(Replace(ss,Split(Chr(10) & {:} & Chr(13),{:}),{}))
' Print {XSLT size:} & Cstr(xslt.Bytes)
'таблица преобразований
Call transformer.SetStylesheet(xslt)
Call transformer.SetOutput(XML_out)
Set out_obj=transformer'для будущих вариантов обработки
If Not DOM_off Then
'включаем в цепочку DOM parser - для обработки в PostParse
Dim docDOM As NotesDOMParser
Set docDOM=ses.CreateDOMParser
Call docDOM.SetOutput(out_obj)
On Event PostDOMParse From docDOM Call postParse
Set out_obj=docDOM'для будущих вариантов обработки
End If
Dim exporter As NotesDXLExporter
Set exporter=ses.CreateDxlExporter(doc, out_obj)
exporter.ConvertNotesbitmapsToGIF=True
' Dim importer As NotesDXLImporter
' Set importer=ses.CreateDXLImporter(transformer, XML_out)
' importer.DesignImportOption = DXLIMPORTOPTION_REPLACE_ELSE_IGNORE
Print {Processing to stream...}
Call exporter.Process
Call RTprocessing(doc, XML_out)
Call lsTimer.StopTimer()
Print Getthreadinfo(1) & { - elapsed time:}Format(lsTimer.GetSecondsLapsed(), "0.000")
'выводим результат
Set ApplyXSLT=XML_out
Quit:
Exit Function
err_IN:
Print "XSL Input error:XSLTransformer Process"
RaiseError
Resume Quit
err_OUT:
Print "XSL Output error:XSLTransformer Process"
RaiseError
Resume Quit
err_SS:
Print "Style Sheet error:XSLTransformer Process"
RaiseError
Resume Quit
err_DXLIN:
Print "DXL input Object error"
ErrH:
RaiseError
If (Not transformer Is Nothing) Then If Len(transformer.Log) > 0 Then Msgbox transformer.Log
Resume Quit
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub RTprocessing (doc As NotesDocument, xml As NotesStream)
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub postParse(xml As NotesDOMParser)
End Sub
End Class
'************************************************
'************************************************
Class DXLprocessing As DXLprocessingBase
Private attachments List As String
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub New(), DXLprocessingBase(False)
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub RTprocessing (doc As NotesDocument, xml As NotesStream)
Dim lsTimer As New LsTimer()
Call lsTimer.StartTimer()
Print {Processing to RT...}
'добавляем вложения (получены в PostParse)
Dim rt As NotesRichTextItem
Set rt=doc.CreateRichTextItem(attachBody)
rt.IsProtected=False
rt.IsEncrypted=False
rt.IsSigned=False
rt.IsSummary=False
Forall a In attachments
Call AddAttachment(a, doc, attachBody)
Call DeleteFile(a)
'Print {attach:} & a
End Forall
'результат кладём в РТ поле
Dim buff As New StringBuffer(DEF_BUFFER)
xml.Position=0
Do
buff.Append(xml.ReadText)
Loop Until xml.IsEOS
Call doc.ReplaceItemValue({Form}, {mainnotes})
Dim item As NotesItem
Set item=doc.ReplaceItemValue(htmlTransform, buff.toString)
item.IsSummary=True
Call doc.ComputeWithForm(False, False)
Call doc.Save(True, True)
Call lsTimer.StopTimer()
Print Getthreadinfo(1) & { - elapsed time:}Format(lsTimer.GetSecondsLapsed(), "0.000")
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'обработка без наложения XSLT
Function ReplaceAttachDOM(doc As NotesDocument) As NotesStream
Dim docDOM As NotesDOMParser
Dim exporter As NotesDXLExporter
Dim importer As NotesDXLImporter
On Error Goto ErrH
Forall m In rtFields
If doc.HasItem(Cstr(m)) Then doc.RemoveItem(Cstr(m)):Call doc.Save(True,False)
End Forall
Dim XML_out As NotesStream
Set XML_out=ses.CreateStream
XML_out.Truncate
Set docDOM=ses.CreateDOMParser
Call docDOM.SetOutput(XML_out)
'здесь будут выдёргиваться вложения и меняться DXL
On Event PostDOMParse From docDOM Call postParse
Set exporter=ses.CreateDXLExporter(doc,docDOM)
exporter.ConvertNotesbitmapsToGIF=True
' Set importer=ses.CreateDXLImporter(docDOM,db)
' importer.DesignImportOption = DXLIMPORTOPTION_REPLACE_ELSE_IGNORE
Set ReplaceAttachDOM=XML_out
Quit:
Exit Function
ErrH:
RaiseError
Resume Quit
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub postParse(xml As NotesDOMParser)
On Error Goto ErrH
Dim lsTimer As New LsTimer()
Call lsTimer.StartTimer()
Dim root As NotesDOMDocumentNode
Dim nodeList As NotesDOMNodeList
Dim node As NotesDOMElementNode
Erase attachments
Dim embViewNode As NotesDOMElementNode
Set root=xml.Document
Set nodeList=root.GetElementsByTagName("noteinfo")
Dim fname As String
Set node=nodeList.GetItem(1)
fname=node.GetAttribute({noteid})
Dim path As String
'совместимость в ОС
path=Replace(ses.GetEnvironmentString("Directory", True), {\}, {/}) & {/} & fname
'path=ses.GetEnvironmentString("Directory", True) & {/} & fname
Set nodeList=root.GetElementsByTagName("picture")
Dim i As Long
For i=1 To nodeList.NumberOfEntries
Set node=nodeList.GetItem(i)
If node.HasChildNodes Then
Dim ext As String
ext={}
Dim imgnode As NotesDOMElementNode
Set imgnode=node.FirstChild
Print {image type:} & imgnode.TagName
Select Case Ucase(imgnode.TagName)
Case {JPEG}:ext={.jpg}
Case {GIF}:ext={.gif}
Case {CGM}:ext={.cgm}
Case Else:
ext={}
End Select
Dim part As String
part= Cstr(i) & ext
Dim out As NotesStream
Set out=ses.CreateStream
Dim encpath As String
encpath=path & Cstr(i) & {enc64}
If out.Open(encpath, {UTF-8}) Then
out.Position=0
Call out.Truncate
Dim s As String
s=imgnode.FirstChild.NodeValue
Print {Base64 len:}Cstr(Len(s))
Call out.WriteText(s)
Call out.Close()
Call Base64Obj.DecodeFileToFile(encpath, path & part)
Call DeleteFile(encpath)
imgnode.FirstChild.NodeValue=fname & part
attachments(fname & part)=path & part
Else
Print {Failed to open:} & encpath
End If
' Do While Not Isnull(imgnode)
' Set imgnode=imgnode.NextSibling
' Loop
End If
Next
Call xml.Serialize
Call lsTimer.StopTimer()
Print Getthreadinfo(1) & { - elapsed time:}Format(lsTimer.GetSecondsLapsed(), "0.000")
Quit:
Exit Sub
ErrH:
RaiseError
Resume Quit
End Sub
End Class
Sub Initialize
Set ses=New NotesSession
Set wks=New NotesUIWorkspace
Set db=ses.CurrentDatabase
rtFields=Split(RT_FIELDS, LIST_SEP)
Set DXLobj=New DXLprocessing
End Sub