How to disable Print option for users with Java?

Creating a macro - Writing a Script - Using the API

How to disable Print option for users with Java?

Postby rameshkancherla » Sun Aug 03, 2008 6:49 pm

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'). 
rameshkancherla
 
Posts: 16
Joined: Fri May 30, 2008 1:38 pm

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

Postby pdjota » Mon Aug 04, 2008 7:38 pm

Hi,
The documentation regarding Disabling commands is very good, take a look at:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/Disable_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/wiki/Framework/Article/OpenOffice.org_2.x_Commands

Based on the example listed in the DevGuide:
Code: Select all   Expand viewCollapse view
   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   Expand viewCollapse view
String[] url = {"Print"};
String suffix = "x";
disableCommands( url, suffix);
OOo 2.3.X on Ms Windows XP + Linux
pdjota
 
Posts: 4
Joined: Tue Jul 15, 2008 9:30 pm

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

Postby rameshkancherla » Fri Aug 08, 2008 8:30 am

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
rameshkancherla
 
Posts: 16
Joined: Fri May 30, 2008 1:38 pm

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

Postby foxcole » Fri Aug 08, 2008 3:03 pm

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
User avatar
foxcole
Volunteer
 
Posts: 1507
Joined: Mon Oct 08, 2007 1:31 am
Location: Minneapolis, Minnesota


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests