Java Code Examples for com.sun.star.lang.XMultiComponentFactory#createInstanceWithContext()
The following examples show how to use
com.sun.star.lang.XMultiComponentFactory#createInstanceWithContext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractInliner.java From yarg with Apache License 2.0 | 6 votes |
protected void insertImage(XComponent document, OfficeResourceProvider officeResourceProvider, XText destination, XTextRange textRange, Image image) throws Exception { XMultiServiceFactory xFactory = as(XMultiServiceFactory.class, document); XComponentContext xComponentContext = officeResourceProvider.getXComponentContext(); XMultiComponentFactory serviceManager = xComponentContext.getServiceManager(); Object oImage = xFactory.createInstance(TEXT_GRAPHIC_OBJECT); Object oGraphicProvider = serviceManager.createInstanceWithContext(GRAPHIC_PROVIDER_OBJECT, xComponentContext); XGraphicProvider xGraphicProvider = as(XGraphicProvider.class, oGraphicProvider); XPropertySet imageProperties = buildImageProperties(xGraphicProvider, oImage, image.imageContent); XTextContent xTextContent = as(XTextContent.class, oImage); destination.insertTextContent(textRange, xTextContent, true); setImageSize(image.width, image.height, oImage, imageProperties); }
Example 2
Source File: OpenOfficeWorker.java From scipio-erp with Apache License 2.0 | 5 votes |
public static List<String> getFilterNames(XMultiComponentFactory xmulticomponentfactory) throws Exception { XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xmulticomponentfactory); Object oDefaultContext = xPropertySet.getPropertyValue("DefaultContext"); XComponentContext xComponentContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, oDefaultContext); Object filterFactory = xmulticomponentfactory.createInstanceWithContext("com.sun.star.document.FilterFactory", xComponentContext); XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, filterFactory); String [] filterNames = xNameAccess.getElementNames(); //String [] serviceNames = filterFactory.getAvailableServiceNames(); for (int i=0; i < filterNames.length; i++) { String s = filterNames[i]; Debug.logInfo(s, module); /* if (s.toLowerCase().indexOf("filter") >= 0) { Debug.logInfo("FILTER: " + s, module); } if (s.toLowerCase().indexOf("desktop") >= 0) { Debug.logInfo("DESKTOP: " + s, module); } */ } List<String> filterNameList = UtilMisc.toListArray(filterNames); return filterNameList; }
Example 3
Source File: DocumentHelper.java From libreoffice-starter-extension with MIT License | 5 votes |
/** Returns the curerent XDesktop */ public static XDesktop getCurrentDesktop(XComponentContext xContext) { XMultiComponentFactory xMCF = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class, xContext.getServiceManager()); Object desktop = null; try { desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext); } catch (Exception e) { return null; } return (XDesktop) UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop); }
Example 4
Source File: HighlightText.java From kkFileViewOfficeEdit with Apache License 2.0 | 4 votes |
private boolean tryLoadingLibrary( XMultiComponentFactory xmcf, XScriptContext context, String name) { System.err.println("Try to load ScriptBindingLibrary"); try { Object obj = xmcf.createInstanceWithContext( "com.sun.star.script.Application" + name + "LibraryContainer", context.getComponentContext()); XLibraryContainer xLibraryContainer = (XLibraryContainer) UnoRuntime.queryInterface(XLibraryContainer.class, obj); System.err.println("Got XLibraryContainer"); Object serviceObj = context.getComponentContext().getValueByName( "/singletons/com.sun.star.util.theMacroExpander"); XMacroExpander xme = (XMacroExpander) AnyConverter.toObject( new Type(XMacroExpander.class), serviceObj); String bootstrapName = "bootstraprc"; if (System.getProperty("os.name").startsWith("Windows")) { bootstrapName = "bootstrap.ini"; } String libURL = xme.expandMacros( "${$OOO_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" + "/share/basic/ScriptBindingLibrary/" + name.toLowerCase() + ".xlb/"); System.err.println("libURL is: " + libURL); xLibraryContainer.createLibraryLink( "ScriptBindingLibrary", libURL, false); System.err.println("liblink created"); } catch (com.sun.star.uno.Exception e) { System.err.println("Got an exception loading lib: " + e.getMessage()); return false; } return true; }
Example 5
Source File: HighlightText.java From kkFileView with Apache License 2.0 | 4 votes |
private boolean tryLoadingLibrary( XMultiComponentFactory xmcf, XScriptContext context, String name) { System.err.println("Try to load ScriptBindingLibrary"); try { Object obj = xmcf.createInstanceWithContext( "com.sun.star.script.Application" + name + "LibraryContainer", context.getComponentContext()); XLibraryContainer xLibraryContainer = (XLibraryContainer) UnoRuntime.queryInterface(XLibraryContainer.class, obj); System.err.println("Got XLibraryContainer"); Object serviceObj = context.getComponentContext().getValueByName( "/singletons/com.sun.star.util.theMacroExpander"); XMacroExpander xme = (XMacroExpander) AnyConverter.toObject( new Type(XMacroExpander.class), serviceObj); String bootstrapName = "bootstraprc"; if (System.getProperty("os.name").startsWith("Windows")) { bootstrapName = "bootstrap.ini"; } String libURL = xme.expandMacros( "${$OOO_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" + "/share/basic/ScriptBindingLibrary/" + name.toLowerCase() + ".xlb/"); System.err.println("libURL is: " + libURL); xLibraryContainer.createLibraryLink( "ScriptBindingLibrary", libURL, false); System.err.println("liblink created"); } catch (com.sun.star.uno.Exception e) { System.err.println("Got an exception loading lib: " + e.getMessage()); return false; } return true; }
Example 6
Source File: OpenOfficeWorker.java From scipio-erp with Apache License 2.0 | 4 votes |
public static void convertOODocToFile(XMultiComponentFactory xmulticomponentfactory, String fileInPath, String fileOutPath, String outputMimeType) throws FileNotFoundException, IOException, MalformedURLException, Exception { // Converting the document to the favoured type // Query for the XPropertySet interface. XPropertySet xpropertysetMultiComponentFactory = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xmulticomponentfactory); // Get the default context from the office server. Object objectDefaultContext = xpropertysetMultiComponentFactory.getPropertyValue("DefaultContext"); // Query for the interface XComponentContext. XComponentContext xcomponentcontext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, objectDefaultContext); /* A desktop environment contains tasks with one or more frames in which components can be loaded. Desktop is the environment for components which can instanciate within frames. */ Object desktopObj = xmulticomponentfactory.createInstanceWithContext("com.sun.star.frame.Desktop", xcomponentcontext); //XDesktop desktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktopObj); XComponentLoader xcomponentloader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktopObj); // Preparing properties for loading the document PropertyValue propertyvalue[] = new PropertyValue[ 2 ]; // Setting the flag for hidding the open document propertyvalue[ 0 ] = new PropertyValue(); propertyvalue[ 0 ].Name = "Hidden"; propertyvalue[ 0 ].Value = Boolean.valueOf(false); propertyvalue[ 1 ] = new PropertyValue(); propertyvalue[ 1 ].Name = "UpdateDocMode"; propertyvalue[ 1 ].Value = "1"; // Loading the wanted document String stringUrl = convertToUrl(fileInPath, xcomponentcontext); Debug.logInfo("stringUrl:" + stringUrl, module); Object objectDocumentToStore = xcomponentloader.loadComponentFromURL(stringUrl, "_blank", 0, propertyvalue); // Getting an object that will offer a simple way to store a document to a URL. XStorable xstorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, objectDocumentToStore); // Preparing properties for converting the document propertyvalue = new PropertyValue[ 3 ]; // Setting the flag for overwriting propertyvalue[ 0 ] = new PropertyValue(); propertyvalue[ 0 ].Name = "Overwrite"; propertyvalue[ 0 ].Value = Boolean.valueOf(true); // Setting the filter name // Preparing properties for converting the document String filterName = getFilterNameFromMimeType(outputMimeType); propertyvalue[ 1 ] = new PropertyValue(); propertyvalue[ 1 ].Name = "FilterName"; propertyvalue[ 1 ].Value = filterName; propertyvalue[2] = new PropertyValue(); propertyvalue[2].Name = "CompressionMode"; propertyvalue[2].Value = "1"; // Storing and converting the document //File newFile = new File(stringConvertedFile); //newFile.createNewFile(); String stringConvertedFile = convertToUrl(fileOutPath, xcomponentcontext); Debug.logInfo("stringConvertedFile: "+stringConvertedFile, module); xstorable.storeToURL(stringConvertedFile, propertyvalue); // Getting the method dispose() for closing the document XComponent xcomponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xstorable); // Closing the converted document xcomponent.dispose(); return; }
Example 7
Source File: OpenOfficeWorker.java From scipio-erp with Apache License 2.0 | 4 votes |
public static OpenOfficeByteArrayOutputStream convertOODocByteStreamToByteStream(XMultiComponentFactory xmulticomponentfactory, OpenOfficeByteArrayInputStream is, String inputMimeType, String outputMimeType) throws Exception { // Query for the XPropertySet interface. XPropertySet xpropertysetMultiComponentFactory = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xmulticomponentfactory); // Get the default context from the office server. Object objectDefaultContext = xpropertysetMultiComponentFactory.getPropertyValue("DefaultContext"); // Query for the interface XComponentContext. XComponentContext xcomponentcontext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, objectDefaultContext); /* A desktop environment contains tasks with one or more frames in which components can be loaded. Desktop is the environment for components which can instanciate within frames. */ Object desktopObj = xmulticomponentfactory.createInstanceWithContext("com.sun.star.frame.Desktop", xcomponentcontext); //XDesktop desktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktopObj); XComponentLoader xcomponentloader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktopObj); // Preparing properties for loading the document PropertyValue propertyvalue[] = new PropertyValue[2]; // Setting the flag for hidding the open document propertyvalue[0] = new PropertyValue(); propertyvalue[0].Name = "Hidden"; propertyvalue[0].Value = Boolean.TRUE; // propertyvalue[1] = new PropertyValue(); propertyvalue[1].Name = "InputStream"; propertyvalue[1].Value = is; // Loading the wanted document Object objectDocumentToStore = xcomponentloader.loadComponentFromURL("private:stream", "_blank", 0, propertyvalue); if (objectDocumentToStore == null) { Debug.logError("Could not get objectDocumentToStore object from xcomponentloader.loadComponentFromURL", module); } // Getting an object that will offer a simple way to store a document to a URL. XStorable xstorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, objectDocumentToStore); if (xstorable == null) { Debug.logError("Could not get XStorable object from UnoRuntime.queryInterface", module); } // Preparing properties for converting the document String filterName = getFilterNameFromMimeType(outputMimeType); propertyvalue = new PropertyValue[4]; propertyvalue[0] = new PropertyValue(); propertyvalue[0].Name = "OutputStream"; OpenOfficeByteArrayOutputStream os = new OpenOfficeByteArrayOutputStream(); propertyvalue[0].Value = os; // Setting the filter name propertyvalue[1] = new PropertyValue(); propertyvalue[1].Name = "FilterName"; propertyvalue[1].Value = filterName; // Setting the flag for overwriting propertyvalue[3] = new PropertyValue(); propertyvalue[3].Name = "Overwrite"; propertyvalue[3].Value = Boolean.TRUE; // For PDFs propertyvalue[2] = new PropertyValue(); propertyvalue[2].Name = "CompressionMode"; propertyvalue[2].Value = "1"; xstorable.storeToURL("private:stream", propertyvalue); //xstorable.storeToURL("file:///home/byersa/testdoc1_file.pdf", propertyvalue); // Getting the method dispose() for closing the document XComponent xcomponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xstorable); // Closing the converted document xcomponent.dispose(); return os; }
Example 8
Source File: TerminationOpenoffice.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * Gets the current component. * @return the current component * @throws Exception * the exception */ public static XComponent getCurrentComponent() throws Exception { XComponentContext xRemoteContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null); // XComponentContext xRemoteContext = // com.sun.star.comp.helper.Bootstrap.bootstrap(); XMultiComponentFactory xRemoteServiceManager = xRemoteContext.getServiceManager(); Object desktop = xRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xRemoteContext); //$NON-NLS-1$ XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop); XComponent currentComponent = xDesktop.getCurrentComponent(); return currentComponent; }
Example 9
Source File: TerminationOpenoffice.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * Gets the current component. * @return the current component * @throws Exception * the exception */ public static XComponent getCurrentComponent() throws Exception { XComponentContext xRemoteContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null); // XComponentContext xRemoteContext = // com.sun.star.comp.helper.Bootstrap.bootstrap(); XMultiComponentFactory xRemoteServiceManager = xRemoteContext.getServiceManager(); Object desktop = xRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xRemoteContext); //$NON-NLS-1$ XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop); XComponent currentComponent = xDesktop.getCurrentComponent(); return currentComponent; }