本文整理汇总了Java中com.sun.star.frame.XComponentLoader类的典型用法代码示例。如果您正苦于以下问题:Java XComponentLoader类的具体用法?Java XComponentLoader怎么用?Java XComponentLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XComponentLoader类属于com.sun.star.frame包,在下文中一共展示了XComponentLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadDocument
import com.sun.star.frame.XComponentLoader; //导入依赖的package包/类
/**
* Loads document into OpenOffice.org
*
* @param serviceProvider the service provider to be used
* @param xComponentLoader OpenOffice.org component loader
* @param URL URL of the document
* @param targetFrameName name of the OpenOffice.org target frame
* @param searchFlags search flags for the target frame
* @param properties properties for OpenOffice.org
*
* @return loaded document
*
* @throws Exception if an OpenOffice.org communication error occurs
* @throws IOException if document can not be found
*/
private static IDocument loadDocument(IServiceProvider serviceProvider,
XComponentLoader xComponentLoader, String URL, String targetFrameName, int searchFlags,
PropertyValue[] properties) throws Exception, IOException {
DocumentService.checkMaxOpenDocuments(serviceProvider);
XComponent xComponent = xComponentLoader.loadComponentFromURL(URL,
targetFrameName,
searchFlags,
properties);
if (xComponent != null) {
return getDocument(xComponent, serviceProvider, properties);
}
throw new IOException("Document not found.");
}
示例2: loadDocument
import com.sun.star.frame.XComponentLoader; //导入依赖的package包/类
private XComponent loadDocument(OfficeContext context, File inputFile) throws OfficeException {
if (!inputFile.exists()) {
throw new OfficeException("input document not found");
}
XComponentLoader loader = cast(XComponentLoader.class, context.getService(SERVICE_DESKTOP));
Map<String, ?> loadProperties = getLoadProperties(inputFile);
XComponent document = null;
try {
document = loader.loadComponentFromURL(toUrl(inputFile), "_blank", 0, toUnoProperties(loadProperties));
} catch (IllegalArgumentException illegalArgumentException) {
throw new OfficeException("could not load document: " + inputFile.getName(), illegalArgumentException);
} catch (ErrorCodeIOException errorCodeIOException) {
throw new OfficeException("could not load document: " + inputFile.getName() + "; errorCode: "
+ errorCodeIOException.ErrCode, errorCodeIOException);
} catch (IOException ioException) {
throw new OfficeException("could not load document: " + inputFile.getName(), ioException);
}
if (document == null) {
throw new OfficeException("could not load document: " + inputFile.getName());
}
XRefreshable refreshable = cast(XRefreshable.class, document);
if (refreshable != null) {
refreshable.refresh();
}
return document;
}
示例3: loadAndExport
import com.sun.star.frame.XComponentLoader; //导入依赖的package包/类
/**
* Load and export.
* @param inputStream
* the input stream
* @param importOptions
* the import options
* @param outputStream
* the output stream
* @param exportOptions
* the export options
* @throws Exception
* the exception
*/
@SuppressWarnings("unchecked")
private void loadAndExport(InputStream inputStream, Map/* <String,Object> */importOptions,
OutputStream outputStream, Map/* <String,Object> */exportOptions) throws Exception {
XComponentLoader desktop = openOfficeConnection.getDesktopObject();
Map/* <String,Object> */loadProperties = new HashMap();
loadProperties.putAll(getDefaultLoadProperties());
loadProperties.putAll(importOptions);
// doesn't work using InputStreamToXInputStreamAdapter; probably because
// it's not XSeekable
// property("InputStream", new
// InputStreamToXInputStreamAdapter(inputStream))
loadProperties.put("InputStream", new ByteArrayToXInputStreamAdapter(IOUtils.toByteArray(inputStream))); //$NON-NLS-1$
XComponent document = desktop.loadComponentFromURL(
"private:stream", "_blank", 0, toPropertyValues(loadProperties)); //$NON-NLS-1$ //$NON-NLS-2$
if (document == null) {
throw new OPException(Messages.getString("ooconverter.StreamOpenOfficeDocumentConverter.6")); //$NON-NLS-1$
}
refreshDocument(document);
Map/* <String,Object> */storeProperties = new HashMap();
storeProperties.putAll(exportOptions);
storeProperties.put("OutputStream", new OutputStreamToXOutputStreamAdapter(outputStream)); //$NON-NLS-1$
try {
XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
storable.storeToURL("private:stream", toPropertyValues(storeProperties)); //$NON-NLS-1$
} finally {
document.dispose();
}
}
示例4: loadDocument
import com.sun.star.frame.XComponentLoader; //导入依赖的package包/类
private XComponent loadDocument(OfficeContext context, File inputFile) throws OfficeException {
if (!inputFile.exists()) {
throw new OfficeException("input document not found");
}
XComponentLoader loader = cast(XComponentLoader.class, context.getService(SERVICE_DESKTOP));
Map<String,?> loadProperties = getLoadProperties(inputFile);
XComponent document = null;
try {
document = loader.loadComponentFromURL(toUrl(inputFile), "_blank", 0, toUnoProperties(loadProperties));
} catch (IllegalArgumentException illegalArgumentException) {
throw new OfficeException("could not load document: " + inputFile.getName(), illegalArgumentException);
} catch (ErrorCodeIOException errorCodeIOException) {
throw new OfficeException("could not load document: " + inputFile.getName() + "; errorCode: " + errorCodeIOException.ErrCode, errorCodeIOException);
} catch (IOException ioException) {
throw new OfficeException("could not load document: " + inputFile.getName(), ioException);
}
if (document == null) {
throw new OfficeException("could not load document: " + inputFile.getName());
}
return document;
}
示例5: initContext
import com.sun.star.frame.XComponentLoader; //导入依赖的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);
}
}
示例6: getInstance
import com.sun.star.frame.XComponentLoader; //导入依赖的package包/类
public static synchronized LibreOfficeManager getInstance() {
try {
if (mgr == null) {
XComponentLoader xCLoader = initContext();
mgr = new LibreOfficeManager(xCLoader);
}
return mgr;
} catch (Exception e) {
throw new LibreOfficeException(e);
}
}
示例7: getWriterDocument
import com.sun.star.frame.XComponentLoader; //导入依赖的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);
}
示例8: simpleBootstrap
import com.sun.star.frame.XComponentLoader; //导入依赖的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;
}
示例9: getXComponentLoader
import com.sun.star.frame.XComponentLoader; //导入依赖的package包/类
public XComponentLoader getXComponentLoader() {
try {
return as(XComponentLoader.class, createDesktop());
} catch (Exception e) {
throw new OpenOfficeException("Unable to create Open office components.", e);
}
}
示例10: loadXComponent
import com.sun.star.frame.XComponentLoader; //导入依赖的package包/类
public XComponent loadXComponent(byte[] bytes) throws com.sun.star.lang.IllegalArgumentException, IOException {
XComponentLoader xComponentLoader = getXComponentLoader();
PropertyValue[] props = new PropertyValue[1];
props[0] = new PropertyValue();
props[0].Name = "Hidden";
props[0].Value = Boolean.TRUE;
File tempFile = createTempFile(bytes);
return xComponentLoader.loadComponentFromURL(toURL(tempFile), "_blank", 0, props);
}
示例11: LibreOfficeManager
import com.sun.star.frame.XComponentLoader; //导入依赖的package包/类
private LibreOfficeManager(XComponentLoader xCLoader) {
this.xCLoader = xCLoader;
}
示例12: convertOODocToFile
import com.sun.star.frame.XComponentLoader; //导入依赖的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.frame.XComponentLoader; //导入依赖的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: extractRaw
import com.sun.star.frame.XComponentLoader; //导入依赖的package包/类
public Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
{
Map<String, Serializable> rawProperties = new HashMap<String, Serializable>(17);
String sourceMimetype = reader.getMimetype();
// create temporary files to convert from and to
File tempFromFile = TempFileProvider.createTempFile("OpenOfficeMetadataExtracter-", "."
+ this.mimetypeService.getExtension(sourceMimetype));
// download the content from the source reader
reader.getContent(tempFromFile);
String sourceUrl = toUrl(tempFromFile, connection);
// UNO Interprocess Bridge *should* be thread-safe, but...
XComponentLoader desktop = connection.getDesktop();
XComponent document = desktop.loadComponentFromURL(sourceUrl, "_blank", 0, new PropertyValue[]
{
property("Hidden", Boolean.TRUE)
});
if (document == null)
{
throw new FileNotFoundException("could not open source document: " + sourceUrl);
}
try
{
XDocumentInfoSupplier infoSupplier = (XDocumentInfoSupplier) UnoRuntime.queryInterface(
XDocumentInfoSupplier.class, document);
XPropertySet propSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, infoSupplier
.getDocumentInfo());
rawProperties.put(KEY_TITLE, propSet.getPropertyValue("Title").toString());
rawProperties.put(KEY_DESCRIPTION, propSet.getPropertyValue("Subject").toString());
rawProperties.put(KEY_AUTHOR, propSet.getPropertyValue("Author").toString());
}
finally
{
document.dispose();
}
// Done
return rawProperties;
}
示例15: convert
import com.sun.star.frame.XComponentLoader; //导入依赖的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);
}