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 "xmlSubDocument.hxx"
25 #include "xmlCell.hxx"
26 #include "xmlfilter.hxx"
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmlnmspe.hxx>
29 #include <xmloff/nmspmap.hxx>
30 #include "xmlEnums.hxx"
31 #include "xmlMasterFields.hxx"
32 #include "xmlTable.hxx"
33 #include <tools/debug.hxx>
34 #include <comphelper/property.hxx>
35 #include <com/sun/star/report/XReportControlModel.hpp>
36 
37 namespace rptxml
38 {
39 	using namespace ::com::sun::star;
40 	using namespace ::com::sun::star::report;
41 	using namespace ::com::sun::star::uno;
42 	using namespace ::com::sun::star::xml::sax;
DBG_NAME(rpt_OXMLSubDocument)43 DBG_NAME( rpt_OXMLSubDocument )
44 
45 OXMLSubDocument::OXMLSubDocument( ORptFilter& rImport,
46 				sal_uInt16 nPrfx
47                 ,const ::rtl::OUString& rLName
48 				,const Reference< XReportComponent > & _xComponent
49                 ,OXMLTable* _pContainer
50                 ,OXMLCell* _pCellParent) :
51 	OXMLReportElementBase( rImport, nPrfx, rLName,_xComponent.get(),_pContainer)
52 ,m_xFake(_xComponent)
53 ,m_pCellParent(_pCellParent)
54 ,m_nCurrentCount(0)
55 ,m_bContainsShape(false)
56 {
57     DBG_CTOR( rpt_OXMLSubDocument,NULL);
58 
59 }
60 // -----------------------------------------------------------------------------
61 
~OXMLSubDocument()62 OXMLSubDocument::~OXMLSubDocument()
63 {
64     DBG_DTOR( rpt_OXMLSubDocument,NULL);
65 }
66 
67 // -----------------------------------------------------------------------------
_CreateChildContext(sal_uInt16 _nPrefix,const::rtl::OUString & _rLocalName,const Reference<XAttributeList> & xAttrList)68 SvXMLImportContext* OXMLSubDocument::_CreateChildContext(
69 		sal_uInt16 _nPrefix,
70 		const ::rtl::OUString& _rLocalName,
71 		const Reference< XAttributeList > & xAttrList )
72 {
73 	SvXMLImportContext *pContext = OXMLReportElementBase::_CreateChildContext(_nPrefix,_rLocalName,xAttrList);
74     if ( pContext )
75         return pContext;
76 	const SvXMLTokenMap&	rTokenMap	= static_cast<ORptFilter&>(GetImport()).GetReportElemTokenMap();
77 
78 	switch( rTokenMap.Get( _nPrefix, _rLocalName ) )
79 	{
80 		case XML_TOK_MASTER_DETAIL_FIELDS:
81 			{
82 				GetImport().GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
83                 pContext = new OXMLMasterFields(static_cast<ORptFilter&>(GetImport()), _nPrefix, _rLocalName,xAttrList ,this);
84             }
85             break;
86         case XML_TOK_SUB_FRAME:
87             {
88                 if ( !m_bContainsShape )
89                     m_nCurrentCount = m_pContainer->getSection()->getCount();
90                 UniReference< XMLShapeImportHelper > xShapeImportHelper = GetImport().GetShapeImport();
91                 uno::Reference< drawing::XShapes > xShapes = m_pContainer->getSection().get();
92                 pContext = xShapeImportHelper->CreateGroupChildContext(GetImport(),_nPrefix,_rLocalName,xAttrList,xShapes);
93                 m_bContainsShape = true;
94 				if (m_pCellParent)
95 				{
96 					// #i94115 say to the parent Cell it contains shapes
97 					m_pCellParent->setContainsShape(true);
98 				}
99             }
100             break;
101         default:
102             break;
103 	}
104 
105 	if( !pContext )
106 		pContext = new SvXMLImportContext( GetImport(), _nPrefix, _rLocalName );
107 
108 	return pContext;
109 }
110 // -----------------------------------------------------------------------------
EndElement()111 void OXMLSubDocument::EndElement()
112 {
113     if ( m_bContainsShape )
114     {
115         m_xComponent.set(m_pContainer->getSection()->getByIndex(m_nCurrentCount),uno::UNO_QUERY);
116         if ( m_xComponent.is() )
117         {
118             // #i94115# this is no longer need.
119             // m_pContainer->addCell(m_xComponent.get());
120 
121             if ( !m_aMasterFields.empty() )
122                 m_xComponent->setMasterFields(Sequence< ::rtl::OUString>(&*m_aMasterFields.begin(),m_aMasterFields.size()));
123             if ( !m_aDetailFields.empty() )
124                 m_xComponent->setDetailFields(Sequence< ::rtl::OUString>(&*m_aDetailFields.begin(),m_aDetailFields.size()));
125 
126             m_xComponent->setName(m_xFake->getName());
127             m_xComponent->setPrintRepeatedValues(m_xFake->getPrintRepeatedValues());
128             uno::Reference< report::XReportControlModel >	xFakeModel(m_xFake,uno::UNO_QUERY);
129             uno::Reference< report::XReportControlModel >	xComponentModel(m_xComponent,uno::UNO_QUERY);
130             if ( xComponentModel.is() && xFakeModel.is() )
131             {
132                 const sal_Int32 nCount = xFakeModel->getCount();
133 	            try
134 	            {
135 		            for (sal_Int32 i = 0; i < nCount ; ++i)
136 		            {
137 			            uno::Reference< report::XFormatCondition > xCond(xFakeModel->getByIndex(i),uno::UNO_QUERY);
138                         uno::Reference< report::XFormatCondition > xNewCond = xComponentModel->createFormatCondition();
139                         ::comphelper::copyProperties(xCond.get(),xNewCond.get());
140                         xComponentModel->insertByIndex(xComponentModel->getCount(),uno::makeAny(xNewCond));
141 		            } // for (sal_Int32 i = 0; i < nCount ; ++i)
142 	            }
143 	            catch(uno::Exception&)
144 	            {
145 		            OSL_ENSURE(0,"Can not access format condition!");
146 	            }
147 
148             }
149         }
150     }
151 }
152 // -----------------------------------------------------------------------------
addMasterDetailPair(const::std::pair<::rtl::OUString,::rtl::OUString> & _aPair)153 void OXMLSubDocument::addMasterDetailPair(const ::std::pair< ::rtl::OUString,::rtl::OUString >& _aPair)
154 {
155     m_aMasterFields.push_back(_aPair.first);
156     m_aDetailFields.push_back(_aPair.second);
157 }
158 //----------------------------------------------------------------------------
159 } // namespace rptxml
160 // -----------------------------------------------------------------------------
161