2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import com
.sun
.star
.beans
.Property
;
22 import com
.sun
.star
.lang
.XMultiServiceFactory
;
23 import com
.sun
.star
.sdbc
.XResultSet
;
24 import com
.sun
.star
.ucb
.Command
;
25 import com
.sun
.star
.ucb
.NumberedSortingInfo
;
26 import com
.sun
.star
.ucb
.OpenCommandArgument2
;
27 import com
.sun
.star
.ucb
.OpenMode
;
28 import com
.sun
.star
.ucb
.XCachedContentResultSetStubFactory
;
29 import com
.sun
.star
.ucb
.XCommandProcessor
;
30 import com
.sun
.star
.ucb
.XContent
;
31 import com
.sun
.star
.ucb
.XContentIdentifier
;
32 import com
.sun
.star
.ucb
.XContentIdentifierFactory
;
33 import com
.sun
.star
.ucb
.XContentProvider
;
34 import com
.sun
.star
.ucb
.XDynamicResultSet
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
37 import com
.sun
.star
.uno
.Type
;
38 import com
.sun
.star
.uno
.AnyConverter
;
39 import java
.io
.PrintWriter
;
41 import lib
.TestEnvironment
;
42 import lib
.TestParameters
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.ucb.CachedContentResultSetFactory</code>. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::ucb::XCachedContentResultSetFactory</code></li>
51 * This object test <b> is NOT </b> designed to be run in several
52 * threads concurrently.
53 * @see com.sun.star.ucb.XCachedContentResultSetFactory
54 * @see com.sun.star.ucb.CachedContentResultSetFactory
55 * @see ifc.ucb._XCachedContentResultSetFactory
57 public class CachedContentResultSetFactory
extends TestCase
{
60 * Creating a TestEnvironment for the interfaces to be tested.
61 * Creates an instance of the service
62 * <code>com.sun.star.ucb.CachedContentResultSetFactory</code>. <p>
63 * Object relations created :
65 * <li> <code>'CachedContentResultSetStub'</code> for
66 * {@link ifc.ucb._XCachedContentResultSetFactory} : the destination
67 * interface requires as its parameter an instance of
68 * <code>CachedContentResultSetStub</code> service. It is created
69 * using <code>UniversalContentBroker</code> and querying it for
70 * <code>PackageContent</code> which represents JAR file mentioned
71 * above. Then the dynamic list of file contents (entries) is retrieved,
72 * and a static list is created from it. Using
73 * <code>CachedContentResultSetStubFactory</code> service a stub of
74 * Cached result set is created which is relation required.
79 public TestEnvironment
createTestEnvironment( TestParameters Param
,
82 XMultiServiceFactory xMSF
= Param
.getMSF();
83 Object oInterface
= xMSF
.createInstance
84 ( "com.sun.star.ucb.CachedContentResultSetFactory" );
85 XInterface oObj
= (XInterface
) oInterface
;
87 TestEnvironment tEnv
= new TestEnvironment( oObj
);
89 // creating relation for XCachedContentResultSetFactory
90 XResultSet resSetStub
= null ;
91 Object oUCB
= xMSF
.createInstanceWithArguments
92 ("com.sun.star.ucb.UniversalContentBroker",
95 XContentIdentifierFactory ciFac
= UnoRuntime
.queryInterface(XContentIdentifierFactory
.class, oUCB
) ;
97 String url
= util
.utils
.getFullTestURL("SwXTextEmbeddedObject.sxw") ;
98 StringBuilder escUrl
= new StringBuilder();
100 // In base URL of a JAR file in content URL all directory
101 // separators ('/') must be replaced with escape symbol '%2F'.
102 int idx
= url
.indexOf("/") ;
105 escUrl
.append(url
.substring(lastIdx
+ 1, idx
)).append("%2F");
107 idx
= url
.indexOf("/", idx
+ 1) ;
109 escUrl
.append(url
.substring(lastIdx
+ 1));
110 String cntUrl
= "vnd.sun.star.pkg://" + escUrl
.toString() + "/" ;
112 XContentIdentifier CI
= ciFac
.createContentIdentifier(cntUrl
) ;
114 XContentProvider cntProv
= UnoRuntime
.queryInterface(XContentProvider
.class, oUCB
) ;
116 XContent cnt
= cntProv
.queryContent(CI
) ;
118 XCommandProcessor cmdProc
= UnoRuntime
.queryInterface(XCommandProcessor
.class, cnt
) ;
120 Property prop
= new Property() ;
121 prop
.Name
= "Title" ;
123 Command cmd
= new Command("open", -1, new OpenCommandArgument2
124 (OpenMode
.ALL
, 10000, null, new Property
[] {prop
},
125 new NumberedSortingInfo
[0])) ;
127 XDynamicResultSet dynResSet
= (XDynamicResultSet
)
128 AnyConverter
.toObject(new Type(XDynamicResultSet
.class),
129 cmdProc
.execute(cmd
, 0, null));
131 XResultSet resSet
= dynResSet
.getStaticResultSet() ;
133 Object oStubFactory
= xMSF
.createInstance
134 ("com.sun.star.ucb.CachedContentResultSetStubFactory") ;
136 XCachedContentResultSetStubFactory xStubFactory
=
137 UnoRuntime
.queryInterface
138 (XCachedContentResultSetStubFactory
.class, oStubFactory
) ;
140 resSetStub
= xStubFactory
.createCachedContentResultSetStub(resSet
) ;
142 tEnv
.addObjRelation("CachedContentResultSetStub", resSetStub
) ;
145 } // finish method getTestEnvironment