1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._cached; 25 26 import com.sun.star.beans.Property; 27 import com.sun.star.lang.XMultiServiceFactory; 28 import com.sun.star.ucb.Command; 29 import com.sun.star.ucb.NumberedSortingInfo; 30 import com.sun.star.ucb.OpenCommandArgument2; 31 import com.sun.star.ucb.OpenMode; 32 import com.sun.star.ucb.XCommandProcessor; 33 import com.sun.star.ucb.XContent; 34 import com.sun.star.ucb.XContentIdentifier; 35 import com.sun.star.ucb.XContentIdentifierFactory; 36 import com.sun.star.ucb.XContentProvider; 37 import com.sun.star.ucb.XDynamicResultSet; 38 import com.sun.star.uno.UnoRuntime; 39 import com.sun.star.uno.XInterface; 40 import com.sun.star.uno.Type; 41 import com.sun.star.uno.AnyConverter; 42 import java.io.PrintWriter; 43 import lib.StatusException; 44 import lib.TestCase; 45 import lib.TestEnvironment; 46 import lib.TestParameters; 47 48 /** 49 * Test for object which is represented by service 50 * <code>com.sun.star.ucb.CachedDynamicResultSetStubFactory</code>. <p> 51 * Object implements the following interfaces : 52 * <ul> 53 * <li> <code>com::sun::star::ucb::XCachedDynamicResultSetStubFactory</code></li> 54 * </ul> <p> 55 * This object test <b> is NOT </b> designed to be run in several 56 * threads concurently. 57 * @see com.sun.star.ucb.XCachedDynamicResultSetStubFactory 58 * @see com.sun.star.ucb.CachedDynamicResultSetStubFactory 59 * @see ifc.ucb._XCachedDynamicResultSetStubFactory 60 */ 61 public class CachedDynamicResultSetStubFactory extends TestCase { 62 63 /** 64 * Creating a TestEnvironment for the interfaces to be tested. 65 * Creates an instance of the service 66 * <code>com.sun.star.ucb.CachedDynamicResultSetStubFactory</code>. <p> 67 * Object relations created : 68 * <ul> 69 * <li> <code>'DynamicResultSet'</code> for 70 * {@link ifc.ucb._XCachedDynamicResultSetStubFactory} : the destination 71 * interface requires as its parameter an instance of 72 * <code>DynamicResultSet</code> service. It is created 73 * using <code>UniversalContentBroker</code> and querying it for 74 * <code>PackageContent</code> which represents JAR file mentioned 75 * above. Then the dynamic list of file contents (entries) is retrieved. 76 * </li> 77 * </ul> 78 */ createTestEnvironment( TestParameters Param, PrintWriter log )79 public TestEnvironment createTestEnvironment( TestParameters Param, 80 PrintWriter log ) 81 throws StatusException { 82 XInterface oObj = null; 83 Object oInterface = null; 84 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF(); 85 Object relationContainer = null ; 86 87 88 try { 89 oInterface = xMSF.createInstance 90 ( "com.sun.star.ucb.CachedDynamicResultSetStubFactory" ); 91 92 // adding one child container 93 } 94 catch( com.sun.star.uno.Exception e ) { 95 log.println("Can't create an object." ); 96 throw new StatusException( "Can't create an object", e ); 97 } 98 99 oObj = (XInterface) oInterface; 100 101 TestEnvironment tEnv = new TestEnvironment( oObj ); 102 103 // creating relation for XCachedDynamicResultSetStubFactory 104 XDynamicResultSet dynResSet = null ; 105 try { 106 Object oUCB = xMSF.createInstanceWithArguments 107 ("com.sun.star.ucb.UniversalContentBroker", 108 new Object[] {"Local", "Office"}) ; 109 110 XContentIdentifierFactory ciFac = (XContentIdentifierFactory) 111 UnoRuntime.queryInterface(XContentIdentifierFactory.class, oUCB) ; 112 113 String url = util.utils.getFullTestURL("SwXTextEmbeddedObject.sxw") ; 114 String escUrl = "" ; 115 116 // In base URL of a JAR file in content URL all directory 117 // separators ('/') must be replaced with escape symbol '%2F'. 118 int idx = url.indexOf("/") ; 119 int lastIdx = -1 ; 120 while (idx >= 0) { 121 escUrl += url.substring(lastIdx + 1, idx) + "%2F" ; 122 lastIdx = idx ; 123 idx = url.indexOf("/", idx + 1) ; 124 } 125 escUrl += url.substring(lastIdx + 1) ; 126 String cntUrl = "vnd.sun.star.pkg://" + escUrl + "/" ; 127 128 XContentIdentifier CI = ciFac.createContentIdentifier(cntUrl) ; 129 130 XContentProvider cntProv = (XContentProvider) 131 UnoRuntime.queryInterface(XContentProvider.class, oUCB) ; 132 133 XContent cnt = cntProv.queryContent(CI) ; 134 135 XCommandProcessor cmdProc = (XCommandProcessor) 136 UnoRuntime.queryInterface(XCommandProcessor.class, cnt) ; 137 138 Property prop = new Property() ; 139 prop.Name = "Title" ; 140 141 Command cmd = new Command("open", -1, new OpenCommandArgument2 142 (OpenMode.ALL, 10000, null, new Property[] {prop}, 143 new NumberedSortingInfo[0])) ; 144 145 dynResSet = null; 146 try { 147 dynResSet = (XDynamicResultSet) 148 AnyConverter.toObject(new Type(XDynamicResultSet.class), 149 cmdProc.execute(cmd, 0, null)); 150 } catch (com.sun.star.lang.IllegalArgumentException iae) { 151 throw new StatusException("Couldn't convert Any ",iae); 152 } 153 154 } catch (com.sun.star.uno.Exception e) { 155 log.println("Can't create relation." ); 156 e.printStackTrace(log) ; 157 throw new StatusException( "Can't create relation", e ); 158 } 159 160 tEnv.addObjRelation("DynamicResultSet", dynResSet) ; 161 162 return tEnv; 163 } // finish method getTestEnvironment 164 165 } 166