Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <cppuhelper/implementationentry.hxx>
21 : #include <cppuhelper/supportsservice.hxx>
22 : #include <WriterFilterDetection.hxx>
23 : #include <comphelper/storagehelper.hxx>
24 : #include <com/sun/star/io/XInputStream.hpp>
25 : #include <sot/storage.hxx>
26 : #include <unotools/ucbstreamhelper.hxx>
27 :
28 : using namespace ::com::sun::star;
29 :
30 0 : WriterFilterDetection::WriterFilterDetection(
31 : const uno::Reference< uno::XComponentContext >& rxContext) :
32 0 : m_xContext( rxContext )
33 : {
34 0 : }
35 :
36 :
37 0 : WriterFilterDetection::~WriterFilterDetection()
38 : {
39 0 : }
40 :
41 :
42 40 : OUString WriterFilterDetection_getImplementationName () throw (uno::RuntimeException)
43 : {
44 40 : return OUString ( "com.sun.star.comp.Writer.WriterFilterDetector" );
45 : }
46 :
47 :
48 :
49 0 : OUString WriterFilterDetection::detect( uno::Sequence< beans::PropertyValue >& rDescriptor )
50 : throw( uno::RuntimeException, std::exception )
51 : {
52 0 : OUString sTypeName;
53 0 : bool bWord = false;
54 0 : sal_Int32 nPropertyCount = rDescriptor.getLength();
55 0 : const beans::PropertyValue* pValues = rDescriptor.getConstArray();
56 0 : OUString sURL;
57 0 : uno::Reference < io::XStream > xStream;
58 0 : uno::Reference < io::XInputStream > xInputStream;
59 0 : for( sal_Int32 nProperty = 0; nProperty < nPropertyCount; ++nProperty )
60 : {
61 0 : if ( pValues[nProperty].Name == "TypeName" )
62 0 : rDescriptor[nProperty].Value >>= sTypeName;
63 0 : else if ( pValues[nProperty].Name == "URL" )
64 0 : pValues[nProperty].Value >>= sURL;
65 0 : else if ( pValues[nProperty].Name == "Stream" )
66 0 : pValues[nProperty].Value >>= xStream;
67 0 : else if ( pValues[nProperty].Name == "InputStream" )
68 0 : pValues[nProperty].Value >>= xInputStream;
69 : }
70 : try
71 : {
72 0 : uno::Reference< embed::XStorage > xDocStorage;
73 0 : if ( sURL == "private:stream" )
74 0 : xDocStorage = comphelper::OStorageHelper::GetStorageFromInputStream( xInputStream );
75 : else
76 0 : xDocStorage = comphelper::OStorageHelper::GetStorageFromURL( sURL, embed::ElementModes::READ );
77 0 : if( xDocStorage.is() )
78 : {
79 0 : uno::Sequence< OUString > aNames = xDocStorage->getElementNames();
80 0 : const OUString* pNames = aNames.getConstArray();
81 0 : for(sal_Int32 nName = 0; nName < aNames.getLength(); ++nName)
82 : {
83 0 : if ( pNames[nName] == "word" )
84 : {
85 0 : bWord = true;
86 0 : if( sTypeName.isEmpty() )
87 0 : sTypeName = "writer_MS_Word_2007";
88 0 : break;
89 : }
90 0 : }
91 0 : }
92 : }
93 0 : catch(const uno::Exception&)
94 : {
95 : OSL_FAIL("exception while opening storage");
96 : }
97 0 : if( !bWord )
98 0 : sTypeName = OUString();
99 0 : return sTypeName;
100 : }
101 :
102 :
103 0 : uno::Sequence< OUString > WriterFilterDetection_getSupportedServiceNames( ) throw (uno::RuntimeException)
104 : {
105 0 : uno::Sequence < OUString > aRet(1);
106 0 : OUString* pArray = aRet.getArray();
107 0 : pArray[0] = "com.sun.star.document.ExtendedTypeDetection";
108 0 : return aRet;
109 : }
110 :
111 :
112 0 : uno::Reference< uno::XInterface > WriterFilterDetection_createInstance( const uno::Reference< uno::XComponentContext >& xContext)
113 : throw( uno::Exception )
114 : {
115 0 : return (cppu::OWeakObject*) new WriterFilterDetection( xContext );
116 : }
117 :
118 :
119 0 : OUString WriterFilterDetection::getImplementationName( ) throw (uno::RuntimeException, std::exception)
120 : {
121 0 : return WriterFilterDetection_getImplementationName();
122 : }
123 :
124 :
125 0 : sal_Bool WriterFilterDetection::supportsService( const OUString& rServiceName ) throw (uno::RuntimeException, std::exception)
126 : {
127 0 : return cppu::supportsService( this, rServiceName );
128 : }
129 :
130 :
131 0 : uno::Sequence< OUString > WriterFilterDetection::getSupportedServiceNames( ) throw (uno::RuntimeException, std::exception)
132 : {
133 0 : return WriterFilterDetection_getSupportedServiceNames();
134 : }
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|