xref: /AOO41X/main/odk/examples/DevelopersGuide/OfficeDev/DisableCommands/DisableCommandsTest.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  *  The Contents of this file are made available subject to the terms of
4*cdf0e10cSrcweir  *  the BSD license.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7*cdf0e10cSrcweir  *  All rights reserved.
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  *  Redistribution and use in source and binary forms, with or without
10*cdf0e10cSrcweir  *  modification, are permitted provided that the following conditions
11*cdf0e10cSrcweir  *  are met:
12*cdf0e10cSrcweir  *  1. Redistributions of source code must retain the above copyright
13*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer.
14*cdf0e10cSrcweir  *  2. Redistributions in binary form must reproduce the above copyright
15*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer in the
16*cdf0e10cSrcweir  *     documentation and/or other materials provided with the distribution.
17*cdf0e10cSrcweir  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18*cdf0e10cSrcweir  *     contributors may be used to endorse or promote products derived
19*cdf0e10cSrcweir  *     from this software without specific prior written permission.
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*cdf0e10cSrcweir  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*cdf0e10cSrcweir  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24*cdf0e10cSrcweir  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25*cdf0e10cSrcweir  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26*cdf0e10cSrcweir  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27*cdf0e10cSrcweir  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28*cdf0e10cSrcweir  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29*cdf0e10cSrcweir  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30*cdf0e10cSrcweir  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31*cdf0e10cSrcweir  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*cdf0e10cSrcweir  *
33*cdf0e10cSrcweir  *************************************************************************/
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
36*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
37*cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory;
38*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
39*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
40*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
41*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
42*cdf0e10cSrcweir import com.sun.star.util.XURLTransformer;
43*cdf0e10cSrcweir import com.sun.star.frame.XDesktop;
44*cdf0e10cSrcweir import com.sun.star.frame.XComponentLoader;
45*cdf0e10cSrcweir import com.sun.star.text.XTextDocument;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir /*
48*cdf0e10cSrcweir  *
49*cdf0e10cSrcweir  * @author  Carsten Driesner
50*cdf0e10cSrcweir  * Provides example code how to enable/disable
51*cdf0e10cSrcweir  * commands.
52*cdf0e10cSrcweir  */
53*cdf0e10cSrcweir public class DisableCommandsTest extends java.lang.Object {
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir     /*
56*cdf0e10cSrcweir      * A list of command names
57*cdf0e10cSrcweir      */
58*cdf0e10cSrcweir     final static private String[] aCommandURLTestSet =
59*cdf0e10cSrcweir     {
60*cdf0e10cSrcweir         new String( "Open" ),
61*cdf0e10cSrcweir         new String( "About" ),
62*cdf0e10cSrcweir         new String( "SelectAll" ),
63*cdf0e10cSrcweir         new String( "Quit" ),
64*cdf0e10cSrcweir     };
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir     private static XComponentContext xRemoteContext = null;
67*cdf0e10cSrcweir     private static XMultiComponentFactory xRemoteServiceManager = null;
68*cdf0e10cSrcweir     private static XURLTransformer xTransformer = null;
69*cdf0e10cSrcweir     private static XMultiServiceFactory xConfigProvider = null;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     /*
72*cdf0e10cSrcweir      * @param args the command line arguments
73*cdf0e10cSrcweir      */
74*cdf0e10cSrcweir     public static void main(String[] args) {
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir         try {
77*cdf0e10cSrcweir             // get the remote office context. If necessary a new office
78*cdf0e10cSrcweir             // process is started
79*cdf0e10cSrcweir             xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
80*cdf0e10cSrcweir             System.out.println("Connected to a running office ...");
81*cdf0e10cSrcweir             xRemoteServiceManager = xRemoteContext.getServiceManager();
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir             Object transformer = xRemoteServiceManager.createInstanceWithContext(
84*cdf0e10cSrcweir                           "com.sun.star.util.URLTransformer", xRemoteContext );
85*cdf0e10cSrcweir             xTransformer = (com.sun.star.util.XURLTransformer)
86*cdf0e10cSrcweir                 UnoRuntime.queryInterface(com.sun.star.util.XURLTransformer.class,
87*cdf0e10cSrcweir                                           transformer );
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir             Object configProvider = xRemoteServiceManager.createInstanceWithContext(
90*cdf0e10cSrcweir                           "com.sun.star.configuration.ConfigurationProvider",
91*cdf0e10cSrcweir                           xRemoteContext );
92*cdf0e10cSrcweir             xConfigProvider = (com.sun.star.lang.XMultiServiceFactory)
93*cdf0e10cSrcweir                 UnoRuntime.queryInterface(
94*cdf0e10cSrcweir                     com.sun.star.lang.XMultiServiceFactory.class, configProvider );
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir             // create a new test document
97*cdf0e10cSrcweir             Object oDesktop = xRemoteServiceManager.createInstanceWithContext(
98*cdf0e10cSrcweir                 "com.sun.star.frame.Desktop", xRemoteContext);
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir             XComponentLoader xCompLoader =(XComponentLoader)
101*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir             com.sun.star.lang.XComponent xComponent =
104*cdf0e10cSrcweir                 xCompLoader.loadComponentFromURL("private:factory/swriter",
105*cdf0e10cSrcweir                     "_blank", 0, new com.sun.star.beans.PropertyValue[0]);
106*cdf0e10cSrcweir             {
107*cdf0e10cSrcweir             XTextDocument xDoc =(XTextDocument)
108*cdf0e10cSrcweir                 UnoRuntime.queryInterface(XTextDocument.class, xComponent);
109*cdf0e10cSrcweir             xDoc.getText().setString("You can now check the disabled commands. The "
110*cdf0e10cSrcweir                                      +"following commands are disabled:\n\n"
111*cdf0e10cSrcweir                                      +"   Open...\n   Exit\n   Select All\n   "
112*cdf0e10cSrcweir                                      +"About StarOffice|OpenOffice\n\nPress "
113*cdf0e10cSrcweir                                      + "\"return\" in the shell where you have "
114*cdf0e10cSrcweir                                      + "started the example to enable the "
115*cdf0e10cSrcweir                                      + "commands!\n\nCheck the commands again and "
116*cdf0e10cSrcweir                                      + "press once more \"return\" to finish the "
117*cdf0e10cSrcweir                                      + "example and close the document.");
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir             // ensure that the document content is optimal visible
120*cdf0e10cSrcweir             com.sun.star.frame.XModel xModel =
121*cdf0e10cSrcweir                 (com.sun.star.frame.XModel)UnoRuntime.queryInterface(
122*cdf0e10cSrcweir                     com.sun.star.frame.XModel.class, xDoc);
123*cdf0e10cSrcweir             // get the frame for later usage
124*cdf0e10cSrcweir             com.sun.star.frame.XFrame xFrame =
125*cdf0e10cSrcweir                 xModel.getCurrentController().getFrame();
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir             com.sun.star.view.XViewSettingsSupplier xViewSettings =
128*cdf0e10cSrcweir                 (com.sun.star.view.XViewSettingsSupplier)UnoRuntime.queryInterface(
129*cdf0e10cSrcweir                     com.sun.star.view.XViewSettingsSupplier.class,
130*cdf0e10cSrcweir                     xModel.getCurrentController());
131*cdf0e10cSrcweir             xViewSettings.getViewSettings().setPropertyValue(
132*cdf0e10cSrcweir                 "ZoomType", new Short((short)0));
133*cdf0e10cSrcweir             }
134*cdf0e10cSrcweir             // test document will be closed later
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir             // First we need a defined starting point. So we have to remove
137*cdf0e10cSrcweir             // all commands from the disabled set!
138*cdf0e10cSrcweir             enableCommands();
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir             // Check if the commands are usable
141*cdf0e10cSrcweir             testCommands( false );
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir             // Disable the commands
144*cdf0e10cSrcweir             disableCommands();
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir             // Now the commands shouldn't be usable anymore
147*cdf0e10cSrcweir             testCommands( true );
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir             // you can now check the test document and see which commands are
150*cdf0e10cSrcweir             // disabled
151*cdf0e10cSrcweir             System.out.println("\nYou can now check the disabled commands.\n"
152*cdf0e10cSrcweir                                +"Please press 'return' to enable the commands!");
153*cdf0e10cSrcweir             waitForUserInput();
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir             // Remove disable commands to make Office usable again
156*cdf0e10cSrcweir             enableCommands();
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir             // you can check the test document again and see that the commands
159*cdf0e10cSrcweir             // are enabled now
160*cdf0e10cSrcweir             System.out.println("Check again the now enabled commands.\n"
161*cdf0e10cSrcweir                                +"Please press 'return' to finish the example and "
162*cdf0e10cSrcweir                                +"close the document!");
163*cdf0e10cSrcweir             waitForUserInput();
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir             // close test document
166*cdf0e10cSrcweir             com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable)
167*cdf0e10cSrcweir                 UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
168*cdf0e10cSrcweir                                           xComponent );
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir             if (xCloseable != null ) {
171*cdf0e10cSrcweir                 xCloseable.close(false);
172*cdf0e10cSrcweir             } else
173*cdf0e10cSrcweir             {
174*cdf0e10cSrcweir                 xComponent.dispose();
175*cdf0e10cSrcweir             }
176*cdf0e10cSrcweir         }
177*cdf0e10cSrcweir         catch (java.lang.Exception e){
178*cdf0e10cSrcweir             e.printStackTrace();
179*cdf0e10cSrcweir         }
180*cdf0e10cSrcweir         finally {
181*cdf0e10cSrcweir             System.exit(0);
182*cdf0e10cSrcweir         }
183*cdf0e10cSrcweir     }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     /**
186*cdf0e10cSrcweir      * Wait for user input -> until the user press 'return'
187*cdf0e10cSrcweir      */
188*cdf0e10cSrcweir     private static void waitForUserInput() throws java.io.IOException {
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir         java.io.BufferedReader reader
191*cdf0e10cSrcweir             = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir         reader.read();
194*cdf0e10cSrcweir     }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     /**
197*cdf0e10cSrcweir      * Test the commands that we enabled/disabled
198*cdf0e10cSrcweir      */
199*cdf0e10cSrcweir     private static void testCommands( boolean bDisabledCmds )
200*cdf0e10cSrcweir         throws com.sun.star.uno.Exception
201*cdf0e10cSrcweir     {
202*cdf0e10cSrcweir         // We need the desktop to get access to the current frame
203*cdf0e10cSrcweir         Object desktop = xRemoteServiceManager.createInstanceWithContext(
204*cdf0e10cSrcweir 		                    "com.sun.star.frame.Desktop", xRemoteContext );
205*cdf0e10cSrcweir         com.sun.star.frame.XDesktop xDesktop = (com.sun.star.frame.XDesktop)
206*cdf0e10cSrcweir             UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop );
207*cdf0e10cSrcweir         com.sun.star.frame.XFrame xFrame = xDesktop.getCurrentFrame();
208*cdf0e10cSrcweir         com.sun.star.frame.XDispatchProvider xDispatchProvider = null;
209*cdf0e10cSrcweir         if ( xFrame != null )
210*cdf0e10cSrcweir         {
211*cdf0e10cSrcweir             // We have a frame. Now we need access to the dispatch provider.
212*cdf0e10cSrcweir             xDispatchProvider =
213*cdf0e10cSrcweir                 (com.sun.star.frame.XDispatchProvider)UnoRuntime.queryInterface(
214*cdf0e10cSrcweir 	                com.sun.star.frame.XDispatchProvider.class, xFrame );
215*cdf0e10cSrcweir             if ( xDispatchProvider != null )
216*cdf0e10cSrcweir             {
217*cdf0e10cSrcweir                 // As we have the dispatch provider we can now check if we get
218*cdf0e10cSrcweir                 // a dispatch object or not.
219*cdf0e10cSrcweir                 for ( int n = 0; n < aCommandURLTestSet.length; n++ )
220*cdf0e10cSrcweir                 {
221*cdf0e10cSrcweir                     // Prepare the URL
222*cdf0e10cSrcweir                     com.sun.star.util.URL[] aURL  = new com.sun.star.util.URL[1];
223*cdf0e10cSrcweir                     aURL[0] = new com.sun.star.util.URL();
224*cdf0e10cSrcweir                     com.sun.star.frame.XDispatch xDispatch = null;
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir                     aURL[0].Complete = ".uno:" + aCommandURLTestSet[n];
227*cdf0e10cSrcweir                     xTransformer.parseSmart( aURL, ".uno:" );
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir                     // Try to get a dispatch object for our URL
230*cdf0e10cSrcweir                     xDispatch = xDispatchProvider.queryDispatch( aURL[0], "", 0 );
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir                     if ( xDispatch != null )
233*cdf0e10cSrcweir                     {
234*cdf0e10cSrcweir                         if ( bDisabledCmds )
235*cdf0e10cSrcweir                             System.out.println(
236*cdf0e10cSrcweir                                 "Something is wrong, I got dispatch object for "
237*cdf0e10cSrcweir                                 + aURL[0].Complete );
238*cdf0e10cSrcweir                         else
239*cdf0e10cSrcweir                             System.out.println( "Ok, dispatch object for "
240*cdf0e10cSrcweir                                                 + aURL[0].Complete  );
241*cdf0e10cSrcweir                     }
242*cdf0e10cSrcweir                     else
243*cdf0e10cSrcweir                     {
244*cdf0e10cSrcweir                         if ( !bDisabledCmds )
245*cdf0e10cSrcweir                             System.out.println("Something is wrong, I cannot get dispatch object for " + aURL[0].Complete );
246*cdf0e10cSrcweir                         else
247*cdf0e10cSrcweir                             System.out.println( "Ok, no dispatch object for "
248*cdf0e10cSrcweir                                                 + aURL[0].Complete );
249*cdf0e10cSrcweir                     }
250*cdf0e10cSrcweir                     resetURL( aURL[0] );
251*cdf0e10cSrcweir                 }
252*cdf0e10cSrcweir             }
253*cdf0e10cSrcweir             else
254*cdf0e10cSrcweir                 System.out.println( "Couldn't get XDispatchProvider from Frame!" );
255*cdf0e10cSrcweir         }
256*cdf0e10cSrcweir         else
257*cdf0e10cSrcweir             System.out.println( "Couldn't get current Frame from Desktop!" );
258*cdf0e10cSrcweir     }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     /**
261*cdf0e10cSrcweir      * Ensure that there are no disabled commands in the user layer. The
262*cdf0e10cSrcweir      * implementation removes all commands from the disabled set!
263*cdf0e10cSrcweir      */
264*cdf0e10cSrcweir     private static void enableCommands() {
265*cdf0e10cSrcweir         // Set the root path for our configuration access
266*cdf0e10cSrcweir         com.sun.star.beans.PropertyValue[] lParams =
267*cdf0e10cSrcweir             new com.sun.star.beans.PropertyValue[1];
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir         lParams[0] = new com.sun.star.beans.PropertyValue();
270*cdf0e10cSrcweir         lParams[0].Name  = new String("nodepath");
271*cdf0e10cSrcweir         lParams[0].Value = "/org.openoffice.Office.Commands/Execute/Disabled";
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir         try {
274*cdf0e10cSrcweir             // Create configuration update access to have write access to the
275*cdf0e10cSrcweir             // configuration
276*cdf0e10cSrcweir             Object xAccess = xConfigProvider.createInstanceWithArguments(
277*cdf0e10cSrcweir                              "com.sun.star.configuration.ConfigurationUpdateAccess",
278*cdf0e10cSrcweir                              lParams );
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir             com.sun.star.container.XNameAccess xNameAccess =
281*cdf0e10cSrcweir                 (com.sun.star.container.XNameAccess)UnoRuntime.queryInterface(
282*cdf0e10cSrcweir                     com.sun.star.container.XNameAccess.class, xAccess );
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir             if ( xNameAccess != null ) {
285*cdf0e10cSrcweir                 // We need the XNameContainer interface to remove the nodes by name
286*cdf0e10cSrcweir                 com.sun.star.container.XNameContainer xNameContainer =
287*cdf0e10cSrcweir                     (com.sun.star.container.XNameContainer)
288*cdf0e10cSrcweir                     UnoRuntime.queryInterface(
289*cdf0e10cSrcweir                         com.sun.star.container.XNameContainer.class, xAccess );
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir                 // Retrieves the names of all Disabled nodes
292*cdf0e10cSrcweir                 String[] aCommandsSeq = xNameAccess.getElementNames();
293*cdf0e10cSrcweir                 for ( int n = 0; n < aCommandsSeq.length; n++ ) {
294*cdf0e10cSrcweir                     try {
295*cdf0e10cSrcweir                         // remove the node
296*cdf0e10cSrcweir                         xNameContainer.removeByName( aCommandsSeq[n] );
297*cdf0e10cSrcweir                     }
298*cdf0e10cSrcweir                     catch ( com.sun.star.lang.WrappedTargetException e ) {
299*cdf0e10cSrcweir                     }
300*cdf0e10cSrcweir                     catch ( com.sun.star.container.NoSuchElementException e ) {
301*cdf0e10cSrcweir                     }
302*cdf0e10cSrcweir                 }
303*cdf0e10cSrcweir             }
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir             // Commit our changes
306*cdf0e10cSrcweir             com.sun.star.util.XChangesBatch xFlush =
307*cdf0e10cSrcweir                 (com.sun.star.util.XChangesBatch)UnoRuntime.queryInterface(
308*cdf0e10cSrcweir                     com.sun.star.util.XChangesBatch.class, xAccess);
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir             xFlush.commitChanges();
311*cdf0e10cSrcweir         }
312*cdf0e10cSrcweir         catch ( com.sun.star.uno.Exception e ) {
313*cdf0e10cSrcweir             System.out.println( "Exception detected!" );
314*cdf0e10cSrcweir             System.out.println( e );
315*cdf0e10cSrcweir         }
316*cdf0e10cSrcweir     }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir     /**
319*cdf0e10cSrcweir      * Disable all commands defined in the aCommandURLTestSet array
320*cdf0e10cSrcweir      */
321*cdf0e10cSrcweir     private static void disableCommands() {
322*cdf0e10cSrcweir         // Set the root path for our configuration access
323*cdf0e10cSrcweir         com.sun.star.beans.PropertyValue[] lParams =
324*cdf0e10cSrcweir             new com.sun.star.beans.PropertyValue[1];
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir         lParams[0] = new com.sun.star.beans.PropertyValue();
327*cdf0e10cSrcweir         lParams[0].Name  = new String("nodepath");
328*cdf0e10cSrcweir         lParams[0].Value = "/org.openoffice.Office.Commands/Execute/Disabled";
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir         try {
331*cdf0e10cSrcweir             // Create configuration update access to have write access to the
332*cdf0e10cSrcweir             // configuration
333*cdf0e10cSrcweir             Object xAccess = xConfigProvider.createInstanceWithArguments(
334*cdf0e10cSrcweir                              "com.sun.star.configuration.ConfigurationUpdateAccess",
335*cdf0e10cSrcweir                              lParams );
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir             com.sun.star.lang.XSingleServiceFactory xSetElementFactory =
338*cdf0e10cSrcweir                 (com.sun.star.lang.XSingleServiceFactory)UnoRuntime.queryInterface(
339*cdf0e10cSrcweir                     com.sun.star.lang.XSingleServiceFactory.class, xAccess );
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir             com.sun.star.container.XNameContainer xNameContainer =
342*cdf0e10cSrcweir                 (com.sun.star.container.XNameContainer)UnoRuntime.queryInterface(
343*cdf0e10cSrcweir                     com.sun.star.container.XNameContainer.class, xAccess );
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir             if ( xSetElementFactory != null && xNameContainer != null ) {
346*cdf0e10cSrcweir                 Object[] aArgs = new Object[0];
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir                 for ( int i = 0; i < aCommandURLTestSet.length; i++ ) {
349*cdf0e10cSrcweir                     // Create the nodes with the XSingleServiceFactory of the
350*cdf0e10cSrcweir                     // configuration
351*cdf0e10cSrcweir                     Object xNewElement =
352*cdf0e10cSrcweir                         xSetElementFactory.createInstanceWithArguments( aArgs );
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir                     if ( xNewElement != null ) {
355*cdf0e10cSrcweir                         // We have a new node. To set the properties of the node
356*cdf0e10cSrcweir                         // we need the XPropertySet interface.
357*cdf0e10cSrcweir                         com.sun.star.beans.XPropertySet xPropertySet =
358*cdf0e10cSrcweir                             (com.sun.star.beans.XPropertySet)
359*cdf0e10cSrcweir                             UnoRuntime.queryInterface(
360*cdf0e10cSrcweir                                 com.sun.star.beans.XPropertySet.class,
361*cdf0e10cSrcweir                                 xNewElement );
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir                         if ( xPropertySet != null ) {
364*cdf0e10cSrcweir                             // Create a unique node name.
365*cdf0e10cSrcweir                             String aCmdNodeName = new String( "Command-" );
366*cdf0e10cSrcweir                             aCmdNodeName += i;
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir                             // Insert the node into the Disabled set
369*cdf0e10cSrcweir                             xPropertySet.setPropertyValue( "Command",
370*cdf0e10cSrcweir                                                            aCommandURLTestSet[i] );
371*cdf0e10cSrcweir                             xNameContainer.insertByName( aCmdNodeName,
372*cdf0e10cSrcweir                                                          xNewElement );
373*cdf0e10cSrcweir                         }
374*cdf0e10cSrcweir                     }
375*cdf0e10cSrcweir                 }
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir                 // Commit our changes
378*cdf0e10cSrcweir                 com.sun.star.util.XChangesBatch xFlush =
379*cdf0e10cSrcweir                     (com.sun.star.util.XChangesBatch)UnoRuntime.queryInterface(
380*cdf0e10cSrcweir                         com.sun.star.util.XChangesBatch.class, xAccess);
381*cdf0e10cSrcweir                 xFlush.commitChanges();
382*cdf0e10cSrcweir             }
383*cdf0e10cSrcweir         }
384*cdf0e10cSrcweir         catch ( com.sun.star.uno.Exception e )
385*cdf0e10cSrcweir         {
386*cdf0e10cSrcweir             System.err.println( "Exception detected!" + e);
387*cdf0e10cSrcweir             e.printStackTrace();
388*cdf0e10cSrcweir         }
389*cdf0e10cSrcweir     }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir     /**
392*cdf0e10cSrcweir      * reset URL so it can be reused
393*cdf0e10cSrcweir 	 *
394*cdf0e10cSrcweir      * @param aURL
395*cdf0e10cSrcweir      *          the URL that should be reseted
396*cdf0e10cSrcweir      */
397*cdf0e10cSrcweir     private static void resetURL( com.sun.star.util.URL aURL )
398*cdf0e10cSrcweir     {
399*cdf0e10cSrcweir         aURL.Protocol   = "";
400*cdf0e10cSrcweir         aURL.User       = "";
401*cdf0e10cSrcweir         aURL.Password   = "";
402*cdf0e10cSrcweir         aURL.Server     = "";
403*cdf0e10cSrcweir         aURL.Port       = 0;
404*cdf0e10cSrcweir         aURL.Path       = "";
405*cdf0e10cSrcweir         aURL.Name       = "";
406*cdf0e10cSrcweir         aURL.Arguments  = "";
407*cdf0e10cSrcweir         aURL.Mark       = "";
408*cdf0e10cSrcweir         aURL.Main       = "";
409*cdf0e10cSrcweir         aURL.Complete   = "";
410*cdf0e10cSrcweir     }
411*cdf0e10cSrcweir }
412