fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / form / fmdocumentclassification.cxx
blob35a6f7bba4580be2361b0cbc2dc013c0b2e4a859
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "fmdocumentclassification.hxx"
22 #include "svx/dbtoolsclient.hxx"
24 #include <com/sun/star/container/XChild.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/xforms/XFormsSupplier.hpp>
27 #include <com/sun/star/sdbc/XConnection.hpp>
28 #include <com/sun/star/frame/XModule.hpp>
30 #include <tools/diagnose_ex.h>
32 //........................................................................
33 namespace svxform
35 //........................................................................
37 namespace
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::XInterface;
41 using ::com::sun::star::container::XChild;
42 using ::com::sun::star::frame::XModel;
43 using ::com::sun::star::uno::UNO_QUERY;
44 using ::com::sun::star::frame::XModule;
46 //....................................................................
47 template< class TYPE >
48 Reference< TYPE > getTypedModelNode( const Reference< XInterface >& _rxModelNode )
50 Reference< TYPE > xTypedNode( _rxModelNode, UNO_QUERY );
51 if ( xTypedNode.is() )
52 return xTypedNode;
53 else
55 Reference< XChild > xChild( _rxModelNode, UNO_QUERY );
56 if ( xChild.is() )
57 return getTypedModelNode< TYPE >( xChild->getParent() );
58 else
59 return Reference< TYPE >();
63 //....................................................................
64 Reference< XModel > getDocument( const Reference< XInterface >& _rxModelNode )
66 return getTypedModelNode< XModel >( _rxModelNode );
70 using namespace ::com::sun::star::uno;
71 using namespace ::com::sun::star::frame;
72 using namespace ::com::sun::star::lang;
73 using namespace ::com::sun::star::xforms;
74 using namespace ::com::sun::star::container;
75 using namespace ::com::sun::star::sdbc;
77 //====================================================================
78 //====================================================================
79 namespace
81 //----------------------------------------------------------------
82 struct ModuleInfo
84 const sal_Char* pAsciiModuleOrServiceName;
85 DocumentType eType;
88 //----------------------------------------------------------------
89 const ModuleInfo* lcl_getModuleInfo()
91 static const ModuleInfo aModuleInfo[] =
93 { "com.sun.star.text.TextDocument", eTextDocument },
94 { "com.sun.star.text.WebDocument", eWebDocument },
95 { "com.sun.star.sheet.SpreadsheetDocument", eSpreadsheetDocument },
96 { "com.sun.star.drawing.DrawingDocument", eDrawingDocument },
97 { "com.sun.star.presentation.PresentationDocument", ePresentationDocument },
98 { "com.sun.star.xforms.XMLFormDocument", eEnhancedForm },
99 { "com.sun.star.sdb.FormDesign", eDatabaseForm },
100 { "com.sun.star.sdb.TextReportDesign", eDatabaseReport },
101 { "com.sun.star.text.GlobalDocument", eTextDocument },
102 { NULL, eUnknownDocumentType }
104 return aModuleInfo;
108 //====================================================================
109 //= DocumentClassification
110 //====================================================================
111 //--------------------------------------------------------------------
112 DocumentType DocumentClassification::classifyDocument( const Reference< XModel >& _rxDocumentModel ) SAL_THROW(())
114 DocumentType eType( eUnknownDocumentType );
116 OSL_ENSURE( _rxDocumentModel.is(), "DocumentClassification::classifyDocument: invalid document!" );
117 if ( !_rxDocumentModel.is() )
118 return eType;
122 // first, check whether the document has a ModuleIdentifier which we know
123 Reference< XModule > xModule( _rxDocumentModel, UNO_QUERY );
124 if ( xModule.is() )
125 eType = getDocumentTypeForModuleIdentifier( xModule->getIdentifier() );
126 if ( eType != eUnknownDocumentType )
127 return eType;
129 // second, check whether it supports one of the services we know
130 Reference< XServiceInfo > xSI( _rxDocumentModel, UNO_QUERY_THROW );
131 const ModuleInfo* pModuleInfo = lcl_getModuleInfo();
132 while ( pModuleInfo->pAsciiModuleOrServiceName )
134 if ( xSI->supportsService( OUString::createFromAscii( pModuleInfo->pAsciiModuleOrServiceName ) ) )
135 return pModuleInfo->eType;
136 ++pModuleInfo;
139 // last: uhm, there is no last resort
140 OSL_FAIL( "DocumentClassification::classifyDocument: unknown document!" );
142 catch( const Exception& )
144 DBG_UNHANDLED_EXCEPTION();
147 return eType;
150 //--------------------------------------------------------------------
151 DocumentType DocumentClassification::classifyHostDocument( const Reference< XInterface >& _rxFormComponent ) SAL_THROW(())
153 DocumentType eType( eUnknownDocumentType );
157 Reference< XModel > xDocument( getDocument( _rxFormComponent.get() ) );
158 if ( !xDocument.is() )
159 return eUnknownDocumentType;
160 eType = classifyDocument( xDocument );
162 catch( const Exception& )
164 OSL_FAIL( "DocumentClassification::classifyHostDocument: caught an exception!" );
167 return eType;
170 //--------------------------------------------------------------------
171 DocumentType DocumentClassification::getDocumentTypeForModuleIdentifier( const OUString& _rModuleIdentifier )
173 const ModuleInfo* pModuleInfo = lcl_getModuleInfo();
174 while ( pModuleInfo->pAsciiModuleOrServiceName )
176 if ( _rModuleIdentifier.equalsAscii( pModuleInfo->pAsciiModuleOrServiceName ) )
177 return pModuleInfo->eType;
178 ++pModuleInfo;
180 return eUnknownDocumentType;
183 //--------------------------------------------------------------------
184 OUString DocumentClassification::getModuleIdentifierForDocumentType( DocumentType _eType )
186 const ModuleInfo* pModuleInfo = lcl_getModuleInfo();
187 while ( pModuleInfo->pAsciiModuleOrServiceName )
189 if ( pModuleInfo->eType == _eType )
190 return OUString::createFromAscii( pModuleInfo->pAsciiModuleOrServiceName );
191 ++pModuleInfo;
193 return OUString();
196 //........................................................................
197 } // namespace svxform
198 //........................................................................
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */