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