1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include "xmlColumn.hxx"
21 #include <xmloff/xmluconv.hxx>
22 #include "xmlfilter.hxx"
23 #include <xmloff/xmltoken.hxx>
24 #include <xmloff/xmlnmspe.hxx>
25 #include <xmloff/nmspmap.hxx>
26 #include "xmlEnums.hxx"
27 #include "xmlStyleImport.hxx"
28 #include <comphelper/genericpropertyset.hxx>
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 #include "strings.hxx"
31 
32 namespace rptxml
33 {
34     using namespace ::comphelper;
35     using namespace ::com::sun::star::uno;
36     using namespace ::com::sun::star::beans;
37     using namespace ::com::sun::star::xml::sax;
38 
39 
OXMLRow(ORptFilter & rImport,sal_uInt16 nPrfx,const OUString & _sLocalName,const Reference<XAttributeList> & _xAttrList,OXMLTable * _pContainer)40 OXMLRow::OXMLRow( ORptFilter& rImport
41                 ,sal_uInt16 nPrfx
42                 ,const OUString& _sLocalName
43                 ,const Reference< XAttributeList > & _xAttrList
44                 ,OXMLTable* _pContainer) :
45     SvXMLImportContext( rImport, nPrfx, _sLocalName )
46     ,m_pContainer(_pContainer)
47 {
48 
49     OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
50 
51     const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
52     const SvXMLTokenMap& rTokenMap = rImport.GetColumnTokenMap();
53 
54     const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
55     for(sal_Int16 i = 0; i < nLength; ++i)
56     {
57      OUString sLocalName;
58         const OUString sAttrName = _xAttrList->getNameByIndex( i );
59         const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
60         const OUString sValue = _xAttrList->getValueByIndex( i );
61 
62         switch( rTokenMap.Get( nPrefix, sLocalName ) )
63         {
64             case XML_TOK_COLUMN_STYLE_NAME:
65                 m_sStyleName = sValue;
66                 break;
67             case XML_TOK_NUMBER_ROWS_SPANNED:
68                 m_pContainer->setRowSpanned(sValue.toInt32());
69                 break;
70             default:
71                 break;
72         }
73     }
74 
75 }
76 
77 
~OXMLRow()78 OXMLRow::~OXMLRow()
79 {
80 }
81 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)82 SvXMLImportContext* OXMLRow::CreateChildContext(
83         sal_uInt16 nPrefix,
84         const OUString& rLocalName,
85         const Reference< XAttributeList > & xAttrList )
86 {
87     SvXMLImportContext *pContext = 0;
88     ORptFilter& rImport = GetOwnImport();
89     const SvXMLTokenMap&    rTokenMap   = rImport.GetControlPropertyElemTokenMap();
90 
91     switch( rTokenMap.Get( nPrefix, rLocalName ) )
92     {
93         case XML_TOK_COLUMN:
94             rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
95             pContext = new OXMLRow( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
96             break;
97         case XML_TOK_ROW:
98             rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
99             pContext = new OXMLRow( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
100             break;
101         case XML_TOK_CELL:
102             rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
103             pContext = new OXMLRow( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
104             break;
105         case XML_TOK_COV_CELL:
106             rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
107             pContext = new OXMLRow( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
108             break;
109         default:
110             break;
111     }
112 
113     if( !pContext )
114         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
115 
116     return pContext;
117 }
118 
EndElement()119 void OXMLRow::EndElement()
120 {
121     if ( m_sStyleName.getLength() )
122     {
123         const SvXMLStylesContext* pAutoStyles = GetImport().GetAutoStyles();
124         if ( pAutoStyles )
125         {
126             PropertySetInfo* pInfo = new PropertySetInfo();
127             static PropertyMapEntry pMap[] =
128             {
129                 {PROPERTY_WIDTH,        static_cast<sal_uInt16>(PROPERTY_WIDTH.length),     0,          &::cppu::UnoType<sal_Int32>::get()       ,PropertyAttribute::BOUND,0},
130                 {PROPERTY_HEIGHT,       static_cast<sal_uInt16>(PROPERTY_HEIGHT.length),    0,          &::cppu::UnoType<sal_Int32>::get()       ,PropertyAttribute::BOUND,0},
131                 { NULL, 0, 0, NULL, 0, 0 }
132             };
133             pInfo->add(pMap);
134             Reference<XPropertySet> xProp = GenericPropertySet_CreateInstance(pInfo);
135             XMLPropStyleContext* pAutoStyle = dynamic_cast< const XMLPropStyleContext *>(pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_COLUMN,m_sStyleName));
136             if ( pAutoStyle )
137             {
138                 pAutoStyle->FillPropertySet(xProp);
139                 sal_Int32 nWidth = 0;
140                 xProp->getPropertyValue(PROPERTY_WIDTH) >>= nWidth;
141                 m_pContainer->addWidth(nWidth);
142             }
143             else
144             {
145                 pAutoStyle = dynamic_cast< const XMLPropStyleContext *>(pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_ROW,m_sStyleName));
146                 if ( pAutoStyle )
147                 {
148                     pAutoStyle->FillPropertySet(xProp);
149                     sal_Int32 nHeight = 0;
150                     xProp->getPropertyValue(PROPERTY_HEIGHT) >>= nHeight;
151                     m_pContainer->addHeight(nHeight);
152                 }
153             }
154         }
155     }
156 }
157 
GetOwnImport()158 ORptFilter& OXMLRow::GetOwnImport()
159 {
160     return static_cast<ORptFilter&>(GetImport());
161 }
162 
163 } // namespace rptxml
164 
165 
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
167