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.XCommandProcessor; 37 import com.sun.star.ucb.XContent; 38 import com.sun.star.ucb.XContentIdentifier; 39 import com.sun.star.ucb.XContentIdentifierFactory; 40 import com.sun.star.ucb.XContentProvider; 41 import com.sun.star.ucb.XDynamicResultSet; 42 import com.sun.star.uno.UnoRuntime; 43 import com.sun.star.uno.XInterface; 44 import com.sun.star.uno.Type; 45 import com.sun.star.uno.AnyConverter; 46 import java.io.PrintWriter; 47 import lib.StatusException; 48 import lib.TestCase; 49 import lib.TestEnvironment; 50 import lib.TestParameters; 51 52 /** 53 * Test for object which is represented by service 54 * <code>com.sun.star.ucb.CachedDynamicResultSetStubFactory</code>. <p> 55 * Object implements the following interfaces : 56 * <ul> 57 * <li> <code>com::sun::star::ucb::XCachedDynamicResultSetStubFactory</code></li> 58 * </ul> <p> 59 * This object test <b> is NOT </b> designed to be run in several 60 * threads concurently. 61 * @see com.sun.star.ucb.XCachedDynamicResultSetStubFactory 62 * @see com.sun.star.ucb.CachedDynamicResultSetStubFactory 63 * @see ifc.ucb._XCachedDynamicResultSetStubFactory 64 */ 65 public class CachedDynamicResultSetStubFactory extends TestCase { 66 67 /** 68 * Creating a Testenvironment for the interfaces to be tested. 69 * Creates an instance of the service 70 * <code>com.sun.star.ucb.CachedDynamicResultSetStubFactory</code>. <p> 71 * Object relations created : 72 * <ul> 73 * <li> <code>'DynamicResultSet'</code> for 74 * {@link ifc.XCachedDynamicResultSetStubFactory} : the destination 75 * interface requires as its parameter an instance of 76 * <code>DynamicResultSet</code> service. It is created 77 * using <code>UniversalContentBroker</code> and queriing it for 78 * <code>PackageContent</code> which represents JAR file mentioned 79 * above. Then the dynamic list of file contents (entries) is retrieved. 80 * </li> 81 * </ul> 82 */ 83 public TestEnvironment createTestEnvironment( TestParameters Param, 84 PrintWriter log ) 85 throws StatusException { 86 XInterface oObj = null; 87 Object oInterface = null; 88 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF(); 89 Object relationContainer = null ; 90 91 92 try { 93 oInterface = xMSF.createInstance 94 ( "com.sun.star.ucb.CachedDynamicResultSetStubFactory" ); 95 96 // adding one child container 97 } 98 catch( com.sun.star.uno.Exception e ) { 99 log.println("Can't create an object." ); 100 throw new StatusException( "Can't create an object", e ); 101 } 102 103 oObj = (XInterface) oInterface; 104 105 TestEnvironment tEnv = new TestEnvironment( oObj ); 106 107 // creating relation for XCachedDynamicResultSetStubFactory 108 XDynamicResultSet dynResSet = null ; 109 try { 110 Object oUCB = xMSF.createInstanceWithArguments 111 ("com.sun.star.ucb.UniversalContentBroker", 112 new Object[] {"Local", "Office"}) ; 113 114 XContentIdentifierFactory ciFac = (XContentIdentifierFactory) 115 UnoRuntime.queryInterface(XContentIdentifierFactory.class, oUCB) ; 116 117 String url = util.utils.getFullTestURL("SwXTextEmbeddedObject.sxw") ; 118 String escUrl = "" ; 119 120 // In base URL of a JAR file in content URL all directory 121 // separators ('/') must be replaced with escape symbol '%2F'. 122 int idx = url.indexOf("/") ; 123 int lastIdx = -1 ; 124 while (idx >= 0) { 125 escUrl += url.substring(lastIdx + 1, idx) + "%2F" ; 126 lastIdx = idx ; 127 idx = url.indexOf("/", idx + 1) ; 128 } 129 escUrl += url.substring(lastIdx + 1) ; 130 String cntUrl = "vnd.sun.star.pkg://" + escUrl + "/" ; 131 132 XContentIdentifier CI = ciFac.createContentIdentifier(cntUrl) ; 133 134 XContentProvider cntProv = (XContentProvider) 135 UnoRuntime.queryInterface(XContentProvider.class, oUCB) ; 136 137 XContent cnt = cntProv.queryContent(CI) ; 138 139 XCommandProcessor cmdProc = (XCommandProcessor) 140 UnoRuntime.queryInterface(XCommandProcessor.class, cnt) ; 141 142 Property prop = new Property() ; 143 prop.Name = "Title" ; 144 145 Command cmd = new Command("open", -1, new OpenCommandArgument2 146 (OpenMode.ALL, 10000, null, new Property[] {prop}, 147 new NumberedSortingInfo[0])) ; 148 149 dynResSet = null; 150 try { 151 dynResSet = (XDynamicResultSet) 152 AnyConverter.toObject(new Type(XDynamicResultSet.class), 153 cmdProc.execute(cmd, 0, null)); 154 } catch (com.sun.star.lang.IllegalArgumentException iae) { 155 throw new StatusException("Couldn't convert Any ",iae); 156 } 157 158 } catch (com.sun.star.uno.Exception e) { 159 log.println("Can't create relation." ); 160 e.printStackTrace(log) ; 161 throw new StatusException( "Can't create relation", e ); 162 } 163 164 tEnv.addObjRelation("DynamicResultSet", dynResSet) ; 165 166 return tEnv; 167 } // finish method getTestEnvironment 168 169 } 170