1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OOXMLTestService.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 Copyright 2005 Sun Microsystems, Inc.
35 #include <cppuhelper/implbase1.hxx>
36 #include <com/sun/star/lang/XMain.hpp>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #include <comphelper/processfactory.hxx>
40 #include "OOXMLTestService.hxx"
43 #include <com/sun/star/io/XStream.hpp>
44 #include <com/sun/star/io/XInputStream.hpp>
45 #include <com/sun/star/io/XSeekable.hpp>
46 #include <com/sun/star/io/XTruncate.hpp>
47 #include <com/sun/star/task/XStatusIndicator.hpp>
48 #include <com/sun/star/container/XNameContainer.hpp>
49 #include <ucbhelper/contentbroker.hxx>
50 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
51 #include <osl/process.h>
52 #include <rtl/string.hxx>
55 #include <cppuhelper/implbase2.hxx>
56 #include <cppuhelper/bootstrap.hxx>
57 #include <com/sun/star/embed/XTransactedObject.hpp>
58 #include <com/sun/star/embed/XStorage.hpp>
59 #include <com/sun/star/util/XCloseable.hpp>
60 #include <comphelper/storagehelper.hxx>
61 #include <com/sun/star/embed/XTransactedObject.hpp>
62 #include <com/sun/star/beans/PropertyValue.hpp>
63 #include <com/sun/star/beans/XPropertySet.hpp>
64 #include <comphelper/seqstream.hxx>
65 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
66 #include <com/sun/star/io/XInputStream.hpp>
67 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
68 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
69 #include <com/sun/star/uno/Any.hxx>
70 #include <com/sun/star/container/XNameContainer.hpp>
71 #include <com/sun/star/text/XTextDocument.hpp>
72 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
73 #include <ooxml/OOXMLDocument.hxx>
77 using namespace ::com::sun::star
;
79 namespace writerfilter
{ namespace ooxmltest
{
81 const sal_Char
ScannerTestService::SERVICE_NAME
[40] = "debugservices.ooxml.ScannerTestService";
82 const sal_Char
ScannerTestService::IMPLEMENTATION_NAME
[40] = "debugservices.ooxml.ScannerTestService";
87 ScannerTestService::ScannerTestService(const uno::Reference
< uno::XComponentContext
> &xContext_
) :
92 sal_Int32 SAL_CALL
ScannerTestService::run( const uno::Sequence
< rtl::OUString
>& aArguments
) throw (uno::RuntimeException
)
94 uno::Sequence
<uno::Any
> aUcbInitSequence(2);
95 aUcbInitSequence
[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local"));
96 aUcbInitSequence
[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office"));
97 uno::Reference
<lang::XMultiServiceFactory
> xServiceFactory(xContext
->getServiceManager(), uno::UNO_QUERY_THROW
);
98 uno::Reference
<lang::XMultiComponentFactory
> xFactory(xContext
->getServiceManager(), uno::UNO_QUERY_THROW
);
99 if (::ucbhelper::ContentBroker::initialize(xServiceFactory
, aUcbInitSequence
))
101 rtl::OUString arg
=aArguments
[0];
103 ::comphelper::setProcessServiceFactory(xServiceFactory
);
105 uno::Reference
<com::sun::star::ucb::XSimpleFileAccess
> xFileAccess
106 (xFactory
->createInstanceWithContext
107 (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
108 ("com.sun.star.ucb.SimpleFileAccess")),
109 xContext
), uno::UNO_QUERY_THROW
);
111 rtl_uString
*dir
=NULL
;
112 osl_getProcessWorkingDir(&dir
);
113 rtl::OUString absFileUrl
;
114 osl_getAbsoluteFileURL(dir
, arg
.pData
, &absFileUrl
.pData
);
115 rtl_uString_release(dir
);
117 uno::Reference
<io::XInputStream
> xInputStream
=
118 xFileAccess
->openFileRead(absFileUrl
);
119 ooxml::OOXMLStream::Pointer_t pDocStream
=
120 ooxml::OOXMLDocumentFactory::createStream(xContext
, xInputStream
);
122 ooxml::OOXMLDocument::Pointer_t pDocument
123 (ooxml::OOXMLDocumentFactory::createDocument(pDocStream
));
126 uno::Reference
<text::XTextDocument
> xDocument
127 (xFactory
->createInstanceWithContext
128 (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
129 ("com.sun.star.text.TextDocument")),
130 xContext
), uno::UNO_QUERY_THROW
);
131 uno::Reference
<frame::XModel
> xModel
132 (xDocument
, uno::UNO_QUERY_THROW
);
134 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier
135 (xDocument
, uno::UNO_QUERY_THROW
);
136 uno::Reference
<drawing::XShapes
> xShapes
137 (xDrawPageSupplier
->getDrawPage(), uno::UNO_QUERY_THROW
);
139 pDocument
->setModel(xModel
);
140 pDocument
->setShapes(xShapes
);
143 Stream::Pointer_t pStream
= createStreamHandler();
144 pDocument
->resolve(*pStream
);
146 ::ucbhelper::ContentBroker::deinitialize();
150 fprintf(stderr
, "can't initialize UCB");
155 ::rtl::OUString
ScannerTestService_getImplementationName ()
157 return rtl::OUString::createFromAscii ( ScannerTestService::IMPLEMENTATION_NAME
);
160 sal_Bool SAL_CALL
ScannerTestService_supportsService( const ::rtl::OUString
& ServiceName
)
162 return ServiceName
.equals( rtl::OUString::createFromAscii( ScannerTestService::SERVICE_NAME
) );
164 uno::Sequence
< rtl::OUString
> SAL_CALL
ScannerTestService_getSupportedServiceNames( ) throw (uno::RuntimeException
)
166 uno::Sequence
< rtl::OUString
> aRet(1);
167 rtl::OUString
* pArray
= aRet
.getArray();
168 pArray
[0] = rtl::OUString::createFromAscii ( ScannerTestService::SERVICE_NAME
);
172 uno::Reference
< uno::XInterface
> SAL_CALL
ScannerTestService_createInstance( const uno::Reference
< uno::XComponentContext
> & xContext
) throw( uno::Exception
)
174 return (cppu::OWeakObject
*) new ScannerTestService( xContext
);
177 } } /* end namespace writerfilter::ooxml */