Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / mod / _cached / CachedContentResultSetStubFactory.java
blob50217e8928c657549028e2b047631dcc66ab4aa6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CachedContentResultSetStubFactory.java,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod._cached;
33 import com.sun.star.beans.Property;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.sdbc.XResultSet;
36 import com.sun.star.ucb.Command;
37 import com.sun.star.ucb.NumberedSortingInfo;
38 import com.sun.star.ucb.OpenCommandArgument2;
39 import com.sun.star.ucb.OpenMode;
40 import com.sun.star.ucb.XCommandProcessor;
41 import com.sun.star.ucb.XContent;
42 import com.sun.star.ucb.XContentIdentifier;
43 import com.sun.star.ucb.XContentIdentifierFactory;
44 import com.sun.star.ucb.XContentProvider;
45 import com.sun.star.ucb.XDynamicResultSet;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 import com.sun.star.uno.Type;
49 import com.sun.star.uno.AnyConverter;
50 import java.io.PrintWriter;
51 import lib.StatusException;
52 import lib.TestCase;
53 import lib.TestEnvironment;
54 import lib.TestParameters;
56 /**
57 * Test for object which is represented by service
58 * <code>com.sun.star.ucb.CachedContentResultSetStubFactory</code>. <p>
59 * Object implements the following interfaces :
60 * <ul>
61 * <li> <code>com::sun::star::ucb::XCachedContentResultSetStubFactory</code></li>
62 * </ul> <p>
63 * This object test <b> is NOT </b> designed to be run in several
64 * threads concurently.
65 * @see com.sun.star.ucb.XCachedContentResultSetStubFactory
66 * @see com.sun.star.ucb.CachedContentResultSetStubFactory
67 * @see ifc.ucb._XCachedContentResultSetStubFactory
69 public class CachedContentResultSetStubFactory extends TestCase {
71 /**
72 * Creating a Testenvironment for the interfaces to be tested.
73 * Creates an instance of the service
74 * <code>com.sun.star.ucb.CachedContentResultSetStubFactory</code>. <p>
75 * Object relations created :
76 * <ul>
77 * <li> <code>'ContentResultSet'</code> for
78 * {@link ifc.XCachedContentResultSetStubFactory} : the destination
79 * interface requires as its parameter an instance of
80 * <code>ContentResultSet</code> service. It is created
81 * using <code>UniversalContentBroker</code> and queriing it for
82 * <code>PackageContent</code> which represents JAR file mentioned
83 * above. Then the dynamic list of file contents (entries) is retrieved,
84 * and a static list is created from it. It represents
85 * <code>ContentResultSet</code> service instance required.
86 * </li>
87 * </ul>
89 public TestEnvironment createTestEnvironment( TestParameters Param,
90 PrintWriter log )
91 throws StatusException {
92 XInterface oObj = null;
93 Object oInterface = null;
94 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF();
95 Object relationContainer = null ;
98 try {
99 oInterface = xMSF.createInstance
100 ( "com.sun.star.ucb.CachedContentResultSetStubFactory" );
102 // adding one child container
104 catch( com.sun.star.uno.Exception e ) {
105 log.println("Can't create an object." );
106 throw new StatusException( "Can't create an object", e );
109 oObj = (XInterface) oInterface;
111 TestEnvironment tEnv = new TestEnvironment( oObj );
113 // creating relation for XCachedContentResultSetStubFactory
114 XResultSet resSet = null ;
115 try {
116 Object oUCB = xMSF.createInstanceWithArguments
117 ("com.sun.star.ucb.UniversalContentBroker",
118 new Object[] {"Local", "Office"}) ;
120 XContentIdentifierFactory ciFac = (XContentIdentifierFactory)
121 UnoRuntime.queryInterface(XContentIdentifierFactory.class, oUCB) ;
123 String url = util.utils.getFullTestURL("SwXTextEmbeddedObject.sxw") ;
124 String escUrl = "" ;
126 // In base URL of a JAR file in content URL all directory
127 // separators ('/') must be replaced with escape symbol '%2F'.
128 int idx = url.indexOf("/") ;
129 int lastIdx = -1 ;
130 while (idx >= 0) {
131 escUrl += url.substring(lastIdx + 1, idx) + "%2F" ;
132 lastIdx = idx ;
133 idx = url.indexOf("/", idx + 1) ;
135 escUrl += url.substring(lastIdx + 1) ;
136 String cntUrl = "vnd.sun.star.pkg://" + escUrl + "/" ;
137 log.println("Getting Content of '" + cntUrl + "'") ;
139 XContentIdentifier CI = ciFac.createContentIdentifier(cntUrl) ;
141 XContentProvider cntProv = (XContentProvider)
142 UnoRuntime.queryInterface(XContentProvider.class, oUCB) ;
144 XContent cnt = cntProv.queryContent(CI) ;
146 XCommandProcessor cmdProc = (XCommandProcessor)
147 UnoRuntime.queryInterface(XCommandProcessor.class, cnt) ;
149 Property prop = new Property() ;
150 prop.Name = "Title" ;
152 Command cmd = new Command("open", -1, new OpenCommandArgument2
153 (OpenMode.ALL, 10000, null, new Property[] {prop},
154 new NumberedSortingInfo[0])) ;
156 XDynamicResultSet dynResSet = null;
157 try {
158 dynResSet = (XDynamicResultSet)
159 AnyConverter.toObject(new Type(XDynamicResultSet.class),
160 cmdProc.execute(cmd, 0, null));
161 } catch (com.sun.star.lang.IllegalArgumentException iae) {
162 throw new StatusException("Couldn't convert Any ",iae);
165 resSet = dynResSet.getStaticResultSet() ;
167 } catch (com.sun.star.uno.Exception e) {
168 log.println("Can't create relation." );
169 e.printStackTrace(log) ;
170 throw new StatusException( "Can't create relation", e );
173 tEnv.addObjRelation("ContentResultSet", resSet) ;
175 return tEnv;
176 } // finish method getTestEnvironment