summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--desktop/inc/liblibreoffice.hxx17
-rw-r--r--desktop/inc/liblibreoffice_impl.hxx27
-rw-r--r--desktop/source/lib/init.cxx109
-rw-r--r--embedserv/source/embed/docholder.cxx3
-rw-r--r--smoketest/libtest.cxx23
5 files changed, 133 insertions, 46 deletions
diff --git a/desktop/inc/liblibreoffice.hxx b/desktop/inc/liblibreoffice.hxx
index 48c0a24edbc0..eb7715b68c8f 100644
--- a/desktop/inc/liblibreoffice.hxx
+++ b/desktop/inc/liblibreoffice.hxx
@@ -10,17 +10,26 @@
#ifndef _LIBLIBREOFFICE_HXX
#define _LIBLIBREOFFICE_HXX
-typedef struct _LODocument LODocument;
+class LODocument
+{
+public:
+ virtual ~LODocument() {}
+
+ virtual bool saveAs (const char *url) = 0;
+};
class LibLibreOffice
{
public:
- virtual bool initialize (const char *installPath) = 0;
+ virtual ~LibLibreOffice () {};
+
+ virtual bool initialize (const char *installPath) = 0;
virtual LODocument *documentLoad (const char *url) = 0;
- virtual bool documentSave (const char *url) = 0;
- virtual ~LibLibreOffice () {};
+ // return the last error as a string, free me.
+ virtual char *getError() = 0;
+
};
LibLibreOffice *lo_init (const char *install_path);
diff --git a/desktop/inc/liblibreoffice_impl.hxx b/desktop/inc/liblibreoffice_impl.hxx
deleted file mode 100644
index 3f7783ec4d67..000000000000
--- a/desktop/inc/liblibreoffice_impl.hxx
+++ /dev/null
@@ -1,27 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#ifndef _LIBLIBREOFFICE_IMPL_HXX
-#define _LIBLIBREOFFICE_IMPL_HXX
-
-#include "liblibreoffice.hxx"
-
-class LibLibreOffice_Impl : public LibLibreOffice
-{
-public:
- virtual bool initialize (const char *installPath);
-
- virtual LODocument *documentLoad (const char *url);
- virtual bool documentSave (const char *url);
-
- virtual ~LibLibreOffice_Impl ();
-};
-
-#endif
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index d564c8c8e2ae..d753f9a33ed6 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -7,9 +7,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#include <liblibreoffice_impl.hxx>
-
#include <stdio.h>
+#include <string.h>
+
+#include "liblibreoffice.hxx"
#include <tools/errinf.hxx>
#include <osl/file.hxx>
@@ -20,7 +21,9 @@
#include <comphelper/processfactory.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
@@ -34,34 +37,111 @@
using namespace ::com::sun::star;
+class LibLODocument_Impl;
+class LibLibreOffice_Impl;
+
+static LibLibreOffice_Impl *gImpl = NULL;
+
+class LibLODocument_Impl : public LODocument
+{
+ uno::Reference < css::lang::XComponent > mxComponent;
+public:
+ LibLODocument_Impl( const uno::Reference < css::lang::XComponent > &xComponent )
+ : mxComponent( xComponent )
+ { }
+ virtual bool saveAs (const char *url);
+};
+
+class LibLibreOffice_Impl : public LibLibreOffice
+{
+public:
+ rtl::OUString maLastExceptionMsg;
+
+ virtual bool initialize (const char *installPath);
+
+ virtual LODocument *documentLoad (const char *url);
+
+ virtual char *getError();
+
+ virtual ~LibLibreOffice_Impl ();
+};
+
// Wonder global state ...
static uno::Reference<css::uno::XComponentContext> xContext;
static uno::Reference<css::lang::XMultiServiceFactory> xSFactory;
static uno::Reference<css::lang::XMultiComponentFactory> xFactory;
+static OUString getUString( const char *str )
+{
+ if( !str )
+ return OUString( "" );
+ return OStringToOUString( OString( str, strlen (str) ),
+ RTL_TEXTENCODING_UTF8 );
+}
+
LODocument *
LibLibreOffice_Impl::documentLoad( const char *docUrl )
{
- OUString sUrl = OUString::createFromAscii (docUrl);
+ OUString sUrl = getUString( docUrl );
OUString sAbsoluteDocUrl, sWorkingDir, sDocPathUrl;
uno::Reference < css::frame::XDesktop2 > xComponentLoader =
css::frame::Desktop::create(xContext);
osl_getProcessWorkingDir(&sWorkingDir.pData);
- osl::FileBase::getFileURLFromSystemPath(sUrl, sDocPathUrl);
+ osl::FileBase::getFileURLFromSystemPath( sUrl, sDocPathUrl );
osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDocPathUrl, sAbsoluteDocUrl);
- uno::Reference < css::lang::XComponent > xComponent = xComponentLoader->loadComponentFromURL(
- sAbsoluteDocUrl, OUString("_blank"), 0,
- uno::Sequence < css::beans::PropertyValue >());
+ maLastExceptionMsg = "";
+ try {
+ uno::Reference < css::lang::XComponent > xComponent =
+ xComponentLoader->loadComponentFromURL(
+ sAbsoluteDocUrl, OUString("_blank"), 0,
+ uno::Sequence < css::beans::PropertyValue >());
+ if( xComponentLoader.is() )
+ return new LibLODocument_Impl( xComponent );
+ else
+ maLastExceptionMsg = "unknown load failure";
+ } catch (const uno::Exception &ex) {
+ maLastExceptionMsg = ex.Message;
+ }
return NULL;
}
-bool
-LibLibreOffice_Impl::documentSave( const char * )
+bool LibLODocument_Impl::saveAs (const char *url)
{
- return 1;
+ OUString sURL = getUString( url );
+
+ try {
+ uno::Reference< frame::XModel > xDocument( mxComponent, uno::UNO_QUERY_THROW );
+ uno::Sequence< beans::PropertyValue > aSeq = xDocument->getArgs();
+
+ OUString aFilterName;
+ for( sal_Int32 i = 0; i < aSeq.getLength(); ++i )
+ {
+ if( aSeq[i].Name == "FilterName" )
+ aSeq[i].Value >>= aFilterName;
+ }
+ aSeq.realloc(2);
+ aSeq[0].Name = "Overwrite";
+ aSeq[0].Value <<= sal_True;
+ aSeq[1].Name = "FilterName";
+ aSeq[1].Value <<= aFilterName;
+
+ uno::Reference< frame::XStorable > xStorable( mxComponent, uno::UNO_QUERY_THROW );
+ xStorable->storeAsURL( sURL, aSeq );
+
+ return true;
+ } catch (const uno::Exception &ex) {
+ gImpl->maLastExceptionMsg = "exception " + ex.Message;
+ return false;
+ }
+}
+
+char *LibLibreOffice_Impl::getError()
+{
+ OString aStr = rtl::OUStringToOString( maLastExceptionMsg, RTL_TEXTENCODING_UTF8 );
+ return strndup( aStr.getStr(), aStr.getLength() );
}
static void
@@ -154,12 +234,17 @@ extern "C" {
LibLibreOffice *liblibreoffice_hook(void)
{
- fprintf( stderr, "create libreoffice object\n" );
- return new LibLibreOffice_Impl();
+ if( !gImpl )
+ {
+ fprintf( stderr, "create libreoffice object\n" );
+ gImpl = new LibLibreOffice_Impl();
+ }
+ return gImpl;
}
LibLibreOffice_Impl::~LibLibreOffice_Impl ()
{
+ gImpl = NULL;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/embedserv/source/embed/docholder.cxx b/embedserv/source/embed/docholder.cxx
index be1cf8db8e88..7114c857937a 100644
--- a/embedserv/source/embed/docholder.cxx
+++ b/embedserv/source/embed/docholder.cxx
@@ -942,8 +942,7 @@ void DocumentHolder::setTitle(const OUString& aDocumentName)
m_xDocument->getArgs();
for(sal_Int32 j = 0; j < aSeq.getLength(); ++j)
{
- if(aSeq[j].Name ==
- OUString("FilterName"))
+ if(aSeq[j].Name == "FilterName")
{
aSeq[j].Value >>= aFilterName;
break;
diff --git a/smoketest/libtest.cxx b/smoketest/libtest.cxx
index f3d207fef39b..390774913f73 100644
--- a/smoketest/libtest.cxx
+++ b/smoketest/libtest.cxx
@@ -8,6 +8,7 @@
*/
#include <stdio.h>
+#include <malloc.h>
#include <assert.h>
#include <liblibreoffice.hxx>
@@ -28,10 +29,30 @@ int main (int argc, char **argv)
LODocument *pDocument = pOffice->documentLoad( argv[2] );
if( !pDocument )
{
- fprintf( stderr, "failed to load document '%s'\n", argv[2] );
+ char *pError = pOffice->getError();
+ fprintf( stderr, "failed to load document '%s': '%s'\n",
+ argv[2], pError );
+ free (pError);
return -1;
}
+
+ if( argc > 3 )
+ {
+ fprintf( stderr, "save document as '%s'\n", argv[3] );
+ if ( !pDocument->saveAs( argv[ 3 ] ) )
+ {
+ char *pError = pOffice->getError();
+ fprintf( stderr, "failed to save document '%s'\n", pError);
+ free (pError);
+ }
+ else
+ fprintf( stderr, "Save succeeded\n" );
+ }
fprintf( stderr, "all tests passed." );
+
+ delete pDocument;
+ delete pOffice;
+
return 0;
}