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 37' Be sure that all variables are dimensioned: 38option explicit 39 40'************************************************************************* 41' This Interface/Service test depends on the following GLOBAL variables, 42' which must be specified in the object creation: 43 44' - Global oStore As Object 45 46'************************************************************************* 47 48 49 50 51 52 53Sub RunTest() 54 55'************************************************************************* 56' INTERFACE: 57' com.sun.star.frame.XDocumentTemplates 58'************************************************************************* 59On Error Goto ErrHndl 60 Dim bOK As Boolean 61 Dim content As Object, groupContent As Object 62 Dim result as Object, statRes As Object 63 Dim res As Boolean 64 65 Test.StartMethod("getContent()") 66 bOK = true 67 content = oObj.getContent() 68 Out.Log("Content list :") 69 Out.Log(getContentList(content)) 70 71 bOK = bOK AND NOT isNull(content) 72 Test.MethodTested("getContent()", bOK) 73 74 Test.StartMethod("addGroup()") 75 bOK = true 76 res = oObj.addGroup("XDocumentTemplatesTemp") 77 Out.Log("Method returned: " + res) 78 bOK = bOK AND res AND NOT isNull(getSubContent(content, "XDocumentTemplatesTemp")) 79 Test.MethodTested("addGroup()", bOK) 80 81 Test.StartMethod("renameGroup()") 82 bOK = true 83 res = oObj.renameGroup("XDocumentTemplatesTemp", "XDocumentTemplates") 84 Out.Log("Method returned: " + res) 85 groupContent = getSubContent(content, "XDocumentTemplates") 86 bOK = bOK AND res AND isNull(getSubContent(content, "XDocumentTemplatesTemp")) _ 87 AND NOT isNull(groupContent) 88 Test.MethodTested("renameGroup()", bOK) 89 90 Test.StartMethod("addTemplate()") 91 Dim testDoc As String 92 testDoc = utils.Path2URL(cTestDocsDir) + "report.stw" 93 Out.Log("Adding template from " + testDoc 94 95 bOK = true 96 res = oObj.addTemplate("XDocumentTemplates", "ANewTemplateTemp", testDoc) 97 Out.Log("Method returned: " + res) 98 bOK = bOK AND res AND NOT isNull(getSubContent(groupContent, "ANewTemplateTemp")) 99 Test.MethodTested("addTemplate()", bOK) 100 101 Test.StartMethod("renameTemplate()") 102 bOK = true 103 res = oObj.renameTemplate("XDocumentTemplates", "ANewTemplateTemp", "ANewTemplate") 104 Out.Log("Method returned: " + res) 105 bOK = bOK AND res AND isNull(getSubContent(groupContent, "ANewTemplateTemp")) _ 106 AND NOT isNull(getSubContent(groupContent, "ANewTemplate")) 107 Test.MethodTested("renameTemplate()", bOK) 108 109 Test.StartMethod("storeTemplate()") 110 bOK = true 111 res = oObj.storeTemplate("XDocumentTemplates", "NewStoreTemplate", oStore) 112 Out.Log("Method returned: " + res) 113 bOK = bOK AND res AND NOT isNull(getSubContent(groupContent, "NewStoreTemplate")) 114 Test.MethodTested("storeTemplate()", bOK) 115 116 Test.StartMethod("removeTemplate()") 117 bOK = true 118 res = oObj.removeTemplate("XDocumentTemplates", "ANewTemplate") 119 Out.Log("Method returned: " + res) 120 bOK = bOK AND res AND isNull(getSubContent(groupContent, "ANewTemplate") 121 Test.MethodTested("removeTemplate()", bOK) 122 123 Test.StartMethod("removeGroup()") 124 bOK = true 125 res = oObj.removeGroup("XDocumentTemplates") 126 Out.Log("Method returned: " + res) 127 bOK = bOK AND res AND isNull(getSubContent(content, "XDocumentTemplatesTemp") 128 Test.MethodTested("removeGroup()", bOK) 129 130 Test.StartMethod("update()") 131 bOK = true 132 oObj.update() 133 Test.MethodTested("update()", bOK) 134 135Exit Sub 136ErrHndl: 137 Test.Exception() 138 bOK = false 139 resume next 140End Sub 141 142Function getDynaResultSet(content As Object) As Object 143 Dim command as new com.sun.star.ucb.Command 144 Dim comArg as new com.sun.star.ucb.OpenCommandArgument2 145 Dim comProps(0) as new com.sun.star.beans.Property 146 Dim result as Object, statRes As Object 147 148 comArg.Mode = com.sun.star.ucb.OpenMode.ALL 149 comProps(0).Name = "Title" 150 comArg.Properties = comProps() 151 152 command.Name = "open" 153 command.Handle = -1 154 command.Argument = comArg 155 156 getDynaResultSet = content.execute(command, 0, NULL_OBJECT) 157End Function 158 159Function getStatResultSet(content As Object) As Object 160 getStatResultSet = getDynaResultSet(content).getStaticResultSet() 161End Function 162 163Function getContentList(content As Object) As String 164 Dim statRes As Object 165 Dim ret As String 166 167 statRes = getStatResultSet(content) 168 statRes.first() 169 ret = "" 170 while NOT statRes.isAfterLast() 171 ret = ret + " " + statRes.getString(1) + chr(13) 172 statRes.next() 173 wend 174 getContentList = ret 175End Function 176 177Function getSubContent(content As Object, subName As String) As Object 178 Dim statRes As Object 179 Dim ret As Object 180 181 statRes = getStatResultSet(content) 182 statRes.first() 183 while NOT statRes.isAfterLast() 184 if subName = statRes.getString(1) then 185 ret = statRes.queryContent() 186 endif 187 statRes.next() 188 wend 189 190 getSubContent = ret 191End Function 192</script:module> 193