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 "xmlCell.hxx"
25 #include "xmlHelper.hxx"
26 #include <xmloff/xmluconv.hxx>
27 #include "xmlfilter.hxx"
28 #include <xmloff/xmltoken.hxx>
29 #include <xmloff/xmlnmspe.hxx>
30 #include <xmloff/nmspmap.hxx>
31 #include "xmlEnums.hxx"
32 #include <tools/debug.hxx>
33 #include "xmlStyleImport.hxx"
34 #include <comphelper/namecontainer.hxx>
35 #include <comphelper/genericpropertyset.hxx>
36 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HXX_
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #endif
39 #include <com/sun/star/report/XShape.hpp>
40 #include <com/sun/star/report/XFixedLine.hpp>
41 #include <com/sun/star/table/BorderLine.hpp>
42 #ifndef RPT_SHARED_XMLSTRINGS_HRC
43 #include "xmlstrings.hrc"
44 #endif
45 #include "xmlTable.hxx"
46 #include "xmlFormattedField.hxx"
47 #include "xmlImage.hxx"
48 #include "xmlFixedContent.hxx"
49 #include "xmlSubDocument.hxx"
50
51 namespace rptxml
52 {
53 using namespace ::comphelper;
54 using namespace ::com::sun::star;
55 using namespace uno;
56 using namespace beans;
57 using namespace xml::sax;
58
DBG_NAME(rpt_OXMLCell)59 DBG_NAME( rpt_OXMLCell )
60
61 OXMLCell::OXMLCell( ORptFilter& rImport
62 ,sal_uInt16 nPrfx
63 ,const ::rtl::OUString& _sLocalName
64 ,const Reference< XAttributeList > & _xAttrList
65 ,OXMLTable* _pContainer
66 ,OXMLCell* _pCell) :
67 SvXMLImportContext( rImport, nPrfx, _sLocalName )
68 ,m_pContainer(_pContainer)
69 ,m_pCell(_pCell)
70 ,m_nCurrentCount(0)
71 ,m_bContainsShape(false)
72 {
73 DBG_CTOR( rpt_OXMLCell,NULL);
74 if ( !m_pCell )
75 m_pCell = this;
76
77 OSL_ENSURE(_xAttrList.is(),"Attribute list is NULL!");
78 const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
79 const SvXMLTokenMap& rTokenMap = rImport.GetColumnTokenMap();
80
81 const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
82 for(sal_Int16 i = 0; i < nLength; ++i)
83 {
84 ::rtl::OUString sLocalName;
85 const rtl::OUString sAttrName = _xAttrList->getNameByIndex( i );
86 const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
87 const rtl::OUString sValue = _xAttrList->getValueByIndex( i );
88
89 switch( rTokenMap.Get( nPrefix, sLocalName ) )
90 {
91 case XML_TOK_COLUMN_STYLE_NAME:
92 m_sStyleName = sValue;
93 break;
94 case XML_TOK_NUMBER_COLUMNS_SPANNED:
95 m_pContainer->setColumnSpanned(sValue.toInt32());
96 break;
97 case XML_TOK_NUMBER_ROWS_SPANNED:
98 m_pContainer->setRowSpanned(sValue.toInt32());
99 break;
100 default:
101 break;
102 }
103 }
104 }
105 // -----------------------------------------------------------------------------
~OXMLCell()106 OXMLCell::~OXMLCell()
107 {
108 DBG_DTOR( rpt_OXMLCell,NULL);
109 }
110 // -----------------------------------------------------------------------------
CreateChildContext(sal_uInt16 _nPrefix,const::rtl::OUString & _rLocalName,const Reference<XAttributeList> & xAttrList)111 SvXMLImportContext* OXMLCell::CreateChildContext(
112 sal_uInt16 _nPrefix,
113 const ::rtl::OUString& _rLocalName,
114 const Reference< XAttributeList > & xAttrList )
115 {
116 SvXMLImportContext *pContext = 0;
117 ORptFilter& rImport = GetOwnImport();
118 const SvXMLTokenMap& rTokenMap = rImport.GetCellElemTokenMap();
119 Reference<XMultiServiceFactory> xFactor(rImport.GetModel(),uno::UNO_QUERY);
120 static const ::rtl::OUString s_sStringConcat(RTL_CONSTASCII_USTRINGPARAM(" & "));
121
122 const sal_uInt16 nToken = rTokenMap.Get( _nPrefix, _rLocalName );
123 switch( nToken )
124 {
125 case XML_TOK_FIXED_CONTENT:
126 {
127 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
128 pContext = new OXMLFixedContent( rImport, _nPrefix, _rLocalName,*m_pCell,m_pContainer);
129 }
130 break;
131 case XML_TOK_PAGE_NUMBER:
132 m_sText += s_sStringConcat + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" PageNumber()"));
133 break;
134 case XML_TOK_PAGE_COUNT:
135 m_sText += s_sStringConcat + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" PageCount()"));
136 break;
137 case XML_TOK_FORMATTED_TEXT:
138 {
139 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
140 uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD);
141 Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY);
142
143 OSL_ENSURE(xControl.is(),"Could not create FormattedField!");
144 setComponent(xControl.get());
145 if ( xControl.is() )
146 pContext = new OXMLFormattedField( rImport, _nPrefix, _rLocalName,xAttrList,xControl.get(),m_pContainer,XML_TOK_PAGE_COUNT == nToken);
147 }
148 break;
149 case XML_TOK_IMAGE:
150 {
151 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
152 Reference< XImageControl > xControl(xFactor->createInstance(SERVICE_IMAGECONTROL),uno::UNO_QUERY);
153
154 OSL_ENSURE(xControl.is(),"Could not create ImageControl!");
155 setComponent(xControl.get());
156 if ( xControl.is() )
157 pContext = new OXMLImage( rImport, _nPrefix, _rLocalName,xAttrList,xControl.get(),m_pContainer);
158 }
159 break;
160 case XML_TOK_SUB_DOCUMENT:
161 {
162 rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
163 if ( !m_bContainsShape )
164 m_nCurrentCount = m_pContainer->getSection()->getCount();
165 uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD);
166 Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY);
167 pContext = new OXMLSubDocument( rImport, _nPrefix, _rLocalName,xControl.get(),m_pContainer, this /* give the current cell as parent*/ );
168 }
169 break;
170
171 case XML_TOK_P:
172 pContext = new OXMLCell( rImport, _nPrefix, _rLocalName,xAttrList ,m_pContainer,this);
173 break;
174 case XML_TOK_CUSTOM_SHAPE:
175 case XML_TOK_FRAME:
176 {
177 if ( !m_bContainsShape )
178 m_nCurrentCount = m_pContainer->getSection()->getCount();
179 UniReference< XMLShapeImportHelper > xShapeImportHelper = rImport.GetShapeImport();
180 uno::Reference< drawing::XShapes > xShapes = m_pContainer->getSection().get();
181 pContext = xShapeImportHelper->CreateGroupChildContext(rImport,_nPrefix,_rLocalName,xAttrList,xShapes);
182 m_bContainsShape = true;
183 }
184 break;
185 default:
186 break;
187 }
188
189 if ( m_xComponent.is() )
190 m_pContainer->addCell(m_xComponent);
191
192 if( !pContext )
193 pContext = new SvXMLImportContext( GetImport(), _nPrefix, _rLocalName );
194
195 return pContext;
196 }
197 // -----------------------------------------------------------------------------
EndElement()198 void OXMLCell::EndElement()
199 {
200 if ( m_bContainsShape )
201 {
202 const sal_Int32 nCount = m_pContainer->getSection()->getCount();
203 for (sal_Int32 i = m_nCurrentCount; i < nCount; ++i)
204 {
205 uno::Reference<report::XShape> xShape(m_pContainer->getSection()->getByIndex(i),uno::UNO_QUERY);
206 if ( xShape.is() )
207 m_pContainer->addCell(xShape.get());
208 }
209 }
210 if ( m_pCell != this && m_sText.getLength() )
211 {
212 ORptFilter& rImport = GetOwnImport();
213 Reference<XMultiServiceFactory> xFactor(rImport.GetModel(),uno::UNO_QUERY);
214 uno::Reference< uno::XInterface> xInt = xFactor->createInstance(SERVICE_FORMATTEDFIELD);
215 Reference< report::XFormattedField > xControl(xInt,uno::UNO_QUERY);
216 xControl->setDataField(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("rpt:")) + m_sText);
217
218 OSL_ENSURE(xControl.is(),"Could not create FormattedField!");
219 setComponent(xControl.get());
220 m_xComponent = xControl.get();
221 m_pContainer->getSection()->add(m_xComponent.get());
222 m_pContainer->addCell(m_xComponent);
223 }
224 // check if we have a FixedLine
225 else if ( m_sStyleName.getLength() && !m_xComponent.is() && m_pCell == this )
226 {
227 ORptFilter& rImport = GetOwnImport();
228 Reference<XMultiServiceFactory> xFactor(rImport.GetModel(),uno::UNO_QUERY);
229 Reference<XFixedLine> xFixedLine(xFactor->createInstance(SERVICE_FIXEDLINE),uno::UNO_QUERY);
230 m_xComponent = xFixedLine.get();
231 m_pContainer->getSection()->add(m_xComponent.get());
232 m_pContainer->addCell(m_xComponent);
233 XMLPropStyleContext* pAutoStyle = PTR_CAST(XMLPropStyleContext,GetImport().GetAutoStyles()->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_CELL,m_sStyleName));
234 if ( pAutoStyle )
235 {
236 uno::Reference<beans::XPropertySet> xBorderProp = OXMLHelper::createBorderPropertySet();
237 try
238 {
239 pAutoStyle->FillPropertySet(xBorderProp);
240 table::BorderLine aRight,aLeft;
241 xBorderProp->getPropertyValue(PROPERTY_BORDERRIGHT) >>= aRight;
242 xBorderProp->getPropertyValue(PROPERTY_BORDERLEFT) >>= aLeft;
243 xFixedLine->setOrientation( (aRight.OuterLineWidth != 0 || aLeft.OuterLineWidth != 0) ? 1 : 0);
244 }
245 catch(uno::Exception&)
246 {
247 OSL_ENSURE(0,"OXMLCell::EndElement -> exception catched");
248 }
249 }
250 }
251 else
252 OXMLHelper::copyStyleElements(GetOwnImport().isOldFormat(),m_sStyleName,GetImport().GetAutoStyles(),m_xComponent.get());
253 }
254 // -----------------------------------------------------------------------------
GetOwnImport()255 ORptFilter& OXMLCell::GetOwnImport()
256 {
257 return static_cast<ORptFilter&>(GetImport());
258 }
259 // -----------------------------------------------------------------------------
setComponent(const uno::Reference<report::XReportComponent> & _xComponent)260 void OXMLCell::setComponent(const uno::Reference< report::XReportComponent >& _xComponent)
261 {
262 m_pCell->m_xComponent = _xComponent;
263 m_xComponent = _xComponent;
264 }
265 // -----------------------------------------------------------------------------
Characters(const::rtl::OUString & rChars)266 void OXMLCell::Characters( const ::rtl::OUString& rChars )
267 {
268 if ( rChars.getLength() )
269 {
270 static const ::rtl::OUString s_Quote(RTL_CONSTASCII_USTRINGPARAM("\""));
271 if ( m_sText.getLength() )
272 {
273 static const ::rtl::OUString s_sStringConcat(RTL_CONSTASCII_USTRINGPARAM(" & "));
274 m_sText += s_sStringConcat;
275 }
276
277 m_sText += s_Quote + rChars + s_Quote;
278 }
279 }
280
setContainsShape(bool _bContainsShape)281 void OXMLCell::setContainsShape(bool _bContainsShape)
282 {
283 m_bContainsShape = _bContainsShape;
284 }
285
286 //----------------------------------------------------------------------------
287 } // namespace rptxml
288 // -----------------------------------------------------------------------------
289
290