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="Meta" script:language="StarBasic">REM  *****  BASIC  *****
24
25Dim oDialog AS Object
26Dim document AS Object
27
28&apos; Fetches the meta values from the document and executes the dialog
29Sub Main
30
31	If not IsHelpFile Then
32		msgbox(strErr_NoHelpFile)
33		Exit Sub
34	End If
35
36	document = StarDesktop.CurrentComponent
37
38	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
39	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgMeta&quot;)
40	oDialogModel = oDialog.Model
41
42	&apos;oTxtFName = oDialog.GetControl(&quot;txtFileName&quot;)
43	&apos;oTxtFName.Text = document.DocumentInfo.PropertyValues(29).Value
44	&apos;oTxtFName.Text = document.DocumentInfo.GetPropertyValue(&quot;Description&quot;)
45
46&apos;	If oTxtFName.Text = &quot;&quot; Then
47&apos;		msgbox &quot;The document must be saved first.&quot;+chr(13)+&quot;Please save the document and call this dialog again.&quot;
48&apos;		oDialog.dispose
49&apos;		Exit Sub
50&apos;	End If
51
52	oTxtTitle = oDialog.GetControl(&quot;txtTitle&quot;)
53	oTxtTitle.Text = document.DocumentInfo.Title
54
55	oOpIndInc = oDialog.GetControl(&quot;opIndexInclude&quot;)
56	oOpIndExc = oDialog.GetControl(&quot;opIndexExclude&quot;)
57
58
59	&apos;oCbFileStatus = oDialog.GetControl(&quot;cbFileStatus&quot;)
60	&apos;arItems = Array(&quot;DRAFT&quot;,&quot;FINAL&quot;,&quot;PUBLISH&quot;,&quot;STALLED&quot;,&quot;DEPRECATED&quot;)
61	&apos;oCbFileStatus.AddItems(arItems,ubound(arItems))
62	&apos;sStatus = document.DocumentInfo.GetPropertyValue(&quot;Keywords&quot;)
63	&apos;If (InStr(&quot;DRAFT FINAL PUBLISH STALLED DEPRECATED&quot;,sStatus)=0) Then
64	&apos;	oCbFileStatus.SetText(&quot;DRAFT&quot;)
65	&apos;Else
66	&apos;	oCbFileStatus.SetText(sStatus)
67	&apos;End If
68
69
70	If document.DocumentInfo.GetUserFieldValue(GetUserFieldNumber(&quot;Indexer&quot;)) = &quot;exclude&quot; then
71		oOpIndExc.State = True
72	Else
73		oOpIndInc.State = True
74	End If
75
76	&apos;oTxtTopicID = oDialog.GetControl(&quot;txtTopicID&quot;)
77	&apos;oTxtTopicID.Text = document.DocumentInfo.GetUserFieldValue(1)
78
79	&apos;oTxtComment = oDialog.GetControl(&quot;txtComment&quot;)
80	&apos;oTxtComment.Text = document.DocumentInfo.GetUserFieldValue(GetUserFieldNumber(&quot;Comment&quot;))
81
82	&apos;oTxtEdited = oDialog.GetControl(&quot;txtLastEdited&quot;)
83	&apos;oTxtEdited.Text = document.DocumentInfo.GetUserFieldValue(3)
84
85	If oDialog.Execute() = 1 Then &apos; update the meta data
86		document.DocumentInfo.Title = oTxtTitle.Text
87		&apos;document.DocumentInfo.SetUserFieldValue(1,oTxtTopicID.Text)
88		&apos;document.DocumentInfo.SetUserFieldValue(GetUserFieldNumber(&quot;Comment&quot;),oTxtComment.Text)
89		&apos;document.DocumentInfo.SetUserFieldValue(3,oTxtEdited.Text)
90		&apos;document.DocumentInfo.SetPropertyValue(&quot;Keywords&quot;,oCbFileStatus.Text)
91
92		&apos;If (oCbFileStatus.Text = &quot;PUBLISH&quot;) Then
93			REM... Check for paras without ID: If there are any, this cannot be PUBLISH!
94
95		&apos;End If
96
97		If oOpIndExc.State = True Then
98			document.DocumentInfo.SetUserFieldValue(GetUserFieldNumber(&quot;Indexer&quot;),&quot;exclude&quot;)
99		Else
100			document.DocumentInfo.SetUserFieldValue(GetUserFieldNumber(&quot;Indexer&quot;),&quot;include&quot;)
101		End If
102	End If
103	oDialog.dispose
104end sub
105
106&apos; Normalizes the values for title and topic id
107&apos; (if the fields are empty or contain invalid values)
108Sub NormalizeMeta (Event As Object)
109	Select Case Event.Source.Model.Name
110		Case &quot;txtTitle&quot;:
111			If Event.Source.Text = &quot;&quot; Then
112				msgbox &quot;Topic title must not be empty!&quot;+chr(13)+&quot;Resetting to default value.&quot;
113			End If
114			SetTopicTitle(Event.Source.Text)
115		Case &quot;txtTopicID&quot;:
116			If Event.Source.Text = &quot;&quot; Then
117				msgbox &quot;Topic ID must not be empty!&quot;+chr(13)+&quot;Resetting to default value.&quot;
118			End If
119			SetTopicID(Event.Source.Text)
120	End Select
121End Sub
122
123&apos; Sets the value in the Topic ID dialog field
124Sub SetTopicID(txt As String)
125	oTxtTopicID = oDialog.GetControl(&quot;txtTopicID&quot;)
126	If txt = &quot;&quot; Then
127		oTxtTopicID.Text = AlphaNum(document.DocumentInfo.PropertyValues(29).Value)
128	Else
129		oTxtTopicID.Text = AlphaNum(txt)
130	End If
131End Sub
132
133Sub Test
134	On Error Resume Next
135	document = StarDesktop.CurrentComponent
136&apos;	showprop document
137	msgbox document.URL
138
139End Sub
140
141&apos; Sets the value in the Topic title dialog field
142Sub SetTopicTitle(txt As String)
143	dim strg As String
144	oTxtTitle = oDialog.GetControl(&quot;txtTitle&quot;)
145
146	If txt =&quot;&quot; Then
147		Enum = document.Text.createEnumeration
148
149		Do While Enum.hasMoreElements
150			TextElement = Enum.nextElement
151			If TextElement.supportsService(&quot;com.sun.star.text.Paragraph&quot;) Then
152				If Left(TextElement.ParaStyleName,8)=&quot;hlp_head&quot; Then
153					Enum2 = TextElement.createEnumeration
154					While Enum2.hasMoreElements
155						TextPortion = Enum2.nextElement
156						If Not(TextPortion.TextPortionType=&quot;TextField&quot;) Then
157							strg = strg + TextPortion.String
158						End If
159					Wend
160					oTxtTitle.Text = strg
161					Exit Do
162				End If
163			End If
164		Loop
165	Else
166		oTxtTitle.Text = txt
167	End If
168End Sub
169
170&apos; Sets the value in the Topic title field when
171&apos; &quot;Fetch&quot; button is pressed
172Sub FetchTopicTitle
173	SetTopicTitle(&quot;&quot;)
174
175End Sub
176
177&apos; Sets the value in the Topic ID dialog field when
178&apos; &quot;Suggest&quot; button is pressed
179Sub SuggestTopicID
180	SetTopicID(&quot;&quot;)
181End Sub
182
183Sub ChangeStatus
184	oCbFileStatus = oDialog.GetControl(&quot;cbFileStatus&quot;)
185	sStatus = document.DocumentInfo.GetPropertyValue(&quot;Keywords&quot;)
186	If (oCbFileStatus.Text = &quot;PUBLISH&quot;) Then
187		nNoID = 0 &apos; DEBUG
188		If nNoID &lt;&gt; 0 Then
189			msgbox &quot;There are &quot;+nNoID+&quot; new paragraphs in the file.&quot;+chr(13)+&quot;File status PUBLISH invalid.&quot;+chr(13)+&quot;Setting back to &quot;+sStatus, 48, &quot;D&apos;oh!&quot;
190		End If
191	End If
192End Sub
193</script:module>
194