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="frame_XDocumentTemplates" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31' Be sure that all variables are dimensioned:
32option explicit
33
34'*************************************************************************
35' This Interface/Service test depends on the following GLOBAL variables,
36' which must be specified in the object creation:
37
38'     - Global oStore As Object
39
40'*************************************************************************
41
42
43
44
45
46
47Sub RunTest()
48
49'*************************************************************************
50' INTERFACE:
51' com.sun.star.frame.XDocumentTemplates
52'*************************************************************************
53On Error Goto ErrHndl
54    Dim bOK As Boolean
55    Dim content As Object, groupContent As Object
56    Dim result as Object, statRes As Object
57    Dim res As Boolean
58
59    Test.StartMethod("getContent()")
60    bOK = true
61    content = oObj.getContent()
62    Out.Log("Content list :")
63    Out.Log(getContentList(content))
64
65    bOK = bOK AND NOT isNull(content)
66    Test.MethodTested("getContent()", bOK)
67
68    Test.StartMethod("addGroup()")
69    bOK = true
70    res = oObj.addGroup("XDocumentTemplatesTemp")
71    Out.Log("Method returned: " + res)
72    bOK = bOK AND res AND NOT isNull(getSubContent(content, "XDocumentTemplatesTemp"))
73    Test.MethodTested("addGroup()", bOK)
74
75    Test.StartMethod("renameGroup()")
76    bOK = true
77    res = oObj.renameGroup("XDocumentTemplatesTemp", "XDocumentTemplates")
78    Out.Log("Method returned: " + res)
79    groupContent = getSubContent(content, "XDocumentTemplates")
80    bOK = bOK AND res AND isNull(getSubContent(content, "XDocumentTemplatesTemp")) _
81        AND NOT isNull(groupContent)
82    Test.MethodTested("renameGroup()", bOK)
83
84    Test.StartMethod("addTemplate()")
85    Dim testDoc As String
86    testDoc = utils.Path2URL(cTestDocsDir) + "report.stw"
87    Out.Log("Adding template from " + testDoc
88
89    bOK = true
90    res = oObj.addTemplate("XDocumentTemplates", "ANewTemplateTemp", testDoc)
91    Out.Log("Method returned: " + res)
92    bOK = bOK AND res AND NOT isNull(getSubContent(groupContent, "ANewTemplateTemp"))
93    Test.MethodTested("addTemplate()", bOK)
94
95    Test.StartMethod("renameTemplate()")
96    bOK = true
97    res = oObj.renameTemplate("XDocumentTemplates", "ANewTemplateTemp", "ANewTemplate")
98    Out.Log("Method returned: " + res)
99    bOK = bOK AND res AND isNull(getSubContent(groupContent, "ANewTemplateTemp")) _
100        AND NOT isNull(getSubContent(groupContent, "ANewTemplate"))
101    Test.MethodTested("renameTemplate()", bOK)
102
103    Test.StartMethod("storeTemplate()")
104    bOK = true
105    res = oObj.storeTemplate("XDocumentTemplates", "NewStoreTemplate", oStore)
106    Out.Log("Method returned: " + res)
107    bOK = bOK AND res AND NOT isNull(getSubContent(groupContent, "NewStoreTemplate"))
108    Test.MethodTested("storeTemplate()", bOK)
109
110    Test.StartMethod("removeTemplate()")
111    bOK = true
112    res = oObj.removeTemplate("XDocumentTemplates", "ANewTemplate")
113    Out.Log("Method returned: " + res)
114    bOK = bOK AND res AND isNull(getSubContent(groupContent, "ANewTemplate")
115    Test.MethodTested("removeTemplate()", bOK)
116
117    Test.StartMethod("removeGroup()")
118    bOK = true
119    res = oObj.removeGroup("XDocumentTemplates")
120    Out.Log("Method returned: " + res)
121    bOK = bOK AND res AND isNull(getSubContent(content, "XDocumentTemplatesTemp")
122    Test.MethodTested("removeGroup()", bOK)
123
124    Test.StartMethod("update()")
125    bOK = true
126    oObj.update()
127    Test.MethodTested("update()", bOK)
128
129Exit Sub
130ErrHndl:
131    Test.Exception()
132    bOK = false
133    resume next
134End Sub
135
136Function getDynaResultSet(content As Object) As Object
137    Dim command as new com.sun.star.ucb.Command
138    Dim comArg as new com.sun.star.ucb.OpenCommandArgument2
139    Dim comProps(0) as new com.sun.star.beans.Property
140    Dim result as Object, statRes As Object
141
142    comArg.Mode = com.sun.star.ucb.OpenMode.ALL
143    comProps(0).Name = "Title"
144    comArg.Properties = comProps()
145
146    command.Name = "open"
147    command.Handle = -1
148    command.Argument = comArg
149
150    getDynaResultSet = content.execute(command, 0, NULL_OBJECT)
151End Function
152
153Function getStatResultSet(content As Object) As Object
154    getStatResultSet = getDynaResultSet(content).getStaticResultSet()
155End Function
156
157Function getContentList(content As Object) As String
158    Dim statRes As Object
159    Dim ret As String
160
161    statRes = getStatResultSet(content)
162    statRes.first()
163    ret = ""
164    while NOT statRes.isAfterLast()
165         ret = ret + "   " + statRes.getString(1) + chr(13)
166         statRes.next()
167    wend
168    getContentList = ret
169End Function
170
171Function getSubContent(content As Object, subName As String) As Object
172    Dim statRes As Object
173    Dim ret As Object
174
175    statRes = getStatResultSet(content)
176    statRes.first()
177    while NOT statRes.isAfterLast()
178         if subName = statRes.getString(1) then
179            ret = statRes.queryContent()
180         endif
181         statRes.next()
182    wend
183
184    getSubContent = ret
185End Function
186</script:module>
187