Kaydet (Commit) 49112ec9 authored tarafından Christoph Lutz's avatar Christoph Lutz Kaydeden (comit) Michael Meeks

liblibo: fixes and improvements for liblibreoffice

fixes for liblibreoffice-Impl (init.cxx): determine outputfilter from file
suffix if no filter is provided; ensure that url provided to
XStorable.storeToUrl is really an url; improved error handling

small improvements in somektest/libtest.cxx: output times required for init,
load and save.

Change-Id: Ic8b2c0d34cbeae3250c43cac02690e6ec1954ed7
üst 67311738
......@@ -166,19 +166,23 @@ LibLibreOffice_Impl::documentLoad( const char *docUrl )
bool LibLODocument_Impl::saveAs (const char *url, const char *format)
{
OUString sURL = getUString( url );
OUString sFormat = getUString( format );
OUString sUrl = getUString( url );
OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl;
osl_getProcessWorkingDir(&sWorkingDir.pData);
osl::FileBase::getFileURLFromSystemPath( sUrl, sDocPathUrl );
osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDocPathUrl, sAbsoluteDocUrl);
try {
uno::Reference< frame::XModel > xDocument( mxComponent, uno::UNO_QUERY_THROW );
uno::Sequence< beans::PropertyValue > aSeq = xDocument->getArgs();
OUString aFilterName, aDocumentService;
OUString aDocumentService;
for( sal_Int32 i = 0; i < aSeq.getLength(); ++i )
{
if( aSeq[i].Name == "FilterName" )
aSeq[i].Value >>= aFilterName;
else if( aSeq[i].Name == "DocumentService" )
if( aSeq[i].Name == "DocumentService" )
aSeq[i].Value >>= aDocumentService;
OUString aValue;
aSeq[i].Value >>= aValue;
......@@ -198,17 +202,35 @@ bool LibLODocument_Impl::saveAs (const char *url, const char *format)
else // for the sake of argument only writer documents ...
pMap = (const ExtensionMap *)aWriterExtensionMap;
if( format )
if( ! format )
{
// sniff from the extension
sal_Int32 idx = sUrl.lastIndexOf( "." );
if( idx > 0 )
{
sFormat = sUrl.copy( idx + 1 );
}
else
{
gImpl->maLastExceptionMsg = "input filename without a suffix";
return false;
}
}
OUString aFilterName;
for( sal_Int32 i = 0; pMap[i].extn; i++ )
{
for( sal_Int32 i = 0; pMap[i].extn; i++ )
if( sFormat.equalsIgnoreAsciiCaseAscii( pMap[i].extn ) )
{
if( sFormat.equalsIgnoreAsciiCaseAscii( pMap[i].extn ) )
{
aFilterName = getUString( pMap[i].filterName );
break;
}
aFilterName = getUString( pMap[i].filterName );
break;
}
}
if( ! aFilterName.getLength() )
{
gImpl->maLastExceptionMsg = "no output filter found for provided suffix";
return false;
}
aSeq.realloc(2);
aSeq[0].Name = "Overwrite";
......@@ -217,7 +239,7 @@ bool LibLODocument_Impl::saveAs (const char *url, const char *format)
aSeq[1].Value <<= aFilterName;
uno::Reference< frame::XStorable > xStorable( mxComponent, uno::UNO_QUERY_THROW );
xStorable->storeToURL( sURL, aSeq );
xStorable->storeToURL( sAbsoluteDocUrl, aSeq );
return true;
} catch (const uno::Exception &ex) {
......
......@@ -10,10 +10,18 @@
#include <stdio.h>
#include <malloc.h>
#include <assert.h>
#include <math.h>
#include <time.h>
#include <liblibreoffice.hxx>
long getTimeMS();
int main (int argc, char **argv)
{
long start, end;
start = getTimeMS();
if( argc < 2 )
return -1;
LibLibreOffice *pOffice = lo_init( argv[1] );
......@@ -25,6 +33,11 @@ int main (int argc, char **argv)
fprintf( stderr, "failed to initialize\n" );
return -1;
}
end = getTimeMS();
fprintf( stderr, "init time: %ld ms\n", (end-start) );
start = end;
fprintf( stderr, "start to load document '%s'\n", argv[2] );
LODocument *pDocument = pOffice->documentLoad( argv[2] );
if( !pDocument )
......@@ -36,6 +49,10 @@ int main (int argc, char **argv)
return -1;
}
end = getTimeMS();
fprintf( stderr, "load time: %ld ms\n", (end-start) );
start = end;
if( argc > 3 )
{
const char *pFilter = NULL;
......@@ -49,9 +66,13 @@ int main (int argc, char **argv)
free (pError);
}
else
{
fprintf( stderr, "Save succeeded\n" );
end = getTimeMS();
fprintf( stderr, "save time: %ld ms\n", (end-start) );
}
}
fprintf( stderr, "all tests passed." );
fprintf( stderr, "all tests passed.\n" );
delete pDocument;
delete pOffice;
......@@ -59,4 +80,11 @@ int main (int argc, char **argv)
return 0;
}
long getTimeMS() {
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
long ms = round(t.tv_nsec / 1.0e6) + t.tv_sec * 1000;
return ms;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment