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; *  The Contents of this file are made available subject to the terms of
12&apos; *  either of the following licenses
13&apos; *
14&apos; *         - GNU Lesser General Public License Version 2.1
15&apos; *         - Sun Industry Standards Source License Version 1.1
16&apos; *
17&apos; *  Sun Microsystems Inc., October, 2000
18&apos; *
19&apos; *  GNU Lesser General Public License Version 2.1
20&apos; *  =============================================
21&apos; *  Copyright 2000 by Sun Microsystems, Inc.
22&apos; *  901 San Antonio Road, Palo Alto, CA 94303, USA
23&apos; *
24&apos; *  This library is free software; you can redistribute it and/or
25&apos; *  modify it under the terms of the GNU Lesser General Public
26&apos; *  License version 2.1, as published by the Free Software Foundation.
27&apos; *
28&apos; *  This library is distributed in the hope that it will be useful,
29&apos; *  but WITHOUT ANY WARRANTY; without even the implied warranty of
30&apos; *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
31&apos; *  Lesser General Public License for more details.
32&apos; *
33&apos; *  You should have received a copy of the GNU Lesser General Public
34&apos; *  License along with this library; if not, write to the Free Software
35&apos; *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
36&apos; *  MA  02111-1307  USA
37&apos; *
38&apos; *
39&apos; *  Sun Industry Standards Source License Version 1.1
40&apos; *  =================================================
41&apos; *  The contents of this file are subject to the Sun Industry Standards
42&apos; *  Source License Version 1.1 (the &quot;License&quot;); You may not use this file
43&apos; *  except in compliance with the License. You may obtain a copy of the
44&apos; *  License at http://www.openoffice.org/license.html.
45&apos; *
46&apos; *  Software provided under this License is provided on an &quot;AS IS&quot; basis,
47&apos; *  WITHOUT WARRUNTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,
48&apos; *  WITHOUT LIMITATION, WARRUNTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
49&apos; *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
50&apos; *  See the License for the specific provisions governing your rights and
51&apos; *  obligations concerning the Software.
52&apos; *
53&apos; *  The Initial Developer of the Original Code is: Sun Microsystems, Inc..
54&apos; *
55&apos; *  Copyright: 2000 by Sun Microsystems, Inc.
56&apos; *
57&apos; *  All Rights Reserved.
58&apos; *
59&apos; *  Contributor(s): _______________________________________
60&apos; *
61&apos; *
62&apos; ************************************************************************
63
64Global Const Version = &quot;v3.20100805&quot;
65
66Global Const strErr_NoHelpFile = &quot;Not a Help File&quot;
67
68&apos;=======================================================
69&apos; Main
70&apos;-------------------------------------------------------
71&apos; Ensure that necessary library functions are available
72&apos;=======================================================
73Sub Main
74	GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
75End Sub
76
77&apos;=======================================================
78&apos; SetMetaDataOnSave
79&apos;-------------------------------------------------------
80&apos; Sets the document meta data. It is called when
81&apos; the document is saved. It changes the data and
82&apos; then saves it again.
83&apos;=======================================================
84Sub SetMetaDataOnSave(Path as String)
85
86	document = StarDesktop.CurrentComponent
87	sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
88
89	If Path = &quot;&quot; Then
90		Path = document.URL
91	End If
92
93	If not(IsSubDir(Path,sDocRoot)) Then &apos; doesn&apos;tr work when resaving the file since it contains the OLD url (before resave)
94		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;)
95	Else
96		Path = Right(Path,Len(Path)-Len(sDocRoot))
97	End If
98
99	document.DocumentInfo.SetUserFieldName(0,&quot;Indexer&quot;)
100	document.DocumentInfo.SetUserFieldName(1,&quot;ID&quot;)
101&apos;	document.DocumentInfo.SetUserFieldName(2,&quot;Comment&quot;)
102	document.DocumentInfo.SetPropertyValue(&quot;Subject&quot;,Path)
103
104
105End Sub
106
107&apos;=======================================================
108&apos; ValidateOnSave
109&apos;-------------------------------------------------------
110&apos; Ensures that the document is validated when saved
111&apos; should be bound to the &quot;Document Save&quot; event but
112&apos; currently isn&apos;t
113&apos;=======================================================
114Sub ValidateOnSave
115	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
116	document = StarDesktop.CurrentComponent
117	If document.URL &lt;&gt; &quot;&quot; Then &apos; not initial save
118		If IsHelpFile Then
119			SetMetaDataOnSave(&quot;&quot;)
120			ValidateXHP
121		End If
122	End If
123End Sub
124
125
126&apos;=======================================================
127&apos; CreateFile
128&apos;-------------------------------------------------------
129&apos; Creates a new help file based on the help template
130&apos; and calls the save dialog
131&apos;=======================================================
132Sub CreateFile
133	GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
134	oPath = createUNOService(&quot;com.sun.star.util.PathSettings&quot;)
135	arPaths = Split(oPath.Template,&quot;;&quot;)  &apos; get the paths to the templates from the configuration
136	sHelpTemplate = &quot;&quot;
137
138	&apos; change stw extension to ott extension for template
139
140	For i=0 to ubound(arPaths)  &apos; see if the template path contains the help template
141		If FileExists(arPaths(i)+&quot;/Help/xmlhelptemplate.ott&quot;) Then
142			sHelpTemplate = arPaths(i)+&quot;/Help/xmlhelptemplate.ott&quot;
143		End If
144	Next i
145
146	If sHelpTemplate = &quot;&quot; Then
147		msgbox &quot;Cannot find the help template.&quot;,256
148	Else
149		oDoc = StarDesktop.loadComponentFromURL(sHelpTemplate,&quot;_blank&quot;,0,Array())
150		SaveAs(oDoc)
151	End If
152
153End Sub
154
155&apos;=======================================================
156&apos; SaveAs
157&apos;-------------------------------------------------------
158&apos; Initially saves a new help file on creation.
159&apos; Is called from CreateFile
160&apos;=======================================================
161Sub SaveAs(oDoc As Object)
162Dim ListAny(0) as Long
163Dim oStoreProperties(0) as New com.sun.star.beans.PropertyValue
164	On Local Error Goto ERRHANDLE:
165
166	sLastSaveDir = ReadConfig(&quot;LastSaveDir&quot;)
167	sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
168
169	ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD
170	oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
171	oFileDialog.Initialize(ListAny())
172
173	If sLastSaveDir &lt;&gt; &quot;&quot; AND IsSubDir(sLastSaveDir,sDocRoot) Then
174		oFileDialog.setDisplayDirectory(sLastSaveDir)
175	Else
176		oFileDialog.setDisplayDirectory(sDocRoot)
177	End If
178
179	oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.Office.TypeDetection/&quot;)
180	oFilters() = oMasterKey.Filters
181	oFileDialog.AppendFilter(&quot;Help&quot;, &quot;*.xhp&quot;)
182
183	oFileDialog.SetTitle(&quot;Save Help File As&quot;)
184	iAccept = oFileDialog.Execute()
185	If iAccept = 1 Then
186		WriteConfig(&quot;LastSaveDir&quot;,oFileDialog.getDisplayDirectory+&quot;/&quot;)
187		sPath = oFileDialog.Files(0)
188		oStoreProperties(0).Name = &quot;FilterName&quot;
189		oStoreProperties(0).Value = &quot;XHP_Help&quot;
190		SetMetaDataOnSave(sPath)
191		oDoc.StoreAsUrl(sPath, oStoreProperties())
192	Else
193		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
194		oDoc.dispose
195	End If
196	oFileDialog.Dispose()
197
198	ERRHANDLE:
199		If Err &lt;&gt; 0 Then
200			msgbox &quot;Error: &quot;+chr(13)+ Error$+chr(13)+&quot;Cannot save file.&quot;+chr(13),48,&quot;Fatal Error&quot;
201			oDoc.dispose
202		End If
203End Sub
204
205Sub CheckOnLoad
206&apos;	oDoc = StarDesktop.CurrentComponent
207&apos;	sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
208&apos;	If sDocRoot=&quot;&quot; Then
209&apos;		msgbox(&quot;No document root set. Please set the root folder for your documents.&quot;)
210&apos;		sDocRoot = SetDocumentRoot
211&apos;	End If
212&apos;	msgbox(HasUnoInterfaces(oDoc, &quot;com.sun.star.lang.XServiceInfo&quot;))
213&apos;	sFName = oDoc.URL
214&apos;	msgbox(sFName+chr(13)+sDocRoot)
215&apos;	If not(IsSubDir(sFName,sDocRoot)) Then
216&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;)
217&apos;	End If
218End Sub
219
220Sub DisplayVersion
221	msgbox &quot;OpenOffice.org Help Authoring Framework&quot;+chr(13)+&quot;Version &quot;+Version+chr(13)+chr(13)+&quot;(c) 2010 Oracle, Licensed under LGPL&quot;,256
222End Sub
223</script:module>