11ecadb57SMathias Bauer<?xml version="1.0" encoding="UTF-8"?>
21ecadb57SMathias Bauer<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
31ecadb57SMathias Bauer<script:module xmlns:script="http://openoffice.org/2000/script" script:name="_Main" script:language="StarBasic">&apos; Set of Macros used for Help Authoring
41ecadb57SMathias Bauer&apos; =====================================
51ecadb57SMathias Bauer&apos; Version
61ecadb57SMathias Bauer&apos; -------------------------------------
71ecadb57SMathias Bauer&apos;
81ecadb57SMathias Bauer
9*841807c9SAndrew Rist&apos; #**************************************************************
10*841807c9SAndrew Rist&apos; #
11*841807c9SAndrew Rist&apos; #  Licensed to the Apache Software Foundation (ASF) under one
12*841807c9SAndrew Rist&apos; #  or more contributor license agreements.  See the NOTICE file
13*841807c9SAndrew Rist&apos; #  distributed with this work for additional information
14*841807c9SAndrew Rist&apos; #  regarding copyright ownership.  The ASF licenses this file
15*841807c9SAndrew Rist&apos; #  to you under the Apache License, Version 2.0 (the
16*841807c9SAndrew Rist&apos; #  "License"); you may not use this file except in compliance
17*841807c9SAndrew Rist&apos; #  with the License.  You may obtain a copy of the License at
18*841807c9SAndrew Rist&apos; #
19*841807c9SAndrew Rist&apos; #    http://www.apache.org/licenses/LICENSE-2.0
20*841807c9SAndrew Rist&apos; #
21*841807c9SAndrew Rist&apos; #  Unless required by applicable law or agreed to in writing,
22*841807c9SAndrew Rist&apos; #  software distributed under the License is distributed on an
23*841807c9SAndrew Rist&apos; #  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24*841807c9SAndrew Rist&apos; #  KIND, either express or implied.  See the License for the
25*841807c9SAndrew Rist&apos; #  specific language governing permissions and limitations
26*841807c9SAndrew Rist&apos; #  under the License.
27*841807c9SAndrew Rist&apos; #
28*841807c9SAndrew Rist&apos; #**************************************************************
291ecadb57SMathias Bauer
301ecadb57SMathias BauerGlobal Const Version = &quot;v3.20100805&quot;
311ecadb57SMathias Bauer
321ecadb57SMathias BauerGlobal Const strErr_NoHelpFile = &quot;Not a Help File&quot;
331ecadb57SMathias Bauer
341ecadb57SMathias Bauer&apos;=======================================================
351ecadb57SMathias Bauer&apos; Main
361ecadb57SMathias Bauer&apos;-------------------------------------------------------
371ecadb57SMathias Bauer&apos; Ensure that necessary library functions are available
381ecadb57SMathias Bauer&apos;=======================================================
391ecadb57SMathias BauerSub Main
401ecadb57SMathias Bauer	GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
411ecadb57SMathias BauerEnd Sub
421ecadb57SMathias Bauer
431ecadb57SMathias Bauer&apos;=======================================================
441ecadb57SMathias Bauer&apos; SetMetaDataOnSave
451ecadb57SMathias Bauer&apos;-------------------------------------------------------
461ecadb57SMathias Bauer&apos; Sets the document meta data. It is called when
471ecadb57SMathias Bauer&apos; the document is saved. It changes the data and
481ecadb57SMathias Bauer&apos; then saves it again.
491ecadb57SMathias Bauer&apos;=======================================================
501ecadb57SMathias BauerSub SetMetaDataOnSave(Path as String)
511ecadb57SMathias Bauer
521ecadb57SMathias Bauer	document = StarDesktop.CurrentComponent
531ecadb57SMathias Bauer	sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
541ecadb57SMathias Bauer
551ecadb57SMathias Bauer	If Path = &quot;&quot; Then
561ecadb57SMathias Bauer		Path = document.URL
571ecadb57SMathias Bauer	End If
581ecadb57SMathias Bauer
591ecadb57SMathias Bauer	If not(IsSubDir(Path,sDocRoot)) Then &apos; doesn&apos;tr work when resaving the file since it contains the OLD url (before resave)
601ecadb57SMathias 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;)
611ecadb57SMathias Bauer	Else
621ecadb57SMathias Bauer		Path = Right(Path,Len(Path)-Len(sDocRoot))
631ecadb57SMathias Bauer	End If
641ecadb57SMathias Bauer
651ecadb57SMathias Bauer	document.DocumentInfo.SetUserFieldName(0,&quot;Indexer&quot;)
661ecadb57SMathias Bauer	document.DocumentInfo.SetUserFieldName(1,&quot;ID&quot;)
671ecadb57SMathias Bauer&apos;	document.DocumentInfo.SetUserFieldName(2,&quot;Comment&quot;)
681ecadb57SMathias Bauer	document.DocumentInfo.SetPropertyValue(&quot;Subject&quot;,Path)
691ecadb57SMathias Bauer
701ecadb57SMathias Bauer
711ecadb57SMathias BauerEnd Sub
721ecadb57SMathias Bauer
731ecadb57SMathias Bauer&apos;=======================================================
741ecadb57SMathias Bauer&apos; ValidateOnSave
751ecadb57SMathias Bauer&apos;-------------------------------------------------------
761ecadb57SMathias Bauer&apos; Ensures that the document is validated when saved
771ecadb57SMathias Bauer&apos; should be bound to the &quot;Document Save&quot; event but
781ecadb57SMathias Bauer&apos; currently isn&apos;t
791ecadb57SMathias Bauer&apos;=======================================================
801ecadb57SMathias BauerSub ValidateOnSave
811ecadb57SMathias Bauer	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
821ecadb57SMathias Bauer	document = StarDesktop.CurrentComponent
831ecadb57SMathias Bauer	If document.URL &lt;&gt; &quot;&quot; Then &apos; not initial save
841ecadb57SMathias Bauer		If IsHelpFile Then
851ecadb57SMathias Bauer			SetMetaDataOnSave(&quot;&quot;)
861ecadb57SMathias Bauer			ValidateXHP
871ecadb57SMathias Bauer		End If
881ecadb57SMathias Bauer	End If
891ecadb57SMathias BauerEnd Sub
901ecadb57SMathias Bauer
911ecadb57SMathias Bauer
921ecadb57SMathias Bauer&apos;=======================================================
931ecadb57SMathias Bauer&apos; CreateFile
941ecadb57SMathias Bauer&apos;-------------------------------------------------------
951ecadb57SMathias Bauer&apos; Creates a new help file based on the help template
961ecadb57SMathias Bauer&apos; and calls the save dialog
971ecadb57SMathias Bauer&apos;=======================================================
981ecadb57SMathias BauerSub CreateFile
991ecadb57SMathias Bauer	GlobalScope.BasicLibraries.loadLibrary(&quot;Tools&quot;)
1001ecadb57SMathias Bauer	oPath = createUNOService(&quot;com.sun.star.util.PathSettings&quot;)
1011ecadb57SMathias Bauer	arPaths = Split(oPath.Template,&quot;;&quot;)  &apos; get the paths to the templates from the configuration
1021ecadb57SMathias Bauer	sHelpTemplate = &quot;&quot;
1031ecadb57SMathias Bauer
1041ecadb57SMathias Bauer	&apos; change stw extension to ott extension for template
1051ecadb57SMathias Bauer
1061ecadb57SMathias Bauer	For i=0 to ubound(arPaths)  &apos; see if the template path contains the help template
1071ecadb57SMathias Bauer		If FileExists(arPaths(i)+&quot;/Help/xmlhelptemplate.ott&quot;) Then
1081ecadb57SMathias Bauer			sHelpTemplate = arPaths(i)+&quot;/Help/xmlhelptemplate.ott&quot;
1091ecadb57SMathias Bauer		End If
1101ecadb57SMathias Bauer	Next i
1111ecadb57SMathias Bauer
1121ecadb57SMathias Bauer	If sHelpTemplate = &quot;&quot; Then
1131ecadb57SMathias Bauer		msgbox &quot;Cannot find the help template.&quot;,256
1141ecadb57SMathias Bauer	Else
1151ecadb57SMathias Bauer		oDoc = StarDesktop.loadComponentFromURL(sHelpTemplate,&quot;_blank&quot;,0,Array())
1161ecadb57SMathias Bauer		SaveAs(oDoc)
1171ecadb57SMathias Bauer	End If
1181ecadb57SMathias Bauer
1191ecadb57SMathias BauerEnd Sub
1201ecadb57SMathias Bauer
1211ecadb57SMathias Bauer&apos;=======================================================
1221ecadb57SMathias Bauer&apos; SaveAs
1231ecadb57SMathias Bauer&apos;-------------------------------------------------------
1241ecadb57SMathias Bauer&apos; Initially saves a new help file on creation.
1251ecadb57SMathias Bauer&apos; Is called from CreateFile
1261ecadb57SMathias Bauer&apos;=======================================================
1271ecadb57SMathias BauerSub SaveAs(oDoc As Object)
1281ecadb57SMathias BauerDim ListAny(0) as Long
1291ecadb57SMathias BauerDim oStoreProperties(0) as New com.sun.star.beans.PropertyValue
1301ecadb57SMathias Bauer	On Local Error Goto ERRHANDLE:
1311ecadb57SMathias Bauer
1321ecadb57SMathias Bauer	sLastSaveDir = ReadConfig(&quot;LastSaveDir&quot;)
1331ecadb57SMathias Bauer	sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
1341ecadb57SMathias Bauer
1351ecadb57SMathias Bauer	ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD
1361ecadb57SMathias Bauer	oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
1371ecadb57SMathias Bauer	oFileDialog.Initialize(ListAny())
1381ecadb57SMathias Bauer
1391ecadb57SMathias Bauer	If sLastSaveDir &lt;&gt; &quot;&quot; AND IsSubDir(sLastSaveDir,sDocRoot) Then
1401ecadb57SMathias Bauer		oFileDialog.setDisplayDirectory(sLastSaveDir)
1411ecadb57SMathias Bauer	Else
1421ecadb57SMathias Bauer		oFileDialog.setDisplayDirectory(sDocRoot)
1431ecadb57SMathias Bauer	End If
1441ecadb57SMathias Bauer
1451ecadb57SMathias Bauer	oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.Office.TypeDetection/&quot;)
1461ecadb57SMathias Bauer	oFilters() = oMasterKey.Filters
1471ecadb57SMathias Bauer	oFileDialog.AppendFilter(&quot;Help&quot;, &quot;*.xhp&quot;)
1481ecadb57SMathias Bauer
1491ecadb57SMathias Bauer	oFileDialog.SetTitle(&quot;Save Help File As&quot;)
1501ecadb57SMathias Bauer	iAccept = oFileDialog.Execute()
1511ecadb57SMathias Bauer	If iAccept = 1 Then
1521ecadb57SMathias Bauer		WriteConfig(&quot;LastSaveDir&quot;,oFileDialog.getDisplayDirectory+&quot;/&quot;)
1531ecadb57SMathias Bauer		sPath = oFileDialog.Files(0)
1541ecadb57SMathias Bauer		oStoreProperties(0).Name = &quot;FilterName&quot;
1551ecadb57SMathias Bauer		oStoreProperties(0).Value = &quot;XHP_Help&quot;
1561ecadb57SMathias Bauer		SetMetaDataOnSave(sPath)
1571ecadb57SMathias Bauer		oDoc.StoreAsUrl(sPath, oStoreProperties())
1581ecadb57SMathias Bauer	Else
1591ecadb57SMathias 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
1601ecadb57SMathias Bauer		oDoc.dispose
1611ecadb57SMathias Bauer	End If
1621ecadb57SMathias Bauer	oFileDialog.Dispose()
1631ecadb57SMathias Bauer
1641ecadb57SMathias Bauer	ERRHANDLE:
1651ecadb57SMathias Bauer		If Err &lt;&gt; 0 Then
1661ecadb57SMathias Bauer			msgbox &quot;Error: &quot;+chr(13)+ Error$+chr(13)+&quot;Cannot save file.&quot;+chr(13),48,&quot;Fatal Error&quot;
1671ecadb57SMathias Bauer			oDoc.dispose
1681ecadb57SMathias Bauer		End If
1691ecadb57SMathias BauerEnd Sub
1701ecadb57SMathias Bauer
1711ecadb57SMathias BauerSub CheckOnLoad
1721ecadb57SMathias Bauer&apos;	oDoc = StarDesktop.CurrentComponent
1731ecadb57SMathias Bauer&apos;	sDocRoot = ReadConfig(&quot;HelpPrefix&quot;)
1741ecadb57SMathias Bauer&apos;	If sDocRoot=&quot;&quot; Then
1751ecadb57SMathias Bauer&apos;		msgbox(&quot;No document root set. Please set the root folder for your documents.&quot;)
1761ecadb57SMathias Bauer&apos;		sDocRoot = SetDocumentRoot
1771ecadb57SMathias Bauer&apos;	End If
1781ecadb57SMathias Bauer&apos;	msgbox(HasUnoInterfaces(oDoc, &quot;com.sun.star.lang.XServiceInfo&quot;))
1791ecadb57SMathias Bauer&apos;	sFName = oDoc.URL
1801ecadb57SMathias Bauer&apos;	msgbox(sFName+chr(13)+sDocRoot)
1811ecadb57SMathias Bauer&apos;	If not(IsSubDir(sFName,sDocRoot)) Then
1821ecadb57SMathias 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;)
1831ecadb57SMathias Bauer&apos;	End If
1841ecadb57SMathias BauerEnd Sub
1851ecadb57SMathias Bauer
1861ecadb57SMathias BauerSub DisplayVersion
1871ecadb57SMathias 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
1881ecadb57SMathias BauerEnd Sub
189*841807c9SAndrew Rist</script:module>
190