1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="_Main" script:language="StarBasic">&apos; Set of Macros used for Help Authoring
4&apos; =====================================
5&apos; Version
6&apos; -------------------------------------
7&apos;
8
9&apos; #**************************************************************
10&apos; #
11&apos; #  Licensed to the Apache Software Foundation (ASF) under one
12&apos; #  or more contributor license agreements.  See the NOTICE file
13&apos; #  distributed with this work for additional information
14&apos; #  regarding copyright ownership.  The ASF licenses this file
15&apos; #  to you under the Apache License, Version 2.0 (the
16&apos; #  "License"); you may not use this file except in compliance
17&apos; #  with the License.  You may obtain a copy of the License at
18&apos; #
19&apos; #    http://www.apache.org/licenses/LICENSE-2.0
20&apos; #
21&apos; #  Unless required by applicable law or agreed to in writing,
22&apos; #  software distributed under the License is distributed on an
23&apos; #  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24&apos; #  KIND, either express or implied.  See the License for the
25&apos; #  specific language governing permissions and limitations
26&apos; #  under the License.
27&apos; #
28&apos; #**************************************************************
29
30Global Const Version = &quot;v3.20100805&quot;
31
32Global Const strErr_NoHelpFile = &quot;Not a Help File&quot;
33
34&apos;=======================================================
35&apos; Main
36&apos;-------------------------------------------------------
37&apos; Ensure that necessary library functions are available
38&apos;=======================================================
39Sub Main
40	GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
41End Sub
42
43&apos;=======================================================
44&apos; SetMetaDataOnSave
45&apos;-------------------------------------------------------
46&apos; Sets the document meta data. It is called when
47&apos; the document is saved. It changes the data and
48&apos; then saves it again.
49&apos;=======================================================
50Sub SetMetaDataOnSave(Path as String)
51
52	document = StarDesktop.CurrentComponent
53	sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
54
55	If Path = &quot;&quot; Then
56		Path = document.URL
57	End If
58
59	If not(IsSubDir(Path,sDocRoot)) Then &apos; doesn&apos;tr work when resaving the file since it contains the OLD url (before resave)
60		msgbox(&quot;The File&quot;+chr(13)+Path+chr(13)+&quot;is outside of your Document Root&quot;+chr(13)+sDocRoot+chr(13)+chr(13)+&quot;You may want to adjust your document root settings and re-save the file.&quot;,48,&quot;Warning&quot;)
61	Else
62		Path = Right(Path,Len(Path)-Len(sDocRoot))
63	End If
64
65	document.DocumentInfo.SetUserFieldName(0,&quot;Indexer&quot;)
66	document.DocumentInfo.SetUserFieldName(1,&quot;ID&quot;)
67&apos;	document.DocumentInfo.SetUserFieldName(2,&quot;Comment&quot;)
68	document.DocumentInfo.SetPropertyValue(&quot;Subject&quot;,Path)
69
70
71End Sub
72
73&apos;=======================================================
74&apos; ValidateOnSave
75&apos;-------------------------------------------------------
76&apos; Ensures that the document is validated when saved
77&apos; should be bound to the &quot;Document Save&quot; event but
78&apos; currently isn&apos;t
79&apos;=======================================================
80Sub ValidateOnSave
81	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
82	document = StarDesktop.CurrentComponent
83	If document.URL &lt;&gt; &quot;&quot; Then &apos; not initial save
84		If IsHelpFile Then
85			SetMetaDataOnSave(&quot;&quot;)
86			ValidateXHP
87		End If
88	End If
89End Sub
90
91
92&apos;=======================================================
93&apos; CreateFile
94&apos;-------------------------------------------------------
95&apos; Creates a new help file based on the help template
96&apos; and calls the save dialog
97&apos;=======================================================
98Sub CreateFile
99	GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
100	oPath = createUNOService(&quot;com.sun.star.util.PathSettings&quot;)
101	arPaths = Split(oPath.Template,&quot;;&quot;)  &apos; get the paths to the templates from the configuration
102	sHelpTemplate = &quot;&quot;
103
104	&apos; change stw extension to ott extension for template
105
106	For i=0 to ubound(arPaths)  &apos; see if the template path contains the help template
107		If FileExists(arPaths(i)+&quot;/Help/xmlhelptemplate.ott&quot;) Then
108			sHelpTemplate = arPaths(i)+&quot;/Help/xmlhelptemplate.ott&quot;
109		End If
110	Next i
111
112	If sHelpTemplate = &quot;&quot; Then
113		msgbox &quot;Cannot find the help template.&quot;,256
114	Else
115		oDoc = StarDesktop.loadComponentFromURL(sHelpTemplate,&quot;_blank&quot;,0,Array())
116		SaveAs(oDoc)
117	End If
118
119End Sub
120
121&apos;=======================================================
122&apos; SaveAs
123&apos;-------------------------------------------------------
124&apos; Initially saves a new help file on creation.
125&apos; Is called from CreateFile
126&apos;=======================================================
127Sub SaveAs(oDoc As Object)
128Dim ListAny(0) as Long
129Dim oStoreProperties(0) as New com.sun.star.beans.PropertyValue
130	On Local Error Goto ERRHANDLE:
131
132	sLastSaveDir = ReadConfig(&quot;LastSaveDir&quot;)
133	sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
134
135	ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD
136	oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
137	oFileDialog.Initialize(ListAny())
138
139	If sLastSaveDir &lt;&gt; &quot;&quot; AND IsSubDir(sLastSaveDir,sDocRoot) Then
140		oFileDialog.setDisplayDirectory(sLastSaveDir)
141	Else
142		oFileDialog.setDisplayDirectory(sDocRoot)
143	End If
144
145	oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.Office.TypeDetection/&quot;)
146	oFilters() = oMasterKey.Filters
147	oFileDialog.AppendFilter(&quot;Help&quot;, &quot;*.xhp&quot;)
148
149	oFileDialog.SetTitle(&quot;Save Help File As&quot;)
150	iAccept = oFileDialog.Execute()
151	If iAccept = 1 Then
152		WriteConfig(&quot;LastSaveDir&quot;,oFileDialog.getDisplayDirectory+&quot;/&quot;)
153		sPath = oFileDialog.Files(0)
154		oStoreProperties(0).Name = &quot;FilterName&quot;
155		oStoreProperties(0).Value = &quot;XHP_Help&quot;
156		SetMetaDataOnSave(sPath)
157		oDoc.StoreAsUrl(sPath, oStoreProperties())
158	Else
159		msgbox &quot;You must save a help document before you can work on it.&quot;+chr(13)+&quot;This document will be disposed.&quot;, 48
160		oDoc.dispose
161	End If
162	oFileDialog.Dispose()
163
164	ERRHANDLE:
165		If Err &lt;&gt; 0 Then
166			msgbox &quot;Error: &quot;+chr(13)+ Error$+chr(13)+&quot;Cannot save file.&quot;+chr(13),48,&quot;Fatal Error&quot;
167			oDoc.dispose
168		End If
169End Sub
170
171Sub CheckOnLoad
172&apos;	oDoc = StarDesktop.CurrentComponent
173&apos;	sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
174&apos;	If sDocRoot=&quot;&quot; Then
175&apos;		msgbox(&quot;No document root set. Please set the root folder for your documents.&quot;)
176&apos;		sDocRoot = SetDocumentRoot
177&apos;	End If
178&apos;	msgbox(HasUnoInterfaces(oDoc, &quot;com.sun.star.lang.XServiceInfo&quot;))
179&apos;	sFName = oDoc.URL
180&apos;	msgbox(sFName+chr(13)+sDocRoot)
181&apos;	If not(IsSubDir(sFName,sDocRoot)) Then
182&apos;		msgbox(&quot;The file is located outside of your Document Root&quot;+chr(13)+sDocRoot+chr(13)+chr(13)+&quot;Please adjust your document root settings to avoid trouble with links, transcludes and images!&quot;,48,&quot;Warning!&quot;)
183&apos;	End If
184End Sub
185
186Sub DisplayVersion
187	msgbox &quot;OpenOffice.org Help Authoring Framework&quot;+chr(13)+&quot;Version &quot;+Version,256
188End Sub
189</script:module>
190