OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

problem read-only...

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
fendavid
General User
General User


Joined: 25 Jul 2004
Posts: 16

PostPosted: Thu Aug 19, 2004 1:06 am    Post subject: problem read-only... Reply with quote

Hello everybody !
I have a java application (java bean), so I have an OpenOffice document (writer) embedded in my application. When I close this application, my OO document become in read-only (after closing the application, I open my OOdocument which is in read-only). Do you know why ?
I am on Linux but when I run my application on UNIX, there is no problem..

Here my code to close the application :
class WindowHandler extends WindowAdapte
{
public void windowClosing(WindowEvent evt)
{
mOfficeWriter.save();
((Window)evt.getSource()).dispose();
}
public void windowClosed(WindowEvent e)
{
mOfficeWriter.closeConnection();
System.exit(0);
}
}
Back to top
View user's profile Send private message
Jeroen
General User
General User


Joined: 09 Aug 2004
Posts: 15
Location: The Netherlands

PostPosted: Thu Aug 19, 2004 3:06 am    Post subject: Reply with quote

Hi!

It seems OpenOffice doesn't close the connection properly, because it's still busy with the save() method... Have you tried calling the save() method before the windowClosing() method? Maybe something like this:

Code:

class WindowHandler extends WindowAdapter
{
  public WindowHandler ()
  {
     mOfficeWriter.save();
  }

  public void windowClosing(WindowEvent evt)
  { 
    ((Window)evt.getSource()).dispose();
  }

  public void windowClosed(WindowEvent e)
  {
    mOfficeWriter.closeConnection();
    System.exit(0);
  }
}
Back to top
View user's profile Send private message
fendavid
General User
General User


Joined: 25 Jul 2004
Posts: 16

PostPosted: Thu Aug 19, 2004 3:23 am    Post subject: read-only Reply with quote

first, thank you for your answer.
I have tried you method but I have the same problem.. Even if I don't save the document, when I quit my application, the OOdocument become in read-only. I is very strange, because on unix, this run well.. my only solution, is to do this when I quit :
try
{
URL urlDoc=new URL(mOfficeWriter.getDocumentURL());
File doc=new File(urlDoc.getFile());
Runtime.getRuntime().exec("cp "+doc.toString()+" tmp.sxw");
Runtime.getRuntime().exec("mv tmp.sxw "+doc.toString());
}catch (Exception e) {System.out.println(e);}

But it isn't a very good solution.....
Back to top
View user's profile Send private message
Jeroen
General User
General User


Joined: 09 Aug 2004
Posts: 15
Location: The Netherlands

PostPosted: Sat Aug 21, 2004 1:57 am    Post subject: Reply with quote

Well, this maybe not a very good solution either, but you can check when you load the document if the document is read-only, if so, you can set it to not read-only...

Here are some method's that can help you accomplish that:

Code:

public void setDocumentReadOnly()
{
  this.dispatchUNOCommand(this.getTextDocument(), ".uno:EditDoc", new PropertyValue[0]);
}

public void dispatchUNOCommand(XComponent poXComponent, String pstrOperation, PropertyValue[] poaProperties)
{
  try
  {
    XModel loXModel;
    XController loXController;
    XDispatchProvider loXDispatchProvider;
    XURLTransformer loParser = null;
    XDispatch loXDispatch;

    URL[] loaParseURL;
    URL loURL;

    loXModel = (XModel)UnoRuntime.queryInterface(XModel.class, poXComponent);
    loXController = loXModel.getCurrentController();
    loXDispatchProvider = (XDispatchProvider)UnoRuntime.queryInterface(XDispatchProvider.class, loXController);
    loParser = (XURLTransformer)UnoRuntime.queryInterface(XURLTransformer.class, this.getServiceFactory().createInstance("com.sun.star.util.URLTransformer"));

    loaParseURL = new URL[1];
    loaParseURL[0] = new URL();
    loaParseURL[0].Complete = pstrOperation;
    loParser.parseStrict(loaParseURL);
    loURL = loaParseURL[0];

    loXDispatch = loXDispatchProvider.queryDispatch(loURL, "", 0);

    if (loXDispatch != null)
    {
      loXDispatch.dispatch(loURL, poaProperties);
    }
  }
  catch (Exception poException)
  {
    poException.printStackTrace();
  }

  return;
}


Now, you only need some code to check if the document is read-only, I believe thereīs a property you can use in the documentīs XPropertySet
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group