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