How to disable Print option for users with Java?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
rameshkancherla
Posts: 16
Joined: Fri May 30, 2008 1:38 pm

How to disable Print option for users with Java?

Post by rameshkancherla »

Good Evening,
This is Ramesh Kancherla. I am doing in open office project. I have to modify (disable or enable)userAccess options like print and copy according with user permissions in open office through programatically using java.
how can I do it.

can any one please give me suggestion.

Thanks & Regards
Ramesh K
 Edit: Hagar: changed title (was 'Print option'). 
pdjota
Posts: 4
Joined: Tue Jul 15, 2008 9:30 pm

Re: How to disable Print option for users with Java?

Post by pdjota »

Hi,
The documentation regarding Disabling commands is very good, take a look at:
http://wiki.services.openoffice.org/wik ... e_Commands
To disable Print you have to put the "Print" command into the disabled list in the Configuration Manager.
Additionaly, the entire list of command names is here:
http://wiki.services.openoffice.org/wik ... x_Commands

Based on the example listed in the DevGuide:

Code: Select all

	private void disableCommands(String[] commandURL, String commandName) {
//		Set the root path for our configuration access
		try {
			com.sun.star.beans.PropertyValue[] lParams = new com.sun.star.beans.PropertyValue[1];
			lParams[0] = new com.sun.star.beans.PropertyValue();
			lParams[0].Name = new String("nodepath");
			lParams[0].Value = "/org.openoffice.Office.Commands/Execute/Disabled";
		
//			Create configuration update access to have write access to the configuration
			Object xAccess = xConfigProvider.createInstanceWithArguments(
					"com.sun.star.configuration.ConfigurationUpdateAccess", lParams);
			com.sun.star.lang.XSingleServiceFactory xSetElementFactory =
				(com.sun.star.lang.XSingleServiceFactory)UnoRuntime.queryInterface(
						com.sun.star.lang.XSingleServiceFactory.class, xAccess);
			com.sun.star.container.XNameContainer xNameContainer =
				(com.sun.star.container.XNameContainer)UnoRuntime.queryInterface(
						com.sun.star.container.XNameContainer.class, xAccess );
			if (xSetElementFactory != null && xNameContainer != null) {
				Object[] aArgs = new Object[0];
				for (int i = 0; i < commandURL.length; i++) {
//					Create the nodes with the XSingleServiceFactory of the configuration
					Object xNewElement = xSetElementFactory.createInstanceWithArguments( aArgs );
					if (xNewElement != null) {
//						We have a new node. To set the properties of the node we need
//						the XPropertySet interface.
						com.sun.star.beans.XPropertySet xPropertySet =
							(com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
									com.sun.star.beans.XPropertySet.class,
									xNewElement );
						if (xPropertySet != null) {
//							Create a unique node name.
							String aCmdNodeName = commandName;
							aCmdNodeName += i;
//							Insert the node into the Disabled set
							xPropertySet.setPropertyValue("Command", commandURL[i]);
							xNameContainer.insertByName(aCmdNodeName, xNewElement);
						}
					}
				}
//				Commit our changes
				com.sun.star.util.XChangesBatch xFlush = (com.sun.star.util.XChangesBatch)
				UnoRuntime.queryInterface(com.sun.star.util.XChangesBatch.class, xAccess);
				xFlush.commitChanges();
			}
		}
		catch (com.sun.star.uno.Exception e) {
			System.out.println("Exception detected!");
			System.out.println(e);
		}
	}
And then use it like this:

Code: Select all

String[] url = {"Print"};
String suffix = "x";
disableCommands( url, suffix);
OOo 2.3.X on Ms Windows XP + Linux
rameshkancherla
Posts: 16
Joined: Fri May 30, 2008 1:38 pm

Re: How to disable Print option for users with Java?

Post by rameshkancherla »

hi,
We are able to block print option but there is no shortcut key for print screen and no Uno command is available for print screen.i wanted to block the print screen based on the user permissions.

how to block print screen with openoffice

Thanks & Regards
Ramesh K
User avatar
foxcole
Volunteer
Posts: 1507
Joined: Mon Oct 08, 2007 1:31 am
Location: Minneapolis, Minnesota

Re: How to disable Print option for users with Java?

Post by foxcole »

rameshkancherla wrote: We are able to block print option but there is no shortcut key for print screen and no Uno command is available for print screen.i wanted to block the print screen based on the user permissions.

how to block print screen with openoffice
You can't. OOo users run many different operating systems, and they use many many many different methods for screen captures. That functionality is beyond the scope and capabilities of OOo.
Cheers!
---Fox

OOo 3.2.0 Portable, Windows 7 Home Premium 64-bit
Post Reply