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