Help Needed to on/off track change word document using Java

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
399192
Posts: 2
Joined: Fri Oct 17, 2014 8:17 am

Help Needed to on/off track change word document using Java

Post by 399192 »

Hi,
In our java application open office 2.3 is used to generate/upload word document. I am trying to generate the word document on Track change mode on during generation. Is there any property or attribute that can be set using java code to achive?

Thanks,
Roy
OpenOffice 2.3 on Windows 7
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Help Needed to on/off track change word document using J

Post by FJCC »

There is a RecordChanges property at the top level of the document. In Basic one would write

Code: Select all

ThisComponent.RecordChange = True
Using the MRI extension I recorded this Java code

Code: Select all

import com.sun.star.beans.PropertyVetoException;
import com.sun.star.beans.UnknownPropertyException;
import com.sun.star.beans.XPropertySet;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

public static void snippet(XComponentContext xComponentContext, Object oInitialTarget)
{
	try
	{
		XPropertySet xPropSet = UnoRuntime.queryInterface(
			XPropertySet.class, oInitialTarget);
		xPropSet.setPropertyValue("RecordChanges", true);
		
	}
	catch (WrappedTargetException e1)
	{
		// setPropertyValue
		e1.printStackTrace();
	}
	catch (PropertyVetoException e2)
	{
		// setPropertyValue
		e2.printStackTrace();
	}
	catch (IllegalArgumentException e3)
	{
		// setPropertyValue
		e3.printStackTrace();
	}
	catch (UnknownPropertyException e4)
	{
		// setPropertyValue
		e4.printStackTrace();
	}
}
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
399192
Posts: 2
Joined: Fri Oct 17, 2014 8:17 am

Re: Help Needed to on/off track change word document using J

Post by 399192 »

Hi FJCC, thanks for you respond. I am getting the Unknown property Exception. Please note I am using version 2.3 which is pretty old version.
com.sun.star.beans.UnknownPropertyException: unknown property RecordChanges

Code snippet --

Code: Select all

 XComponentContext xcomponentcontext = null;
	try {
		xcomponentcontext = Bootstrap.createInitialComponentContext( null );
	} catch (com.sun.star.uno.Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (java.lang.Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

      XMultiComponentFactory xmulticomponentfactory =
      xcomponentcontext.getServiceManager();

      Object objectUrlResolver = null;
	try {
		objectUrlResolver = xmulticomponentfactory.createInstanceWithContext(
		  "com.sun.star.bridge.UnoUrlResolver", xcomponentcontext );
	} catch (com.sun.star.uno.Exception e) {
		logException("Unable to create Instance With Context", e);
	}

      // Create a new url resolver
      XUnoUrlResolver xurlresolver = ( XUnoUrlResolver )
      UnoRuntime.queryInterface( XUnoUrlResolver.class,
      objectUrlResolver );

           Object objectInitial = null;
	try {
		objectInitial = xurlresolver.resolve(pURL);
	} catch (NoConnectException e) {
		logException("URL Resolver.resolve -" + pURL, e);
	} catch (ConnectionSetupException e) {
		logException("URL Resolver.resolve -" + pURL, e);
	} catch (IllegalArgumentException e) {
		logException("URL Resolver.resolve -" + pURL, e);
	}

      // Create a service manager from the initial object
      xmulticomponentfactory = ( XMultiComponentFactory )
      UnoRuntime.queryInterface( XMultiComponentFactory.class, objectInitial );

      // Query for the XPropertySet interface.
      XPropertySet xpropertysetMultiComponentFactory = ( XPropertySet )
      UnoRuntime.queryInterface( XPropertySet.class, xmulticomponentfactory );

      // Get the default context from the office server.
      Object objectDefaultContext = null;
	try {
		try {
			xpropertysetMultiComponentFactory.setPropertyValue("RecordChanges", true);
OpenOffice 2.3 on Windows 7
Post Reply