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