xref: /trunk/main/sw/source/filter/xml/xmlimpit.cxx (revision 8996694b)
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_sw.hxx"
26 #include "xmlimpit.hxx"
27 #include <xmloff/xmluconv.hxx>
28 #include <svl/itempool.hxx>
29 #include <svl/poolitem.hxx>
30 #include <svl/itemset.hxx>
31 #include <xmloff/attrlist.hxx>
32 #include <xmloff/nmspmap.hxx>
33 #include <xmloff/xmlnmspe.hxx>
34 #include <editeng/xmlcnitm.hxx>
35 #include <editeng/memberids.hrc>
36 
37 
38 #include "hintids.hxx"
39 #include "unomid.h"
40 #include <svx/unomid.hxx>
41 #include <editeng/lrspitem.hxx>
42 #include <editeng/ulspitem.hxx>
43 #include <editeng/shaditem.hxx>
44 #include <editeng/boxitem.hxx>
45 #include <editeng/brkitem.hxx>
46 #include <editeng/keepitem.hxx>
47 #include <editeng/brshitem.hxx>
48 #include "fmtpdsc.hxx"
49 #include "fmtornt.hxx"
50 #include "fmtfsize.hxx"
51 
52 #ifndef _FMTLSPLT_HXX
53 #include "fmtlsplt.hxx"
54 #endif
55 #include <xmloff/prhdlfac.hxx>
56 #include <xmloff/xmltypes.hxx>
57 #include "xmlithlp.hxx"
58 #include <com/sun/star/uno/Any.hxx>
59 
60 using ::rtl::OUString;
61 using namespace ::com::sun::star;
62 using namespace ::xmloff::token;
63 using uno::Any;
64 
SvXMLImportItemMapper(SvXMLItemMapEntriesRef rMapEntries,sal_uInt16 nUnknWhich)65 SvXMLImportItemMapper::SvXMLImportItemMapper(
66 								SvXMLItemMapEntriesRef rMapEntries,
67 								sal_uInt16 nUnknWhich ) :
68 	mrMapEntries( rMapEntries ),
69 	nUnknownWhich( nUnknWhich )
70 {
71 }
72 
~SvXMLImportItemMapper()73 SvXMLImportItemMapper::~SvXMLImportItemMapper()
74 {
75 }
76 
77 void
setMapEntries(SvXMLItemMapEntriesRef rMapEntries)78 SvXMLImportItemMapper::setMapEntries( SvXMLItemMapEntriesRef rMapEntries )
79 {
80 	mrMapEntries = rMapEntries;
81 }
82 
83 /** fills the given itemset with the attributes in the given list */
importXML(SfxItemSet & rSet,uno::Reference<xml::sax::XAttributeList> xAttrList,const SvXMLUnitConverter & rUnitConverter,const SvXMLNamespaceMap & rNamespaceMap)84 void SvXMLImportItemMapper::importXML( SfxItemSet& rSet,
85 									  uno::Reference< xml::sax::XAttributeList > xAttrList,
86 									  const SvXMLUnitConverter& rUnitConverter,
87                                       const SvXMLNamespaceMap& rNamespaceMap )
88 {
89 	sal_Int16 nAttr = xAttrList->getLength();
90 
91 	SvXMLAttrContainerItem *pUnknownItem = 0;
92 	for( sal_Int16 i=0; i < nAttr; i++ )
93 	{
94 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
95 		OUString aLocalName, aPrefix, aNamespace;
96 		sal_uInt16 nPrefix =
97 			rNamespaceMap.GetKeyByAttrName( rAttrName, &aPrefix, &aLocalName,
98 											&aNamespace );
99 		if( XML_NAMESPACE_XMLNS == nPrefix )
100 			continue;
101 
102 		const OUString& rValue = xAttrList->getValueByIndex( i );
103 
104 		// find a map entry for this attribute
105 		SvXMLItemMapEntry* pEntry = mrMapEntries->getByName( nPrefix, aLocalName );
106 
107 		if( pEntry )
108 		{
109 			// we have a valid map entry here, so lets use it...
110 			if( 0 == (pEntry->nMemberId & (MID_SW_FLAG_NO_ITEM_IMPORT|
111 									   MID_SW_FLAG_ELEMENT_ITEM_IMPORT)) )
112 			{
113 				// first get item from itemset
114 				const SfxPoolItem* pItem = 0;
115 				SfxItemState eState = rSet.GetItemState( pEntry->nWhichId, sal_True,
116 														 &pItem );
117 
118 				// if its not set, try the pool
119 				if(SFX_ITEM_SET != eState && SFX_WHICH_MAX > pEntry->nWhichId )
120 					pItem = &rSet.GetPool()->GetDefaultItem(pEntry->nWhichId);
121 
122 				// do we have an item?
123 				if(eState >= SFX_ITEM_DEFAULT && pItem)
124 				{
125 					SfxPoolItem *pNewItem = pItem->Clone();
126 					sal_Bool bPut = sal_False;
127 
128 					if( 0 == (pEntry->nMemberId&MID_SW_FLAG_SPECIAL_ITEM_IMPORT) )
129 					{
130 // 						bPut = pNewItem->importXML( rValue,
131 // 											pEntry->nMemberId & MID_SW_FLAG_MASK,
132 // 											rUnitConverter );
133                         bPut = PutXMLValue( *pNewItem, rValue,
134                                             static_cast<sal_uInt16>( pEntry->nMemberId & MID_SW_FLAG_MASK ),
135                                             rUnitConverter );
136 
137 					}
138 					else
139 					{
140 						bPut = handleSpecialItem( *pEntry, *pNewItem, rSet,
141 												  rValue, rUnitConverter,
142 												  rNamespaceMap );
143 					}
144 
145 					if( bPut )
146 						rSet.Put( *pNewItem );
147 
148 					delete pNewItem;
149 				}
150 				else
151 				{
152 					DBG_ERROR( "Could not get a needed item for xml import!" );
153 				}
154 			}
155 			else if( 0 != (pEntry->nMemberId & MID_SW_FLAG_NO_ITEM_IMPORT) )
156 			{
157 				handleNoItem( *pEntry, rSet, rValue, rUnitConverter,
158 							  rNamespaceMap );
159 			}
160 		}
161 		else if( USHRT_MAX != nUnknownWhich )
162 		{
163 			if( !pUnknownItem )
164 			{
165 				const SfxPoolItem* pItem = 0;
166 				if( SFX_ITEM_SET == rSet.GetItemState( nUnknownWhich, sal_True,
167 													   &pItem ) )
168 				{
169 					SfxPoolItem *pNew = pItem->Clone();
170 					pUnknownItem = PTR_CAST( SvXMLAttrContainerItem, pNew );
171 					DBG_ASSERT( pUnknownItem,
172 								"SvXMLAttrContainerItem expected" );
173 					if( !pUnknownItem )
174 						delete pNew;
175 				}
176 				else
177 				{
178 					pUnknownItem = new SvXMLAttrContainerItem( nUnknownWhich );
179 				}
180 			}
181 			if( pUnknownItem )
182 			{
183 				if( XML_NAMESPACE_NONE == nPrefix )
184 					pUnknownItem->AddAttr( aLocalName, rValue );
185 				else
186 					pUnknownItem->AddAttr( aPrefix, aNamespace, aLocalName,
187 										   rValue );
188 			}
189 		}
190 	}
191 
192 	if( pUnknownItem )
193 	{
194 		rSet.Put( *pUnknownItem );
195 		delete pUnknownItem;
196 	}
197 
198     finished(rSet, rUnitConverter);
199 }
200 
201 /** this method is called for every item that has the
202 	MID_SW_FLAG_SPECIAL_ITEM_IMPORT flag set */
203 sal_Bool
handleSpecialItem(const SvXMLItemMapEntry &,SfxPoolItem &,SfxItemSet &,const OUString &,const SvXMLUnitConverter &,const SvXMLNamespaceMap &)204 SvXMLImportItemMapper::handleSpecialItem(  const SvXMLItemMapEntry& /*rEntry*/,
205 											SfxPoolItem& /*rItem*/,
206 											SfxItemSet& /*rSet*/,
207 											const OUString& /*rValue*/,
208 											const SvXMLUnitConverter& /*rUnitConverter*/,
209                                             const SvXMLNamespaceMap& /*rNamespaceMap*/ )
210 {
211 	DBG_ERROR( "unsuported special item in xml import" );
212 	return sal_False;
213 }
214 
215 /** this method is called for every item that has the
216 	MID_SW_FLAG_NO_ITEM_IMPORT flag set */
handleNoItem(const SvXMLItemMapEntry &,SfxItemSet &,const OUString &,const SvXMLUnitConverter &,const SvXMLNamespaceMap &)217 sal_Bool SvXMLImportItemMapper::handleNoItem( const SvXMLItemMapEntry& /*rEntry*/,
218 										   SfxItemSet& /*rSet*/,
219 										   const OUString& /*rValue*/,
220 										   const SvXMLUnitConverter& /*rUnitConverter*/,
221                                            const SvXMLNamespaceMap& /*rNamespaceMap*/ )
222 {
223 	DBG_ERROR( "unsuported no item in xml import" );
224 	return sal_False;
225 }
226 
227 void
finished(SfxItemSet &,SvXMLUnitConverter const &) const228 SvXMLImportItemMapper::finished(SfxItemSet &, SvXMLUnitConverter const&) const
229 {
230 	// nothing to do here
231 }
232 
233 
234 
235 // put an XML-string value into an item
PutXMLValue(SfxPoolItem & rItem,const::rtl::OUString & rValue,sal_uInt16 nMemberId,const SvXMLUnitConverter & rUnitConverter)236 sal_Bool SvXMLImportItemMapper::PutXMLValue(
237     SfxPoolItem& rItem,
238     const ::rtl::OUString& rValue,
239     sal_uInt16 nMemberId,
240     const SvXMLUnitConverter& rUnitConverter )
241 {
242     sal_Bool bOk = sal_False;
243 
244     switch (rItem.Which())
245         {
246         case RES_LR_SPACE:
247         {
248             SvxLRSpaceItem* pLRSpace = PTR_CAST(SvxLRSpaceItem, &rItem);
249             DBG_ASSERT( pLRSpace != NULL, "Wrong Which-ID!" );
250 
251             switch( nMemberId )
252             {
253                 case MID_L_MARGIN:
254                 case MID_R_MARGIN:
255                 {
256                     sal_Int32 nProp = 100;
257                     sal_Int32 nAbs = 0;
258 
259                     if( rValue.indexOf( sal_Unicode('%') ) != -1 )
260                         bOk = rUnitConverter.convertPercent( nProp, rValue );
261                     else
262                         bOk = rUnitConverter.convertMeasure( nAbs, rValue );
263 
264                     if( bOk )
265                     {
266                         switch( nMemberId )
267                         {
268                             case MID_L_MARGIN:
269                                 pLRSpace->SetTxtLeft( (sal_Int32)nAbs, (sal_uInt16)nProp );
270                                 break;
271                             case MID_R_MARGIN:
272                                 pLRSpace->SetRight( (sal_Int32)nAbs, (sal_uInt16)nProp );
273                                 break;
274                         }
275                     }
276                 }
277                 break;
278                 case MID_FIRST_LINE_INDENT:
279                 {
280                     sal_Int32 nProp = 100;
281                     sal_Int32 nAbs = 0;
282 
283                     if( rValue.indexOf( sal_Unicode('%') ) != -1 )
284                         bOk = rUnitConverter.convertPercent( nProp, rValue );
285                     else
286                         bOk = rUnitConverter.convertMeasure( nAbs, rValue,
287                                                              -0x7fff, 0x7fff );
288 
289                     pLRSpace->SetTxtFirstLineOfst( (short)nAbs, (sal_uInt16)nProp );
290                 }
291 
292                 case MID_FIRST_AUTO:
293                 {
294                     sal_Bool bAutoFirst;
295                     bOk = rUnitConverter.convertBool( bAutoFirst, rValue );
296                     if( bOk )
297                         pLRSpace->SetAutoFirst( bAutoFirst );
298                 }
299                 break;
300 
301                 default:
302                     DBG_ERROR( "unknown member id!");
303             }
304         }
305         break;
306 
307         case RES_UL_SPACE:
308         {
309             SvxULSpaceItem* pULSpace = PTR_CAST(SvxULSpaceItem, &rItem);
310             DBG_ASSERT( pULSpace != NULL, "Wrong Which-ID!" );
311 
312             sal_Int32 nProp = 100;
313             sal_Int32 nAbs = 0;
314 
315             if( rValue.indexOf( sal_Unicode('%') ) != -1 )
316                 bOk = rUnitConverter.convertPercent( nProp, rValue );
317             else
318                 bOk = rUnitConverter.convertMeasure( nAbs, rValue );
319 
320             switch( nMemberId )
321             {
322                 case MID_UP_MARGIN:
323                     pULSpace->SetUpper( (sal_uInt16)nAbs, (sal_uInt16)nProp );
324                     break;
325                 case MID_LO_MARGIN:
326                     pULSpace->SetLower( (sal_uInt16)nAbs, (sal_uInt16)nProp );
327                     break;
328                 default:
329                     DBG_ERROR("unknown MemberId");
330             }
331         }
332         break;
333 
334         case RES_SHADOW:
335         {
336             SvxShadowItem* pShadow = PTR_CAST(SvxShadowItem, &rItem);
337             DBG_ASSERT( pShadow != NULL, "Wrong Which-ID" );
338 
339             sal_Bool bColorFound = sal_False;
340             sal_Bool bOffsetFound = sal_False;
341 
342             SvXMLTokenEnumerator aTokenEnum( rValue );
343 
344             Color aColor( 128,128, 128 );
345             pShadow->SetLocation( SVX_SHADOW_BOTTOMRIGHT );
346 
347             OUString aToken;
348             while( aTokenEnum.getNextToken( aToken ) )
349             {
350                 if( IsXMLToken( aToken, XML_NONE ) )
351                 {
352                     pShadow->SetLocation( SVX_SHADOW_NONE );
353                     bOk = sal_True;
354                 }
355                 else if( !bColorFound && aToken.compareToAscii( "#", 1 ) == 0 )
356                 {
357                     bOk = rUnitConverter.convertColor( aColor, aToken );
358                     if( !bOk )
359                         return sal_False;
360 
361                     bColorFound = sal_True;
362                 }
363                 else if( !bOffsetFound )
364                 {
365                     sal_Int32 nX = 0, nY = 0;
366 
367                     bOk = rUnitConverter.convertMeasure( nX, aToken );
368                     if( bOk && aTokenEnum.getNextToken( aToken ) )
369                         bOk = rUnitConverter.convertMeasure( nY, aToken );
370 
371                     if( bOk )
372                     {
373                         if( nX < 0 )
374                         {
375                             if( nY < 0 )
376                             {
377                                 pShadow->SetLocation( SVX_SHADOW_TOPLEFT );
378                             }
379                             else
380                             {
381                                 pShadow->SetLocation( SVX_SHADOW_BOTTOMLEFT );
382                             }
383                         }
384                         else
385                         {
386                             if( nY < 0 )
387                             {
388                                 pShadow->SetLocation( SVX_SHADOW_TOPRIGHT );
389                             }
390                             else
391                             {
392                                 pShadow->SetLocation( SVX_SHADOW_BOTTOMRIGHT );
393                             }
394                         }
395 
396                         if( nX < 0 ) nX *= -1;
397                         if( nY < 0 ) nY *= -1;
398 
399                         pShadow->SetWidth( static_cast< sal_uInt16 >( (nX + nY) >> 1 ) );
400                     }
401                 }
402             }
403 
404             if( bOk && ( bColorFound || bOffsetFound ) )
405             {
406                 pShadow->SetColor( aColor );
407             }
408             else
409                 bOk = sal_False;
410         }
411         break;
412 
413         case RES_BOX:
414         {
415             SvxBoxItem* pBox = PTR_CAST(SvxBoxItem, &rItem);
416             DBG_ASSERT( pBox != NULL, "Wrong WHich-ID" );
417 
418             /** copy SvxBorderLines */
419             SvxBorderLine* pTop    = pBox->GetTop() == NULL ?
420                                 NULL : new SvxBorderLine( *pBox->GetTop() );
421             SvxBorderLine* pBottom = pBox->GetBottom() == NULL ?
422                                 NULL : new SvxBorderLine( *pBox->GetBottom() );
423             SvxBorderLine* pLeft   = pBox->GetLeft() == NULL ?
424                                 NULL : new SvxBorderLine( *pBox->GetLeft() );
425             SvxBorderLine* pRight  = pBox->GetRight() == NULL ?
426                                 NULL : new SvxBorderLine( *pBox->GetRight() );
427 
428             sal_Int32 nTemp;
429 
430             switch( nMemberId )
431             {
432                 case ALL_BORDER_PADDING:
433                 case LEFT_BORDER_PADDING:
434                 case RIGHT_BORDER_PADDING:
435                 case TOP_BORDER_PADDING:
436                 case BOTTOM_BORDER_PADDING:
437                     if(!rUnitConverter.convertMeasure( nTemp, rValue, 0, 0xffff ))
438                         return sal_False;
439 
440                     if( nMemberId == LEFT_BORDER_PADDING ||
441                         nMemberId == ALL_BORDER_PADDING )
442                         pBox->SetDistance( (sal_uInt16)nTemp, BOX_LINE_LEFT );
443                     if( nMemberId == RIGHT_BORDER_PADDING ||
444                         nMemberId == ALL_BORDER_PADDING )
445                         pBox->SetDistance( (sal_uInt16)nTemp, BOX_LINE_RIGHT );
446                     if( nMemberId == TOP_BORDER_PADDING ||
447                         nMemberId == ALL_BORDER_PADDING )
448                         pBox->SetDistance( (sal_uInt16)nTemp, BOX_LINE_TOP );
449                     if( nMemberId == BOTTOM_BORDER_PADDING ||
450                         nMemberId == ALL_BORDER_PADDING )
451                         pBox->SetDistance( (sal_uInt16)nTemp, BOX_LINE_BOTTOM);
452                     break;
453 
454                 case ALL_BORDER:
455                 case LEFT_BORDER:
456                 case RIGHT_BORDER:
457                 case TOP_BORDER:
458                 case BOTTOM_BORDER:
459                 {
460                     sal_Bool bHasStyle = sal_False;
461                     sal_Bool bHasWidth = sal_False;
462                     sal_Bool bHasColor = sal_False;
463 
464                     sal_uInt16 nStyle = USHRT_MAX;
465                     sal_uInt16 nWidth = 0;
466                     sal_uInt16 nNamedWidth = USHRT_MAX;
467 
468                     Color aColor( COL_BLACK );
469 
470                     if( !lcl_frmitems_parseXMLBorder( rValue, rUnitConverter,
471                                                       bHasStyle, nStyle,
472                                                       bHasWidth, nWidth, nNamedWidth,
473                                                       bHasColor, aColor ) )
474                         return sal_False;
475 
476                     if( TOP_BORDER == nMemberId || ALL_BORDER == nMemberId )
477                         lcl_frmitems_setXMLBorder( pTop,
478                                                    bHasStyle, nStyle,
479                                                    bHasWidth, nWidth, nNamedWidth,
480                                                    bHasColor, aColor );
481 
482                     if( BOTTOM_BORDER == nMemberId || ALL_BORDER == nMemberId )
483                         lcl_frmitems_setXMLBorder( pBottom,
484                                                    bHasStyle, nStyle,
485                                                    bHasWidth, nWidth, nNamedWidth,
486                                                    bHasColor, aColor );
487 
488                     if( LEFT_BORDER == nMemberId || ALL_BORDER == nMemberId )
489                         lcl_frmitems_setXMLBorder( pLeft,
490                                                    bHasStyle, nStyle,
491                                                    bHasWidth, nWidth, nNamedWidth,
492                                                    bHasColor, aColor );
493 
494                     if( RIGHT_BORDER == nMemberId || ALL_BORDER == nMemberId )
495                         lcl_frmitems_setXMLBorder( pRight,
496                                                    bHasStyle, nStyle,
497                                                    bHasWidth, nWidth, nNamedWidth,
498                                                    bHasColor, aColor );
499                 }
500                 break;
501                 case ALL_BORDER_LINE_WIDTH:
502                 case LEFT_BORDER_LINE_WIDTH:
503                 case RIGHT_BORDER_LINE_WIDTH:
504                 case TOP_BORDER_LINE_WIDTH:
505                 case BOTTOM_BORDER_LINE_WIDTH:
506                 {
507                     SvXMLTokenEnumerator aTokenEnum( rValue );
508 
509                     sal_Int32 nInWidth, nDistance, nOutWidth;
510 
511                     OUString aToken;
512                     if( !aTokenEnum.getNextToken( aToken ) )
513                         return sal_False;
514 
515                     if( !rUnitConverter.convertMeasure( nInWidth, aToken,
516                                                         DEF_LINE_WIDTH_0,
517                                                         DEF_LINE_WIDTH_4 ) )
518                         return sal_False;
519 
520                     if( !aTokenEnum.getNextToken( aToken ) )
521                         return sal_False;
522 
523                     if( !rUnitConverter.convertMeasure( nDistance, aToken,
524                                                         DEF_LINE_WIDTH_0,
525                                                         DEF_LINE_WIDTH_4 ) )
526                         return sal_False;
527 
528                     if( !aTokenEnum.getNextToken( aToken ) )
529                         return sal_False;
530 
531                     if( !rUnitConverter.convertMeasure( nOutWidth, aToken,
532                                                         DEF_LINE_WIDTH_0,
533                                                         DEF_LINE_WIDTH_4 ) )
534                         return sal_False;
535 
536                     // #i61946: accept line style even it's not part of our "normal" set of line styles
537                     sal_uInt16 nWidth = 0;
538 
539                     if( TOP_BORDER_LINE_WIDTH == nMemberId ||
540                         ALL_BORDER_LINE_WIDTH == nMemberId )
541                         lcl_frmitems_setXMLBorder( pTop, nWidth,
542 								static_cast< sal_uInt16 >( nOutWidth ),
543                                 static_cast< sal_uInt16 >( nInWidth ),
544 								static_cast< sal_uInt16 >( nDistance ) );
545 
546                     if( BOTTOM_BORDER_LINE_WIDTH == nMemberId ||
547                         ALL_BORDER_LINE_WIDTH == nMemberId )
548                         lcl_frmitems_setXMLBorder( pBottom, nWidth,
549 								static_cast< sal_uInt16 >( nOutWidth ),
550                                 static_cast< sal_uInt16 >( nInWidth ),
551 								static_cast< sal_uInt16 >( nDistance ) );
552 
553                     if( LEFT_BORDER_LINE_WIDTH == nMemberId ||
554                         ALL_BORDER_LINE_WIDTH == nMemberId )
555                         lcl_frmitems_setXMLBorder( pLeft, nWidth,
556 								static_cast< sal_uInt16 >( nOutWidth ),
557                                 static_cast< sal_uInt16 >( nInWidth ),
558 								static_cast< sal_uInt16 >( nDistance ) );
559 
560                     if( RIGHT_BORDER_LINE_WIDTH == nMemberId ||
561                         ALL_BORDER_LINE_WIDTH == nMemberId )
562                         lcl_frmitems_setXMLBorder( pRight, nWidth,
563 								static_cast< sal_uInt16 >( nOutWidth ),
564                                 static_cast< sal_uInt16 >( nInWidth ),
565 								static_cast< sal_uInt16 >( nDistance ) );
566                 }
567                 break;
568             }
569 
570 			pBox->SetLine( pTop,    BOX_LINE_TOP    );
571 			pBox->SetLine( pBottom, BOX_LINE_BOTTOM );
572 			pBox->SetLine( pLeft,   BOX_LINE_LEFT   );
573 			pBox->SetLine( pRight,  BOX_LINE_RIGHT  );
574 
575             delete pTop;
576             delete pBottom;
577             delete pLeft;
578             delete pRight;
579 
580             bOk = sal_True;
581         }
582         break;
583 
584         case RES_BREAK:
585         {
586             SvxFmtBreakItem* pFmtBreak = PTR_CAST(SvxFmtBreakItem, &rItem);
587             DBG_ASSERT( pFmtBreak != NULL, "Wrong Which-ID" );
588 
589             sal_uInt16 eEnum;
590 
591             if( !rUnitConverter.convertEnum( eEnum, rValue, psXML_BreakType ) )
592                 return sal_False;
593 
594             if( eEnum == 0 )
595             {
596                 pFmtBreak->SetValue( SVX_BREAK_NONE );
597                 bOk = sal_True;
598             }
599             else
600             {
601                 switch( nMemberId )
602                 {
603                     case MID_BREAK_BEFORE:
604                         pFmtBreak->SetValue( static_cast< sal_uInt16 >((eEnum == 1) ?
605                                              SVX_BREAK_COLUMN_BEFORE :
606                                              SVX_BREAK_PAGE_BEFORE) );
607                         break;
608                     case MID_BREAK_AFTER:
609                         pFmtBreak->SetValue( static_cast< sal_uInt16 >((eEnum == 1) ?
610                                              SVX_BREAK_COLUMN_AFTER :
611                                              SVX_BREAK_PAGE_AFTER) );
612                         break;
613                 }
614                 bOk = sal_True;
615             }
616         }
617         break;
618 
619         case RES_KEEP:
620         {
621             SvxFmtKeepItem* pFmtKeep = PTR_CAST(SvxFmtKeepItem, &rItem);
622             DBG_ASSERT( pFmtKeep != NULL, "Wrong Which-ID" );
623 
624             if( IsXMLToken( rValue, XML_ALWAYS ) ||
625 			 	IsXMLToken( rValue, XML_TRUE ) )
626             {
627                 pFmtKeep->SetValue( sal_True );
628                 bOk = sal_True;
629             }
630             else if( IsXMLToken( rValue, XML_AUTO ) ||
631 				     IsXMLToken( rValue, XML_FALSE ) )
632             {
633                 pFmtKeep->SetValue( sal_False );
634                 bOk = sal_True;
635             }
636         }
637         break;
638 
639         case RES_BACKGROUND:
640         {
641             SvxBrushItem* pBrush = PTR_CAST(SvxBrushItem, &rItem);
642             DBG_ASSERT( pBrush != NULL, "Wrong Which-ID" );
643 
644             Color aTempColor;
645             switch( nMemberId )
646                 {
647                 case MID_BACK_COLOR:
648                     if(	IsXMLToken( rValue, XML_TRANSPARENT ) )
649                     {
650                         pBrush->GetColor().SetTransparency(0xff);
651                         bOk = sal_True;
652                     }
653                     else if( rUnitConverter.convertColor( aTempColor, rValue ) )
654                     {
655                         aTempColor.SetTransparency(0);
656                         pBrush->SetColor( aTempColor );
657                         bOk = sal_True;
658                     }
659                     break;
660 
661                 case MID_GRAPHIC_LINK:
662                 {
663                     SvxGraphicPosition eOldGraphicPos = pBrush->GetGraphicPos();
664                     uno::Any aAny;
665                     aAny <<= rValue;
666                     pBrush->PutValue( aAny, MID_GRAPHIC_URL );
667                     if( GPOS_NONE == eOldGraphicPos &&
668                         GPOS_NONE != pBrush->GetGraphicPos() )
669                         pBrush->SetGraphicPos( GPOS_TILED );
670                     bOk = sal_True	;
671                 }
672                 break;
673 
674                 case MID_GRAPHIC_REPEAT:
675                 {
676                     SvxGraphicPosition eGraphicPos = pBrush->GetGraphicPos();
677                     sal_uInt16 nPos = GPOS_NONE;
678                     if( rUnitConverter.convertEnum( nPos, rValue,
679                                                     psXML_BrushRepeat ) )
680                     {
681                         if( GPOS_MM != nPos || GPOS_NONE == eGraphicPos ||
682                             GPOS_AREA == eGraphicPos || GPOS_TILED == eGraphicPos )
683                             pBrush->SetGraphicPos( (SvxGraphicPosition)nPos );
684                         bOk = sal_True;
685                     }
686                 }
687                 break;
688 
689                 case MID_GRAPHIC_POSITION:
690                 {
691                     SvxGraphicPosition ePos = GPOS_NONE, eTmp;
692                     sal_uInt16 nTmp;
693                     SvXMLTokenEnumerator aTokenEnum( rValue );
694                     OUString aToken;
695                     sal_Bool bHori = sal_False, bVert = sal_False;
696                     bOk = sal_True;
697                     while( bOk && aTokenEnum.getNextToken( aToken ) )
698                     {
699                         if( bHori && bVert )
700                         {
701                             bOk = sal_False;
702                         }
703                         else if( -1 != aToken.indexOf( sal_Unicode('%') ) )
704                         {
705                             sal_Int32 nPrc = 50;
706                             if( rUnitConverter.convertPercent( nPrc, aToken ) )
707                             {
708                                 if( !bHori )
709                                 {
710                                     ePos = nPrc < 25 ? GPOS_LT :
711                                                (nPrc < 75 ? GPOS_MM : GPOS_RB);
712                                     bHori = sal_True;
713                                 }
714                                 else
715                                 {
716                                     eTmp = nPrc < 25 ? GPOS_LT:
717                                                (nPrc < 75 ? GPOS_LM : GPOS_LB);
718                                     lcl_frmitems_MergeXMLVertPos( ePos, eTmp );
719                                     bVert = sal_True;
720                                 }
721                             }
722                             else
723                             {
724                                 // wrong percentage
725                                 bOk = sal_False;
726                             }
727                         }
728                         else if( IsXMLToken( aToken, XML_CENTER ) )
729                         {
730                             if( bHori )
731                                 lcl_frmitems_MergeXMLVertPos( ePos, GPOS_MM );
732                             else if ( bVert )
733                                 lcl_frmitems_MergeXMLHoriPos( ePos, GPOS_MM );
734                             else
735                                 ePos = GPOS_MM;
736                         }
737                         else if( rUnitConverter.convertEnum( nTmp, aToken,
738                                                          psXML_BrushHoriPos ) )
739                         {
740                             if( bVert )
741                                 lcl_frmitems_MergeXMLHoriPos(
742                                     ePos, (SvxGraphicPosition)nTmp );
743                             else if( !bHori )
744                                 ePos = (SvxGraphicPosition)nTmp;
745                             else
746                                 bOk = sal_False;
747                             bHori = sal_True;
748                         }
749                         else if( rUnitConverter.convertEnum( nTmp, aToken,
750                                                          psXML_BrushVertPos ) )
751                         {
752                             if( bHori )
753                                 lcl_frmitems_MergeXMLVertPos(
754                                     ePos, (SvxGraphicPosition)nTmp );
755                             else if( !bVert )
756                                 ePos = (SvxGraphicPosition)nTmp;
757                             else
758                                 bOk = sal_False;
759                             bVert = sal_True;
760                         }
761                         else
762                         {
763                             bOk = sal_False;
764                         }
765                     }
766 
767                     bOk &= GPOS_NONE != ePos;
768                     if( bOk )
769                         pBrush->SetGraphicPos( ePos );
770                 }
771                 break;
772 
773                 case MID_GRAPHIC_FILTER:
774                     pBrush->SetGraphicFilter( rValue.getStr() );
775                     bOk = sal_True;
776                     break;
777                 }
778         }
779         break;
780 
781         case RES_PAGEDESC:
782         {
783             SwFmtPageDesc* pPageDesc = PTR_CAST(SwFmtPageDesc, &rItem);
784             DBG_ASSERT( pPageDesc != NULL, "Wrong Which-ID" );
785 
786             if( MID_PAGEDESC_PAGENUMOFFSET==nMemberId )
787             {
788                 sal_Int32 nVal;
789                 bOk = rUnitConverter.convertNumber( nVal, rValue, 0, USHRT_MAX );
790                 if( bOk )
791                     pPageDesc->SetNumOffset( (sal_uInt16)nVal );
792             }
793         }
794         break;
795 
796         case RES_LAYOUT_SPLIT:
797         case RES_ROW_SPLIT:
798         {
799             SfxBoolItem* pSplit = PTR_CAST(SfxBoolItem, &rItem);
800             DBG_ASSERT( pSplit != NULL, "Wrong Which-ID" );
801 
802             if( IsXMLToken( rValue, XML_AUTO ) ||
803 			 	IsXMLToken( rValue, XML_TRUE ) )
804             {
805                 pSplit->SetValue( sal_True );
806                 bOk = sal_True;
807             }
808             else if( IsXMLToken( rValue, XML_ALWAYS ) ||
809 				     IsXMLToken( rValue, XML_FALSE ) )
810             {
811                 pSplit->SetValue( sal_False );
812                 bOk = sal_True;
813             }
814         }
815         break;
816 
817         case RES_HORI_ORIENT:
818         {
819             SwFmtHoriOrient* pHoriOrient = PTR_CAST(SwFmtHoriOrient, &rItem);
820             DBG_ASSERT( pHoriOrient != NULL, "Wrong Which-ID" );
821 
822             sal_uInt16 nValue;
823             bOk = rUnitConverter.convertEnum( nValue, rValue,
824                                               aXMLTableAlignMap );
825             if( bOk )
826                 pHoriOrient->SetHoriOrient( nValue );
827         }
828         break;
829 
830         case RES_VERT_ORIENT:
831         {
832             SwFmtVertOrient* pVertOrient = PTR_CAST(SwFmtVertOrient, &rItem);
833             DBG_ASSERT( pVertOrient != NULL, "Wrong Which-ID" );
834 
835             sal_uInt16 nValue;
836             bOk = rUnitConverter.convertEnum( nValue, rValue,
837                                               aXMLTableVAlignMap );
838             if( bOk )
839                 pVertOrient->SetVertOrient( nValue );
840             //#i8855# text::VertOrientation::NONE is stored as empty string and should be applied here
841             else if(!rValue.getLength())
842             {
843                 pVertOrient->SetVertOrient( text::VertOrientation::NONE );
844                 bOk = sal_True;
845             }
846         }
847         break;
848 
849         case RES_FRM_SIZE:
850         {
851             SwFmtFrmSize* pFrmSize = PTR_CAST(SwFmtFrmSize, &rItem);
852             DBG_ASSERT( pFrmSize != NULL, "Wrong Which-ID" );
853 
854             sal_Bool bSetHeight = sal_False;
855             sal_Bool bSetWidth = sal_False;
856             sal_Bool bSetSizeType = sal_False;
857             SwFrmSize eSizeType = ATT_VAR_SIZE;
858             sal_Int32 nMin = MINLAY;
859 
860             switch( nMemberId )
861                 {
862                 case MID_FRMSIZE_REL_WIDTH:
863                 {
864                     sal_Int32 nValue;
865                     bOk = rUnitConverter.convertPercent( nValue, rValue );
866                     if( bOk )
867                     {
868                         if( nValue < 1 )
869                             nValue = 1;
870                         else if( nValue > 100 )
871                             nValue = 100;
872 
873                         pFrmSize->SetWidthPercent( (sal_Int8)nValue );
874                     }
875                 }
876                 break;
877                 case MID_FRMSIZE_WIDTH:
878                     bSetWidth = sal_True;
879                     break;
880                 case MID_FRMSIZE_MIN_HEIGHT:
881                     eSizeType = ATT_MIN_SIZE;
882                     bSetHeight = sal_True;
883                     nMin = 1;
884                     bSetSizeType = sal_True;
885                     break;
886                 case MID_FRMSIZE_FIX_HEIGHT:
887                     eSizeType = ATT_FIX_SIZE;
888                     bSetHeight = sal_True;
889                     nMin = 1;
890                     bSetSizeType = sal_True;
891                     break;
892                 case MID_FRMSIZE_COL_WIDTH:
893                     eSizeType = ATT_FIX_SIZE;
894                     bSetWidth = sal_True;
895                     bSetSizeType = sal_True;
896                     break;
897                 case MID_FRMSIZE_REL_COL_WIDTH:
898                 {
899                     sal_Int32 nPos = rValue.indexOf( (sal_Unicode)'*' );
900                     if( -1L != nPos )
901                     {
902                         OUString sNum( rValue.copy( 0L, nPos ) );
903                         sal_Int32 nValue = rValue.toInt32();
904                         if( nValue < MINLAY )
905                             nValue = MINLAY;
906                         else if( nValue > USHRT_MAX )
907                             nValue = USHRT_MAX;
908 
909                         pFrmSize->SetWidth( (sal_uInt16)nValue );
910                         pFrmSize->SetHeightSizeType( ATT_VAR_SIZE );
911                         bOk = sal_True;
912                     }
913                 }
914                 break;
915                 }
916 
917             sal_Int32 nValue;
918             if( bSetHeight || bSetWidth )
919             {
920                 bOk = rUnitConverter.convertMeasure( nValue, rValue, nMin,
921                                                      USHRT_MAX );
922                 if( bOk )
923                 {
924                     if( bSetWidth )
925                         pFrmSize->SetWidth( (sal_uInt16)nValue );
926                     if( bSetHeight )
927                         pFrmSize->SetHeight( (sal_uInt16)nValue );
928                     if( bSetSizeType )
929                         pFrmSize->SetHeightSizeType( eSizeType );
930                 }
931             }
932         }
933         break;
934 
935         case RES_FRAMEDIR:
936         {
937             const XMLPropertyHandler* pWritingModeHandler =
938                 XMLPropertyHandlerFactory::CreatePropertyHandler(
939                     XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT );
940             if( pWritingModeHandler != NULL )
941             {
942                 Any aAny;
943                 bOk = pWritingModeHandler->importXML( rValue, aAny,
944                                                       rUnitConverter );
945                 if( bOk )
946                     bOk = rItem.PutValue( aAny );
947 
948                 delete pWritingModeHandler;
949             }
950         }
951         break;
952 
953         case RES_COLLAPSING_BORDERS:
954         {
955             SfxBoolItem* pBorders = PTR_CAST(SfxBoolItem, &rItem);
956             DBG_ASSERT( pBorders != NULL, "Wrong Which-ID" );
957 
958             if( IsXMLToken( rValue, XML_COLLAPSING ) )
959             {
960                 pBorders->SetValue( sal_True );
961                 bOk = sal_True;
962             }
963             else if( IsXMLToken( rValue, XML_SEPARATING ) )
964             {
965                 pBorders->SetValue( sal_False );
966                 bOk = sal_True;
967             }
968             else
969                 bOk = sal_False;
970         }
971         break;
972 
973         default:
974             DBG_ERROR("Item not implemented!");
975         break;
976    }
977 
978     return bOk;
979 }
980 
981 
982