1*cd519653SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*cd519653SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cd519653SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cd519653SAndrew Rist  * distributed with this work for additional information
6*cd519653SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cd519653SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cd519653SAndrew Rist  * "License"); you may not use this file except in compliance
9*cd519653SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cd519653SAndrew Rist  *
11*cd519653SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cd519653SAndrew Rist  *
13*cd519653SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cd519653SAndrew Rist  * software distributed under the License is distributed on an
15*cd519653SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cd519653SAndrew Rist  * KIND, either express or implied.  See the License for the
17*cd519653SAndrew Rist  * specific language governing permissions and limitations
18*cd519653SAndrew Rist  * under the License.
19*cd519653SAndrew Rist  *
20*cd519653SAndrew Rist  *************************************************************/
21*cd519653SAndrew Rist 
22*cd519653SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package mod._scripting;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.uno.XInterface;
27cdf0e10cSrcweir import java.io.PrintWriter;
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir import lib.TestCase;
30cdf0e10cSrcweir import lib.TestEnvironment;
31cdf0e10cSrcweir import lib.TestParameters;
32cdf0e10cSrcweir import util.utils;
33cdf0e10cSrcweir import java.net.URLEncoder;
34cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
35cdf0e10cSrcweir import com.sun.star.ucb.XSimpleFileAccess;
36cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir import drafts.com.sun.star.script.framework.storage.XScriptInfoAccess;
39cdf0e10cSrcweir import drafts.com.sun.star.script.framework.storage.XScriptInfo;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir public class ScriptInfo extends TestCase {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir     String docPath = null;
initialize( TestParameters tParam, PrintWriter log )44cdf0e10cSrcweir     public void initialize( TestParameters tParam, PrintWriter log ) {
45cdf0e10cSrcweir         // Get path to test documents
46cdf0e10cSrcweir         String rootDocPath = ( String )tParam.get( "DOCPTH" );
47cdf0e10cSrcweir         System.out.println( "DOCPTH is " + rootDocPath );
48cdf0e10cSrcweir         rootDocPath = util.utils.getFullTestURL( "ExampleSpreadSheetLatest.sxc" );
49cdf0e10cSrcweir         if ( rootDocPath != null && rootDocPath.length() > 1 ){
50cdf0e10cSrcweir             // convert all "\\" to "/", necessary for UCB
51cdf0e10cSrcweir             if ( rootDocPath.indexOf( "\\" ) > 0 ){
52cdf0e10cSrcweir                 rootDocPath = rootDocPath.replace( '\\','/' );
53cdf0e10cSrcweir 	    }
54cdf0e10cSrcweir             System.out.println("After processing the path is " + rootDocPath);
55cdf0e10cSrcweir 	    // encode the ulr (for UCB)
56cdf0e10cSrcweir             String encodedPath = URLEncoder.encode( rootDocPath );
57cdf0e10cSrcweir             System.out.println("The encoded path is " + encodedPath );
58cdf0e10cSrcweir             docPath = "vnd.sun.star.pkg://" + encodedPath;
59cdf0e10cSrcweir             System.out.println( "docPath path is " + docPath );
60cdf0e10cSrcweir         }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     }
63cdf0e10cSrcweir 
createTestEnvironment( TestParameters tParam, PrintWriter log )64cdf0e10cSrcweir     public synchronized TestEnvironment createTestEnvironment(
65cdf0e10cSrcweir         TestParameters tParam, PrintWriter log ) throws StatusException {
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	log.println("creating test environment");
68cdf0e10cSrcweir         if ( docPath == null ){
69cdf0e10cSrcweir             log.println("Testdata not set up, docPath is null");
70cdf0e10cSrcweir             throw new StatusException(
71cdf0e10cSrcweir                 "Can't create object environment, no test document available",
72cdf0e10cSrcweir                 new Exception() ) ;
73cdf0e10cSrcweir         }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         XInterface oObj = null;
76cdf0e10cSrcweir         XSimpleFileAccess access = null;
77cdf0e10cSrcweir         try {
78cdf0e10cSrcweir             XMultiServiceFactory xMSF = tParam.getMSF();
79cdf0e10cSrcweir             Object xInterface =
80cdf0e10cSrcweir                 xMSF.createInstance( "com.sun.star.ucb.SimpleFileAccess" );
81cdf0e10cSrcweir             access = ( XSimpleFileAccess )
82cdf0e10cSrcweir                 UnoRuntime.queryInterface( XSimpleFileAccess.class, xInterface );
83cdf0e10cSrcweir             Object storageObj = ( XInterface )xMSF.createInstanceWithArguments(
84cdf0e10cSrcweir                 "drafts.com.sun.star.script.framework.storage.ScriptStorage",
85cdf0e10cSrcweir                 new Object[]{ access, new Integer(99), docPath } );
86cdf0e10cSrcweir             XScriptInfoAccess infoAccess = ( XScriptInfoAccess )UnoRuntime.queryInterface(XScriptInfoAccess.class, storageObj);
87cdf0e10cSrcweir             XScriptInfo[] infos = infoAccess.getImplementations("script://MemoryUtils.MemUsage?location=document");
88cdf0e10cSrcweir            oObj = infos[0];
89cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
90cdf0e10cSrcweir             throw new StatusException("Can't create object environment", e) ;
91cdf0e10cSrcweir         }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         TestEnvironment tEnv = new TestEnvironment(oObj) ;
94cdf0e10cSrcweir         TestDataLoader.setupData(tEnv, "ScriptInfo");
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         return tEnv ;
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
disposeTestEnvironment( TestEnvironment tEnv, TestParameters tParam)99cdf0e10cSrcweir     public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
100cdf0e10cSrcweir             TestParameters tParam) {
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 
105