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: DocTokTestService.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 "DocTokTestService.hxx"
38 #include <com/sun/star/io/XStream.hpp>
39 #include <com/sun/star/io/XInputStream.hpp>
40 #include <com/sun/star/io/XSeekable.hpp>
41 #include <com/sun/star/io/XTruncate.hpp>
42 #include <com/sun/star/task/XStatusIndicator.hpp>
43 #include <com/sun/star/container/XNameContainer.hpp>
44 #include <ucbhelper/contentbroker.hxx>
45 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
46 #include <osl/process.h>
47 #include <rtl/string.hxx>
50 #include <cppuhelper/implbase2.hxx>
51 #include <com/sun/star/embed/XTransactedObject.hpp>
52 #include <com/sun/star/embed/XStorage.hpp>
53 #include <com/sun/star/util/XCloseable.hpp>
54 #include <comphelper/storagehelper.hxx>
55 #include <com/sun/star/embed/XTransactedObject.hpp>
56 #include <com/sun/star/beans/PropertyValue.hpp>
57 #include <com/sun/star/beans/XPropertySet.hpp>
58 #include <comphelper/seqstream.hxx>
59 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
60 #include <com/sun/star/io/XInputStream.hpp>
61 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
62 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
63 #include <com/sun/star/uno/Any.hxx>
64 #include <com/sun/star/container/XNameContainer.hpp>
65 #include <resourcemodel/WW8ResourceModel.hxx>
66 #include <resourcemodel/exceptions.hxx>
67 #include <doctok/WW8Document.hxx>
71 using namespace ::com::sun::star
;
73 namespace writerfilter
{ namespace doctoktest
{
75 const sal_Char
ScannerTestService::SERVICE_NAME
[40] = "debugservices.doctok.ScannerTestService";
76 const sal_Char
ScannerTestService::IMPLEMENTATION_NAME
[40] = "debugservices.doctok.ScannerTestService";
81 ScannerTestService::ScannerTestService(const uno::Reference
< uno::XComponentContext
> &xContext_
) :
86 sal_Int32 SAL_CALL
ScannerTestService::run( const uno::Sequence
< rtl::OUString
>& aArguments
) throw (uno::RuntimeException
)
88 uno::Sequence
<uno::Any
> aUcbInitSequence(2);
89 aUcbInitSequence
[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local"));
90 aUcbInitSequence
[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office"));
91 uno::Reference
<lang::XMultiServiceFactory
> xServiceFactory(xContext
->getServiceManager(), uno::UNO_QUERY_THROW
);
92 uno::Reference
<lang::XMultiComponentFactory
> xFactory(xContext
->getServiceManager(), uno::UNO_QUERY_THROW
);
93 if (::ucbhelper::ContentBroker::initialize(xServiceFactory
, aUcbInitSequence
))
95 rtl::OUString arg
=aArguments
[0];
97 uno::Reference
<com::sun::star::ucb::XSimpleFileAccess
> xFileAccess(
98 xFactory
->createInstanceWithContext(
99 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess")),
100 xContext
), uno::UNO_QUERY_THROW
);
102 rtl_uString
*dir
=NULL
;
103 osl_getProcessWorkingDir(&dir
);
104 rtl::OUString absFileUrl
;
105 osl_getAbsoluteFileURL(dir
, arg
.pData
, &absFileUrl
.pData
);
106 rtl_uString_release(dir
);
108 uno::Reference
<io::XInputStream
> xInputStream
= xFileAccess
->openFileRead(absFileUrl
);
109 doctok::WW8Stream::Pointer_t pDocStream
= doctok::WW8DocumentFactory::createStream(xContext
, xInputStream
);
111 doctok::WW8Document::Pointer_t
pDocument(doctok::WW8DocumentFactory::createDocument(pDocStream
));
114 TimeValue t1
; osl_getSystemTime(&t1
);
117 Stream::Pointer_t pStream
= createStreamHandler();
118 pDocument
->resolve(*pStream
);
121 TimeValue t2
; osl_getSystemTime(&t2
);
122 printf("time=%is\n", t2
.Seconds
-t1
.Seconds
);
125 ::ucbhelper::ContentBroker::deinitialize();
129 fprintf(stderr
, "can't initialize UCB");
134 ::rtl::OUString
ScannerTestService_getImplementationName ()
136 return rtl::OUString::createFromAscii ( ScannerTestService::IMPLEMENTATION_NAME
);
139 sal_Bool SAL_CALL
ScannerTestService_supportsService( const ::rtl::OUString
& ServiceName
)
141 return ServiceName
.equals( rtl::OUString::createFromAscii( ScannerTestService::SERVICE_NAME
) );
143 uno::Sequence
< rtl::OUString
> SAL_CALL
ScannerTestService_getSupportedServiceNames( ) throw (uno::RuntimeException
)
145 uno::Sequence
< rtl::OUString
> aRet(1);
146 rtl::OUString
* pArray
= aRet
.getArray();
147 pArray
[0] = rtl::OUString::createFromAscii ( ScannerTestService::SERVICE_NAME
);
151 uno::Reference
< uno::XInterface
> SAL_CALL
ScannerTestService_createInstance( const uno::Reference
< uno::XComponentContext
> & xContext
) throw( uno::Exception
)
153 return (cppu::OWeakObject
*) new ScannerTestService( xContext
);
156 } } /* end namespace writerfilter::doctok */