1*a1b4a26bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*a1b4a26bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*a1b4a26bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*a1b4a26bSAndrew Rist * distributed with this work for additional information 6*a1b4a26bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*a1b4a26bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*a1b4a26bSAndrew Rist * "License"); you may not use this file except in compliance 9*a1b4a26bSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*a1b4a26bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*a1b4a26bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*a1b4a26bSAndrew Rist * software distributed under the License is distributed on an 15*a1b4a26bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*a1b4a26bSAndrew Rist * KIND, either express or implied. See the License for the 17*a1b4a26bSAndrew Rist * specific language governing permissions and limitations 18*a1b4a26bSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*a1b4a26bSAndrew Rist *************************************************************/ 21*a1b4a26bSAndrew Rist 22*a1b4a26bSAndrew Rist 23cdf0e10cSrcweir package com.sun.star.wizards.common; 24cdf0e10cSrcweir 25cdf0e10cSrcweir // import java.util.Date; 26cdf0e10cSrcweir 27cdf0e10cSrcweir // import com.sun.star.awt.XToolkit; 28cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 29cdf0e10cSrcweir // import com.sun.star.frame.XDesktop; 30cdf0e10cSrcweir // import com.sun.star.frame.XFrame; 31cdf0e10cSrcweir // import com.sun.star.frame.XFramesSupplier; 32cdf0e10cSrcweir 33cdf0e10cSrcweir import com.sun.star.lang.WrappedTargetException; 34cdf0e10cSrcweir import com.sun.star.lang.XComponent; 35cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 36cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 37cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument; 38cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 39cdf0e10cSrcweir import com.sun.star.uno.Any; 40cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 41cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 42cdf0e10cSrcweir import com.sun.star.uno.XNamingService; 43cdf0e10cSrcweir import com.sun.star.util.XURLTransformer; 44cdf0e10cSrcweir import com.sun.star.lang.Locale; 45cdf0e10cSrcweir import com.sun.star.uno.XInterface; 46cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver; 47cdf0e10cSrcweir import com.sun.star.comp.helper.Bootstrap; 48cdf0e10cSrcweir import com.sun.star.container.NoSuchElementException; 49cdf0e10cSrcweir import com.sun.star.container.XEnumeration; 50cdf0e10cSrcweir import com.sun.star.container.XHierarchicalNameAccess; 51cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 52cdf0e10cSrcweir import com.sun.star.util.XStringSubstitution; 53cdf0e10cSrcweir import com.sun.star.frame.*; 54cdf0e10cSrcweir import com.sun.star.i18n.KParseType; 55cdf0e10cSrcweir import com.sun.star.i18n.ParseResult; 56cdf0e10cSrcweir import com.sun.star.i18n.XCharacterClassification; 57cdf0e10cSrcweir 58cdf0e10cSrcweir public class Desktop 59cdf0e10cSrcweir { 60cdf0e10cSrcweir 61cdf0e10cSrcweir /** Creates a new instance of Desktop */ Desktop()62cdf0e10cSrcweir public Desktop() 63cdf0e10cSrcweir { 64cdf0e10cSrcweir } 65cdf0e10cSrcweir getDesktop(XMultiServiceFactory xMSF)66cdf0e10cSrcweir public static XDesktop getDesktop(XMultiServiceFactory xMSF) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir com.sun.star.uno.XInterface xInterface = null; 69cdf0e10cSrcweir XDesktop xDesktop = null; 70cdf0e10cSrcweir if (xMSF != null) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir try 73cdf0e10cSrcweir { 74cdf0e10cSrcweir xInterface = (com.sun.star.uno.XInterface) xMSF.createInstance("com.sun.star.frame.Desktop"); 75cdf0e10cSrcweir xDesktop = UnoRuntime.queryInterface(XDesktop.class, xInterface); 76cdf0e10cSrcweir } 77cdf0e10cSrcweir catch (Exception exception) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir exception.printStackTrace(System.out); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir } 82cdf0e10cSrcweir else 83cdf0e10cSrcweir { 84cdf0e10cSrcweir System.out.println("Can't create a desktop. null pointer !"); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir return xDesktop; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir getActiveFrame(XMultiServiceFactory xMSF)89cdf0e10cSrcweir public static XFrame getActiveFrame(XMultiServiceFactory xMSF) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir XDesktop xDesktop = getDesktop(xMSF); 92cdf0e10cSrcweir XFramesSupplier xFrameSuppl = UnoRuntime.queryInterface(XFramesSupplier.class, xDesktop); 93cdf0e10cSrcweir return xFrameSuppl.getActiveFrame(); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir getActiveComponent(XMultiServiceFactory _xMSF)96cdf0e10cSrcweir public static XComponent getActiveComponent(XMultiServiceFactory _xMSF) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir XFrame xFrame = getActiveFrame(_xMSF); 99cdf0e10cSrcweir return UnoRuntime.queryInterface(XComponent.class, xFrame.getController().getModel()); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir getActiveTextDocument(XMultiServiceFactory _xMSF)102cdf0e10cSrcweir public static XTextDocument getActiveTextDocument(XMultiServiceFactory _xMSF) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir XComponent xComponent = getActiveComponent(_xMSF); 105cdf0e10cSrcweir return UnoRuntime.queryInterface(XTextDocument.class, xComponent); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir getActiveSpreadsheetDocument(XMultiServiceFactory _xMSF)108cdf0e10cSrcweir public static XSpreadsheetDocument getActiveSpreadsheetDocument(XMultiServiceFactory _xMSF) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir XComponent xComponent = getActiveComponent(_xMSF); 111cdf0e10cSrcweir return UnoRuntime.queryInterface(XSpreadsheetDocument.class, xComponent); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir getDispatcher(XMultiServiceFactory xMSF, XFrame xFrame, String _stargetframe, com.sun.star.util.URL oURL)114cdf0e10cSrcweir public static XDispatch getDispatcher(XMultiServiceFactory xMSF, XFrame xFrame, String _stargetframe, com.sun.star.util.URL oURL) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir try 117cdf0e10cSrcweir { 118cdf0e10cSrcweir com.sun.star.util.URL[] oURLArray = new com.sun.star.util.URL[1]; 119cdf0e10cSrcweir oURLArray[0] = oURL; 120cdf0e10cSrcweir XDispatchProvider xDispatchProvider = UnoRuntime.queryInterface(XDispatchProvider.class, xFrame); 121cdf0e10cSrcweir return xDispatchProvider.queryDispatch(oURLArray[0], _stargetframe, FrameSearchFlag.ALL); // "_self" 122cdf0e10cSrcweir } 123cdf0e10cSrcweir catch (Exception e) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir e.printStackTrace(System.out); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir return null; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir getDispatchURL(XMultiServiceFactory xMSF, String _sURL)130cdf0e10cSrcweir public static com.sun.star.util.URL getDispatchURL(XMultiServiceFactory xMSF, String _sURL) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir try 133cdf0e10cSrcweir { 134cdf0e10cSrcweir Object oTransformer = xMSF.createInstance("com.sun.star.util.URLTransformer"); 135cdf0e10cSrcweir XURLTransformer xTransformer = UnoRuntime.queryInterface(XURLTransformer.class, oTransformer); 136cdf0e10cSrcweir com.sun.star.util.URL[] oURL = new com.sun.star.util.URL[1]; 137cdf0e10cSrcweir oURL[0] = new com.sun.star.util.URL(); 138cdf0e10cSrcweir oURL[0].Complete = _sURL; 139cdf0e10cSrcweir xTransformer.parseStrict(oURL); 140cdf0e10cSrcweir return oURL[0]; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir catch (Exception e) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir e.printStackTrace(System.out); 145cdf0e10cSrcweir } 146cdf0e10cSrcweir return null; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir dispatchURL(XMultiServiceFactory xMSF, String sURL, XFrame xFrame, String _stargetframe)149cdf0e10cSrcweir public static void dispatchURL(XMultiServiceFactory xMSF, String sURL, XFrame xFrame, String _stargetframe) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir com.sun.star.util.URL oURL = getDispatchURL(xMSF, sURL); 152cdf0e10cSrcweir XDispatch xDispatch = getDispatcher(xMSF, xFrame, _stargetframe, oURL); 153cdf0e10cSrcweir dispatchURL(xDispatch, oURL); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir dispatchURL(XMultiServiceFactory xMSF, String sURL, XFrame xFrame)156cdf0e10cSrcweir public static void dispatchURL(XMultiServiceFactory xMSF, String sURL, XFrame xFrame) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir dispatchURL(xMSF, sURL, xFrame, PropertyNames.EMPTY_STRING); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir dispatchURL(XDispatch _xDispatch, com.sun.star.util.URL oURL)161cdf0e10cSrcweir public static void dispatchURL(XDispatch _xDispatch, com.sun.star.util.URL oURL) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir PropertyValue[] oArg = new PropertyValue[0]; 164cdf0e10cSrcweir _xDispatch.dispatch(oURL, oArg); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir getMultiComponentFactory()167cdf0e10cSrcweir public static XMultiComponentFactory getMultiComponentFactory() throws com.sun.star.uno.Exception, RuntimeException, java.lang.Exception 168cdf0e10cSrcweir { 169cdf0e10cSrcweir XComponentContext xcomponentcontext = Bootstrap.createInitialComponentContext(null); 170cdf0e10cSrcweir // initial serviceManager 171cdf0e10cSrcweir return xcomponentcontext.getServiceManager(); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir connect(String connectStr)174cdf0e10cSrcweir public static XMultiServiceFactory connect(String connectStr) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException, Exception 175cdf0e10cSrcweir { 176cdf0e10cSrcweir XMultiComponentFactory componentFactory = getMultiComponentFactory(); 177cdf0e10cSrcweir Object xUrlResolver = componentFactory.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", null ); 178cdf0e10cSrcweir XUnoUrlResolver urlResolver = UnoRuntime.queryInterface(XUnoUrlResolver.class, xUrlResolver); 179cdf0e10cSrcweir return UnoRuntime.queryInterface(XMultiServiceFactory.class, urlResolver.resolve( connectStr ) ); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir getIncrementSuffix(XNameAccess xElementContainer, String ElementName)182cdf0e10cSrcweir public static String getIncrementSuffix(XNameAccess xElementContainer, String ElementName) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir boolean bElementexists = true; 185cdf0e10cSrcweir int i = 1; 186cdf0e10cSrcweir String sIncSuffix = PropertyNames.EMPTY_STRING; 187cdf0e10cSrcweir String BaseName = ElementName; 188cdf0e10cSrcweir while (bElementexists) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir bElementexists = xElementContainer.hasByName(ElementName); 191cdf0e10cSrcweir if (bElementexists) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir i += 1; 194cdf0e10cSrcweir ElementName = BaseName + Integer.toString(i); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir } 197cdf0e10cSrcweir if (i > 1) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir sIncSuffix = Integer.toString(i); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir return sIncSuffix; 202cdf0e10cSrcweir } 203cdf0e10cSrcweir getIncrementSuffix(XHierarchicalNameAccess xElementContainer, String ElementName)204cdf0e10cSrcweir public static String getIncrementSuffix(XHierarchicalNameAccess xElementContainer, String ElementName) 205cdf0e10cSrcweir { 206cdf0e10cSrcweir boolean bElementexists = true; 207cdf0e10cSrcweir int i = 1; 208cdf0e10cSrcweir String sIncSuffix = PropertyNames.EMPTY_STRING; 209cdf0e10cSrcweir String BaseName = ElementName; 210cdf0e10cSrcweir while (bElementexists) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir bElementexists = xElementContainer.hasByHierarchicalName(ElementName); 213cdf0e10cSrcweir if (bElementexists) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir i += 1; 216cdf0e10cSrcweir ElementName = BaseName + Integer.toString(i); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir } 219cdf0e10cSrcweir if (i > 1) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir sIncSuffix = Integer.toString(i); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir return sIncSuffix; 224cdf0e10cSrcweir } 225cdf0e10cSrcweir checkforfirstSpecialCharacter(XMultiServiceFactory _xMSF, String _sString, Locale _aLocale)226cdf0e10cSrcweir public static int checkforfirstSpecialCharacter(XMultiServiceFactory _xMSF, String _sString, Locale _aLocale) 227cdf0e10cSrcweir { 228cdf0e10cSrcweir try 229cdf0e10cSrcweir { 230cdf0e10cSrcweir int nStartFlags = com.sun.star.i18n.KParseTokens.ANY_LETTER_OR_NUMBER + com.sun.star.i18n.KParseTokens.ASC_UNDERSCORE; 231cdf0e10cSrcweir Object ocharservice = _xMSF.createInstance("com.sun.star.i18n.CharacterClassification"); 232cdf0e10cSrcweir XCharacterClassification xCharacterClassification = UnoRuntime.queryInterface(XCharacterClassification.class, ocharservice); 233cdf0e10cSrcweir ParseResult aResult = xCharacterClassification.parsePredefinedToken(KParseType.IDENTNAME, _sString, 0, _aLocale, nStartFlags, PropertyNames.EMPTY_STRING, nStartFlags, PropertyNames.SPACE); 234cdf0e10cSrcweir return aResult.EndPos; 235cdf0e10cSrcweir } 236cdf0e10cSrcweir catch (Exception e) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir e.printStackTrace(System.out); 239cdf0e10cSrcweir return -1; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir } 242cdf0e10cSrcweir removeSpecialCharacters(XMultiServiceFactory _xMSF, Locale _aLocale, String _sname)243cdf0e10cSrcweir public static String removeSpecialCharacters(XMultiServiceFactory _xMSF, Locale _aLocale, String _sname) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir String snewname = _sname; 246cdf0e10cSrcweir int i = 0; 247cdf0e10cSrcweir while (i < snewname.length()) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir i = Desktop.checkforfirstSpecialCharacter(_xMSF, snewname, _aLocale); 250cdf0e10cSrcweir if (i < snewname.length()) 251cdf0e10cSrcweir { 252cdf0e10cSrcweir String sspecialchar = snewname.substring(i, i + 1); 253cdf0e10cSrcweir snewname = JavaTools.replaceSubString(snewname, PropertyNames.EMPTY_STRING, sspecialchar); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir } 256cdf0e10cSrcweir return snewname; 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir /** 260cdf0e10cSrcweir * Checks if the passed Element Name already exists in the ElementContainer. If yes it appends a 261cdf0e10cSrcweir * suffix to make it unique 262cdf0e10cSrcweir * @param xElementContainer 263cdf0e10cSrcweir * @param sElementName 264cdf0e10cSrcweir * @return a unique Name ready to be added to the container. 265cdf0e10cSrcweir */ getUniqueName(XNameAccess xElementContainer, String sElementName)266cdf0e10cSrcweir public static String getUniqueName(XNameAccess xElementContainer, String sElementName) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir String sIncSuffix = getIncrementSuffix(xElementContainer, sElementName); 269cdf0e10cSrcweir return sElementName + sIncSuffix; 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir /** 273cdf0e10cSrcweir * Checks if the passed Element Name already exists in the ElementContainer. If yes it appends a 274cdf0e10cSrcweir * suffix to make it unique 275cdf0e10cSrcweir * @param xElementContainer 276cdf0e10cSrcweir * @param sElementName 277cdf0e10cSrcweir * @return a unique Name ready to be added to the container. 278cdf0e10cSrcweir */ getUniqueName(XHierarchicalNameAccess xElementContainer, String sElementName)279cdf0e10cSrcweir public static String getUniqueName(XHierarchicalNameAccess xElementContainer, String sElementName) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir String sIncSuffix = getIncrementSuffix(xElementContainer, sElementName); 282cdf0e10cSrcweir return sElementName + sIncSuffix; 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir /** 286cdf0e10cSrcweir * Checks if the passed Element Name already exists in the list If yes it appends a 287cdf0e10cSrcweir * suffix to make it unique 288cdf0e10cSrcweir * @param _slist 289cdf0e10cSrcweir * @param _sElementName 290cdf0e10cSrcweir * @param _sSuffixSeparator 291cdf0e10cSrcweir * @return a unique Name not being in the passed list. 292cdf0e10cSrcweir */ getUniqueName(String[] _slist, String _sElementName, String _sSuffixSeparator)293cdf0e10cSrcweir public static String getUniqueName(String[] _slist, String _sElementName, String _sSuffixSeparator) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir int a = 2; 296cdf0e10cSrcweir String scompname = _sElementName; 297cdf0e10cSrcweir boolean bElementexists = true; 298cdf0e10cSrcweir if (_slist == null) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir return _sElementName; 301cdf0e10cSrcweir } 302cdf0e10cSrcweir if (_slist.length == 0) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir return _sElementName; 305cdf0e10cSrcweir } 306cdf0e10cSrcweir while (bElementexists) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir for (int i = 0; i < _slist.length; i++) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir if (JavaTools.FieldInList(_slist, scompname) == -1) 311cdf0e10cSrcweir { 312cdf0e10cSrcweir return scompname; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir } 315cdf0e10cSrcweir scompname = _sElementName + _sSuffixSeparator + a++; 316cdf0e10cSrcweir } 317cdf0e10cSrcweir return PropertyNames.EMPTY_STRING; 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir /** 321cdf0e10cSrcweir * @deprecated use Configuration.getConfigurationRoot() with the same parameters instead 322cdf0e10cSrcweir * @param xMSF 323cdf0e10cSrcweir * @param KeyName 324cdf0e10cSrcweir * @param bForUpdate 325cdf0e10cSrcweir * @return 326cdf0e10cSrcweir */ getRegistryKeyContent(XMultiServiceFactory xMSF, String KeyName, boolean bForUpdate)327cdf0e10cSrcweir public static XInterface getRegistryKeyContent(XMultiServiceFactory xMSF, String KeyName, boolean bForUpdate) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir try 330cdf0e10cSrcweir { 331cdf0e10cSrcweir Object oConfigProvider; 332cdf0e10cSrcweir PropertyValue[] aNodePath = new PropertyValue[1]; 333cdf0e10cSrcweir oConfigProvider = xMSF.createInstance("com.sun.star.configuration.ConfigurationProvider"); 334cdf0e10cSrcweir aNodePath[0] = new PropertyValue(); 335cdf0e10cSrcweir aNodePath[0].Name = "nodepath"; 336cdf0e10cSrcweir aNodePath[0].Value = KeyName; 337cdf0e10cSrcweir XMultiServiceFactory xMSFConfig = UnoRuntime.queryInterface(XMultiServiceFactory.class, oConfigProvider); 338cdf0e10cSrcweir if (bForUpdate) 339cdf0e10cSrcweir { 340cdf0e10cSrcweir return (XInterface) xMSFConfig.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", aNodePath); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir else 343cdf0e10cSrcweir { 344cdf0e10cSrcweir return (XInterface) xMSFConfig.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath); 345cdf0e10cSrcweir } 346cdf0e10cSrcweir } 347cdf0e10cSrcweir catch (Exception exception) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir exception.printStackTrace(System.out); 350cdf0e10cSrcweir return null; 351cdf0e10cSrcweir } 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir /** 355cdf0e10cSrcweir * @deprecated used to retrieve the most common paths used in the office application 356cdf0e10cSrcweir * @author bc93774 357cdf0e10cSrcweir * 358cdf0e10cSrcweir */ 359cdf0e10cSrcweir public class OfficePathRetriever 360cdf0e10cSrcweir { 361cdf0e10cSrcweir 362cdf0e10cSrcweir public String TemplatePath; 363cdf0e10cSrcweir public String BitmapPath; 364cdf0e10cSrcweir public String UserTemplatePath; 365cdf0e10cSrcweir public String WorkPath; 366cdf0e10cSrcweir OfficePathRetriever(XMultiServiceFactory xMSF)367cdf0e10cSrcweir public OfficePathRetriever(XMultiServiceFactory xMSF) 368cdf0e10cSrcweir { 369cdf0e10cSrcweir try 370cdf0e10cSrcweir { 371cdf0e10cSrcweir TemplatePath = FileAccess.getOfficePath(xMSF, "Template", "share", "/wizard"); 372cdf0e10cSrcweir UserTemplatePath = FileAccess.getOfficePath(xMSF, "Template", "user", PropertyNames.EMPTY_STRING); 373cdf0e10cSrcweir BitmapPath = FileAccess.combinePaths(xMSF, TemplatePath, "/../wizard/bitmap"); 374cdf0e10cSrcweir WorkPath = FileAccess.getOfficePath(xMSF, "Work", PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING); 375cdf0e10cSrcweir } 376cdf0e10cSrcweir catch (NoValidPathException nopathexception) 377cdf0e10cSrcweir { 378cdf0e10cSrcweir } 379cdf0e10cSrcweir } 380cdf0e10cSrcweir } 381cdf0e10cSrcweir getTemplatePath(XMultiServiceFactory _xMSF)382cdf0e10cSrcweir public static String getTemplatePath(XMultiServiceFactory _xMSF) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir try 385cdf0e10cSrcweir { 386cdf0e10cSrcweir return FileAccess.getOfficePath(_xMSF, "Template", "share", "/wizard"); 387cdf0e10cSrcweir } 388cdf0e10cSrcweir catch (NoValidPathException nopathexception) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir } 391cdf0e10cSrcweir return PropertyNames.EMPTY_STRING; 392cdf0e10cSrcweir } 393cdf0e10cSrcweir getUserTemplatePath(XMultiServiceFactory _xMSF)394cdf0e10cSrcweir public static String getUserTemplatePath(XMultiServiceFactory _xMSF) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir try 397cdf0e10cSrcweir { 398cdf0e10cSrcweir return FileAccess.getOfficePath(_xMSF, "Template", "user", PropertyNames.EMPTY_STRING); 399cdf0e10cSrcweir } 400cdf0e10cSrcweir catch (NoValidPathException nopathexception) 401cdf0e10cSrcweir { 402cdf0e10cSrcweir } 403cdf0e10cSrcweir return PropertyNames.EMPTY_STRING; 404cdf0e10cSrcweir } 405cdf0e10cSrcweir getBitmapPath(XMultiServiceFactory _xMSF)406cdf0e10cSrcweir public static String getBitmapPath(XMultiServiceFactory _xMSF) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir try 409cdf0e10cSrcweir { 410cdf0e10cSrcweir return FileAccess.combinePaths(_xMSF, getTemplatePath(_xMSF), "/../wizard/bitmap"); 411cdf0e10cSrcweir } 412cdf0e10cSrcweir catch (NoValidPathException nopathexception) 413cdf0e10cSrcweir { 414cdf0e10cSrcweir } 415cdf0e10cSrcweir return PropertyNames.EMPTY_STRING; 416cdf0e10cSrcweir } 417cdf0e10cSrcweir getWorkPath(XMultiServiceFactory _xMSF)418cdf0e10cSrcweir public static String getWorkPath(XMultiServiceFactory _xMSF) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir try 421cdf0e10cSrcweir { 422cdf0e10cSrcweir return FileAccess.getOfficePath(_xMSF, "Work", PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir catch (NoValidPathException nopathexception) 425cdf0e10cSrcweir { 426cdf0e10cSrcweir } 427cdf0e10cSrcweir return PropertyNames.EMPTY_STRING; 428cdf0e10cSrcweir } 429cdf0e10cSrcweir createStringSubstitution(XMultiServiceFactory xMSF)430cdf0e10cSrcweir public static XStringSubstitution createStringSubstitution(XMultiServiceFactory xMSF) 431cdf0e10cSrcweir { 432cdf0e10cSrcweir Object xPathSubst = null; 433cdf0e10cSrcweir try 434cdf0e10cSrcweir { 435cdf0e10cSrcweir xPathSubst = xMSF.createInstance("com.sun.star.util.PathSubstitution"); 436cdf0e10cSrcweir } 437cdf0e10cSrcweir catch (com.sun.star.uno.Exception e) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir e.printStackTrace(); 440cdf0e10cSrcweir } 441cdf0e10cSrcweir if (xPathSubst != null) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir return UnoRuntime.queryInterface(XStringSubstitution.class, xPathSubst); 444cdf0e10cSrcweir } 445cdf0e10cSrcweir else 446cdf0e10cSrcweir { 447cdf0e10cSrcweir return null; 448cdf0e10cSrcweir } 449cdf0e10cSrcweir } 450cdf0e10cSrcweir 451cdf0e10cSrcweir /** 452cdf0e10cSrcweir * This method searches (and hopefully finds...) a frame 453cdf0e10cSrcweir * with a componentWindow. 454cdf0e10cSrcweir * It does it in three phases: 455cdf0e10cSrcweir * 1. Check if the given desktop argument has a componentWindow. 456cdf0e10cSrcweir * If it is null, the myFrame argument is taken. 457cdf0e10cSrcweir * 2. Go up the tree of frames and search a frame with a component window. 458cdf0e10cSrcweir * 3. Get from the desktop all the components, and give the first one 459cdf0e10cSrcweir * which has a frame. 460cdf0e10cSrcweir * @param xMSF 461cdf0e10cSrcweir * @param myFrame 462cdf0e10cSrcweir * @param desktop 463cdf0e10cSrcweir * @return 464cdf0e10cSrcweir * @throws NoSuchElementException 465cdf0e10cSrcweir * @throws WrappedTargetException 466cdf0e10cSrcweir */ findAFrame(XMultiServiceFactory xMSF, XFrame myFrame, XFrame desktop)467cdf0e10cSrcweir public static XFrame findAFrame(XMultiServiceFactory xMSF, XFrame myFrame, XFrame desktop) 468cdf0e10cSrcweir throws NoSuchElementException, 469cdf0e10cSrcweir WrappedTargetException 470cdf0e10cSrcweir { 471cdf0e10cSrcweir if (desktop == null) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir desktop = myFrame; // we go up in the tree... 474cdf0e10cSrcweir } 475cdf0e10cSrcweir while (desktop != null && desktop.getComponentWindow() == null) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir desktop = desktop.findFrame("_parent", FrameSearchFlag.PARENT); 478cdf0e10cSrcweir } 479cdf0e10cSrcweir if (desktop == null) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir 482cdf0e10cSrcweir for (XEnumeration e = Desktop.getDesktop(xMSF).getComponents().createEnumeration(); e.hasMoreElements();) 483cdf0e10cSrcweir { 484cdf0e10cSrcweir 485cdf0e10cSrcweir Object comp = ((Any) e.nextElement()).getObject(); 486cdf0e10cSrcweir XModel xModel = UnoRuntime.queryInterface(XModel.class, comp); 487cdf0e10cSrcweir XFrame xFrame = xModel.getCurrentController().getFrame(); 488cdf0e10cSrcweir 489cdf0e10cSrcweir if (xFrame != null && xFrame.getComponentWindow() != null) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir return xFrame; 492cdf0e10cSrcweir } 493cdf0e10cSrcweir } 494cdf0e10cSrcweir } 495cdf0e10cSrcweir return desktop; 496cdf0e10cSrcweir } 497cdf0e10cSrcweir } 498