1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "DocTokTestService.hxx"
25 #include <stdio.h>
26 #include <wchar.h>
27 #include <com/sun/star/io/XStream.hpp>
28 #include <com/sun/star/io/XInputStream.hpp>
29 #include <com/sun/star/io/XSeekable.hpp>
30 #include <com/sun/star/io/XTruncate.hpp>
31 #include <com/sun/star/task/XStatusIndicator.hpp>
32 #include <com/sun/star/container/XNameContainer.hpp>
33 #include <ucbhelper/contentbroker.hxx>
34 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
35 #include <osl/process.h>
36 #include <rtl/string.hxx>
37 #include <hash_set>
38 #include <assert.h>
39 #include <cppuhelper/implbase2.hxx>
40 #include <com/sun/star/embed/XTransactedObject.hpp>
41 #include <com/sun/star/embed/XStorage.hpp>
42 #include <com/sun/star/util/XCloseable.hpp>
43 #include <comphelper/storagehelper.hxx>
44 #include <com/sun/star/embed/XTransactedObject.hpp>
45 #include <com/sun/star/beans/PropertyValue.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <comphelper/seqstream.hxx>
48 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
49 #include <com/sun/star/io/XInputStream.hpp>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
52 #include <com/sun/star/uno/Any.hxx>
53 #include <com/sun/star/container/XNameContainer.hpp>
54 #include <resourcemodel/WW8ResourceModel.hxx>
55 #include <resourcemodel/exceptions.hxx>
56 #include <doctok/WW8Document.hxx>
57 
58 #include <ctype.h>
59 
60 using namespace ::com::sun::star;
61 
62 namespace writerfilter { namespace doctoktest  {
63 
64 const sal_Char ScannerTestService::SERVICE_NAME[40] = "debugservices.doctok.ScannerTestService";
65 const sal_Char ScannerTestService::IMPLEMENTATION_NAME[40] = "debugservices.doctok.ScannerTestService";
66 
67 
68 
69 
ScannerTestService(const uno::Reference<uno::XComponentContext> & xContext_)70 ScannerTestService::ScannerTestService(const uno::Reference< uno::XComponentContext > &xContext_) :
71 xContext( xContext_ )
72 {
73 }
74 
run(const uno::Sequence<rtl::OUString> & aArguments)75 sal_Int32 SAL_CALL ScannerTestService::run( const uno::Sequence< rtl::OUString >& aArguments ) throw (uno::RuntimeException)
76 {
77 	uno::Sequence<uno::Any> aUcbInitSequence(2);
78 	aUcbInitSequence[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local"));
79 	aUcbInitSequence[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office"));
80 	uno::Reference<lang::XMultiServiceFactory> xServiceFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW);
81 	uno::Reference<lang::XMultiComponentFactory> xFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW );
82     if (::ucbhelper::ContentBroker::initialize(xServiceFactory, aUcbInitSequence))
83 	{
84 			rtl::OUString arg=aArguments[0];
85 
86 			uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess(
87 			xFactory->createInstanceWithContext(
88 				::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess")),
89 				xContext), uno::UNO_QUERY_THROW );
90 
91 			rtl_uString *dir=NULL;
92 			osl_getProcessWorkingDir(&dir);
93 			rtl::OUString absFileUrl;
94 			osl_getAbsoluteFileURL(dir, arg.pData, &absFileUrl.pData);
95 			rtl_uString_release(dir);
96 
97 			uno::Reference<io::XInputStream> xInputStream = xFileAccess->openFileRead(absFileUrl);
98             doctok::WW8Stream::Pointer_t pDocStream = doctok::WW8DocumentFactory::createStream(xContext, xInputStream);
99 
100 			doctok::WW8Document::Pointer_t pDocument(doctok::WW8DocumentFactory::createDocument(pDocStream));
101 
102 #if 0
103 		TimeValue t1; osl_getSystemTime(&t1);
104 #endif
105 
106 		Stream::Pointer_t pStream = createStreamHandler();
107 		pDocument->resolve(*pStream);
108 
109 #if 0
110 		TimeValue t2; osl_getSystemTime(&t2);
111 		printf("time=%is\n", t2.Seconds-t1.Seconds);
112 #endif
113 
114         ::ucbhelper::ContentBroker::deinitialize();
115 	}
116 	else
117 	{
118 		fprintf(stderr, "can't initialize UCB");
119 	}
120 	return 0;
121 }
122 
ScannerTestService_getImplementationName()123 ::rtl::OUString ScannerTestService_getImplementationName ()
124 {
125 	return rtl::OUString::createFromAscii ( ScannerTestService::IMPLEMENTATION_NAME );
126 }
127 
ScannerTestService_supportsService(const::rtl::OUString & ServiceName)128 sal_Bool SAL_CALL ScannerTestService_supportsService( const ::rtl::OUString& ServiceName )
129 {
130 	return ServiceName.equals( rtl::OUString::createFromAscii( ScannerTestService::SERVICE_NAME ) );
131 }
ScannerTestService_getSupportedServiceNames()132 uno::Sequence< rtl::OUString > SAL_CALL ScannerTestService_getSupportedServiceNames(  ) throw (uno::RuntimeException)
133 {
134 	uno::Sequence < rtl::OUString > aRet(1);
135 	rtl::OUString* pArray = aRet.getArray();
136 	pArray[0] =  rtl::OUString::createFromAscii ( ScannerTestService::SERVICE_NAME );
137 	return aRet;
138 }
139 
ScannerTestService_createInstance(const uno::Reference<uno::XComponentContext> & xContext)140 uno::Reference< uno::XInterface > SAL_CALL ScannerTestService_createInstance( const uno::Reference< uno::XComponentContext > & xContext) throw( uno::Exception )
141 {
142 	return (cppu::OWeakObject*) new ScannerTestService( xContext );
143 }
144 
145 } } /* end namespace writerfilter::doctok */
146