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
109e0e4191SAndrew Rist  *
119e0e4191SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129e0e4191SAndrew Rist  *
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.
199e0e4191SAndrew Rist  *
209e0e4191SAndrew Rist  *************************************************************/
219e0e4191SAndrew Rist 
229e0e4191SAndrew Rist 
23*b63233d8Sdamjan #include "precompiled_rptxml.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #ifndef RPT_XMLCOLUMN_HXX
26cdf0e10cSrcweir #include "xmlColumn.hxx"
27cdf0e10cSrcweir #endif
28cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
29cdf0e10cSrcweir #include "xmlfilter.hxx"
30cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
31cdf0e10cSrcweir #include <xmloff/xmlnmspe.hxx>
32cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
33cdf0e10cSrcweir #include "xmlEnums.hxx"
34cdf0e10cSrcweir #include <tools/debug.hxx>
35cdf0e10cSrcweir #include "xmlStyleImport.hxx"
36cdf0e10cSrcweir #include <comphelper/namecontainer.hxx>
37cdf0e10cSrcweir #include <comphelper/genericpropertyset.hxx>
38cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HXX_
39cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #ifndef RPT_SHARED_XMLSTRINGS_HRC
42cdf0e10cSrcweir #include "xmlstrings.hrc"
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir 
45cdf0e10cSrcweir namespace rptxml
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     using namespace ::comphelper;
48cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
49cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
50cdf0e10cSrcweir 	using namespace ::com::sun::star::xml::sax;
51cdf0e10cSrcweir 
DBG_NAME(rpt_OXMLRow)52cdf0e10cSrcweir DBG_NAME( rpt_OXMLRow )
53cdf0e10cSrcweir 
54cdf0e10cSrcweir OXMLRow::OXMLRow( ORptFilter& rImport
55cdf0e10cSrcweir 				,sal_uInt16 nPrfx
56cdf0e10cSrcweir 				,const ::rtl::OUString& _sLocalName
57cdf0e10cSrcweir 				,const Reference< XAttributeList > & _xAttrList
58cdf0e10cSrcweir 				,OXMLTable* _pContainer) :
59cdf0e10cSrcweir 	SvXMLImportContext( rImport, nPrfx, _sLocalName )
60cdf0e10cSrcweir 	,m_pContainer(_pContainer)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     DBG_CTOR( rpt_OXMLRow,NULL);
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
67cdf0e10cSrcweir 	const SvXMLTokenMap& rTokenMap = rImport.GetColumnTokenMap();
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
70cdf0e10cSrcweir 	for(sal_Int16 i = 0; i < nLength; ++i)
71cdf0e10cSrcweir 	{
72cdf0e10cSrcweir 	 ::rtl::OUString sLocalName;
73cdf0e10cSrcweir 		const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
74cdf0e10cSrcweir 		const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
75cdf0e10cSrcweir 		const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 		switch( rTokenMap.Get( nPrefix, sLocalName ) )
78cdf0e10cSrcweir 		{
79cdf0e10cSrcweir 			case XML_TOK_COLUMN_STYLE_NAME:
80cdf0e10cSrcweir 				m_sStyleName = sValue;
81cdf0e10cSrcweir 				break;
82cdf0e10cSrcweir             case XML_TOK_NUMBER_ROWS_SPANNED:
83cdf0e10cSrcweir 				m_pContainer->setRowSpanned(sValue.toInt32());
84cdf0e10cSrcweir 				break;
85cdf0e10cSrcweir             default:
86cdf0e10cSrcweir                 break;
87cdf0e10cSrcweir 		}
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 
90cdf0e10cSrcweir }
91cdf0e10cSrcweir // -----------------------------------------------------------------------------
92cdf0e10cSrcweir 
~OXMLRow()93cdf0e10cSrcweir OXMLRow::~OXMLRow()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     DBG_DTOR( rpt_OXMLRow,NULL);
96cdf0e10cSrcweir }
97cdf0e10cSrcweir // -----------------------------------------------------------------------------
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const Reference<XAttributeList> & xAttrList)98cdf0e10cSrcweir SvXMLImportContext* OXMLRow::CreateChildContext(
99cdf0e10cSrcweir 		sal_uInt16 nPrefix,
100cdf0e10cSrcweir 		const ::rtl::OUString& rLocalName,
101cdf0e10cSrcweir 		const Reference< XAttributeList > & xAttrList )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	SvXMLImportContext *pContext = 0;
104cdf0e10cSrcweir     ORptFilter& rImport = GetOwnImport();
105cdf0e10cSrcweir 	const SvXMLTokenMap&	rTokenMap	= rImport.GetControlPropertyElemTokenMap();
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	switch( rTokenMap.Get( nPrefix, rLocalName ) )
108cdf0e10cSrcweir 	{
109cdf0e10cSrcweir 		case XML_TOK_COLUMN:
110cdf0e10cSrcweir             rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
111cdf0e10cSrcweir 			pContext = new OXMLRow( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
112cdf0e10cSrcweir 			break;
113cdf0e10cSrcweir         case XML_TOK_ROW:
114cdf0e10cSrcweir             rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
115cdf0e10cSrcweir 			pContext = new OXMLRow( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
116cdf0e10cSrcweir 			break;
117cdf0e10cSrcweir         case XML_TOK_CELL:
118cdf0e10cSrcweir             rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
119cdf0e10cSrcweir 			pContext = new OXMLRow( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
120cdf0e10cSrcweir 			break;
121cdf0e10cSrcweir         case XML_TOK_COV_CELL:
122cdf0e10cSrcweir             rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
123cdf0e10cSrcweir 			pContext = new OXMLRow( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
124cdf0e10cSrcweir 			break;
125cdf0e10cSrcweir         default:
126cdf0e10cSrcweir             break;
127cdf0e10cSrcweir 	}
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	if( !pContext )
130cdf0e10cSrcweir 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	return pContext;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir // -----------------------------------------------------------------------------
EndElement()135cdf0e10cSrcweir void OXMLRow::EndElement()
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	if ( m_sStyleName.getLength() )
138cdf0e10cSrcweir 	{
139cdf0e10cSrcweir         const SvXMLStylesContext* pAutoStyles = GetImport().GetAutoStyles();
140cdf0e10cSrcweir 		if ( pAutoStyles )
141cdf0e10cSrcweir 		{
142cdf0e10cSrcweir             PropertySetInfo* pInfo = new PropertySetInfo();
143cdf0e10cSrcweir 			static PropertyMapEntry pMap[] =
144cdf0e10cSrcweir 			{
145cdf0e10cSrcweir 				{PROPERTY_WIDTH,		static_cast<sal_uInt16>(PROPERTY_WIDTH.length),		0,			&::getCppuType(static_cast< sal_Int32* >( NULL ))		,PropertyAttribute::BOUND,0},
146cdf0e10cSrcweir 				{PROPERTY_HEIGHT,		static_cast<sal_uInt16>(PROPERTY_HEIGHT.length),	0,			&::getCppuType(static_cast< sal_Int32* >( NULL ))		,PropertyAttribute::BOUND,0},
147cdf0e10cSrcweir 				{ NULL, 0, 0, NULL, 0, 0 }
148cdf0e10cSrcweir 			};
149cdf0e10cSrcweir 			pInfo->add(pMap);
150cdf0e10cSrcweir 			Reference<XPropertySet> xProp = GenericPropertySet_CreateInstance(pInfo);
151cdf0e10cSrcweir 			XMLPropStyleContext* pAutoStyle = PTR_CAST(XMLPropStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_COLUMN,m_sStyleName));
152cdf0e10cSrcweir 			if ( pAutoStyle )
153cdf0e10cSrcweir 			{
154cdf0e10cSrcweir 				pAutoStyle->FillPropertySet(xProp);
155cdf0e10cSrcweir                 sal_Int32 nWidth = 0;
156cdf0e10cSrcweir                 xProp->getPropertyValue(PROPERTY_WIDTH) >>= nWidth;
157cdf0e10cSrcweir                 m_pContainer->addWidth(nWidth);
158cdf0e10cSrcweir 			}
159cdf0e10cSrcweir             else
160cdf0e10cSrcweir             {
161cdf0e10cSrcweir                 pAutoStyle = PTR_CAST(XMLPropStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_ROW,m_sStyleName));
162cdf0e10cSrcweir 			    if ( pAutoStyle )
163cdf0e10cSrcweir 			    {
164cdf0e10cSrcweir                     pAutoStyle->FillPropertySet(xProp);
165cdf0e10cSrcweir                     sal_Int32 nHeight = 0;
166cdf0e10cSrcweir                     xProp->getPropertyValue(PROPERTY_HEIGHT) >>= nHeight;
167cdf0e10cSrcweir                     m_pContainer->addHeight(nHeight);
168cdf0e10cSrcweir 			    }
169cdf0e10cSrcweir             }
170cdf0e10cSrcweir 		}
171cdf0e10cSrcweir 	}
172cdf0e10cSrcweir }
173cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetOwnImport()174cdf0e10cSrcweir ORptFilter& OXMLRow::GetOwnImport()
175cdf0e10cSrcweir {
176cdf0e10cSrcweir 	return static_cast<ORptFilter&>(GetImport());
177cdf0e10cSrcweir }
178cdf0e10cSrcweir //----------------------------------------------------------------------------
179cdf0e10cSrcweir } // namespace rptxml
180cdf0e10cSrcweir // -----------------------------------------------------------------------------
181