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 #include "precompiled_reportdesign.hxx"
24 #include "dbloader2.hxx"
25 #include <comphelper/sequence.hxx>
26 // -------------------------------------------------------------------------
27 namespace rptxml
28 {
29 
30 using namespace ::ucbhelper;
31 using namespace ::com::sun::star::task;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::ucb;
34 using namespace ::com::sun::star::io;
35 using namespace ::com::sun::star::util;
36 using namespace ::com::sun::star::frame;
37 using namespace ::com::sun::star::beans;
38 using namespace ::com::sun::star::container;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star::document;
41 using namespace ::com::sun::star::registry;
42 using namespace ::com::sun::star::embed;
43 using namespace ::com::sun::star::ui::dialogs;
44 using ::com::sun::star::awt::XWindow;
45 
46 // -------------------------------------------------------------------------
ORptTypeDetection(Reference<XComponentContext> const & xContext)47 ORptTypeDetection::ORptTypeDetection(Reference< XComponentContext > const & xContext)
48 : m_xContext(xContext)
49 {
50 }
51 // -------------------------------------------------------------------------
detect(Sequence<::com::sun::star::beans::PropertyValue> & Descriptor)52 ::rtl::OUString SAL_CALL ORptTypeDetection::detect( Sequence< ::com::sun::star::beans::PropertyValue >& Descriptor ) throw (RuntimeException)
53 {
54 
55 	::comphelper::SequenceAsHashMap aTemp(Descriptor);
56 	::rtl::OUString sTemp = aTemp.getUnpackedValueOrDefault(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL")),::rtl::OUString());
57 
58 	if ( sTemp.getLength() )
59 	{
60 		INetURLObject aURL(sTemp);
61 		if ( aURL.GetExtension().equalsIgnoreAsciiCaseAscii("orp") )
62 			return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StarBaseReport"));
63 		else
64 		{
65 			try
66 			{
67 				Reference<XPropertySet> xProp(::comphelper::OStorageHelper::GetStorageFromURL(sTemp,ElementModes::READ,Reference< XMultiServiceFactory >(m_xContext->getServiceManager(),UNO_QUERY)),UNO_QUERY);
68 				if ( xProp.is() )
69 				{
70 					::rtl::OUString sMediaType;
71 					xProp->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType")) ) >>= sMediaType;
72 					if ( sMediaType.equalsAscii(MIMETYPE_OASIS_OPENDOCUMENT_REPORT_ASCII) )
73 						return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StarBaseReport"));
74 					::comphelper::disposeComponent(xProp);
75 				} // if ( xProp.is() )
76 			}
77 			catch(Exception&)
78 			{
79 			}
80 		}
81 	}
82 	return ::rtl::OUString();
83 }
84 // -------------------------------------------------------------------------
85 Reference< XInterface > SAL_CALL
create(Reference<XComponentContext> const & xContext)86 		ORptTypeDetection::create(Reference< XComponentContext > const & xContext)
87 {
88 	return *(new ORptTypeDetection(xContext));
89 }
90 // -------------------------------------------------------------------------
91 // XServiceInfo
getImplementationName()92 ::rtl::OUString SAL_CALL ORptTypeDetection::getImplementationName() throw(  )
93 {
94 	return getImplementationName_Static();
95 }
96 // -------------------------------------------------------------------------
97 
98 // XServiceInfo
supportsService(const::rtl::OUString & ServiceName)99 sal_Bool SAL_CALL ORptTypeDetection::supportsService(const ::rtl::OUString& ServiceName) throw(  )
100 {
101     return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_Static());
102 }
103 // -------------------------------------------------------------------------
104 // XServiceInfo
getSupportedServiceNames(void)105 Sequence< ::rtl::OUString > SAL_CALL ORptTypeDetection::getSupportedServiceNames(void) throw(  )
106 {
107 	return getSupportedServiceNames_Static();
108 }
109 // -------------------------------------------------------------------------
110 // ORegistryServiceManager_Static
getSupportedServiceNames_Static(void)111 Sequence< ::rtl::OUString > ORptTypeDetection::getSupportedServiceNames_Static(void) throw( RuntimeException )
112 {
113 	Sequence< ::rtl::OUString > aSNS( 1 );
114 	aSNS.getArray()[0] = ::rtl::OUString::createFromAscii("com.sun.star.document.ExtendedTypeDetection");
115 	return aSNS;
116 }
117 // -----------------------------------------------------------------------------
118 // -----------------------------------------------------------------------------
119 }//rptxml
120 // -----------------------------------------------------------------------------
121 
122