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