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' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9' 10' Copyright 2000, 2010 Oracle and/or its affiliates. 11' 12' OpenOffice.org - a multi-platform office productivity suite 13' 14' This file is part of OpenOffice.org. 15' 16' OpenOffice.org is free software: you can redistribute it and/or modify 17' it under the terms of the GNU Lesser General Public License version 3 18' only, as published by the Free Software Foundation. 19' 20' OpenOffice.org is distributed in the hope that it will be useful, 21' but WITHOUT ANY WARRANTY; without even the implied warranty of 22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23' GNU Lesser General Public License version 3 for more details 24' (a copy is included in the LICENSE file that accompanied this code). 25' 26' You should have received a copy of the GNU Lesser General Public License 27' version 3 along with OpenOffice.org. If not, see 28' <http://www.openoffice.org/license.html> 29' for a copy of the LGPLv3 License. 30' 31'************************************************************************* 32'************************************************************************* 33 34 35 36' Be sure that all variables are dimensioned: 37option explicit 38 39'************************************************************************* 40' This Interface/Service test depends on the following GLOBAL variables, 41' which must be specified in the object creation: 42 43' - Global oStore As Object 44 45'************************************************************************* 46 47 48 49 50 51 52Sub RunTest() 53 54'************************************************************************* 55' INTERFACE: 56' com.sun.star.frame.XDocumentTemplates 57'************************************************************************* 58On Error Goto ErrHndl 59 Dim bOK As Boolean 60 Dim content As Object, groupContent As Object 61 Dim result as Object, statRes As Object 62 Dim res As Boolean 63 64 Test.StartMethod("getContent()") 65 bOK = true 66 content = oObj.getContent() 67 Out.Log("Content list :") 68 Out.Log(getContentList(content)) 69 70 bOK = bOK AND NOT isNull(content) 71 Test.MethodTested("getContent()", bOK) 72 73 Test.StartMethod("addGroup()") 74 bOK = true 75 res = oObj.addGroup("XDocumentTemplatesTemp") 76 Out.Log("Method returned: " + res) 77 bOK = bOK AND res AND NOT isNull(getSubContent(content, "XDocumentTemplatesTemp")) 78 Test.MethodTested("addGroup()", bOK) 79 80 Test.StartMethod("renameGroup()") 81 bOK = true 82 res = oObj.renameGroup("XDocumentTemplatesTemp", "XDocumentTemplates") 83 Out.Log("Method returned: " + res) 84 groupContent = getSubContent(content, "XDocumentTemplates") 85 bOK = bOK AND res AND isNull(getSubContent(content, "XDocumentTemplatesTemp")) _ 86 AND NOT isNull(groupContent) 87 Test.MethodTested("renameGroup()", bOK) 88 89 Test.StartMethod("addTemplate()") 90 Dim testDoc As String 91 testDoc = utils.Path2URL(cTestDocsDir) + "report.stw" 92 Out.Log("Adding template from " + testDoc 93 94 bOK = true 95 res = oObj.addTemplate("XDocumentTemplates", "ANewTemplateTemp", testDoc) 96 Out.Log("Method returned: " + res) 97 bOK = bOK AND res AND NOT isNull(getSubContent(groupContent, "ANewTemplateTemp")) 98 Test.MethodTested("addTemplate()", bOK) 99 100 Test.StartMethod("renameTemplate()") 101 bOK = true 102 res = oObj.renameTemplate("XDocumentTemplates", "ANewTemplateTemp", "ANewTemplate") 103 Out.Log("Method returned: " + res) 104 bOK = bOK AND res AND isNull(getSubContent(groupContent, "ANewTemplateTemp")) _ 105 AND NOT isNull(getSubContent(groupContent, "ANewTemplate")) 106 Test.MethodTested("renameTemplate()", bOK) 107 108 Test.StartMethod("storeTemplate()") 109 bOK = true 110 res = oObj.storeTemplate("XDocumentTemplates", "NewStoreTemplate", oStore) 111 Out.Log("Method returned: " + res) 112 bOK = bOK AND res AND NOT isNull(getSubContent(groupContent, "NewStoreTemplate")) 113 Test.MethodTested("storeTemplate()", bOK) 114 115 Test.StartMethod("removeTemplate()") 116 bOK = true 117 res = oObj.removeTemplate("XDocumentTemplates", "ANewTemplate") 118 Out.Log("Method returned: " + res) 119 bOK = bOK AND res AND isNull(getSubContent(groupContent, "ANewTemplate") 120 Test.MethodTested("removeTemplate()", bOK) 121 122 Test.StartMethod("removeGroup()") 123 bOK = true 124 res = oObj.removeGroup("XDocumentTemplates") 125 Out.Log("Method returned: " + res) 126 bOK = bOK AND res AND isNull(getSubContent(content, "XDocumentTemplatesTemp") 127 Test.MethodTested("removeGroup()", bOK) 128 129 Test.StartMethod("update()") 130 bOK = true 131 oObj.update() 132 Test.MethodTested("update()", bOK) 133 134Exit Sub 135ErrHndl: 136 Test.Exception() 137 bOK = false 138 resume next 139End Sub 140 141Function getDynaResultSet(content As Object) As Object 142 Dim command as new com.sun.star.ucb.Command 143 Dim comArg as new com.sun.star.ucb.OpenCommandArgument2 144 Dim comProps(0) as new com.sun.star.beans.Property 145 Dim result as Object, statRes As Object 146 147 comArg.Mode = com.sun.star.ucb.OpenMode.ALL 148 comProps(0).Name = "Title" 149 comArg.Properties = comProps() 150 151 command.Name = "open" 152 command.Handle = -1 153 command.Argument = comArg 154 155 getDynaResultSet = content.execute(command, 0, NULL_OBJECT) 156End Function 157 158Function getStatResultSet(content As Object) As Object 159 getStatResultSet = getDynaResultSet(content).getStaticResultSet() 160End Function 161 162Function getContentList(content As Object) As String 163 Dim statRes As Object 164 Dim ret As String 165 166 statRes = getStatResultSet(content) 167 statRes.first() 168 ret = "" 169 while NOT statRes.isAfterLast() 170 ret = ret + " " + statRes.getString(1) + chr(13) 171 statRes.next() 172 wend 173 getContentList = ret 174End Function 175 176Function getSubContent(content As Object, subName As String) As Object 177 Dim statRes As Object 178 Dim ret As Object 179 180 statRes = getStatResultSet(content) 181 statRes.first() 182 while NOT statRes.isAfterLast() 183 if subName = statRes.getString(1) then 184 ret = statRes.queryContent() 185 endif 186 statRes.next() 187 wend 188 189 getSubContent = ret 190End Function 191</script:module> 192