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