本文整理汇总了Java中com.sun.star.lang.XMultiComponentFactory.createInstanceWithContext方法的典型用法代码示例。如果您正苦于以下问题:Java XMultiComponentFactory.createInstanceWithContext方法的具体用法?Java XMultiComponentFactory.createInstanceWithContext怎么用?Java XMultiComponentFactory.createInstanceWithContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.star.lang.XMultiComponentFactory
的用法示例。
在下文中一共展示了XMultiComponentFactory.createInstanceWithContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertImage
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
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);
}
示例2: getCurrentDesktop
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
/**
* Returns the current XDesktop
* Returns null if it fails
*/
@Nullable
private static XDesktop getCurrentDesktop(XComponentContext xContext) throws Exception {
try {
if (xContext == null) {
return null;
}
XMultiComponentFactory xMCF = UnoRuntime.queryInterface(XMultiComponentFactory.class,
xContext.getServiceManager());
if (xMCF == null) {
return null;
}
Object desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
if (desktop == null) {
return null;
}
return UnoRuntime.queryInterface(XDesktop.class, desktop);
} catch (Exception e) {
printException(e); // all Exceptions thrown by UnoRuntime.queryInterface are caught
return null; // Return null as method failed
}
}
示例3: getCurrentDesktop
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
/**
* Returns the current XDesktop
* Returns null if it fails
*/
@Nullable
private static XDesktop getCurrentDesktop(XComponentContext xContext) {
try {
if (xContext == null) {
return null;
}
XMultiComponentFactory xMCF = UnoRuntime.queryInterface(XMultiComponentFactory.class,
xContext.getServiceManager());
if (xMCF == null) {
return null;
}
Object desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
if (desktop == null) {
return null;
}
return UnoRuntime.queryInterface(XDesktop.class, desktop);
} catch (Exception e) {
printException(e); // all Exceptions thrown by UnoRuntime.queryInterface are caught
return null; // Return null as method failed
}
}
示例4: initContext
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
private static XComponentLoader initContext() {
try {
XComponentContext xContext = Bootstrap.bootstrap();
XMultiComponentFactory xMCF = xContext.getServiceManager();
Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
return UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
} catch (Exception e) {
throw new LibreOfficeException(e);
}
}
示例5: getFilterNames
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
public static List 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 filterNameList = UtilMisc.toListArray(filterNames);
return filterNameList;
}
示例6: getCurrentDesktop
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
/** 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);
}
示例7: stopOffice
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
private void stopOffice() {
try {
if (componentContext != null) {
// Only the uno test suite which started the office can stop it
XMultiComponentFactory xMngr = componentContext.getServiceManager();
Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", componentContext);
XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, oDesktop);
xDesktop.terminate();
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: getWriterDocument
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
public static XTextDocument getWriterDocument() throws Exception {
XMultiComponentFactory xMngr = UnoSuite.getComponentContext().getServiceManager();
Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", UnoSuite.getComponentContext());
XComponentLoader xLoader = (XComponentLoader)UnoRuntime.queryInterface(
XComponentLoader.class, oDesktop);
XComponent xDoc = xLoader.loadComponentFromURL("private:factory/swriter", "_default",
FrameSearchFlag.ALL, new PropertyValue[0]);
return (XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, xDoc);
}
示例9: connect
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
/**
* To set up connection.
* @throws ConnectException if failure occurs
*/
public void connect() throws ConnectException {
LOGGER.fine(String.format("connecting with connectString '%s'", unoUrl));
try {
XComponentContext localContext = Bootstrap.createInitialComponentContext(null);
XMultiComponentFactory localServiceManager = localContext.getServiceManager();
Object urlResolver = localServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext);
XUnoUrlResolver unoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(XUnoUrlResolver.class, urlResolver);
Object initialObject = unoUrlResolver.resolve(unoUrl.getConnectString());
XPropertySet properties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, initialObject);
componentContext = OfficeUtils.cast(XComponentContext.class, properties.getPropertyValue("DefaultContext"));
serviceManager = componentContext.getServiceManager();
connected = true;
LOGGER.info(String.format("connected: '%s'", unoUrl));
OfficeConnectionEvent connectionEvent = new OfficeConnectionEvent(this);
for (OfficeConnectionEventListener listener : connectionEventListeners) {
listener.connected(connectionEvent);
}
} catch (NoConnectException connectException) {
throw new ConnectException(String.format("connection failed: '%s'; %s", unoUrl, connectException.getMessage()));
} catch (Exception exception) {
throw new OfficeException("connection failed: " + unoUrl, exception);
}
}
示例10: getConfigValue
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
private static String getConfigValue(String path, String name)
{
try
{
XMultiComponentFactory xMultiComponentFactory =
UNO.defaultContext.getServiceManager();
Object oProvider =
xMultiComponentFactory.createInstanceWithContext(
"com.sun.star.configuration.ConfigurationProvider", UNO.defaultContext);
XMultiServiceFactory xConfigurationServiceFactory =
UnoRuntime.queryInterface(XMultiServiceFactory.class,
oProvider);
PropertyValue[] lArgs = new PropertyValue[1];
lArgs[0] = new PropertyValue();
lArgs[0].Name = "nodepath";
lArgs[0].Value = path;
Object configAccess =
xConfigurationServiceFactory.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationAccess", lArgs);
XNameAccess xNameAccess =
UnoRuntime.queryInterface(XNameAccess.class, configAccess);
return xNameAccess.getByName(name).toString();
}
catch (Exception ex)
{
Logger.log(ex);
return "";
}
}
示例11: simpleBootstrap
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
private XDesktop simpleBootstrap(String pathToExecutable)
throws IllegalAccessException, InvocationTargetException, BootstrapException,
CreationException, IOException {
ClassLoader loader = ClassLoader.getSystemClassLoader();
if (loader instanceof URLClassLoader) {
URLClassLoader cl = (URLClassLoader) loader;
Class<URLClassLoader> sysclass = URLClassLoader.class;
try {
Method method = sysclass.getDeclaredMethod("addURL", URL.class);
method.setAccessible(true);
method.invoke(cl, new File(pathToExecutable).toURI().toURL());
} catch (SecurityException | NoSuchMethodException | MalformedURLException t) {
LOGGER.error("Error, could not add URL to system classloader", t);
cl.close();
throw new IOException("Error, could not add URL to system classloader", t);
}
} else {
LOGGER.error("Error occured, URLClassLoader expected but " + loader.getClass()
+ " received. Could not continue.");
}
//Get the office component context:
XComponentContext xContext = Bootstrap.bootstrap();
//Get the office service manager:
XMultiComponentFactory xServiceManager = xContext.getServiceManager();
//Create the desktop, which is the root frame of the
//hierarchy of frames that contain viewable components:
Object desktop;
try {
desktop = xServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
} catch (Exception e) {
throw new CreationException(e.getMessage());
}
XDesktop resultDesktop = UnoRuntime.queryInterface(XDesktop.class, desktop);
UnoRuntime.queryInterface(XComponentLoader.class, desktop);
return resultDesktop;
}
示例12: convertOODocToFile
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
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;
}
示例13: convertOODocByteStreamToByteStream
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
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;
}
示例14: getCurrentComponent
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
/**
* 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;
}
示例15: convert
import com.sun.star.lang.XMultiComponentFactory; //导入方法依赖的package包/类
public void convert(OOoInputStream input, OOoOutputStream output,
String filterName, Map<String, Object> filterParameters)
throws Exception {
XMultiComponentFactory xMultiComponentFactory = xComponentContext
.getServiceManager();
Object desktopService = xMultiComponentFactory
.createInstanceWithContext("com.sun.star.frame.Desktop",
xComponentContext);
XComponentLoader xComponentLoader = UnoRuntime.queryInterface(
XComponentLoader.class, desktopService);
PropertyValue[] conversionProperties = new PropertyValue[3];
conversionProperties[0] = new PropertyValue();
conversionProperties[1] = new PropertyValue();
conversionProperties[2] = new PropertyValue();
conversionProperties[0].Name = "InputStream";
conversionProperties[0].Value = input;
conversionProperties[1].Name = "Hidden";
conversionProperties[1].Value = Boolean.TRUE;
XComponent document = xComponentLoader.loadComponentFromURL(
"private:stream", "_blank", 0, conversionProperties);
List<PropertyValue> filterData = new ArrayList<PropertyValue>();
for (Map.Entry<String, Object> entry : filterParameters.entrySet()) {
PropertyValue propertyValue = new PropertyValue();
propertyValue.Name = entry.getKey();
propertyValue.Value = entry.getValue();
filterData.add(propertyValue);
}
conversionProperties[0].Name = "OutputStream";
conversionProperties[0].Value = output;
conversionProperties[1].Name = "FilterName";
conversionProperties[1].Value = filterName;
conversionProperties[2].Name = "FilterData";
conversionProperties[2].Value = filterData
.toArray(new PropertyValue[1]);
XStorable xstorable = UnoRuntime.queryInterface(XStorable.class,
document);
xstorable.storeToURL("private:stream", conversionProperties);
XCloseable xclosable = UnoRuntime.queryInterface(XCloseable.class,
document);
xclosable.close(true);
}