To comment on the following update, log in, then open the issue:
http://www.openoffice.org/issues/show_bug.cgi?id=58023
                  Issue #:|58023
                  Summary:|In OOBasic macro, loadComponentFromURL leaves
                          |soffice.bin in a stuck and non-functional state
                Component:|framework
                  Version:|OOo 2.0
                 Platform:|All
                      URL:|
               OS/Version:|All
                   Status:|UNCONFIRMED
        Status whiteboard:|
                 Keywords:|
               Resolution:|
               Issue type:|DEFECT
                 Priority:|P3
             Subcomponent:|code
              Assigned to:|tm
              Reported by:|jgreif





------- Additional comments from [EMAIL PROTECTED] Wed Nov 16 09:51:47 -0800 
2005 -------
The OOBasic macros below are run from the command line as
soffice -invisible 
macro:///MDA.Conversion.ConvertExcelToNative("some-full-path")
The second argument will need to be enclosed in single-quotes in bash or other
unix shells.  

The macros are designed to convert MS Office .xls files to .ods, in a way that
is supposed to provide a clean state before and after execution (which would be
harder if instead there were communication with a long-running OOo server), exit
cleanly after all errors, documenting them in an error file, and defend against
likely errors (e.g. the input file not existing, not being a spreadsheet). 
These defenses work fine against files which are properly labeled (e.g. an MS
Office .doc file).

If the input file's extension is inconsistent with its type, in particular, if
an MS Word doc is stored in a file called some-name.doc, when the macro exits
after getting the error described below, the OOo process soffice.bin is stuck,
in such a way that OOo cannot be invoked further by that user, either as a GUI
or command-line process.  The soffice.bin process must be manually killed.

Details: The call to loadComponentFromURL in the macros returns without raising
an error (that is, nothing handled by On Local Error ...).  However, the
variable oDoc, to which its result is assigned, is not set.  The test
oDoc.supportsService(...) then fails with error code 91 "Object variable is not
set".  However, apparently loadComponentFromURL has created some XComponent
underneath that is not cleaned up, nor is a reference to it returned, because
terminating the StarDesktop does not succeed.

'-----------------------  MDA.Conversion library.module -------------------
' These macros should be loaded in the library MDA
' module Conversion.  
'  Tools -> Macros -> Organize Macros -> OpenOffice.org Basic
'   -> Organizer -> Libraries Tab
'   -> New 
' Follow same steps to add module Conversion from the Modules Tab
' Then paste the code below into that module.


Sub ConvertExcelToNative( cFile )
   Dim debug As Boolean
   Dim terminateStatus As Boolean
   debug = True
   cURL = ConvertToURL( cFile )
   cErrFile = Left(cFile, Len(cFile) - 4) + ".err"
   cLogFile = Left(cFile, Len(cFile) - 4) + ".log"

   If (Not FileExists(cFile))_
      Then
        WriteErrorFile(1, "Non-existent input file.", cErrFile)
        GoTo leave
      End If
   If (debug) Then
      logStatus("File exists", cLogFile)
      End If
   On Local Error GoTo leaveWriteError
   ' Open the document.
   ' Just blindly assume that the document is of a type that OOo will
   '  correctly recognize and open -- without specifying an import filter.
   oDoc = StarDesktop.loadComponentFromURL( cURL, "_blank", 0, Array(_
            MakePropertyValue( "Hidden", True ),_
            ) )
   If (debug) Then
      logStatus("Loaded component without error exit.", cLogFile)
      End If
   If (Not oDoc.supportsService("com.sun.star.sheet.SpreadsheetDocument"))_
     Then
        WriteErrorFile(2, "Non-spreadsheet input type.", cErrFile )
        GoTo closeIt
     End If 

   cFile = Left( cFile, Len( cFile ) - 4 ) + ".ods"
   cURL = ConvertToURL( cFile )
   
   ' Save the document in standard format.   
   oDoc.storeToURL( cURL, Array())
closeIt:   
   oDoc.close( True )
   terminateStatus = StarDesktop.Terminate()
   If (debug) Then        
      logStatus("Past desktop close and terminate " + terminateStatus, cLogFile)
      End If
   Exit Sub
leaveWriteError:
   WriteErrorFile(Err, Error$, cErrFile)
leave:
   If (debug) Then        
      logStatus("Wrote local error msg", cLogFile)
      End If
   terminateStatus = StarDesktop.Terminate()
   If (debug) Then        
      logStatus("Past desktop terminate " + terminateStatus, cLogFile)
      End If
   Exit Sub
End Sub


Function MakePropertyValue( Optional cName As String, Optional uValue ) As
com.sun.star.beans.PropertyValue
   Dim oPropertyValue As New com.sun.star.beans.PropertyValue
   If Not IsMissing( cName ) Then
      oPropertyValue.Name = cName
   EndIf
   If Not IsMissing( uValue ) Then
      oPropertyValue.Value = uValue
   EndIf
   MakePropertyValue() = oPropertyValue
End Function

Sub WriteErrorFile(code As Integer, msg As String, errFile As String)
  On Local Error Goto done
  n = FreeFile
  Open errFile for output as #n
  Print #n, code
  Print #n, msg
  Close #n
done:
  Exit Sub
End Sub

Sub logStatus(msg As String, logFile as String)
  On Local Error Goto Done
  n = FreeFile
  Open logFile for Append as #n
  Print #n msg
  Close #n
done:
  Exit Sub
End Sub

---------------------------------------------------------------------
Please do not reply to this automatically generated notification from
Issue Tracker. Please log onto the website and enter your comments.
http://qa.openoffice.org/issue_handling/project_issues.html#notification

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


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

Reply via email to