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 <DomainMapper_Impl.hxx>
24 #include <ConversionHelper.hxx>
25 #include <DomainMapperTableHandler.hxx>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <com/sun/star/graphic/XGraphic.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/beans/XPropertyState.hpp>
30 #include <com/sun/star/container/XIndexReplace.hpp>
31 #include <com/sun/star/container/XNamed.hpp>
32 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
33 #include <com/sun/star/drawing/XShapes.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
36 #include <com/sun/star/style/LineNumberPosition.hpp>
37 #include <com/sun/star/style/NumberingType.hpp>
38 #include <com/sun/star/drawing/XShape.hpp>
39 #include <com/sun/star/table/BorderLine.hpp>
40 #include <com/sun/star/text/ChapterFormat.hpp>
41 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
42 #include <com/sun/star/text/UserDataPart.hpp>
43 #include <com/sun/star/text/SetVariableType.hpp>
44 #include <com/sun/star/text/XFootnote.hpp>
45 #include <com/sun/star/text/XLineNumberingProperties.hpp>
46 #include <com/sun/star/text/PageNumberType.hpp>
47 #include <com/sun/star/text/RelOrientation.hpp>
48 #include <com/sun/star/text/HoriOrientation.hpp>
49 #include <com/sun/star/text/VertOrientation.hpp>
50 #include <com/sun/star/text/ReferenceFieldPart.hpp>
51 #include <com/sun/star/text/ReferenceFieldSource.hpp>
52 #include <com/sun/star/text/SizeType.hpp>
53 #include <com/sun/star/text/TextContentAnchorType.hpp>
54 #include <com/sun/star/text/WrapTextMode.hpp>
55 #include <com/sun/star/text/XDependentTextField.hpp>
56 #include <com/sun/star/text/XParagraphCursor.hpp>
57 #include <com/sun/star/text/XRedline.hpp>
58 #include <com/sun/star/text/XTextAppendAndConvert.hpp>
59 #include <com/sun/star/text/XTextCopy.hpp>
60 #include <com/sun/star/text/XTextField.hpp>
61 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
62 #include <com/sun/star/style/DropCapFormat.hpp>
63 #include <com/sun/star/util/DateTime.hpp>
64 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
65 #include <com/sun/star/util/XNumberFormats.hpp>
66 #include <rtl/ustrbuf.hxx>
67 #include <rtl/string.h>
68 #include "FieldTypes.hxx"
69 
70 #include <tools/string.hxx>
71 #ifdef DEBUG_DOMAINMAPPER
72 #include <resourcemodel/QNameToString.hxx>
73 #include <resourcemodel/util.hxx>
74 #include <dmapperLoggers.hxx>
75 #endif
76 #include <ooxml/OOXMLFastTokens.hxx>
77 
78 #if DEBUG
79 #include <com/sun/star/lang/XServiceInfo.hpp>
80 #include <com/sun/star/style/TabStop.hpp>
81 #endif
82 
83 #include <map>
84 
85 using namespace ::com::sun::star;
86 using namespace ::rtl;
87 namespace writerfilter {
88 namespace dmapper{
89 struct FieldConversion
90 {
91     ::rtl::OUString     sWordCommand;
92     const sal_Char*     cFieldServiceName;
93     const sal_Char*     cFieldMasterServiceName;
94     FieldId             eFieldId;
95 };
96 
97 typedef ::std::map< ::rtl::OUString, FieldConversion>
98             FieldConversionMap_t;
99 
100 /*-- 18.07.2006 08:56:55---------------------------------------------------
101 
102   -----------------------------------------------------------------------*/
103 sal_Int32 FIB::GetData( Id nName )
104 {
105     if( nName >= NS_rtf::LN_WIDENT && nName <= NS_rtf::LN_LCBSTTBFUSSR)
106         return aFIBData[nName - NS_rtf::LN_WIDENT];
107     OSL_ENSURE( false, "invalid index in FIB");
108     return -1;
109 }
110 /*-- 18.07.2006 08:56:55---------------------------------------------------
111 
112   -----------------------------------------------------------------------*/
113 void FIB::SetData( Id nName, sal_Int32 nValue )
114 {
115     OSL_ENSURE( nName >= NS_rtf::LN_WIDENT && nName <= NS_rtf::LN_LCBSTTBFUSSR, "invalid index in FIB");
116     if( nName >= NS_rtf::LN_WIDENT && nName <= NS_rtf::LN_LCBSTTBFUSSR)
117         aFIBData[nName - NS_rtf::LN_WIDENT] = nValue;
118 }
119 /*-- 01.09.2006 10:22:03---------------------------------------------------
120 
121   -----------------------------------------------------------------------*/
122 DomainMapper_Impl::DomainMapper_Impl(
123     DomainMapper& rDMapper,
124     uno::Reference < uno::XComponentContext >  xContext,
125     uno::Reference< lang::XComponent >  xModel,
126     SourceDocumentType eDocumentType) :
127     m_eDocumentType( eDocumentType ),
128     m_rDMapper( rDMapper ),
129     m_xTextDocument( xModel, uno::UNO_QUERY ),
130     m_xTextFactory( xModel, uno::UNO_QUERY ),
131     m_xComponentContext( xContext ),
132     m_bFieldMode( false ),
133     m_bSetUserFieldContent( false ),
134     m_bIsFirstSection( true ),
135     m_bIsColumnBreakDeferred( false ),
136     m_bIsPageBreakDeferred( false ),
137     m_bIsInShape( false ),
138     m_bShapeContextAdded( false ),
139     m_pLastSectionContext( ),
140     m_nCurrentTabStopIndex( 0 ),
141     m_sCurrentParaStyleId(),
142     m_bInStyleSheetImport( false ),
143     m_bInAnyTableImport( false ),
144     m_bLineNumberingSet( false ),
145     m_bIsInFootnoteProperties( true ),
146     m_bIsCustomFtnMark( false ),
147     m_bIsParaChange( false ),
148     m_bParaChanged( false ),
149     m_bIsLastParaInSection( false ),
150     m_bIsInComments( false )
151     , m_xAnnotationField()
152     , m_nAnnotationId( -1 )
153     , m_aAnnotationPositions()
154 {
155     appendTableManager( );
156     GetBodyText();
157     uno::Reference< text::XTextAppend > xBodyTextAppend = uno::Reference< text::XTextAppend >( m_xBodyText, uno::UNO_QUERY );
158     m_aTextAppendStack.push(xBodyTextAppend);
159 
160     //todo: does it make sense to set the body text as static text interface?
161     uno::Reference< text::XTextAppendAndConvert > xBodyTextAppendAndConvert( m_xBodyText, uno::UNO_QUERY );
162     TableDataHandler_t::Pointer_t pTableHandler
163         (new DomainMapperTableHandler(xBodyTextAppendAndConvert, *this));
164     getTableManager( ).setHandler(pTableHandler);
165 
166     getTableManager( ).startLevel();
167 }
168 /*-- 01.09.2006 10:22:28---------------------------------------------------
169 
170   -----------------------------------------------------------------------*/
171 DomainMapper_Impl::~DomainMapper_Impl()
172 {
173     RemoveLastParagraph( );
174     getTableManager( ).endLevel();
175     popTableManager( );
176 }
177 /*-------------------------------------------------------------------------
178 
179   -----------------------------------------------------------------------*/
180 uno::Reference< container::XNameContainer >    DomainMapper_Impl::GetPageStyles()
181 {
182     if(!m_xPageStyles.is())
183     {
184         uno::Reference< style::XStyleFamiliesSupplier > xSupplier( m_xTextDocument, uno::UNO_QUERY );
185         xSupplier->getStyleFamilies()->getByName(::rtl::OUString::createFromAscii("PageStyles")) >>= m_xPageStyles;
186     }
187     return m_xPageStyles;
188 }
189 /*-------------------------------------------------------------------------
190 
191   -----------------------------------------------------------------------*/
192 uno::Reference< text::XText > DomainMapper_Impl::GetBodyText()
193 {
194     if(!m_xBodyText.is() && m_xTextDocument.is())
195     {
196         m_xBodyText = m_xTextDocument->getText();
197     }
198     return m_xBodyText;
199 }
200 /*-- 21.12.2006 12:09:30---------------------------------------------------
201 
202   -----------------------------------------------------------------------*/
203 uno::Reference< beans::XPropertySet > DomainMapper_Impl::GetDocumentSettings()
204 {
205     if( !m_xDocumentSettings.is() )
206     {
207         m_xDocumentSettings = uno::Reference< beans::XPropertySet >(
208             m_xTextFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.Settings"))), uno::UNO_QUERY );
209     }
210     return m_xDocumentSettings;
211 }
212 /*-- 21.12.2006 12:16:23---------------------------------------------------
213 
214   -----------------------------------------------------------------------*/
215 void DomainMapper_Impl::SetDocumentSettingsProperty( const ::rtl::OUString& rPropName, const uno::Any& rValue )
216 {
217     uno::Reference< beans::XPropertySet > xSettings = GetDocumentSettings();
218     if( xSettings.is() )
219     {
220         try
221         {
222             xSettings->setPropertyValue( rPropName, rValue );
223         }
224         catch( const uno::Exception& )
225         {
226         }
227     }
228 }
229 
230 void DomainMapper_Impl::RemoveLastParagraph( )
231 {
232     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
233     try
234     {
235         uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursor();
236         xCursor->gotoEnd(false);
237         xCursor->goLeft( 1, true );
238         xCursor->setString(::rtl::OUString());
239     }
240     catch( const uno::Exception& rEx)
241     {
242         (void)rEx;
243     }
244 }
245 
246 void DomainMapper_Impl::SetIsLastParagraphInSection( bool bIsLast )
247 {
248     m_bIsLastParaInSection = bIsLast;
249 }
250 
251 /*-------------------------------------------------------------------------
252 
253   -----------------------------------------------------------------------*/
254 void    DomainMapper_Impl::PushProperties(ContextType eId)
255 {
256     SectionPropertyMap* pSectionContext = 0;
257     PropertyMapPtr pInsert(eId == CONTEXT_SECTION ?
258         (pSectionContext = new SectionPropertyMap( m_bIsFirstSection )) :
259         eId == CONTEXT_PARAGRAPH ? new ParagraphPropertyMap :  new PropertyMap);
260     if(eId == CONTEXT_SECTION)
261     {
262         if( m_bIsFirstSection )
263             m_bIsFirstSection = false;
264         // beginning with the second section group a section has to be inserted
265         // into the document
266         SectionPropertyMap* pSectionContext_ = dynamic_cast< SectionPropertyMap* >( pInsert.get() );
267          uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
268          if(xTextAppend.is())
269              pSectionContext_->SetStart( xTextAppend->getEnd() );
270     }
271     m_aPropertyStacks[eId].push( pInsert );
272     m_aContextStack.push(eId);
273 
274     m_pTopContext = m_aPropertyStacks[eId].top();
275 }
276 /*-- 13.06.2007 16:18:18---------------------------------------------------
277 
278   -----------------------------------------------------------------------*/
279 void DomainMapper_Impl::PushStyleProperties( PropertyMapPtr pStyleProperties )
280 {
281     m_aPropertyStacks[CONTEXT_STYLESHEET].push( pStyleProperties );
282     m_aContextStack.push(CONTEXT_STYLESHEET);
283 
284     m_pTopContext = m_aPropertyStacks[CONTEXT_STYLESHEET].top();
285 }
286 /*-- 28.01.2008 14:47:46---------------------------------------------------
287 
288   -----------------------------------------------------------------------*/
289 void DomainMapper_Impl::PushListProperties(PropertyMapPtr pListProperties)
290 {
291     m_aPropertyStacks[CONTEXT_LIST].push( pListProperties );
292     m_aContextStack.push(CONTEXT_LIST);
293     m_pTopContext = m_aPropertyStacks[CONTEXT_LIST].top();
294 }
295 /*-------------------------------------------------------------------------
296 
297   -----------------------------------------------------------------------*/
298 void    DomainMapper_Impl::PopProperties(ContextType eId)
299 {
300     OSL_ENSURE(!m_aPropertyStacks[eId].empty(), "section stack already empty");
301 
302     if ( eId == CONTEXT_SECTION )
303     {
304         m_pLastSectionContext = m_aPropertyStacks[eId].top( );
305     }
306 
307     m_aPropertyStacks[eId].pop();
308     m_aContextStack.pop();
309     if(!m_aContextStack.empty() && !m_aPropertyStacks[m_aContextStack.top()].empty())
310 
311             m_pTopContext = m_aPropertyStacks[m_aContextStack.top()].top();
312     else
313     {
314         // OSL_ENSURE(eId == CONTEXT_SECTION, "this should happen at a section context end");
315         m_pTopContext.reset();
316     }
317 }
318 /*-------------------------------------------------------------------------
319 
320   -----------------------------------------------------------------------*/
321 PropertyMapPtr DomainMapper_Impl::GetTopContextOfType(ContextType eId)
322 {
323     PropertyMapPtr pRet;
324     OSL_ENSURE( !m_aPropertyStacks[eId].empty(),
325             "no context of this type available");
326     if(!m_aPropertyStacks[eId].empty())
327         pRet = m_aPropertyStacks[eId].top();
328     return pRet;
329 }
330 
331 /*-- 24.05.2007 15:54:51---------------------------------------------------
332 
333   -----------------------------------------------------------------------*/
334 uno::Reference< text::XTextAppend >  DomainMapper_Impl::GetTopTextAppend()
335 {
336     OSL_ENSURE(!m_aTextAppendStack.empty(), "text append stack is empty" );
337     return m_aTextAppendStack.top().xTextAppend;
338 }
339 
340 /*-- 17.07.2006 08:47:04---------------------------------------------------
341 
342   -----------------------------------------------------------------------*/
343 void DomainMapper_Impl::InitTabStopFromStyle( const uno::Sequence< style::TabStop >& rInitTabStops )
344 {
345     OSL_ENSURE(!m_aCurrentTabStops.size(), "tab stops already initialized");
346     for( sal_Int32 nTab = 0; nTab < rInitTabStops.getLength(); ++nTab)
347     {
348         m_aCurrentTabStops.push_back( DeletableTabStop(rInitTabStops[nTab]) );
349     }
350 }
351 
352 /*-- 29.06.2006 13:35:33---------------------------------------------------
353 
354   -----------------------------------------------------------------------*/
355 void DomainMapper_Impl::ModifyCurrentTabStop( Id nId, sal_Int32 nValue)
356 {
357     OSL_ENSURE(nId == NS_rtf::LN_dxaAdd || m_nCurrentTabStopIndex < m_aCurrentTabStops.size(),
358         "tab stop creation error");
359 
360     if( nId != NS_rtf::LN_dxaAdd && m_nCurrentTabStopIndex >= m_aCurrentTabStops.size())
361         return;
362     static const style::TabAlign aTabAlignFromWord[] =
363     {
364         style::TabAlign_LEFT,
365         style::TabAlign_CENTER,
366         style::TabAlign_RIGHT,
367         style::TabAlign_DECIMAL,
368         style::TabAlign_LEFT
369     };
370     static const sal_Unicode aTabFillCharWord[] =
371     {
372         ' ',
373         '.',
374         '-',
375         '_',
376         '_',
377         0xb7
378     };
379 
380     switch(nId)
381     {
382         case NS_rtf::LN_dxaAdd: //set tab
383             m_aCurrentTabStops.push_back(
384                     DeletableTabStop(style::TabStop(ConversionHelper::convertTwipToMM100(nValue), style::TabAlign_LEFT, ' ', ' ')));
385         break;
386         case NS_rtf::LN_dxaDel: //deleted tab
387         {
388             //mark the tab stop at the given position as deleted
389             ::std::vector<DeletableTabStop>::iterator aIt = m_aCurrentTabStops.begin();
390             ::std::vector<DeletableTabStop>::iterator aEndIt = m_aCurrentTabStops.end();
391             sal_Int32 nConverted = ConversionHelper::convertTwipToMM100(nValue);
392             for( ; aIt != aEndIt; ++aIt)
393             {
394                 if( aIt->Position == nConverted )
395                 {
396                     aIt->bDeleted = true;
397                     break;
398                 }
399             }
400         }
401         break;
402         case NS_rtf::LN_TLC: //tab leading characters - for decimal tabs
403             // 0 - no leader, 1- dotted, 2 - hyphenated, 3 - single line, 4 - heavy line, 5 - middle dot
404             if( nValue >= 0 &&  nValue < sal::static_int_cast<sal_Int32>(sizeof(aTabFillCharWord) / sizeof (sal_Unicode)))
405                 m_aCurrentTabStops[m_nCurrentTabStopIndex].FillChar = aTabFillCharWord[nValue];
406         break;
407         case NS_rtf::LN_JC: //tab justification
408             //0 - left, 1 - centered, 2 - right, 3 - decimal 4 - bar
409             if( nValue >= 0 && nValue < sal::static_int_cast<sal_Int32>(sizeof(aTabAlignFromWord) / sizeof (style::TabAlign)))
410                 m_aCurrentTabStops[m_nCurrentTabStopIndex].Alignment = aTabAlignFromWord[nValue];
411         break;
412     }
413 }
414 
415 void DomainMapper_Impl::IncorporateTabStop( const DeletableTabStop &  rTabStop )
416 {
417     ::std::vector<DeletableTabStop>::iterator aIt = m_aCurrentTabStops.begin();
418     ::std::vector<DeletableTabStop>::iterator aEndIt = m_aCurrentTabStops.end();
419     sal_Int32 nConverted = rTabStop.Position;
420     bool bFound = false;
421     for( ; aIt != aEndIt; ++aIt)
422     {
423         if( aIt->Position == nConverted )
424         {
425             bFound = true;
426             if( rTabStop.bDeleted )
427                 m_aCurrentTabStops.erase( aIt );
428             else
429                 *aIt = rTabStop;
430             break;
431         }
432     }
433     if( !bFound )
434         m_aCurrentTabStops.push_back( rTabStop );
435 }
436 /*-- 29.06.2006 13:35:33---------------------------------------------------
437 
438   -----------------------------------------------------------------------*/
439 uno::Sequence< style::TabStop > DomainMapper_Impl::GetCurrentTabStopAndClear()
440 {
441     uno::Sequence< style::TabStop > aRet( sal_Int32( m_aCurrentTabStops.size() ) );
442     style::TabStop* pArray = aRet.getArray();
443     ::std::vector<DeletableTabStop>::const_iterator aIt = m_aCurrentTabStops.begin();
444     ::std::vector<DeletableTabStop>::const_iterator aEndIt = m_aCurrentTabStops.end();
445     sal_Int32 nDeleted = 0;
446     for(sal_Int32 nIndex = 0; aIt != aEndIt; ++aIt)
447     {
448         if(!aIt->bDeleted)
449             pArray[nIndex++] = *aIt;
450         else
451             ++nDeleted;
452     }
453     m_aCurrentTabStops.clear();
454     m_nCurrentTabStopIndex = 0;
455     if(nDeleted)
456     {
457         aRet.realloc( aRet.getLength() - nDeleted);
458     }
459     return aRet;
460 }
461 
462 /*-- 17.07.2006 09:08:26---------------------------------------------------
463     returns a the value from the current paragraph style - if available
464     TODO: What about parent styles?
465   -----------------------------------------------------------------------*/
466 uno::Any DomainMapper_Impl::GetPropertyFromStyleSheet(PropertyIds eId)
467 {
468     StyleSheetEntryPtr pEntry;
469     if( m_bInStyleSheetImport )
470         pEntry = GetStyleSheetTable()->FindParentStyleSheet(::rtl::OUString());
471     else
472         pEntry =
473                 GetStyleSheetTable()->FindStyleSheetByISTD(GetCurrentParaStyleId());
474     while(pEntry.get( ) )
475     {
476         //is there a tab stop set?
477         if(pEntry->pProperties)
478         {
479             PropertyMap::const_iterator aPropertyIter =
480                     pEntry->pProperties->find(PropertyDefinition(eId, false ));
481             if( aPropertyIter != pEntry->pProperties->end())
482             {
483                 return aPropertyIter->second;
484             }
485         }
486         //search until the property is set or no parent is available
487         pEntry = GetStyleSheetTable()->FindParentStyleSheet(pEntry->sBaseStyleIdentifier);
488     }
489     return uno::Any();
490 }
491 /*-------------------------------------------------------------------------
492 
493   -----------------------------------------------------------------------*/
494 ListsManager::Pointer DomainMapper_Impl::GetListTable()
495 {
496     if(!m_pListTable)
497         m_pListTable.reset(
498             new ListsManager( m_rDMapper, m_xTextFactory ));
499     return m_pListTable;
500 }
501 
502 
503 void DomainMapper_Impl::deferBreak( BreakType deferredBreakType)
504 {
505     switch (deferredBreakType)
506     {
507     case COLUMN_BREAK:
508             m_bIsColumnBreakDeferred = true;
509         break;
510     case PAGE_BREAK:
511             m_bIsPageBreakDeferred = true;
512         break;
513     default:
514         return;
515     }
516 }
517 
518 bool DomainMapper_Impl::isBreakDeferred( BreakType deferredBreakType )
519 {
520     switch (deferredBreakType)
521     {
522     case COLUMN_BREAK:
523     	return m_bIsColumnBreakDeferred;
524     case PAGE_BREAK:
525         return m_bIsPageBreakDeferred;
526     default:
527         return false;
528     }
529 }
530 
531 void DomainMapper_Impl::clearDeferredBreaks()
532 {
533     m_bIsColumnBreakDeferred = false;
534     m_bIsPageBreakDeferred = false;
535 }
536 /*-------------------------------------------------------------------------
537 
538   -----------------------------------------------------------------------*/
539 void lcl_MoveBorderPropertiesToFrame(uno::Sequence<beans::PropertyValue>& rFrameProperties,
540     uno::Reference<text::XTextRange> xStartTextRange,
541     uno::Reference<text::XTextRange> xEndTextRange )
542 {
543     try
544     {
545         uno::Reference<text::XTextCursor> xRangeCursor = xStartTextRange->getText()->createTextCursorByRange( xStartTextRange );
546         xRangeCursor->gotoRange( xEndTextRange, true );
547 
548         uno::Reference<beans::XPropertySet> xTextRangeProperties(xRangeCursor, uno::UNO_QUERY);
549         if(!xTextRangeProperties.is())
550             return ;
551 
552         PropertyIds aBorderProperties[] =
553         {
554             PROP_LEFT_BORDER,
555             PROP_RIGHT_BORDER,
556             PROP_TOP_BORDER,
557             PROP_BOTTOM_BORDER,
558             PROP_LEFT_BORDER_DISTANCE,
559             PROP_RIGHT_BORDER_DISTANCE,
560             PROP_TOP_BORDER_DISTANCE,
561             PROP_BOTTOM_BORDER_DISTANCE
562         };
563 
564         sal_uInt32 nStart = rFrameProperties.getLength();
565         sal_uInt32 nBorderPropertyCount = sizeof( aBorderProperties ) / sizeof(PropertyIds);
566         rFrameProperties.realloc(nStart + nBorderPropertyCount);
567 
568         beans::PropertyValue* pFrameProperties = rFrameProperties.getArray();
569         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
570         for( sal_uInt32 nProperty = 0; nProperty < nBorderPropertyCount; ++nProperty)
571         {
572             ::rtl::OUString sPropertyName = rPropNameSupplier.GetName(aBorderProperties[nProperty]);
573             pFrameProperties[nStart].Name = sPropertyName;
574             pFrameProperties[nStart].Value = xTextRangeProperties->getPropertyValue(sPropertyName);
575             if( nProperty < 4 )
576                 xTextRangeProperties->setPropertyValue( sPropertyName, uno::makeAny(table::BorderLine()));
577             ++nStart;
578         }
579         rFrameProperties.realloc(nStart);
580     }
581     catch( const uno::Exception& rEx )
582    {
583         (void)rEx;
584    }
585 }
586 /*-- 04.01.2008 10:59:19---------------------------------------------------
587 
588   -----------------------------------------------------------------------*/
589 void lcl_AddRangeAndStyle(
590     ParagraphPropertiesPtr& pToBeSavedProperties,
591     uno::Reference< text::XTextAppend > xTextAppend,
592     PropertyMapPtr pPropertyMap)
593 {
594     uno::Reference<text::XParagraphCursor> xParaCursor(
595         xTextAppend->createTextCursorByRange( xTextAppend->getEnd()), uno::UNO_QUERY_THROW );
596     pToBeSavedProperties->SetEndingRange(xParaCursor->getStart());
597     xParaCursor->gotoStartOfParagraph( false );
598 
599     pToBeSavedProperties->SetStartingRange(xParaCursor->getStart());
600     if(pPropertyMap)
601     {
602         PropertyMap::iterator aParaStyleIter = pPropertyMap->find(PropertyDefinition( PROP_PARA_STYLE_NAME, false ) );
603         if( aParaStyleIter != pPropertyMap->end())
604         {
605             ::rtl::OUString sName;
606             aParaStyleIter->second >>= sName;
607             pToBeSavedProperties->SetParaStyleName(sName);
608         }
609     }
610 }
611 /*-------------------------------------------------------------------------
612 
613   -----------------------------------------------------------------------*/
614 //define some default frame width - 0cm ATM: this allow the frame to be wrapped around the text
615 #define DEFAULT_FRAME_MIN_WIDTH 0
616 
617 void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap )
618 {
619 #ifdef DEBUG_DOMAINMAPPER
620     dmapper_logger->startElement("finishParagraph");
621 #endif
622 
623     ParagraphPropertyMap* pParaContext = dynamic_cast< ParagraphPropertyMap* >( pPropertyMap.get() );
624     TextAppendContext& rAppendContext = m_aTextAppendStack.top();
625     uno::Reference< text::XTextAppend >  xTextAppend = rAppendContext.xTextAppend;
626     PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
627 
628 #ifdef DEBUG_DOMAINMAPPER
629     dmapper_logger->attribute("isTextAppend", xTextAppend.is());
630 #endif
631 
632     if(xTextAppend.is() && ! getTableManager( ).isIgnore() && pParaContext != NULL)
633     {
634         try
635         {
636             /*the following combinations of previous and current frame settings can occur:
637                 (1) - no old frame and no current frame     -> no special action
638                 (2) - no old frame and current DropCap      -> save DropCap for later use, don't call finishParagraph
639                                                             remove character properties of the DropCap?
640                 (3) - no old frame and current Frame        -> save Frame for later use
641                 (4) - old DropCap and no current frame      -> add DropCap to the properties of the finished paragraph, delete previous setting
642                 (5) - old DropCap and current frame         -> add DropCap to the properties of the finished paragraph, save current frame settings
643                 (6) - old Frame and new DropCap             -> add old Frame, save DropCap for later use
644                 (7) - old Frame and new same Frame          -> continue
645                 (8) - old Frame and new different Frame     -> add old Frame, save new Frame for later use
646                 (9) - old Frame and no current frame        -> add old Frame, delete previous settings
647 
648               old _and_ new DropCap must not occur
649              */
650 
651             bool bIsDropCap =
652                 pParaContext->IsFrameMode() &&
653                 sal::static_int_cast<Id>(pParaContext->GetDropCap()) != NS_ooxml::LN_Value_wordprocessingml_ST_DropCap_none;
654 
655             style::DropCapFormat aDrop;
656             ParagraphPropertiesPtr pToBeSavedProperties;
657             bool bKeepLastParagraphProperties = false;
658             if( bIsDropCap )
659             {
660                 uno::Reference<text::XParagraphCursor> xParaCursor(
661                     xTextAppend->createTextCursorByRange(xTextAppend->getEnd()), uno::UNO_QUERY_THROW);
662                 //select paragraph
663                 xParaCursor->gotoStartOfParagraph( true );
664                 uno::Reference< beans::XPropertyState > xParaProperties( xParaCursor, uno::UNO_QUERY_THROW );
665                 xParaProperties->setPropertyToDefault(rPropNameSupplier.GetName(PROP_CHAR_ESCAPEMENT));
666                 xParaProperties->setPropertyToDefault(rPropNameSupplier.GetName(PROP_CHAR_HEIGHT));
667                 //handles (2) and part of (6)
668                 pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
669                 sal_Int32 nCount = xParaCursor->getString().getLength();
670                 pToBeSavedProperties->SetDropCapLength(nCount > 0 && nCount < 255 ? (sal_Int8)nCount : 1);
671             }
672             if( rAppendContext.pLastParagraphProperties.get() )
673             {
674                 if( sal::static_int_cast<Id>(rAppendContext.pLastParagraphProperties->GetDropCap()) != NS_ooxml::LN_Value_wordprocessingml_ST_DropCap_none)
675                 {
676                     //handles (4) and part of (5)
677                     //create a DropCap property, add it to the property sequence of finishParagraph
678                     sal_Int32 nLines = rAppendContext.pLastParagraphProperties->GetLines();
679                     aDrop.Lines = nLines > 0 && nLines < 254 ? (sal_Int8)++nLines : 2;
680                     aDrop.Count = rAppendContext.pLastParagraphProperties->GetDropCapLength();
681                     aDrop.Distance  = 0; //TODO: find distance value
682                     //completes (5)
683                     if( pParaContext->IsFrameMode() )
684                         pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
685                 }
686                 else if(*rAppendContext.pLastParagraphProperties == *pParaContext )
687                 {
688                     //handles (7)
689                     rAppendContext.pLastParagraphProperties->SetEndingRange(xTextAppend->getEnd());
690                     bKeepLastParagraphProperties = true;
691                 }
692                 else
693                 {
694                     //handles (8)(9) and completes (6)
695                     try
696                        {
697                             //
698                             StyleSheetEntryPtr pParaStyle =
699                                 m_pStyleSheetTable->FindStyleSheetByConvertedStyleName(rAppendContext.pLastParagraphProperties->GetParaStyleName());
700 
701                             uno::Sequence< beans::PropertyValue > aFrameProperties(pParaStyle ? 15: 0);
702                             if ( pParaStyle.get( ) )
703                             {
704                                 const ParagraphProperties* pStyleProperties = dynamic_cast<const ParagraphProperties*>( pParaStyle->pProperties.get() );
705                                 beans::PropertyValue* pFrameProperties = aFrameProperties.getArray();
706                                 pFrameProperties[0].Name = rPropNameSupplier.GetName(PROP_WIDTH);
707                                 pFrameProperties[1].Name = rPropNameSupplier.GetName(PROP_HEIGHT);
708                                 pFrameProperties[2].Name = rPropNameSupplier.GetName(PROP_SIZE_TYPE);
709                                 pFrameProperties[3].Name = rPropNameSupplier.GetName(PROP_WIDTH_TYPE);
710                                 pFrameProperties[4].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT);
711                                 pFrameProperties[5].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_POSITION);
712                                 pFrameProperties[6].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_RELATION);
713                                 pFrameProperties[7].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT);
714                                 pFrameProperties[8].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_POSITION);
715                                 pFrameProperties[9].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_RELATION);
716                                 pFrameProperties[10].Name = rPropNameSupplier.GetName(PROP_SURROUND);
717                                 pFrameProperties[11].Name = rPropNameSupplier.GetName(PROP_LEFT_MARGIN);
718                                 pFrameProperties[12].Name = rPropNameSupplier.GetName(PROP_RIGHT_MARGIN);
719                                 pFrameProperties[13].Name = rPropNameSupplier.GetName(PROP_TOP_MARGIN);
720                                 pFrameProperties[14].Name = rPropNameSupplier.GetName(PROP_BOTTOM_MARGIN);
721                                 sal_Int32 nWidth =
722                                     rAppendContext.pLastParagraphProperties->Getw() > 0 ?
723                                         rAppendContext.pLastParagraphProperties->Getw() :
724                                         pStyleProperties->Getw();
725                                 bool bAutoWidth = nWidth < 1;
726                                 if( bAutoWidth )
727                                     nWidth = DEFAULT_FRAME_MIN_WIDTH;
728                                 pFrameProperties[0].Value <<= nWidth;
729                                 pFrameProperties[1].Value <<=
730                                     rAppendContext.pLastParagraphProperties->Geth() > 0 ?
731                                         rAppendContext.pLastParagraphProperties->Geth() :
732                                         pStyleProperties->Geth();
733                                 pFrameProperties[2].Value <<= sal_Int16(
734                                     rAppendContext.pLastParagraphProperties->GethRule() >= 0 ?
735                                         rAppendContext.pLastParagraphProperties->GethRule() :
736                                 pStyleProperties->GethRule() >=0 ? pStyleProperties->GethRule() : text::SizeType::VARIABLE);
737 
738                                 pFrameProperties[3].Value <<= bAutoWidth ?  text::SizeType::MIN : text::SizeType::FIX;
739 
740                                 sal_Int16 nHoriOrient = sal_Int16(
741                                     rAppendContext.pLastParagraphProperties->GetxAlign() >= 0 ?
742                                         rAppendContext.pLastParagraphProperties->GetxAlign() :
743                                         pStyleProperties->GetxAlign() >= 0 ? pStyleProperties->GetxAlign() : text::HoriOrientation::NONE );
744                                 pFrameProperties[4].Value <<= nHoriOrient;
745 
746                                 pFrameProperties[5].Value <<=
747                                     rAppendContext.pLastParagraphProperties->IsxValid() ?
748                                         rAppendContext.pLastParagraphProperties->Getx() : pStyleProperties->Getx();
749                                 pFrameProperties[6].Value <<= sal_Int16(
750                                     rAppendContext.pLastParagraphProperties->GethAnchor() >= 0 ?
751                                         rAppendContext.pLastParagraphProperties->GethAnchor() :
752                                     pStyleProperties->GethAnchor() );
753 
754                                 sal_Int16 nVertOrient = sal_Int16(
755                                     rAppendContext.pLastParagraphProperties->GetyAlign() >= 0 ?
756                                         rAppendContext.pLastParagraphProperties->GetyAlign() :
757                                         pStyleProperties->GetyAlign() >= 0 ? pStyleProperties->GetyAlign() : text::VertOrientation::NONE );
758                                 pFrameProperties[7].Value <<= nVertOrient;
759 
760                                 pFrameProperties[8].Value <<=
761                                     rAppendContext.pLastParagraphProperties->IsyValid() ?
762                                         rAppendContext.pLastParagraphProperties->Gety() : pStyleProperties->Gety();
763                                 pFrameProperties[9].Value <<= sal_Int16(
764                                     rAppendContext.pLastParagraphProperties->GetvAnchor() >= 0 ?
765                                         rAppendContext.pLastParagraphProperties->GetvAnchor() :
766                                         pStyleProperties->GetvAnchor() );
767 
768                                 pFrameProperties[10].Value <<= text::WrapTextMode(
769                                     rAppendContext.pLastParagraphProperties->GetWrap() >= 0 ?
770                                     rAppendContext.pLastParagraphProperties->GetWrap() :
771                                     pStyleProperties->GetWrap());
772 
773                                 sal_Int32 nBottomDist;
774                                 sal_Int32 nTopDist = nBottomDist =
775                                     rAppendContext.pLastParagraphProperties->GethSpace() >= 0 ?
776                                     rAppendContext.pLastParagraphProperties->GethSpace() :
777                                     pStyleProperties->GethSpace();
778 
779                                 pFrameProperties[11].Value <<= nVertOrient == text::VertOrientation::TOP ? 0 : nTopDist;
780                                 pFrameProperties[12].Value <<= nVertOrient == text::VertOrientation::BOTTOM ? 0 : nBottomDist;
781 
782                                 sal_Int32 nRightDist;
783                                 sal_Int32 nLeftDist = nRightDist =
784                                     rAppendContext.pLastParagraphProperties->GetvSpace() >= 0 ?
785                                     rAppendContext.pLastParagraphProperties->GetvSpace() :
786                                 pStyleProperties->GetvSpace() >= 0 ? pStyleProperties->GetvSpace() : 0;
787                                 pFrameProperties[13].Value <<= nHoriOrient == text::HoriOrientation::LEFT ? 0 : nLeftDist;
788                                 pFrameProperties[14].Value <<= nHoriOrient == text::HoriOrientation::RIGHT ? 0 : nRightDist;
789 
790                                 lcl_MoveBorderPropertiesToFrame(aFrameProperties,
791                                     rAppendContext.pLastParagraphProperties->GetStartingRange(),
792                                     rAppendContext.pLastParagraphProperties->GetEndingRange());
793                             }
794                             //frame conversion has to be executed after table conversion
795                             RegisterFrameConversion(
796                             rAppendContext.pLastParagraphProperties->GetStartingRange(),
797                             rAppendContext.pLastParagraphProperties->GetEndingRange(),
798                             aFrameProperties );
799                             // next frame follows directly
800                             if( pParaContext->IsFrameMode() )
801                             {
802                                 pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
803                                 lcl_AddRangeAndStyle(pToBeSavedProperties, xTextAppend, pPropertyMap);
804                             }
805                        }
806                        catch( const uno::Exception& rEx )
807                        {
808                             (void)rEx;
809                        }
810                 }
811 
812             }
813             else //
814             {
815                 // (1) doesn't need handling
816                 //
817                 if( !bIsDropCap && pParaContext->IsFrameMode() )
818                 {
819                     pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
820                     lcl_AddRangeAndStyle(pToBeSavedProperties, xTextAppend, pPropertyMap);
821                 }
822             }
823             uno::Sequence< beans::PropertyValue > aProperties;
824             if( pPropertyMap.get() )
825             {
826                 aProperties = pPropertyMap->GetPropertyValues();
827             }
828             if( !bIsDropCap )
829             {
830                 if( aDrop.Lines > 1 )
831                 {
832                     sal_uInt32 nLength = aProperties.getLength();
833                     aProperties.realloc(  nLength + 1 );
834                     aProperties[nLength].Value <<= aDrop;
835                     aProperties[nLength].Name = rPropNameSupplier.GetName(PROP_DROP_CAP_FORMAT);
836                 }
837                 uno::Reference< text::XTextRange > xTextRange =
838                     xTextAppend->finishParagraph( aProperties );
839                 getTableManager( ).handle(xTextRange);
840 
841                 // Set the anchor of the objects to the created paragraph
842                 while ( m_aAnchoredStack.size( ) > 0 && !m_bIsInShape )
843                 {
844                     uno::Reference< text::XTextContent > xObj = m_aAnchoredStack.top( );
845                     try
846                     {
847 #if DEBUG
848                         rtl::OUString sText( xTextRange->getString( ) );
849 #endif
850                         xObj->attach( xTextRange );
851                     }
852                     catch ( uno::RuntimeException& )
853                     {
854                         // this is normal: the shape is already attached
855                     }
856                     m_aAnchoredStack.pop( );
857                 }
858 
859                 // Get the end of paragraph character inserted
860                 uno::Reference< text::XTextCursor > xCur = xTextRange->getText( )->createTextCursor( );
861                 xCur->gotoEnd( false );
862                 xCur->goLeft( 1 , true );
863                 uno::Reference< text::XTextRange > xParaEnd( xCur, uno::UNO_QUERY );
864                 CheckParaRedline( xParaEnd );
865 
866                 // Remove the last empty section paragraph if needed
867                 if ( m_bIsLastParaInSection && !m_bParaChanged )
868                 {
869                     RemoveLastParagraph( );
870                     m_bIsLastParaInSection = false;
871                 }
872 
873                 m_bParaChanged = false;
874             }
875             if( !bKeepLastParagraphProperties )
876                 rAppendContext.pLastParagraphProperties = pToBeSavedProperties;
877         }
878         catch(const lang::IllegalArgumentException& rIllegal)
879         {
880             (void)rIllegal;
881             OSL_ENSURE( false, "IllegalArgumentException in DomainMapper_Impl::finishParagraph" );
882         }
883         catch(const uno::Exception& rEx)
884         {
885             (void)rEx;
886             //OSL_ENSURE( false, "ArgumentException in DomainMapper_Impl::finishParagraph" );
887         }
888     }
889 
890 #ifdef DEBUG_DOMAINMAPPER
891     dmapper_logger->endElement("finishParagraph");
892 #endif
893 }
894 /*-------------------------------------------------------------------------
895 
896   -----------------------------------------------------------------------*/
897 util::DateTime lcl_DateStringToDateTime( const ::rtl::OUString& rDateTime )
898 {
899     util::DateTime aDateTime;
900     //xsd::DateTime in the format [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm] example: 2008-01-21T10:42:00Z
901     //OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(())
902     sal_Int32 nIndex = 0;
903     ::rtl::OUString sDate = rDateTime.getToken( 0, 'T', nIndex );
904     ::rtl::OUString sTime = rDateTime.getToken( 0, 'Z', nIndex );
905     nIndex = 0;
906     aDateTime.Year = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() );
907     aDateTime.Month = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() );
908     aDateTime.Day = sal_uInt16( sDate.copy( nIndex ).toInt32() );
909 
910     nIndex = 0;
911     aDateTime.Hours = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() );
912     aDateTime.Minutes = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() );
913     aDateTime.Seconds = sal_uInt16( sTime.copy( nIndex ).toInt32() );
914 
915     return aDateTime;
916 }
917 void DomainMapper_Impl::appendTextPortion( const ::rtl::OUString& rString, PropertyMapPtr pPropertyMap )
918 {
919     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
920     if(xTextAppend.is() && ! getTableManager( ).isIgnore())
921     {
922         try
923         {
924             uno::Reference< text::XTextRange > xTextRange =
925                 xTextAppend->appendTextPortion
926                 (rString, pPropertyMap->GetPropertyValues());
927             CheckRedline( xTextRange );
928             m_bParaChanged = true;
929 
930             //getTableManager( ).handle(xTextRange);
931         }
932         catch(const lang::IllegalArgumentException& rEx)
933         {
934             (void)rEx;
935             OSL_ENSURE( false, "IllegalArgumentException in DomainMapper_Impl::appendTextPortion" );
936         }
937         catch(const uno::Exception& rEx)
938         {
939             (void)rEx;
940             OSL_ENSURE( false, "Exception in DomainMapper_Impl::appendTextPortion" );
941         }
942     }
943 }
944 /*-- 02.11.2006 12:08:33---------------------------------------------------
945 
946   -----------------------------------------------------------------------*/
947 void DomainMapper_Impl::appendTextContent(
948     const uno::Reference< text::XTextContent > xContent,
949     const uno::Sequence< beans::PropertyValue > xPropertyValues
950     )
951 {
952     uno::Reference< text::XTextAppendAndConvert >  xTextAppendAndConvert( m_aTextAppendStack.top().xTextAppend, uno::UNO_QUERY );
953     OSL_ENSURE( xTextAppendAndConvert.is(), "trying to append a text content without XTextAppendAndConvert" );
954     if(xTextAppendAndConvert.is() && ! getTableManager( ).isIgnore())
955     {
956         try
957         {
958             xTextAppendAndConvert->appendTextContent( xContent, xPropertyValues );
959         }
960         catch(const lang::IllegalArgumentException& )
961         {
962         }
963         catch(const uno::Exception& )
964         {
965         }
966     }
967 }
968 
969 /*-- 24.04.2008 08:38:07---------------------------------------------------
970 
971   -----------------------------------------------------------------------*/
972 void DomainMapper_Impl::appendOLE( const ::rtl::OUString& rStreamName, OLEHandlerPtr pOLEHandler )
973 {
974     static const rtl::OUString sEmbeddedService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextEmbeddedObject"));
975     try
976     {
977         uno::Reference< text::XTextContent > xOLE( m_xTextFactory->createInstance(sEmbeddedService), uno::UNO_QUERY_THROW );
978         uno::Reference< beans::XPropertySet > xOLEProperties(xOLE, uno::UNO_QUERY_THROW);
979 
980         xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_STREAM_NAME ),
981                         uno::makeAny( rStreamName ));
982         awt::Size aSize = pOLEHandler->getSize();
983         if( !aSize.Width )
984             aSize.Width = 1000;
985         if( !aSize.Height )
986             aSize.Height = 1000;
987         xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_WIDTH ),
988                         uno::makeAny(aSize.Width));
989         xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_HEIGHT ),
990                         uno::makeAny(aSize.Height));
991 
992         uno::Reference< graphic::XGraphic > xGraphic = pOLEHandler->getReplacement();
993         xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_GRAPHIC ),
994                         uno::makeAny(xGraphic));
995 
996         //
997         appendTextContent( xOLE, uno::Sequence< beans::PropertyValue >() );
998 
999     }
1000     catch( const uno::Exception& rEx )
1001     {
1002         (void)rEx;
1003         OSL_ENSURE( false, "Exception in creation of OLE object" );
1004     }
1005 
1006 }
1007 /*-- 14.12.2006 12:26:00---------------------------------------------------
1008 
1009   -----------------------------------------------------------------------*/
1010 uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter(
1011                                     uno::Reference< text::XTextRange >& xBefore )
1012 {
1013     uno::Reference< beans::XPropertySet > xRet;
1014     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
1015     if(xTextAppend.is())
1016     {
1017         try
1018         {
1019             uno::Reference< text::XParagraphCursor > xCursor(
1020                 xTextAppend->createTextCursorByRange( xBefore ), uno::UNO_QUERY_THROW);
1021             //the cursor has been moved to the end of the paragraph because of the appendTextPortion() calls
1022             xCursor->gotoStartOfParagraph( false );
1023             xCursor->gotoEnd( true );
1024             //the paragraph after this new section is already inserted
1025             xCursor->goLeft(1, true);
1026             static const rtl::OUString sSectionService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextSection"));
1027             uno::Reference< text::XTextContent > xSection( m_xTextFactory->createInstance(sSectionService), uno::UNO_QUERY_THROW );
1028             xSection->attach( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW) );
1029             xRet = uno::Reference< beans::XPropertySet > (xSection, uno::UNO_QUERY );
1030         }
1031         catch(const uno::Exception& )
1032         {
1033         }
1034 
1035     }
1036 
1037     return xRet;
1038 }
1039 /*-- 02.11.2006 12:08:33---------------------------------------------------
1040 
1041   -----------------------------------------------------------------------*/
1042 void DomainMapper_Impl::PushPageHeader(SectionPropertyMap::PageType eType)
1043 {
1044     //get the section context
1045     PropertyMapPtr pContext = DomainMapper_Impl::GetTopContextOfType(CONTEXT_SECTION);
1046     //ask for the header name of the given type
1047     SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() );
1048     if(pSectionContext)
1049     {
1050         uno::Reference< beans::XPropertySet > xPageStyle =
1051             pSectionContext->GetPageStyle(
1052                 GetPageStyles(),
1053                 m_xTextFactory,
1054                 eType == SectionPropertyMap::PAGE_FIRST );
1055         try
1056         {
1057             PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1058             //switch on header use
1059             xPageStyle->setPropertyValue(
1060                     rPropNameSupplier.GetName(PROP_HEADER_IS_ON),
1061                     uno::makeAny(sal_True) );
1062             // if a left header is available then header are not shared
1063             bool bLeft = eType == SectionPropertyMap::PAGE_LEFT;
1064             if( bLeft )
1065                 xPageStyle->setPropertyValue(rPropNameSupplier.GetName(PROP_HEADER_IS_SHARED), uno::makeAny( false ));
1066 
1067             //set the interface
1068             uno::Reference< text::XText > xHeaderText;
1069             xPageStyle->getPropertyValue(rPropNameSupplier.GetName( bLeft ? PROP_HEADER_TEXT_LEFT : PROP_HEADER_TEXT) ) >>= xHeaderText;
1070             m_aTextAppendStack.push( uno::Reference< text::XTextAppend >( xHeaderText, uno::UNO_QUERY_THROW));
1071         }
1072         catch( uno::Exception& )
1073         {
1074         }
1075     }
1076 }
1077 /*-- 24.07.2006 09:41:20---------------------------------------------------
1078 
1079   -----------------------------------------------------------------------*/
1080 void DomainMapper_Impl::PushPageFooter(SectionPropertyMap::PageType eType)
1081 {
1082     //get the section context
1083     PropertyMapPtr pContext = DomainMapper_Impl::GetTopContextOfType(CONTEXT_SECTION);
1084     //ask for the footer name of the given type
1085     SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() );
1086     if(pSectionContext)
1087     {
1088         uno::Reference< beans::XPropertySet > xPageStyle =
1089                 pSectionContext->GetPageStyle(
1090                     GetPageStyles(),
1091                     m_xTextFactory,
1092                     eType == SectionPropertyMap::PAGE_FIRST );
1093         try
1094         {
1095             PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1096             //switch on footer use
1097             xPageStyle->setPropertyValue(
1098                     rPropNameSupplier.GetName(PROP_FOOTER_IS_ON),
1099                     uno::makeAny(sal_True) );
1100             // if a left header is available then footer is not shared
1101             bool bLeft = eType == SectionPropertyMap::PAGE_LEFT;
1102             if( bLeft )
1103                 xPageStyle->setPropertyValue(rPropNameSupplier.GetName(PROP_FOOTER_IS_SHARED), uno::makeAny( false ));
1104             //set the interface
1105             uno::Reference< text::XText > xFooterText;
1106             xPageStyle->getPropertyValue(rPropNameSupplier.GetName( bLeft ? PROP_FOOTER_TEXT_LEFT : PROP_FOOTER_TEXT) ) >>= xFooterText;
1107             m_aTextAppendStack.push(uno::Reference< text::XTextAppend >( xFooterText, uno::UNO_QUERY_THROW ));
1108         }
1109         catch( uno::Exception& )
1110         {
1111         }
1112     }
1113 }
1114 /*-- 24.07.2006 09:41:20---------------------------------------------------
1115 
1116   -----------------------------------------------------------------------*/
1117 void DomainMapper_Impl::PopPageHeaderFooter()
1118 {
1119     //header and footer always have an empty paragraph at the end
1120     //this has to be removed
1121     RemoveLastParagraph( );
1122     m_aTextAppendStack.pop();
1123 }
1124 /*-- 24.05.2007 14:22:28---------------------------------------------------
1125 
1126   -----------------------------------------------------------------------*/
1127 void DomainMapper_Impl::PushFootOrEndnote( bool bIsFootnote )
1128 {
1129     try
1130     {
1131         PropertyMapPtr pTopContext = GetTopContext();
1132         uno::Reference< text::XText > xFootnoteText( GetTextFactory()->createInstance(
1133             bIsFootnote ?
1134                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Footnote") ) : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Endnote") )),
1135             uno::UNO_QUERY_THROW );
1136         uno::Reference< text::XFootnote > xFootnote( xFootnoteText, uno::UNO_QUERY_THROW );
1137         pTopContext->SetFootnote( xFootnote );
1138         if( pTopContext->GetFootnoteSymbol() != 0)
1139         {
1140             xFootnote->setLabel( ::rtl::OUString( pTopContext->GetFootnoteSymbol() ) );
1141         }
1142         FontTablePtr pFontTable = GetFontTable();
1143         uno::Sequence< beans::PropertyValue > aFontProperties;
1144         if( pFontTable && pTopContext->GetFootnoteFontId() >= 0 && pFontTable->size() > (size_t)pTopContext->GetFootnoteFontId() )
1145         {
1146             const FontEntry::Pointer_t pFontEntry(pFontTable->getFontEntry(sal_uInt32(pTopContext->GetFootnoteFontId())));
1147             PropertyMapPtr aFontProps( new PropertyMap );
1148             aFontProps->Insert(PROP_CHAR_FONT_NAME, true, uno::makeAny( pFontEntry->sFontName  ));
1149             aFontProps->Insert(PROP_CHAR_FONT_CHAR_SET, true, uno::makeAny( (sal_Int16)pFontEntry->nTextEncoding  ));
1150             aFontProps->Insert(PROP_CHAR_FONT_PITCH, true, uno::makeAny( pFontEntry->nPitchRequest  ));
1151             aFontProperties = aFontProps->GetPropertyValues();
1152         }
1153         else if(pTopContext->GetFootnoteFontName().getLength())
1154         {
1155             PropertyMapPtr aFontProps( new PropertyMap );
1156             aFontProps->Insert(PROP_CHAR_FONT_NAME, true, uno::makeAny( pTopContext->GetFootnoteFontName()  ));
1157             aFontProperties = aFontProps->GetPropertyValues();
1158         }
1159         appendTextContent( uno::Reference< text::XTextContent >( xFootnoteText, uno::UNO_QUERY_THROW ), aFontProperties );
1160         m_aTextAppendStack.push(uno::Reference< text::XTextAppend >( xFootnoteText, uno::UNO_QUERY_THROW ));
1161 
1162         // Redlines for the footnote anchor
1163         CheckRedline( xFootnote->getAnchor( ) );
1164     }
1165     catch( uno::Exception& )
1166     {
1167         OSL_ENSURE( false, "exception in PushFootOrEndnote" );
1168     }
1169 }
1170 
1171 void DomainMapper_Impl::CreateRedline( uno::Reference< text::XTextRange > xRange, RedlineParamsPtr& pRedline )
1172 {
1173     if ( pRedline.get( ) )
1174     {
1175         try
1176         {
1177             ::rtl::OUString sType;
1178             PropertyNameSupplier & rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(  );
1179             switch ( pRedline->m_nToken & 0xffff )
1180             {
1181             case ooxml::OOXML_mod:
1182                 sType = rPropNameSupplier.GetName( PROP_FORMAT );
1183                 break;
1184             case ooxml::OOXML_ins:
1185                 sType = rPropNameSupplier.GetName( PROP_INSERT );
1186                 break;
1187             case ooxml::OOXML_del:
1188                 sType = rPropNameSupplier.GetName( PROP_DELETE );
1189                 break;
1190             }
1191             uno::Reference < text::XRedline > xRedline( xRange, uno::UNO_QUERY_THROW );
1192             beans::PropertyValues aRedlineProperties( 2 );
1193             beans::PropertyValue * pRedlineProperties = aRedlineProperties.getArray(  );
1194             pRedlineProperties[0].Name = rPropNameSupplier.GetName( PROP_REDLINE_AUTHOR );
1195             pRedlineProperties[0].Value <<= pRedline->m_sAuthor;
1196             pRedlineProperties[1].Name = rPropNameSupplier.GetName( PROP_REDLINE_DATE_TIME );
1197             pRedlineProperties[1].Value <<= lcl_DateStringToDateTime( pRedline->m_sDate );
1198 
1199             xRedline->makeRedline( sType, aRedlineProperties );
1200         }
1201         catch( const uno::Exception & rEx )
1202         {
1203             ( void ) rEx;
1204 // disabled: current writer redline impl. rather primitive, so it gets annoying
1205 //            OSL_ENSURE( false, "Exception in makeRedline" );
1206         }
1207     }
1208 }
1209 
1210 void DomainMapper_Impl::CheckParaRedline( uno::Reference< text::XTextRange > xRange )
1211 {
1212     if ( m_pParaRedline.get( ) )
1213     {
1214         CreateRedline( xRange, m_pParaRedline );
1215         ResetParaRedline( );
1216     }
1217 }
1218 
1219 void DomainMapper_Impl::CheckRedline( uno::Reference< text::XTextRange > xRange )
1220 {
1221     vector<RedlineParamsPtr>::iterator pIt = m_aRedlines.begin( );
1222     vector< RedlineParamsPtr > aCleaned;
1223     for (; pIt != m_aRedlines.end( ); pIt++ )
1224     {
1225         CreateRedline( xRange, *pIt );
1226 
1227         // Adding the non-mod redlines to the temporary vector
1228         if ( pIt->get( ) && ( ( *pIt )->m_nToken & 0xffff ) != ooxml::OOXML_mod )
1229         {
1230             aCleaned.push_back( *pIt );
1231         }
1232     }
1233 
1234     m_aRedlines.swap( aCleaned );
1235 }
1236 
1237 void DomainMapper_Impl::StartParaChange( )
1238 {
1239     m_bIsParaChange = true;
1240 }
1241 
1242 void DomainMapper_Impl::EndParaChange( )
1243 {
1244     m_bIsParaChange = false;
1245 }
1246 
1247 /*-- 22.12.2008 13:45:15---------------------------------------------------
1248 
1249   -----------------------------------------------------------------------*/
1250 void DomainMapper_Impl::PushAnnotation()
1251 {
1252     try
1253     {
1254         PropertyMapPtr pTopContext = GetTopContext();
1255         m_bIsInComments = true;
1256         m_xAnnotationField = uno::Reference< beans::XPropertySet >( GetTextFactory()->createInstance(
1257                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField.Annotation") ) ),
1258             uno::UNO_QUERY_THROW );
1259         uno::Reference< text::XText > xAnnotationText;
1260         m_xAnnotationField->getPropertyValue(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextRange"))) >>= xAnnotationText;
1261         m_aTextAppendStack.push(uno::Reference< text::XTextAppend >( xAnnotationText, uno::UNO_QUERY_THROW ));
1262     }
1263     catch( uno::Exception& )
1264     {
1265         OSL_ENSURE( false, "exception in PushAnnotation" );
1266     }
1267 }
1268 /*-- 24.05.2007 14:22:29---------------------------------------------------
1269 
1270   -----------------------------------------------------------------------*/
1271 void DomainMapper_Impl::PopFootOrEndnote()
1272 {
1273     RemoveLastParagraph();
1274     m_aTextAppendStack.pop();
1275 }
1276 /*-- 22.12.2008 13:45:15---------------------------------------------------
1277 
1278   -----------------------------------------------------------------------*/
1279 void DomainMapper_Impl::PopAnnotation()
1280 {
1281     m_bIsInComments = false;
1282 
1283     RemoveLastParagraph();
1284     m_aTextAppendStack.pop();
1285 
1286     if ( m_nAnnotationId != -1 )
1287     {
1288         // See if the annotation will be a single position or a range.
1289         AnnotationPosition& aAnnotationPosition = m_aAnnotationPositions[ m_nAnnotationId ];
1290         if ( !aAnnotationPosition.m_xStart.is()
1291              || !aAnnotationPosition.m_xEnd.is() )
1292         {
1293             uno::Sequence< beans::PropertyValue > aEmptyProperties;
1294             appendTextContent( uno::Reference< text::XTextContent >( m_xAnnotationField, uno::UNO_QUERY_THROW ), aEmptyProperties );
1295         }
1296         else
1297         {
1298             // Create a range that points to the annotation start/end.
1299             uno::Reference<text::XText> xText = aAnnotationPosition.m_xStart->getText();
1300             uno::Reference<text::XTextCursor> xCursor = xText->createTextCursorByRange( aAnnotationPosition.m_xStart );
1301             xCursor->gotoRange( aAnnotationPosition.m_xEnd, true );
1302             uno::Reference<text::XTextRange> xTextRange(xCursor, uno::UNO_QUERY_THROW);
1303 
1304             // Attach the annotation to the range.
1305             uno::Reference<text::XTextAppend> xTextAppend = m_aTextAppendStack.top().xTextAppend;
1306             xTextAppend->insertTextContent(xTextRange, uno::Reference<text::XTextContent>(m_xAnnotationField, uno::UNO_QUERY_THROW), !xCursor->isCollapsed());
1307         }
1308         m_aAnnotationPositions.erase( m_nAnnotationId );
1309     }
1310 
1311     m_xAnnotationField.clear();
1312     m_nAnnotationId = -1;
1313 }
1314 
1315 void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape > xShape )
1316 {
1317     m_bIsInShape = true;
1318     try
1319     {
1320         // Add the shape to the text append stack
1321         m_aTextAppendStack.push( uno::Reference< text::XTextAppend >( xShape, uno::UNO_QUERY_THROW ) );
1322         m_bShapeContextAdded = true;
1323 
1324         // Add the shape to the anchored objects stack
1325         uno::Reference< text::XTextContent > xTxtContent( xShape, uno::UNO_QUERY_THROW );
1326         m_aAnchoredStack.push( xTxtContent );
1327 
1328         PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1329 
1330         uno::Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY_THROW );
1331         xProps->setPropertyValue(
1332                 rPropNameSupplier.GetName( PROP_ANCHOR_TYPE ),
1333                 uno::makeAny( text::TextContentAnchorType_AT_PARAGRAPH ) );
1334         xProps->setPropertyValue(
1335                 rPropNameSupplier.GetName( PROP_OPAQUE ),
1336                 uno::makeAny( true ) );
1337     }
1338     catch ( const uno::Exception& e )
1339     {
1340 #if DEBUG
1341         clog << "Exception when adding shape: ";
1342         clog << rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr( );
1343         clog << endl;
1344 #endif
1345     }
1346 }
1347 
1348 /*-- 20.03.2008 09:01:59---------------------------------------------------
1349 
1350   -----------------------------------------------------------------------*/
1351 void DomainMapper_Impl::PopShapeContext()
1352 {
1353     if ( m_bShapeContextAdded )
1354     {
1355         m_aTextAppendStack.pop();
1356         m_bShapeContextAdded = false;
1357     }
1358     m_bIsInShape = false;
1359 }
1360 /*-- 12.09.2006 08:07:55---------------------------------------------------
1361 
1362   -----------------------------------------------------------------------*/
1363 ::rtl::OUString lcl_FindQuotedText( const ::rtl::OUString& rCommand,
1364                 const sal_Char* cStartQuote, const sal_Unicode uEndQuote )
1365 {
1366     ::rtl::OUString sRet;
1367     ::rtl::OUString sStartQuote( ::rtl::OUString::createFromAscii(cStartQuote) );
1368     sal_Int32 nStartIndex = rCommand.indexOf( sStartQuote );
1369     if( nStartIndex >= 0 )
1370     {
1371         sal_Int32 nStartLength = sStartQuote.getLength();
1372         sal_Int32 nEndIndex = rCommand.indexOf( uEndQuote, nStartIndex + nStartLength);
1373         if( nEndIndex > nStartIndex )
1374         {
1375             sRet = rCommand.copy( nStartIndex + nStartLength, nEndIndex - nStartIndex - nStartLength);
1376         }
1377     }
1378     return sRet;
1379 
1380 }
1381 /*-- 08.09.2006 14:05:17---------------------------------------------------
1382 
1383   -----------------------------------------------------------------------*/
1384 sal_Int16 lcl_ParseNumberingType( const ::rtl::OUString& rCommand )
1385 {
1386     sal_Int16 nRet = style::NumberingType::PAGE_DESCRIPTOR;
1387 
1388     //  The command looks like: " PAGE \* Arabic "
1389     ::rtl::OUString sNumber = lcl_FindQuotedText(rCommand, "\\* ", ' ');
1390 
1391     if( sNumber.getLength() )
1392     {
1393         //todo: might make sense to hash this list, too
1394         struct NumberingPairs
1395         {
1396             const sal_Char* cWordName;
1397             sal_Int16       nType;
1398         };
1399         static const NumberingPairs aNumberingPairs[] =
1400         {
1401             {"Arabic", style::NumberingType::ARABIC}
1402             ,{"ROMAN", style::NumberingType::ROMAN_UPPER}
1403             ,{"roman", style::NumberingType::ROMAN_LOWER}
1404             ,{"ALPHABETIC", style::NumberingType::CHARS_UPPER_LETTER}
1405             ,{"alphabetic", style::NumberingType::CHARS_LOWER_LETTER}
1406             ,{"CircleNum", style::NumberingType::CIRCLE_NUMBER}
1407             ,{"ThaiArabic", style::NumberingType::CHARS_THAI}
1408             ,{"ThaiCardText", style::NumberingType::CHARS_THAI}
1409             ,{"ThaiLetter", style::NumberingType::CHARS_THAI}
1410 //            ,{"SBCHAR", style::NumberingType::}
1411 //            ,{"DBCHAR", style::NumberingType::}
1412 //            ,{"DBNUM1", style::NumberingType::}
1413 //            ,{"DBNUM2", style::NumberingType::}
1414 //            ,{"DBNUM3", style::NumberingType::}
1415 //            ,{"DBNUM4", style::NumberingType::}
1416             ,{"Aiueo", style::NumberingType::AIU_FULLWIDTH_JA}
1417             ,{"Iroha", style::NumberingType::IROHA_FULLWIDTH_JA}
1418 //            ,{"ZODIAC1", style::NumberingType::}
1419 //            ,{"ZODIAC2", style::NumberingType::}
1420 //            ,{"ZODIAC3", style::NumberingType::}
1421 //            ,{"CHINESENUM1", style::NumberingType::}
1422 //            ,{"CHINESENUM2", style::NumberingType::}
1423 //            ,{"CHINESENUM3", style::NumberingType::}
1424             ,{"ArabicAlpha", style::NumberingType::CHARS_ARABIC}
1425             ,{"ArabicAbjad", style::NumberingType::FULLWIDTH_ARABIC}
1426 /* possible values:
1427 style::NumberingType::
1428 
1429     CHARS_UPPER_LETTER_N
1430     CHARS_LOWER_LETTER_N
1431     TRANSLITERATION
1432     NATIVE_NUMBERING
1433     CIRCLE_NUMBER
1434     NUMBER_LOWER_ZH
1435     NUMBER_UPPER_ZH
1436     NUMBER_UPPER_ZH_TW
1437     TIAN_GAN_ZH
1438     DI_ZI_ZH
1439     NUMBER_TRADITIONAL_JA
1440     AIU_HALFWIDTH_JA
1441     IROHA_HALFWIDTH_JA
1442     NUMBER_UPPER_KO
1443     NUMBER_HANGUL_KO
1444     HANGUL_JAMO_KO
1445     HANGUL_SYLLABLE_KO
1446     HANGUL_CIRCLED_JAMO_KO
1447     HANGUL_CIRCLED_SYLLABLE_KO
1448     CHARS_HEBREW
1449     CHARS_NEPALI
1450     CHARS_KHMER
1451     CHARS_LAO
1452     CHARS_TIBETAN
1453     CHARS_CYRILLIC_UPPER_LETTER_BG
1454     CHARS_CYRILLIC_LOWER_LETTER_BG
1455     CHARS_CYRILLIC_UPPER_LETTER_N_BG
1456     CHARS_CYRILLIC_LOWER_LETTER_N_BG
1457     CHARS_CYRILLIC_UPPER_LETTER_RU
1458     CHARS_CYRILLIC_LOWER_LETTER_RU
1459     CHARS_CYRILLIC_UPPER_LETTER_N_RU
1460     CHARS_CYRILLIC_LOWER_LETTER_N_RU
1461     CHARS_CYRILLIC_UPPER_LETTER_SR
1462     CHARS_CYRILLIC_LOWER_LETTER_SR
1463     CHARS_CYRILLIC_UPPER_LETTER_N_SR
1464     CHARS_CYRILLIC_LOWER_LETTER_N_SR*/
1465 
1466         };
1467         for( sal_uInt32 nNum = 0; nNum < sizeof(aNumberingPairs)/sizeof( NumberingPairs ); ++nNum)
1468         {
1469             if( /*sCommand*/sNumber.equalsAscii(aNumberingPairs[nNum].cWordName ))
1470             {
1471                 nRet = aNumberingPairs[nNum].nType;
1472                 break;
1473             }
1474         }
1475 
1476     }
1477     return nRet;
1478 }
1479 /*-- 08.09.2006 13:52:09---------------------------------------------------
1480 
1481   -----------------------------------------------------------------------*/
1482 OUString lcl_ParseFormat( const ::rtl::OUString& rCommand )
1483 {
1484     //  The command looks like: " DATE \@ "dd MMMM yyyy"
1485     return lcl_FindQuotedText(rCommand, "\\@ \"", '\"');
1486 }
1487 /*-- 19.09.2006 10:01:20---------------------------------------------------
1488 extract a parameter (with or without quotes) between the command and the following backslash
1489   -----------------------------------------------------------------------*/
1490 ::rtl::OUString lcl_ExtractParameter(const ::rtl::OUString& rCommand, sal_Int32 nCommandLength )
1491 {
1492     sal_Int32 nStartIndex = nCommandLength;
1493     sal_Int32 nEndIndex = 0;
1494     sal_Int32 nQuoteIndex = rCommand.indexOf( '\"', nStartIndex);
1495     if( nQuoteIndex >= 0)
1496     {
1497         nStartIndex = nQuoteIndex + 1;
1498         nEndIndex = rCommand.indexOf( '\"', nStartIndex + 1) - 1;
1499     }
1500     else
1501     {
1502         nEndIndex = rCommand.indexOf( ::rtl::OUString::createFromAscii(" \\"), nStartIndex);
1503     }
1504     ::rtl::OUString sRet;
1505     if( nEndIndex > nStartIndex + 1 )
1506     {
1507         //remove spaces at start and end of the result
1508         if(nQuoteIndex <= 0)
1509         {
1510             const sal_Unicode* pCommandStr = rCommand.getStr();
1511             while( nStartIndex < nEndIndex && pCommandStr[nStartIndex] == ' ')
1512                     ++nStartIndex;
1513             while( nEndIndex > nStartIndex && pCommandStr[nEndIndex] == ' ')
1514                     --nEndIndex;
1515         }
1516         sRet = rCommand.copy( nStartIndex, nEndIndex - nStartIndex + 1);
1517     }
1518     return sRet;
1519 }
1520 
1521 /*-- 15.09.2006 10:57:57---------------------------------------------------
1522 
1523   -----------------------------------------------------------------------*/
1524 ::rtl::OUString lcl_ExctractAskVariableAndHint( const ::rtl::OUString& rCommand, ::rtl::OUString& rHint )
1525 {
1526     // the first word after "ASK " is the variable
1527     // the text after the variable and before a '\' is the hint
1528     // if no hint is set the variable is used as hint
1529     // the quotes of the hint have to be removed
1530     sal_Int32 nIndex = rCommand.indexOf( ' ', 2);//find last space after 'ASK'
1531     while(rCommand.getStr()[nIndex] == ' ')
1532         ++nIndex;
1533     ::rtl::OUString sShortCommand( rCommand.copy( nIndex ) ); //cut off the " ASK "
1534 
1535     nIndex = 0;
1536     sShortCommand = sShortCommand.getToken( 0, '\\', nIndex);
1537     nIndex = 0;
1538     ::rtl::OUString sRet = sShortCommand.getToken( 0, ' ', nIndex);
1539     if( nIndex > 0)
1540         rHint = sShortCommand.copy( nIndex );
1541     if( !rHint.getLength() )
1542         rHint = sRet;
1543     return sRet;
1544 }
1545 /*-- 24.01.2007 16:04:33---------------------------------------------------
1546 
1547   -----------------------------------------------------------------------*/
1548 bool lcl_FindInCommand(
1549     const ::rtl::OUString& rCommand,
1550     sal_Unicode cSwitch,
1551     ::rtl::OUString& rValue )
1552 {
1553     bool bRet = false;
1554     ::rtl::OUString sSearch('\\');
1555     sSearch += ::rtl::OUString( cSwitch );
1556     sal_Int32 nIndex = rCommand.indexOf( sSearch  );
1557     if( nIndex >= 0 )
1558     {
1559         bRet = true;
1560         //find next '\' or end of string
1561         sal_Int32 nEndIndex = rCommand.indexOf( '\\', nIndex + 1);
1562         if( nEndIndex < 0 )
1563             nEndIndex = rCommand.getLength() - 1;
1564         if( nEndIndex - nIndex > 3 )
1565             rValue = rCommand.copy( nIndex + 3, nEndIndex - nIndex - 3);
1566     }
1567     return bRet;
1568 }
1569 /*-- 01.09.2006 11:48:08---------------------------------------------------
1570 
1571   -----------------------------------------------------------------------*/
1572 /*void DomainMapper_Impl::CreateField( ::rtl::OUString& rCommand )
1573 {
1574     static FieldConversionMap_t aFieldConversionMap;
1575     static bool bFilled = false;
1576     m_bSetUserFieldContent = false;
1577     if(!bFilled)
1578     {
1579         static const FieldConversion aFields[] =
1580         {
1581 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ADDRESSBLOCK")),  "",                         "", FIELD_ADDRESSBLOCK  },
1582 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ADVANCE")),       "",                         "", FIELD_ADVANCE       },
1583             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ASK")),           "SetExpression",             "SetExpression", FIELD_ASK      },
1584             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTONUM")),       "SetExpression",            "SetExpression", FIELD_AUTONUM   },
1585             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTONUMLGL")),     "SetExpression",            "SetExpression", FIELD_AUTONUMLGL },
1586             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTONUMOUT")),     "SetExpression",            "SetExpression", FIELD_AUTONUMOUT },
1587             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTHOR")),        "Author",                   "", FIELD_AUTHOR       },
1588             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DATE")),          "DateTime",                 "", FIELD_DATE         },
1589             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("COMMENTS")),      "DocInfo.Description",      "", FIELD_COMMENTS     },
1590             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CREATEDATE")),    "DocInfo.CreateDateTime",   "", FIELD_CREATEDATE   },
1591             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOCPROPERTY")),   "",                         "", FIELD_DOCPROPERTY },
1592             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOCVARIABLE")),   "User",                     "", FIELD_DOCVARIABLE  },
1593             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EDITTIME")),      "DocInfo.EditTime",         "", FIELD_EDITTIME     },
1594             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILLIN")),        "Input",                    "", FIELD_FILLIN       },
1595             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILENAME")),      "FileName",                 "", FIELD_FILENAME     },
1596 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILESIZE")),      "",                         "", FIELD_FILESIZE     },
1597 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMULA")),     "",                           "", FIELD_FORMULA
1598 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GOTOBUTTON")),    "",                         "", FIELD_GOTOBUTTON   },
1599             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HYPERLINK")),     "",                         "", FIELD_HYPERLINK    },
1600             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IF")),            "ConditionalText",          "", FIELD_IF           },
1601 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INFO")),      "","", FIELD_INFO         },
1602 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INCLUDEPICTURE")), "",                        "", FIELD_INCLUDEPICTURE},
1603             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("KEYWORDS")),      "DocInfo.KeyWords",         "", FIELD_KEYWORDS     },
1604             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LASTSAVEDBY")),   "DocInfo.ChangeAuthor",                         "", FIELD_LASTSAVEDBY  },
1605             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MACROBUTTON")),   "Macro",                         "", FIELD_MACROBUTTON  },
1606             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MERGEFIELD")),    "Database",                 "Database", FIELD_MERGEFIELD},
1607             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MERGEREC")),      "DatabaseNumberOfSet",      "", FIELD_MERGEREC     },
1608 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MERGESEQ")),      "",                         "", FIELD_MERGESEQ     },
1609             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NEXT")),          "DatabaseNextSet",          "", FIELD_NEXT         },
1610             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NEXTIF")),        "DatabaseNextSet",          "", FIELD_NEXTIF       },
1611             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PAGE")),          "PageNumber",               "", FIELD_PAGE         },
1612             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REF")),           "",                         "", FIELD_REF          },
1613             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REVNUM")),        "DocInfo.Revision",         "", FIELD_REVNUM       },
1614             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SAVEDATE")),      "DocInfo.Change",           "", FIELD_SAVEDATE     },
1615 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SECTION")),       "",                         "", FIELD_SECTION      },
1616 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SECTIONPAGES")),  "",                         "", FIELD_SECTIONPAGES },
1617             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SEQ")),           "SetExpression",            "SetExpression", FIELD_SEQ          },
1618 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SET")),           "","", FIELD_SET          },
1619 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SKIPIF")),"",                                 "", FIELD_SKIPIF       },
1620 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("STYLEREF")),"",                               "", FIELD_STYLEREF     },
1621             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SUBJECT")),       "DocInfo.Subject",          "", FIELD_SUBJECT      },
1622 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SYMBOL")),"",                                 "", FIELD_SYMBOL       },
1623             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TEMPLATE")),      "TemplateName",             "", FIELD_TEMPLATE},
1624             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TIME")),          "DateTime",                 "", FIELD_TIME         },
1625             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TITLE")),         "DocInfo.Title",            "", FIELD_TITLE        },
1626             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("USERINITIALS")),  "ExtendedUser",              "", FIELD_USERINITIALS},
1627 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("USERADDRESS")),   "",                         "", FIELD_USERADDRESS  },
1628 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("USERNAME")),      "ExtendedUser",             "", FIELD_USERNAME     }
1629             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TOC")), "com.sun.star.text.ContentIndex", "", FIELD_TOC},
1630             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TC")), "com.sun.star.text.ContentIndexMark", "", FIELD_TC},
1631 
1632 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("")), "", "", FIELD_},
1633 
1634         };
1635         size_t nConversions = sizeof(aFields)/sizeof(FieldConversion);
1636         for( size_t nConversion = 0; nConversion < nConversions; ++nConversion)
1637         {
1638             aFieldConversionMap.insert( FieldConversionMap_t::value_type(
1639                     aFields[nConversion].sWordCommand,
1640                     aFields[nConversion] ));
1641         }
1642 
1643         bFilled = true;
1644     }
1645     try
1646     {
1647         uno::Reference< uno::XInterface > xFieldInterface;
1648         //at first determine the field type - skip first space
1649         ::rtl::OUString sCommand( rCommand.copy(rCommand.getLength() ? 1 : 0) );
1650         sal_Int32 nSpaceIndex = sCommand.indexOf( ' ' );
1651         if( 0 <= nSpaceIndex )
1652             sCommand = sCommand.copy( 0, nSpaceIndex );
1653 
1654         FieldConversionMap_t::iterator aIt = aFieldConversionMap.find(sCommand);
1655         if(aIt != aFieldConversionMap.end())
1656         {
1657             uno::Reference< beans::XPropertySet > xFieldProperties;
1658             if( FIELD_HYPERLINK != aIt->second.eFieldId &&
1659                     FIELD_DOCPROPERTY != aIt->second.eFieldId &&
1660                     FIELD_TOC != aIt->second.eFieldId &&
1661                     FIELD_TC != aIt->second.eFieldId)
1662             {
1663                 //add the service prefix
1664                 OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField."));
1665                 sServiceName += ::rtl::OUString::createFromAscii(aIt->second.cFieldServiceName );
1666                 xFieldInterface = m_xTextFactory->createInstance(sServiceName);
1667                 xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW);
1668             }
1669             PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1670             switch( aIt->second.eFieldId )
1671             {
1672                 case FIELD_ADDRESSBLOCK: break;
1673                 case FIELD_ADVANCE     : break;
1674                 case FIELD_ASK         :
1675                 {
1676                     //doesn the command contain a variable name?
1677                     ::rtl::OUString sVariable, sHint;
1678 
1679                     sVariable = lcl_ExctractAskVariableAndHint( rCommand, sHint );
1680                     if(sVariable.getLength())
1681                     {
1682                         // determine field master name
1683                         uno::Reference< beans::XPropertySet > xMaster = FindOrCreateFieldMaster(
1684                                 "com.sun.star.text.FieldMaster.SetExpression", sVariable );
1685 
1686                         // attach the master to the field
1687                         uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
1688                         xDependentField->attachTextFieldMaster( xMaster );
1689 
1690                         // set input flag at the field
1691                         xFieldProperties->setPropertyValue(
1692                                 rPropNameSupplier.GetName(PROP_IS_INPUT), uno::makeAny( true ));
1693                         // set the prompt
1694                         xFieldProperties->setPropertyValue(
1695                                 rPropNameSupplier.GetName(PROP_HINT),
1696                                 uno::makeAny( sHint ));
1697                     }
1698                     else
1699                     {
1700                         //don't insert the field
1701                         //todo: maybe import a 'normal' input field here?
1702                         xFieldInterface = 0;
1703                     }
1704                 }
1705                 break;
1706                 case FIELD_AUTONUM    :
1707                 case FIELD_AUTONUMLGL :
1708                 case FIELD_AUTONUMOUT :
1709                 {
1710                     //create a sequence field master "AutoNr"
1711                     uno::Reference< beans::XPropertySet > xMaster = FindOrCreateFieldMaster(
1712                                 "com.sun.star.text.FieldMaster.SetExpression",
1713                                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoNr") ));
1714 
1715                     xMaster->setPropertyValue( rPropNameSupplier.GetName(PROP_SUB_TYPE),
1716                                 uno::makeAny(text::SetVariableType::SEQUENCE));
1717 
1718                     //apply the numbering type
1719                     xFieldProperties->setPropertyValue(
1720                         rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
1721                         uno::makeAny( lcl_ParseNumberingType(rCommand) ));
1722                         // attach the master to the field
1723                     uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
1724                     xDependentField->attachTextFieldMaster( xMaster );
1725                 }
1726                 break;
1727                 case FIELD_AUTHOR       :
1728                 {
1729                     xFieldProperties->setPropertyValue( rPropNameSupplier.GetName(PROP_FULL_NAME), uno::makeAny( true ));
1730                     ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" AUTHOR") );
1731                     if(sParam.getLength())
1732                     {
1733                         xFieldProperties->setPropertyValue(
1734                                 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
1735                         //PROP_CURRENT_PRESENTATION is set later anyway
1736                     }
1737                 }
1738                 break;
1739                 case FIELD_DATE:
1740                 {
1741                     //not fixed,
1742                     xFieldProperties->setPropertyValue(
1743                         rPropNameSupplier.GetName(PROP_IS_FIXED),
1744                         uno::makeAny( false ));
1745                     SetNumberFormat( rCommand, xFieldProperties );
1746                 }
1747                 break;
1748                 case FIELD_COMMENTS     :
1749                 {
1750                     ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" COMMENTS") );
1751                     if(sParam.getLength())
1752                     {
1753                         xFieldProperties->setPropertyValue(
1754                                 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
1755                         //PROP_CURRENT_PRESENTATION is set later anyway
1756                     }
1757                 }
1758                 break;
1759                 case FIELD_CREATEDATE  :
1760                 {
1761                     SetNumberFormat( rCommand, xFieldProperties );
1762                 }
1763                 break;
1764                 case FIELD_DOCPROPERTY :
1765                 {
1766                     //some docproperties should be imported as document statistic fields, some as DocInfo fields
1767                     //others should be user fields
1768                     ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" DOCPROPERTY") );
1769                     if(sParam.getLength())
1770                     {
1771                         #define SET_ARABIC      0x01
1772                         #define SET_FULL_NAME   0x02
1773                         struct DocPropertyMap
1774                         {
1775                             const sal_Char* pDocPropertyName;
1776                             const sal_Char* pServiceName;
1777                             sal_uInt8       nFlags;
1778                         };
1779                         static const DocPropertyMap aDocProperties[] =
1780                         {
1781                             {"Author",           "Author",                  SET_FULL_NAME},
1782                             {"CreateTime",       "DocInfo.CreateDateTime",  0},
1783                             {"Characters",       "CharacterCount",          SET_ARABIC},
1784                             {"Comments",         "DocInfo.Description",     0},
1785                             {"Keywords",         "DocInfo.KeyWords",        0},
1786                             {"LastPrinted",      "DocInfo.PrintDateTime",   0},
1787                             {"LastSavedBy",      "DocInfo.ChangeAuthor",    0},
1788                             {"LastSavedTime",    "DocInfo.ChangeDateTime",  0},
1789                             {"Paragraphs",       "ParagraphCount",          SET_ARABIC},
1790                             {"RevisionNumber",   "DocInfo.Revision",        0},
1791                             {"Subject",          "DocInfo.Subject",         0},
1792                             {"Template",         "TemplateName",            0},
1793                             {"Title",            "DocInfo.Title",           0},
1794                             {"TotalEditingTime", "DocInfo.EditTime",        9},
1795                             {"Words",            "WordCount",               SET_ARABIC}
1796 
1797                             //other available DocProperties:
1798                             //Bytes, Category, CharactersWithSpaces, Company
1799                             //HyperlinkBase,
1800                             //Lines, Manager, NameofApplication, ODMADocId, Pages,
1801                             //Security,
1802                         };
1803                         //search for a field mapping
1804                         ::rtl::OUString sFieldServiceName;
1805                         sal_uInt16 nMap = 0;
1806                         for( ; nMap < sizeof(aDocProperties) / sizeof(DocPropertyMap); ++nMap )
1807                         {
1808                             if(sParam.equalsAscii(aDocProperties[nMap].pDocPropertyName))
1809                             {
1810                                 sFieldServiceName = ::rtl::OUString::createFromAscii(aDocProperties[nMap].pServiceName);
1811                                 break;
1812                             }
1813                         }
1814                         ::rtl::OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField."));
1815                         if(sFieldServiceName.getLength())
1816                         {
1817                             sServiceName += sFieldServiceName;
1818                             xFieldInterface = m_xTextFactory->createInstance(sServiceName);
1819                             xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW);
1820                             if(0 != (aDocProperties[nMap].nFlags & SET_ARABIC))
1821                                 xFieldProperties->setPropertyValue(
1822                                     rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
1823                                     uno::makeAny( style::NumberingType::ARABIC ));
1824                             else if(0 != (aDocProperties[nMap].nFlags & SET_FULL_NAME))
1825                                 xFieldProperties->setPropertyValue(
1826                                     rPropNameSupplier.GetName(PROP_FULL_NAME), uno::makeAny( true ));
1827 
1828                         }
1829                         else
1830                         {
1831                             //create a user field and type
1832                             uno::Reference< beans::XPropertySet > xMaster =
1833                                 FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.User", sParam );
1834                             sServiceName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("User"));
1835                             xFieldInterface = m_xTextFactory->createInstance(sServiceName);
1836                             xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW);
1837                             uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
1838                             xDependentField->attachTextFieldMaster( xMaster );
1839                             m_bSetUserFieldContent = true;
1840                         }
1841                     }
1842                 }
1843                 #undef SET_ARABIC
1844                 #undef SET_FULL_NAME
1845                 break;
1846                 case FIELD_DOCVARIABLE  :
1847                 {
1848                     ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" DOCVARIABLE") );
1849                     //create a user field and type
1850                     uno::Reference< beans::XPropertySet > xMaster =
1851                         FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.User", sParam );
1852                     uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
1853                     xDependentField->attachTextFieldMaster( xMaster );
1854                     m_bSetUserFieldContent = true;
1855                 }
1856                 break;
1857                 case FIELD_EDITTIME     :
1858                     //it's a numbering type, no number format! SetNumberFormat( rCommand, xFieldProperties );
1859                 break;
1860                 case FIELD_FILLIN       :
1861                 {
1862                     sal_Int32 nIndex = 0;
1863                     xFieldProperties->setPropertyValue(
1864                             rPropNameSupplier.GetName(PROP_HINT), uno::makeAny( rCommand.getToken( 1, '\"', nIndex)));
1865                 }
1866                 break;
1867                 case FIELD_FILENAME:
1868                 {
1869                     sal_Int32 nNumberingTypeIndex = rCommand.indexOf( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\p")));
1870                     xFieldProperties->setPropertyValue(
1871                             rPropNameSupplier.GetName(PROP_FILE_FORMAT),
1872                             uno::makeAny( nNumberingTypeIndex > 0 ? text::FilenameDisplayFormat::FULL : text::FilenameDisplayFormat::NAME ));
1873                 }
1874                 break;
1875                 case FIELD_FILESIZE     : break;
1876                 case FIELD_FORMULA : break;
1877                 case FIELD_GOTOBUTTON   : break;
1878                 case FIELD_HYPERLINK:
1879                 {
1880                     sal_Int32 nStartQuote = rCommand.indexOf( '\"' );
1881                     sal_Int32 nEndQuote = nStartQuote < rCommand.getLength() + 1 ? rCommand.indexOf( '\"', nStartQuote + 1) : -1;
1882                     if( nEndQuote > 0)
1883                         m_sHyperlinkURL = rCommand.copy(nStartQuote + 1, nEndQuote - nStartQuote - 1);
1884                 }
1885                 break;
1886                 case FIELD_IF           : break;
1887                 case FIELD_INFO         : break;
1888                 case FIELD_INCLUDEPICTURE: break;
1889                 case FIELD_KEYWORDS     :
1890                 {
1891                     ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" KEYWORDS") );
1892                     if(sParam.getLength())
1893                     {
1894                         xFieldProperties->setPropertyValue(
1895                                 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
1896                         //PROP_CURRENT_PRESENTATION is set later anyway
1897                     }
1898                 }
1899                 break;
1900                 case FIELD_LASTSAVEDBY  : break;
1901                 case FIELD_MACROBUTTON:
1902                 {
1903                     //extract macro name
1904                     sal_Int32 nIndex = sizeof(" MACROBUTTON ");
1905                     ::rtl::OUString sMacro = rCommand.getToken( 0, ' ', nIndex);
1906                     xFieldProperties->setPropertyValue(
1907                             rPropNameSupplier.GetName(PROP_MACRO_NAME), uno::makeAny( sMacro ));
1908 
1909                     //extract quick help text
1910                     if( rCommand.getLength() > nIndex + 1)
1911                     {
1912                         xFieldProperties->setPropertyValue(
1913                             rPropNameSupplier.GetName(PROP_HINT),
1914                             uno::makeAny( rCommand.copy( nIndex )));
1915                     }
1916                 }
1917                 break;
1918                 case FIELD_MERGEFIELD  :
1919                 {
1920                     //todo: create a database field and fieldmaster pointing to a column, only
1921                     ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" MERGEFIELD") );
1922                     //create a user field and type
1923                     uno::Reference< beans::XPropertySet > xMaster =
1924                         FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.Database", sParam );
1925 
1926 //                    xFieldProperties->setPropertyValue(
1927 //                             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldCode")),
1928 //                             uno::makeAny( rCommand.copy( nIndex + 1 )));
1929                     uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
1930                     xDependentField->attachTextFieldMaster( xMaster );
1931                     m_bSetUserFieldContent = true;
1932                 }
1933                 break;
1934                 case FIELD_MERGEREC     : break;
1935                 case FIELD_MERGESEQ     : break;
1936                 case FIELD_NEXT         : break;
1937                 case FIELD_NEXTIF       : break;
1938                 case FIELD_PAGE        :
1939                     xFieldProperties->setPropertyValue(
1940                         rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
1941                         uno::makeAny( lcl_ParseNumberingType(rCommand) ));
1942                     xFieldProperties->setPropertyValue(
1943                         rPropNameSupplier.GetName(PROP_SUB_TYPE),
1944                         uno::makeAny( text::PageNumberType_CURRENT ));
1945 
1946                 break;
1947                 case FIELD_REF          : break;
1948                 case FIELD_REVNUM       : break;
1949                 case FIELD_SAVEDATE     :
1950                     SetNumberFormat( rCommand, xFieldProperties );
1951                 break;
1952                 case FIELD_SECTION      : break;
1953                 case FIELD_SECTIONPAGES : break;
1954                 case FIELD_SEQ          : break;
1955                 case FIELD_SET          : break;
1956                 case FIELD_SKIPIF       : break;
1957                 case FIELD_STYLEREF     : break;
1958                 case FIELD_SUBJECT      :
1959                 {
1960                     ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" SUBJECT") );
1961                     if(sParam.getLength())
1962                     {
1963                         xFieldProperties->setPropertyValue(
1964                                 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
1965                         //PROP_CURRENT_PRESENTATION is set later anyway
1966                     }
1967                 }
1968                 break;
1969                 case FIELD_SYMBOL       : break;
1970                 case FIELD_TEMPLATE: break;
1971                 case FIELD_TIME         :
1972                     SetNumberFormat( rCommand, xFieldProperties );
1973                 break;
1974                 case FIELD_TITLE        :
1975                 {
1976                     ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" TITLE") );
1977                     if(sParam.getLength())
1978                     {
1979                         xFieldProperties->setPropertyValue(
1980                                 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
1981                         //PROP_CURRENT_PRESENTATION is set later anyway
1982                     }
1983                 }
1984                 break;
1985                 case FIELD_USERINITIALS:
1986                 {
1987                     xFieldProperties->setPropertyValue(
1988                         rPropNameSupplier.GetName(PROP_USER_DATA_TYPE), uno::makeAny( text::UserDataPart::SHORTCUT ));
1989                     //todo: if initials are provided - set them as fixed content
1990                     ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" USERINITIALS") );
1991                     if(sParam.getLength())
1992                     {
1993                         xFieldProperties->setPropertyValue(
1994                                 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
1995                         //PROP_CURRENT_PRESENTATION is set later anyway
1996                     }
1997                 }
1998                 break;
1999                 case FIELD_USERADDRESS  : //todo: user address collects street, city ...
2000                 break;
2001                 case FIELD_USERNAME     : //todo: user name is firstname + lastname
2002                 break;
2003                 case FIELD_TOC:
2004                 {
2005                     ::rtl::OUString sValue;
2006                     bool bTableOfFigures = false;
2007                     bool bHyperlinks = false;
2008                     bool bFromOutline = false;
2009                     bool bFromEntries = false;
2010                     ::rtl::OUString sTemplate;
2011                     ::rtl::OUString sChapterNoSeparator;
2012 //                  \a Builds a table of figures but does not include the captions's label and number
2013                     if( lcl_FindInCommand( rCommand, 'a', sValue ))
2014                     { //make it a table of figures
2015                         bTableOfFigures = true;
2016                     }
2017 //                  \b Uses a bookmark to specify area of document from which to build table of contents
2018 //                    if( lcl_FindInCommand( rCommand, 'b', sValue ))
2019 //                    { //todo: sValue contains the bookmark name - unsupported feature
2020 //                    }
2021                     if( lcl_FindInCommand( rCommand, 'c', sValue ))
2022 //                  \c Builds a table of figures of the given label
2023                     {
2024                         //todo: sValue contains the label's name
2025                         bTableOfFigures = true;
2026                     }
2027 //                  \d Defines the separator between sequence and page numbers
2028                     if( lcl_FindInCommand( rCommand, 'd', sValue ))
2029                     {
2030                         //todo: insert the chapter number into each level and insert the separator additionally
2031                         sChapterNoSeparator = sValue;
2032                     }
2033 //                  \f Builds a table of contents using TC entries instead of outline levels
2034                     if( lcl_FindInCommand( rCommand, 'f', sValue ))
2035                     {
2036                         //todo: sValue can contain a TOC entry identifier - use unclear
2037                         bFromEntries = true;
2038                     }
2039 //                  \h Hyperlinks the entries and page numbers within the table of contents
2040                     if( lcl_FindInCommand( rCommand, 'h', sValue ))
2041                     {
2042                         //todo: make all entries to hyperlinks
2043                         bHyperlinks = true;
2044                     }
2045 //                  \l Defines the TC entries field level used to build a table of contents
2046 //                    if( lcl_FindInCommand( rCommand, 'l', sValue ))
2047 //                    {
2048                             //todo: entries can only be included completely
2049 //                    }
2050 //                  \n Builds a table of contents or a range of entries, sucah as ?-9? in a table of contents without page numbers
2051 //                    if( lcl_FindInCommand( rCommand, 'n', sValue ))
2052 //                    {
2053                         //todo: what does the description mean?
2054 //                    }
2055 //                  \o  Builds a table of contents by using outline levels instead of TC entries
2056                     if( lcl_FindInCommand( rCommand, 'o', sValue ))
2057                     {
2058                         bFromOutline = true;
2059                     }
2060 //                  \p Defines the separator between the table entry and its page number
2061                     if( lcl_FindInCommand( rCommand, 'p', sValue ))
2062                     {  }
2063 //                  \s  Builds a table of contents by using a sequence type
2064                     if( lcl_FindInCommand( rCommand, 's', sValue ))
2065                     {  }
2066 //                  \t  Builds a table of contents by using style names other than the standard outline styles
2067                     if( lcl_FindInCommand( rCommand, 't', sValue ))
2068                     {
2069                         sTemplate = sValue;
2070                     }
2071 //                  \u  Builds a table of contents by using the applied paragraph outline level
2072                     if( lcl_FindInCommand( rCommand, 'u', sValue ))
2073                     {
2074                         bFromOutline = true;
2075                         //todo: what doesn 'the applied paragraph outline level' refer to?
2076                     }
2077 //                  \w Preserve tab characters within table entries
2078 //                    if( lcl_FindInCommand( rCommand, 'w', sValue ))
2079 //                    {
2080                         //todo: not supported
2081 //                    }
2082 //                  \x Preserve newline characters within table entries
2083 //                    if( lcl_FindInCommand( rCommand, 'x', sValue ))
2084 //                    {
2085                         //todo: unsupported
2086 //                    }
2087 //                  \z Hides page numbers within the table of contens when shown in Web Layout View
2088 //                    if( lcl_FindInCommand( rCommand, 'z', sValue ))
2089 //                    { //todo: unsupported feature  }
2090 
2091                     m_xTOC = uno::Reference< beans::XPropertySet >(
2092                             m_xTextFactory->createInstance(
2093                                 bTableOfFigures ?
2094                                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.IllustrationsIndex")) :
2095                                 ::rtl::OUString::createFromAscii(aIt->second.cFieldServiceName)),
2096                                 uno::UNO_QUERY_THROW);
2097                     if( !bTableOfFigures )
2098                     {
2099                         m_xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_OUTLINE ), uno::makeAny( bFromOutline ));
2100                         m_xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_MARKS ), uno::makeAny( bFromEntries ));
2101                         if( sTemplate.getLength() )
2102                         {
2103                             uno::Reference< container::XIndexReplace> xParaStyles;
2104                             m_xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_PARAGRAPH_STYLES)) >>= xParaStyles;
2105                             uno::Sequence< rtl::OUString> aStyles(1);
2106                             aStyles[0] = sTemplate;
2107                             xParaStyles->replaceByIndex(0, uno::makeAny(aStyles));
2108                         }
2109                         if(bHyperlinks  || sChapterNoSeparator.getLength())
2110                         {
2111                             uno::Reference< container::XIndexReplace> xLevelFormats;
2112                             m_xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_FORMAT)) >>= xLevelFormats;
2113                             sal_Int32 nLevelCount = xLevelFormats->getCount();
2114                             //start with level 1, 0 is the header level
2115                             for( sal_Int32 nLevel = 1; nLevel < nLevelCount; ++nLevel)
2116                             {
2117                                 uno::Sequence< beans::PropertyValues > aLevel;
2118                                 xLevelFormats->getByIndex( nLevel ) >>= aLevel;
2119                                 //create a copy of the level and add two new entries - hyperlink start and end
2120                                 bool bChapterNoSeparator  = sChapterNoSeparator.getLength() > 0;
2121                                 sal_Int32 nAdd = (bHyperlinks && bChapterNoSeparator) ? 4 : 2;
2122                                 uno::Sequence< beans::PropertyValues > aNewLevel( aLevel.getLength() + nAdd);
2123                                 beans::PropertyValues* pNewLevel = aNewLevel.getArray();
2124                                 if( bHyperlinks )
2125                                 {
2126                                     beans::PropertyValues aHyperlink(1);
2127                                     aHyperlink[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
2128                                     aHyperlink[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_HYPERLINK_START );
2129                                     pNewLevel[0] = aHyperlink;
2130                                     aHyperlink[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_HYPERLINK_END );
2131                                     pNewLevel[aNewLevel.getLength() -1] = aHyperlink;
2132                                 }
2133                                 if( bChapterNoSeparator )
2134                                 {
2135                                     beans::PropertyValues aChapterNo(2);
2136                                     aChapterNo[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
2137                                     aChapterNo[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_CHAPTER_INFO );
2138                                     aChapterNo[1].Name = rPropNameSupplier.GetName( PROP_CHAPTER_FORMAT );
2139                                     //todo: is ChapterFormat::Number correct?
2140                                     aChapterNo[1].Value <<= (sal_Int16)text::ChapterFormat::NUMBER;
2141                                     pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 4 : 2) ] = aChapterNo;
2142 
2143                                     beans::PropertyValues aChapterSeparator(2);
2144                                     aChapterSeparator[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
2145                                     aChapterSeparator[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_TEXT );
2146                                     aChapterSeparator[1].Name = rPropNameSupplier.GetName( PROP_TEXT );
2147                                     aChapterSeparator[1].Value <<= sChapterNoSeparator;
2148                                     pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 3 : 1)] = aChapterSeparator;
2149                                 }
2150                                 //copy the 'old' entries except the last (page no)
2151                                 for( sal_Int32 nToken = 0; nToken < aLevel.getLength() - 1; ++nToken)
2152                                 {
2153                                     pNewLevel[nToken + 1] = aLevel[nToken];
2154                                 }
2155                                 //copy page no entry (last or last but one depending on bHyperlinks
2156                                 sal_Int32 nPageNo = aNewLevel.getLength() - (bHyperlinks ? 2 : 3);
2157                                 pNewLevel[nPageNo] = aLevel[aLevel.getLength() - 1];
2158 
2159                                 xLevelFormats->replaceByIndex( nLevel, uno::makeAny( aNewLevel ) );
2160                             }
2161                         }
2162                     }
2163                 }
2164                 break;
2165                 case FIELD_TC :
2166                 {
2167                     m_xTC = uno::Reference< beans::XPropertySet >(
2168                         m_xTextFactory->createInstance(
2169                             ::rtl::OUString::createFromAscii(aIt->second.cFieldServiceName)),
2170                             uno::UNO_QUERY_THROW);
2171                     ::rtl::OUString sTCText = lcl_ExtractParameter(rCommand, sizeof(" TC") );
2172                     if( sTCText.getLength())
2173                         m_xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_ALTERNATIVE_TEXT),
2174                             uno::makeAny(sTCText));
2175                     ::rtl::OUString sValue;
2176                     // \f TC entry in doc with multiple tables
2177 //                    if( lcl_FindInCommand( rCommand, 'f', sValue ))
2178 //                    {
2179                         // todo: unsupported
2180 //                    }
2181                     if( lcl_FindInCommand( rCommand, 'l', sValue ))
2182                     // \l Outline Level
2183                     {
2184                         sal_Int32 nLevel = sValue.toInt32();
2185                         if( sValue.getLength() && nLevel >= 0 && nLevel <= 10 )
2186                             m_xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL), uno::makeAny( nLevel ));
2187                     }
2188 //                    if( lcl_FindInCommand( rCommand, 'n', sValue ))
2189 //                    \n Suppress page numbers
2190 //                    {
2191                         //todo: unsupported feature
2192 //                    }
2193                 }
2194                 break;
2195             }
2196         }
2197         m_xTextField = uno::Reference< text::XTextField >( xFieldInterface, uno::UNO_QUERY );
2198     }
2199     catch( uno::Exception& )
2200     {
2201     }
2202 }
2203 */
2204 
2205 /*-- 11.09.2006 13:16:35---------------------------------------------------
2206 
2207   -----------------------------------------------------------------------*/
2208 /*bool DomainMapper_Impl::IsFieldAvailable() const
2209 {
2210     return m_xTextField.is() || m_xTOC.is() || m_xTC.is() || m_sHyperlinkURL.getLength();
2211 }
2212 */
2213 /*-- 14.09.2006 12:46:52---------------------------------------------------
2214 
2215   -----------------------------------------------------------------------*/
2216 void DomainMapper_Impl::GetCurrentLocale(lang::Locale& rLocale)
2217 {
2218     PropertyMapPtr pTopContext = GetTopContext();
2219     PropertyDefinition aCharLocale( PROP_CHAR_LOCALE, true );
2220     PropertyMap::iterator aLocaleIter = pTopContext->find( aCharLocale );
2221     if( aLocaleIter != pTopContext->end())
2222         aLocaleIter->second >>= rLocale;
2223     else
2224     {
2225         PropertyMapPtr pParaContext = GetTopContextOfType(CONTEXT_PARAGRAPH);
2226         aLocaleIter = pParaContext->find(aCharLocale);
2227         if( aLocaleIter != pParaContext->end())
2228         {
2229             aLocaleIter->second >>= rLocale;
2230         }
2231     }
2232 }
2233 
2234 /*-- 14.09.2006 12:52:58---------------------------------------------------
2235     extract the number format from the command and apply the resulting number
2236     format to the XPropertySet
2237   -----------------------------------------------------------------------*/
2238 void DomainMapper_Impl::SetNumberFormat( const ::rtl::OUString& rCommand,
2239                             uno::Reference< beans::XPropertySet >& xPropertySet )
2240 {
2241     OUString sFormatString = lcl_ParseFormat( rCommand );
2242     // find \h - hijri/luna calendar todo: what about saka/era calendar?
2243     bool bHijri = 0 < rCommand.indexOf( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\h ")));
2244     lang::Locale aUSLocale;
2245     aUSLocale.Language = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en"));
2246     aUSLocale.Country = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("US"));
2247 
2248     //determine current locale - todo: is it necessary to initialize this locale?
2249     lang::Locale aCurrentLocale = aUSLocale;
2250     GetCurrentLocale( aCurrentLocale );
2251     ::rtl::OUString sFormat = ConversionHelper::ConvertMSFormatStringToSO( sFormatString, aCurrentLocale, bHijri);
2252 
2253     //get the number formatter and convert the string to a format value
2254     try
2255     {
2256         uno::Reference< util::XNumberFormatsSupplier > xNumberSupplier( m_xTextDocument, uno::UNO_QUERY_THROW );
2257         long nKey = xNumberSupplier->getNumberFormats()->addNewConverted( sFormat, aUSLocale, aCurrentLocale );
2258         xPropertySet->setPropertyValue(
2259             PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_NUMBER_FORMAT),
2260             uno::makeAny( nKey ));
2261     }
2262     catch(const uno::Exception&)
2263     {
2264     }
2265 }
2266 
2267 /*-- 15.09.2006 15:10:20---------------------------------------------------
2268 
2269   -----------------------------------------------------------------------*/
2270 uno::Reference< beans::XPropertySet > DomainMapper_Impl::FindOrCreateFieldMaster(
2271         const sal_Char* pFieldMasterService, const ::rtl::OUString& rFieldMasterName )
2272             throw(::com::sun::star::uno::Exception)
2273 {
2274     // query master, create if not available
2275     uno::Reference< text::XTextFieldsSupplier > xFieldsSupplier( GetTextDocument(), uno::UNO_QUERY );
2276     uno::Reference< container::XNameAccess > xFieldMasterAccess = xFieldsSupplier->getTextFieldMasters();
2277     uno::Reference< beans::XPropertySet > xMaster;
2278     ::rtl::OUString sFieldMasterService( ::rtl::OUString::createFromAscii(pFieldMasterService) );
2279     ::rtl::OUStringBuffer aFieldMasterName;
2280     aFieldMasterName.appendAscii( pFieldMasterService );
2281     aFieldMasterName.append(sal_Unicode('.'));
2282     aFieldMasterName.append(rFieldMasterName);
2283     ::rtl::OUString sFieldMasterName = aFieldMasterName.makeStringAndClear();
2284     if(xFieldMasterAccess->hasByName(sFieldMasterName))
2285     {
2286         //get the master
2287         xMaster = uno::Reference< beans::XPropertySet >(xFieldMasterAccess->getByName(sFieldMasterName),
2288                                                                             uno::UNO_QUERY_THROW);
2289     }
2290     else
2291     {
2292         //create the master
2293         xMaster = uno::Reference< beans::XPropertySet >(
2294                 m_xTextFactory->createInstance(sFieldMasterService), uno::UNO_QUERY_THROW);
2295         //set the master's name
2296 //        sal_Int32 nIndex = rtl_str_indexOfStr( pFieldMasterService, "Database" );
2297 //        if( nIndex < 0 )
2298             xMaster->setPropertyValue(
2299                     PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_NAME),
2300                     uno::makeAny(rFieldMasterName));
2301 //        else
2302 //        {
2303 //            xMaster->setPropertyValue(
2304 //                    PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_DATA_COLUMN_NAME),
2305 //                    uno::makeAny(rFieldMasterName));
2306 //        }
2307     }
2308     return xMaster;
2309 }
2310 
2311 /*-- 29.01.2007 11:33:10---------------------------------------------------
2312 //field context starts with a 0x13
2313   -----------------------------------------------------------------------*/
2314 void DomainMapper_Impl::PushFieldContext()
2315 {
2316 #ifdef DEBUG_DOMAINMAPPER
2317     dmapper_logger->element("pushFieldContext");
2318 #endif
2319 
2320     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
2321     //insert a dummy char to make sure the start range doesn't move together with the to-be-appended text
2322     xTextAppend->appendTextPortion(::rtl::OUString( '-' ), uno::Sequence< beans::PropertyValue >() );
2323     uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange( xTextAppend->getEnd() );
2324     xCrsr->goLeft( 1, false );
2325     m_aFieldStack.push( FieldContextPtr( new FieldContext( xCrsr->getStart() ) ) );
2326 }
2327 /*-- 29.01.2007 11:33:13---------------------------------------------------
2328 //the current field context waits for the completion of the command
2329   -----------------------------------------------------------------------*/
2330 bool DomainMapper_Impl::IsOpenFieldCommand() const
2331 {
2332     return !m_aFieldStack.empty() && !m_aFieldStack.top()->IsCommandCompleted();
2333 }
2334 /*-- 29.01.2007 11:33:13---------------------------------------------------
2335 //the current field context waits for the completion of the command
2336   -----------------------------------------------------------------------*/
2337 bool DomainMapper_Impl::IsOpenField() const
2338 {
2339     return !m_aFieldStack.empty();
2340 }
2341 /*-- 29.01.2007 11:49:13---------------------------------------------------
2342 
2343   -----------------------------------------------------------------------*/
2344 FieldContext::FieldContext(uno::Reference< text::XTextRange > xStart) :
2345     m_bFieldCommandCompleted( false )
2346     ,m_xStartRange( xStart )
2347 {
2348 }
2349 /*-- 29.01.2007 11:48:44---------------------------------------------------
2350 
2351   -----------------------------------------------------------------------*/
2352 FieldContext::~FieldContext()
2353 {
2354 }
2355 /*-- 29.01.2007 11:48:45---------------------------------------------------
2356 
2357   -----------------------------------------------------------------------*/
2358 void FieldContext::AppendCommand(const ::rtl::OUString& rPart)
2359 {
2360     m_sCommand += rPart;
2361 }
2362 
2363 ::std::vector<rtl::OUString> FieldContext::GetCommandParts() const
2364 {
2365     ::std::vector<rtl::OUString> aResult;
2366     sal_Int32 nIndex = 0;
2367     bool bInString = false;
2368     OUString sPart;
2369     while (nIndex != -1)
2370     {
2371         OUString sToken = GetCommand().getToken(0, ' ', nIndex);
2372         bool bInStringNext = bInString;
2373 
2374         if (sToken.getLength() == 0)
2375             continue;
2376 
2377         if (sToken.getStr()[0] == '"')
2378         {
2379             bInStringNext = true;
2380             sToken = sToken.copy(1);
2381         }
2382         if (sToken.getStr()[sToken.getLength() - 1] == '"')
2383         {
2384             bInStringNext = false;
2385             sToken = sToken.copy(0, sToken.getLength() - 1);
2386         }
2387 
2388         if (bInString)
2389         {
2390             if (bInStringNext)
2391             {
2392                 sPart += OUString(' ');
2393                 sPart += sToken;
2394             }
2395             else
2396             {
2397                 sPart += sToken;
2398                 aResult.push_back(sPart);
2399             }
2400         }
2401         else
2402         {
2403             if (bInStringNext)
2404             {
2405                 sPart = sToken;
2406             }
2407             else
2408             {
2409                 aResult.push_back(sToken);
2410             }
2411         }
2412 
2413         bInString = bInStringNext;
2414     }
2415 
2416     return aResult;
2417 }
2418 
2419 /*-- 29.01.2007 11:33:15---------------------------------------------------
2420 //collect the pieces of the command
2421   -----------------------------------------------------------------------*/
2422 void DomainMapper_Impl::AppendFieldCommand(::rtl::OUString& rPartOfCommand)
2423 {
2424 #ifdef DEBUG_DOMAINMAPPER
2425     dmapper_logger->startElement("appendFieldCommand");
2426     dmapper_logger->chars(rPartOfCommand);
2427     dmapper_logger->endElement("appendFieldCommand");
2428 #endif
2429 
2430     FieldContextPtr pContext = m_aFieldStack.top();
2431     OSL_ENSURE( pContext.get(), "no field context available");
2432     if( pContext.get() )
2433     {
2434         pContext->AppendCommand( rPartOfCommand );
2435     }
2436 }
2437 /*-- 13.12.2007 11:45:43---------------------------------------------------
2438 
2439   -----------------------------------------------------------------------*/
2440 typedef std::multimap < sal_Int32, ::rtl::OUString > TOCStyleMap;
2441 
2442 const FieldConversionMap_t & lcl_GetFieldConversion()
2443 {
2444 static FieldConversionMap_t aFieldConversionMap;
2445 static bool bFilled = false;
2446 if(!bFilled)
2447 {
2448     static const FieldConversion aFields[] =
2449     {
2450 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ADDRESSBLOCK")),  "",                         "", FIELD_ADDRESSBLOCK  },
2451 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ADVANCE")),       "",                         "", FIELD_ADVANCE       },
2452         {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ASK")),           "SetExpression",             "SetExpression", FIELD_ASK      },
2453             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTONUM")),       "SetExpression",            "SetExpression", FIELD_AUTONUM   },
2454             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTONUMLGL")),     "SetExpression",            "SetExpression", FIELD_AUTONUMLGL },
2455             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTONUMOUT")),     "SetExpression",            "SetExpression", FIELD_AUTONUMOUT },
2456             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTHOR")),        "Author",                   "", FIELD_AUTHOR       },
2457             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DATE")),          "DateTime",                 "", FIELD_DATE         },
2458             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("COMMENTS")),      "DocInfo.Description",      "", FIELD_COMMENTS     },
2459             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CREATEDATE")),    "DocInfo.CreateDateTime",   "", FIELD_CREATEDATE   },
2460             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOCPROPERTY")),   "",                         "", FIELD_DOCPROPERTY },
2461             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOCVARIABLE")),   "User",                     "", FIELD_DOCVARIABLE  },
2462             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EDITTIME")),      "DocInfo.EditTime",         "", FIELD_EDITTIME     },
2463             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILLIN")),        "Input",                    "", FIELD_FILLIN       },
2464             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILENAME")),      "FileName",                 "", FIELD_FILENAME     },
2465 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILESIZE")),      "",                         "", FIELD_FILESIZE     },
2466 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMULA")),     "",                           "", FIELD_FORMULA },
2467             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMCHECKBOX")),     "",                           "", FIELD_FORMCHECKBOX},
2468 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMDROPDOWN")),     "",                           "", FIELD_FORMDROWDOWN},
2469             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMTEXT")),     "Input", "", FIELD_FORMTEXT},
2470 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GOTOBUTTON")),    "",                         "", FIELD_GOTOBUTTON   },
2471             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HYPERLINK")),     "",                         "", FIELD_HYPERLINK    },
2472             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IF")),            "ConditionalText",          "", FIELD_IF           },
2473 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INFO")),      "","", FIELD_INFO         },
2474 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INCLUDEPICTURE")), "",                        "", FIELD_INCLUDEPICTURE},
2475             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("KEYWORDS")),      "DocInfo.KeyWords",         "", FIELD_KEYWORDS     },
2476             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LASTSAVEDBY")),   "DocInfo.ChangeAuthor",                         "", FIELD_LASTSAVEDBY  },
2477             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MACROBUTTON")),   "Macro",                         "", FIELD_MACROBUTTON  },
2478             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MERGEFIELD")),    "Database",                 "Database", FIELD_MERGEFIELD},
2479             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MERGEREC")),      "DatabaseNumberOfSet",      "", FIELD_MERGEREC     },
2480 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MERGESEQ")),      "",                         "", FIELD_MERGESEQ     },
2481             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NEXT")),          "DatabaseNextSet",          "", FIELD_NEXT         },
2482             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NEXTIF")),        "DatabaseNextSet",          "", FIELD_NEXTIF       },
2483             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PAGE")),          "PageNumber",               "", FIELD_PAGE         },
2484             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REF")),           "GetReference",             "", FIELD_REF          },
2485             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REVNUM")),        "DocInfo.Revision",         "", FIELD_REVNUM       },
2486             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SAVEDATE")),      "DocInfo.Change",           "", FIELD_SAVEDATE     },
2487 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SECTION")),       "",                         "", FIELD_SECTION      },
2488 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SECTIONPAGES")),  "",                         "", FIELD_SECTIONPAGES },
2489             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SEQ")),           "SetExpression",            "SetExpression", FIELD_SEQ          },
2490 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SET")),           "","", FIELD_SET          },
2491 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SKIPIF")),"",                                 "", FIELD_SKIPIF       },
2492 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("STYLEREF")),"",                               "", FIELD_STYLEREF     },
2493             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SUBJECT")),       "DocInfo.Subject",          "", FIELD_SUBJECT      },
2494 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SYMBOL")),"",                                 "", FIELD_SYMBOL       },
2495             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TEMPLATE")),      "TemplateName",             "", FIELD_TEMPLATE},
2496             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TIME")),          "DateTime",                 "", FIELD_TIME         },
2497             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TITLE")),         "DocInfo.Title",            "", FIELD_TITLE        },
2498             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("USERINITIALS")),  "ExtendedUser",              "", FIELD_USERINITIALS},
2499 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("USERADDRESS")),   "",                         "", FIELD_USERADDRESS  },
2500 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("USERNAME")),      "ExtendedUser",             "", FIELD_USERNAME     }
2501             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TOC")), "com.sun.star.text.ContentIndex", "", FIELD_TOC},
2502             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TC")), "com.sun.star.text.ContentIndexMark", "", FIELD_TC},
2503             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NUMCHARS")), "CharacterCount", "", FIELD_NUMCHARS},
2504             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NUMWORDS")), "WordCount", "", FIELD_NUMWORDS},
2505             {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NUMPAGES")), "PageCount", "", FIELD_NUMPAGES},
2506 
2507 //            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("")), "", "", FIELD_},
2508 
2509         };
2510         size_t nConversions = sizeof(aFields)/sizeof(FieldConversion);
2511         for( size_t nConversion = 0; nConversion < nConversions; ++nConversion)
2512         {
2513             aFieldConversionMap.insert( FieldConversionMap_t::value_type(
2514                 aFields[nConversion].sWordCommand,
2515                 aFields[nConversion] ));
2516         }
2517 
2518         bFilled = true;
2519     }
2520 
2521     return aFieldConversionMap;
2522 }
2523 
2524 void DomainMapper_Impl::handleFieldAsk
2525     (FieldContextPtr pContext,
2526      PropertyNameSupplier& rPropNameSupplier,
2527      uno::Reference< uno::XInterface > & xFieldInterface,
2528      uno::Reference< beans::XPropertySet > xFieldProperties)
2529 {
2530     //doesn the command contain a variable name?
2531     ::rtl::OUString sVariable, sHint;
2532 
2533     sVariable = lcl_ExctractAskVariableAndHint( pContext->GetCommand(),
2534         sHint );
2535     if(sVariable.getLength())
2536     {
2537         // determine field master name
2538         uno::Reference< beans::XPropertySet > xMaster =
2539             FindOrCreateFieldMaster
2540             ("com.sun.star.text.FieldMaster.SetExpression", sVariable );
2541 
2542         // attach the master to the field
2543         uno::Reference< text::XDependentTextField > xDependentField
2544             ( xFieldInterface, uno::UNO_QUERY_THROW );
2545         xDependentField->attachTextFieldMaster( xMaster );
2546 
2547         // set input flag at the field
2548         xFieldProperties->setPropertyValue(
2549             rPropNameSupplier.GetName(PROP_IS_INPUT), uno::makeAny( true ));
2550         // set the prompt
2551         xFieldProperties->setPropertyValue(
2552             rPropNameSupplier.GetName(PROP_HINT),
2553             uno::makeAny( sHint ));
2554     }
2555     else
2556     {
2557         //don't insert the field
2558         //todo: maybe import a 'normal' input field here?
2559         xFieldInterface = 0;
2560     }
2561 }
2562 
2563 void DomainMapper_Impl::handleAutoNum
2564     (FieldContextPtr pContext,
2565     PropertyNameSupplier& rPropNameSupplier,
2566     uno::Reference< uno::XInterface > & xFieldInterface,
2567     uno::Reference< beans::XPropertySet > xFieldProperties)
2568 {
2569     //create a sequence field master "AutoNr"
2570     uno::Reference< beans::XPropertySet > xMaster =
2571     FindOrCreateFieldMaster
2572         ("com.sun.star.text.FieldMaster.SetExpression",
2573         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoNr") ));
2574 
2575     xMaster->setPropertyValue( rPropNameSupplier.GetName(PROP_SUB_TYPE),
2576         uno::makeAny(text::SetVariableType::SEQUENCE));
2577 
2578     //apply the numbering type
2579     xFieldProperties->setPropertyValue(
2580         rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
2581         uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
2582         // attach the master to the field
2583     uno::Reference< text::XDependentTextField > xDependentField
2584         ( xFieldInterface, uno::UNO_QUERY_THROW );
2585     xDependentField->attachTextFieldMaster( xMaster );
2586 }
2587 
2588 void DomainMapper_Impl::handleAuthor
2589     (FieldContextPtr pContext,
2590     PropertyNameSupplier& rPropNameSupplier,
2591      uno::Reference< uno::XInterface > & /*xFieldInterface*/,
2592      uno::Reference< beans::XPropertySet > xFieldProperties)
2593 {
2594     xFieldProperties->setPropertyValue
2595         ( rPropNameSupplier.GetName(PROP_FULL_NAME), uno::makeAny( true ));
2596     ::rtl::OUString sParam =
2597         lcl_ExtractParameter(pContext->GetCommand(), sizeof(" AUTHOR") );
2598     if(sParam.getLength())
2599     {
2600         xFieldProperties->setPropertyValue(
2601                 rPropNameSupplier.GetName( PROP_IS_FIXED ),
2602                 uno::makeAny( true ));
2603         //PROP_CURRENT_PRESENTATION is set later anyway
2604     }
2605 }
2606 
2607     void DomainMapper_Impl::handleDocProperty
2608         (FieldContextPtr pContext,
2609         PropertyNameSupplier& rPropNameSupplier,
2610         uno::Reference< uno::XInterface > & xFieldInterface,
2611         uno::Reference< beans::XPropertySet > xFieldProperties)
2612 {
2613     //some docproperties should be imported as document statistic fields, some as DocInfo fields
2614     //others should be user fields
2615     ::rtl::OUString sParam =
2616         lcl_ExtractParameter(pContext->GetCommand(), sizeof(" DOCPROPERTY") );
2617 
2618     if(sParam.getLength())
2619     {
2620         #define SET_ARABIC      0x01
2621         #define SET_FULL_NAME   0x02
2622         struct DocPropertyMap
2623         {
2624             const sal_Char* pDocPropertyName;
2625             const sal_Char* pServiceName;
2626             sal_uInt8       nFlags;
2627         };
2628         static const DocPropertyMap aDocProperties[] =
2629         {
2630             {"Author",           "Author",                  SET_FULL_NAME},
2631             {"CreateTime",       "DocInfo.CreateDateTime",  0},
2632             {"Characters",       "CharacterCount",          SET_ARABIC},
2633             {"Comments",         "DocInfo.Description",     0},
2634             {"Keywords",         "DocInfo.KeyWords",        0},
2635             {"LastPrinted",      "DocInfo.PrintDateTime",   0},
2636             {"LastSavedBy",      "DocInfo.ChangeAuthor",    0},
2637             {"LastSavedTime",    "DocInfo.ChangeDateTime",  0},
2638             {"Paragraphs",       "ParagraphCount",          SET_ARABIC},
2639             {"RevisionNumber",   "DocInfo.Revision",        0},
2640             {"Subject",          "DocInfo.Subject",         0},
2641             {"Template",         "TemplateName",            0},
2642             {"Title",            "DocInfo.Title",           0},
2643             {"TotalEditingTime", "DocInfo.EditTime",        9},
2644             {"Words",            "WordCount",               SET_ARABIC}
2645 
2646             //other available DocProperties:
2647             //Bytes, Category, CharactersWithSpaces, Company
2648             //HyperlinkBase,
2649             //Lines, Manager, NameofApplication, ODMADocId, Pages,
2650             //Security,
2651         };
2652         //search for a field mapping
2653         ::rtl::OUString sFieldServiceName;
2654         sal_uInt16 nMap = 0;
2655         for( ; nMap < sizeof(aDocProperties) / sizeof(DocPropertyMap);
2656             ++nMap )
2657         {
2658             if(sParam.equalsAscii(aDocProperties[nMap].pDocPropertyName))
2659             {
2660                 sFieldServiceName =
2661                 ::rtl::OUString::createFromAscii
2662                 (aDocProperties[nMap].pServiceName);
2663                 break;
2664             }
2665         }
2666         ::rtl::OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM
2667             ("com.sun.star.text.TextField."));
2668         bool bIsCustomField = false;
2669         if(!sFieldServiceName.getLength())
2670         {
2671             //create a custom property field
2672             sServiceName +=
2673                 ::rtl::OUString::createFromAscii("DocInfo.Custom");
2674             bIsCustomField = true;
2675         }
2676         else
2677         {
2678             sServiceName += sFieldServiceName;
2679         }
2680         xFieldInterface = m_xTextFactory->createInstance(sServiceName);
2681         xFieldProperties =
2682             uno::Reference< beans::XPropertySet >( xFieldInterface,
2683                 uno::UNO_QUERY_THROW);
2684         if( bIsCustomField )
2685             xFieldProperties->setPropertyValue(
2686                 rPropNameSupplier.GetName(PROP_NAME), uno::makeAny( sParam ));
2687         else
2688         {
2689             if(0 != (aDocProperties[nMap].nFlags & SET_ARABIC))
2690                 xFieldProperties->setPropertyValue(
2691                     rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
2692                     uno::makeAny( style::NumberingType::ARABIC ));
2693             else if(0 != (aDocProperties[nMap].nFlags & SET_FULL_NAME))
2694                 xFieldProperties->setPropertyValue(
2695                     rPropNameSupplier.GetName(PROP_FULL_NAME),
2696                         uno::makeAny( true ));
2697         }
2698     }
2699 
2700 #undef SET_ARABIC
2701 #undef SET_FULL_NAME
2702 }
2703 
2704 void DomainMapper_Impl::handleToc
2705     (FieldContextPtr pContext,
2706     PropertyNameSupplier& rPropNameSupplier,
2707      uno::Reference< uno::XInterface > & /*xFieldInterface*/,
2708      uno::Reference< beans::XPropertySet > /*xFieldProperties*/,
2709     const ::rtl::OUString & sTOCServiceName)
2710 {
2711     ::rtl::OUString sValue;
2712     bool bTableOfFigures = false;
2713     bool bHyperlinks = false;
2714     bool bFromOutline = false;
2715     bool bFromEntries = false;
2716     sal_Int16 nMaxLevel = 10;
2717     ::rtl::OUString sTemplate;
2718     ::rtl::OUString sChapterNoSeparator;
2719 //                  \a Builds a table of figures but does not include the captions's label and number
2720     if( lcl_FindInCommand( pContext->GetCommand(), 'a', sValue ))
2721     { //make it a table of figures
2722         bTableOfFigures = true;
2723     }
2724 //                  \b Uses a bookmark to specify area of document from which to build table of contents
2725 //                    if( lcl_FindInCommand( pContext->GetCommand(), 'b', sValue ))
2726 //                    { //todo: sValue contains the bookmark name - unsupported feature
2727 //                    }
2728     if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue ))
2729 //                  \c Builds a table of figures of the given label
2730     {
2731                         //todo: sValue contains the label's name
2732         bTableOfFigures = true;
2733     }
2734 //                  \d Defines the separator between sequence and page numbers
2735     if( lcl_FindInCommand( pContext->GetCommand(), 'd', sValue ))
2736     {
2737                         //todo: insert the chapter number into each level and insert the separator additionally
2738         sChapterNoSeparator = sValue;
2739     }
2740 //                  \f Builds a table of contents using TC entries instead of outline levels
2741     if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue ))
2742     {
2743                         //todo: sValue can contain a TOC entry identifier - use unclear
2744         bFromEntries = true;
2745     }
2746 //                  \h Hyperlinks the entries and page numbers within the table of contents
2747     if( lcl_FindInCommand( pContext->GetCommand(), 'h', sValue ))
2748     {
2749                         //todo: make all entries to hyperlinks
2750         bHyperlinks = true;
2751     }
2752 //                  \l Defines the TC entries field level used to build a table of contents
2753 //                    if( lcl_FindInCommand( pContext->GetCommand(), 'l', sValue ))
2754 //                    {
2755                             //todo: entries can only be included completely
2756 //                    }
2757 //                  \n Builds a table of contents or a range of entries, sucah as ?-9? in a table of contents without page numbers
2758 //                    if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue ))
2759 //                    {
2760                         //todo: what does the description mean?
2761 //                    }
2762 //                  \o  Builds a table of contents by using outline levels instead of TC entries
2763     if( lcl_FindInCommand( pContext->GetCommand(), 'o', sValue ))
2764     {
2765         bFromOutline = true;
2766         UniString sParam( sValue );
2767         if (!sParam.Len())
2768             nMaxLevel = WW_OUTLINE_MAX;
2769         else
2770         {
2771             xub_StrLen nIndex = 0;
2772             sParam.GetToken( 0, '-', nIndex );
2773             nMaxLevel = sal_Int16( sParam.Copy( nIndex ).ToInt32( ) );
2774         }
2775     }
2776 //                  \p Defines the separator between the table entry and its page number
2777     if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue ))
2778         {  }
2779 //                  \s  Builds a table of contents by using a sequence type
2780     if( lcl_FindInCommand( pContext->GetCommand(), 's', sValue ))
2781         {  }
2782 //                  \t  Builds a table of contents by using style names other than the standard outline styles
2783     if( lcl_FindInCommand( pContext->GetCommand(), 't', sValue ))
2784     {
2785         sal_Int32 nPos = 0;
2786         ::rtl::OUString sToken = sValue.getToken( 1, '"', nPos);
2787         sTemplate = sToken.getLength() ? sToken : sValue;
2788     }
2789 //                  \u  Builds a table of contents by using the applied paragraph outline level
2790     if( lcl_FindInCommand( pContext->GetCommand(), 'u', sValue ))
2791     {
2792         bFromOutline = true;
2793                         //todo: what doesn 'the applied paragraph outline level' refer to?
2794     }
2795 //                  \w Preserve tab characters within table entries
2796 //                    if( lcl_FindInCommand( pContext->GetCommand(), 'w', sValue ))
2797 //                    {
2798                         //todo: not supported
2799 //                    }
2800 //                  \x Preserve newline characters within table entries
2801 //                    if( lcl_FindInCommand( pContext->GetCommand(), 'x', sValue ))
2802 //                    {
2803                         //todo: unsupported
2804 //                    }
2805 //                  \z Hides page numbers within the table of contens when shown in Web Layout View
2806 //                    if( lcl_FindInCommand( pContext->GetCommand(), 'z', sValue ))
2807 //                    { //todo: unsupported feature  }
2808 
2809                     //if there's no option then it should be created from outline
2810     if( !bFromOutline && !bFromEntries && !sTemplate.getLength()  )
2811         bFromOutline = true;
2812 
2813     uno::Reference< beans::XPropertySet > xTOC(
2814         m_xTextFactory->createInstance
2815         ( bTableOfFigures ?
2816               ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM
2817                 ("com.sun.star.text.IllustrationsIndex"))
2818             : sTOCServiceName),
2819          uno::UNO_QUERY_THROW);
2820     xTOC->setPropertyValue(rPropNameSupplier.GetName( PROP_TITLE ), uno::makeAny(::rtl::OUString()));
2821     if( !bTableOfFigures )
2822     {
2823         xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_LEVEL ), uno::makeAny( nMaxLevel ) );
2824         xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_OUTLINE ), uno::makeAny( bFromOutline ));
2825         xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_MARKS ), uno::makeAny( bFromEntries ));
2826         if( sTemplate.getLength() )
2827         {
2828                             //the string contains comma separated the names and related levels
2829                             //like: "Heading 1,1,Heading 2,2"
2830             TOCStyleMap aMap;
2831             sal_Int32 nLevel;
2832             sal_Int32 nPosition = 0;
2833             while( nPosition >= 0)
2834             {
2835                 ::rtl::OUString sStyleName = sTemplate.getToken( 0, ',', nPosition );
2836                                 //empty tokens should be skipped
2837                 while( !sStyleName.getLength() && nPosition > 0 )
2838                     sStyleName = sTemplate.getToken( 0, ',', nPosition );
2839                 nLevel = sTemplate.getToken( 0, ',', nPosition ).toInt32();
2840                 if( !nLevel )
2841                     nLevel = 1;
2842                 if( sStyleName.getLength() )
2843                     aMap.insert( TOCStyleMap::value_type(nLevel, sStyleName) );
2844             }
2845             uno::Reference< container::XIndexReplace> xParaStyles;
2846             xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_PARAGRAPH_STYLES)) >>= xParaStyles;
2847             for( nLevel = 1; nLevel < 10; ++nLevel)
2848             {
2849                 sal_Int32 nLevelCount = aMap.count( nLevel );
2850                 if( nLevelCount  )
2851                 {
2852                     TOCStyleMap::iterator aTOCStyleIter = aMap.find( nLevel );
2853 
2854                     uno::Sequence< rtl::OUString> aStyles( nLevelCount );
2855                     for ( sal_Int32 nStyle = 0; nStyle < nLevelCount; ++nStyle, ++aTOCStyleIter )
2856                     {
2857                         aStyles[nStyle] = aTOCStyleIter->second;
2858                     }
2859                     xParaStyles->replaceByIndex(nLevel - 1, uno::makeAny(aStyles));
2860                 }
2861             }
2862             xTOC->setPropertyValue(rPropNameSupplier.GetName(PROP_CREATE_FROM_LEVEL_PARAGRAPH_STYLES), uno::makeAny( true ));
2863 
2864         }
2865         if(bHyperlinks  || sChapterNoSeparator.getLength())
2866         {
2867             uno::Reference< container::XIndexReplace> xLevelFormats;
2868             xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_FORMAT)) >>= xLevelFormats;
2869             sal_Int32 nLevelCount = xLevelFormats->getCount();
2870                             //start with level 1, 0 is the header level
2871             for( sal_Int32 nLevel = 1; nLevel < nLevelCount; ++nLevel)
2872             {
2873                 uno::Sequence< beans::PropertyValues > aLevel;
2874                 xLevelFormats->getByIndex( nLevel ) >>= aLevel;
2875                                 //create a copy of the level and add two new entries - hyperlink start and end
2876                 bool bChapterNoSeparator  = sChapterNoSeparator.getLength() > 0;
2877                 sal_Int32 nAdd = (bHyperlinks && bChapterNoSeparator) ? 4 : 2;
2878                 uno::Sequence< beans::PropertyValues > aNewLevel( aLevel.getLength() + nAdd);
2879                 beans::PropertyValues* pNewLevel = aNewLevel.getArray();
2880                 if( bHyperlinks )
2881                 {
2882                     beans::PropertyValues aHyperlink(1);
2883                     aHyperlink[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
2884                     aHyperlink[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_HYPERLINK_START );
2885                     pNewLevel[0] = aHyperlink;
2886                     aHyperlink[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_HYPERLINK_END );
2887                     pNewLevel[aNewLevel.getLength() -1] = aHyperlink;
2888                 }
2889                 if( bChapterNoSeparator )
2890                 {
2891                     beans::PropertyValues aChapterNo(2);
2892                     aChapterNo[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
2893                     aChapterNo[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_CHAPTER_INFO );
2894                     aChapterNo[1].Name = rPropNameSupplier.GetName( PROP_CHAPTER_FORMAT );
2895                                     //todo: is ChapterFormat::Number correct?
2896                     aChapterNo[1].Value <<= (sal_Int16)text::ChapterFormat::NUMBER;
2897                     pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 4 : 2) ] = aChapterNo;
2898 
2899                     beans::PropertyValues aChapterSeparator(2);
2900                     aChapterSeparator[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
2901                     aChapterSeparator[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_TEXT );
2902                     aChapterSeparator[1].Name = rPropNameSupplier.GetName( PROP_TEXT );
2903                     aChapterSeparator[1].Value <<= sChapterNoSeparator;
2904                     pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 3 : 1)] = aChapterSeparator;
2905                 }
2906                                 //copy the 'old' entries except the last (page no)
2907                 for( sal_Int32 nToken = 0; nToken < aLevel.getLength() - 1; ++nToken)
2908                 {
2909                     pNewLevel[nToken + 1] = aLevel[nToken];
2910                 }
2911                                 //copy page no entry (last or last but one depending on bHyperlinks
2912                 sal_Int32 nPageNo = aNewLevel.getLength() - (bHyperlinks ? 2 : 3);
2913                 pNewLevel[nPageNo] = aLevel[aLevel.getLength() - 1];
2914 
2915                 xLevelFormats->replaceByIndex( nLevel, uno::makeAny( aNewLevel ) );
2916             }
2917         }
2918     }
2919     pContext->SetTOC( xTOC );
2920 }
2921 
2922 void DomainMapper_Impl::AddAnnotationPosition(
2923     const bool bStart,
2924     const sal_Int32 nAnnotationId )
2925 {
2926     if (m_aTextAppendStack.empty())
2927         return;
2928 
2929     // Create a cursor, pointing to the current position.
2930     uno::Reference<text::XTextAppend>  xTextAppend = m_aTextAppendStack.top().xTextAppend;
2931     uno::Reference<text::XTextRange> xCurrent;
2932     if (xTextAppend.is())
2933     {
2934         uno::Reference<text::XTextCursor> xCursor = xTextAppend->createTextCursorByRange(xTextAppend->getEnd());
2935         xCurrent = xCursor->getStart();
2936     }
2937 
2938     // And save it, to be used by PopAnnotation() later.
2939     AnnotationPosition& aAnnotationPosition = m_aAnnotationPositions[ nAnnotationId ];
2940     if ( bStart )
2941     {
2942         aAnnotationPosition.m_xStart = xCurrent;
2943     }
2944     else
2945     {
2946         aAnnotationPosition.m_xEnd = xCurrent;
2947     }
2948     m_aAnnotationPositions[ nAnnotationId ] = aAnnotationPosition;
2949 }
2950 
2951 /*-- 29.01.2007 11:33:16---------------------------------------------------
2952 //the field command has to be closed (0x14 appeared)
2953   -----------------------------------------------------------------------*/
2954 void DomainMapper_Impl::CloseFieldCommand()
2955 {
2956 #ifdef DEBUG_DOMAINMAPPER
2957     dmapper_logger->element("closeFieldCommand");
2958 #endif
2959 
2960     FieldContextPtr pContext = m_aFieldStack.top();
2961     OSL_ENSURE( pContext.get(), "no field context available");
2962     if( pContext.get() )
2963     {
2964         m_bSetUserFieldContent = false;
2965         FieldConversionMap_t aFieldConversionMap = lcl_GetFieldConversion();
2966 
2967         try
2968         {
2969             uno::Reference< uno::XInterface > xFieldInterface;
2970             //at first determine the field type - erase leading and trailing whitespaces
2971             ::rtl::OUString sCommand( pContext->GetCommand().trim() );
2972             sal_Int32 nSpaceIndex = sCommand.indexOf( ' ' );
2973             if( 0 <= nSpaceIndex )
2974                 sCommand = sCommand.copy( 0, nSpaceIndex );
2975 
2976             FieldConversionMap_t::iterator aIt = aFieldConversionMap.find(sCommand);
2977             if(aIt != aFieldConversionMap.end())
2978             {
2979                 uno::Reference< beans::XPropertySet > xFieldProperties;
2980                 bool bCreateField = true;
2981                 switch (aIt->second.eFieldId)
2982                 {
2983                 case FIELD_HYPERLINK:
2984                 case FIELD_DOCPROPERTY:
2985                 case FIELD_TOC:
2986                 case FIELD_TC:
2987                 case FIELD_FORMCHECKBOX:
2988                     bCreateField = false;
2989                     break;
2990                 default:
2991                     break;
2992                 }
2993                 if( bCreateField)
2994                 {
2995                     //add the service prefix
2996                     OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField."));
2997                     sServiceName += ::rtl::OUString::createFromAscii(aIt->second.cFieldServiceName );
2998 
2999 #ifdef DEBUG_DOMAINMAPPER
3000                     dmapper_logger->startElement("fieldService");
3001                     dmapper_logger->chars(sServiceName);
3002                     dmapper_logger->endElement("fieldService");
3003 #endif
3004 
3005                     xFieldInterface = m_xTextFactory->createInstance(sServiceName);
3006                     xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW);
3007                 }
3008                 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
3009                 switch( aIt->second.eFieldId )
3010                 {
3011                     case FIELD_ADDRESSBLOCK: break;
3012                     case FIELD_ADVANCE     : break;
3013                     case FIELD_ASK         :
3014                         handleFieldAsk(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties);
3015                     break;
3016                     case FIELD_AUTONUM    :
3017                     case FIELD_AUTONUMLGL :
3018                     case FIELD_AUTONUMOUT :
3019                         handleAutoNum(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties);
3020                     break;
3021                     case FIELD_AUTHOR       :
3022                         handleAuthor(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties);
3023                     break;
3024                     case FIELD_DATE:
3025                     {
3026                         //not fixed,
3027                         xFieldProperties->setPropertyValue(
3028                             rPropNameSupplier.GetName(PROP_IS_FIXED),
3029                             uno::makeAny( false ));
3030                         xFieldProperties->setPropertyValue(
3031                             rPropNameSupplier.GetName(PROP_IS_DATE),
3032                             uno::makeAny( true ));
3033                         SetNumberFormat( pContext->GetCommand(), xFieldProperties );
3034                     }
3035                     break;
3036                     case FIELD_COMMENTS     :
3037                     {
3038                         ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" COMMENTS") );
3039                         if(sParam.getLength())
3040                         {
3041                             xFieldProperties->setPropertyValue(
3042                                     rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
3043                             //PROP_CURRENT_PRESENTATION is set later anyway
3044                         }
3045                     }
3046                     break;
3047                     case FIELD_CREATEDATE  :
3048                     {
3049                         SetNumberFormat( pContext->GetCommand(), xFieldProperties );
3050                     }
3051                     break;
3052                     case FIELD_DOCPROPERTY :
3053                         handleDocProperty(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties);
3054                     break;
3055                     case FIELD_DOCVARIABLE  :
3056                     {
3057                         ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" DOCVARIABLE") );
3058                         //create a user field and type
3059                         uno::Reference< beans::XPropertySet > xMaster =
3060                             FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.User", sParam );
3061                         uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
3062                         xDependentField->attachTextFieldMaster( xMaster );
3063                         m_bSetUserFieldContent = true;
3064                     }
3065                     break;
3066                     case FIELD_EDITTIME     :
3067                         //it's a numbering type, no number format! SetNumberFormat( pContext->GetCommand(), xFieldProperties );
3068                     break;
3069                     case FIELD_FILLIN       :
3070                     {
3071                         sal_Int32 nIndex = 0;
3072                         xFieldProperties->setPropertyValue(
3073                                 rPropNameSupplier.GetName(PROP_HINT), uno::makeAny( pContext->GetCommand().getToken( 1, '\"', nIndex)));
3074                     }
3075                     break;
3076                     case FIELD_FILENAME:
3077                     {
3078                         sal_Int32 nNumberingTypeIndex = pContext->GetCommand().indexOf( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\p")));
3079                         xFieldProperties->setPropertyValue(
3080                                 rPropNameSupplier.GetName(PROP_FILE_FORMAT),
3081                                 uno::makeAny( nNumberingTypeIndex > 0 ? text::FilenameDisplayFormat::FULL : text::FilenameDisplayFormat::NAME_AND_EXT ));
3082                     }
3083                     break;
3084                     case FIELD_FILESIZE     : break;
3085                     case FIELD_FORMULA : break;
3086                     case FIELD_FORMCHECKBOX :
3087                         {
3088                             FFDataHandler::Pointer_t
3089                                 pFFDataHandler(pContext->getFFDataHandler());
3090                             FormControlHelper::Pointer_t
3091                                 pFormControlHelper(new FormControlHelper
3092                                                    (FIELD_FORMCHECKBOX,
3093                                                     m_xTextDocument, pFFDataHandler));
3094                             pContext->setFormControlHelper(pFormControlHelper);
3095                         }
3096                         break;
3097                     case FIELD_FORMDROPDOWN : break;
3098                     case FIELD_FORMTEXT :
3099                     {
3100                         FFDataHandler::Pointer_t pFFDataHandler
3101                             (pContext->getFFDataHandler());
3102 
3103                         xFieldProperties->setPropertyValue
3104                             (rPropNameSupplier.GetName(PROP_HINT),
3105                             uno::makeAny(pFFDataHandler->getStatusText()));
3106                         xFieldProperties->setPropertyValue
3107                             (rPropNameSupplier.GetName(PROP_HELP),
3108                             uno::makeAny(pFFDataHandler->getHelpText()));
3109                         xFieldProperties->setPropertyValue
3110                             (rPropNameSupplier.GetName(PROP_CONTENT),
3111                             uno::makeAny(pFFDataHandler->getTextDefault()));
3112                     }
3113                     break;
3114                     case FIELD_GOTOBUTTON   : break;
3115                     case FIELD_HYPERLINK:
3116                     {
3117                         ::std::vector<rtl::OUString> aParts = pContext->GetCommandParts();
3118                         ::std::vector<rtl::OUString>::const_iterator aItEnd = aParts.end();
3119                         ::std::vector<rtl::OUString>::const_iterator aPartIt = aParts.begin();
3120 
3121                         OUString sURL;
3122 
3123                         while (aPartIt != aItEnd)
3124                         {
3125                             if (aPartIt->equalsAscii("\\l"))
3126                             {
3127                                 aPartIt++;
3128 
3129                                 if (aPartIt == aItEnd)
3130                                     break;
3131 
3132                                 sURL = OUString('#');
3133                                 sURL += *aPartIt;
3134                             }
3135                             else if (aPartIt->equalsAscii("\\m") ||
3136                                      aPartIt->equalsAscii("\\n"))
3137                             {
3138                             }
3139                             else if (aPartIt->equalsAscii("\\o") ||
3140                                      aPartIt->equalsAscii("\\t"))
3141                             {
3142                                 aPartIt++;
3143 
3144                                 if (aPartIt == aItEnd)
3145                                     break;
3146                             }
3147                             else
3148                             {
3149                                 sURL = *aPartIt;
3150                             }
3151 
3152                             aPartIt++;
3153                         }
3154 
3155                         if (sURL.getLength() > 0)
3156                         {
3157                             pContext->SetHyperlinkURL(sURL);
3158                         }
3159                     }
3160                     break;
3161                     case FIELD_IF           : break;
3162                     case FIELD_INFO         : break;
3163                     case FIELD_INCLUDEPICTURE: break;
3164                     case FIELD_KEYWORDS     :
3165                     {
3166                         ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" KEYWORDS") );
3167                         if(sParam.getLength())
3168                         {
3169                             xFieldProperties->setPropertyValue(
3170                                     rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
3171                             //PROP_CURRENT_PRESENTATION is set later anyway
3172                         }
3173                     }
3174                     break;
3175                     case FIELD_LASTSAVEDBY  : break;
3176                     case FIELD_MACROBUTTON:
3177                     {
3178                         //extract macro name
3179                         sal_Int32 nIndex = sizeof(" MACROBUTTON ");
3180                         ::rtl::OUString sMacro = pContext->GetCommand().getToken( 0, ' ', nIndex);
3181                         xFieldProperties->setPropertyValue(
3182                                 rPropNameSupplier.GetName(PROP_MACRO_NAME), uno::makeAny( sMacro ));
3183 
3184                         //extract quick help text
3185                         if( pContext->GetCommand().getLength() > nIndex + 1)
3186                         {
3187                             xFieldProperties->setPropertyValue(
3188                                 rPropNameSupplier.GetName(PROP_HINT),
3189                                 uno::makeAny( pContext->GetCommand().copy( nIndex )));
3190                         }
3191                     }
3192                     break;
3193                     case FIELD_MERGEFIELD  :
3194                     {
3195                         //todo: create a database field and fieldmaster pointing to a column, only
3196                         ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" MERGEFIELD") );
3197                         //create a user field and type
3198                         uno::Reference< beans::XPropertySet > xMaster =
3199                             FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.Database", sParam );
3200 
3201     //                    xFieldProperties->setPropertyValue(
3202     //                             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldCode")),
3203     //                             uno::makeAny( pContext->GetCommand().copy( nIndex + 1 )));
3204                         uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
3205                         xDependentField->attachTextFieldMaster( xMaster );
3206                         m_bSetUserFieldContent = true;
3207                     }
3208                     break;
3209                     case FIELD_MERGEREC     : break;
3210                     case FIELD_MERGESEQ     : break;
3211                     case FIELD_NEXT         : break;
3212                     case FIELD_NEXTIF       : break;
3213                     case FIELD_PAGE        :
3214                         xFieldProperties->setPropertyValue(
3215                             rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
3216                             uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
3217                         xFieldProperties->setPropertyValue(
3218                             rPropNameSupplier.GetName(PROP_SUB_TYPE),
3219                             uno::makeAny( text::PageNumberType_CURRENT ));
3220 
3221                     break;
3222                     case FIELD_REF:
3223                     {
3224                         ::rtl::OUString sBookmark = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" REF") );
3225                         xFieldProperties->setPropertyValue(
3226                             rPropNameSupplier.GetName(PROP_REFERENCE_FIELD_SOURCE),
3227                             uno::makeAny( sal_Int16(text::ReferenceFieldSource::BOOKMARK)) );
3228                         xFieldProperties->setPropertyValue(
3229                             rPropNameSupplier.GetName(PROP_SOURCE_NAME),
3230                             uno::makeAny( sBookmark) );
3231                         sal_Int16 nFieldPart = text::ReferenceFieldPart::TEXT;
3232                         ::rtl::OUString sValue;
3233                         if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue ))
3234                         {
3235                             //above-below
3236                             nFieldPart = text::ReferenceFieldPart::UP_DOWN;
3237                         }
3238                         xFieldProperties->setPropertyValue(
3239                                 rPropNameSupplier.GetName( PROP_REFERENCE_FIELD_PART ), uno::makeAny( nFieldPart ));
3240                     }
3241                     break;
3242                     case FIELD_REVNUM       : break;
3243                     case FIELD_SAVEDATE     :
3244                         SetNumberFormat( pContext->GetCommand(), xFieldProperties );
3245                     break;
3246                     case FIELD_SECTION      : break;
3247                     case FIELD_SECTIONPAGES : break;
3248                     case FIELD_SEQ          :
3249 					{
3250                         // command looks like: " SEQ Table \* ARABIC "
3251                         ::rtl::OUString sCmd(pContext->GetCommand());
3252                         // find the sequence name, e.g. "SEQ"
3253                         ::rtl::OUString sSeqName = lcl_FindQuotedText(sCmd, "SEQ ", '\\');
3254                         sSeqName = sSeqName.trim();
3255 
3256                         // create a sequence field master using the sequence name
3257                         uno::Reference< beans::XPropertySet > xMaster = FindOrCreateFieldMaster(
3258                                     "com.sun.star.text.FieldMaster.SetExpression",
3259                                     sSeqName);
3260 
3261                         xMaster->setPropertyValue(
3262                             rPropNameSupplier.GetName(PROP_SUB_TYPE),
3263                             uno::makeAny(text::SetVariableType::SEQUENCE));
3264 
3265                         // apply the numbering type
3266                         xFieldProperties->setPropertyValue(
3267                             rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
3268                             uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
3269 
3270                         // attach the master to the field
3271                         uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
3272                         xDependentField->attachTextFieldMaster( xMaster );
3273                     }
3274                     break;
3275                     case FIELD_SET          : break;
3276                     case FIELD_SKIPIF       : break;
3277                     case FIELD_STYLEREF     : break;
3278                     case FIELD_SUBJECT      :
3279                     {
3280                         ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" SUBJECT") );
3281                         if(sParam.getLength())
3282                         {
3283                             xFieldProperties->setPropertyValue(
3284                                     rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
3285                             //PROP_CURRENT_PRESENTATION is set later anyway
3286                         }
3287                     }
3288                     break;
3289                     case FIELD_SYMBOL       : break;
3290                     case FIELD_TEMPLATE: break;
3291                     case FIELD_TIME         :
3292                         SetNumberFormat( pContext->GetCommand(), xFieldProperties );
3293                     break;
3294                     case FIELD_TITLE        :
3295                     {
3296                         ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" TITLE") );
3297                         if(sParam.getLength())
3298                         {
3299                             xFieldProperties->setPropertyValue(
3300                                     rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
3301                             //PROP_CURRENT_PRESENTATION is set later anyway
3302                         }
3303                     }
3304                     break;
3305                     case FIELD_USERINITIALS:
3306                     {
3307                         xFieldProperties->setPropertyValue(
3308                             rPropNameSupplier.GetName(PROP_USER_DATA_TYPE), uno::makeAny( text::UserDataPart::SHORTCUT ));
3309                         //todo: if initials are provided - set them as fixed content
3310                         ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" USERINITIALS") );
3311                         if(sParam.getLength())
3312                         {
3313                             xFieldProperties->setPropertyValue(
3314                                     rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
3315                             //PROP_CURRENT_PRESENTATION is set later anyway
3316                         }
3317                     }
3318                     break;
3319                     case FIELD_USERADDRESS  : //todo: user address collects street, city ...
3320                     break;
3321                     case FIELD_USERNAME     : //todo: user name is firstname + lastname
3322                     break;
3323                     case FIELD_TOC:
3324                         handleToc(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties,
3325                                   ::rtl::OUString::createFromAscii(aIt->second.cFieldServiceName));
3326                     break;
3327                     case FIELD_TC :
3328                     {
3329                         uno::Reference< beans::XPropertySet > xTC(
3330                             m_xTextFactory->createInstance(
3331                                 ::rtl::OUString::createFromAscii(aIt->second.cFieldServiceName)),
3332                                 uno::UNO_QUERY_THROW);
3333                         ::rtl::OUString sTCText = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" TC") );
3334                         if( sTCText.getLength())
3335                             xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_ALTERNATIVE_TEXT),
3336                                 uno::makeAny(sTCText));
3337                         ::rtl::OUString sValue;
3338                         // \f TC entry in doc with multiple tables
3339     //                    if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue ))
3340     //                    {
3341                             // todo: unsupported
3342     //                    }
3343                         if( lcl_FindInCommand( pContext->GetCommand(), 'l', sValue ))
3344                         // \l Outline Level
3345                         {
3346                             sal_Int32 nLevel = sValue.toInt32();
3347                             if( sValue.getLength() && nLevel >= 0 && nLevel <= 10 )
3348                                 xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL), uno::makeAny( (sal_Int16)nLevel ));
3349                         }
3350     //                    if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue ))
3351     //                    \n Suppress page numbers
3352     //                    {
3353                             //todo: unsupported feature
3354     //                    }
3355                         pContext->SetTC( xTC );
3356                     }
3357                     break;
3358                     case  FIELD_NUMCHARS:
3359                     case  FIELD_NUMWORDS:
3360                     case  FIELD_NUMPAGES:
3361                         xFieldProperties->setPropertyValue(
3362                             rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
3363                             uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
3364                         break;
3365 
3366                 }
3367             }
3368             //set the text field if there is any
3369             pContext->SetTextField( uno::Reference< text::XTextField >( xFieldInterface, uno::UNO_QUERY ) );
3370         }
3371         catch( uno::Exception& rEx)
3372         {
3373             (void)rEx;
3374             OSL_ENSURE( false, "Exception in CloseFieldCommand()" );
3375         }
3376         pContext->SetCommandCompleted();
3377     }
3378 }
3379 /*-- 29.01.2007 11:33:16---------------------------------------------------
3380 //the _current_ fields require a string type result while TOCs accept richt results
3381   -----------------------------------------------------------------------*/
3382 bool DomainMapper_Impl::IsFieldResultAsString()
3383 {
3384     bool bRet = false;
3385     OSL_ENSURE( !m_aFieldStack.empty(), "field stack empty?");
3386     FieldContextPtr pContext = m_aFieldStack.top();
3387     OSL_ENSURE( pContext.get(), "no field context available");
3388     if( pContext.get() )
3389     {
3390         bRet = pContext->GetTextField().is();
3391     }
3392     return bRet;
3393 }
3394 /*-- 01.09.2006 11:48:09---------------------------------------------------
3395 
3396   -----------------------------------------------------------------------*/
3397 void DomainMapper_Impl::SetFieldResult( ::rtl::OUString& rResult )
3398 {
3399 #ifdef DEBUG_DOMAINMAPPER
3400     dmapper_logger->startElement("setFieldResult");
3401     dmapper_logger->chars(rResult);
3402 #endif
3403 
3404     FieldContextPtr pContext = m_aFieldStack.top();
3405     OSL_ENSURE( pContext.get(), "no field context available");
3406     if( pContext.get() )
3407     {
3408         uno::Reference<text::XTextField> xTextField = pContext->GetTextField();
3409         try
3410         {
3411             PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
3412             OSL_ENSURE( xTextField.is()
3413             //||m_xTOC.is() ||m_xTC.is()
3414             //||m_sHyperlinkURL.getLength()
3415             , "DomainMapper_Impl::SetFieldResult: field not created" );
3416             if(xTextField.is())
3417             {
3418                 try
3419                 {
3420                     if( m_bSetUserFieldContent )
3421                     {
3422                         // user field content has to be set at the field master
3423                         uno::Reference< text::XDependentTextField > xDependentField( xTextField, uno::UNO_QUERY_THROW );
3424                         xDependentField->getTextFieldMaster()->setPropertyValue(
3425                                 rPropNameSupplier.GetName(PROP_CONTENT),
3426                              uno::makeAny( rResult ));
3427                     }
3428                     else
3429                     {
3430                         uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW);
3431                         xFieldProperties->setPropertyValue(
3432                                 rPropNameSupplier.GetName(PROP_CURRENT_PRESENTATION),
3433                              uno::makeAny( rResult ));
3434                     }
3435                 }
3436                 catch( const beans::UnknownPropertyException& )
3437                 {
3438                     //some fields don't have a CurrentPresentation (DateTime)
3439                 }
3440             }
3441         }
3442         catch( uno::Exception& )
3443         {
3444 
3445         }
3446     }
3447 }
3448 
3449 void DomainMapper_Impl::SetFieldFFData(FFDataHandler::Pointer_t pFFDataHandler)
3450 {
3451 #ifdef DEBUG_DOMAINMAPPER
3452     dmapper_logger->startElement("setFieldFFData");
3453 #endif
3454 
3455     FieldContextPtr pContext = m_aFieldStack.top();
3456     if (pContext.get())
3457     {
3458         pContext->setFFDataHandler(pFFDataHandler);
3459     }
3460 
3461 #ifdef DEBUG_DOMAINMAPPER
3462     dmapper_logger->endElement("setFieldFFData");
3463 #endif
3464 }
3465 
3466 /*-- 29.01.2007 11:33:17---------------------------------------------------
3467 //the end of field is reached (0x15 appeared) - the command might still be open
3468   -----------------------------------------------------------------------*/
3469 void DomainMapper_Impl::PopFieldContext()
3470 {
3471 #ifdef DEBUG_DOMAINMAPPER
3472     dmapper_logger->element("popFieldContext");
3473 #endif
3474 
3475     FieldContextPtr pContext = m_aFieldStack.top();
3476     OSL_ENSURE( pContext.get(), "no field context available");
3477     if( pContext.get() )
3478     {
3479         if( !pContext->IsCommandCompleted() )
3480             CloseFieldCommand();
3481 
3482         //insert the field, TC or TOC
3483         uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
3484         if(xTextAppend.is())
3485         {
3486             try
3487             {
3488                 uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange(pContext->GetStartRange());
3489                 //remove the dummy character
3490                 xCrsr->goRight( 1, true );
3491                 xCrsr->setString( ::rtl::OUString() );
3492                 uno::Reference< text::XTextContent > xToInsert( pContext->GetTOC(), uno::UNO_QUERY );
3493                 if( xToInsert.is() )
3494                 {
3495                     xCrsr->gotoEnd( true );
3496                     xToInsert->attach( uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ));
3497                 }
3498                 else
3499                 {
3500                     xToInsert = uno::Reference< text::XTextContent >(pContext->GetTC(), uno::UNO_QUERY);
3501                     if( !xToInsert.is() )
3502                         xToInsert = uno::Reference< text::XTextContent >(pContext->GetTextField(), uno::UNO_QUERY);
3503                     if( xToInsert.is() )
3504                     {
3505                         uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( xTextAppend, uno::UNO_QUERY_THROW );
3506                         xTextAppendAndConvert->appendTextContent( xToInsert, uno::Sequence< beans::PropertyValue >() );
3507                     }
3508                     else
3509                     {
3510                         FormControlHelper::Pointer_t pFormControlHelper(pContext->getFormControlHelper());
3511                         if (pFormControlHelper.get() != NULL)
3512                         {
3513                             uno::Reference<text::XTextRange> xTxtRange(xCrsr, uno::UNO_QUERY);
3514                             pFormControlHelper->insertControl(xTxtRange);
3515                         }
3516                         else if(pContext->GetHyperlinkURL().getLength())
3517                         {
3518                             PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
3519                             xCrsr->gotoEnd( true );
3520 
3521                             uno::Reference< beans::XPropertySet > xCrsrProperties( xCrsr, uno::UNO_QUERY_THROW );
3522                             xCrsrProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_HYPER_LINK_U_R_L), uno::
3523                                                               makeAny(pContext->GetHyperlinkURL()));
3524                         }
3525                     }
3526                 }
3527             }
3528             catch(const lang::IllegalArgumentException& )
3529             {
3530                 OSL_ENSURE( false, "IllegalArgumentException in PopFieldContext()" );
3531             }
3532             catch(const uno::Exception& )
3533             {
3534                 OSL_ENSURE( false, "exception in PopFieldContext()" );
3535             }
3536         }
3537         //
3538         //TOCs have to include all the imported content
3539         //...
3540     }
3541     //remove the field context
3542     m_aFieldStack.pop();
3543 }
3544 /*-- 11.06.2007 16:19:00---------------------------------------------------
3545 
3546   -----------------------------------------------------------------------*/
3547 void DomainMapper_Impl::AddBookmark( const ::rtl::OUString& rBookmarkName, const ::rtl::OUString& rId )
3548 {
3549     uno::Reference< text::XTextAppend >  xTextAppend = m_aTextAppendStack.top().xTextAppend;
3550     BookmarkMap_t::iterator aBookmarkIter = m_aBookmarkMap.find( rId );
3551     //is the bookmark name already registered?
3552     try
3553     {
3554         if( aBookmarkIter != m_aBookmarkMap.end() )
3555         {
3556             static const rtl::OUString sBookmarkService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Bookmark"));
3557             uno::Reference< text::XTextContent > xBookmark( m_xTextFactory->createInstance( sBookmarkService ), uno::UNO_QUERY_THROW );
3558             uno::Reference< text::XTextCursor > xCursor;
3559             uno::Reference< text::XText > xText = aBookmarkIter->second.m_xTextRange->getText();
3560             if( aBookmarkIter->second.m_bIsStartOfText )
3561                 xCursor = xText->createTextCursorByRange( xText->getStart() );
3562             else
3563             {
3564                 xCursor = xText->createTextCursorByRange( aBookmarkIter->second.m_xTextRange );
3565                 xCursor->goRight( 1, false );
3566             }
3567 
3568             xCursor->gotoRange( xTextAppend->getEnd(), true );
3569             uno::Reference< container::XNamed > xBkmNamed( xBookmark, uno::UNO_QUERY_THROW );
3570             //todo: make sure the name is not used already!
3571             xBkmNamed->setName( aBookmarkIter->second.m_sBookmarkName );
3572             xTextAppend->insertTextContent( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW), xBookmark, !xCursor->isCollapsed() );
3573             m_aBookmarkMap.erase( aBookmarkIter );
3574         }
3575         else
3576         {
3577             //otherwise insert a text range as marker
3578             uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursorByRange( xTextAppend->getEnd() );
3579             bool bIsStart = !xCursor->goLeft(1, false);
3580             uno::Reference< text::XTextRange > xCurrent = xCursor->getStart();
3581             m_aBookmarkMap.insert(BookmarkMap_t::value_type( rId, BookmarkInsertPosition( bIsStart, rBookmarkName, xCurrent ) ));
3582         }
3583     }
3584     catch( const uno::Exception& )
3585     {
3586         //TODO: What happens to bookmarks where start and end are at different XText objects?
3587     }
3588 }
3589 /*-- 01.11.2006 14:57:44---------------------------------------------------
3590 
3591   -----------------------------------------------------------------------*/
3592 GraphicImportPtr DomainMapper_Impl::GetGraphicImport(GraphicImportType eGraphicImportType)
3593 {
3594     if(!m_pGraphicImport)
3595         m_pGraphicImport.reset( new GraphicImport( m_xComponentContext, m_xTextFactory, m_rDMapper, eGraphicImportType ) );
3596     return m_pGraphicImport;
3597 }
3598 /*-- 09.08.2007 10:19:45---------------------------------------------------
3599     reset graphic import if the last import resulted in a shape, not a graphic
3600   -----------------------------------------------------------------------*/
3601 void DomainMapper_Impl::ResetGraphicImport()
3602 {
3603     m_pGraphicImport.reset();
3604 }
3605 /*-- 01.11.2006 09:25:40---------------------------------------------------
3606 
3607   -----------------------------------------------------------------------*/
3608 void  DomainMapper_Impl::ImportGraphic(writerfilter::Reference< Properties >::Pointer_t ref, GraphicImportType eGraphicImportType)
3609 {
3610     GetGraphicImport(eGraphicImportType);
3611     if( eGraphicImportType != IMPORT_AS_DETECTED_INLINE && eGraphicImportType != IMPORT_AS_DETECTED_ANCHOR )
3612     {
3613         //create the graphic
3614         ref->resolve( *m_pGraphicImport );
3615     }
3616 
3617     //insert it into the document at the current cursor position
3618 
3619     uno::Reference<text::XTextContent> xTextContent
3620         (m_pGraphicImport->GetGraphicObject());
3621 
3622     //insert it into the document at the current cursor position
3623     OSL_ENSURE( xTextContent.is(), "DomainMapper_Impl::ImportGraphic");
3624     if( xTextContent.is())
3625         appendTextContent( xTextContent, uno::Sequence< beans::PropertyValue >() );
3626 
3627     m_pGraphicImport.reset();
3628 }
3629 
3630 /*-- 28.12.2006 14:00:47---------------------------------------------------
3631 
3632   -----------------------------------------------------------------------*/
3633 void DomainMapper_Impl::SetLineNumbering( sal_Int32 nLnnMod, sal_Int32 nLnc, sal_Int32 ndxaLnn )
3634 {
3635     if( !m_bLineNumberingSet )
3636     {
3637         const PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
3638 
3639         try
3640         {
3641             uno::Reference< text::XLineNumberingProperties > xLineProperties( m_xTextDocument, uno::UNO_QUERY_THROW );
3642             uno::Reference< beans::XPropertySet > xProperties = xLineProperties->getLineNumberingProperties();
3643             uno::Any aTrue( uno::makeAny( true ));
3644             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_IS_ON                  ), aTrue);
3645             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_COUNT_EMPTY_LINES      ), aTrue );
3646             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_COUNT_LINES_IN_FRAMES  ), uno::makeAny( false ) );
3647             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_INTERVAL               ), uno::makeAny( static_cast< sal_Int16 >( nLnnMod )));
3648             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_DISTANCE               ), uno::makeAny( ConversionHelper::convertTwipToMM100(ndxaLnn) ));
3649             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_NUMBER_POSITION        ), uno::makeAny( style::LineNumberPosition::LEFT));
3650             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_NUMBERING_TYPE         ), uno::makeAny( style::NumberingType::ARABIC));
3651             xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_RESTART_AT_EACH_PAGE   ), uno::makeAny( nLnc == 0 ));
3652         }
3653         catch( const uno::Exception& )
3654         {}
3655 
3656 
3657 
3658 /*
3659         { SW_PROP_NAME(UNO_NAME_CHAR_STYLE_NAME
3660         { SW_PROP_NAME(UNO_NAME_COUNT_EMPTY_LINES
3661         { SW_PROP_NAME(UNO_NAME_COUNT_LINES_IN_FRAMES
3662         { SW_PROP_NAME(UNO_NAME_DISTANCE
3663         { SW_PROP_NAME(UNO_NAME_IS_ON
3664         { SW_PROP_NAME(UNO_NAME_INTERVAL
3665         { SW_PROP_NAME(UNO_NAME_SEPARATOR_TEXT
3666         { SW_PROP_NAME(UNO_NAME_NUMBER_POSITION
3667         { SW_PROP_NAME(UNO_NAME_NUMBERING_TYPE
3668         { SW_PROP_NAME(UNO_NAME_RESTART_AT_EACH_PAGE
3669         { SW_PROP_NAME(UNO_NAME_SEPARATOR_INTERVAL
3670 */
3671     }
3672     m_bLineNumberingSet = true;
3673 }
3674 /*-- 31.08.2007 13:50:49---------------------------------------------------
3675 
3676   -----------------------------------------------------------------------*/
3677 void DomainMapper_Impl::SetPageMarginTwip( PageMarElement eElement, sal_Int32 nValue )
3678 {
3679     nValue = ConversionHelper::convertTwipToMM100(nValue);
3680     switch(eElement)
3681     {
3682         case PAGE_MAR_TOP    : m_aPageMargins.top     = nValue; break;
3683         case PAGE_MAR_RIGHT  : m_aPageMargins.right   = nValue; break;
3684         case PAGE_MAR_BOTTOM : m_aPageMargins.bottom  = nValue; break;
3685         case PAGE_MAR_LEFT   : m_aPageMargins.left    = nValue; break;
3686         case PAGE_MAR_HEADER : m_aPageMargins.header  = nValue; break;
3687         case PAGE_MAR_FOOTER : m_aPageMargins.footer  = nValue; break;
3688         case PAGE_MAR_GUTTER : m_aPageMargins.gutter  = nValue; break;
3689     }
3690 }
3691 
3692 /*-- 31.08.2007 13:47:50---------------------------------------------------
3693 
3694   -----------------------------------------------------------------------*/
3695 _PageMar::_PageMar()
3696 {
3697     header = footer = top = bottom = ConversionHelper::convertTwipToMM100( sal_Int32(1440));
3698     right = left = ConversionHelper::convertTwipToMM100( sal_Int32(1800));
3699     gutter = 0;
3700 }
3701 
3702 /*-- 07.03.2008 12:07:27---------------------------------------------------
3703 
3704   -----------------------------------------------------------------------*/
3705 void DomainMapper_Impl::RegisterFrameConversion(
3706         uno::Reference< text::XTextRange >      xFrameStartRange,
3707         uno::Reference< text::XTextRange >      xFrameEndRange,
3708         uno::Sequence< beans::PropertyValue >   aFrameProperties
3709         )
3710 {
3711     OSL_ENSURE(
3712         !m_aFrameProperties.getLength() && !m_xFrameStartRange.is() && !m_xFrameEndRange.is(),
3713         "frame properties not removed");
3714     m_aFrameProperties = aFrameProperties;
3715     m_xFrameStartRange = xFrameStartRange;
3716     m_xFrameEndRange   = xFrameEndRange;
3717 }
3718 /*-- 07.03.2008 12:07:33---------------------------------------------------
3719 
3720   -----------------------------------------------------------------------*/
3721 bool DomainMapper_Impl::ExecuteFrameConversion()
3722 {
3723     bool bRet = false;
3724     if( m_xFrameStartRange.is() && m_xFrameEndRange.is() )
3725     {
3726         bRet = true;
3727         try
3728         {
3729             uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( GetTopTextAppend(), uno::UNO_QUERY_THROW );
3730             xTextAppendAndConvert->convertToTextFrame(
3731                 m_xFrameStartRange,
3732                 m_xFrameEndRange,
3733                 m_aFrameProperties );
3734         }
3735         catch( const uno::Exception& rEx)
3736         {
3737             (void)rEx;
3738             bRet = false;
3739         }
3740         m_xFrameStartRange = 0;
3741         m_xFrameEndRange = 0;
3742         m_aFrameProperties.realloc( 0 );
3743     }
3744     return bRet;
3745 }
3746 
3747 void DomainMapper_Impl::AddNewRedline(  )
3748 {
3749     RedlineParamsPtr pNew( new RedlineParams );
3750     pNew->m_nToken = ooxml::OOXML_mod;
3751     if ( !m_bIsParaChange )
3752     {
3753         m_aRedlines.push_back( pNew );
3754     }
3755     else
3756     {
3757         m_pParaRedline.swap( pNew );
3758     }
3759 }
3760 
3761 RedlineParamsPtr DomainMapper_Impl::GetTopRedline(  )
3762 {
3763     RedlineParamsPtr pResult;
3764     if ( !m_bIsParaChange && m_aRedlines.size(  ) > 0 )
3765         pResult = m_aRedlines.back(  );
3766     else if ( m_bIsParaChange )
3767         pResult = m_pParaRedline;
3768     return pResult;
3769 }
3770 
3771 sal_Int32 DomainMapper_Impl::GetCurrentRedlineToken(  )
3772 {
3773     sal_Int32 nToken = 0;
3774     RedlineParamsPtr pCurrent( GetTopRedline(  ) );
3775     if ( pCurrent.get(  ) )
3776         nToken = pCurrent->m_nToken;
3777     return nToken;
3778 }
3779 
3780 void DomainMapper_Impl::SetCurrentRedlineAuthor( rtl::OUString sAuthor )
3781 {
3782     if (m_xAnnotationField.is())
3783     {
3784         m_xAnnotationField->setPropertyValue(
3785             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Author")),
3786             uno::makeAny(sAuthor) );
3787     }
3788     else
3789     {
3790         RedlineParamsPtr pCurrent( GetTopRedline(  ) );
3791         if ( pCurrent.get(  ) )
3792             pCurrent->m_sAuthor = sAuthor;
3793     }
3794 }
3795 
3796 void DomainMapper_Impl::SetCurrentRedlineInitials( rtl::OUString sInitials )
3797 {
3798     if (m_xAnnotationField.is())
3799     {
3800         m_xAnnotationField->setPropertyValue(
3801             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Initials")),
3802             uno::makeAny(sInitials) );
3803     }
3804 }
3805 
3806 void DomainMapper_Impl::SetCurrentRedlineDate( rtl::OUString sDate )
3807 {
3808     if (m_xAnnotationField.is())
3809     {
3810         m_xAnnotationField->setPropertyValue(
3811             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DateTimeValue")),
3812             uno::makeAny( ConversionHelper::convertDateTime( sDate ) ) );
3813     }
3814     else
3815     {
3816         RedlineParamsPtr pCurrent( GetTopRedline(  ) );
3817         if ( pCurrent.get(  ) )
3818             pCurrent->m_sDate = sDate;
3819     }
3820 }
3821 
3822 void DomainMapper_Impl::SetCurrentRedlineId( sal_Int32 sId )
3823 {
3824     if (m_xAnnotationField.is())
3825     {
3826         m_nAnnotationId = sId;
3827     }
3828     else
3829     {
3830         RedlineParamsPtr pCurrent( GetTopRedline(  ) );
3831         if ( pCurrent.get(  ) )
3832             pCurrent->m_nId = sId;
3833     }
3834 }
3835 
3836 void DomainMapper_Impl::SetCurrentRedlineToken( sal_Int32 nToken )
3837 {
3838     RedlineParamsPtr pCurrent( GetTopRedline(  ) );
3839     if ( pCurrent.get(  ) )
3840         pCurrent->m_nToken = nToken;
3841 }
3842 
3843 /*-- 19.03.2008 11:35:38---------------------------------------------------
3844 
3845   -----------------------------------------------------------------------*/
3846 void DomainMapper_Impl::RemoveCurrentRedline( )
3847 {
3848     if ( m_aRedlines.size( ) > 0 )
3849     {
3850         m_aRedlines.pop_back( );
3851     }
3852 }
3853 
3854 void DomainMapper_Impl::ResetParaRedline( )
3855 {
3856     if ( m_pParaRedline.get( ) )
3857     {
3858         RedlineParamsPtr pEmpty;
3859         m_pParaRedline.swap( pEmpty );
3860     }
3861 }
3862 
3863 /*-- 22.09.2009 10:26:19---------------------------------------------------
3864 
3865 -----------------------------------------------------------------------*/
3866 void DomainMapper_Impl::ApplySettingsTable()
3867 {
3868     if( m_pSettingsTable )
3869     {
3870         try
3871         {
3872             uno::Reference< beans::XPropertySet > xTextDefaults(
3873                                                                 m_xTextFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Defaults"))), uno::UNO_QUERY_THROW );
3874             sal_Int32 nDefTab = m_pSettingsTable->GetDefaultTabStop();
3875             xTextDefaults->setPropertyValue( PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_TAB_STOP_DISTANCE ), uno::makeAny(nDefTab) );
3876         }
3877         catch(const uno::Exception& )
3878         {
3879         }
3880     }
3881 }
3882 
3883 SectionPropertyMap * DomainMapper_Impl::GetSectionContext()
3884 {
3885     SectionPropertyMap* pSectionContext = 0;
3886     //the section context is not availabe before the first call of startSectionGroup()
3887     if( !IsAnyTableImport() )
3888     {
3889         PropertyMapPtr pContext = GetTopContextOfType(CONTEXT_SECTION);
3890         OSL_ENSURE(pContext.get(), "Section context is not in the stack!");
3891         pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() );
3892     }
3893 
3894     return pSectionContext;
3895 }
3896 
3897 }}
3898