1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package ifc.document;
24 
25 import com.sun.star.beans.PropertyValue;
26 import com.sun.star.container.XIndexAccess;
27 import com.sun.star.container.XIndexContainer;
28 import com.sun.star.document.XViewDataSupplier;
29 import com.sun.star.uno.UnoRuntime;
30 import lib.MultiMethodTest;
31 import lib.Status;
32 
33 /**
34  * Check the XViewDataSupplier interface.
35  * Test idea: take the property values from the index access, change one
36  * property value, put this into the index access and write it back.
37  * Get the property value again and check that the change made it.
38  */
39 public class _XViewDataSupplier extends MultiMethodTest {
40     public XViewDataSupplier oObj = null;
41     XIndexAccess xAccess = null;
42     PropertyValue[] newProps = null;
43     PropertyValue[] oldProps = null;
44     String myview = "myview1";
45 
_getViewData()46     public void _getViewData() {
47         xAccess = oObj.getViewData();
48 //        util.dbg.printInterfaces(xAccess);
49         if (xAccess != null) {
50             setViewID(xAccess, myview);
51         }
52         tRes.tested("getViewData()", true);
53     }
54 
_setViewData()55     public void _setViewData() {
56         if (xAccess == null) {
57             log.println("No view data to change available");
58             tRes.tested("setViewData()", Status.skipped(true));
59         }
60         else {
61             // 2do: provide an own implementation of the XIndexAccess to set.
62             // this will work without "setViewData()", it just checks that a
63             // setViewData can be done.
64             oObj.setViewData(xAccess);
65             XIndexAccess xAccess2 = oObj.getViewData();
66             String newView = getViewID(xAccess2);
67             tRes.tested("setViewData()", newView.equals(myview));
68         }
69     }
70 
setViewID(XIndexAccess xAccess, String value)71     private void setViewID(XIndexAccess xAccess, String value) {
72         XIndexContainer xIndexContainer = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class, xAccess);
73         int count = xAccess.getCount();
74         try {
75             if (count > 0) {
76                 oldProps = (PropertyValue[])xAccess.getByIndex(0);
77                 newProps = new PropertyValue[oldProps.length];
78                 for (int j=0; j<oldProps.length; j++) {
79 //                    log.println("Name: " + oldProps[j].Name);
80 //                    log.println("Value: " + oldProps[j].Value.toString());
81                     newProps[j] = new PropertyValue();
82                     newProps[j].Name = oldProps[j].Name;
83                     newProps[j].Handle = oldProps[j].Handle;
84                     newProps[j].State = oldProps[j].State;
85                     if (oldProps[j].Name.equals("ViewId")) {
86                         newProps[j].Value = value;
87                     }
88 
89                 }
90                 xIndexContainer.insertByIndex(0, newProps);
91             }
92         }
93         catch(Exception e) {
94             e.printStackTrace((java.io.PrintWriter)log);
95         }
96     }
97 
getViewID(XIndexAccess xAccess)98     private String getViewID(XIndexAccess xAccess) {
99         String retValue = null;
100         int count = xAccess.getCount();
101         try {
102             if (count > 0) {
103                 oldProps = (PropertyValue[])xAccess.getByIndex(0);
104                 for (int j=0; j<oldProps.length; j++) {
105 //                    log.println("Name: " + oldProps[j].Name);
106 //                    log.println("Value: " + oldProps[j].Value.toString());
107                     if (oldProps[j].Name.equals("ViewId")) {
108                         retValue = (String)newProps[j].Value;
109                     }
110 
111                 }
112             }
113         }
114         catch(Exception e) {
115             e.printStackTrace((java.io.PrintWriter)log);
116         }
117         return retValue;
118     }
119 }
120