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