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 <cppuhelper/implbase1.hxx>
25 #include <com/sun/star/lang/XMain.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <comphelper/processfactory.hxx>
28 
29 #include "OOXMLTestService.hxx"
30 #include <stdio.h>
31 #include <wchar.h>
32 #include <com/sun/star/io/XStream.hpp>
33 #include <com/sun/star/io/XInputStream.hpp>
34 #include <com/sun/star/io/XSeekable.hpp>
35 #include <com/sun/star/io/XTruncate.hpp>
36 #include <com/sun/star/task/XStatusIndicator.hpp>
37 #include <com/sun/star/container/XNameContainer.hpp>
38 #include <ucbhelper/contentbroker.hxx>
39 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
40 #include <osl/process.h>
41 #include <rtl/string.hxx>
42 #include <hash_set>
43 #include <assert.h>
44 #include <cppuhelper/implbase2.hxx>
45 #include <cppuhelper/bootstrap.hxx>
46 #include <com/sun/star/embed/XTransactedObject.hpp>
47 #include <com/sun/star/embed/XStorage.hpp>
48 #include <com/sun/star/util/XCloseable.hpp>
49 #include <comphelper/storagehelper.hxx>
50 #include <com/sun/star/embed/XTransactedObject.hpp>
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #include <com/sun/star/beans/XPropertySet.hpp>
53 #include <comphelper/seqstream.hxx>
54 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
55 #include <com/sun/star/io/XInputStream.hpp>
56 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
57 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
58 #include <com/sun/star/uno/Any.hxx>
59 #include <com/sun/star/container/XNameContainer.hpp>
60 #include <com/sun/star/text/XTextDocument.hpp>
61 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
62 #include <ooxml/OOXMLDocument.hxx>
63 #include <resourcemodel/TagLogger.hxx>
64 
65 #include <ctype.h>
66 
67 using namespace ::com::sun::star;
68 
69 namespace writerfilter { namespace ooxmltest  {
70 
71 const sal_Char ScannerTestService::SERVICE_NAME[40] = "debugservices.ooxml.ScannerTestService";
72 const sal_Char ScannerTestService::IMPLEMENTATION_NAME[40] = "debugservices.ooxml.ScannerTestService";
73 
74 
75 
76 
ScannerTestService(const uno::Reference<uno::XComponentContext> & xContext_)77 ScannerTestService::ScannerTestService(const uno::Reference< uno::XComponentContext > &xContext_) :
78 xContext( xContext_ )
79 {
80 }
81 
run(const uno::Sequence<rtl::OUString> & aArguments)82 sal_Int32 SAL_CALL ScannerTestService::run( const uno::Sequence< rtl::OUString >& aArguments ) throw (uno::RuntimeException)
83 {
84 	uno::Sequence<uno::Any> aUcbInitSequence(2);
85 	aUcbInitSequence[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local"));
86 	aUcbInitSequence[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office"));
87 	uno::Reference<lang::XMultiServiceFactory> xServiceFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW);
88 	uno::Reference<lang::XMultiComponentFactory> xFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW );
89     if (::ucbhelper::ContentBroker::initialize(xServiceFactory, aUcbInitSequence))
90 	{
91 #ifdef DEBUG_ELEMENT
92         writerfilter::TagLogger::Pointer_t debugLogger
93         (writerfilter::TagLogger::getInstance("DEBUG"));
94         debugLogger->startDocument();
95 #endif
96 
97         rtl::OUString arg=aArguments[0];
98 
99         ::comphelper::setProcessServiceFactory(xServiceFactory);
100 
101         uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess
102             (xFactory->createInstanceWithContext
103              (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
104                               ("com.sun.star.ucb.SimpleFileAccess")),
105               xContext), uno::UNO_QUERY_THROW );
106 
107         rtl_uString *dir=NULL;
108         osl_getProcessWorkingDir(&dir);
109         rtl::OUString absFileUrl;
110         osl_getAbsoluteFileURL(dir, arg.pData, &absFileUrl.pData);
111         rtl_uString_release(dir);
112 
113         uno::Reference<io::XInputStream> xInputStream =
114             xFileAccess->openFileRead(absFileUrl);
115         ooxml::OOXMLStream::Pointer_t pDocStream =
116             ooxml::OOXMLDocumentFactory::createStream(xContext, xInputStream);
117 
118         ooxml::OOXMLDocument::Pointer_t pDocument
119             (ooxml::OOXMLDocumentFactory::createDocument(pDocStream));
120 
121 #if 0
122         uno::Reference<text::XTextDocument> xDocument
123             (xFactory->createInstanceWithContext
124              (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
125                               ("com.sun.star.text.TextDocument")),
126               xContext), uno::UNO_QUERY_THROW );
127         uno::Reference<frame::XModel> xModel
128             (xDocument, uno::UNO_QUERY_THROW);
129 
130         uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier
131             (xDocument, uno::UNO_QUERY_THROW);
132         uno::Reference<drawing::XShapes> xShapes
133             (xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW);
134 
135         pDocument->setModel(xModel);
136         pDocument->setShapes(xShapes);
137 #endif
138 
139 		Stream::Pointer_t pStream = createStreamHandler();
140 		pDocument->resolve(*pStream);
141 
142 #ifdef DEBUG_ELEMENT
143         writerfilter::TagLogger::dump("DEBUG");
144         debugLogger->endDocument();
145 #endif
146 
147         ::ucbhelper::ContentBroker::deinitialize();
148 	}
149 	else
150 	{
151 		fprintf(stderr, "can't initialize UCB");
152 	}
153 	return 0;
154 }
155 
ScannerTestService_getImplementationName()156 ::rtl::OUString ScannerTestService_getImplementationName ()
157 {
158 	return rtl::OUString::createFromAscii ( ScannerTestService::IMPLEMENTATION_NAME );
159 }
160 
ScannerTestService_supportsService(const::rtl::OUString & ServiceName)161 sal_Bool SAL_CALL ScannerTestService_supportsService( const ::rtl::OUString& ServiceName )
162 {
163 	return ServiceName.equals( rtl::OUString::createFromAscii( ScannerTestService::SERVICE_NAME ) );
164 }
ScannerTestService_getSupportedServiceNames()165 uno::Sequence< rtl::OUString > SAL_CALL ScannerTestService_getSupportedServiceNames(  ) throw (uno::RuntimeException)
166 {
167 	uno::Sequence < rtl::OUString > aRet(1);
168 	rtl::OUString* pArray = aRet.getArray();
169 	pArray[0] =  rtl::OUString::createFromAscii ( ScannerTestService::SERVICE_NAME );
170 	return aRet;
171 }
172 
ScannerTestService_createInstance(const uno::Reference<uno::XComponentContext> & xContext)173 uno::Reference< uno::XInterface > SAL_CALL ScannerTestService_createInstance( const uno::Reference< uno::XComponentContext > & xContext) throw( uno::Exception )
174 {
175 	return (cppu::OWeakObject*) new ScannerTestService( xContext );
176 }
177 
178 } } /* end namespace writerfilter::ooxml */
179