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