11ecadb57SMathias Bauer<?xml version="1.0" encoding="UTF-8"?> 21ecadb57SMathias Bauer<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3*3e02b54dSAndrew Rist<!--*********************************************************** 4*3e02b54dSAndrew Rist * 5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 6*3e02b54dSAndrew Rist * or more contributor license agreements. See the NOTICE file 7*3e02b54dSAndrew Rist * distributed with this work for additional information 8*3e02b54dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the 10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance 11*3e02b54dSAndrew Rist * with the License. You may obtain a copy of the License at 12*3e02b54dSAndrew Rist * 13*3e02b54dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 14*3e02b54dSAndrew Rist * 15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing, 16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an 17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18*3e02b54dSAndrew Rist * KIND, either express or implied. See the License for the 19*3e02b54dSAndrew Rist * specific language governing permissions and limitations 20*3e02b54dSAndrew Rist * under the License. 21*3e02b54dSAndrew Rist * 22*3e02b54dSAndrew Rist ***********************************************************--> 231ecadb57SMathias Bauer<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Validate" script:language="StarBasic"> 241ecadb57SMathias Bauer'############################################ 251ecadb57SMathias Bauer' VALIDATION ROUTINES 261ecadb57SMathias Bauer' 271ecadb57SMathias Bauer' May, 19 2004 - fpe 281ecadb57SMathias Bauer'############################################ 291ecadb57SMathias Bauer 301ecadb57SMathias BauerDim sSwitchType As String 311ecadb57SMathias BauerDim sCellSwitchType As String 321ecadb57SMathias BauerDim sCaseType As String 331ecadb57SMathias BauerDim sCellCaseType As String 341ecadb57SMathias BauerDim sDefaultType As String 351ecadb57SMathias BauerDim sCellDefaultType As String 361ecadb57SMathias BauerDim bDefaultSet As Boolean 371ecadb57SMathias BauerDim bCellDefaultSet As Boolean 381ecadb57SMathias BauerDim bCaseSet As Boolean 391ecadb57SMathias BauerDim bCellCaseSet As Boolean 401ecadb57SMathias BauerDim aTagsOpen(0) As String 411ecadb57SMathias BauerDim aCellTagsOpen(0) As String 421ecadb57SMathias BauerDim bWarn As Boolean 431ecadb57SMathias BauerDim bWarnEmptyPara As Boolean 441ecadb57SMathias BauerDim bWarnParaNoID As Boolean 451ecadb57SMathias Bauer 461ecadb57SMathias Bauer 471ecadb57SMathias BauerSub ValidateXHP 481ecadb57SMathias Bauer Validate 491ecadb57SMathias BauerEnd Sub 501ecadb57SMathias Bauer 511ecadb57SMathias BauerSub Validate 521ecadb57SMathias Bauer 531ecadb57SMathias Bauer If not IsHelpFile Then 541ecadb57SMathias Bauer msgbox(strErr_NoHelpFile) 551ecadb57SMathias Bauer Exit Sub 561ecadb57SMathias Bauer End If 571ecadb57SMathias Bauer 581ecadb57SMathias Bauer oDoc = StarDesktop.CurrentComponent 591ecadb57SMathias Bauer sSwitchType = "" 601ecadb57SMathias Bauer sCaseType = "" 611ecadb57SMathias Bauer sDefaultType = "" 621ecadb57SMathias Bauer bWarn = TRUE 631ecadb57SMathias Bauer bWarnEmptyPara = TRUE 641ecadb57SMathias Bauer bWarnParaNoID = TRUE 651ecadb57SMathias Bauer 661ecadb57SMathias Bauer CheckMetaData(oDoc) 671ecadb57SMathias Bauer CheckHeading(oDoc) 681ecadb57SMathias Bauer 691ecadb57SMathias Bauer Enum = oDoc.Text.createEnumeration 701ecadb57SMathias Bauer Do While Enum.hasMoreElements 711ecadb57SMathias Bauer 721ecadb57SMathias Bauer TextElement = Enum.nextElement 731ecadb57SMathias Bauer If TextElement.supportsService("com.sun.star.text.Paragraph") Then ' we are a paragraph 741ecadb57SMathias Bauer 751ecadb57SMathias Bauer CheckSwitches(TextElement) 761ecadb57SMathias Bauer CheckParaID(TextElement) 771ecadb57SMathias Bauer CheckParaFormat(TextElement) 781ecadb57SMathias Bauer CheckTags(TextElement) 791ecadb57SMathias Bauer CheckInlineTags(TextElement) 801ecadb57SMathias Bauer 811ecadb57SMathias Bauer ElseIf TextElement.supportsService("com.sun.star.text.TextTable") Then 821ecadb57SMathias Bauer 831ecadb57SMathias Bauer If sSwitchType <> "" AND (sCaseType = "" AND sDefaultType = "") Then '<------ 841ecadb57SMathias Bauer Terminate("Switch must be closed or case/default must be opened before a table starts.",tmpCellElement) 851ecadb57SMathias Bauer End If 861ecadb57SMathias Bauer 871ecadb57SMathias Bauer CheckCell(TextElement) 881ecadb57SMathias Bauer End If 891ecadb57SMathias Bauer Loop 901ecadb57SMathias Bauer 911ecadb57SMathias Bauer If sCaseType <> "" Then 921ecadb57SMathias Bauer Terminate("Previous case ("+sCaseType+") not closed!",TextElement) 931ecadb57SMathias Bauer End If 941ecadb57SMathias Bauer 951ecadb57SMathias Bauer If sDefaultType <> "" Then 961ecadb57SMathias Bauer Terminate("Previous default not closed!",TextElement) 971ecadb57SMathias Bauer End If 981ecadb57SMathias Bauer 991ecadb57SMathias Bauer If sSwitchType <> "" Then 1001ecadb57SMathias Bauer Terminate("Previous switch ("+sSwitchType+") not closed!",TextElement) 1011ecadb57SMathias Bauer End If 1021ecadb57SMathias Bauer 1031ecadb57SMathias Bauer If ubound(aTagsOpen()) > 0 Then 1041ecadb57SMathias Bauer Terminate("Element "+aTagsOpen(ubound(aTagsOpen()))+" not closed",TextElement) 1051ecadb57SMathias Bauer End If 1061ecadb57SMathias Bauer 1071ecadb57SMathias Bauer msgbox("Validation finished.") 1081ecadb57SMathias Bauer 1091ecadb57SMathias BauerEnd Sub 1101ecadb57SMathias Bauer 1111ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1121ecadb57SMathias Bauer' CHECKCELL 1131ecadb57SMathias Bauer' checks a table cell contents 1141ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1151ecadb57SMathias Bauer 1161ecadb57SMathias BauerSub CheckCell(TE As Object) 1171ecadb57SMathias Bauer On Local Error Goto ERRHANDLE: 1181ecadb57SMathias Bauer 1191ecadb57SMathias Bauer CellName = "A1" 1201ecadb57SMathias Bauer Cell = TE.getCellByName(CellName) 1211ecadb57SMathias Bauer tmpCellEnum = Cell.createEnumeration 1221ecadb57SMathias Bauer tmpCellElement = tmpCellEnum.nextElement 1231ecadb57SMathias Bauer 1241ecadb57SMathias Bauer Rows = TE.getRows 1251ecadb57SMathias Bauer Cols = TE.getColumns 1261ecadb57SMathias Bauer 1271ecadb57SMathias Bauer ReDim aCellTagsOpen(0) 1281ecadb57SMathias Bauer 1291ecadb57SMathias Bauer For RowIndex = 1 to Rows.getCount() 1301ecadb57SMathias Bauer 1311ecadb57SMathias Bauer For ColIndex = 1 to Cols.getCount() 1321ecadb57SMathias Bauer 1331ecadb57SMathias Bauer CellName = Chr(64 + ColIndex) & RowIndex 1341ecadb57SMathias Bauer Cell = TE.getCellByName(CellName) 1351ecadb57SMathias Bauer CellEnum = Cell.createEnumeration 1361ecadb57SMathias Bauer 1371ecadb57SMathias Bauer Do While CellEnum.hasMoreElements 1381ecadb57SMathias Bauer 1391ecadb57SMathias Bauer CellElement = CellEnum.nextElement ' <-- MODIFY, check closed switches within cells 1401ecadb57SMathias Bauer 1411ecadb57SMathias Bauer If CellElement.supportsService("com.sun.star.text.Paragraph") Then 1421ecadb57SMathias Bauer CheckSwitchesInCell(CellElement) 1431ecadb57SMathias Bauer CheckParaID(CellElement) 1441ecadb57SMathias Bauer CheckParaFormat(CellElement) 1451ecadb57SMathias Bauer CheckTagsInCell(CellElement) 1461ecadb57SMathias Bauer CheckInlineTags(CellElement) 1471ecadb57SMathias Bauer EndIf 1481ecadb57SMathias Bauer 1491ecadb57SMathias Bauer Loop 1501ecadb57SMathias Bauer 1511ecadb57SMathias Bauer If sCellCaseType <> "" Then 1521ecadb57SMathias Bauer Terminate("Previous case ("+sCellCaseType+") not closed!",CellElement) 1531ecadb57SMathias Bauer End If 1541ecadb57SMathias Bauer 1551ecadb57SMathias Bauer If sCellSwitchType <> "" Then 1561ecadb57SMathias Bauer Terminate("Previous switch ("+sCellSwitchType+") not closed!",CellElement) 1571ecadb57SMathias Bauer End If 1581ecadb57SMathias Bauer 1591ecadb57SMathias Bauer If ubound(aCellTagsOpen()) > 0 Then 1601ecadb57SMathias Bauer Terminate("Element "+aCellTagsOpen(ubound(aCellTagsOpen()))+" not closed",CellElement) 1611ecadb57SMathias Bauer End If 1621ecadb57SMathias Bauer 1631ecadb57SMathias Bauer Next 1641ecadb57SMathias Bauer Next 1651ecadb57SMathias Bauer 1661ecadb57SMathias Bauer ERRHANDLE: 1671ecadb57SMathias Bauer If Err <> 0 Then 1681ecadb57SMathias Bauer msgbox "Error: "+chr(13)+ Error$,48,"D'oh!" 1691ecadb57SMathias Bauer End If 1701ecadb57SMathias BauerEnd Sub 1711ecadb57SMathias Bauer 1721ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1731ecadb57SMathias Bauer' CHECK PARA ID 1741ecadb57SMathias Bauer' checks a paragraph for an ID 1751ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1761ecadb57SMathias Bauer 1771ecadb57SMathias BauerSub CheckParaID(TE As Object) 1781ecadb57SMathias Bauer 1791ecadb57SMathias Bauer If Left(TE.ParaStyleName,4) = "hlp_" AND Not(Left(TE.ParaStyleName,8) = "hlp_aux_") Then 1801ecadb57SMathias Bauer 1811ecadb57SMathias Bauer sText = TE.GetString 1821ecadb57SMathias Bauer 1831ecadb57SMathias Bauer If sText = "" Then 1841ecadb57SMathias Bauer If bWarnEmptyPara Then 1851ecadb57SMathias Bauer Warn("Empty Paragraph","Empty paragraphs should be avoided. Do not use empty paragraphs for formatting purpose.",TE) 1861ecadb57SMathias Bauer bWarnEmptyPara = FALSE 1871ecadb57SMathias Bauer End If 1881ecadb57SMathias Bauer Else 1891ecadb57SMathias Bauer 1901ecadb57SMathias Bauer TP = TE.createEnumeration 1911ecadb57SMathias Bauer Ct = 0 1921ecadb57SMathias Bauer posID = 0 1931ecadb57SMathias Bauer 1941ecadb57SMathias Bauer While TP.hasmoreElements 1951ecadb57SMathias Bauer Ct = Ct+1 1961ecadb57SMathias Bauer TPE = TP.nextElement 1971ecadb57SMathias Bauer If TPE.TextPortionType="TextField" Then 1981ecadb57SMathias Bauer If TPE.TextField.TextFieldMaster.Name="ID" Then 1991ecadb57SMathias Bauer posID = Ct 2001ecadb57SMathias Bauer End If 2011ecadb57SMathias Bauer End If 2021ecadb57SMathias Bauer ' Lets cheat and allow empty strings before the ID -- otherwise we'll get 2031ecadb57SMathias Bauer ' a validation error if a paragraph starts at the top of a page after 2041ecadb57SMathias Bauer ' a page break (for whatever reason) 2051ecadb57SMathias Bauer If TPE.String = "" Then 2061ecadb57SMathias Bauer Ct = Ct-1 2071ecadb57SMathias Bauer End If 2081ecadb57SMathias Bauer Wend 2091ecadb57SMathias Bauer 2101ecadb57SMathias Bauer If posID = 0 Then 2111ecadb57SMathias Bauer If bWarnParaNoID Then 2121ecadb57SMathias Bauer Warn("Paragraph has no id.","IDs will be assigned on safe. You can also assign an ID using the Assign Paragraph ID menu item",TPE) 2131ecadb57SMathias Bauer bWarnParaNoID = FALSE 2141ecadb57SMathias Bauer InsertNewParaData 2151ecadb57SMathias Bauer Else 2161ecadb57SMathias Bauer oCur = TE.getText.createTextCursorByRange(TE) 2171ecadb57SMathias Bauer thiscomponent.getcurrentcontroller.select(oCur) 2181ecadb57SMathias Bauer InsertNewParaData 2191ecadb57SMathias Bauer End If 2201ecadb57SMathias Bauer ElseIf posID > 1 Then 2211ecadb57SMathias Bauer Terminate("Paragraph ID not at the start of the paragraph. The paragraph ID must be the first element of a paragraph. Move the ID to the beginning of the paragraph",TPE) 2221ecadb57SMathias Bauer End If 2231ecadb57SMathias Bauer 2241ecadb57SMathias Bauer End If 2251ecadb57SMathias Bauer 2261ecadb57SMathias Bauer End If 2271ecadb57SMathias BauerEnd Sub 2281ecadb57SMathias Bauer 2291ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2301ecadb57SMathias Bauer' CHECK PARA FORMAT 2311ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2321ecadb57SMathias BauerSub CheckParaFormat(TE As Object) 2331ecadb57SMathias Bauer 2341ecadb57SMathias Bauer sText = TE.GetString 2351ecadb57SMathias Bauer If Left(TE.ParaStyleName,4) <> "hlp_" AND sText <> "" Then ' just disregard empty paras in wrong formats 2361ecadb57SMathias Bauer Warn("Invalid paragraph format. Contents will be lost.",_ 2371ecadb57SMathias Bauer "Use only the paragraph styles starting with ""hlp_""."+_ 2381ecadb57SMathias Bauer " Paragraphs in other formats will be lost on export",TE) 2391ecadb57SMathias Bauer End If 2401ecadb57SMathias Bauer 2411ecadb57SMathias BauerEnd Sub 2421ecadb57SMathias Bauer 2431ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2441ecadb57SMathias Bauer' CHECK SWITCHES 2451ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2461ecadb57SMathias BauerSub CheckSwitches(TE As Object) 2471ecadb57SMathias Bauer 2481ecadb57SMathias Bauer If TE.ParaStyleName="hlp_aux_switch" Then ' we are a switch or case or default 2491ecadb57SMathias Bauer sText = TE.GetString ' get the switch contents 2501ecadb57SMathias Bauer 2511ecadb57SMathias Bauer If Left(sText,8) = "<SWITCH " Then ' an opening switch tag 2521ecadb57SMathias Bauer 2531ecadb57SMathias Bauer If sSwitchType = "" Then ' no other switch is open 2541ecadb57SMathias Bauer sSwitchType = Right(sText,Len(sText)-16) 2551ecadb57SMathias Bauer sSwitchType = Left(sSwitchType,InStr(sSwitchType,"""")-1) 2561ecadb57SMathias Bauer 2571ecadb57SMathias Bauer If (sSwitchType <> "sys" AND sSwitchType <> "appl" AND sSwitchType <> "distrib") Then 2581ecadb57SMathias Bauer Terminate("Unknown switch type """+sSwitchType+"""",TE) 2591ecadb57SMathias Bauer End If 2601ecadb57SMathias Bauer 2611ecadb57SMathias Bauer Else 2621ecadb57SMathias Bauer Terminate("Previous switch ("+sSwitchType+") not closed!",TE) 2631ecadb57SMathias Bauer End If 2641ecadb57SMathias Bauer 2651ecadb57SMathias Bauer End If ' OPENING SWITCH 2661ecadb57SMathias Bauer 2671ecadb57SMathias Bauer If Left(sText,8) = "</SWITCH" Then ' a closing switch tag 2681ecadb57SMathias Bauer 2691ecadb57SMathias Bauer If sSwitchType = "" Then ' there was no switch open 2701ecadb57SMathias Bauer Terminate("No switch open!",TE) 2711ecadb57SMathias Bauer Else 2721ecadb57SMathias Bauer If not(bCaseSet OR bDefaultSet) Then 2731ecadb57SMathias Bauer Terminate("Empty switch",TE) 2741ecadb57SMathias Bauer End If 2751ecadb57SMathias Bauer 2761ecadb57SMathias Bauer If sCaseType <> "" Then ' there is still a case open 2771ecadb57SMathias Bauer Terminate("Previous case ("+sCaseType+") not closed!",TE) 2781ecadb57SMathias Bauer End If 2791ecadb57SMathias Bauer sSwitchType = "" 2801ecadb57SMathias Bauer bDefaultSet = FALSE 2811ecadb57SMathias Bauer bCaseSet = FALSE 2821ecadb57SMathias Bauer End If 2831ecadb57SMathias Bauer 2841ecadb57SMathias Bauer End If ' CLOSING SWITCH 2851ecadb57SMathias Bauer 2861ecadb57SMathias Bauer If Left(sText,6) = "<CASE " Then ' an opening case tag 2871ecadb57SMathias Bauer 2881ecadb57SMathias Bauer If bDefaultSet Then 2891ecadb57SMathias Bauer Terminate("No case after default allowed.",TE) 2901ecadb57SMathias Bauer End If 2911ecadb57SMathias Bauer 2921ecadb57SMathias Bauer If sCaseType = "" Then 2931ecadb57SMathias Bauer sCaseType = Right(sText,Len(sText)-14) 2941ecadb57SMathias Bauer sCaseType = Left(sCaseType,InStr(sCaseType,"""")-1) 2951ecadb57SMathias Bauer bCaseSet = TRUE 2961ecadb57SMathias Bauer If sSwitchType = "" Then 2971ecadb57SMathias Bauer Terminate("Case without switch",TE) 2981ecadb57SMathias Bauer End If 2991ecadb57SMathias Bauer Else 3001ecadb57SMathias Bauer Terminate("Previous case ("+sCaseType+") not closed!",TE) 3011ecadb57SMathias Bauer End If 3021ecadb57SMathias Bauer 3031ecadb57SMathias Bauer End If ' OPENING CASE 3041ecadb57SMathias Bauer 3051ecadb57SMathias Bauer If Left(sText,6) = "</CASE" Then ' a closing case tag 3061ecadb57SMathias Bauer 3071ecadb57SMathias Bauer If sCaseType = "" Then 3081ecadb57SMathias Bauer Terminate("No case open!",TE) 3091ecadb57SMathias Bauer Else 3101ecadb57SMathias Bauer sCaseType = "" 3111ecadb57SMathias Bauer End If 3121ecadb57SMathias Bauer 3131ecadb57SMathias Bauer End If ' CLOSING CASE 3141ecadb57SMathias Bauer 3151ecadb57SMathias Bauer If Left(sText,8) = "<DEFAULT" Then ' an opening default tag 3161ecadb57SMathias Bauer 3171ecadb57SMathias Bauer If sCaseType = "" Then 3181ecadb57SMathias Bauer If (sDefaultType <> "" OR bDefaultSet) Then 3191ecadb57SMathias Bauer Terminate("Multiple default not allowed.",TE) 3201ecadb57SMathias Bauer Else 3211ecadb57SMathias Bauer sDefaultType = "DEFAULT" 3221ecadb57SMathias Bauer 3231ecadb57SMathias Bauer If sSwitchType = "" Then 3241ecadb57SMathias Bauer Terminate("Default without switch",TE) 3251ecadb57SMathias Bauer End If 3261ecadb57SMathias Bauer End If 3271ecadb57SMathias Bauer sDefaultType = "DEFAULT" 3281ecadb57SMathias Bauer bDefaultSet = TRUE 3291ecadb57SMathias Bauer Else 3301ecadb57SMathias Bauer Terminate("Previous case ("+sCaseType+") not closed!",TE) 3311ecadb57SMathias Bauer End If 3321ecadb57SMathias Bauer 3331ecadb57SMathias Bauer End If ' OPENING CASE 3341ecadb57SMathias Bauer 3351ecadb57SMathias Bauer If Left(sText,9) = "</DEFAULT" Then ' a closing default tag 3361ecadb57SMathias Bauer 3371ecadb57SMathias Bauer If sDefaultType <> "DEFAULT" Then 3381ecadb57SMathias Bauer Terminate("No default open!",TE) 3391ecadb57SMathias Bauer Else 3401ecadb57SMathias Bauer sDefaultType = "" 3411ecadb57SMathias Bauer End If 3421ecadb57SMathias Bauer 3431ecadb57SMathias Bauer End If ' CLOSING CASE 3441ecadb57SMathias Bauer Else ' We are not hlp_aux_switch 3451ecadb57SMathias Bauer If (sSwitchType <> "" AND sCaseType = "" AND sDefaultType = "") Then 3461ecadb57SMathias Bauer Terminate("Nothing allowed between switch and case or default or /case or /default and /switch", TE) 3471ecadb57SMathias Bauer End If 3481ecadb57SMathias Bauer End If 3491ecadb57SMathias Bauer 3501ecadb57SMathias BauerEnd Sub 3511ecadb57SMathias Bauer 3521ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3531ecadb57SMathias Bauer' CHECK SWITCHES IN A CELL 3541ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3551ecadb57SMathias BauerSub CheckSwitchesInCell(CE As Object) 3561ecadb57SMathias Bauer 3571ecadb57SMathias Bauer If CE.ParaStyleName="hlp_aux_switch" Then ' we are a switch or case or default 3581ecadb57SMathias Bauer sText = CE.GetString ' get the switch contents 3591ecadb57SMathias Bauer 3601ecadb57SMathias Bauer If Left(sText,8) = "<SWITCH " Then ' an opening switch tag 3611ecadb57SMathias Bauer 3621ecadb57SMathias Bauer If sCellSwitchType = "" Then ' no other switch is open 3631ecadb57SMathias Bauer sCellSwitchType = Right(sText,Len(sText)-16) 3641ecadb57SMathias Bauer sCellSwitchType = Left(sCellSwitchType,InStr(sCellSwitchType,"""")-1) 3651ecadb57SMathias Bauer 3661ecadb57SMathias Bauer If (sCellSwitchType <> "sys" AND sCellSwitchType <> "appl" AND sCellSwitchType <> "distrib") Then 3671ecadb57SMathias Bauer Terminate("Unknown switch type """+sCellSwitchType+"""",CE) 3681ecadb57SMathias Bauer End If 3691ecadb57SMathias Bauer 3701ecadb57SMathias Bauer Else 3711ecadb57SMathias Bauer Terminate("Previous switch ("+sCellSwitchType+") not closed!",CE) 3721ecadb57SMathias Bauer End If 3731ecadb57SMathias Bauer 3741ecadb57SMathias Bauer End If ' OPENING SWITCH 3751ecadb57SMathias Bauer 3761ecadb57SMathias Bauer If Left(sText,8) = "</SWITCH" Then ' a closing switch tag 3771ecadb57SMathias Bauer 3781ecadb57SMathias Bauer If sCellSwitchType = "" Then ' there was no switch open 3791ecadb57SMathias Bauer Terminate("No switch open!",CE) 3801ecadb57SMathias Bauer Else 3811ecadb57SMathias Bauer If not(bCellCaseSet OR bCellDefaultSet) Then 3821ecadb57SMathias Bauer Terminate("Empty switch",CE) 3831ecadb57SMathias Bauer End If 3841ecadb57SMathias Bauer 3851ecadb57SMathias Bauer If sCellCaseType <> "" Then ' there is still a case open 3861ecadb57SMathias Bauer Terminate("Previous case ("+sCellCaseType+") not closed!",CE) 3871ecadb57SMathias Bauer End If 3881ecadb57SMathias Bauer sCellSwitchType = "" 3891ecadb57SMathias Bauer bCellDefaultSet = FALSE 3901ecadb57SMathias Bauer bCellCaseSet = FALSE 3911ecadb57SMathias Bauer End If 3921ecadb57SMathias Bauer 3931ecadb57SMathias Bauer End If ' CLOSING SWITCH 3941ecadb57SMathias Bauer 3951ecadb57SMathias Bauer If Left(sText,6) = "<CASE " Then ' an opening case tag 3961ecadb57SMathias Bauer 3971ecadb57SMathias Bauer If bCellDefaultSet Then 3981ecadb57SMathias Bauer Terminate("No case after default allowed.",CE) 3991ecadb57SMathias Bauer End If 4001ecadb57SMathias Bauer 4011ecadb57SMathias Bauer If sCellCaseType = "" Then 4021ecadb57SMathias Bauer sCellCaseType = Right(sText,Len(sText)-14) 4031ecadb57SMathias Bauer sCellCaseType = Left(sCellCaseType,InStr(sCellCaseType,"""")-1) 4041ecadb57SMathias Bauer bCellCaseSet = TRUE 4051ecadb57SMathias Bauer If sCellSwitchType = "" Then 4061ecadb57SMathias Bauer Terminate("Case without switch",CE) 4071ecadb57SMathias Bauer End If 4081ecadb57SMathias Bauer Else 4091ecadb57SMathias Bauer Terminate("Previous case ("+sCellCaseType+") not closed!",CE) 4101ecadb57SMathias Bauer End If 4111ecadb57SMathias Bauer 4121ecadb57SMathias Bauer End If ' OPENING CASE 4131ecadb57SMathias Bauer 4141ecadb57SMathias Bauer If Left(sText,6) = "</CASE" Then ' a closing case tag 4151ecadb57SMathias Bauer 4161ecadb57SMathias Bauer If sCellCaseType = "" Then 4171ecadb57SMathias Bauer Terminate("No case open!",CE) 4181ecadb57SMathias Bauer Else 4191ecadb57SMathias Bauer sCellCaseType = "" 4201ecadb57SMathias Bauer End If 4211ecadb57SMathias Bauer 4221ecadb57SMathias Bauer End If ' CLOSING CASE 4231ecadb57SMathias Bauer 4241ecadb57SMathias Bauer If Left(sText,8) = "<DEFAULT" Then ' an opening default tag 4251ecadb57SMathias Bauer 4261ecadb57SMathias Bauer If sCellCaseType = "" Then 4271ecadb57SMathias Bauer If (sCellDefaultType <> "" OR bCellDefaultSet) Then 4281ecadb57SMathias Bauer Terminate("Multiple default not allowed.",CE) 4291ecadb57SMathias Bauer Else 4301ecadb57SMathias Bauer sCellDefaultType = "DEFAULT" 4311ecadb57SMathias Bauer 4321ecadb57SMathias Bauer If sCellSwitchType = "" Then 4331ecadb57SMathias Bauer Terminate("Default without switch",CE) 4341ecadb57SMathias Bauer End If 4351ecadb57SMathias Bauer End If 4361ecadb57SMathias Bauer sCellDefaultType = "DEFAULT" 4371ecadb57SMathias Bauer bCellDefaultSet = TRUE 4381ecadb57SMathias Bauer Else 4391ecadb57SMathias Bauer Terminate("Previous case ("+sCellCaseType+") not closed!",CE) 4401ecadb57SMathias Bauer End If 4411ecadb57SMathias Bauer 4421ecadb57SMathias Bauer End If ' OPENING CASE 4431ecadb57SMathias Bauer 4441ecadb57SMathias Bauer If Left(sText,9) = "</DEFAULT" Then ' a closing default tag 4451ecadb57SMathias Bauer 4461ecadb57SMathias Bauer If sCellDefaultType <> "DEFAULT" Then 4471ecadb57SMathias Bauer Terminate("No default open!",CE) 4481ecadb57SMathias Bauer Else 4491ecadb57SMathias Bauer sCellDefaultType = "" 4501ecadb57SMathias Bauer End If 4511ecadb57SMathias Bauer 4521ecadb57SMathias Bauer End If ' CLOSING CASE 4531ecadb57SMathias Bauer Else ' We are not hlp_aux_switch 4541ecadb57SMathias Bauer If (sCellSwitchType <> "" AND sCellCaseType = "" AND sCellDefaultType = "") Then 4551ecadb57SMathias Bauer Terminate("Nothing allowed between switch and case or default or /case or /default and /switch", CE) 4561ecadb57SMathias Bauer End If 4571ecadb57SMathias Bauer End If 4581ecadb57SMathias Bauer 4591ecadb57SMathias Bauer 4601ecadb57SMathias BauerEnd Sub 4611ecadb57SMathias Bauer 4621ecadb57SMathias Bauer 4631ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4641ecadb57SMathias Bauer' TERMINATE VALIDATION WITH AN ERROR MESSAGE 4651ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4661ecadb57SMathias BauerSub Terminate(sStr As String, TE As Object) 4671ecadb57SMathias Bauer 4681ecadb57SMathias Bauer oCur = TE.getText.createTextCursorByRange(TE) 4691ecadb57SMathias Bauer thiscomponent.getcurrentcontroller.select(oCur) 4701ecadb57SMathias Bauer msgbox sStr,48,"D'oh!" 4711ecadb57SMathias Bauer Stop 4721ecadb57SMathias Bauer 4731ecadb57SMathias BauerEnd Sub 4741ecadb57SMathias Bauer 4751ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4761ecadb57SMathias Bauer' SHOW A WARNING 4771ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4781ecadb57SMathias BauerSub Warn(sWarn As String, sSolv As String, Optional TE As Object) 4791ecadb57SMathias Bauer 4801ecadb57SMathias Bauer If bWarn Then 4811ecadb57SMathias Bauer BasicLibraries.LoadLibrary("HelpAuthoring") 4821ecadb57SMathias Bauer oDialog = LoadDialog("HelpAuthoring", "dlgWarn") 4831ecadb57SMathias Bauer oTxtWarn = oDialog.GetControl("txtWarning") 4841ecadb57SMathias Bauer oTxtWarn.Text = sWarn 4851ecadb57SMathias Bauer oTxtSolv = oDialog.GetControl("txtSolution") 4861ecadb57SMathias Bauer oTxtSolv.Text = sSolv 4871ecadb57SMathias Bauer 4881ecadb57SMathias Bauer If not(IsMissing(TE)) Then 4891ecadb57SMathias Bauer oCur = TE.getText.createTextCursorByRange(TE) 4901ecadb57SMathias Bauer thiscomponent.getcurrentcontroller.select(oCur) 4911ecadb57SMathias Bauer End If 4921ecadb57SMathias Bauer 4931ecadb57SMathias Bauer If oDialog.Execute() = 1 Then 4941ecadb57SMathias Bauer oCbWarn = oDialog.GetControl("cbWarn") 4951ecadb57SMathias Bauer If oCbWarn.State = 1 Then 4961ecadb57SMathias Bauer bWarn = FALSE 4971ecadb57SMathias Bauer End If 4981ecadb57SMathias Bauer Exit Sub 4991ecadb57SMathias Bauer Else 5001ecadb57SMathias Bauer Stop 5011ecadb57SMathias Bauer End If 5021ecadb57SMathias Bauer End If 5031ecadb57SMathias BauerEnd Sub 5041ecadb57SMathias Bauer 5051ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5061ecadb57SMathias Bauer' CHECK DOCUMENT META DATA 5071ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5081ecadb57SMathias BauerSub CheckMetaData(oDoc As Object) 5091ecadb57SMathias Bauer 5101ecadb57SMathias Bauer sTopicID = oDoc.DocumentInfo.GetUserFieldValue(1) 5111ecadb57SMathias Bauer 5121ecadb57SMathias Bauer If sTopicID <> AlphaNum(sTopicID) OR sTopicID="" Then 5131ecadb57SMathias Bauer sTopicID = "topic_"+CreateID ' create a topic id 5141ecadb57SMathias Bauer End If 5151ecadb57SMathias Bauer 5161ecadb57SMathias Bauer oDoc.DocumentInfo.SetUserFieldValue(1,sTopicID) 5171ecadb57SMathias Bauer sCreated = oDoc.DocumentInfo.GetUserFieldValue(2) 5181ecadb57SMathias Bauer sEdited = oDoc.DocumentInfo.GetUserFieldValue(3) 5191ecadb57SMathias Bauer sTitle = oDoc.DocumentInfo.Title 5201ecadb57SMathias Bauer 5211ecadb57SMathias Bauer If sTitle="" OR sTitle="<Set Topic Title>" Then 5221ecadb57SMathias Bauer Enum = document.Text.createEnumeration 5231ecadb57SMathias Bauer Do While Enum.hasMoreElements 5241ecadb57SMathias Bauer TextElement = Enum.nextElement 5251ecadb57SMathias Bauer If TextElement.supportsService("com.sun.star.text.Paragraph") Then 5261ecadb57SMathias Bauer If Left(TextElement.ParaStyleName,8)="hlp_head" Then 5271ecadb57SMathias Bauer Enum2 = TextElement.createEnumeration 5281ecadb57SMathias Bauer While Enum2.hasMoreElements 5291ecadb57SMathias Bauer TextPortion = Enum2.nextElement 5301ecadb57SMathias Bauer If Not(TextPortion.TextPortionType="TextField") Then 5311ecadb57SMathias Bauer strg = strg + TextPortion.String 5321ecadb57SMathias Bauer End If 5331ecadb57SMathias Bauer Wend 5341ecadb57SMathias Bauer document.DocumentInfo.Title = strg 5351ecadb57SMathias Bauer Exit Do 5361ecadb57SMathias Bauer End If 5371ecadb57SMathias Bauer End If 5381ecadb57SMathias Bauer Loop 5391ecadb57SMathias Bauer End If 5401ecadb57SMathias Bauer 5411ecadb57SMathias Bauer sIndex = oDoc.DocumentInfo.GetUserFieldValue(0) 5421ecadb57SMathias Bauer 5431ecadb57SMathias BauerEnd Sub 5441ecadb57SMathias Bauer 5451ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5461ecadb57SMathias Bauer' CHECK IF HEADING EXISTS 5471ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5481ecadb57SMathias BauerSub CheckHeading(oDoc As Object) 5491ecadb57SMathias Bauer 5501ecadb57SMathias BauerEnd Sub 5511ecadb57SMathias Bauer 5521ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5531ecadb57SMathias Bauer' CHECK FOR CORRECT INLINE TAGS 5541ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5551ecadb57SMathias BauerSub CheckInlineTags(TE As Object) 5561ecadb57SMathias Bauer 5571ecadb57SMathias Bauer 5581ecadb57SMathias Bauer 5591ecadb57SMathias Bauer If Left(TE.ParaStyleName,4)="hlp_" AND (Left(TE.ParaStyleName,8)<>"hlp_aux_" OR TE.ParaStyleName="hlp_aux_bookmark") Then 5601ecadb57SMathias Bauer 5611ecadb57SMathias Bauer Dim aTokens(0) As Object 5621ecadb57SMathias Bauer Dim aInlineTagsOpen(0) As String 5631ecadb57SMathias Bauer TP = TE.createEnumeration 5641ecadb57SMathias Bauer 5651ecadb57SMathias Bauer While TP.hasmoreElements 5661ecadb57SMathias Bauer sDim = ubound(aTokens())+1 5671ecadb57SMathias Bauer ReDim Preserve aTokens(sDim) As Object 5681ecadb57SMathias Bauer aTokens(sDim) = TP.nextElement 5691ecadb57SMathias Bauer Wend 5701ecadb57SMathias Bauer 5711ecadb57SMathias Bauer For i=1 to ubound(aTokens()) 5721ecadb57SMathias Bauer Token = aTokens(i) 5731ecadb57SMathias Bauer 5741ecadb57SMathias Bauer If Token.supportsService("com.sun.star.text.TextField") Then 5751ecadb57SMathias Bauer sTag = Token.TextField.TextFieldMaster.Name 5761ecadb57SMathias Bauer 5771ecadb57SMathias Bauer If Right(sTag,1)="_" Then ' a tag starts 5781ecadb57SMathias Bauer 5791ecadb57SMathias Bauer sTagName = Left(sTag,Len(sTag)-1) 5801ecadb57SMathias Bauer 5811ecadb57SMathias Bauer ' check for forbidden tags in paragraphs 5821ecadb57SMathias Bauer sTagFormat = TagFormatIsCorrect(sTagName, TE.ParaStyleName) 5831ecadb57SMathias Bauer If sTagFormat <> "" Then 5841ecadb57SMathias Bauer Terminate(sTagName+" element has wrong paragraph style ("+TE.ParaStyleName+")."+chr(13)+"Must be "+sTagFormat,Token) 5851ecadb57SMathias Bauer End If 5861ecadb57SMathias Bauer 5871ecadb57SMathias Bauer sDim = ubound(aInlineTagsOpen())+1 5881ecadb57SMathias Bauer Redim Preserve aInlineTagsOpen(sDim) as String 5891ecadb57SMathias Bauer aInlineTagsOpen(sDim)=sTagName 5901ecadb57SMathias Bauer 5911ecadb57SMathias Bauer ElseIf Left(sTag,1)="_" Then ' a tag ends, all other cases are empty tags 5921ecadb57SMathias Bauer 5931ecadb57SMathias Bauer sTagName = Right(sTag,Len(sTag)-1) 5941ecadb57SMathias Bauer 5951ecadb57SMathias Bauer ' check for forbidden tags in paragraphs 5961ecadb57SMathias Bauer sTagFormat = TagFormatIsCorrect(sTagName, TE.ParaStyleName) 5971ecadb57SMathias Bauer If sTagFormat <> "" Then 5981ecadb57SMathias Bauer Terminate(sTagName+" element has wrong paragraph style ("+TE.ParaStyleName+")."+chr(13)+"Must be "+sTagFormat,Token) 5991ecadb57SMathias Bauer End If 6001ecadb57SMathias Bauer 6011ecadb57SMathias Bauer If ubound(aInlineTagsOpen()) > 0 Then 6021ecadb57SMathias Bauer If aInlineTagsOpen(ubound(aInlineTagsOpen())) <> sTagName Then 6031ecadb57SMathias Bauer Terminate("Inline Element "+aInlineTagsOpen(ubound(aInlineTagsOpen()))+" not closed",Token) 6041ecadb57SMathias Bauer End If 6051ecadb57SMathias Bauer sDim = ubound(aInlineTagsOpen())-1 6061ecadb57SMathias Bauer Else 6071ecadb57SMathias Bauer Terminate("No opening tag for "+sTagName,Token) 6081ecadb57SMathias Bauer End If 6091ecadb57SMathias Bauer Redim Preserve aInlineTagsOpen(sDim) as String 6101ecadb57SMathias Bauer 6111ecadb57SMathias Bauer Else ' empty tag 6121ecadb57SMathias Bauer sTagName = sTag 6131ecadb57SMathias Bauer sTagFormat = TagFormatIsCorrect(sTagName, TE.ParaStyleName) 6141ecadb57SMathias Bauer If sTagFormat <> "" Then 6151ecadb57SMathias Bauer Terminate(sTagName+" element has wrong paragraph style ("+TE.ParaStyleName+")."+chr(13)+"Must be "+sTagFormat,Token) 6161ecadb57SMathias Bauer End If 6171ecadb57SMathias Bauer 6181ecadb57SMathias Bauer EndIf 6191ecadb57SMathias Bauer ElseIf (i > 1) AND (Trim(Token.String) <> "") Then 6201ecadb57SMathias Bauer If aInlineTagsOpen(ubound(aInlineTagsOpen())) = "SWITCHINLINE" Then 6211ecadb57SMathias Bauer Terminate("No text allowed here.",Token) 6221ecadb57SMathias Bauer End If 6231ecadb57SMathias Bauer End If 6241ecadb57SMathias Bauer Next 6251ecadb57SMathias Bauer 6261ecadb57SMathias Bauer If ubound(aInlineTagsOpen()) > 0 Then 6271ecadb57SMathias Bauer Terminate("Inline Element "+aInlineTagsOpen(ubound(aInlineTagsOpen()))+" not closed",Token) 6281ecadb57SMathias Bauer End If 6291ecadb57SMathias Bauer 6301ecadb57SMathias Bauer End If 6311ecadb57SMathias BauerEnd Sub 6321ecadb57SMathias Bauer 6331ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6341ecadb57SMathias Bauer' CHECK FOR CORRECT TAGS 6351ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6361ecadb57SMathias BauerSub CheckTags(TE As Object) 6371ecadb57SMathias Bauer If (Left(TE.ParaStyleName,8) = "hlp_aux_" AND TE.ParaStyleName <> "hlp_aux_bookmark") Then 6381ecadb57SMathias Bauer 6391ecadb57SMathias Bauer TP = TE.createEnumeration 6401ecadb57SMathias Bauer 6411ecadb57SMathias Bauer While TP.hasmoreElements 6421ecadb57SMathias Bauer TPE = TP.nextElement 6431ecadb57SMathias Bauer 6441ecadb57SMathias Bauer If TPE.supportsService("com.sun.star.text.TextField") Then 6451ecadb57SMathias Bauer sTag = TPE.TextField.TextFieldMaster.Name 6461ecadb57SMathias Bauer If Right(sTag,1)="_" Then ' a tag starts 6471ecadb57SMathias Bauer 6481ecadb57SMathias Bauer sTagName = Left(sTag,Len(sTag)-1) 6491ecadb57SMathias Bauer sDim = ubound(aTagsOpen())+1 6501ecadb57SMathias Bauer Redim Preserve aTagsOpen(sDim) as String 6511ecadb57SMathias Bauer aTagsOpen(sDim)=sTagName 6521ecadb57SMathias Bauer 6531ecadb57SMathias Bauer ElseIf Left(sTag,1)="_" Then ' a tag ends, all other cases are empty tags 6541ecadb57SMathias Bauer 6551ecadb57SMathias Bauer sTagName = Right(sTag,Len(sTag)-1) 6561ecadb57SMathias Bauer If ubound(aTagsOpen()) > 0 Then 6571ecadb57SMathias Bauer If aTagsOpen(ubound(aTagsOpen())) <> sTagName Then 6581ecadb57SMathias Bauer Terminate("No close tag for "+aTagsOpen(ubound(aTagsOpen())),TPE) 6591ecadb57SMathias Bauer Else 6601ecadb57SMathias Bauer sDim = ubound(aTagsOpen())-1 6611ecadb57SMathias Bauer End If 6621ecadb57SMathias Bauer Else 6631ecadb57SMathias Bauer Terminate("No opening tag for "+sTagName,TPE) 6641ecadb57SMathias Bauer End If 6651ecadb57SMathias Bauer Redim Preserve aTagsOpen(sDim) as String 6661ecadb57SMathias Bauer 6671ecadb57SMathias Bauer Else ' empty tags 6681ecadb57SMathias Bauer 6691ecadb57SMathias Bauer EndIf 6701ecadb57SMathias Bauer End If 6711ecadb57SMathias Bauer Wend 6721ecadb57SMathias Bauer End If 6731ecadb57SMathias BauerEnd Sub 6741ecadb57SMathias Bauer 6751ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6761ecadb57SMathias Bauer' CHECK FOR CORRECT TAGS IN A TABLE CELL 6771ecadb57SMathias Bauer'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6781ecadb57SMathias BauerSub CheckTagsInCell(CE As Object) 6791ecadb57SMathias Bauer If (Left(CE.ParaStyleName,8) = "hlp_aux_" AND CE.ParaStyleName <> "hlp_aux_bookmark") Then 6801ecadb57SMathias Bauer 6811ecadb57SMathias Bauer CP = CE.createEnumeration 6821ecadb57SMathias Bauer 6831ecadb57SMathias Bauer While CP.hasmoreElements 6841ecadb57SMathias Bauer CPE = CP.nextElement 6851ecadb57SMathias Bauer 6861ecadb57SMathias Bauer If CPE.supportsService("com.sun.star.text.TextField") Then 6871ecadb57SMathias Bauer sTag = CPE.TextField.TextFieldMaster.Name 6881ecadb57SMathias Bauer If Right(sTag,1)="_" Then ' a tag starts 6891ecadb57SMathias Bauer 6901ecadb57SMathias Bauer sTagName = Left(sTag,Len(sTag)-1) 6911ecadb57SMathias Bauer sDim = ubound(aCellTagsOpen())+1 6921ecadb57SMathias Bauer Redim Preserve aCellTagsOpen(sDim) as String 6931ecadb57SMathias Bauer aCellTagsOpen(sDim)=sTagName 6941ecadb57SMathias Bauer 6951ecadb57SMathias Bauer ElseIf Left(sTag,1)="_" Then ' a tag ends, all other cases are empty tags 6961ecadb57SMathias Bauer 6971ecadb57SMathias Bauer sTagName = Right(sTag,Len(sTag)-1) 6981ecadb57SMathias Bauer If ubound(aCellTagsOpen()) > 0 Then 6991ecadb57SMathias Bauer If aCellTagsOpen(ubound(aCellTagsOpen())) <> sTagName Then 7001ecadb57SMathias Bauer Terminate("No close tag for "+aCellTagsOpen(ubound(aCellTagsOpen())),CPE) 7011ecadb57SMathias Bauer Else 7021ecadb57SMathias Bauer sDim = ubound(aCellTagsOpen())-1 7031ecadb57SMathias Bauer End If 7041ecadb57SMathias Bauer Else 7051ecadb57SMathias Bauer Terminate("No opening tag for "+sTagName,CPE) 7061ecadb57SMathias Bauer End If 7071ecadb57SMathias Bauer Redim Preserve aCellTagsOpen(sDim) as String 7081ecadb57SMathias Bauer 7091ecadb57SMathias Bauer EndIf 7101ecadb57SMathias Bauer End If 7111ecadb57SMathias Bauer Wend 7121ecadb57SMathias Bauer End If 7131ecadb57SMathias BauerEnd Sub 7141ecadb57SMathias Bauer 715*3e02b54dSAndrew Rist</script:module> 716