woerie Newbie

Joined: 06 Oct 2009 Posts: 1
|
Posted: Tue Oct 06, 2009 6:32 am Post subject: [Java] Set writer document language (locale) |
|
|
Hello
I have an embedded OOo Writer in a java application, through the officebean. And want to set the document language when loading it.
First I tried to set the Language by receiving the document and it's XPropertySet and setting the "Language" property. The property gets set, but it doesn't change anything in the embedded Writer. I tested by setting other properties like the title or author and those worked perfectly.
| Code: |
OfficeDocument a = myOOoBean.getDocument();
XDocumentPropertiesSupplier xdps = (XDocumentPropertiesSupplier)
UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, a);
XDocumentProperties xdp = xdps.getDocumentProperties();
XDocumentInfoSupplier xdis = (XDocumentInfoSupplier)UnoRuntime.queryInterface(XDocumentInfoSupplier.class,a);
XDocumentInfo xdi = xdis.getDocumentInfo();
XPropertySet xps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xdi);
XPropertySetInfo xpsi = xps.getPropertySetInfo();
Property[] propy = xpsi.getProperties();
// Try to set a value
Object r = "TEST TITLE";
xps.setPropertyValue("Title", r);
r = "Test Author";
xps.setPropertyValue("Author", r);
// Works perfectly
// Doesn't work
xps.setPropertyValue("Language", new Locale("af","ZA",""));
|
Then I tried a different approach. Retrieving and setting the linguistic LinguProperties, but this also yielded no results.
| Code: |
protected XMultiServiceFactory mxFactory = null;
private boolean getLingProps() throws Exception
{
if (mxFactory != null)
{
Object aObj = mxFactory.createInstance("com.sun.star.linguistic2.LinguProperties" );
mxLinguProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, aObj);
}
return mxLinguProps != null;
}
private void setLang2() throws Exception, java.lang.Exception
{
XComponentContext xContext = com.sun.star.comp.helper.Bootstrap.createInitialComponentContext(null);
XMultiComponentFactory xLocalServiceManager = xContext.getServiceManager();
Object xUrlResolver = xLocalServiceManager.createInstanceWithContext
("com.sun.star.bridge.UnoUrlResolver", xContext );
XUnoUrlResolver urlResolver = (XUnoUrlResolver)UnoRuntime.queryInterface(XUnoUrlResolver.class, xUrlResolver);
Object rInitialObject = urlResolver.resolve( "uno:" + "socket,host=localhost,port=8100"+ ";urp;StarOffice.NamingService");
XNamingService rName = (XNamingService)UnoRuntime.queryInterface(XNamingService.class,rInitialObject );
if( rName != null )
{
Object rXsmgr = rName.getRegisteredObject( "StarOffice.ServiceManager");
mxFactory = (XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, rXsmgr);
}
if(getLingProps())
{
System.out.println("Got the LingProps");
Locale aLocale = new Locale("af", "ZA", "");
Object s = mxLinguProps.getPropertyValue("DefaultLocale");
Locale p = (Locale)s;
System.out.println("Default Locale:");
System.out.println(p.Language + " " + p.Country);
System.out.println("Set Default Locale");
mxLinguProps.setPropertyValue("DefaultLocale", (Object)aLocale);
}
}
|
The successfully retrieves the properties and displays the default locale, but setting it doesn't do squat.
Next I'm considering to select all the text in the document and set the language property for the selected text. But I first wanted to inquire if what I'm attempting is even possible and if so what course of action to take. |
|