1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ChangeAllChars" script:language="StarBasic">&apos; This macro replaces all characters in a writer-documet through &quot;x&quot; or &quot;X&quot; signs.
24&apos; It works on the currently activated document.
25Private const UPPERREPLACECHAR = &quot;X&quot;
26Private const LOWERREPLACECHAR = &quot;x&quot;
27
28Private MSGBOXTITLE
29Private NOTSAVEDTEXT
30Private WARNING
31
32Sub ChangeAllChars   &apos; Change all chars in the active document
33Dim oSheets, oPages as Object
34Dim i as Integer
35Const MBYES = 6
36Const MBABORT = 2
37Const MBNO = 7
38	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
39	MSGBOXTITLE = &quot;Change All Characters to an &apos;&quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos;&quot;
40	NOTSAVEDTEXT = &quot;This document has already been modified: All characters will be changed to an &quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos;. Should the document be saved now?&quot;
41	WARNING = &quot;This macro changes all characters and numbers to an &apos;&quot; &amp; UPPERREPLACECHAR &amp; &quot;&apos; in this document.&quot;
42
43	On Local Error GoTo NODOCUMENT
44	oDocument = StarDesktop.ActiveFrame.Controller.Model
45	NODOCUMENT:
46	If Err &lt;&gt; 0 Then
47		Msgbox(WARNING &amp; chr(13) &amp; &quot;First, activate a Writer document.&quot; , 16, GetProductName())
48		Exit Sub
49	End If
50	On Local Error Goto 0
51
52	sDocType = GetDocumentType(oDocument)
53
54	If oDocument.IsModified And oDocument.Url &lt;&gt; &quot;&quot; Then
55		Status = MsgBox(NOTSAVEDTEXT, 3+32, MSGBOXTITLE)
56		Select Case Status
57			Case MBYES
58				oDocument.Store
59			Case MBABORT, MBNO
60				End
61		End Select
62	Else
63		Status = MsgBox(WARNING, 3+32, MSGBOXTITLE)
64		If Status = MBNO Or Status = MBABORT Then  &apos; No, Abort
65			End
66		End If
67	End If
68
69	Select Case sDocType
70		Case &quot;swriter&quot;
71			ReplaceAllStrings(oDocument)
72
73		Case Else
74			Msgbox(&quot;This macro only works with Writer documents.&quot;, 16, GetProductName())
75	End Select
76End Sub
77
78
79Sub ReplaceAllStrings(oContainer as Object)
80	ReplaceStrings(oContainer, &quot;[a-z]&quot;, LOWERREPLACECHAR)
81	ReplaceStrings(oContainer, &quot;[à-þ]&quot;, LOWERREPLACECHAR)
82	ReplaceStrings(oContainer, &quot;[A-Z]&quot;, UPPERREPLACECHAR)
83	ReplaceStrings(oContainer, &quot;[À-ß]&quot;, UPPERREPLACECHAR)
84	ReplaceStrings(oContainer, &quot;[0-9]&quot;, UPPERREPLACECHAR)
85End Sub
86
87
88Sub ReplaceStrings(oContainer as Object, sSearchString, sReplaceString  as String)
89	oReplaceDesc = oContainer.createReplaceDescriptor()
90	oReplaceDesc.SearchCaseSensitive = True
91	oReplaceDesc.SearchRegularExpression = True
92	oReplaceDesc.Searchstring = sSearchString
93	oReplaceDesc.ReplaceString = sReplaceString
94	oReplCount = oContainer.ReplaceAll(oReplaceDesc)
95End Sub</script:module>
96