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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 
27 #ifndef DBA_XMLSTYLEIMPORT_HXX
28 #include "xmlStyleImport.hxx"
29 #endif
30 
31 #ifndef _XMLOFF_NMSPMAP_HXX
32 #include <xmloff/nmspmap.hxx>
33 #endif
34 #ifndef _XMLOFF_XMLNMSPE_HXX
35 #include <xmloff/xmlnmspe.hxx>
36 #endif
37 #ifndef _XMLOFF_XMLIMPPR_HXX
38 #include <xmloff/xmlimppr.hxx>
39 #endif
40 #ifndef _XMLOFF_FAMILIES_HXX_
41 #include <xmloff/families.hxx>
42 #endif
43 #ifndef _XMLOFF_XMLNUMFI_HXX
44 #include <xmloff/xmlnumfi.hxx>
45 #endif
46 #ifndef _XMLOFF_XMLTOKEN_HXX
47 #include <xmloff/xmltoken.hxx>
48 #endif
49 #ifndef _COM_SUN_STAR_STYLE_XSTYLEFAMILIESSUPPLIER_HPP_
50 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
51 #endif
52 #ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_
53 #include <com/sun/star/container/XNameContainer.hpp>
54 #endif
55 #ifndef _COM_SUN_STAR_TABLE_BORDERLINE_HPP_
56 #include <com/sun/star/table/BorderLine.hpp>
57 #endif
58 #ifndef _COMPHELPER_EXTRACT_HXX_
59 #include <comphelper/extract.hxx>
60 #endif
61 #ifndef _XMLOFF_XMLPROPERTYSETCONTEXT_HXX
62 #include <xmloff/xmlprcon.hxx>
63 #endif
64 #ifndef _XMLOFF_XMLUCONV_HXX
65 #include <xmloff/xmluconv.hxx>
66 #endif
67 #ifndef _TOOLS_DEBUG_HXX
68 #include <tools/debug.hxx>
69 #endif
70 #ifndef DBA_XMLFILTER_HXX
71 #include "xmlfilter.hxx"
72 #endif
73 #ifndef DBA_XMLHELPER_HXX
74 #include "xmlHelper.hxx"
75 #endif
76 #ifndef _TOOLS_DEBUG_HXX
77 #include <tools/debug.hxx>
78 #endif
79 
80 
81 #define XML_LINE_LEFT 0
82 #define XML_LINE_RIGHT 1
83 #define XML_LINE_TOP 2
84 #define XML_LINE_BOTTOM 3
85 
86 namespace dbaxml
87 {
88 
89 using namespace ::com::sun::star;
90 using namespace ::com::sun::star::uno;
91 using namespace ::com::sun::star::xml::sax;
92 using namespace ::com::sun::star::style;
93 using namespace ::com::sun::star::frame;
94 using namespace ::com::sun::star::beans;
95 using namespace ::com::sun::star::container;
96 using namespace xmloff::token;
97 
98 // -----------------------------------------------------------------------------
99 TYPEINIT1( OTableStyleContext, XMLPropStyleContext );
100 TYPEINIT1( OTableStylesContext, SvXMLStylesContext );
DBG_NAME(OTableStyleContext)101 DBG_NAME(OTableStyleContext)
102 
103 OTableStyleContext::OTableStyleContext( ODBFilter& rImport,
104 		sal_uInt16 nPrfx, const ::rtl::OUString& rLName,
105 		const Reference< XAttributeList > & xAttrList,
106 		SvXMLStylesContext& rStyles, sal_uInt16 nFamily, sal_Bool bDefaultStyle )
107     :XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle )
108     ,sNumberFormat(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberFormat")))
109     ,pStyles(&rStyles)
110     ,m_nNumberFormat(-1)
111     ,bConditionalFormatCreated(sal_False)
112     ,bParentSet(sal_False)
113 {
114     DBG_CTOR(OTableStyleContext,NULL);
115 
116 }
117 // -----------------------------------------------------------------------------
118 
~OTableStyleContext()119 OTableStyleContext::~OTableStyleContext()
120 {
121 
122     DBG_DTOR(OTableStyleContext,NULL);
123 }
124 // -----------------------------------------------------------------------------
125 
FillPropertySet(const Reference<XPropertySet> & rPropSet)126 void OTableStyleContext::FillPropertySet(
127 			const Reference< XPropertySet > & rPropSet )
128 {
129 	if ( !IsDefaultStyle() )
130 	{
131 		if ( GetFamily() == XML_STYLE_FAMILY_TABLE_TABLE )
132 		{
133 			if ( sPageStyle.getLength() )
134 			{
135 				uno::Any aAny;
136 				aAny <<= sPageStyle;
137 				AddProperty(CTF_DB_MASTERPAGENAME, aAny);
138 			}
139 		}
140 		else if ( GetFamily() == XML_STYLE_FAMILY_TABLE_COLUMN )
141 		{
142 			if ((m_nNumberFormat == -1) && m_sDataStyleName.getLength())
143 			{
144 				SvXMLNumFormatContext* pStyle = PTR_CAST(SvXMLNumFormatContext,pStyles->FindStyleChildContext(
145 					XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, sal_True));
146 				if ( !pStyle )
147 				{
148 					OTableStylesContext* pMyStyles = PTR_CAST(OTableStylesContext,GetOwnImport().GetAutoStyles());
149 					if ( pMyStyles )
150 						pStyle = PTR_CAST(SvXMLNumFormatContext,pMyStyles->
151 							FindStyleChildContext(XML_STYLE_FAMILY_DATA_STYLE, m_sDataStyleName, sal_True));
152 					else {
153 						DBG_ERROR("not possible to get style");
154                     }
155 				}
156 				if ( pStyle )
157 				{
158 					uno::Any aNumberFormat;
159 					m_nNumberFormat = pStyle->GetKey();
160 					aNumberFormat <<= m_nNumberFormat;
161 					//rPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_NUMBERFORMAT)), aNumberFormat);
162 					AddProperty(CTF_DB_NUMBERFORMAT, aNumberFormat);
163 				}
164 			}
165 		}
166 	}
167 	XMLPropStyleContext::FillPropertySet(rPropSet);
168 }
169 // -----------------------------------------------------------------------------
170 
SetDefaults()171 void OTableStyleContext::SetDefaults()
172 {
173 }
174 // -----------------------------------------------------------------------------
175 
AddProperty(const sal_Int16 nContextID,const uno::Any & rValue)176 void OTableStyleContext::AddProperty(const sal_Int16 nContextID, const uno::Any& rValue)
177 {
178 	sal_Int32 nIndex(static_cast<OTableStylesContext *>(pStyles)->GetIndex(nContextID));
179 	DBG_ASSERT(nIndex != -1, "Property not found in Map");
180 	XMLPropertyState aPropState(nIndex, rValue);
181 	GetProperties().push_back(aPropState); // has to be insertes in a sort order later
182 }
183 // -----------------------------------------------------------------------------
SetAttribute(sal_uInt16 nPrefixKey,const::rtl::OUString & rLocalName,const::rtl::OUString & rValue)184 void OTableStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
185 										const ::rtl::OUString& rLocalName,
186 										const ::rtl::OUString& rValue )
187 {
188 	// TODO: use a map here
189 	if( IsXMLToken(rLocalName, XML_DATA_STYLE_NAME ) )
190 		m_sDataStyleName = rValue;
191 	else if ( IsXMLToken(rLocalName, XML_MASTER_PAGE_NAME ) )
192 		sPageStyle = rValue;
193 	else
194 		XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
195 }
196 // -----------------------------------------------------------------------------
GetOwnImport()197 ODBFilter& OTableStyleContext::GetOwnImport()
198 {
199 	return static_cast<ODBFilter&>(GetImport());
200 }
201 // -----------------------------------------------------------------------------
DBG_NAME(OTableStylesContext)202 DBG_NAME(OTableStylesContext)
203 
204 OTableStylesContext::OTableStylesContext( SvXMLImport& rImport,
205 		sal_uInt16 nPrfx ,
206 		const ::rtl::OUString& rLName ,
207 		const Reference< XAttributeList > & xAttrList,
208 		const sal_Bool bTempAutoStyles ) :
209 	SvXMLStylesContext( rImport, nPrfx, rLName, xAttrList ),
210 	sTableStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME ))),
211     sColumnStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME ))),
212     sCellStyleServiceName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME ))),
213 	m_nNumberFormatIndex(-1),
214 	bAutoStyles(bTempAutoStyles)
215 {
216     DBG_CTOR(OTableStylesContext,NULL);
217 
218 }
219 // -----------------------------------------------------------------------------
220 
~OTableStylesContext()221 OTableStylesContext::~OTableStylesContext()
222 {
223 
224     DBG_DTOR(OTableStylesContext,NULL);
225 }
226 // -----------------------------------------------------------------------------
227 
EndElement()228 void OTableStylesContext::EndElement()
229 {
230 	SvXMLStylesContext::EndElement();
231 	if (bAutoStyles)
232 		GetImport().GetTextImport()->SetAutoStyles( this );
233 	else
234 		GetImport().GetStyles()->CopyStylesToDoc(sal_True);
235 }
236 // -----------------------------------------------------------------------------
237 
238 UniReference < SvXMLImportPropertyMapper >
GetImportPropertyMapper(sal_uInt16 nFamily) const239 	OTableStylesContext::GetImportPropertyMapper(
240 					sal_uInt16 nFamily ) const
241 {
242 	UniReference < SvXMLImportPropertyMapper > xMapper = SvXMLStylesContext::GetImportPropertyMapper(nFamily);
243 
244 	if (!xMapper.is())
245 	{
246 		switch( nFamily )
247 		{
248 			case XML_STYLE_FAMILY_TABLE_TABLE:
249 			{
250 				if ( !m_xTableImpPropMapper.is() )
251 					m_xTableImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetTableStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
252 				xMapper = m_xTableImpPropMapper;
253 			}
254 	 		break;
255             case XML_STYLE_FAMILY_TABLE_COLUMN:
256 			{
257 				if ( !m_xColumnImpPropMapper.is() )
258 					m_xColumnImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetColumnStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
259 				xMapper = m_xColumnImpPropMapper;
260 			}
261 	 		break;
262             case XML_STYLE_FAMILY_TABLE_CELL:
263 			{
264 				if ( !m_xCellImpPropMapper.is() )
265 					m_xCellImpPropMapper = new SvXMLImportPropertyMapper( const_cast<OTableStylesContext*>(this)->GetOwnImport().GetCellStylesPropertySetMapper(), const_cast<SvXMLImport&>(GetImport()) );
266 				xMapper = m_xCellImpPropMapper;
267 			}
268 	 		break;
269 		}
270 	}
271 
272 	return xMapper;
273 }
274 // ----------------------------------------------------------------------------
CreateStyleStyleChildContext(sal_uInt16 nFamily,sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const Reference<xml::sax::XAttributeList> & xAttrList)275 SvXMLStyleContext *OTableStylesContext::CreateStyleStyleChildContext(
276 		sal_uInt16 nFamily, sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
277 		const Reference< xml::sax::XAttributeList > & xAttrList )
278 {
279 	SvXMLStyleContext *pStyle = SvXMLStylesContext::CreateStyleStyleChildContext( nFamily, nPrefix,
280 															rLocalName,
281 															xAttrList );
282 	if (!pStyle)
283 	{
284 		switch( nFamily )
285 		{
286 		case XML_STYLE_FAMILY_TABLE_TABLE:
287         case XML_STYLE_FAMILY_TABLE_COLUMN:
288         case XML_STYLE_FAMILY_TABLE_CELL:
289 			pStyle = new OTableStyleContext( GetOwnImport(), nPrefix, rLocalName,
290 			   								xAttrList, *this, nFamily );
291 			break;
292 		}
293 	}
294 
295 	return pStyle;
296 }
297 // -----------------------------------------------------------------------------
298 Reference < XNameContainer >
GetStylesContainer(sal_uInt16 nFamily) const299 		OTableStylesContext::GetStylesContainer( sal_uInt16 nFamily ) const
300 {
301 	Reference < XNameContainer > xStyles = SvXMLStylesContext::GetStylesContainer(nFamily);
302 	return xStyles;
303 }
304 // -----------------------------------------------------------------------------
305 
GetServiceName(sal_uInt16 nFamily) const306 ::rtl::OUString OTableStylesContext::GetServiceName( sal_uInt16 nFamily ) const
307 {
308 	rtl::OUString sServiceName = SvXMLStylesContext::GetServiceName(nFamily);
309 	if (!sServiceName.getLength())
310 	{
311 		switch( nFamily )
312 		{
313 		case XML_STYLE_FAMILY_TABLE_TABLE:
314 			sServiceName = sTableStyleServiceName;
315 			break;
316         case XML_STYLE_FAMILY_TABLE_COLUMN:
317 			sServiceName = sColumnStyleServiceName;
318 			break;
319         case XML_STYLE_FAMILY_TABLE_CELL:
320 			sServiceName = sCellStyleServiceName;
321 			break;
322 
323 		}
324 	}
325 	return sServiceName;
326 }
327 // -----------------------------------------------------------------------------
328 
GetIndex(const sal_Int16 nContextID)329 sal_Int32 OTableStylesContext::GetIndex(const sal_Int16 nContextID)
330 {
331 	if ( nContextID == CTF_DB_NUMBERFORMAT )
332 	{
333 		if (m_nNumberFormatIndex == -1)
334 			m_nNumberFormatIndex =
335 				GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_COLUMN)->getPropertySetMapper()->FindEntryIndex(nContextID);
336 		return m_nNumberFormatIndex;
337 	}
338 	else if ( nContextID == CTF_DB_MASTERPAGENAME )
339 	{
340 		if (nMasterPageNameIndex == -1)
341 			nMasterPageNameIndex =
342 				GetImportPropertyMapper(XML_STYLE_FAMILY_TABLE_TABLE)->getPropertySetMapper()->FindEntryIndex(nContextID);
343 		return nMasterPageNameIndex;
344 	}
345 	else if ( nContextID == CTF_DB_ISVISIBLE )
346 	{
347 		return -1;
348 	}
349 	else
350 		return -1;
351 }
352 // -----------------------------------------------------------------------------
GetOwnImport()353 ODBFilter& OTableStylesContext::GetOwnImport()
354 {
355 	return static_cast<ODBFilter&>(GetImport());
356 }
357 // -----------------------------------------------------------------------------
358 } // dbaxml
359 // -----------------------------------------------------------------------------
360