1*34dd1e25SAndrew Rist /**************************************************************
2*34dd1e25SAndrew Rist  *
3*34dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*34dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*34dd1e25SAndrew Rist  * distributed with this work for additional information
6*34dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*34dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*34dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
9*34dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*34dd1e25SAndrew Rist  *
11*34dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*34dd1e25SAndrew Rist  *
13*34dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*34dd1e25SAndrew Rist  * software distributed under the License is distributed on an
15*34dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*34dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
17*34dd1e25SAndrew Rist  * specific language governing permissions and limitations
18*34dd1e25SAndrew Rist  * under the License.
19*34dd1e25SAndrew Rist  *
20*34dd1e25SAndrew Rist  *************************************************************/
21*34dd1e25SAndrew Rist 
22*34dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir //***************************************************************************
25cdf0e10cSrcweir // comment: Step 1: get the Desktop object from the office
26cdf0e10cSrcweir //          Step 2: open an empty Calc document
27cdf0e10cSrcweir //          Step 3: enter a example text, set the numberformat to DM
28cdf0e10cSrcweir //          Step 4: change the numberformat to EUR (Euro)
29cdf0e10cSrcweir //          Step 5: use the DM/EUR factor on each cell with a content
30cdf0e10cSrcweir //***************************************************************************
31cdf0e10cSrcweir 
32cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
33cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir import com.sun.star.container.XEnumeration;
36cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
37cdf0e10cSrcweir import com.sun.star.container.XEnumerationAccess;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir import com.sun.star.document.XActionLockable;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir import com.sun.star.frame.XDesktop;
42cdf0e10cSrcweir import com.sun.star.frame.XComponentLoader;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir import com.sun.star.lang.Locale;
45cdf0e10cSrcweir import com.sun.star.lang.XComponent;
46cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir import com.sun.star.table.XCell;
49cdf0e10cSrcweir import com.sun.star.table.XCellRange;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet;
52cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheets;
53cdf0e10cSrcweir import com.sun.star.sheet.XSheetCellRanges;
54cdf0e10cSrcweir import com.sun.star.sheet.XCellRangesQuery;
55cdf0e10cSrcweir import com.sun.star.sheet.XCellFormatRangesSupplier;
56cdf0e10cSrcweir import com.sun.star.sheet.XCellRangesQuery;
57cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
60cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
61cdf0e10cSrcweir import com.sun.star.uno.XInterface;
62cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir import com.sun.star.util.NumberFormat;
65cdf0e10cSrcweir import com.sun.star.util.XNumberFormats;
66cdf0e10cSrcweir import com.sun.star.util.XNumberFormatsSupplier;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
69cdf0e10cSrcweir public class EuroAdaption {
70cdf0e10cSrcweir 
main(String args[])71cdf0e10cSrcweir     public static void main(String args[]) {
72cdf0e10cSrcweir         // You need the desktop to create a document
73cdf0e10cSrcweir         // The getDesktop method does the UNO bootstrapping, gets the
74cdf0e10cSrcweir         // remote servie manager and the desktop object.
75cdf0e10cSrcweir         com.sun.star.frame.XDesktop xDesktop = null;
76cdf0e10cSrcweir         xDesktop = getDesktop();
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         // create a sheet document
79cdf0e10cSrcweir         XSpreadsheetDocument xSheetdocument = null;
80cdf0e10cSrcweir         xSheetdocument = ( XSpreadsheetDocument ) createSheetdocument( xDesktop );
81cdf0e10cSrcweir         System.out.println( "Create a new Spreadsheet" );
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         // get the collection of all sheets from the document
84cdf0e10cSrcweir         XSpreadsheets xSheets = null;
85cdf0e10cSrcweir         xSheets = (XSpreadsheets) xSheetdocument.getSheets();
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         // the Action Interface provides methods to hide actions,
88cdf0e10cSrcweir         // like inserting data, on a sheet, that increase the performance
89cdf0e10cSrcweir         XActionLockable xActionInterface = null;
90cdf0e10cSrcweir         xActionInterface = (XActionLockable) UnoRuntime.queryInterface(
91cdf0e10cSrcweir             XActionLockable.class, xSheetdocument );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir         // lock all actions
94cdf0e10cSrcweir         xActionInterface.addActionLock();
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         com.sun.star.sheet.XSpreadsheet xSheet = null;
97cdf0e10cSrcweir         try {
98cdf0e10cSrcweir             // get via the index access the first sheet
99cdf0e10cSrcweir             XIndexAccess xElements = (XIndexAccess) UnoRuntime.queryInterface(
100cdf0e10cSrcweir                 XIndexAccess.class, xSheets );
101cdf0e10cSrcweir 
102cdf0e10cSrcweir             // specify the first sheet from the spreadsheet
103cdf0e10cSrcweir             xSheet = (XSpreadsheet) UnoRuntime.queryInterface(
104cdf0e10cSrcweir                 XSpreadsheet.class, xElements.getByIndex( 0 ));
105cdf0e10cSrcweir         }
106cdf0e10cSrcweir         catch( Exception e) {
107cdf0e10cSrcweir             e.printStackTrace(System.err);
108cdf0e10cSrcweir         }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir         // get the interface to apply and create new numberformats
111cdf0e10cSrcweir         XNumberFormatsSupplier xNumberFormatSupplier = null;
112cdf0e10cSrcweir         xNumberFormatSupplier = (XNumberFormatsSupplier) UnoRuntime.queryInterface(
113cdf0e10cSrcweir             XNumberFormatsSupplier.class, xSheetdocument );
114cdf0e10cSrcweir         XNumberFormats xNumberFormats = null;
115cdf0e10cSrcweir         xNumberFormats = xNumberFormatSupplier.getNumberFormats();
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         // insert some example data in a sheet
118cdf0e10cSrcweir         createExampleData( xSheet, xNumberFormats );
119cdf0e10cSrcweir         System.out.println( "Insert example data and use the number format with the currency 'DM'" );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         // Change the currency from the cells from DM to Euro
122cdf0e10cSrcweir         Convert(  xSheet, xNumberFormats, "DM", "EUR", 1.95583f );
123cdf0e10cSrcweir         System.out.println( "Change the number format to EUR and divide the values with the factor 1.95583" );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         // remove all locks, the user see all changes
126cdf0e10cSrcweir         xActionInterface.removeActionLock();
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         System.out.println("done");
129cdf0e10cSrcweir         System.exit(0);
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 
Convert( XSpreadsheet xSheet, XNumberFormats xNumberFormats, String sOldSymbol, String sNewSymbol, float fFactor )133cdf0e10cSrcweir     public static void Convert( XSpreadsheet xSheet, XNumberFormats xNumberFormats,
134cdf0e10cSrcweir                                 String sOldSymbol, String sNewSymbol,
135cdf0e10cSrcweir                                 float fFactor ) {
136cdf0e10cSrcweir         try {
137cdf0e10cSrcweir             Locale xLanguage = new Locale();
138cdf0e10cSrcweir             xLanguage.Country = "de";    // Germany -> DM
139cdf0e10cSrcweir             xLanguage.Language = "de";   // German
140cdf0e10cSrcweir 
141cdf0e10cSrcweir             // Numberformat string with sNewSymbol
142cdf0e10cSrcweir             String sSimple = "0 [$" + sNewSymbol + "]";
143cdf0e10cSrcweir             // create a number format key with the sNewSymbol
144cdf0e10cSrcweir             int iSimpleKey = NumberFormat( xNumberFormats, sSimple, xLanguage );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir             // you have to use the FormatSupplier interface to get the
147cdf0e10cSrcweir             // CellFormat enumeration
148cdf0e10cSrcweir             XCellFormatRangesSupplier xCellFormatSupplier =
149cdf0e10cSrcweir                 (XCellFormatRangesSupplier)UnoRuntime.queryInterface(
150cdf0e10cSrcweir                     XCellFormatRangesSupplier.class, xSheet );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir             // getCellFormatRanges() has the interfaces for the enumeration
153cdf0e10cSrcweir             XEnumerationAccess xEnumerationAccess =
154cdf0e10cSrcweir                 (XEnumerationAccess)UnoRuntime.queryInterface(
155cdf0e10cSrcweir                     XEnumerationAccess.class,
156cdf0e10cSrcweir                     xCellFormatSupplier.getCellFormatRanges() );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir             XEnumeration xRanges = xEnumerationAccess.createEnumeration();
159cdf0e10cSrcweir 
160cdf0e10cSrcweir             // create an AnyConverter for later use
161cdf0e10cSrcweir             AnyConverter aAnyConv = new AnyConverter();
162cdf0e10cSrcweir 
163cdf0e10cSrcweir             while( xRanges.hasMoreElements() ) {
164cdf0e10cSrcweir                 // the enumeration returns a cellrange
165cdf0e10cSrcweir                 XCellRange xCellRange = (XCellRange) UnoRuntime.queryInterface(
166cdf0e10cSrcweir                     XCellRange.class, xRanges.nextElement());
167cdf0e10cSrcweir 
168cdf0e10cSrcweir                 // the PropertySet the get and set the properties from the cellrange
169cdf0e10cSrcweir                 XPropertySet xCellProp = (XPropertySet)UnoRuntime.queryInterface(
170cdf0e10cSrcweir                     XPropertySet.class, xCellRange );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir                 // getPropertyValue returns an Object, you have to cast it to
173cdf0e10cSrcweir                 // type that you need
174cdf0e10cSrcweir                 Object oNumberObject = xCellProp.getPropertyValue( "NumberFormat" );
175cdf0e10cSrcweir                 int iNumberFormat = aAnyConv.toInt(oNumberObject);
176cdf0e10cSrcweir 
177cdf0e10cSrcweir                 // get the properties from the cellrange numberformat
178cdf0e10cSrcweir                 XPropertySet xFormat = (XPropertySet)
179cdf0e10cSrcweir                     xNumberFormats.getByKey(iNumberFormat );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir                 short fType = aAnyConv.toShort(xFormat.getPropertyValue("Type"));
182cdf0e10cSrcweir                 String sCurrencySymbol = aAnyConv.toString(
183cdf0e10cSrcweir                     xFormat.getPropertyValue("CurrencySymbol"));
184cdf0e10cSrcweir 
185cdf0e10cSrcweir                 // change the numberformat only on cellranges with a
186cdf0e10cSrcweir                 // currency numberformat
187cdf0e10cSrcweir                 if( ( (fType & com.sun.star.util.NumberFormat.CURRENCY) > 0) &&
188cdf0e10cSrcweir                     ( sCurrencySymbol.compareTo( sOldSymbol ) == 0 ) ) {
189cdf0e10cSrcweir                     boolean bThousandSep = aAnyConv.toBoolean(
190cdf0e10cSrcweir                         xFormat.getPropertyValue("ThousandsSeparator"));
191cdf0e10cSrcweir                     boolean bNegativeRed = aAnyConv.toBoolean(
192cdf0e10cSrcweir                         xFormat.getPropertyValue("NegativeRed"));
193cdf0e10cSrcweir                     short fDecimals = aAnyConv.toShort(
194cdf0e10cSrcweir                         xFormat.getPropertyValue("Decimals"));
195cdf0e10cSrcweir                     short fLeadingZeros = aAnyConv.toShort(
196cdf0e10cSrcweir                         xFormat.getPropertyValue("LeadingZeros"));
197cdf0e10cSrcweir                     Locale oLocale = (Locale) aAnyConv.toObject(
198cdf0e10cSrcweir                        new com.sun.star.uno.Type(Locale.class),
199cdf0e10cSrcweir                        xFormat.getPropertyValue("Locale"));
200cdf0e10cSrcweir 
201cdf0e10cSrcweir                     // create a new numberformat string
202cdf0e10cSrcweir                     String sNew = xNumberFormats.generateFormat( iSimpleKey,
203cdf0e10cSrcweir                                          oLocale, bThousandSep, bNegativeRed,
204cdf0e10cSrcweir                                          fDecimals, fLeadingZeros );
205cdf0e10cSrcweir 
206cdf0e10cSrcweir                     // get the NumberKey from the numberformat
207cdf0e10cSrcweir                     int iNewNumberFormat = NumberFormat( xNumberFormats,
208cdf0e10cSrcweir                                                          sNew, oLocale );
209cdf0e10cSrcweir 
210cdf0e10cSrcweir                     // set the new numberformat to the cellrange DM->EUR
211cdf0e10cSrcweir                     xCellProp.setPropertyValue( "NumberFormat",
212cdf0e10cSrcweir                                                 new Integer( iNewNumberFormat ) );
213cdf0e10cSrcweir 
214cdf0e10cSrcweir                     // interate over all cells from the cellrange with an
215cdf0e10cSrcweir                     // content and use the DM/EUR factor
216cdf0e10cSrcweir                     XCellRangesQuery xCellRangesQuery = (XCellRangesQuery)
217cdf0e10cSrcweir                         UnoRuntime.queryInterface(
218cdf0e10cSrcweir                         XCellRangesQuery.class, xCellRange );
219cdf0e10cSrcweir 
220cdf0e10cSrcweir                     XSheetCellRanges xSheetCellRanges =
221cdf0e10cSrcweir                         xCellRangesQuery.queryContentCells(
222cdf0e10cSrcweir                             (short) com.sun.star.sheet.CellFlags.VALUE );
223cdf0e10cSrcweir 
224cdf0e10cSrcweir                     if( xSheetCellRanges.getCount() > 0 ) {
225cdf0e10cSrcweir                         XEnumerationAccess xCellEnumerationAccess =
226cdf0e10cSrcweir                             xSheetCellRanges.getCells();
227cdf0e10cSrcweir                         XEnumeration xCellEnumeration =
228cdf0e10cSrcweir                             xCellEnumerationAccess.createEnumeration();
229cdf0e10cSrcweir 
230cdf0e10cSrcweir                         while( xCellEnumeration.hasMoreElements() ) {
231cdf0e10cSrcweir                             XCell xCell = (XCell) UnoRuntime.queryInterface(
232cdf0e10cSrcweir                                 XCell.class, xCellEnumeration.nextElement());
233cdf0e10cSrcweir                             xCell.setValue( (double) xCell.getValue() / fFactor );
234cdf0e10cSrcweir                         }
235cdf0e10cSrcweir                     }
236cdf0e10cSrcweir                 }
237cdf0e10cSrcweir             }
238cdf0e10cSrcweir         }
239cdf0e10cSrcweir         catch( Exception e) {
240cdf0e10cSrcweir             e.printStackTrace(System.err);
241cdf0e10cSrcweir         }
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 
NumberFormat( XNumberFormats xNumberFormat, String sFormat, com.sun.star.lang.Locale xLanguage )245cdf0e10cSrcweir     public static int NumberFormat( XNumberFormats xNumberFormat, String sFormat,
246cdf0e10cSrcweir                                     com.sun.star.lang.Locale xLanguage ) {
247cdf0e10cSrcweir         int nRetKey = 0;
248cdf0e10cSrcweir 
249cdf0e10cSrcweir         try {
250cdf0e10cSrcweir             // exists the numberformat
251cdf0e10cSrcweir             nRetKey = xNumberFormat.queryKey( sFormat, xLanguage, true );
252cdf0e10cSrcweir 
253cdf0e10cSrcweir             // if not, create a new one
254cdf0e10cSrcweir             if( nRetKey == -1 ) {
255cdf0e10cSrcweir                 nRetKey = xNumberFormat.addNew( sFormat, xLanguage );
256cdf0e10cSrcweir                 if( nRetKey == -1 )
257cdf0e10cSrcweir                     nRetKey = 0;
258cdf0e10cSrcweir             }
259cdf0e10cSrcweir         }
260cdf0e10cSrcweir         catch( Exception e) {
261cdf0e10cSrcweir             e.printStackTrace(System.err);
262cdf0e10cSrcweir         }
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         return( nRetKey );
265cdf0e10cSrcweir     }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 
createExampleData( XSpreadsheet xSheet, XNumberFormats xNumberFormat )268cdf0e10cSrcweir     public static void createExampleData( XSpreadsheet xSheet,
269cdf0e10cSrcweir                                           XNumberFormats xNumberFormat ) {
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         // enter in a cellrange numbers and change the numberformat to DM
272cdf0e10cSrcweir         XCell xCell = null;
273cdf0e10cSrcweir         XCellRange xCellRange = null;
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         try {
276cdf0e10cSrcweir             Locale xLanguage = new Locale();
277cdf0e10cSrcweir             xLanguage.Country = "de";    // Germany -> DM
278cdf0e10cSrcweir             xLanguage.Language = "de";   // German
279cdf0e10cSrcweir 
280cdf0e10cSrcweir             // Numberformat string from DM
281cdf0e10cSrcweir             String sSimple = "0 [$DM]";
282cdf0e10cSrcweir 
283cdf0e10cSrcweir             // get the numberformat key
284cdf0e10cSrcweir             int iNumberFormatKey = NumberFormat(xNumberFormat, sSimple, xLanguage);
285cdf0e10cSrcweir 
286cdf0e10cSrcweir             for( int iCounter=1; iCounter < 10; iCounter++ ) {
287cdf0e10cSrcweir                 // get one cell and insert a number
288cdf0e10cSrcweir                 xCell = xSheet.getCellByPosition( 2, 1 + iCounter );
289cdf0e10cSrcweir                 xCell.setValue( (double) iCounter * 2 );
290cdf0e10cSrcweir                 xCellRange = xSheet.getCellRangeByPosition( 2, 1 + iCounter,
291cdf0e10cSrcweir                                                             2, 1 + iCounter );
292cdf0e10cSrcweir 
293cdf0e10cSrcweir                 // get the ProperySet from the cell, to change the numberformat
294cdf0e10cSrcweir                 XPropertySet xCellProp = (XPropertySet)UnoRuntime.queryInterface(
295cdf0e10cSrcweir                     XPropertySet.class, xCellRange );
296cdf0e10cSrcweir                 xCellProp.setPropertyValue( "NumberFormat",
297cdf0e10cSrcweir                                             new Integer(iNumberFormatKey) );
298cdf0e10cSrcweir             }
299cdf0e10cSrcweir         }
300cdf0e10cSrcweir         catch( Exception e) {
301cdf0e10cSrcweir             e.printStackTrace(System.err);
302cdf0e10cSrcweir         }
303cdf0e10cSrcweir     }
304cdf0e10cSrcweir 
getDesktop()305cdf0e10cSrcweir     public static XDesktop getDesktop() {
306cdf0e10cSrcweir         XDesktop xDesktop = null;
307cdf0e10cSrcweir         XMultiComponentFactory xMCF = null;
308cdf0e10cSrcweir 
309cdf0e10cSrcweir         try {
310cdf0e10cSrcweir             XComponentContext xContext = null;
311cdf0e10cSrcweir 
312cdf0e10cSrcweir             // get the remote office component context
313cdf0e10cSrcweir             xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
314cdf0e10cSrcweir 
315cdf0e10cSrcweir             // get the remote office service manager
316cdf0e10cSrcweir             xMCF = xContext.getServiceManager();
317cdf0e10cSrcweir             if( xMCF != null ) {
318cdf0e10cSrcweir                 System.out.println("Connected to a running office ...");
319cdf0e10cSrcweir 
320cdf0e10cSrcweir                 Object oDesktop = xMCF.createInstanceWithContext(
321cdf0e10cSrcweir                     "com.sun.star.frame.Desktop", xContext);
322cdf0e10cSrcweir                 xDesktop = (XDesktop) UnoRuntime.queryInterface(
323cdf0e10cSrcweir                     XDesktop.class, oDesktop);
324cdf0e10cSrcweir             }
325cdf0e10cSrcweir             else
326cdf0e10cSrcweir                 System.out.println( "Can't create a desktop. No connection, no remote servicemanager available!" );
327cdf0e10cSrcweir         }
328cdf0e10cSrcweir         catch( Exception e) {
329cdf0e10cSrcweir             e.printStackTrace(System.err);
330cdf0e10cSrcweir             System.exit(1);
331cdf0e10cSrcweir         }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 
334cdf0e10cSrcweir         return xDesktop;
335cdf0e10cSrcweir     }
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 
createSheetdocument( XDesktop xDesktop )338cdf0e10cSrcweir     public static XSpreadsheetDocument createSheetdocument( XDesktop xDesktop ) {
339cdf0e10cSrcweir         XSpreadsheetDocument aSheetDocument = null;
340cdf0e10cSrcweir 
341cdf0e10cSrcweir         try {
342cdf0e10cSrcweir             XComponent xComponent = null;
343cdf0e10cSrcweir             xComponent = CreateNewDocument( xDesktop, "scalc" );
344cdf0e10cSrcweir 
345cdf0e10cSrcweir             aSheetDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(
346cdf0e10cSrcweir                 XSpreadsheetDocument.class, xComponent);
347cdf0e10cSrcweir         }
348cdf0e10cSrcweir         catch( Exception e) {
349cdf0e10cSrcweir             e.printStackTrace(System.err);
350cdf0e10cSrcweir         }
351cdf0e10cSrcweir 
352cdf0e10cSrcweir         return aSheetDocument;
353cdf0e10cSrcweir     }
354cdf0e10cSrcweir 
CreateNewDocument( XDesktop xDesktop, String sDocumentType )355cdf0e10cSrcweir     protected static XComponent CreateNewDocument( XDesktop xDesktop,
356cdf0e10cSrcweir                                                    String sDocumentType ) {
357cdf0e10cSrcweir         String sURL = "private:factory/" + sDocumentType;
358cdf0e10cSrcweir 
359cdf0e10cSrcweir         XComponent xComponent = null;
360cdf0e10cSrcweir         XComponentLoader xComponentLoader = null;
361cdf0e10cSrcweir         PropertyValue xValues[] = new PropertyValue[1];
362cdf0e10cSrcweir         PropertyValue xEmptyArgs[] = new PropertyValue[0];
363cdf0e10cSrcweir 
364cdf0e10cSrcweir         try {
365cdf0e10cSrcweir             xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(
366cdf0e10cSrcweir                 XComponentLoader.class, xDesktop );
367cdf0e10cSrcweir 
368cdf0e10cSrcweir             xComponent  = xComponentLoader.loadComponentFromURL(
369cdf0e10cSrcweir                 sURL, "_blank", 0, xEmptyArgs);
370cdf0e10cSrcweir         }
371cdf0e10cSrcweir         catch( Exception e) {
372cdf0e10cSrcweir             e.printStackTrace(System.err);
373cdf0e10cSrcweir         }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir         return xComponent ;
376cdf0e10cSrcweir     }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir }
379