OO-Snippets: Open Document from URL

Commons

Keywordsopen, document
LanguageJava
ApplicationOffice
AuthorsTobias Krais (www.design-to-use.de)
Supported Versions1.1.x  2.0.x  
Supported OSAll  
QuestionHow to open a document?
Answer

Code-Snippet-Listing (snippet-source)

import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.uno.UnoRuntime;

/**
 * A specified document is loaded. 
 * 
 * @param source_File
 * @return
 */
public void openDocument(String source_File) {
	// Query the XComponentLoader interface from the desktop Object.
	// See this snippet how to get the desktop Object: ../Office/Office.BootstrapOpenOffice.snip
	XComponentLoader xComponentLoader = (XComponentLoader)
	UnoRuntime.queryInterface(XComponentLoader.class, desktop);

	PropertyValue[] myProperties = new PropertyValue[1];
	myProperties[0] = new PropertyValue();
	myProperties[0].Name = "Hidden";
	// for open document and do not show user interface use "true"
	myProperties[0].Value = new Boolean(false);

	// Load a given document
	try	{
		XComponent xComponent = xComponentLoader.loadComponentFromURL(
				createUNOFileURL(source_File),  // For createUNOFileURL see: ../Office/Office.CreateUNOCompatibleURL.snip
				"_blank",                       // New windos
				0,                              // Is ignored
				myProperties);            // Special properties
	}
	catch(Exception e) {
	}
}

Changelog

DateUserModification
2006-12-11tobiaskraisAdded Snippet linking features
2006-03-27tobiaskraisInitial version

and