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