xref: /AOO41X/main/reportdesign/source/core/api/Tools.cxx (revision 9e0e41911c53968aad5ad356e2b2126da667034f)
1*9e0e4191SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9e0e4191SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9e0e4191SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9e0e4191SAndrew Rist  * distributed with this work for additional information
6*9e0e4191SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9e0e4191SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9e0e4191SAndrew Rist  * "License"); you may not use this file except in compliance
9*9e0e4191SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9e0e4191SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9e0e4191SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9e0e4191SAndrew Rist  * software distributed under the License is distributed on an
15*9e0e4191SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9e0e4191SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9e0e4191SAndrew Rist  * specific language governing permissions and limitations
18*9e0e4191SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9e0e4191SAndrew Rist  *************************************************************/
21*9e0e4191SAndrew Rist 
22*9e0e4191SAndrew Rist 
23cdf0e10cSrcweir #include "Tools.hxx"
24cdf0e10cSrcweir #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
25cdf0e10cSrcweir #include "core_resource.hrc"
26cdf0e10cSrcweir #endif
27cdf0e10cSrcweir #include "core_resource.hxx"
28cdf0e10cSrcweir #include <comphelper/property.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir // =============================================================================
31cdf0e10cSrcweir namespace reportdesign
32cdf0e10cSrcweir {
33cdf0e10cSrcweir // =============================================================================
34cdf0e10cSrcweir using namespace com::sun::star;
35cdf0e10cSrcweir 
lcl_getSection(const uno::Reference<uno::XInterface> & _xReportComponent)36cdf0e10cSrcweir uno::Reference< report::XSection> lcl_getSection(const uno::Reference< uno::XInterface>& _xReportComponent)
37cdf0e10cSrcweir {
38cdf0e10cSrcweir     uno::Reference< container::XChild> xChild(_xReportComponent,uno::UNO_QUERY);
39cdf0e10cSrcweir     uno::Reference< report::XSection> xRet(_xReportComponent,uno::UNO_QUERY);
40cdf0e10cSrcweir     while( !xRet.is() && xChild.is() )
41cdf0e10cSrcweir     {
42cdf0e10cSrcweir         uno::Reference< uno::XInterface> xTemp = xChild->getParent();
43cdf0e10cSrcweir         xChild.set(xTemp,uno::UNO_QUERY);
44cdf0e10cSrcweir         xRet.set(xTemp,uno::UNO_QUERY);
45cdf0e10cSrcweir     }
46cdf0e10cSrcweir     return xRet;
47cdf0e10cSrcweir }
48cdf0e10cSrcweir // -----------------------------------------------------------------------------
throwIllegallArgumentException(const::rtl::OUString & _sTypeName,const uno::Reference<uno::XInterface> & ExceptionContext_,const::sal_Int16 & ArgumentPosition_,const::com::sun::star::uno::Reference<::com::sun::star::uno::XComponentContext> & Context_)49cdf0e10cSrcweir void throwIllegallArgumentException( const ::rtl::OUString& _sTypeName
50cdf0e10cSrcweir                                     ,const uno::Reference< uno::XInterface >& ExceptionContext_
51cdf0e10cSrcweir                                     ,const ::sal_Int16& ArgumentPosition_
52cdf0e10cSrcweir                                     ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& Context_
53cdf0e10cSrcweir                                     )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     ::rtl::OUString sErrorMessage(RPT_RESSTRING(RID_STR_ERROR_WRONG_ARGUMENT,Context_->getServiceManager()));
56cdf0e10cSrcweir     sErrorMessage = sErrorMessage.replaceAt(sErrorMessage.indexOf('#'),2,_sTypeName);
57cdf0e10cSrcweir 	throw lang::IllegalArgumentException(sErrorMessage,ExceptionContext_,ArgumentPosition_);
58cdf0e10cSrcweir }
59cdf0e10cSrcweir // -----------------------------------------------------------------------------
cloneObject(const uno::Reference<report::XReportComponent> & _xReportComponent,const uno::Reference<lang::XMultiServiceFactory> & _xFactory,const::rtl::OUString & _sServiceName)60cdf0e10cSrcweir uno::Reference< util::XCloneable > cloneObject(const uno::Reference< report::XReportComponent>& _xReportComponent
61cdf0e10cSrcweir     ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
62cdf0e10cSrcweir     ,const ::rtl::OUString& _sServiceName)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     OSL_ENSURE(_xReportComponent.is() && _xFactory.is() ,"reportcomponent is null -> GPF");
65cdf0e10cSrcweir     uno::Reference< report::XReportComponent> xClone(_xFactory->createInstance(_sServiceName),uno::UNO_QUERY_THROW);
66cdf0e10cSrcweir     ::comphelper::copyProperties(_xReportComponent.get(),xClone.get());
67cdf0e10cSrcweir     return xClone.get();
68cdf0e10cSrcweir }
69cdf0e10cSrcweir // -----------------------------------------------------------------------------
70cdf0e10cSrcweir 
71cdf0e10cSrcweir // =============================================================================
72cdf0e10cSrcweir } // namespace reportdesign
73cdf0e10cSrcweir // =============================================================================
74