Hi Tom & Mathias,

@Mathias: thanks for your review.

@Tom: a new snippet with linking.

>>> I will post it soon as a snippet. Please review it and add
>>> comments/corrections.
> 
>> Done. :-)
> 
> Thanks Matthias. I'll post it Monday as a snippet.

Greetings, Tobias
<?xml version="1.0"?>
<!--
$RCSfile: $
last change: $Revision: $ $Author: $ $Date: $

(c)2003 by the copyright holders listed with the author-tags.
If no explicit copyright holder is mentioned with a certain author,
the author him-/herself is the copyright holder. All rights reserved.

Public Documentation License Notice:

The contents of this Documentation are subject to the
Public Documentation License Version 1.0 (the "License");
you may only use this Documentation if you comply with
the terms of this License. A copy of the License is
available at http://www.openoffice.org/licenses/PDL.html

The Original Documentation can be found in the CVS archives
of openoffice.org at the place specified by RCSfile: in this header.

The Initial Writer(s) of the Original Documentation are listed
with the author-tags below.

The Contributor(s) are listed with the author-tags below
without the marker for being an initial author.

All Rights Reserved.
-->

<snippet language="Java" application="Office">

<keywords>
	<keyword>.uno:SaveTo</keyword>
	<keyword>.uno:SaveAs</keyword>
	<keyword>save</keyword>
	<keyword>store</keyword>
	<keyword>XStorable</keyword>
</keywords>

<authors>
	<author id="tobiaskrais" initial="false" email="[EMAIL PROTECTED]" copyright="Copy and use it.">Tobias Krais</author>
</authors>

<question heading="&quot;Save as...&quot; but remain at old URL">How to save a document under a new URL but remain a representative of the old URL?
</question>

<answer>
<listing>import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XController;
import com.sun.star.frame.XDispatchHelper;
import com.sun.star.frame.XDispatchProvider;
import com.sun.star.frame.XFrame;
import com.sun.star.frame.XModel;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

// Conditions:
// XComponentContext xRemoteContext (how to get: {%internal ../Office/Office.BootstrapOpenOffice.snip})
// XComponent openDocument (how to get: {%internal ../Office/Office.OpenDocumentFromURL.snip})

    /**
     * This function shows the SaveAs dialog to the user but continues after
     * saving with the old file URL representative.
     */
    public void saveTo()
    {
        // Setting the SaveTo properties
        PropertyValue[] saveProperties = new PropertyValue[1];
        saveProperties[0] = new PropertyValue();
        saveProperties[0].Name = &quot;SaveTo&quot;;
        saveProperties[0].Value = true;

        // Getting the Dispatch Provider
        XModel xModel = (XModel) UnoRuntime.queryInterface (
                XModel.class, openDocument);
        XController xController = xModel.getCurrentController();
        XFrame xFrame = xController.getFrame();
        XDispatchProvider xDispatchProvider = (XDispatchProvider)
                UnoRuntime.queryInterface (XDispatchProvider.class, xFrame);

        // Getting the Dispatch Helper
        XMultiServiceFactory xMultiServiceManager = (XMultiServiceFactory)
                UnoRuntime.queryInterface( XMultiServiceFactory.class,
                        xRemoteContext.getServiceManager());
        Object oDispatchHelper = null;
        try{
            oDispatchHelper = xMultiServiceManager.createInstance(
                    &quot;com.sun.star.frame.DispatchHelper&quot;);
        }
        catch(com.sun.star.uno.Exception e)
        {
            System.out.println(&quot;Can&apos;t get the Dispatch Helper Object...&quot;);
        }
        XDispatchHelper xDispatchHelper = (XDispatchHelper)
                UnoRuntime.queryInterface(XDispatchHelper.class, oDispatchHelper);
        // Executing the commandURL
        xDispatchHelper.executeDispatch(xDispatchProvider,
                &quot;.uno:SaveAs&quot;,
                &quot;_self&quot;,
                0,
                saveProperties);
    }</listing>
</answer>

<versions>
	<version number="2.0.x" status="tested"/>
	<version number="1.1.x" status="untested"/>
</versions>

<operating-systems>
<operating-system name="All"/>
</operating-systems>

<changelog>
	<change author-id="tobiaskrais" date="2006-04-03">Initial version</change>
</changelog>

</snippet>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to