1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 package ifc.document; 28 29 import com.sun.star.beans.PropertyValue; 30 import com.sun.star.container.XIndexAccess; 31 import com.sun.star.container.XIndexContainer; 32 import com.sun.star.document.XViewDataSupplier; 33 import com.sun.star.uno.UnoRuntime; 34 import lib.MultiMethodTest; 35 import lib.Status; 36 37 /** 38 * Check the XViewDataSupplier interface. 39 * Test idea: take the property values from the index access, change one 40 * property value, put this into the index access and write it back. 41 * Get the property value again and check that the change made it. 42 */ 43 public class _XViewDataSupplier extends MultiMethodTest { 44 public XViewDataSupplier oObj = null; 45 XIndexAccess xAccess = null; 46 PropertyValue[] newProps = null; 47 PropertyValue[] oldProps = null; 48 String myview = "myview1"; 49 50 public void _getViewData() { 51 xAccess = oObj.getViewData(); 52 // util.dbg.printInterfaces(xAccess); 53 if (xAccess != null) { 54 setViewID(xAccess, myview); 55 } 56 tRes.tested("getViewData()", true); 57 } 58 59 public void _setViewData() { 60 if (xAccess == null) { 61 log.println("No view data to change available"); 62 tRes.tested("setViewData()", Status.skipped(true)); 63 } 64 else { 65 // 2do: provide an own implementation of the XIndexAccess to set. 66 // this will work without "setViewData()", it just checks that a 67 // setViewData can be done. 68 oObj.setViewData(xAccess); 69 XIndexAccess xAccess2 = oObj.getViewData(); 70 String newView = getViewID(xAccess2); 71 tRes.tested("setViewData()", newView.equals(myview)); 72 } 73 } 74 75 private void setViewID(XIndexAccess xAccess, String value) { 76 XIndexContainer xIndexContainer = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class, xAccess); 77 int count = xAccess.getCount(); 78 try { 79 if (count > 0) { 80 oldProps = (PropertyValue[])xAccess.getByIndex(0); 81 newProps = new PropertyValue[oldProps.length]; 82 for (int j=0; j<oldProps.length; j++) { 83 // log.println("Name: " + oldProps[j].Name); 84 // log.println("Value: " + oldProps[j].Value.toString()); 85 newProps[j] = new PropertyValue(); 86 newProps[j].Name = oldProps[j].Name; 87 newProps[j].Handle = oldProps[j].Handle; 88 newProps[j].State = oldProps[j].State; 89 if (oldProps[j].Name.equals("ViewId")) { 90 newProps[j].Value = value; 91 } 92 93 } 94 xIndexContainer.insertByIndex(0, newProps); 95 } 96 } 97 catch(Exception e) { 98 e.printStackTrace((java.io.PrintWriter)log); 99 } 100 } 101 102 private String getViewID(XIndexAccess xAccess) { 103 String retValue = null; 104 int count = xAccess.getCount(); 105 try { 106 if (count > 0) { 107 oldProps = (PropertyValue[])xAccess.getByIndex(0); 108 for (int j=0; j<oldProps.length; j++) { 109 // log.println("Name: " + oldProps[j].Name); 110 // log.println("Value: " + oldProps[j].Value.toString()); 111 if (oldProps[j].Name.equals("ViewId")) { 112 retValue = (String)newProps[j].Value; 113 } 114 115 } 116 } 117 } 118 catch(Exception e) { 119 e.printStackTrace((java.io.PrintWriter)log); 120 } 121 return retValue; 122 } 123 } 124