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