LibreOffice Module reportdesign (master)  1
dbloader2.cxx
Go to the documentation of this file.
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 #include "dbloader2.hxx"
20 #include <tools/urlobj.hxx>
24 #include <comphelper/types.hxx>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/embed/XStorage.hpp>
28 
29 namespace rptxml
30 {
31 
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::io;
34 using namespace ::com::sun::star::util;
35 using namespace ::com::sun::star::beans;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star::document;
38 using namespace ::com::sun::star::embed;
39 using namespace ::com::sun::star::ui::dialogs;
40 
41 
43 : m_xContext(xContext)
44 {
45 }
46 
47 OUString SAL_CALL ORptTypeDetection::detect( Sequence< css::beans::PropertyValue >& Descriptor )
48 {
49 
50  ::comphelper::SequenceAsHashMap aTemp(Descriptor);
51  OUString sTemp = aTemp.getUnpackedValueOrDefault("URL",OUString());
52 
53  if ( !sTemp.isEmpty() )
54  {
55  INetURLObject aURL(sTemp);
56  if ( aURL.GetFileExtension().equalsIgnoreAsciiCase("orp") )
57  return "StarBaseReport";
58  else
59  {
60  try
61  {
62  Reference<XPropertySet> xProp(::comphelper::OStorageHelper::GetStorageFromURL(sTemp,ElementModes::READ, m_xContext),UNO_QUERY);
63  if ( xProp.is() )
64  {
65  OUString sMediaType;
66  xProp->getPropertyValue("MediaType") >>= sMediaType;
67  if ( sMediaType == MIMETYPE_OASIS_OPENDOCUMENT_REPORT_ASCII )
68  return "StarBaseReport";
69  ::comphelper::disposeComponent(xProp);
70  }
71  }
72  catch(Exception&)
73  {
74  }
75  }
76  }
77  return OUString();
78 }
79 
80 // XServiceInfo
82 {
83  return "com.sun.star.comp.report.ORptTypeDetection";
84 }
85 
86 
87 // XServiceInfo
88 sal_Bool SAL_CALL ORptTypeDetection::supportsService(const OUString& ServiceName)
89 {
90  return cppu::supportsService(this, ServiceName);
91 }
92 
93 // XServiceInfo
95 {
96  return { "com.sun.star.document.ExtendedTypeDetection" };
97 }
98 
99 
100 }//rptxml
101 
102 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
104  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
105 {
106  return cppu::acquire(new rptxml::ORptTypeDetection(context));
107 }
108 
109 
110 
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
URL aURL
ORptTypeDetection(css::uno::Reference< css::uno::XComponentContext > const &xContext)
Definition: dbloader2.cxx:42
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: dbloader2.hxx:34
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * reportdesign_ORptTypeDetection_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: dbloader2.cxx:103
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OUString SAL_CALL getImplementationName() override
Definition: dbloader2.cxx:81
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
unsigned char sal_Bool
static css::uno::Reference< css::embed::XStorage > GetStorageFromURL(const OUString &aURL, sal_Int32 nStorageMode, const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: dbloader2.cxx:94
virtual OUString SAL_CALL detect(css::uno::Sequence< css::beans::PropertyValue > &Descriptor) override
Definition: dbloader2.cxx:47
constexpr OUStringLiteral sMediaType
OUString GetFileExtension() const
#define MIMETYPE_OASIS_OPENDOCUMENT_REPORT_ASCII
sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: dbloader2.cxx:88
Reference< XComponentContext > m_xContext