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
.XCommandProcessor
;
29 import com
.sun
.star
.ucb
.XContent
;
30 import com
.sun
.star
.ucb
.XContentIdentifier
;
31 import com
.sun
.star
.ucb
.XContentIdentifierFactory
;
32 import com
.sun
.star
.ucb
.XContentProvider
;
33 import com
.sun
.star
.ucb
.XDynamicResultSet
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
36 import com
.sun
.star
.uno
.Type
;
37 import com
.sun
.star
.uno
.AnyConverter
;
38 import java
.io
.PrintWriter
;
39 import lib
.StatusException
;
41 import lib
.TestEnvironment
;
42 import lib
.TestParameters
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.ucb.CachedContentResultSetStubFactory</code>. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::ucb::XCachedContentResultSetStubFactory</code></li>
51 * This object test <b> is NOT </b> designed to be run in several
52 * threads concurently.
53 * @see com.sun.star.ucb.XCachedContentResultSetStubFactory
54 * @see com.sun.star.ucb.CachedContentResultSetStubFactory
55 * @see ifc.ucb._XCachedContentResultSetStubFactory
57 public class CachedContentResultSetStubFactory
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.CachedContentResultSetStubFactory</code>. <p>
63 * Object relations created :
65 * <li> <code>'ContentResultSet'</code> for
66 * {@link ifc.ucb._XCachedContentResultSetStubFactory} : the destination
67 * interface requires as its parameter an instance of
68 * <code>ContentResultSet</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. It represents
73 * <code>ContentResultSet</code> service instance required.
78 public TestEnvironment
createTestEnvironment( TestParameters Param
,
80 throws StatusException
{
81 XInterface oObj
= null;
82 Object oInterface
= null;
83 XMultiServiceFactory xMSF
= Param
.getMSF();
85 oInterface
= xMSF
.createInstance
86 ( "com.sun.star.ucb.CachedContentResultSetStubFactory" );
88 // adding one child container
90 catch( com
.sun
.star
.uno
.Exception e
) {
91 log
.println("Can't create an object." );
92 throw new StatusException( "Can't create an object", e
);
95 oObj
= (XInterface
) oInterface
;
97 TestEnvironment tEnv
= new TestEnvironment( oObj
);
99 // creating relation for XCachedContentResultSetStubFactory
100 XResultSet resSet
= null ;
102 Object oUCB
= xMSF
.createInstanceWithArguments
103 ("com.sun.star.ucb.UniversalContentBroker",
106 XContentIdentifierFactory ciFac
= UnoRuntime
.queryInterface(XContentIdentifierFactory
.class, oUCB
) ;
108 String url
= util
.utils
.getFullTestURL("SwXTextEmbeddedObject.sxw") ;
111 // In base URL of a JAR file in content URL all directory
112 // separators ('/') must be replaced with escape symbol '%2F'.
113 int idx
= url
.indexOf("/") ;
116 escUrl
+= url
.substring(lastIdx
+ 1, idx
) + "%2F" ;
118 idx
= url
.indexOf("/", idx
+ 1) ;
120 escUrl
+= url
.substring(lastIdx
+ 1) ;
121 String cntUrl
= "vnd.sun.star.pkg://" + escUrl
+ "/" ;
122 log
.println("Getting Content of '" + cntUrl
+ "'") ;
124 XContentIdentifier CI
= ciFac
.createContentIdentifier(cntUrl
) ;
126 XContentProvider cntProv
= UnoRuntime
.queryInterface(XContentProvider
.class, oUCB
) ;
128 XContent cnt
= cntProv
.queryContent(CI
) ;
130 XCommandProcessor cmdProc
= UnoRuntime
.queryInterface(XCommandProcessor
.class, cnt
) ;
132 Property prop
= new Property() ;
133 prop
.Name
= "Title" ;
135 Command cmd
= new Command("open", -1, new OpenCommandArgument2
136 (OpenMode
.ALL
, 10000, null, new Property
[] {prop
},
137 new NumberedSortingInfo
[0])) ;
139 XDynamicResultSet dynResSet
= null;
141 dynResSet
= (XDynamicResultSet
)
142 AnyConverter
.toObject(new Type(XDynamicResultSet
.class),
143 cmdProc
.execute(cmd
, 0, null));
144 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
145 throw new StatusException("Couldn't convert Any ",iae
);
148 resSet
= dynResSet
.getStaticResultSet() ;
150 } catch (com
.sun
.star
.uno
.Exception e
) {
151 log
.println("Can't create relation." );
152 e
.printStackTrace(log
) ;
153 throw new StatusException( "Can't create relation", e
);
156 tEnv
.addObjRelation("ContentResultSet", resSet
) ;
159 } // finish method getTestEnvironment