1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10ef39d40dSAndrew Rist * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12ef39d40dSAndrew Rist * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19ef39d40dSAndrew Rist * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir package util; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import java.util.Hashtable; 26cdf0e10cSrcweir // access the implementations via names 27cdf0e10cSrcweir import com.sun.star.uno.XInterface; 28cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 29cdf0e10cSrcweir 30cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 31cdf0e10cSrcweir // staroffice interfaces to provide desktop and componentloader 32cdf0e10cSrcweir // and components i.e. spreadsheets, writerdocs etc. 33cdf0e10cSrcweir import com.sun.star.frame.XDesktop; 34cdf0e10cSrcweir import com.sun.star.frame.XComponentLoader; 35cdf0e10cSrcweir import com.sun.star.lang.XComponent; 36cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 37cdf0e10cSrcweir 38cdf0e10cSrcweir // name - value pair 39cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 40cdf0e10cSrcweir import com.sun.star.beans.PropertyState; 41cdf0e10cSrcweir 42cdf0e10cSrcweir // additional classes required for testcase 43cdf0e10cSrcweir import com.sun.star.sheet.*; 44cdf0e10cSrcweir import com.sun.star.text.*; 45cdf0e10cSrcweir import com.sun.star.container.*; 46cdf0e10cSrcweir import com.sun.star.chart.*; 47cdf0e10cSrcweir import com.sun.star.drawing.*; 48cdf0e10cSrcweir import com.sun.star.awt.*; 49cdf0e10cSrcweir 50cdf0e10cSrcweir public class SOfficeFactory { 51cdf0e10cSrcweir 52cdf0e10cSrcweir private static Hashtable lookup = new Hashtable(10); 53cdf0e10cSrcweir protected XComponentLoader oCLoader; 54cdf0e10cSrcweir SOfficeFactory(XMultiServiceFactory xMSF)55cdf0e10cSrcweir private SOfficeFactory(XMultiServiceFactory xMSF) { 56cdf0e10cSrcweir // get XInterface of Desktop service 57cdf0e10cSrcweir Object oInterface; 58cdf0e10cSrcweir try { 59cdf0e10cSrcweir oInterface = xMSF.createInstance("com.sun.star.frame.Desktop"); 60cdf0e10cSrcweir } catch (com.sun.star.uno.Exception e) { 61cdf0e10cSrcweir throw new IllegalArgumentException( 62cdf0e10cSrcweir "Desktop Service not available"); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir // query the desktop interface and then it's componentloader 66cdf0e10cSrcweir XDesktop oDesktop = (XDesktop) UnoRuntime.queryInterface( 67cdf0e10cSrcweir XDesktop.class, oInterface); 68cdf0e10cSrcweir 69cdf0e10cSrcweir oCLoader = (XComponentLoader) UnoRuntime.queryInterface( 70cdf0e10cSrcweir XComponentLoader.class, oDesktop); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir getFactory(XMultiServiceFactory xMSF)73cdf0e10cSrcweir public static SOfficeFactory getFactory(XMultiServiceFactory xMSF) { 74cdf0e10cSrcweir 75cdf0e10cSrcweir SOfficeFactory soFactory = (SOfficeFactory) lookup.get(new Integer(xMSF.hashCode()).toString()); 76cdf0e10cSrcweir 77cdf0e10cSrcweir if (soFactory == null) { 78cdf0e10cSrcweir soFactory = new SOfficeFactory(xMSF); 79cdf0e10cSrcweir lookup.put(new Integer(xMSF.hashCode()).toString(), soFactory); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir return soFactory; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir // ********************************************************* 86cdf0e10cSrcweir // Document creation. The documents needed are created here. 87cdf0e10cSrcweir // ********************************************************* 88cdf0e10cSrcweir /** 89cdf0e10cSrcweir * method which opens a new TextDocument 90cdf0e10cSrcweir * 91cdf0e10cSrcweir * @see XTextDocument 92cdf0e10cSrcweir */ createTextDoc(String frameName)93cdf0e10cSrcweir public XTextDocument createTextDoc(String frameName) 94cdf0e10cSrcweir throws com.sun.star.uno.Exception { 95cdf0e10cSrcweir 96cdf0e10cSrcweir XComponent oDoc = openDoc("swriter", frameName); 97cdf0e10cSrcweir 98cdf0e10cSrcweir if (oDoc != null) { 99cdf0e10cSrcweir DesktopTools.bringWindowToFront(oDoc); 100cdf0e10cSrcweir return (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, oDoc); 101cdf0e10cSrcweir } else { 102cdf0e10cSrcweir return null; 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir } // finished createTextDoc 106cdf0e10cSrcweir 107cdf0e10cSrcweir /** 108cdf0e10cSrcweir * method which opens a new TextDocument 109cdf0e10cSrcweir * 110cdf0e10cSrcweir * @see XTextDocument 111cdf0e10cSrcweir */ createTextDoc(String frameName, PropertyValue[] mediaDescriptor)112cdf0e10cSrcweir public XTextDocument createTextDoc(String frameName, PropertyValue[] mediaDescriptor) 113cdf0e10cSrcweir throws com.sun.star.uno.Exception { 114cdf0e10cSrcweir 115cdf0e10cSrcweir XComponent oDoc = openDoc("swriter", frameName, mediaDescriptor); 116cdf0e10cSrcweir 117cdf0e10cSrcweir if (oDoc != null) { 118cdf0e10cSrcweir DesktopTools.bringWindowToFront(oDoc); 119cdf0e10cSrcweir return (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, oDoc); 120cdf0e10cSrcweir } else { 121cdf0e10cSrcweir return null; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir } // finished createTextDoc 124cdf0e10cSrcweir 125cdf0e10cSrcweir /** 126cdf0e10cSrcweir * method which opens a new SpreadsheetDocument 127cdf0e10cSrcweir * 128cdf0e10cSrcweir * @see XSpreadsheetDocument 129cdf0e10cSrcweir */ createCalcDoc(String frameName)130cdf0e10cSrcweir public XSpreadsheetDocument createCalcDoc(String frameName) 131cdf0e10cSrcweir throws com.sun.star.uno.Exception { 132cdf0e10cSrcweir 133cdf0e10cSrcweir XComponent oDoc = openDoc("scalc", frameName); 134cdf0e10cSrcweir 135cdf0e10cSrcweir if (oDoc != null) { 136cdf0e10cSrcweir DesktopTools.bringWindowToFront(oDoc); 137cdf0e10cSrcweir return (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, oDoc); 138cdf0e10cSrcweir } else { 139cdf0e10cSrcweir return null; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir } // finished createCalcDoc 142cdf0e10cSrcweir 143cdf0e10cSrcweir /** 144cdf0e10cSrcweir * method which opens a new SpreadsheetDocument 145cdf0e10cSrcweir * 146cdf0e10cSrcweir * @see XSpreadsheetDocument 147cdf0e10cSrcweir */ createCalcDoc(String frameName, PropertyValue[] mediaDescriptor)148cdf0e10cSrcweir public XSpreadsheetDocument createCalcDoc(String frameName, PropertyValue[] mediaDescriptor) 149cdf0e10cSrcweir throws com.sun.star.uno.Exception { 150cdf0e10cSrcweir 151cdf0e10cSrcweir XComponent oDoc = openDoc("scalc", frameName, mediaDescriptor); 152cdf0e10cSrcweir 153cdf0e10cSrcweir if (oDoc != null) { 154cdf0e10cSrcweir DesktopTools.bringWindowToFront(oDoc); 155cdf0e10cSrcweir return (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, oDoc); 156cdf0e10cSrcweir } else { 157cdf0e10cSrcweir return null; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir } // finished createCalcDoc 160cdf0e10cSrcweir 161cdf0e10cSrcweir /** 162cdf0e10cSrcweir * method which opens a new DrawDocument 163cdf0e10cSrcweir */ createDrawDoc(String frameName)164cdf0e10cSrcweir public XComponent createDrawDoc(String frameName) 165cdf0e10cSrcweir throws com.sun.star.uno.Exception { 166cdf0e10cSrcweir 167cdf0e10cSrcweir return openDoc("sdraw", frameName); 168cdf0e10cSrcweir } // finished createDrawDoc 169cdf0e10cSrcweir 170cdf0e10cSrcweir /** 171cdf0e10cSrcweir * method which opens a new ImpressDocument 172cdf0e10cSrcweir */ 173cdf0e10cSrcweir /** 174cdf0e10cSrcweir * method which opens a new DrawDocument 175cdf0e10cSrcweir */ createDrawDoc(String frameName, PropertyValue[] mediaDescriptor)176cdf0e10cSrcweir public XComponent createDrawDoc(String frameName, PropertyValue[] mediaDescriptor) 177cdf0e10cSrcweir throws com.sun.star.uno.Exception { 178cdf0e10cSrcweir 179cdf0e10cSrcweir return openDoc("sdraw", frameName, mediaDescriptor); 180cdf0e10cSrcweir } // finished createDrawDoc 181cdf0e10cSrcweir 182cdf0e10cSrcweir /** 183cdf0e10cSrcweir * method which opens a new ImpressDocument 184cdf0e10cSrcweir */ createImpressDoc(String frameName)185cdf0e10cSrcweir public XComponent createImpressDoc(String frameName) 186cdf0e10cSrcweir throws com.sun.star.uno.Exception { 187cdf0e10cSrcweir 188cdf0e10cSrcweir return openDoc("simpress", frameName); 189cdf0e10cSrcweir } // finished createImpressDoc 190cdf0e10cSrcweir 191cdf0e10cSrcweir /** 192cdf0e10cSrcweir * method which opens a new ImpressDocument 193cdf0e10cSrcweir */ createImpressDoc(String frameName, PropertyValue[] mediaDescriptor)194cdf0e10cSrcweir public XComponent createImpressDoc(String frameName, PropertyValue[] mediaDescriptor) 195cdf0e10cSrcweir throws com.sun.star.uno.Exception { 196cdf0e10cSrcweir 197cdf0e10cSrcweir return openDoc("simpress", frameName, mediaDescriptor); 198cdf0e10cSrcweir } // finished createImpressDoc 199cdf0e10cSrcweir 200cdf0e10cSrcweir /** 201cdf0e10cSrcweir * method which opens a new MathDocument 202cdf0e10cSrcweir */ createMathDoc(String frameName)203cdf0e10cSrcweir public XComponent createMathDoc(String frameName) 204cdf0e10cSrcweir throws com.sun.star.uno.Exception { 205cdf0e10cSrcweir 206cdf0e10cSrcweir return openDoc("smath", frameName); 207cdf0e10cSrcweir } // finished createMathDoc 208cdf0e10cSrcweir 209cdf0e10cSrcweir /** 210cdf0e10cSrcweir * method which opens a new MathDocument 211cdf0e10cSrcweir */ createMathDoc(String frameName, PropertyValue[] mediaDescriptor)212cdf0e10cSrcweir public XComponent createMathDoc(String frameName, PropertyValue[] mediaDescriptor) 213cdf0e10cSrcweir throws com.sun.star.uno.Exception { 214cdf0e10cSrcweir 215cdf0e10cSrcweir return openDoc("smath", frameName, mediaDescriptor); 216cdf0e10cSrcweir } // finished createMathDoc 217cdf0e10cSrcweir 218cdf0e10cSrcweir /** 219cdf0e10cSrcweir * method which opens a new ChartDocument 220cdf0e10cSrcweir * 221cdf0e10cSrcweir * @see XChartDocument 222cdf0e10cSrcweir */ createChartDoc(String frameName)223cdf0e10cSrcweir public XChartDocument createChartDoc(String frameName) 224cdf0e10cSrcweir throws com.sun.star.uno.Exception { 225cdf0e10cSrcweir 226cdf0e10cSrcweir // XComponent oDoc = loadDocument( 227cdf0e10cSrcweir // util.utils.getFullTestURL("emptyChart.sds")); 228cdf0e10cSrcweir 229cdf0e10cSrcweir XComponent oDoc = loadDocument("private:factory/schart"); 230cdf0e10cSrcweir 231cdf0e10cSrcweir if (oDoc != null) { 232cdf0e10cSrcweir DesktopTools.bringWindowToFront(oDoc); 233cdf0e10cSrcweir return (XChartDocument) UnoRuntime.queryInterface(XChartDocument.class, oDoc); 234cdf0e10cSrcweir } else { 235cdf0e10cSrcweir return null; 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir } // finished createChartDoc 239cdf0e10cSrcweir 240cdf0e10cSrcweir /** 241cdf0e10cSrcweir * creates a simple TextTable defaultet to 2 rows and 2 columns 242cdf0e10cSrcweir */ createTextTable(XTextDocument xTextDoc)243cdf0e10cSrcweir public static XTextTable createTextTable(XTextDocument xTextDoc) 244cdf0e10cSrcweir throws com.sun.star.uno.Exception { 245cdf0e10cSrcweir 246cdf0e10cSrcweir TableDsc tDsc = new TableDsc(); 247cdf0e10cSrcweir InstCreator instCreate = new InstCreator(xTextDoc, tDsc); 248cdf0e10cSrcweir 249cdf0e10cSrcweir XTextTable oTable = (XTextTable) instCreate.getInstance(); 250cdf0e10cSrcweir return oTable; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir /** 254cdf0e10cSrcweir * creates a TextTable with a specified count of rows and columns 255cdf0e10cSrcweir */ createTextTable(XTextDocument xTextDoc, int rows, int columns)256cdf0e10cSrcweir public static XTextTable createTextTable(XTextDocument xTextDoc, 257cdf0e10cSrcweir int rows, int columns) 258cdf0e10cSrcweir throws com.sun.star.uno.Exception { 259cdf0e10cSrcweir 260cdf0e10cSrcweir TableDsc tDsc = new TableDsc(rows, columns); 261cdf0e10cSrcweir InstCreator instCreate = new InstCreator(xTextDoc, tDsc); 262cdf0e10cSrcweir 263cdf0e10cSrcweir XTextTable oTable = (XTextTable) instCreate.getInstance(); 264cdf0e10cSrcweir return oTable; 265cdf0e10cSrcweir } 266cdf0e10cSrcweir 267cdf0e10cSrcweir /** 268cdf0e10cSrcweir * creates a simple TextFrame 269cdf0e10cSrcweir * ... to be continued 270cdf0e10cSrcweir */ createTextFrame(XTextDocument xTextDoc)271cdf0e10cSrcweir public static XTextFrame createTextFrame(XTextDocument xTextDoc) 272cdf0e10cSrcweir throws com.sun.star.uno.Exception { 273cdf0e10cSrcweir 274cdf0e10cSrcweir FrameDsc tDsc = new FrameDsc(); 275cdf0e10cSrcweir InstCreator instCreate = new InstCreator(xTextDoc, tDsc); 276cdf0e10cSrcweir 277cdf0e10cSrcweir XTextFrame oFrame = (XTextFrame) instCreate.getInstance(); 278cdf0e10cSrcweir return oFrame; 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir /** 282cdf0e10cSrcweir * creates a simple TextFrame 283cdf0e10cSrcweir * ... to be continued 284cdf0e10cSrcweir */ createTextFrame(XTextDocument xTextDoc, int height, int width)285cdf0e10cSrcweir public static XTextFrame createTextFrame(XTextDocument xTextDoc, 286cdf0e10cSrcweir int height, int width) { 287cdf0e10cSrcweir 288cdf0e10cSrcweir FrameDsc tDsc = new FrameDsc(height, width); 289cdf0e10cSrcweir InstCreator instCreate = new InstCreator(xTextDoc, tDsc); 290cdf0e10cSrcweir 291cdf0e10cSrcweir XTextFrame oFrame = (XTextFrame) instCreate.getInstance(); 292cdf0e10cSrcweir return oFrame; 293cdf0e10cSrcweir } 294cdf0e10cSrcweir insertString(XTextDocument xTextDoc, String cString)295cdf0e10cSrcweir public static void insertString(XTextDocument xTextDoc, String cString) 296cdf0e10cSrcweir throws com.sun.star.uno.Exception { 297cdf0e10cSrcweir XText xText = xTextDoc.getText(); 298cdf0e10cSrcweir XText oText = (XText) UnoRuntime.queryInterface( 299cdf0e10cSrcweir XText.class, xText); 300cdf0e10cSrcweir 301cdf0e10cSrcweir XTextCursor oCursor = oText.createTextCursor(); 302cdf0e10cSrcweir oText.insertString(oCursor, cString, false); 303cdf0e10cSrcweir } 304cdf0e10cSrcweir insertTextContent(XTextDocument xTextDoc, XTextContent xCont)305cdf0e10cSrcweir public static void insertTextContent(XTextDocument xTextDoc, 306cdf0e10cSrcweir XTextContent xCont) 307cdf0e10cSrcweir throws com.sun.star.lang.IllegalArgumentException { 308cdf0e10cSrcweir XText xText = xTextDoc.getText(); 309cdf0e10cSrcweir XText oText = (XText) UnoRuntime.queryInterface( 310cdf0e10cSrcweir XText.class, xText); 311cdf0e10cSrcweir 312cdf0e10cSrcweir XTextCursor oCursor = oText.createTextCursor(); 313cdf0e10cSrcweir oText.insertTextContent(oCursor, xCont, false); 314cdf0e10cSrcweir } 315cdf0e10cSrcweir getFirstTableCell( XTextContent oTable)316cdf0e10cSrcweir public static com.sun.star.table.XCell getFirstTableCell( 317cdf0e10cSrcweir XTextContent oTable) { 318cdf0e10cSrcweir 319cdf0e10cSrcweir String CellNames[] = ((XTextTable) oTable).getCellNames(); 320cdf0e10cSrcweir 321cdf0e10cSrcweir com.sun.star.table.XCell oCell = ((XTextTable) oTable).getCellByName( 322cdf0e10cSrcweir CellNames[0]); 323cdf0e10cSrcweir return oCell; 324cdf0e10cSrcweir 325cdf0e10cSrcweir } 326cdf0e10cSrcweir 327cdf0e10cSrcweir /** 328cdf0e10cSrcweir * the method createBookmark 329cdf0e10cSrcweir */ createBookmark(XTextDocument xTextDoc)330cdf0e10cSrcweir public static XTextContent createBookmark(XTextDocument xTextDoc) 331cdf0e10cSrcweir throws com.sun.star.uno.Exception { 332cdf0e10cSrcweir 333cdf0e10cSrcweir BookmarkDsc tDsc = new BookmarkDsc(); 334cdf0e10cSrcweir InstCreator instCreate = new InstCreator(xTextDoc, tDsc); 335cdf0e10cSrcweir 336cdf0e10cSrcweir XTextContent oBookmark = (XTextContent) instCreate.getInstance(); 337cdf0e10cSrcweir return oBookmark; 338cdf0e10cSrcweir 339cdf0e10cSrcweir } /// finish createBookmark 340cdf0e10cSrcweir 341cdf0e10cSrcweir /** 342cdf0e10cSrcweir * the method createReferenceMark 343cdf0e10cSrcweir */ createReferenceMark(XTextDocument xTextDoc)344cdf0e10cSrcweir public static XTextContent createReferenceMark(XTextDocument xTextDoc) 345cdf0e10cSrcweir throws com.sun.star.uno.Exception { 346cdf0e10cSrcweir 347cdf0e10cSrcweir ReferenceMarkDsc tDsc = new ReferenceMarkDsc(); 348cdf0e10cSrcweir InstCreator instCreate = new InstCreator(xTextDoc, tDsc); 349cdf0e10cSrcweir 350cdf0e10cSrcweir XTextContent oReferenceMark = (XTextContent) instCreate.getInstance(); 351cdf0e10cSrcweir return oReferenceMark; 352cdf0e10cSrcweir 353cdf0e10cSrcweir } /// finish createReferenceMark 354cdf0e10cSrcweir 355cdf0e10cSrcweir /** 356cdf0e10cSrcweir * the method createFootnote 357cdf0e10cSrcweir */ createFootnote(XTextDocument xTextDoc)358cdf0e10cSrcweir public static XTextContent createFootnote(XTextDocument xTextDoc) 359cdf0e10cSrcweir throws com.sun.star.uno.Exception { 360cdf0e10cSrcweir 361cdf0e10cSrcweir FootnoteDsc tDsc = new FootnoteDsc(); 362cdf0e10cSrcweir InstCreator instCreate = new InstCreator(xTextDoc, tDsc); 363cdf0e10cSrcweir 364cdf0e10cSrcweir XTextContent oFootnote = (XTextContent) instCreate.getInstance(); 365cdf0e10cSrcweir return oFootnote; 366cdf0e10cSrcweir 367cdf0e10cSrcweir } /// finish createFootnote 368cdf0e10cSrcweir 369cdf0e10cSrcweir /** 370cdf0e10cSrcweir * the method create Index 371cdf0e10cSrcweir */ createIndex(XTextDocument xTextDoc, String kind)372cdf0e10cSrcweir public static XTextContent createIndex(XTextDocument xTextDoc, String kind) 373cdf0e10cSrcweir throws com.sun.star.uno.Exception { 374cdf0e10cSrcweir 375cdf0e10cSrcweir XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, 376cdf0e10cSrcweir xTextDoc); 377cdf0e10cSrcweir 378cdf0e10cSrcweir Object oInt = oDocMSF.createInstance(kind); 379cdf0e10cSrcweir 380cdf0e10cSrcweir XTextContent xTC = (XTextContent) UnoRuntime.queryInterface(XDocumentIndex.class, oInt); 381cdf0e10cSrcweir 382cdf0e10cSrcweir return xTC; 383cdf0e10cSrcweir 384cdf0e10cSrcweir } 385cdf0e10cSrcweir createSpreadsheet(XSpreadsheetDocument oDoc)386cdf0e10cSrcweir public static XSpreadsheet createSpreadsheet(XSpreadsheetDocument oDoc) 387cdf0e10cSrcweir throws com.sun.star.uno.Exception { 388cdf0e10cSrcweir 389cdf0e10cSrcweir XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc); 390cdf0e10cSrcweir 391cdf0e10cSrcweir Object oInt = oDocMSF.createInstance( 392cdf0e10cSrcweir "com.sun.star.sheet.Spreadsheet"); 393cdf0e10cSrcweir 394cdf0e10cSrcweir XSpreadsheet oSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, oInt); 395cdf0e10cSrcweir 396cdf0e10cSrcweir return oSpreadsheet; 397cdf0e10cSrcweir } 398cdf0e10cSrcweir getTableCollection(XTextDocument oDoc)399cdf0e10cSrcweir public static XIndexAccess getTableCollection(XTextDocument oDoc) { 400cdf0e10cSrcweir 401cdf0e10cSrcweir XTextTablesSupplier oTTS = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, oDoc); 402cdf0e10cSrcweir 403cdf0e10cSrcweir XNameAccess oNA = oTTS.getTextTables(); 404cdf0e10cSrcweir XIndexAccess oIA = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, oNA); 405cdf0e10cSrcweir 406cdf0e10cSrcweir return oIA; 407cdf0e10cSrcweir } 408cdf0e10cSrcweir getUniqueName(XInterface oInterface, String prefix)409cdf0e10cSrcweir public static String getUniqueName(XInterface oInterface, String prefix) { 410cdf0e10cSrcweir XNameAccess oNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, oInterface); 411cdf0e10cSrcweir if (oNameAccess == null) { 412cdf0e10cSrcweir return null; 413cdf0e10cSrcweir } 414cdf0e10cSrcweir int i; 415cdf0e10cSrcweir for (i = 0; oNameAccess.hasByName(prefix + i); i++) { 416cdf0e10cSrcweir } 417cdf0e10cSrcweir return prefix + i; 418cdf0e10cSrcweir } 419cdf0e10cSrcweir createShape(XComponent oDoc, int height, int width, int x, int y, String kind)420cdf0e10cSrcweir public XShape createShape(XComponent oDoc, int height, int width, int x, int y, String kind) { 421cdf0e10cSrcweir //possible values for kind are 'Ellipse', 'Line' and 'Rectangle' 422cdf0e10cSrcweir 423cdf0e10cSrcweir ShapeDsc sDsc = new ShapeDsc(height, width, x, y, kind); 424cdf0e10cSrcweir InstCreator instCreate = new InstCreator(oDoc, sDsc); 425cdf0e10cSrcweir 426cdf0e10cSrcweir XShape oShape = (XShape) instCreate.getInstance(); 427cdf0e10cSrcweir 428cdf0e10cSrcweir return oShape; 429cdf0e10cSrcweir 430cdf0e10cSrcweir } 431cdf0e10cSrcweir 432cdf0e10cSrcweir /** 433cdf0e10cSrcweir * creates a Diagram wich specified in kind(String) 434cdf0e10cSrcweir */ createDiagram(XComponent oDoc, String kind)435cdf0e10cSrcweir public XDiagram createDiagram(XComponent oDoc, String kind) { 436cdf0e10cSrcweir XInterface oInterface = null; 437cdf0e10cSrcweir XDiagram oDiagram = null; 438cdf0e10cSrcweir 439cdf0e10cSrcweir //get LineDiagram 440cdf0e10cSrcweir XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc); 441cdf0e10cSrcweir 442cdf0e10cSrcweir try { 443cdf0e10cSrcweir oInterface = (XInterface) oDocMSF.createInstance("com.sun.star.chart." + kind); 444cdf0e10cSrcweir oDiagram = (XDiagram) UnoRuntime.queryInterface(XDiagram.class, oInterface); 445cdf0e10cSrcweir } catch (Exception e) { 446cdf0e10cSrcweir // Some exception occures.FAILED 447cdf0e10cSrcweir System.out.println("Couldn't create " + kind + "-Diagram " + e); 448cdf0e10cSrcweir } 449cdf0e10cSrcweir return oDiagram; 450cdf0e10cSrcweir } 451cdf0e10cSrcweir 452cdf0e10cSrcweir /* 453cdf0e10cSrcweir // create a Control-Instance which specified in kind(String) 454cdf0e10cSrcweir */ createControl(XComponent oDoc, String kind)455cdf0e10cSrcweir public XInterface createControl(XComponent oDoc, String kind) { 456cdf0e10cSrcweir 457cdf0e10cSrcweir XInterface oControl = null; 458cdf0e10cSrcweir 459cdf0e10cSrcweir XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc); 460cdf0e10cSrcweir 461cdf0e10cSrcweir try { 462cdf0e10cSrcweir oControl = (XInterface) oDocMSF.createInstance("com.sun.star.form.component." + kind); 463cdf0e10cSrcweir } catch (Exception e) { 464cdf0e10cSrcweir // Some exception occures.FAILED 465cdf0e10cSrcweir System.out.println("Couldn't create instance " + kind + ": " + e); 466cdf0e10cSrcweir } 467cdf0e10cSrcweir return oControl; 468cdf0e10cSrcweir } 469cdf0e10cSrcweir 470cdf0e10cSrcweir /* 471cdf0e10cSrcweir // create an Instance which is specified in kind(String) 472cdf0e10cSrcweir */ createInstance(XComponent oDoc, String kind)473cdf0e10cSrcweir public Object createInstance(XComponent oDoc, String kind) { 474cdf0e10cSrcweir 475cdf0e10cSrcweir Object oInstance = null; 476cdf0e10cSrcweir 477cdf0e10cSrcweir XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc); 478cdf0e10cSrcweir 479cdf0e10cSrcweir try { 480cdf0e10cSrcweir oInstance = (Object) oDocMSF.createInstance(kind); 481cdf0e10cSrcweir } catch (Exception e) { 482cdf0e10cSrcweir // Some exception occures.FAILED 483cdf0e10cSrcweir System.out.println("Couldn't create instance " + kind + ": " + e); 484cdf0e10cSrcweir } 485cdf0e10cSrcweir return oInstance; 486cdf0e10cSrcweir } 487cdf0e10cSrcweir createControlShape(XComponent oDoc, int height, int width, int x, int y, String kind)488cdf0e10cSrcweir public XControlShape createControlShape(XComponent oDoc, int height, int width, int x, int y, String kind) { 489cdf0e10cSrcweir 490cdf0e10cSrcweir Size size = new Size(); 491cdf0e10cSrcweir Point position = new Point(); 492cdf0e10cSrcweir XControlShape oCShape = null; 493cdf0e10cSrcweir XControlModel aControl = null; 494cdf0e10cSrcweir 495cdf0e10cSrcweir //get MSF 496cdf0e10cSrcweir XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc); 497cdf0e10cSrcweir 498cdf0e10cSrcweir try { 499cdf0e10cSrcweir Object oInt = oDocMSF.createInstance("com.sun.star.drawing.ControlShape"); 500cdf0e10cSrcweir Object aCon = oDocMSF.createInstance("com.sun.star.form.component." + kind); 501cdf0e10cSrcweir aControl = (XControlModel) UnoRuntime.queryInterface(XControlModel.class, aCon); 502cdf0e10cSrcweir oCShape = (XControlShape) UnoRuntime.queryInterface(XControlShape.class, oInt); 503cdf0e10cSrcweir size.Height = height; 504cdf0e10cSrcweir size.Width = width; 505cdf0e10cSrcweir position.X = x; 506cdf0e10cSrcweir position.Y = y; 507cdf0e10cSrcweir oCShape.setSize(size); 508cdf0e10cSrcweir oCShape.setPosition(position); 509cdf0e10cSrcweir 510cdf0e10cSrcweir 511cdf0e10cSrcweir } catch (Exception e) { 512cdf0e10cSrcweir // Some exception occures.FAILED 513cdf0e10cSrcweir System.out.println("Couldn't create instance " + e); 514cdf0e10cSrcweir } 515cdf0e10cSrcweir 516cdf0e10cSrcweir try { 517cdf0e10cSrcweir oCShape.setControl(aControl); 518cdf0e10cSrcweir } catch (Exception e) { 519cdf0e10cSrcweir // Some exception occures.FAILED 520cdf0e10cSrcweir System.out.println("Couldn't get Control " + e); 521cdf0e10cSrcweir } 522cdf0e10cSrcweir 523cdf0e10cSrcweir 524cdf0e10cSrcweir return oCShape; 525cdf0e10cSrcweir 526cdf0e10cSrcweir } 527cdf0e10cSrcweir loadDocument(String fileName)528cdf0e10cSrcweir public XComponent loadDocument(String fileName) 529cdf0e10cSrcweir throws com.sun.star.lang.IllegalArgumentException, 530cdf0e10cSrcweir com.sun.star.io.IOException, 531cdf0e10cSrcweir com.sun.star.uno.Exception { 532cdf0e10cSrcweir 533cdf0e10cSrcweir // that noargs thing for load attributes 534cdf0e10cSrcweir PropertyValue[] szEmptyArgs = new PropertyValue[0]; 535cdf0e10cSrcweir String frameName = "_blank"; 536cdf0e10cSrcweir 537cdf0e10cSrcweir XComponent oDoc = oCLoader.loadComponentFromURL( 538cdf0e10cSrcweir fileName, frameName, 0, szEmptyArgs); 539cdf0e10cSrcweir 540cdf0e10cSrcweir if (oDoc == null) { 541cdf0e10cSrcweir return null; 542cdf0e10cSrcweir } 543cdf0e10cSrcweir DesktopTools.bringWindowToFront(oDoc); 544cdf0e10cSrcweir return oDoc; 545cdf0e10cSrcweir } 546cdf0e10cSrcweir loadDocument(String fileName, PropertyValue[] Args)547cdf0e10cSrcweir public XComponent loadDocument(String fileName, PropertyValue[] Args) 548cdf0e10cSrcweir throws com.sun.star.lang.IllegalArgumentException, 549cdf0e10cSrcweir com.sun.star.io.IOException, 550cdf0e10cSrcweir com.sun.star.uno.Exception { 551cdf0e10cSrcweir 552cdf0e10cSrcweir // that noargs thing for load attributes 553cdf0e10cSrcweir String frameName = "_blank"; 554cdf0e10cSrcweir 555cdf0e10cSrcweir XComponent oDoc = oCLoader.loadComponentFromURL( 556cdf0e10cSrcweir fileName, frameName, 0, Args); 557cdf0e10cSrcweir 558cdf0e10cSrcweir if (oDoc == null) { 559cdf0e10cSrcweir return null; 560cdf0e10cSrcweir } 561cdf0e10cSrcweir DesktopTools.bringWindowToFront(oDoc); 562cdf0e10cSrcweir 563cdf0e10cSrcweir return oDoc; 564cdf0e10cSrcweir } 565cdf0e10cSrcweir openDoc(String kind, String frameName)566cdf0e10cSrcweir public XComponent openDoc(String kind, String frameName) 567cdf0e10cSrcweir throws com.sun.star.lang.IllegalArgumentException, 568cdf0e10cSrcweir com.sun.star.io.IOException, 569cdf0e10cSrcweir com.sun.star.uno.Exception { 570cdf0e10cSrcweir 571cdf0e10cSrcweir // that noargs thing for load attributes 572cdf0e10cSrcweir PropertyValue[] Args = null; 573cdf0e10cSrcweir if (kind.equals("simpress")) { 574cdf0e10cSrcweir Args = new PropertyValue[1]; 575cdf0e10cSrcweir PropertyValue Arg = new PropertyValue(); 576cdf0e10cSrcweir Arg.Name = "OpenFlags"; 577cdf0e10cSrcweir Arg.Value = "S"; 578cdf0e10cSrcweir Arg.Handle = -1; 579cdf0e10cSrcweir Arg.State = PropertyState.DEFAULT_VALUE; 580cdf0e10cSrcweir Args[0] = Arg; 581cdf0e10cSrcweir } else { 582cdf0e10cSrcweir Args = new PropertyValue[0]; 583cdf0e10cSrcweir } 584cdf0e10cSrcweir 585cdf0e10cSrcweir if (frameName == null) { 586cdf0e10cSrcweir frameName = "_blank"; 587cdf0e10cSrcweir } 588cdf0e10cSrcweir // load a blank a doc 589cdf0e10cSrcweir XComponent oDoc = oCLoader.loadComponentFromURL("private:factory/" + kind, frameName, 40, Args); 590cdf0e10cSrcweir DesktopTools.bringWindowToFront(oDoc); 591cdf0e10cSrcweir 592cdf0e10cSrcweir return oDoc; 593cdf0e10cSrcweir 594cdf0e10cSrcweir } // finished openDoc 595cdf0e10cSrcweir openDoc(String kind, String frameName, PropertyValue[] mediaDescriptor)596cdf0e10cSrcweir public XComponent openDoc(String kind, String frameName, PropertyValue[] mediaDescriptor) 597cdf0e10cSrcweir throws com.sun.star.lang.IllegalArgumentException, 598cdf0e10cSrcweir com.sun.star.io.IOException, 599cdf0e10cSrcweir com.sun.star.uno.Exception { 600cdf0e10cSrcweir 601cdf0e10cSrcweir if (frameName == null) { 602cdf0e10cSrcweir frameName = "_blank"; 603cdf0e10cSrcweir } 604cdf0e10cSrcweir // load a blank a doc 605cdf0e10cSrcweir XComponent oDoc = oCLoader.loadComponentFromURL( 606cdf0e10cSrcweir "private:factory/" + kind, frameName, 40, mediaDescriptor); 607cdf0e10cSrcweir DesktopTools.bringWindowToFront(oDoc); 608cdf0e10cSrcweir 609cdf0e10cSrcweir return oDoc; 610cdf0e10cSrcweir 611cdf0e10cSrcweir } // finished openDoc 612cdf0e10cSrcweir 613cdf0e10cSrcweir // query for XServiceInfo queryXServiceInfo(Object oObj)614cdf0e10cSrcweir public Object queryXServiceInfo(Object oObj) { 615cdf0e10cSrcweir if (oObj != null) { 616cdf0e10cSrcweir XServiceInfo oInfo = (XServiceInfo) UnoRuntime.queryInterface( 617cdf0e10cSrcweir XServiceInfo.class, oObj); 618cdf0e10cSrcweir System.out.println("!!!! XServiceInfo n.a. !!!! "); 619cdf0e10cSrcweir } else { 620cdf0e10cSrcweir System.out.println("Object is empty!!!! "); 621cdf0e10cSrcweir } 622cdf0e10cSrcweir return null; 623cdf0e10cSrcweir } // finish queryXServiceInfo 624*170fb961SPedro Giffuni } 625