Hi
The attached sample java program does the following:
1. Connect to a remote open office
2. Ask open office to loadComponentFromURL using tomcat and webdav
3. Ask open office to storeToURL using the writer_export_PDF filter,
saving the doc
back to tomcat with the original name and add a ".pdf"
4. release the connection to the remote open office.
The program works fine when Open office is running on a remote linux
server (gentoo used emerge openoffice-1.9.109.ebuild)
However, when openoffice runs on a windows machine (server 2003) the
loadComponent returns null.
The openoffice on the windows machine does manage to open the url when i
am using the GUI interface of openoffice.
Anything i need to enable in openoffice to make this work ?
Thanks
David Dankwerth
________________________________________________________________________
This e-mail and its attachments are confidential. If you are not the intended
recipient of this e-mail message, please telephone or e-mail us immediately,
delete this message from your system and do not read, copy, distribute,
disclose or otherwise use this e-mail message and any attachments.
Although ri3k believes this e-mail and any attachments to be free of any virus
or other defect which may affect your computer, it is the responsibility of the
recipient to ensure that it is virus free and ri3k does not accept any
responsibility for any loss or damage in any way from its use.import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.XComponentContext;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XStorable;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.PropertyValue;
import com.sun.star.bridge.XBridgeFactory;
import com.sun.star.bridge.XBridge;
import com.sun.star.connection.XConnector;
import com.sun.star.connection.XConnection;
public class sample
{
private XBridge bridge = null ;
private XComponentContext xRemoteContext = null;
private com.sun.star.frame.XComponentLoader officeComponentLoader;
private XMultiComponentFactory xRemoteServiceManager = null;
private String con ;
/**
* main
*/
public static void main(String[] args)
throws Exception
{
sample s = new sample(args) ;
try
{
//connect to oo server
s.useConnection() ;
//load doc
Object o = s.load(args[2]) ;
// export to pdf
s.save(o,args[2]) ;
// release connection to oo server
s.release();
}
catch (Exception e)
{
s.release() ;
throw e;
}
}
/* constructor */
public sample(String[] args)
{
if (args.length != 3)
{
System.out.println("usage java sample host port
url");
System.exit(-1);
}
else
con = "socket,host="+args[0]+",port="+args[1];
}
/**
* load to an object
*/
public Object load(String url)
throws Exception
{
com.sun.star.beans.PropertyValue [] args =
new com.sun.star.beans.PropertyValue [1];
// Setting the flag for read-only
args[ 0 ] = new PropertyValue();
args[ 0 ].Name = "read-only";
args[ 0 ].Value = new Boolean(true);
System.out.println("About to load is : "+url);
Object o = officeComponentLoader.loadComponentFromURL(url,
"_blank", 0, args);
System.out.println("o is "+o);
return o ;
}
/**
* export to PDF
*/
public void save(Object o,String url) throws Exception
{
XStorable xstorable =
( XStorable ) UnoRuntime.queryInterface(
XStorable.class,o );
PropertyValue[] propertyvalue = new PropertyValue[ 2 ];
// Setting the flag for overwriting
propertyvalue[ 0 ] = new PropertyValue();
propertyvalue[ 0 ].Name = "Overwrite";
propertyvalue[ 0 ].Value = new Boolean(true);
// Setting the filter name
propertyvalue[ 1 ] = new PropertyValue();
propertyvalue[ 1 ].Name = "FilterName";
propertyvalue[ 1 ].Value = "writer_pdf_Export";
String res = url+".pdf" ;
try
{
xstorable.storeToURL(res, propertyvalue );
// close
XComponent xcomponent =
( XComponent ) UnoRuntime.queryInterface(
XComponent.class,
xstorable );
// Closing the converted document
xcomponent.dispose();
}
catch (com.sun.star.io.IOException ioe)
{
ioe.printStackTrace() ;
throw ioe ;
}
}
/**
* open connection to openoffice
*/
public void useConnection() throws java.lang.Exception {
try {
XComponentContext _ctx =
com.sun.star.comp.helper.Bootstrap.createInitialComponentContext( null );
xRemoteContext = _ctx ;
XComponentContext xLocalContext = _ctx ;
XMultiComponentFactory xLocalServiceManager =
xLocalContext.getServiceManager();
Object x =
xRemoteContext.getServiceManager().createInstanceWithContext(
"com.sun.star.connection.Connector",
xRemoteContext );
XConnector xConnector = (XConnector )
UnoRuntime.queryInterface(XConnector.class, x);
XConnection connection = xConnector.connect( con);
if (connection == null)
System.out.println("Connection is null");
x =
xRemoteContext.getServiceManager().createInstanceWithContext(
"com.sun.star.bridge.BridgeFactory",
xRemoteContext);
XBridgeFactory xBridgeFactory = (XBridgeFactory)
UnoRuntime.queryInterface(
XBridgeFactory.class , x );
if (xBridgeFactory== null)
System.out.println("bridge factoriy is null");
// this is the bridge that you will dispose
bridge = xBridgeFactory.createBridge( "" , "urp",
connection , null );
XComponent xComponent = (XComponent)
UnoRuntime.queryInterface(
XComponent.class, bridge );
// get the remote instance
x = bridge.getInstance( "StarOffice.ServiceManager");
// Query the initial object for its main factory
interface
xRemoteServiceManager = ( XMultiComponentFactory )
UnoRuntime.queryInterface(
XMultiComponentFactory.class, x );
// retrieve the component context (it's not yet exported
from the office)
// Query for the XPropertySet interface.
XPropertySet xProperySet = ( XPropertySet )
UnoRuntime.queryInterface( XPropertySet.class,
xRemoteServiceManager );
// Get the default context from the office server.
Object oDefaultContext =
xProperySet.getPropertyValue( "DefaultContext"
);
// Query for the interface XComponentContext.
XComponentContext xOfficeComponentContext =
( XComponentContext ) UnoRuntime.queryInterface(
XComponentContext.class, oDefaultContext );
// now create the desktop service
// NOTE: use the office component context here !
Object oDesktop =
xRemoteServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", xOfficeComponentContext );
officeComponentLoader = ( XComponentLoader )
UnoRuntime.queryInterface(
XComponentLoader.class, oDesktop );
String available = (null !=officeComponentLoader ?
"available" : "not available");
System.out.println( "remote ServiceManager is " + available
);
}
catch( com.sun.star.lang.DisposedException e ) { //works from
Patch 1
xRemoteContext = null;
throw e;
}
}
/**
* when all the work is done, call release to dispose of the
bridge
* and your program can exit normaly, without forcing a
System.exit
*/
public void release()
throws Exception
{
XComponent xcomponent =
( XComponent ) UnoRuntime.queryInterface( XComponent.class,
bridge );
// Closing the bridge
xcomponent.dispose();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]