1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._cached; 29 30 import com.sun.star.beans.Property; 31 import com.sun.star.lang.XMultiServiceFactory; 32 import com.sun.star.ucb.Command; 33 import com.sun.star.ucb.NumberedSortingInfo; 34 import com.sun.star.ucb.OpenCommandArgument2; 35 import com.sun.star.ucb.OpenMode; 36 import com.sun.star.ucb.XCachedDynamicResultSetStubFactory; 37 import com.sun.star.ucb.XCommandProcessor; 38 import com.sun.star.ucb.XContent; 39 import com.sun.star.ucb.XContentIdentifier; 40 import com.sun.star.ucb.XContentIdentifierFactory; 41 import com.sun.star.ucb.XContentProvider; 42 import com.sun.star.ucb.XDynamicResultSet; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 import com.sun.star.uno.Type; 46 import com.sun.star.uno.AnyConverter; 47 import java.io.PrintWriter; 48 import lib.StatusException; 49 import lib.TestCase; 50 import lib.TestEnvironment; 51 import lib.TestParameters; 52 53 /** 54 * Test for object which is represented by service 55 * <code>com.sun.star.ucb.CachedDynamicResultSetFactory</code>. <p> 56 * Object implements the following interfaces : 57 * <ul> 58 * <li> <code>com::sun::star::ucb::XCachedDynamicResultSetFactory</code></li> 59 * </ul> <p> 60 * This object test <b> is NOT </b> designed to be run in several 61 * threads concurently. 62 * @see com.sun.star.ucb.XCachedDynamicResultSetFactory 63 * @see com.sun.star.ucb.CachedDynamicResultSetFactory 64 * @see ifc.ucb._XCachedDynamicResultSetFactory 65 */ 66 public class CachedDynamicResultSetFactory extends TestCase { 67 68 /** 69 * Creating a Testenvironment for the interfaces to be tested. 70 * Creates an instance of the service 71 * <code>com.sun.star.ucb.CachedDynamicResultSetFactory</code>. <p> 72 * Object relations created : 73 * <ul> 74 * <li> <code>'CachedDynamicResultSetStub'</code> for 75 * {@link ifc.XCachedDynamicResultSetFactory} : the destination 76 * interface requires as its parameter an instance of 77 * <code>CachedDynamicResultSetStub</code> service. It is created 78 * using <code>UniversalContentBroker</code> and queriing it for 79 * <code>PackageContent</code> which represents JAR file mentioned 80 * above. Then the dynamic list of file contents (entries) is retrieved. 81 * Using <code>CachedDynamicResultSetStubFactory</code> service a stub of 82 * Cached result set is created which is relation required. 83 * </li> 84 * </ul> 85 */ 86 public TestEnvironment createTestEnvironment( TestParameters Param, 87 PrintWriter log ) 88 throws StatusException { 89 XInterface oObj = null; 90 Object oInterface = null; 91 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF(); 92 Object relationContainer = null ; 93 94 95 try { 96 oInterface = xMSF.createInstance 97 ( "com.sun.star.ucb.CachedDynamicResultSetFactory" ); 98 99 // adding one child container 100 } 101 catch( com.sun.star.uno.Exception e ) { 102 log.println("Can't create an object." ); 103 throw new StatusException( "Can't create an object", e ); 104 } 105 106 oObj = (XInterface) oInterface; 107 108 TestEnvironment tEnv = new TestEnvironment( oObj ); 109 110 // creating relation for XCachedDynamicResultSetFactory 111 XDynamicResultSet resSetStub = null ; 112 try { 113 Object oUCB = xMSF.createInstanceWithArguments 114 ("com.sun.star.ucb.UniversalContentBroker", 115 new Object[] {"Local", "Office"}) ; 116 117 XContentIdentifierFactory ciFac = (XContentIdentifierFactory) 118 UnoRuntime.queryInterface(XContentIdentifierFactory.class, oUCB) ; 119 120 String url = util.utils.getFullTestURL("SwXTextEmbeddedObject.sxw") ; 121 String escUrl = "" ; 122 123 // In base URL of a JAR file in content URL all directory 124 // separators ('/') must be replaced with escape symbol '%2F'. 125 int idx = url.indexOf("/") ; 126 int lastIdx = -1 ; 127 while (idx >= 0) { 128 escUrl += url.substring(lastIdx + 1, idx) + "%2F" ; 129 lastIdx = idx ; 130 idx = url.indexOf("/", idx + 1) ; 131 } 132 escUrl += url.substring(lastIdx + 1) ; 133 String cntUrl = "vnd.sun.star.pkg://" + escUrl + "/" ; 134 135 XContentIdentifier CI = ciFac.createContentIdentifier(cntUrl) ; 136 137 XContentProvider cntProv = (XContentProvider) 138 UnoRuntime.queryInterface(XContentProvider.class, oUCB) ; 139 140 XContent cnt = cntProv.queryContent(CI) ; 141 142 XCommandProcessor cmdProc = (XCommandProcessor) 143 UnoRuntime.queryInterface(XCommandProcessor.class, cnt) ; 144 145 Property prop = new Property() ; 146 prop.Name = "Title" ; 147 148 Command cmd = new Command("open", -1, new OpenCommandArgument2 149 (OpenMode.ALL, 10000, null, new Property[] {prop}, 150 new NumberedSortingInfo[0])) ; 151 152 XDynamicResultSet dynResSet = null; 153 try { 154 dynResSet = (XDynamicResultSet) 155 AnyConverter.toObject(new Type(XDynamicResultSet.class), 156 cmdProc.execute(cmd, 0, null)); 157 } catch (com.sun.star.lang.IllegalArgumentException iae) { 158 throw new StatusException("Couldn't convert Any ",iae); 159 } 160 161 Object oStubFactory = xMSF.createInstance 162 ("com.sun.star.ucb.CachedDynamicResultSetStubFactory") ; 163 164 XCachedDynamicResultSetStubFactory xStubFactory = 165 (XCachedDynamicResultSetStubFactory) UnoRuntime.queryInterface 166 (XCachedDynamicResultSetStubFactory.class, oStubFactory) ; 167 168 resSetStub = 169 xStubFactory.createCachedDynamicResultSetStub(dynResSet) ; 170 171 } catch (com.sun.star.uno.Exception e) { 172 log.println("Can't create relation." ); 173 e.printStackTrace(log) ; 174 throw new StatusException( "Can't create relation", e ); 175 } 176 177 tEnv.addObjRelation("CachedDynamicResultSetStub", resSetStub) ; 178 179 return tEnv; 180 } // finish method getTestEnvironment 181 182 } 183 184