Hi Henri,
I have created Java code that sets the title of the current document.
Be sure to have the SDK installed and to include the necessary class
files (jar files).
As a side note, compare my Java code to Andrew's SB code ;).
And do not ask yourself why I am using such an awkward coding style, I
just played around in Eclipse a bit to refresh my Java knowledge.
<code>
import com.sun.star.uno.UnoRuntime;
import com.sun.star.document.XDocumentInfoSupplier;
public class Setting_Title
{
public static final String title = "My new title";
public static void main(String args[])
{
try {
com.sun.star.uno.XComponentContext xContext = null;
// get the remote office component context
xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
System.out.println("Connected to a running office ...");
// get the remote office service manager
com.sun.star.lang.XMultiComponentFactory xMCF =
xContext.getServiceManager();
Object Stardesktop = xMCF.createInstanceWithContext(
"com.sun.star.frame.Desktop", xContext);
com.sun.star.frame.XDesktop xDesktop =
(com.sun.star.frame.XDesktop)
UnoRuntime.queryInterface(
com.sun.star.frame.XDesktop.class, Stardesktop);
com.sun.star.lang.XComponent Doc =
xDesktop.getCurrentComponent();
XDocumentInfoSupplier xDocInfo = (XDocumentInfoSupplier)
UnoRuntime.queryInterface(XDocumentInfoSupplier.class, Doc);
Object info = xDocInfo.getDocumentInfo();
com.sun.star.beans.XPropertySet xProps =
(com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(
com.sun.star.beans.XPropertySet.class, info);
xProps.setPropertyValue("Title", getTitle());
}
catch( Exception e ) {
e.printStackTrace(System.err);
System.exit(1);
}
}
/**
* @return Returns the title.
*/
public static String getTitle() {
return title;
}
}
</code>
On Sun, 27 Mar 2005 13:07:45 +0300, Henri Sivonen <[EMAIL PROTECTED]> wrote:
> How can I get and set the title of a document (the one available
> through document properties and meta.xml) through the Java API?
>
> --
> Henri Sivonen
> [EMAIL PROTECTED]
> http://hsivonen.iki.fi/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Best Regards
Christian Junker
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]