Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / transform / TransformerBase.cxx
blobe7d955c414f275057567959a5445edfe6baaabc0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <rtl/ref.hxx>
21 #include <rtl/ustrbuf.hxx>
22 #include <osl/diagnose.h>
23 #include <com/sun/star/i18n/CharacterClassification.hpp>
24 #include <com/sun/star/i18n/UnicodeType.hpp>
25 #include <com/sun/star/util/MeasureUnit.hpp>
26 #include <sax/tools/converter.hxx>
27 #include <comphelper/processfactory.hxx>
28 #include <xmloff/nmspmap.hxx>
29 #include <xmloff/xmlnmspe.hxx>
30 #include "IgnoreTContext.hxx"
31 #include "RenameElemTContext.hxx"
32 #include "ProcAttrTContext.hxx"
33 #include "ProcAddAttrTContext.hxx"
34 #include "MergeElemTContext.hxx"
35 #include "CreateElemTContext.hxx"
36 #include "MutableAttrList.hxx"
37 #include "TransformerActions.hxx"
38 #include "ElemTransformerAction.hxx"
39 #include "PropertyActionsOOo.hxx"
40 #include "TransformerTokenMap.hxx"
42 #include "TransformerBase.hxx"
44 using namespace ::osl;
45 using namespace ::xmloff::token;
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::lang;
50 using namespace ::com::sun::star::i18n;
51 using namespace ::com::sun::star::xml::sax;
53 namespace
55 bool lcl_ConvertAttr( OUString & rOutAttribute, sal_Int32 nParam )
57 bool bResult = false;
58 enum XMLTokenEnum eTokenToRename =
59 static_cast< enum XMLTokenEnum >( nParam & 0xffff );
60 if( eTokenToRename != XML_TOKEN_INVALID &&
61 IsXMLToken( rOutAttribute, eTokenToRename ))
63 enum XMLTokenEnum eReplacementToken =
64 static_cast< enum XMLTokenEnum >( nParam >> 16 );
65 rOutAttribute = GetXMLToken( eReplacementToken );
66 bResult = true;
68 return bResult;
70 } // anonymous namespace
72 XMLTransformerContext *XMLTransformerBase::CreateContext( sal_uInt16 nPrefix,
73 const OUString& rLocalName, const OUString& rQName )
75 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
76 XMLTransformerActions::const_iterator aIter =
77 GetElemActions().find( aKey );
79 if( !(aIter == GetElemActions().end()) )
81 sal_uInt32 nActionType = (*aIter).second.m_nActionType;
82 if( (nActionType & XML_ETACTION_USER_DEFINED) != 0 )
84 XMLTransformerContext *pContext =
85 CreateUserDefinedContext( (*aIter).second,
86 rQName );
87 OSL_ENSURE( pContext && !pContext->IsPersistent(),
88 "unknown or not persistent action" );
89 return pContext;
92 switch( nActionType )
94 case XML_ETACTION_COPY_CONTENT:
95 return new XMLIgnoreTransformerContext( *this, rQName, false,
96 false );
97 case XML_ETACTION_COPY:
98 return new XMLTransformerContext( *this, rQName );
99 case XML_ETACTION_RENAME_ELEM:
100 return new XMLRenameElemTransformerContext( *this, rQName,
101 (*aIter).second.GetQNamePrefixFromParam1(),
102 (*aIter).second.GetQNameTokenFromParam1() );
103 case XML_ETACTION_RENAME_ELEM_ADD_ATTR:
104 return new XMLRenameElemTransformerContext( *this, rQName,
105 (*aIter).second.GetQNamePrefixFromParam1(),
106 (*aIter).second.GetQNameTokenFromParam1(),
107 (*aIter).second.GetQNamePrefixFromParam2(),
108 (*aIter).second.GetQNameTokenFromParam2(),
109 static_cast< XMLTokenEnum >( (*aIter).second.m_nParam3 ) );
110 case XML_ETACTION_RENAME_ELEM_PROC_ATTRS:
111 return new XMLProcAttrTransformerContext( *this, rQName,
112 (*aIter).second.GetQNamePrefixFromParam1(),
113 (*aIter).second.GetQNameTokenFromParam1(),
114 static_cast< sal_uInt16 >( (*aIter).second.m_nParam2 ) );
115 case XML_ETACTION_RENAME_ELEM_ADD_PROC_ATTR:
116 return new XMLProcAddAttrTransformerContext( *this, rQName,
117 (*aIter).second.GetQNamePrefixFromParam1(),
118 (*aIter).second.GetQNameTokenFromParam1(),
119 static_cast< sal_uInt16 >(
120 (*aIter).second.m_nParam3 >> 16 ),
121 (*aIter).second.GetQNamePrefixFromParam2(),
122 (*aIter).second.GetQNameTokenFromParam2(),
123 static_cast< XMLTokenEnum >(
124 (*aIter).second.m_nParam3 & 0xffff ) );
125 case XML_ETACTION_RENAME_ELEM_COND:
127 const XMLTransformerContext *pCurrent = GetCurrentContext();
128 if( pCurrent->HasQName(
129 (*aIter).second.GetQNamePrefixFromParam2(),
130 (*aIter).second.GetQNameTokenFromParam2() ) )
131 return new XMLRenameElemTransformerContext( *this, rQName,
132 (*aIter).second.GetQNamePrefixFromParam1(),
133 (*aIter).second.GetQNameTokenFromParam1() );
135 break;
136 case XML_ETACTION_RENAME_ELEM_PROC_ATTRS_COND:
138 const XMLTransformerContext *pCurrent = GetCurrentContext();
139 if( pCurrent->HasQName(
140 (*aIter).second.GetQNamePrefixFromParam3(),
141 (*aIter).second.GetQNameTokenFromParam3() ) )
142 return new XMLProcAttrTransformerContext( *this, rQName,
143 (*aIter).second.GetQNamePrefixFromParam1(),
144 (*aIter).second.GetQNameTokenFromParam1(),
145 static_cast< sal_uInt16 >( (*aIter).second.m_nParam2 ) );
146 else
147 return new XMLProcAttrTransformerContext( *this, rQName,
148 static_cast< sal_uInt16 >( (*aIter).second.m_nParam2 ) );
150 case XML_ETACTION_PROC_ATTRS:
151 return new XMLProcAttrTransformerContext( *this, rQName,
152 static_cast< sal_uInt16 >( (*aIter).second.m_nParam1 ) );
153 case XML_ETACTION_PROC_ATTRS_COND:
155 const XMLTransformerContext *pCurrent = GetCurrentContext();
156 if( pCurrent->HasQName(
157 (*aIter).second.GetQNamePrefixFromParam1(),
158 (*aIter).second.GetQNameTokenFromParam1() ) )
159 return new XMLProcAttrTransformerContext( *this, rQName,
160 static_cast< sal_uInt16 >( (*aIter).second.m_nParam2 ) );
162 break;
163 case XML_ETACTION_MOVE_ATTRS_TO_ELEMS:
164 return new XMLCreateElemTransformerContext( *this, rQName,
165 static_cast< sal_uInt16 >( (*aIter).second.m_nParam1 ) );
166 case XML_ETACTION_MOVE_ELEMS_TO_ATTRS:
167 return new XMLMergeElemTransformerContext( *this, rQName,
168 static_cast< sal_uInt16 >( (*aIter).second.m_nParam1 ) );
169 default:
170 OSL_ENSURE( false, "unknown action" );
171 break;
175 // default is copying
176 return new XMLTransformerContext( *this, rQName );
179 XMLTransformerActions *XMLTransformerBase::GetUserDefinedActions( sal_uInt16 )
181 return nullptr;
184 XMLTransformerBase::XMLTransformerBase( XMLTransformerActionInit *pInit,
185 ::xmloff::token::XMLTokenEnum *pTKMapInit )
186 throw () :
187 m_pNamespaceMap( new SvXMLNamespaceMap ),
188 m_pReplaceNamespaceMap( new SvXMLNamespaceMap ),
189 m_pElemActions( new XMLTransformerActions( pInit ) ),
190 m_pTokenMap( new XMLTransformerTokenMap( pTKMapInit ) )
192 GetNamespaceMap().Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
193 GetNamespaceMap().Add( GetXMLToken(XML_NP_DC), GetXMLToken(XML_N_DC), XML_NAMESPACE_DC );
194 GetNamespaceMap().Add( GetXMLToken(XML_NP_MATH), GetXMLToken(XML_N_MATH), XML_NAMESPACE_MATH );
195 GetNamespaceMap().Add( GetXMLToken(XML_NP_OOO), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
196 GetNamespaceMap().Add( GetXMLToken(XML_NP_DOM), GetXMLToken(XML_N_DOM), XML_NAMESPACE_DOM );
197 GetNamespaceMap().Add( GetXMLToken(XML_NP_OOOW), GetXMLToken(XML_N_OOOW), XML_NAMESPACE_OOOW );
198 GetNamespaceMap().Add( GetXMLToken(XML_NP_OOOC), GetXMLToken(XML_N_OOOC), XML_NAMESPACE_OOOC );
201 XMLTransformerBase::~XMLTransformerBase() throw ()
203 delete m_pNamespaceMap;
204 delete m_pReplaceNamespaceMap;
205 delete m_pElemActions;
206 delete m_pTokenMap;
209 void SAL_CALL XMLTransformerBase::startDocument()
210 throw( SAXException, RuntimeException, std::exception )
212 m_xHandler->startDocument();
215 void SAL_CALL XMLTransformerBase::endDocument()
216 throw( SAXException, RuntimeException, std::exception)
218 m_xHandler->endDocument();
221 void SAL_CALL XMLTransformerBase::startElement( const OUString& rName,
222 const Reference< XAttributeList >& rAttrList )
223 throw(SAXException, RuntimeException, std::exception)
225 SvXMLNamespaceMap *pRewindMap = nullptr;
227 bool bRect = rName == "presentation:show-shape";
228 (void)bRect;
230 // Process namespace attributes. This must happen before creating the
231 // context, because namespace decaration apply to the element name itself.
232 XMLMutableAttributeList *pMutableAttrList = nullptr;
233 Reference< XAttributeList > xAttrList( rAttrList );
234 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
235 for( sal_Int16 i=0; i < nAttrCount; i++ )
237 const OUString& rAttrName = xAttrList->getNameByIndex( i );
238 if( ( rAttrName.getLength() >= 5 ) &&
239 ( rAttrName.startsWith( GetXMLToken(XML_XMLNS) ) ) &&
240 ( rAttrName.getLength() == 5 || ':' == rAttrName[5] ) )
242 if( !pRewindMap )
244 pRewindMap = m_pNamespaceMap;
245 m_pNamespaceMap = new SvXMLNamespaceMap( *m_pNamespaceMap );
247 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
249 OUString aPrefix( ( rAttrName.getLength() == 5 )
250 ? OUString()
251 : rAttrName.copy( 6 ) );
252 // Add namespace, but only if it is known.
253 sal_uInt16 nKey = m_pNamespaceMap->AddIfKnown( aPrefix, rAttrValue );
254 // If namespace is unknown, try to match a name with similar
255 // TC Id an version
256 if( XML_NAMESPACE_UNKNOWN == nKey )
258 OUString aTestName( rAttrValue );
259 if( SvXMLNamespaceMap::NormalizeOasisURN( aTestName ) )
260 nKey = m_pNamespaceMap->AddIfKnown( aPrefix, aTestName );
262 // If that namespace is not known, too, add it as unknown
263 if( XML_NAMESPACE_UNKNOWN == nKey )
264 nKey = m_pNamespaceMap->Add( aPrefix, rAttrValue );
266 const OUString& rRepName = m_pReplaceNamespaceMap->GetNameByKey( nKey );
267 if( !rRepName.isEmpty() )
269 if( !pMutableAttrList )
271 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
272 xAttrList = pMutableAttrList;
275 pMutableAttrList->SetValueByIndex( i, rRepName );
280 // Get element's namespace and local name.
281 OUString aLocalName;
282 sal_uInt16 nPrefix =
283 m_pNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
285 // If there are contexts already, call a CreateChildContext at the topmost
286 // context. Otherwise, create a default context.
287 ::rtl::Reference < XMLTransformerContext > xContext;
288 if( !m_pContexts.empty() )
290 xContext = m_pContexts.back()->CreateChildContext( nPrefix,
291 aLocalName,
292 rName,
293 xAttrList );
295 else
297 xContext = CreateContext( nPrefix, aLocalName, rName );
300 OSL_ENSURE( xContext.is(), "XMLTransformerBase::startElement: missing context" );
301 if( !xContext.is() )
302 xContext = new XMLTransformerContext( *this, rName );
304 // Remember old namespace map.
305 if( pRewindMap )
306 xContext->PutRewindMap( pRewindMap );
308 // Push context on stack.
309 m_pContexts.push_back( xContext );
311 // Call a startElement at the new context.
312 xContext->StartElement( xAttrList );
315 void SAL_CALL XMLTransformerBase::endElement( const OUString&
316 #if OSL_DEBUG_LEVEL > 0
317 rName
318 #endif
320 throw(SAXException, RuntimeException, std::exception)
322 if( !m_pContexts.empty() )
324 // Get topmost context
325 ::rtl::Reference< XMLTransformerContext > xContext = m_pContexts.back();
327 #if OSL_DEBUG_LEVEL > 0
328 OSL_ENSURE( xContext->GetQName() == rName,
329 "XMLTransformerBase::endElement: popped context has wrong lname" );
330 #endif
332 // Call a EndElement at the current context.
333 xContext->EndElement();
335 // and remove it from the stack.
336 m_pContexts.pop_back();
338 // Get a namespace map to rewind.
339 SvXMLNamespaceMap *pRewindMap = xContext->TakeRewindMap();
341 // Delete the current context.
342 xContext = nullptr;
344 // Rewind a namespace map.
345 if( pRewindMap )
347 delete m_pNamespaceMap;
348 m_pNamespaceMap = pRewindMap;
353 void SAL_CALL XMLTransformerBase::characters( const OUString& rChars )
354 throw(SAXException, RuntimeException, std::exception)
356 if( !m_pContexts.empty() )
358 m_pContexts.back()->Characters( rChars );
362 void SAL_CALL XMLTransformerBase::ignorableWhitespace( const OUString& rWhitespaces )
363 throw(SAXException, RuntimeException, std::exception)
365 m_xHandler->ignorableWhitespace( rWhitespaces );
368 void SAL_CALL XMLTransformerBase::processingInstruction( const OUString& rTarget,
369 const OUString& rData )
370 throw(SAXException, RuntimeException, std::exception)
372 m_xHandler->processingInstruction( rTarget, rData );
375 void SAL_CALL XMLTransformerBase::setDocumentLocator( const Reference< XLocator >& rLocator )
376 throw(SAXException, RuntimeException, std::exception)
378 m_xLocator = rLocator;
381 // XExtendedDocumentHandler
382 void SAL_CALL XMLTransformerBase::startCDATA() throw(SAXException, RuntimeException, std::exception)
384 if( m_xExtHandler.is() )
385 m_xExtHandler->startCDATA();
388 void SAL_CALL XMLTransformerBase::endCDATA() throw(RuntimeException, std::exception)
390 if( m_xExtHandler.is() )
391 m_xExtHandler->endCDATA();
394 void SAL_CALL XMLTransformerBase::comment( const OUString& rComment )
395 throw(SAXException, RuntimeException, std::exception)
397 if( m_xExtHandler.is() )
398 m_xExtHandler->comment( rComment );
401 void SAL_CALL XMLTransformerBase::allowLineBreak()
402 throw(SAXException, RuntimeException, std::exception)
404 if( m_xExtHandler.is() )
405 m_xExtHandler->allowLineBreak();
408 void SAL_CALL XMLTransformerBase::unknown( const OUString& rString )
409 throw(SAXException, RuntimeException, std::exception)
411 if( m_xExtHandler.is() )
412 m_xExtHandler->unknown( rString );
415 // XInitialize
416 void SAL_CALL XMLTransformerBase::initialize( const Sequence< Any >& aArguments )
417 throw(Exception, RuntimeException, std::exception)
419 const sal_Int32 nAnyCount = aArguments.getLength();
420 const Any* pAny = aArguments.getConstArray();
422 for( sal_Int32 nIndex = 0; nIndex < nAnyCount; nIndex++, pAny++ )
424 // use isAssignableFrom instead of comparing the types to
425 // allow XExtendedDocumentHandler instead of XDocumentHandler (used in
426 // writeOasis2OOoLibraryElement in sfx2).
427 // The Any shift operator can't be used to query the type because it
428 // uses queryInterface, and the model also has a XPropertySet interface.
430 // document handler
431 if( cppu::UnoType<XDocumentHandler>::get().isAssignableFrom( pAny->getValueType() ) )
432 m_xHandler.set( *pAny, UNO_QUERY );
434 // property set to transport data across
435 if( cppu::UnoType<XPropertySet>::get().isAssignableFrom( pAny->getValueType() ) )
436 m_xPropSet.set( *pAny, UNO_QUERY );
438 // xmodel
439 if( cppu::UnoType<css::frame::XModel>::get().isAssignableFrom( pAny->getValueType() ) )
440 mxModel.set( *pAny, UNO_QUERY );
443 if( m_xPropSet.is() )
445 Any aAny;
446 OUString sRelPath, sName;
447 Reference< XPropertySetInfo > xPropSetInfo =
448 m_xPropSet->getPropertySetInfo();
449 OUString sPropName( "StreamRelPath" );
450 if( xPropSetInfo->hasPropertyByName(sPropName) )
452 aAny = m_xPropSet->getPropertyValue(sPropName);
453 aAny >>= sRelPath;
455 sPropName = "StreamName";
456 if( xPropSetInfo->hasPropertyByName(sPropName) )
458 aAny = m_xPropSet->getPropertyValue(sPropName);
459 aAny >>= sName;
461 if( !sName.isEmpty() )
463 m_aExtPathPrefix = "../";
465 // If there is a rel path within a package, then append
466 // additional '../'. If the rel path contains an ':', then it is
467 // an absolute URI (or invalid URI, because zip files don't
468 // permit ':'), and it will be ignored.
469 if( !sRelPath.isEmpty() )
471 sal_Int32 nColPos = sRelPath.indexOf( ':' );
472 OSL_ENSURE( -1 == nColPos,
473 "StreamRelPath contains ':', absolute URI?" );
475 if( -1 == nColPos )
477 OUString sTmp = m_aExtPathPrefix;
478 sal_Int32 nPos = 0;
481 m_aExtPathPrefix += sTmp;
482 nPos = sRelPath.indexOf( '/', nPos + 1 );
484 while( -1 != nPos );
491 assert(m_xHandler.is()); // can't do anything without that
494 static sal_Int16 lcl_getUnit( const OUString& rValue )
496 if( rValue.endsWithIgnoreAsciiCase( "cm" ) )
497 return util::MeasureUnit::CM;
498 else if ( rValue.endsWithIgnoreAsciiCase( "mm" ) )
499 return util::MeasureUnit::MM;
500 else
501 return util::MeasureUnit::INCH;
504 XMLMutableAttributeList *XMLTransformerBase::ProcessAttrList(
505 Reference< XAttributeList >& rAttrList, sal_uInt16 nActionMap,
506 bool bClone )
508 XMLMutableAttributeList *pMutableAttrList = nullptr;
509 XMLTransformerActions *pActions = GetUserDefinedActions( nActionMap );
510 OSL_ENSURE( pActions, "go no actions" );
511 if( pActions )
513 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
514 for( sal_Int16 i=0; i < nAttrCount; ++i )
516 const OUString& rAttrName = rAttrList->getNameByIndex( i );
517 const OUString& rAttrValue = rAttrList->getValueByIndex( i );
518 OUString aLocalName;
519 sal_uInt16 nPrefix = GetNamespaceMap().GetKeyByAttrName( rAttrName,
520 &aLocalName );
522 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
523 XMLTransformerActions::const_iterator aIter =
524 pActions->find( aKey );
525 if( !(aIter == pActions->end() ) )
527 if( !pMutableAttrList )
529 pMutableAttrList = new XMLMutableAttributeList( rAttrList,
530 bClone );
531 rAttrList = pMutableAttrList;
534 sal_uInt32 nAction = (*aIter).second.m_nActionType;
535 bool bRename = false;
536 switch( nAction )
538 case XML_ATACTION_RENAME:
539 bRename = true;
540 break;
541 case XML_ATACTION_COPY:
542 break;
543 case XML_ATACTION_REMOVE:
544 case XML_ATACTION_STYLE_DISPLAY_NAME:
545 pMutableAttrList->RemoveAttributeByIndex( i );
546 --i;
547 --nAttrCount;
548 break;
549 case XML_ATACTION_RENAME_IN2INCH:
550 bRename = true;
551 SAL_FALLTHROUGH;
552 case XML_ATACTION_IN2INCH:
554 OUString aAttrValue( rAttrValue );
555 if( ReplaceSingleInWithInch( aAttrValue ) )
556 pMutableAttrList->SetValueByIndex( i, aAttrValue );
558 break;
559 case XML_ATACTION_INS2INCHS:
561 OUString aAttrValue( rAttrValue );
562 if( ReplaceInWithInch( aAttrValue ) )
563 pMutableAttrList->SetValueByIndex( i, aAttrValue );
565 break;
566 case XML_ATACTION_RENAME_INCH2IN:
567 bRename = true;
568 SAL_FALLTHROUGH;
569 case XML_ATACTION_INCH2IN:
571 OUString aAttrValue( rAttrValue );
572 if( ReplaceSingleInchWithIn( aAttrValue ) )
573 pMutableAttrList->SetValueByIndex( i, aAttrValue );
575 break;
576 case XML_ATACTION_INCHS2INS:
578 OUString aAttrValue( rAttrValue );
579 if( ReplaceInchWithIn( aAttrValue ) )
580 pMutableAttrList->SetValueByIndex( i, aAttrValue );
582 break;
583 case XML_ATACTION_TWIPS2IN:
585 OUString aAttrValue( rAttrValue );
587 XMLTransformerBase::ReplaceSingleInchWithIn( aAttrValue );
588 if( isWriter() )
590 sal_Int16 const nDestUnit = lcl_getUnit(aAttrValue);
592 // convert twips value to inch
593 sal_Int32 nMeasure;
594 if (::sax::Converter::convertMeasure(nMeasure,
595 aAttrValue))
598 // #i13778#,#i36248# apply correct twip-to-1/100mm
599 nMeasure = (sal_Int32)( nMeasure >= 0
600 ? ((nMeasure*127+36)/72)
601 : ((nMeasure*127-36)/72) );
603 OUStringBuffer aBuffer;
604 ::sax::Converter::convertMeasure(aBuffer,
605 nMeasure, util::MeasureUnit::MM_100TH,
606 nDestUnit );
607 aAttrValue = aBuffer.makeStringAndClear();
611 pMutableAttrList->SetValueByIndex( i, aAttrValue );
613 break;
614 case XML_ATACTION_RENAME_DECODE_STYLE_NAME_REF:
615 bRename = true;
616 SAL_FALLTHROUGH;
617 case XML_ATACTION_DECODE_STYLE_NAME:
618 case XML_ATACTION_DECODE_STYLE_NAME_REF:
620 OUString aAttrValue( rAttrValue );
621 if( DecodeStyleName(aAttrValue) )
622 pMutableAttrList->SetValueByIndex( i, aAttrValue );
624 break;
625 case XML_ATACTION_ENCODE_STYLE_NAME:
627 OUString aAttrValue( rAttrValue );
628 if( EncodeStyleName(aAttrValue) )
630 pMutableAttrList->SetValueByIndex( i, aAttrValue );
631 OUString aNewAttrQName(
632 GetNamespaceMap().GetQNameByKey(
633 nPrefix,
634 ::xmloff::token::GetXMLToken(
635 XML_DISPLAY_NAME ) ) );
636 pMutableAttrList->AddAttribute( aNewAttrQName,
637 rAttrValue );
640 break;
641 case XML_ATACTION_RENAME_ENCODE_STYLE_NAME_REF:
642 bRename = true;
643 SAL_FALLTHROUGH;
644 case XML_ATACTION_ENCODE_STYLE_NAME_REF:
646 OUString aAttrValue( rAttrValue );
647 if( EncodeStyleName(aAttrValue) )
648 pMutableAttrList->SetValueByIndex( i, aAttrValue );
650 break;
651 case XML_ATACTION_RENAME_NEG_PERCENT:
652 bRename = true;
653 SAL_FALLTHROUGH;
654 case XML_ATACTION_NEG_PERCENT:
656 OUString aAttrValue( rAttrValue );
657 if( NegPercent( aAttrValue ) )
658 pMutableAttrList->SetValueByIndex( i, aAttrValue );
660 break;
661 case XML_ATACTION_RENAME_ADD_NAMESPACE_PREFIX:
662 bRename = true;
663 SAL_FALLTHROUGH;
664 case XML_ATACTION_ADD_NAMESPACE_PREFIX:
666 OUString aAttrValue( rAttrValue );
667 sal_uInt16 nValPrefix =
668 static_cast<sal_uInt16>(
669 bRename ? (*aIter).second.m_nParam2
670 : (*aIter).second.m_nParam1);
671 if( AddNamespacePrefix( aAttrValue, nValPrefix ) )
672 pMutableAttrList->SetValueByIndex( i, aAttrValue );
674 break;
675 case XML_ATACTION_ADD_APP_NAMESPACE_PREFIX:
677 OUString aAttrValue( rAttrValue );
678 sal_uInt16 nValPrefix =
679 static_cast<sal_uInt16>((*aIter).second.m_nParam1);
680 if( IsXMLToken( GetClass(), XML_SPREADSHEET ) )
681 nValPrefix = XML_NAMESPACE_OOOC;
682 else if( IsXMLToken( GetClass(), XML_TEXT ) )
683 nValPrefix = XML_NAMESPACE_OOOW;
684 if( AddNamespacePrefix( aAttrValue, nValPrefix ) )
685 pMutableAttrList->SetValueByIndex( i, aAttrValue );
687 break;
688 case XML_ATACTION_RENAME_REMOVE_NAMESPACE_PREFIX:
689 bRename = true;
690 SAL_FALLTHROUGH;
691 case XML_ATACTION_REMOVE_NAMESPACE_PREFIX:
693 OUString aAttrValue( rAttrValue );
694 sal_uInt16 nValPrefix =
695 static_cast<sal_uInt16>(
696 bRename ? (*aIter).second.m_nParam2
697 : (*aIter).second.m_nParam1);
698 if( RemoveNamespacePrefix( aAttrValue, nValPrefix ) )
699 pMutableAttrList->SetValueByIndex( i, aAttrValue );
701 break;
702 case XML_ATACTION_REMOVE_ANY_NAMESPACE_PREFIX:
704 OUString aAttrValue( rAttrValue );
705 if( RemoveNamespacePrefix( aAttrValue ) )
706 pMutableAttrList->SetValueByIndex( i, aAttrValue );
708 break;
709 case XML_ATACTION_URI_OOO:
711 OUString aAttrValue( rAttrValue );
712 if( ConvertURIToOASIS( aAttrValue,
713 static_cast< bool >((*aIter).second.m_nParam1)))
714 pMutableAttrList->SetValueByIndex( i, aAttrValue );
716 break;
717 case XML_ATACTION_URI_OASIS:
719 OUString aAttrValue( rAttrValue );
720 if( ConvertURIToOOo( aAttrValue,
721 static_cast< bool >((*aIter).second.m_nParam1)))
722 pMutableAttrList->SetValueByIndex( i, aAttrValue );
724 break;
725 case XML_ATACTION_RENAME_ATTRIBUTE:
727 OUString aAttrValue( rAttrValue );
728 RenameAttributeValue(
729 aAttrValue,
730 (*aIter).second.m_nParam1,
731 (*aIter).second.m_nParam2,
732 (*aIter).second.m_nParam3 );
733 pMutableAttrList->SetValueByIndex( i, aAttrValue );
735 break;
736 case XML_ATACTION_RNG2ISO_DATETIME:
738 OUString aAttrValue( rAttrValue );
739 if( ConvertRNGDateTimeToISO( aAttrValue ))
740 pMutableAttrList->SetValueByIndex( i, aAttrValue );
742 break;
743 case XML_ATACTION_RENAME_RNG2ISO_DATETIME:
745 OUString aAttrValue( rAttrValue );
746 if( ConvertRNGDateTimeToISO( aAttrValue ))
747 pMutableAttrList->SetValueByIndex( i, aAttrValue );
748 bRename = true;
750 break;
751 case XML_ATACTION_IN2TWIPS:
753 OUString aAttrValue( rAttrValue );
754 XMLTransformerBase::ReplaceSingleInWithInch( aAttrValue );
756 if( isWriter() )
758 sal_Int16 const nDestUnit = lcl_getUnit(aAttrValue);
760 // convert inch value to twips and export as faked inch
761 sal_Int32 nMeasure;
762 if (::sax::Converter::convertMeasure(nMeasure,
763 aAttrValue))
766 // #i13778#,#i36248#/ apply correct 1/100mm-to-twip conversion
767 nMeasure = (sal_Int32)( nMeasure >= 0
768 ? ((nMeasure*72+63)/127)
769 : ((nMeasure*72-63)/127) );
771 OUStringBuffer aBuffer;
772 ::sax::Converter::convertMeasure( aBuffer,
773 nMeasure, util::MeasureUnit::MM_100TH,
774 nDestUnit );
775 aAttrValue = aBuffer.makeStringAndClear();
779 pMutableAttrList->SetValueByIndex( i, aAttrValue );
781 break;
782 case XML_ATACTION_SVG_WIDTH_HEIGHT_OOO:
784 OUString aAttrValue( rAttrValue );
785 ReplaceSingleInchWithIn( aAttrValue );
787 sal_Int16 const nDestUnit = lcl_getUnit( aAttrValue );
789 sal_Int32 nMeasure;
790 if (::sax::Converter::convertMeasure(nMeasure,
791 aAttrValue))
794 if( nMeasure > 0 )
795 nMeasure -= 1;
796 else if( nMeasure < 0 )
797 nMeasure += 1;
800 OUStringBuffer aBuffer;
801 ::sax::Converter::convertMeasure(aBuffer, nMeasure,
802 util::MeasureUnit::MM_100TH, nDestUnit);
803 aAttrValue = aBuffer.makeStringAndClear();
806 pMutableAttrList->SetValueByIndex( i, aAttrValue );
808 break;
809 case XML_ATACTION_SVG_WIDTH_HEIGHT_OASIS:
811 OUString aAttrValue( rAttrValue );
812 ReplaceSingleInWithInch( aAttrValue );
814 sal_Int16 const nDestUnit = lcl_getUnit( aAttrValue );
816 sal_Int32 nMeasure;
817 if (::sax::Converter::convertMeasure(nMeasure,
818 aAttrValue))
821 if( nMeasure > 0 )
822 nMeasure += 1;
823 else if( nMeasure < 0 )
824 nMeasure -= 1;
827 OUStringBuffer aBuffer;
828 ::sax::Converter::convertMeasure(aBuffer, nMeasure,
829 util::MeasureUnit::MM_100TH, nDestUnit );
830 aAttrValue = aBuffer.makeStringAndClear();
833 pMutableAttrList->SetValueByIndex( i, aAttrValue );
835 break;
836 case XML_ATACTION_DECODE_ID:
838 const sal_Int32 nLen = rAttrValue.getLength();
839 OUStringBuffer aBuffer;
841 sal_Int32 pos;
842 for( pos = 0; pos < nLen; pos++ )
844 sal_Unicode c = rAttrValue[pos];
845 if( (c >= '0') && (c <= '9') )
846 aBuffer.append( c );
847 else
848 aBuffer.append( (sal_Int32)c );
851 pMutableAttrList->SetValueByIndex( i, aBuffer.makeStringAndClear() );
853 break;
854 // #i50322# - special handling for the
855 // transparency of writer background graphics.
856 case XML_ATACTION_WRITER_BACK_GRAPHIC_TRANSPARENCY:
858 // determine, if it's the transparency of a document style
859 XMLTransformerContext* pFirstContext = m_pContexts[0].get();
860 OUString aFirstContextLocalName;
861 /* sal_uInt16 nFirstContextPrefix = */
862 GetNamespaceMap().GetKeyByAttrName( pFirstContext->GetQName(),
863 &aFirstContextLocalName );
864 bool bIsDocumentStyle(
865 ::xmloff::token::IsXMLToken( aFirstContextLocalName,
866 XML_DOCUMENT_STYLES ) );
867 // no conversion of transparency value for document
868 // styles, because former OpenOffice.org version writes
869 // writes always a transparency value of 100% and doesn't
870 // read the value. Thus, it's intepreted as 0%
871 if ( !bIsDocumentStyle )
873 OUString aAttrValue( rAttrValue );
874 NegPercent(aAttrValue);
875 pMutableAttrList->SetValueByIndex( i, aAttrValue );
877 bRename = true;
879 break;
880 case XML_ATACTION_SHAPEID:
882 OUString sNewValue( "shape" );
883 sNewValue += rAttrValue;
884 pMutableAttrList->SetValueByIndex( i, sNewValue );
885 break;
888 default:
889 OSL_ENSURE( false, "unknown action" );
890 break;
893 if( bRename )
895 OUString aNewAttrQName(
896 GetNamespaceMap().GetQNameByKey(
897 (*aIter).second.GetQNamePrefixFromParam1(),
898 ::xmloff::token::GetXMLToken(
899 (*aIter).second.GetQNameTokenFromParam1()) ) );
900 pMutableAttrList->RenameAttributeByIndex( i,
901 aNewAttrQName );
907 return pMutableAttrList;
910 bool XMLTransformerBase::ReplaceSingleInchWithIn( OUString& rValue )
912 bool bRet = false;
913 sal_Int32 nPos = rValue.getLength();
914 while( nPos && rValue[nPos-1] <= ' ' )
915 --nPos;
916 if( nPos > 2 &&
917 ('c'==rValue[nPos-2] || 'C'==rValue[nPos-2]) &&
918 ('h'==rValue[nPos-1] || 'H'==rValue[nPos-1]) )
920 rValue =rValue.copy( 0, nPos-2 );
921 bRet = true;
924 return bRet;
927 bool XMLTransformerBase::ReplaceInchWithIn( OUString& rValue )
929 bool bRet = false;
930 sal_Int32 nPos = 1;
931 while( nPos < rValue.getLength()-3 )
933 sal_Unicode c = rValue[nPos];
934 if( 'i'==c || 'I'==c )
936 c = rValue[nPos-1];
937 if( (c >= '0' && c <= '9') || '.' == c )
939 c = rValue[nPos+1];
940 if( 'n'==c || 'N'==c )
942 c = rValue[nPos+2];
943 if( 'c'==c || 'C'==c )
945 c = rValue[nPos+3];
946 if( 'h'==c || 'H'==c )
948 rValue = rValue.replaceAt( nPos,
949 4, GetXMLToken(XML_UNIT_INCH) );
950 nPos += 2;
951 bRet = true;
952 continue;
958 ++nPos;
961 return bRet;
964 bool XMLTransformerBase::ReplaceSingleInWithInch( OUString& rValue )
966 bool bRet = false;
968 sal_Int32 nPos = rValue.getLength();
969 while( nPos && rValue[nPos-1] <= ' ' )
970 --nPos;
971 if( nPos > 2 &&
972 ('i'==rValue[nPos-2] ||
973 'I'==rValue[nPos-2]) &&
974 ('n'==rValue[nPos-1] ||
975 'N'==rValue[nPos-1]) )
977 nPos -= 2;
978 rValue = rValue.replaceAt( nPos, rValue.getLength() - nPos,
979 GetXMLToken(XML_INCH) );
980 bRet = true;
983 return bRet;
986 bool XMLTransformerBase::ReplaceInWithInch( OUString& rValue )
988 bool bRet = false;
989 sal_Int32 nPos = 1;
990 while( nPos < rValue.getLength()-1 )
992 sal_Unicode c = rValue[nPos];
993 if( 'i'==c || 'I'==c )
995 c = rValue[nPos-1];
996 if( (c >= '0' && c <= '9') || '.' == c )
998 c = rValue[nPos+1];
999 if( 'n'==c || 'N'==c )
1001 rValue = rValue.replaceAt( nPos,
1002 2, GetXMLToken(XML_INCH) );
1003 nPos += 4;
1004 bRet = true;
1005 continue;
1009 ++nPos;
1012 return bRet;
1015 bool XMLTransformerBase::EncodeStyleName( OUString& rName ) const
1017 static const sal_Char aHexTab[] = "0123456789abcdef";
1019 bool bEncoded = false;
1021 sal_Int32 nLen = rName.getLength();
1022 OUStringBuffer aBuffer( nLen );
1024 for( sal_Int32 i = 0; i < nLen; i++ )
1026 sal_Unicode c = rName[i];
1027 bool bValidChar = false;
1028 if( c < 0x00ffU )
1030 bValidChar =
1031 (c >= 0x0041 && c <= 0x005a) ||
1032 (c >= 0x0061 && c <= 0x007a) ||
1033 (c >= 0x00c0 && c <= 0x00d6) ||
1034 (c >= 0x00d8 && c <= 0x00f6) ||
1035 (c >= 0x00f8 && c <= 0x00ff) ||
1036 ( i > 0 && ( (c >= 0x0030 && c <= 0x0039) ||
1037 c == 0x00b7 || c == '-' || c == '.') );
1039 else
1041 if( (c >= 0xf900U && c <= 0xfffeU) ||
1042 (c >= 0x20ddU && c <= 0x20e0U))
1044 bValidChar = false;
1046 else if( (c >= 0x02bbU && c <= 0x02c1U) || c == 0x0559 ||
1047 c == 0x06e5 || c == 0x06e6 )
1049 bValidChar = true;
1051 else if( c == 0x0387 )
1053 bValidChar = i > 0;
1055 else
1057 if( !xCharClass.is() )
1059 const_cast < XMLTransformerBase * >(this)
1060 ->xCharClass = CharacterClassification::create( comphelper::getProcessComponentContext() );
1062 sal_Int16 nType = xCharClass->getType( rName, i );
1064 switch( nType )
1066 case UnicodeType::UPPERCASE_LETTER: // Lu
1067 case UnicodeType::LOWERCASE_LETTER: // Ll
1068 case UnicodeType::TITLECASE_LETTER: // Lt
1069 case UnicodeType::OTHER_LETTER: // Lo
1070 case UnicodeType::LETTER_NUMBER: // Nl
1071 bValidChar = true;
1072 break;
1073 case UnicodeType::NON_SPACING_MARK: // Ms
1074 case UnicodeType::ENCLOSING_MARK: // Me
1075 case UnicodeType::COMBINING_SPACING_MARK: //Mc
1076 case UnicodeType::MODIFIER_LETTER: // Lm
1077 case UnicodeType::DECIMAL_DIGIT_NUMBER: // Nd
1078 bValidChar = i > 0;
1079 break;
1083 if( bValidChar )
1085 aBuffer.append( c );
1087 else
1089 aBuffer.append( '_' );
1090 if( c > 0x0fff )
1091 aBuffer.append( static_cast< sal_Unicode >(
1092 aHexTab[ (c >> 12) & 0x0f ] ) );
1093 if( c > 0x00ff )
1094 aBuffer.append( static_cast< sal_Unicode >(
1095 aHexTab[ (c >> 8) & 0x0f ] ) );
1096 if( c > 0x000f )
1097 aBuffer.append( static_cast< sal_Unicode >(
1098 aHexTab[ (c >> 4) & 0x0f ] ) );
1099 aBuffer.append( static_cast< sal_Unicode >(
1100 aHexTab[ c & 0x0f ] ) );
1101 aBuffer.append( '_' );
1102 bEncoded = true;
1106 if( aBuffer.getLength() > (1<<15)-1 )
1107 bEncoded = false;
1109 if( bEncoded )
1110 rName = aBuffer.makeStringAndClear();
1111 return bEncoded;
1114 bool XMLTransformerBase::DecodeStyleName( OUString& rName )
1116 bool bEncoded = false;
1118 sal_Int32 nLen = rName.getLength();
1119 OUStringBuffer aBuffer( nLen );
1121 bool bWithinHex = false;
1122 sal_Unicode cEnc = 0;
1123 for( sal_Int32 i = 0; i < nLen; i++ )
1125 sal_Unicode c = rName[i];
1126 if( '_' == c )
1128 if( bWithinHex )
1130 aBuffer.append( cEnc );
1131 cEnc = 0;
1133 else
1135 bEncoded = true;
1137 bWithinHex = !bWithinHex;
1139 else if( bWithinHex )
1141 sal_Unicode cDigit;
1142 if( c >= '0' && c <= '9' )
1144 cDigit = c - '0';
1146 else if( c >= 'a' && c <= 'f' )
1148 cDigit = c - 'a' + 10;
1150 else if( c >= 'A' && c <= 'F' )
1152 cDigit = c - 'A' + 10;
1154 else
1156 // error
1157 bEncoded = false;
1158 break;
1160 cEnc = (cEnc << 4) + cDigit;
1162 else
1164 aBuffer.append( c );
1168 if( bEncoded )
1169 rName = aBuffer.makeStringAndClear();
1170 return bEncoded;
1173 bool XMLTransformerBase::NegPercent( OUString& rValue )
1175 bool bRet = false;
1176 bool bNeg = false;
1177 double nVal = 0;
1179 sal_Int32 nPos = 0;
1180 sal_Int32 nLen = rValue.getLength();
1182 // skip white space
1183 while( nPos < nLen && ' ' == rValue[nPos] )
1184 nPos++;
1186 if( nPos < nLen && '-' == rValue[nPos] )
1188 bNeg = true;
1189 nPos++;
1192 // get number
1193 while( nPos < nLen &&
1194 '0' <= rValue[nPos] &&
1195 '9' >= rValue[nPos] )
1197 // TODO: check overflow!
1198 nVal *= 10;
1199 nVal += (rValue[nPos] - '0');
1200 nPos++;
1202 if( nPos < nLen && '.' == rValue[nPos] )
1204 nPos++;
1205 double nDiv = 1.;
1207 while( nPos < nLen &&
1208 '0' <= rValue[nPos] &&
1209 '9' >= rValue[nPos] )
1211 // TODO: check overflow!
1212 nDiv *= 10;
1213 nVal += ( static_cast<double>(rValue[nPos] - '0') / nDiv );
1214 nPos++;
1218 // skip white space
1219 while( nPos < nLen && ' ' == rValue[nPos] )
1220 nPos++;
1222 if( nPos < nLen && '%' == rValue[nPos] )
1224 if( bNeg )
1225 nVal = -nVal;
1226 nVal += .5;
1228 sal_Int32 nIntVal = 100 - static_cast<sal_Int32>( nVal );
1230 rValue = OUString::number(nIntVal) + "%";
1232 bRet = true;
1235 return bRet;
1238 bool XMLTransformerBase::AddNamespacePrefix( OUString& rName,
1239 sal_uInt16 nPrefix ) const
1241 rName = GetNamespaceMap().GetQNameByKey( nPrefix, rName, false );
1242 return true;
1245 bool XMLTransformerBase::RemoveNamespacePrefix( OUString& rName,
1246 sal_uInt16 nPrefixOnly ) const
1248 OUString aLocalName;
1249 sal_uInt16 nPrefix =
1250 GetNamespaceMap().GetKeyByAttrName_( rName, &aLocalName );
1251 bool bRet = XML_NAMESPACE_UNKNOWN != nPrefix &&
1252 (USHRT_MAX == nPrefixOnly || nPrefix == nPrefixOnly);
1253 if( bRet )
1254 rName = aLocalName;
1256 return bRet;
1259 bool XMLTransformerBase::ConvertURIToOASIS( OUString& rURI,
1260 bool bSupportPackage ) const
1262 bool bRet = false;
1263 if( !m_aExtPathPrefix.isEmpty() && !rURI.isEmpty() )
1265 bool bRel = false;
1266 switch( rURI[0] )
1268 case '#':
1269 // no rel path, but
1270 // for package URIs, the '#' has to be removed
1271 if( bSupportPackage )
1273 rURI = rURI.copy( 1 );
1274 bRet = true;
1276 break;
1277 case '/':
1278 // no rel path; nothing to do
1279 break;
1280 case '.':
1281 // a rel path; to keep URI simple, remove './', if there
1282 bRel = true;
1283 if( rURI.getLength() > 1 && '/' == rURI[1] )
1285 rURI = rURI.copy( 2 );
1286 bRet = true;
1288 break;
1289 default:
1290 // check for a RFC2396 schema
1292 bRel = true;
1293 sal_Int32 nPos = 1;
1294 sal_Int32 nLen = rURI.getLength();
1295 while( nPos < nLen )
1297 switch( rURI[nPos] )
1299 case '/':
1300 // a relative path segement
1301 nPos = nLen; // leave loop
1302 break;
1303 case ':':
1304 // a schema
1305 bRel = false;
1306 nPos = nLen; // leave loop
1307 break;
1308 default:
1309 // we don't care about any other characters
1310 break;
1312 ++nPos;
1317 if( bRel )
1319 OUString sTmp( m_aExtPathPrefix );
1320 sTmp += rURI;
1321 rURI = sTmp;
1322 bRet = true;
1326 return bRet;
1329 bool XMLTransformerBase::ConvertURIToOOo( OUString& rURI,
1330 bool bSupportPackage ) const
1332 bool bRet = false;
1333 if( !rURI.isEmpty() )
1335 bool bPackage = false;
1336 switch( rURI[0] )
1338 case '/':
1339 // no rel path; nothing to do
1340 break;
1341 case '.':
1342 // a rel path
1343 if( rURI.startsWith( m_aExtPathPrefix ) )
1345 // an external URI; remove '../'
1346 rURI = rURI.copy( m_aExtPathPrefix.getLength() );
1347 bRet = true;
1349 else
1351 bPackage = true;
1353 break;
1354 default:
1355 // check for a RFC2396 schema
1357 bPackage = true;
1358 sal_Int32 nPos = 1;
1359 sal_Int32 nLen = rURI.getLength();
1360 while( nPos < nLen )
1362 switch( rURI[nPos] )
1364 case '/':
1365 // a relative path segement within the package
1366 nPos = nLen; // leave loop
1367 break;
1368 case ':':
1369 // a schema
1370 bPackage = false;
1371 nPos = nLen; // leave loop
1372 break;
1373 default:
1374 // we don't care about any other characters
1375 break;
1377 ++nPos;
1382 if( bPackage && bSupportPackage )
1384 OUString sTmp( '#' );
1385 if( rURI.startsWith( "./" ) )
1386 rURI = rURI.copy( 2 );
1387 sTmp += rURI;
1388 rURI = sTmp;
1389 bRet = true;
1393 return bRet;
1396 bool XMLTransformerBase::RenameAttributeValue(
1397 OUString& rOutAttributeValue,
1398 sal_Int32 nParam1,
1399 sal_Int32 nParam2,
1400 sal_Int32 nParam3 )
1402 return ( lcl_ConvertAttr( rOutAttributeValue, nParam1) ||
1403 lcl_ConvertAttr( rOutAttributeValue, nParam2) ||
1404 lcl_ConvertAttr( rOutAttributeValue, nParam3) );
1407 // static
1408 bool XMLTransformerBase::ConvertRNGDateTimeToISO( OUString& rDateTime )
1410 if( !rDateTime.isEmpty() &&
1411 rDateTime.indexOf( '.' ) != -1 )
1413 rDateTime = rDateTime.replace( '.', ',');
1414 return true;
1417 return false;
1420 XMLTokenEnum XMLTransformerBase::GetToken( const OUString& rStr ) const
1422 XMLTransformerTokenMap::const_iterator aIter =
1423 m_pTokenMap->find( rStr );
1424 if( aIter == m_pTokenMap->end() )
1425 return XML_TOKEN_END;
1426 else
1427 return (*aIter).second;
1431 const XMLTransformerContext *XMLTransformerBase::GetCurrentContext() const
1433 OSL_ENSURE( !m_pContexts.empty(), "empty stack" );
1436 return m_pContexts.empty() ? nullptr : m_pContexts.back().get();
1439 const XMLTransformerContext *XMLTransformerBase::GetAncestorContext(
1440 sal_uInt32 n ) const
1442 auto nSize = m_pContexts.size();
1444 OSL_ENSURE( nSize > n + 2 , "invalid context" );
1446 return nSize > n + 2 ? m_pContexts[nSize - (n + 2)].get() : nullptr;
1449 bool XMLTransformerBase::isWriter() const
1451 Reference< XServiceInfo > xSI( mxModel, UNO_QUERY );
1452 return xSI.is() &&
1453 ( xSI->supportsService("com.sun.star.text.TextDocument") ||
1454 xSI->supportsService("com.sun.star.text.WebDocument") ||
1455 xSI->supportsService("com.sun.star.text.GlobalDocument") );
1458 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */