cleanandvalidate/Redaction/Validation.xba

322 lines
11 KiB
Text
Raw Normal View History

2019-10-16 15:42:48 +03:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
2020-07-03 16:13:34 +02:00
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Validation" script:language="StarBasic">Sub markval4
2019-10-16 15:42:48 +03:00
End Sub
2020-03-21 11:55:13 +01:00
Private Function isInDoc(searchString As String) As Boolean
2019-10-17 18:48:22 +03:00
Dim founds As Object
Dim sDesc As Object
Dim srch(0) as new com.sun.star.beans.PropertyValue
sDesc = Thiscomponent.createSearchDescriptor()
sDesc.SearchAll = true
sDesc.ValueSearch = false
sDesc.SearchStyles = false
sDesc.SearchRegularExpression = true
sDesc.SearchString = searchString
founds = Thiscomponent.findAll(sDesc)
If founds.count &lt;&gt; 0 Then
isInDoc = true
Else
isInDoc = false
EndIf
End Function
2019-10-16 16:17:28 +03:00
Sub validateButton
2019-10-17 18:48:22 +03:00
Dim footnotesReport As String
Dim graphicsReport As String
Dim outlineInNotesReport As String
2019-10-17 18:48:22 +03:00
Dim badText As Boolean
Dim badNumberings As Boolean
2020-03-06 17:37:35 +01:00
Dim needExtendedInfo As Boolean
Dim config As Object
config = initRedactionConfiguration()
2019-10-17 18:48:22 +03:00
badText = false
badNumberings = false
2020-07-03 15:47:47 +02:00
footnotesReport = noteSingsCheck
2019-10-17 18:48:22 +03:00
graphicsReport = checkGraphics
outlineInNotesReport = checkNotesOutline()
If outlineInNotesReport &lt;&gt; &quot;&quot; Then
MsgBox outlineInNotesReport
2019-10-17 18:48:22 +03:00
EndIf
If footnotesReport &lt;&gt; &quot;&quot; Then
MsgBox footnotesReport
EndIf
2019-10-17 18:48:22 +03:00
If graphicsReport &lt;&gt; &quot;&quot; Then
MsgBox graphicsReport
2019-10-17 18:48:22 +03:00
EndIf
If isInDoc(&quot;[\uE000-\uF8FF]&quot;) Then
badText = true
EndIf
2020-03-06 17:37:35 +01:00
If config.getPropertyValue(&quot;complexity&quot;) = &quot;makerUp&quot; then
needExtendedInfo = true
Else
needExtendedInfo = false
EndIf
printNumberingSymbols(needExtendedInfo)
If badText OR badNumberings OR footnotesReport &lt;&gt; &quot;&quot; OR graphicsReport &lt;&gt; &quot;&quot; Or outlineInNotesReport &lt;&gt; &quot;&quot; Then
2020-05-04 15:52:04 +02:00
MsgBox getTranslation(&quot;validationWarning&quot;)
2019-10-17 18:48:22 +03:00
If badText Then
2020-05-04 15:52:04 +02:00
MsgBox getTranslation(&quot;validationBadSymbolsNotification&quot;)
2019-10-17 18:48:22 +03:00
removeBadCharacters
EndIf
Else
2020-05-04 15:52:04 +02:00
MsgBox getTranslation(&quot;validationSuccess&quot;)
2019-10-17 18:48:22 +03:00
EndIf
2019-10-17 00:31:08 +03:00
End Sub
2020-03-21 11:55:13 +01:00
Private Function checkGraphics() As String
2019-10-17 18:48:22 +03:00
Dim drawPages As Object
Dim count as Integer
Dim draw As Object
Dim result As String
2019-10-18 18:56:22 +03:00
result = &quot;&quot;
2019-10-17 18:48:22 +03:00
Dim shapeType As String
2019-10-18 18:56:22 +03:00
Dim embeededObject As Object
Dim badFrame As Long
badFrame = 0
2019-10-17 18:48:22 +03:00
Dim drawingN As Long
drawingN = 0
drawPages = ThisComponent.DrawPage
2020-03-21 12:37:32 +01:00
Dim i As Integer
2019-10-17 18:48:22 +03:00
count = drawPages.getCount()
For i = 0 to count-1
draw = drawPages.getByIndex(i)
shapeType = draw.ShapeType
If InStr(shapeType,&quot;com.sun.star.drawing&quot;) = 1 Then
drawingN = drawingN + 1
EndIf
2019-10-18 18:56:22 +03:00
If InStr(shapeType,&quot;FrameShape&quot;) = 1 Then
2019-10-21 13:25:47 +03:00
If draw.supportsService(&quot;com.sun.star.text.TextEmbeddedObject&quot;) Then
embeededObject = draw.getEmbeddedObject()
2020-01-13 16:08:46 +01:00
If IsNull(embeededObject) Then
2019-10-21 13:25:47 +03:00
badFrame = badFrame + 1
Else
2020-01-13 16:08:46 +01:00
If Not embeededObject.supportsService(&quot;com.sun.star.formula.FormulaProperties&quot;) Then
badFrame = badFrame + 1
Else
&apos;Formula
EndIf
2019-10-21 13:25:47 +03:00
EndIf
2019-10-18 18:56:22 +03:00
EndIf
EndIf
2019-10-17 18:48:22 +03:00
Next i
If drawingN &lt;&gt; 0 Then
2020-05-04 15:52:04 +02:00
result = result &amp; getTranslation(&quot;validationBadDrawings&quot;) &amp; drawingN &amp; getTranslation(&quot;validationExcerptNotSuitable&quot;) &amp; chr(10)
2019-10-18 18:56:22 +03:00
EndIf
If badFrame &lt;&gt; 0 Then
2020-05-04 15:52:04 +02:00
result = result &amp; getTranslation(&quot;validationBadEmbeededObjects&quot;) &amp; badFrame &amp; getTranslation(&quot;validationExcerptNotSuitable&quot;) &amp; chr(10)
2019-10-17 18:48:22 +03:00
EndIf
checkGraphics = result
End Function
2019-10-17 00:31:08 +03:00
Private Sub removeBadCharacters
StartTracking
2020-03-21 11:55:13 +01:00
AskAndReplace(&quot;[\uE000-\uF8FF]+&quot;,&quot;&quot;)
2019-10-17 00:31:08 +03:00
StopTracking
showTrackedChanges
End Sub
2020-07-03 15:47:47 +02:00
Private Function noteSingsCheck() As String
2019-10-17 00:31:08 +03:00
Dim footnotes As Object
2020-07-03 15:47:47 +02:00
Dim footnote As Object
Dim endnote As Object
Dim endnotes As Object
2019-10-17 00:31:08 +03:00
Dim count as Integer
Dim charNum as Long
Dim char As Long
Dim label As String
Dim result As String
result = &quot;&quot;
2020-07-03 15:47:47 +02:00
footnotes = ThisComponent.footnotes
endnotes = ThisComponent.Footnotes
2019-10-17 00:31:08 +03:00
count = footnotes.getCount
2020-03-21 12:37:32 +01:00
Dim i As Integer
Dim j As Integer
2019-10-17 00:31:08 +03:00
For i = 0 to count-1
footnote = footnotes.getByIndex(i)
label = footnote.Label
charNum = Len(label)
For j = 1 to charNum
char = Asc(Right(Left(label,j),1))
If char &gt;= 57344 AND char &lt;= 63743 then
2020-05-04 15:52:04 +02:00
result = result &amp; getTranslation(&quot;validateFootnotes1&quot;) &amp; &quot; &quot; &amp; Chr(char) &amp; &quot; &quot; &amp; getTranslation(&quot;validateFootnotes2&quot;) &amp; &quot; &quot; &amp; i &amp; &quot; &quot; &amp; getTranslation(&quot;validateFootnotes3&quot;) &amp; chr(10)
2019-10-17 00:31:08 +03:00
End If
Next j
Next i
2020-07-03 15:47:47 +02:00
count = endnotes.getCount
For i = 0 to count-1
endnote = endnotes.getByIndex(i)
label = endnote.Label
charNum = Len(label)
For j = 1 to charNum
char = Asc(Right(Left(label,j),1))
If char &gt;= 57344 AND char &lt;= 63743 then
2020-07-03 16:13:34 +02:00
result = result &amp; getTranslation(&quot;validateFootnotes1&quot;) &amp; &quot; &quot; &amp; Chr(char) &amp; &quot; &quot; &amp; getTranslation(&quot;validateEndnotes1&quot;) &amp; &quot; &quot; &amp; i &amp; &quot; &quot; &amp; getTranslation(&quot;validateFootnotes3&quot;) &amp; chr(10)
2020-07-03 15:47:47 +02:00
End If
Next j
Next i
noteSingsCheck = result
2019-10-17 18:48:22 +03:00
End Function
2019-10-16 15:42:48 +03:00
Function checkNotesOutline As String
Dim oDescriptor As Object
Dim footNotes As Object
Dim x As Integer
Dim aNote As Object
Dim oEnum As Object
Dim oCurPar As Object
Dim result As String
result = &quot;&quot;
footNotes = thisComponent.footNotes
endNotes = thisComponent.footNotes
for x = 0 to footNotes.Count -1
aNote = footNotes.getByIndex(x)
aNote.Anchor.CharStyleName=&quot;Footnote anchor&quot;
oEnum = aNote.Text.createEnumeration()
Do While oEnum.hasMoreElements()
oCurPar = oEnum.nextElement()
If oCurPar.OutlineLevel &gt; 0 Then
result = result &amp; getTranslation(&quot;validateFootnotes2&quot;) &amp; &quot; &quot; &amp; x &amp; &quot; &quot; &amp; getTranslation(&quot;setOutlineLevel&quot;) &amp; &quot; &quot; &amp; oCurPar.OutlineLevel &amp; chr(10)
EndIf
Loop
Next
for x = 0 to endNotes.Count -1
aNote = endNotes.getByIndex(x)
aNote.Anchor.CharStyleName=&quot;Footnote anchor&quot;
oEnum = aNote.Text.createEnumeration()
Do While oEnum.hasMoreElements()
oCurPar = oEnum.nextElement()
If oCurPar.OutlineLevel &gt; 0 Then
result = result &amp; getTranslation(&quot;validateEndnotes1&quot;) &amp; &quot; &quot; &amp; x &amp; &quot; &quot; &amp; getTranslation(&quot;setOutlineLevel&quot;) &amp; &quot; &quot; &amp; oCurPar.OutlineLevel &amp; chr(10)
EndIf
Loop
Next
checkNotesOutline = result
End Function
2020-03-06 17:37:35 +01:00
Private Sub printNumberingSymbols(needExtendedInfo)
Dim families As Object
Dim numStyles As Object
Dim numStyle As Object
Dim numRules As Object
Dim numRule As Object
Dim prop As Object
Dim enum1 As Object
Dim enum1Element As Object
Dim fontProp As Object
Dim fontName As String
Dim result As String
Dim resultBad As String
2020-03-21 12:37:32 +01:00
Dim excerpt As String
Dim exLength As Integer
Dim report As String
Dim k As Integer
2020-03-06 17:37:35 +01:00
families = ThisComponent.StyleFamilies
numStyles = families.getByName(&quot;NumberingStyles&quot;)
result = &quot;&quot;
resultBad = &quot;&quot;
enum1 = ThisComponent.Text.createEnumeration
Do While enum1.hasMoreElements
enum1Element = enum1.nextElement
If enum1Element.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
If NOT IsMissing(enum1Element.NumberingRules) AND NOT IsEmpty(enum1Element.NumberingRules) Then
numRules = enum1Element.NumberingRules
If numRules.hasElements Then
numRule = numRules.getByIndex(enum1Element.NumberingLevel)
fontName = &quot;&quot;
fontChar = &quot;&quot;
For k = 0 To Ubound(numRule)
prop = numRule(k)
If prop.Name = &quot;BulletFont&quot; Then
fontName = prop.Value.Name
EndIf
If prop.Name = &quot;BulletChar&quot; Then
fontChar = prop.Value
EndIf
Next k
exLength = 15
excerpt = enum1Element.String
If Len(excerpt) &lt; exLength Then
exLength = Len(excerpt)
EndIf
2020-03-18 22:14:07 +01:00
If fontChar &lt;&gt; &quot;&quot; Then
2020-05-04 15:52:04 +02:00
tmp = getTranslation(&quot;validateNumberingLevel&quot;) &amp;&quot; &quot; &amp; (j + 1) &amp; &quot; &quot; &amp; getTranslation(&quot;validateNumberingFont&quot;) &amp; &quot; &quot; &amp; fontName &amp; &quot; &quot; &amp; getTranslation(&quot;validateNumberingSymbol&quot;) &amp; &quot; &quot; &amp; fontChar &amp; &quot; (&quot; &amp; Hex(Asc(fontChar)) &amp; &quot;) &quot;&amp; Left(excerpt,exLength) &amp; chr(10)
2020-03-18 22:14:07 +01:00
If Asc(fontChar) &gt; 57344 AND Asc(fontChar) &lt; 63743 Then
resultBad = resultBad &amp; tmp
ElseIf fontName &lt;&gt; &quot;IPH Astra Serif&quot; _
AND fontName &lt;&gt; &quot;OpenSymbol&quot; _
AND fontName &lt;&gt; &quot;IPH Lib Serif&quot; _
AND fontName &lt;&gt; &quot;IPH Lib Sans&quot; _
AND fontName &lt;&gt; &quot;Liberation Serif&quot; _
AND fontName &lt;&gt; &quot;Liberation Sans&quot; _
AND needExtendedInfo Then
result = result &amp; tmp
EndIf
2020-03-06 17:37:35 +01:00
EndIf
EndIf
EndIf
EndIf
Loop
2020-03-21 12:37:32 +01:00
2020-03-06 17:37:35 +01:00
report = &quot;&quot;
If result = &quot;&quot; AND resultBad = &quot;&quot; Then
Exit sub
Else
If resultBad &lt;&gt; &quot;&quot; Then
2020-05-04 15:52:04 +02:00
report = getTranslation(&quot;validateNumberingsReportSymbols&quot;) &amp; chr(10) &amp; resultBad
2020-03-06 17:37:35 +01:00
EndIf
If result &lt;&gt; &quot;&quot; Then
2020-05-04 15:52:04 +02:00
report = report &amp; getTranslation(&quot;validateNumberingsReportFonts&quot;) &amp; &quot; &quot;&amp; chr(10)&amp; result
2020-03-06 17:37:35 +01:00
EndIf
EndIf
MsgBox report
End Sub
2019-10-17 00:31:08 +03:00
Private Sub showTrackedChanges
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:AcceptTrackedChanges&quot;, &quot;&quot;, 0, Array())
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = &quot;ShowTrackedChanges&quot;
args2(0).Value = true
dispatcher.executeDispatch(document, &quot;.uno:ShowTrackedChanges&quot;, &quot;&quot;, 0, args2())
end Sub
Private Sub StartTracking
2020-03-21 12:37:32 +01:00
Dim dispatcher As Object
Dim document As Object
2019-10-17 00:31:08 +03:00
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
document = ThisComponent.CurrentController.Frame
dim trackProperties(0) as new com.sun.star.beans.PropertyValue
trackProperties(0).Name = &quot;TrackChanges&quot;
trackProperties(0).Value = true
dispatcher.executeDispatch(document, &quot;.uno:TrackChanges&quot;, &quot;&quot;, 0, trackProperties())
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = &quot;ShowTrackedChanges&quot;
args1(0).Value = true
dispatcher.executeDispatch(document, &quot;.uno:ShowTrackedChanges&quot;, &quot;&quot;, 0, args1())
End Sub
Private Sub StopTracking
2020-03-21 12:37:32 +01:00
Dim dispatcher As Object
Dim document As Object
2019-10-17 00:31:08 +03:00
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
document = ThisComponent.CurrentController.Frame
2020-03-21 12:37:32 +01:00
Dim trackProperties(0) as new com.sun.star.beans.PropertyValue
2019-10-17 00:31:08 +03:00
trackProperties(0).Name = &quot;TrackChanges&quot;
trackProperties(0).Value = false
dispatcher.executeDispatch(document, &quot;.uno:TrackChanges&quot;, &quot;&quot;, 0, trackProperties())
2020-03-21 12:37:32 +01:00
Dim args1(0) as new com.sun.star.beans.PropertyValue
2019-10-17 00:31:08 +03:00
args1(0).Name = &quot;ShowTrackedChanges&quot;
args1(0).Value = true
dispatcher.executeDispatch(document, &quot;.uno:ShowTrackedChanges&quot;, &quot;&quot;, 0, args1())
End Sub
2020-04-23 14:15:18 +02:00
2020-01-13 16:08:46 +01:00
</script:module>