Hello,
I'm using the OfficeBean in a java project in windows, and I'd like to disable document recovery after a crash for some documents.
I've tried to use the NoRestore Property, with no success.
If I close the application after loading the document, and then I terminate soffice.bin, on the next start of openoffice I get the Recovery window.
Any ideas?

Here's an extract from my code, look down for the complete working code if you want to test:

PropertyValue[] loadProps = new PropertyValue[1];
loadProps[0] = new PropertyValue();
loadProps[0].Name = "NoRestore";
loadProps[0].Value = new Boolean(Boolean.TRUE);
System.out.println(System.currentTimeMillis() + " - Loading blank document");
            oBean.loadFromURL("private:factory/swriter",loadProps);
String docUrl = createUNOFileURL("\\\\mobyv01\\test\\HP_DX2200_uT_P4_524.doc", oBean); System.out.println(System.currentTimeMillis() + " - Loading document: " + docUrl);
oBean.loadFromURL(docUrl, loadProps);


THIS IS THE COMPLETE CODE (TestConnection.java):

import java.awt.Frame;
import java.net.MalformedURLException;

import org.eclipse.swt.widgets.Shell;

import com.sun.star.beans.PropertyValue;
import com.sun.star.comp.beans.OOoBean;
import com.sun.star.comp.beans.OfficeDocument;
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.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;


public class TestConnection {

    static com.sun.star.uno.XComponentContext xContext = null;
    static long SLEEPTIME = 3000;
    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
//             get the remote office component context
           // xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();

           // System.out.println("Connected to a running office ...");

            Shell oShell = new Shell();
            Frame oFrame = new Frame();
            System.out.println("Creating bean");
            OOoBean oBean = new OOoBean();
            System.out.println("Created Bean");
            if (oBean.getOOoConnection()!=null)
                System.out.println("Connection is not null");
            else
                System.out.println("Connection is null");
            oFrame.add(oBean);
            oFrame.setVisible(true);
            oFrame.setSize(500, 400);
            //imposto le proprietà di apertura del documento.
//In questo caso faccio in modo che non venga chiesto il recovery in caso di crash.
            PropertyValue[] loadProps = new PropertyValue[1];
            loadProps[0] = new PropertyValue();
            loadProps[0].Name = "NoRestore";
            loadProps[0].Value = new Boolean(Boolean.TRUE);
System.out.println(System.currentTimeMillis() + " - Loading blank document");
            oBean.loadFromURL("private:factory/swriter",loadProps);
            //Thread.sleep(SLEEPTIME);
String docUrl = createUNOFileURL("\\\\mobyv01\\test\\HP_DX2200_uT_P4_524.doc", oBean); System.out.println(System.currentTimeMillis() + " - Loading document: " + docUrl);
            oBean.loadFromURL(docUrl, loadProps);
//System.out.println(System.currentTimeMillis() + " - Aquiring system window");
            //oBean.aquireSystemWindow();
System.out.println(System.currentTimeMillis() + " - Saving document");
            oBean.storeToURL("file:///C:/prova/prova.doc", null);
System.out.println(System.currentTimeMillis() + " - Document saved");
            Thread.sleep(SLEEPTIME);
//            prende il documento corrente
            OfficeDocument oDoc = oBean.getDocument();
            XMultiServiceFactory xFactory = oBean.getMultiServiceFactory();
/* richiedo alla factory il servizio (?) dispatchHelper, dapprima creandolo come object (la factory è fatta in modo * che restituisca sempre oggetti generici) e poi la casto al'interfaccia XDispatchHelper. * Non posso fare il cast direttamente perché il framework di OOO mi obbliga ad utilizzare il metodo queryInterface, * che esegue un cast "safe" dell'oggetto. Se il cast non riesce per qualche motivo, allora mi restituisce null.
             */
Object dispatchHelperObject = xFactory.createInstance("com.sun.star.frame.DispatchHelper"); XDispatchHelper xDispatchHelper = (com.sun.star.frame.XDispatchHelper) UnoRuntime.queryInterface( com.sun.star.frame.XDispatchHelper.class, dispatchHelperObject);
            XController xController = oDoc.getCurrentController();
/* questa non l'ho capita bene: Frame implementa l'interfaccia XDispatchProvider. Non so se ci sono altri servizi o
             * oggetti che la implementano.
             */
            XFrame xFrame = xController.getFrame();
XDispatchProvider xDispatchProvider = (XDispatchProvider)UnoRuntime.queryInterface(XDispatchProvider.class, xFrame); //adesso finalmente posso inviare (dispatch) il comando all'istanza remota (anche se in questo caso è in locale) di OOO. System.out.println(System.currentTimeMillis() + " - mando il comando close"); xDispatchHelper.executeDispatch(xDispatchProvider, ".uno:CloseDoc", null, 0, null); System.out.println(System.currentTimeMillis() + " - mandato il comando close");
            Thread.sleep(SLEEPTIME);
            if (oBean.getOOoDesktop().getCurrentComponent()==null) {
                System.out.println("component is null");
                //oBean = new OOoBean();
            }

            oBean.loadFromURL("file:///C:/prova/prova.doc", loadProps);
System.out.println(System.currentTimeMillis() + " - Stopping connection");
            //oBean.stopOOoConnection();
            //System.out.println("Connection stopped");
        } catch (Exception oEx) {
            System.out.println("Errore in creazione officebean");
            oEx.printStackTrace();
        }
    }

    /**
     * Creating a correct File URL that OpenOffice can handle. This is
     * necessary to be platform independent.
     *
     * @param filelocation
     * @return
     */
public static String createUNOFileURL(String filelocation, OOoBean oBean)
    {
        java.io.File newfile = new java.io.File(filelocation);
        java.net.URL before = null;
        try
        {
            before = newfile.toURL();
        }
        catch (MalformedURLException e) {
            System.out.println(e);
        }

        String myUNOFileURL = "";
        try {
        // Create a URL, which can be used by UNO
            myUNOFileURL =  com.sun.star.uri.ExternalUriReferenceTranslator

.create(oBean.getOOoConnection().getComponentContext()).translateToInternal(before.toExternalForm());
        } catch (Exception oEx) {
            System.out.println("Errore: ");
            oEx.printStackTrace();
        }
        if (myUNOFileURL.length() == 0 && filelocation.length() > 0)
        {
            System.out.println("File URL conversion faild. Filelocation " +
                    "contains illegal characters: " + filelocation);
        }
        return myUNOFileURL;
    }

}

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

Reply via email to