fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / xmloff / source / transform / TransformerBase.cxx
blob5619a0d24da997ce8a4bfcc7defd9eedd0730e63
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 <com/sun/star/i18n/CharacterClassification.hpp>
23 #include <com/sun/star/i18n/UnicodeType.hpp>
24 #include <com/sun/star/util/MeasureUnit.hpp>
25 #include <sax/tools/converter.hxx>
26 #include <comphelper/processfactory.hxx>
27 #include <xmloff/nmspmap.hxx>
28 #include "xmloff/xmlnmspe.hxx"
29 #include "IgnoreTContext.hxx"
30 #include "RenameElemTContext.hxx"
31 #include "ProcAttrTContext.hxx"
32 #include "ProcAddAttrTContext.hxx"
33 #include "MergeElemTContext.hxx"
34 #include "CreateElemTContext.hxx"
35 #include "MutableAttrList.hxx"
36 #include "TransformerActions.hxx"
37 #include "ElemTransformerAction.hxx"
38 #include "PropertyActionsOOo.hxx"
39 #include "TransformerTokenMap.hxx"
41 #include "TransformerBase.hxx"
42 #include "TContextVector.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, sal_False,
96 sal_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( !this, "unknown action" );
171 break;
175 // default is copying
176 return new XMLTransformerContext( *this, rQName );
179 XMLTransformerActions *XMLTransformerBase::GetUserDefinedActions( sal_uInt16 )
181 return 0;
184 XMLTransformerBase::XMLTransformerBase( XMLTransformerActionInit *pInit,
185 ::xmloff::token::XMLTokenEnum *pTKMapInit )
186 throw () :
187 m_pNamespaceMap( new SvXMLNamespaceMap ),
188 m_pReplaceNamespaceMap( new SvXMLNamespaceMap ),
189 m_pContexts( new XMLTransformerContextVector ),
190 m_pElemActions( new XMLTransformerActions( pInit ) ),
191 m_pTokenMap( new XMLTransformerTokenMap( pTKMapInit ) )
193 GetNamespaceMap().Add( GetXMLToken(XML_NP_XLINK), GetXMLToken(XML_N_XLINK), XML_NAMESPACE_XLINK );
194 GetNamespaceMap().Add( GetXMLToken(XML_NP_DC), GetXMLToken(XML_N_DC), XML_NAMESPACE_DC );
195 GetNamespaceMap().Add( GetXMLToken(XML_NP_MATH), GetXMLToken(XML_N_MATH), XML_NAMESPACE_MATH );
196 GetNamespaceMap().Add( GetXMLToken(XML_NP_OOO), GetXMLToken(XML_N_OOO), XML_NAMESPACE_OOO );
197 GetNamespaceMap().Add( GetXMLToken(XML_NP_DOM), GetXMLToken(XML_N_DOM), XML_NAMESPACE_DOM );
198 GetNamespaceMap().Add( GetXMLToken(XML_NP_OOOW), GetXMLToken(XML_N_OOOW), XML_NAMESPACE_OOOW );
199 GetNamespaceMap().Add( GetXMLToken(XML_NP_OOOC), GetXMLToken(XML_N_OOOC), XML_NAMESPACE_OOOC );
202 XMLTransformerBase::~XMLTransformerBase() throw ()
204 ResetTokens();
206 delete m_pNamespaceMap;
207 delete m_pReplaceNamespaceMap;
208 delete m_pContexts;
209 delete m_pElemActions;
210 delete m_pTokenMap;
213 void SAL_CALL XMLTransformerBase::startDocument( void )
214 throw( SAXException, RuntimeException )
216 m_xHandler->startDocument();
219 void SAL_CALL XMLTransformerBase::endDocument( void )
220 throw( SAXException, RuntimeException)
222 m_xHandler->endDocument();
225 void SAL_CALL XMLTransformerBase::startElement( const OUString& rName,
226 const Reference< XAttributeList >& rAttrList )
227 throw(SAXException, RuntimeException)
229 SvXMLNamespaceMap *pRewindMap = 0;
231 bool bRect = rName == "presentation:show-shape";
232 (void)bRect;
234 // Process namespace attributes. This must happen before creating the
235 // context, because namespace decaration apply to the element name itself.
236 XMLMutableAttributeList *pMutableAttrList = 0;
237 Reference< XAttributeList > xAttrList( rAttrList );
238 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
239 for( sal_Int16 i=0; i < nAttrCount; i++ )
241 const OUString& rAttrName = xAttrList->getNameByIndex( i );
242 if( ( rAttrName.getLength() >= 5 ) &&
243 ( rAttrName.startsWith( GetXMLToken(XML_XMLNS) ) ) &&
244 ( rAttrName.getLength() == 5 || ':' == rAttrName[5] ) )
246 if( !pRewindMap )
248 pRewindMap = m_pNamespaceMap;
249 m_pNamespaceMap = new SvXMLNamespaceMap( *m_pNamespaceMap );
251 const OUString& rAttrValue = xAttrList->getValueByIndex( i );
253 OUString aPrefix( ( rAttrName.getLength() == 5 )
254 ? OUString()
255 : rAttrName.copy( 6 ) );
256 // Add namespace, but only if it is known.
257 sal_uInt16 nKey = m_pNamespaceMap->AddIfKnown( aPrefix, rAttrValue );
258 // If namespace is unknown, try to match a name with similar
259 // TC Id an version
260 if( XML_NAMESPACE_UNKNOWN == nKey )
262 OUString aTestName( rAttrValue );
263 if( SvXMLNamespaceMap::NormalizeOasisURN( aTestName ) )
264 nKey = m_pNamespaceMap->AddIfKnown( aPrefix, aTestName );
266 // If that namespace is not known, too, add it as unknown
267 if( XML_NAMESPACE_UNKNOWN == nKey )
268 nKey = m_pNamespaceMap->Add( aPrefix, rAttrValue );
270 const OUString& rRepName = m_pReplaceNamespaceMap->GetNameByKey( nKey );
271 if( !rRepName.isEmpty() )
273 if( !pMutableAttrList )
275 pMutableAttrList = new XMLMutableAttributeList( xAttrList );
276 xAttrList = pMutableAttrList;
279 pMutableAttrList->SetValueByIndex( i, rRepName );
284 // Get element's namespace and local name.
285 OUString aLocalName;
286 sal_uInt16 nPrefix =
287 m_pNamespaceMap->GetKeyByAttrName( rName, &aLocalName );
289 // If there are contexts already, call a CreateChildContext at the topmost
290 // context. Otherwise, create a default context.
291 ::rtl::Reference < XMLTransformerContext > xContext;
292 if( !m_pContexts->empty() )
294 xContext = m_pContexts->back()->CreateChildContext( nPrefix,
295 aLocalName,
296 rName,
297 xAttrList );
299 else
301 xContext = CreateContext( nPrefix, aLocalName, rName );
304 OSL_ENSURE( xContext.is(), "XMLTransformerBase::startElement: missing context" );
305 if( !xContext.is() )
306 xContext = new XMLTransformerContext( *this, rName );
308 // Remember old namespace map.
309 if( pRewindMap )
310 xContext->SetRewindMap( pRewindMap );
312 // Push context on stack.
313 m_pContexts->push_back( xContext );
315 // Call a startElement at the new context.
316 xContext->StartElement( xAttrList );
319 void SAL_CALL XMLTransformerBase::endElement( const OUString&
320 #if OSL_DEBUG_LEVEL > 0
321 rName
322 #endif
324 throw(SAXException, RuntimeException)
326 if( !m_pContexts->empty() )
328 // Get topmost context
329 ::rtl::Reference< XMLTransformerContext > xContext = m_pContexts->back();
331 #if OSL_DEBUG_LEVEL > 0
332 OSL_ENSURE( xContext->GetQName() == rName,
333 "XMLTransformerBase::endElement: popped context has wrong lname" );
334 #endif
336 // Call a EndElement at the current context.
337 xContext->EndElement();
339 // and remove it from the stack.
340 m_pContexts->pop_back();
342 // Get a namespace map to rewind.
343 SvXMLNamespaceMap *pRewindMap = xContext->GetRewindMap();
345 // Delete the current context.
346 xContext = 0;
348 // Rewind a namespace map.
349 if( pRewindMap )
351 delete m_pNamespaceMap;
352 m_pNamespaceMap = pRewindMap;
357 void SAL_CALL XMLTransformerBase::characters( const OUString& rChars )
358 throw(SAXException, RuntimeException)
360 if( !m_pContexts->empty() )
362 m_pContexts->back()->Characters( rChars );
366 void SAL_CALL XMLTransformerBase::ignorableWhitespace( const OUString& rWhitespaces )
367 throw(SAXException, RuntimeException)
369 m_xHandler->ignorableWhitespace( rWhitespaces );
372 void SAL_CALL XMLTransformerBase::processingInstruction( const OUString& rTarget,
373 const OUString& rData )
374 throw(SAXException, RuntimeException)
376 m_xHandler->processingInstruction( rTarget, rData );
379 void SAL_CALL XMLTransformerBase::setDocumentLocator( const Reference< XLocator >& rLocator )
380 throw(SAXException, RuntimeException)
382 m_xLocator = rLocator;
385 // XExtendedDocumentHandler
386 void SAL_CALL XMLTransformerBase::startCDATA( void ) throw(SAXException, RuntimeException)
388 if( m_xExtHandler.is() )
389 m_xExtHandler->startCDATA();
392 void SAL_CALL XMLTransformerBase::endCDATA( void ) throw(RuntimeException)
394 if( m_xExtHandler.is() )
395 m_xExtHandler->endCDATA();
398 void SAL_CALL XMLTransformerBase::comment( const OUString& rComment )
399 throw(SAXException, RuntimeException)
401 if( m_xExtHandler.is() )
402 m_xExtHandler->comment( rComment );
405 void SAL_CALL XMLTransformerBase::allowLineBreak( void )
406 throw(SAXException, RuntimeException)
408 if( m_xExtHandler.is() )
409 m_xExtHandler->allowLineBreak();
412 void SAL_CALL XMLTransformerBase::unknown( const OUString& rString )
413 throw(SAXException, RuntimeException)
415 if( m_xExtHandler.is() )
416 m_xExtHandler->unknown( rString );
419 // XInitialize
420 void SAL_CALL XMLTransformerBase::initialize( const Sequence< Any >& aArguments )
421 throw(Exception, RuntimeException)
423 const sal_Int32 nAnyCount = aArguments.getLength();
424 const Any* pAny = aArguments.getConstArray();
426 for( sal_Int32 nIndex = 0; nIndex < nAnyCount; nIndex++, pAny++ )
428 // use isAssignableFrom instead of comparing the types to
429 // allow XExtendedDocumentHandler instead of XDocumentHandler (used in
430 // writeOasis2OOoLibraryElement in sfx2).
431 // The Any shift operator can't be used to query the type because it
432 // uses queryInterface, and the model also has a XPropertySet interface.
434 // document handler
435 if( ::getCppuType( (const Reference< XDocumentHandler >*) 0 ).isAssignableFrom( pAny->getValueType() ) )
436 m_xHandler.set( *pAny, UNO_QUERY );
438 // property set to transport data across
439 if( ::getCppuType( (const Reference< XPropertySet >*) 0 ).isAssignableFrom( pAny->getValueType() ) )
440 m_xPropSet.set( *pAny, UNO_QUERY );
442 // xmodel
443 if( ::getCppuType( (const Reference< ::com::sun::star::frame::XModel >*) 0 ).isAssignableFrom( pAny->getValueType() ) )
444 mxModel.set( *pAny, UNO_QUERY );
447 if( m_xPropSet.is() )
449 Any aAny;
450 OUString sRelPath, sName;
451 Reference< XPropertySetInfo > xPropSetInfo =
452 m_xPropSet->getPropertySetInfo();
453 OUString sPropName( "StreamRelPath" );
454 if( xPropSetInfo->hasPropertyByName(sPropName) )
456 aAny = m_xPropSet->getPropertyValue(sPropName);
457 aAny >>= sRelPath;
459 sPropName = OUString( "StreamName" );
460 if( xPropSetInfo->hasPropertyByName(sPropName) )
462 aAny = m_xPropSet->getPropertyValue(sPropName);
463 aAny >>= sName;
465 if( !sName.isEmpty() )
467 m_aExtPathPrefix = OUString( "../" );
469 // If there is a rel path within a package, then append
470 // additional '../'. If the rel path contains an ':', then it is
471 // an absolute URI (or invalid URI, because zip files don't
472 // permit ':'), and it will be ignored.
473 if( !sRelPath.isEmpty() )
475 sal_Int32 nColPos = sRelPath.indexOf( ':' );
476 OSL_ENSURE( -1 == nColPos,
477 "StreamRelPath contains ':', absolute URI?" );
479 if( -1 == nColPos )
481 OUString sTmp = m_aExtPathPrefix;
482 sal_Int32 nPos = 0;
485 m_aExtPathPrefix += sTmp;
486 nPos = sRelPath.indexOf( '/', nPos + 1 );
488 while( -1 != nPos );
496 static sal_Int16 lcl_getUnit( const OUString& rValue )
498 if( rValue.endsWithIgnoreAsciiCase( "cm" ) )
499 return util::MeasureUnit::CM;
500 else if ( rValue.endsWithIgnoreAsciiCase( "mm" ) )
501 return util::MeasureUnit::MM;
502 else
503 return util::MeasureUnit::INCH;
506 XMLMutableAttributeList *XMLTransformerBase::ProcessAttrList(
507 Reference< XAttributeList >& rAttrList, sal_uInt16 nActionMap,
508 sal_Bool bClone )
510 XMLMutableAttributeList *pMutableAttrList = 0;
511 XMLTransformerActions *pActions = GetUserDefinedActions( nActionMap );
512 OSL_ENSURE( pActions, "go no actions" );
513 if( pActions )
515 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
516 for( sal_Int16 i=0; i < nAttrCount; ++i )
518 const OUString& rAttrName = rAttrList->getNameByIndex( i );
519 const OUString& rAttrValue = rAttrList->getValueByIndex( i );
520 OUString aLocalName;
521 sal_uInt16 nPrefix = GetNamespaceMap().GetKeyByAttrName( rAttrName,
522 &aLocalName );
524 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
525 XMLTransformerActions::const_iterator aIter =
526 pActions->find( aKey );
527 if( !(aIter == pActions->end() ) )
529 if( !pMutableAttrList )
531 pMutableAttrList = new XMLMutableAttributeList( rAttrList,
532 bClone );
533 rAttrList = pMutableAttrList;
536 sal_uInt32 nAction = (*aIter).second.m_nActionType;
537 sal_Bool bRename = sal_False;
538 switch( nAction )
540 case XML_ATACTION_RENAME:
541 bRename = sal_True;
542 break;
543 case XML_ATACTION_COPY:
544 break;
545 case XML_ATACTION_REMOVE:
546 case XML_ATACTION_STYLE_DISPLAY_NAME:
547 pMutableAttrList->RemoveAttributeByIndex( i );
548 --i;
549 --nAttrCount;
550 break;
551 case XML_ATACTION_RENAME_IN2INCH:
552 bRename = sal_True;
553 case XML_ATACTION_IN2INCH:
555 OUString aAttrValue( rAttrValue );
556 if( ReplaceSingleInWithInch( aAttrValue ) )
557 pMutableAttrList->SetValueByIndex( i, aAttrValue );
559 break;
560 case XML_ATACTION_INS2INCHS:
562 OUString aAttrValue( rAttrValue );
563 if( ReplaceInWithInch( aAttrValue ) )
564 pMutableAttrList->SetValueByIndex( i, aAttrValue );
566 break;
567 case XML_ATACTION_RENAME_INCH2IN:
568 bRename = sal_True;
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, util::MeasureUnit::MM_100TH))
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 = sal_True;
616 case XML_ATACTION_DECODE_STYLE_NAME:
617 case XML_ATACTION_DECODE_STYLE_NAME_REF:
619 OUString aAttrValue( rAttrValue );
620 if( DecodeStyleName(aAttrValue) )
621 pMutableAttrList->SetValueByIndex( i, aAttrValue );
623 break;
624 case XML_ATACTION_ENCODE_STYLE_NAME:
626 OUString aAttrValue( rAttrValue );
627 if( EncodeStyleName(aAttrValue) )
629 pMutableAttrList->SetValueByIndex( i, aAttrValue );
630 OUString aNewAttrQName(
631 GetNamespaceMap().GetQNameByKey(
632 nPrefix,
633 ::xmloff::token::GetXMLToken(
634 XML_DISPLAY_NAME ) ) );
635 pMutableAttrList->AddAttribute( aNewAttrQName,
636 rAttrValue );
639 break;
640 case XML_ATACTION_RENAME_ENCODE_STYLE_NAME_REF:
641 bRename = sal_True;
642 case XML_ATACTION_ENCODE_STYLE_NAME_REF:
644 OUString aAttrValue( rAttrValue );
645 if( EncodeStyleName(aAttrValue) )
646 pMutableAttrList->SetValueByIndex( i, aAttrValue );
648 break;
649 case XML_ATACTION_RENAME_NEG_PERCENT:
650 bRename = sal_True;
651 case XML_ATACTION_NEG_PERCENT:
653 OUString aAttrValue( rAttrValue );
654 if( NegPercent( aAttrValue ) )
655 pMutableAttrList->SetValueByIndex( i, aAttrValue );
657 break;
658 case XML_ATACTION_RENAME_ADD_NAMESPACE_PREFIX:
659 bRename = sal_True;
660 case XML_ATACTION_ADD_NAMESPACE_PREFIX:
662 OUString aAttrValue( rAttrValue );
663 sal_uInt16 nValPrefix =
664 static_cast<sal_uInt16>(
665 bRename ? (*aIter).second.m_nParam2
666 : (*aIter).second.m_nParam1);
667 if( AddNamespacePrefix( aAttrValue, nValPrefix ) )
668 pMutableAttrList->SetValueByIndex( i, aAttrValue );
670 break;
671 case XML_ATACTION_ADD_APP_NAMESPACE_PREFIX:
673 OUString aAttrValue( rAttrValue );
674 sal_uInt16 nValPrefix =
675 static_cast<sal_uInt16>((*aIter).second.m_nParam1);
676 if( IsXMLToken( GetClass(), XML_SPREADSHEET ) )
677 nValPrefix = XML_NAMESPACE_OOOC;
678 else if( IsXMLToken( GetClass(), XML_TEXT ) )
679 nValPrefix = XML_NAMESPACE_OOOW;
680 if( AddNamespacePrefix( aAttrValue, nValPrefix ) )
681 pMutableAttrList->SetValueByIndex( i, aAttrValue );
683 break;
684 case XML_ATACTION_RENAME_REMOVE_NAMESPACE_PREFIX:
685 bRename = sal_True;
686 case XML_ATACTION_REMOVE_NAMESPACE_PREFIX:
688 OUString aAttrValue( rAttrValue );
689 sal_uInt16 nValPrefix =
690 static_cast<sal_uInt16>(
691 bRename ? (*aIter).second.m_nParam2
692 : (*aIter).second.m_nParam1);
693 if( RemoveNamespacePrefix( aAttrValue, nValPrefix ) )
694 pMutableAttrList->SetValueByIndex( i, aAttrValue );
696 break;
697 case XML_ATACTION_REMOVE_ANY_NAMESPACE_PREFIX:
699 OUString aAttrValue( rAttrValue );
700 if( RemoveNamespacePrefix( aAttrValue ) )
701 pMutableAttrList->SetValueByIndex( i, aAttrValue );
703 break;
704 case XML_ATACTION_URI_OOO:
706 OUString aAttrValue( rAttrValue );
707 if( ConvertURIToOASIS( aAttrValue,
708 static_cast< sal_Bool >((*aIter).second.m_nParam1)))
709 pMutableAttrList->SetValueByIndex( i, aAttrValue );
711 break;
712 case XML_ATACTION_URI_OASIS:
714 OUString aAttrValue( rAttrValue );
715 if( ConvertURIToOOo( aAttrValue,
716 static_cast< sal_Bool >((*aIter).second.m_nParam1)))
717 pMutableAttrList->SetValueByIndex( i, aAttrValue );
719 break;
720 case XML_ATACTION_RENAME_ATTRIBUTE:
722 OUString aAttrValue( rAttrValue );
723 RenameAttributeValue(
724 aAttrValue,
725 (*aIter).second.m_nParam1,
726 (*aIter).second.m_nParam2,
727 (*aIter).second.m_nParam3 );
728 pMutableAttrList->SetValueByIndex( i, aAttrValue );
730 break;
731 case XML_ATACTION_RNG2ISO_DATETIME:
733 OUString aAttrValue( rAttrValue );
734 if( ConvertRNGDateTimeToISO( aAttrValue ))
735 pMutableAttrList->SetValueByIndex( i, aAttrValue );
737 break;
738 case XML_ATACTION_RENAME_RNG2ISO_DATETIME:
740 OUString aAttrValue( rAttrValue );
741 if( ConvertRNGDateTimeToISO( aAttrValue ))
742 pMutableAttrList->SetValueByIndex( i, aAttrValue );
743 bRename = sal_True;
745 break;
746 case XML_ATACTION_IN2TWIPS:
748 OUString aAttrValue( rAttrValue );
749 XMLTransformerBase::ReplaceSingleInWithInch( aAttrValue );
751 if( isWriter() )
753 sal_Int16 const nDestUnit = lcl_getUnit(aAttrValue);
755 // convert inch value to twips and export as faked inch
756 sal_Int32 nMeasure;
757 if (::sax::Converter::convertMeasure(nMeasure,
758 aAttrValue, util::MeasureUnit::MM_100TH))
761 // #i13778#,#i36248#/ apply correct 1/100mm-to-twip conversion
762 nMeasure = (sal_Int32)( nMeasure >= 0
763 ? ((nMeasure*72+63)/127)
764 : ((nMeasure*72-63)/127) );
766 OUStringBuffer aBuffer;
767 ::sax::Converter::convertMeasure( aBuffer,
768 nMeasure, util::MeasureUnit::MM_100TH,
769 nDestUnit );
770 aAttrValue = aBuffer.makeStringAndClear();
774 pMutableAttrList->SetValueByIndex( i, aAttrValue );
776 break;
777 case XML_ATACTION_SVG_WIDTH_HEIGHT_OOO:
779 OUString aAttrValue( rAttrValue );
780 ReplaceSingleInchWithIn( aAttrValue );
782 sal_Int16 const nDestUnit = lcl_getUnit( aAttrValue );
784 sal_Int32 nMeasure;
785 if (::sax::Converter::convertMeasure(nMeasure,
786 aAttrValue, util::MeasureUnit::MM_100TH))
789 if( nMeasure > 0 )
790 nMeasure -= 1;
791 else if( nMeasure < 0 )
792 nMeasure += 1;
795 OUStringBuffer aBuffer;
796 ::sax::Converter::convertMeasure(aBuffer, nMeasure,
797 util::MeasureUnit::MM_100TH, nDestUnit);
798 aAttrValue = aBuffer.makeStringAndClear();
801 pMutableAttrList->SetValueByIndex( i, aAttrValue );
803 break;
804 case XML_ATACTION_SVG_WIDTH_HEIGHT_OASIS:
806 OUString aAttrValue( rAttrValue );
807 ReplaceSingleInWithInch( aAttrValue );
809 sal_Int16 const nDestUnit = lcl_getUnit( aAttrValue );
811 sal_Int32 nMeasure;
812 if (::sax::Converter::convertMeasure(nMeasure,
813 aAttrValue, util::MeasureUnit::MM_100TH))
816 if( nMeasure > 0 )
817 nMeasure += 1;
818 else if( nMeasure < 0 )
819 nMeasure -= 1;
822 OUStringBuffer aBuffer;
823 ::sax::Converter::convertMeasure(aBuffer, nMeasure,
824 util::MeasureUnit::MM_100TH, nDestUnit );
825 aAttrValue = aBuffer.makeStringAndClear();
828 pMutableAttrList->SetValueByIndex( i, aAttrValue );
830 break;
831 case XML_ATACTION_DECODE_ID:
833 const sal_Int32 nLen = rAttrValue.getLength();
834 OUStringBuffer aBuffer;
836 sal_Int32 pos;
837 for( pos = 0; pos < nLen; pos++ )
839 sal_Unicode c = rAttrValue[pos];
840 if( (c >= '0') && (c <= '9') )
841 aBuffer.append( c );
842 else
843 aBuffer.append( (sal_Int32)c );
846 pMutableAttrList->SetValueByIndex( i, aBuffer.makeStringAndClear() );
848 break;
849 // #i50322# - special handling for the
850 // transparency of writer background graphics.
851 case XML_ATACTION_WRITER_BACK_GRAPHIC_TRANSPARENCY:
853 // determine, if it's the transparency of a document style
854 XMLTransformerContext* pFirstContext = (*m_pContexts)[0].get();
855 OUString aFirstContextLocalName;
856 /* sal_uInt16 nFirstContextPrefix = */
857 GetNamespaceMap().GetKeyByAttrName( pFirstContext->GetQName(),
858 &aFirstContextLocalName );
859 bool bIsDocumentStyle(
860 ::xmloff::token::IsXMLToken( aFirstContextLocalName,
861 XML_DOCUMENT_STYLES ) );
862 // no conversion of transparency value for document
863 // styles, because former OpenOffice.org version writes
864 // writes always a transparency value of 100% and doesn't
865 // read the value. Thus, it's intepreted as 0%
866 if ( !bIsDocumentStyle )
868 OUString aAttrValue( rAttrValue );
869 NegPercent(aAttrValue);
870 pMutableAttrList->SetValueByIndex( i, aAttrValue );
872 bRename = sal_True;
874 break;
875 case XML_ATACTION_SHAPEID:
877 OUString sNewValue( "shape" );
878 sNewValue += rAttrValue;
879 pMutableAttrList->SetValueByIndex( i, sNewValue );
880 break;
883 default:
884 OSL_ENSURE( !this, "unknown action" );
885 break;
888 if( bRename )
890 OUString aNewAttrQName(
891 GetNamespaceMap().GetQNameByKey(
892 (*aIter).second.GetQNamePrefixFromParam1(),
893 ::xmloff::token::GetXMLToken(
894 (*aIter).second.GetQNameTokenFromParam1()) ) );
895 pMutableAttrList->RenameAttributeByIndex( i,
896 aNewAttrQName );
902 return pMutableAttrList;
905 sal_Bool XMLTransformerBase::ReplaceSingleInchWithIn( OUString& rValue )
907 sal_Bool bRet = sal_False;
908 sal_Int32 nPos = rValue.getLength();
909 while( nPos && rValue[nPos-1] <= ' ' )
910 --nPos;
911 if( nPos > 2 &&
912 ('c'==rValue[nPos-2] || 'C'==rValue[nPos-2]) &&
913 ('h'==rValue[nPos-1] || 'H'==rValue[nPos-1]) )
915 rValue =rValue.copy( 0, nPos-2 );
916 bRet = sal_True;
919 return bRet;
922 sal_Bool XMLTransformerBase::ReplaceInchWithIn( OUString& rValue )
924 sal_Bool bRet = sal_False;
925 sal_Int32 nPos = 1;
926 while( nPos < rValue.getLength()-3 )
928 sal_Unicode c = rValue[nPos];
929 if( 'i'==c || 'I'==c )
931 c = rValue[nPos-1];
932 if( (c >= '0' && c <= '9') || '.' == c )
934 c = rValue[nPos+1];
935 if( 'n'==c || 'N'==c )
937 c = rValue[nPos+2];
938 if( 'c'==c || 'C'==c )
940 c = rValue[nPos+3];
941 if( 'h'==c || 'H'==c )
943 rValue = rValue.replaceAt( nPos,
944 4, GetXMLToken(XML_UNIT_INCH) );
945 nPos += 2;
946 bRet = sal_True;
947 continue;
953 ++nPos;
956 return bRet;
959 sal_Bool XMLTransformerBase::ReplaceSingleInWithInch( OUString& rValue )
961 sal_Bool bRet = sal_False;
963 sal_Int32 nPos = rValue.getLength();
964 while( nPos && rValue[nPos-1] <= ' ' )
965 --nPos;
966 if( nPos > 2 &&
967 ('i'==rValue[nPos-2] ||
968 'I'==rValue[nPos-2]) &&
969 ('n'==rValue[nPos-1] ||
970 'N'==rValue[nPos-1]) )
972 nPos -= 2;
973 rValue = rValue.replaceAt( nPos, rValue.getLength() - nPos,
974 GetXMLToken(XML_INCH) );
975 bRet = sal_True;
978 return bRet;
981 sal_Bool XMLTransformerBase::ReplaceInWithInch( OUString& rValue )
983 sal_Bool bRet = sal_False;
984 sal_Int32 nPos = 1;
985 while( nPos < rValue.getLength()-1 )
987 sal_Unicode c = rValue[nPos];
988 if( 'i'==c || 'I'==c )
990 c = rValue[nPos-1];
991 if( (c >= '0' && c <= '9') || '.' == c )
993 c = rValue[nPos+1];
994 if( 'n'==c || 'N'==c )
996 rValue = rValue.replaceAt( nPos,
997 2, GetXMLToken(XML_INCH) );
998 nPos += 4;
999 bRet = sal_True;
1000 continue;
1004 ++nPos;
1007 return bRet;
1010 sal_Bool XMLTransformerBase::EncodeStyleName( OUString& rName ) const
1012 static sal_Char aHexTab[] = "0123456789abcdef";
1014 sal_Bool bEncoded = sal_False;
1016 sal_Int32 nLen = rName.getLength();
1017 OUStringBuffer aBuffer( nLen );
1019 for( sal_Int32 i = 0; i < nLen; i++ )
1021 sal_Unicode c = rName[i];
1022 sal_Bool bValidChar = sal_False;
1023 if( c < 0x00ffU )
1025 bValidChar =
1026 (c >= 0x0041 && c <= 0x005a) ||
1027 (c >= 0x0061 && c <= 0x007a) ||
1028 (c >= 0x00c0 && c <= 0x00d6) ||
1029 (c >= 0x00d8 && c <= 0x00f6) ||
1030 (c >= 0x00f8 && c <= 0x00ff) ||
1031 ( i > 0 && ( (c >= 0x0030 && c <= 0x0039) ||
1032 c == 0x00b7 || c == '-' || c == '.') );
1034 else
1036 if( (c >= 0xf900U && c <= 0xfffeU) ||
1037 (c >= 0x20ddU && c <= 0x20e0U))
1039 bValidChar = sal_False;
1041 else if( (c >= 0x02bbU && c <= 0x02c1U) || c == 0x0559 ||
1042 c == 0x06e5 || c == 0x06e6 )
1044 bValidChar = sal_True;
1046 else if( c == 0x0387 )
1048 bValidChar = i > 0;
1050 else
1052 if( !xCharClass.is() )
1054 const_cast < XMLTransformerBase * >(this)
1055 ->xCharClass = CharacterClassification::create( comphelper::getProcessComponentContext() );
1057 sal_Int16 nType = xCharClass->getType( rName, i );
1059 switch( nType )
1061 case UnicodeType::UPPERCASE_LETTER: // Lu
1062 case UnicodeType::LOWERCASE_LETTER: // Ll
1063 case UnicodeType::TITLECASE_LETTER: // Lt
1064 case UnicodeType::OTHER_LETTER: // Lo
1065 case UnicodeType::LETTER_NUMBER: // Nl
1066 bValidChar = sal_True;
1067 break;
1068 case UnicodeType::NON_SPACING_MARK: // Ms
1069 case UnicodeType::ENCLOSING_MARK: // Me
1070 case UnicodeType::COMBINING_SPACING_MARK: //Mc
1071 case UnicodeType::MODIFIER_LETTER: // Lm
1072 case UnicodeType::DECIMAL_DIGIT_NUMBER: // Nd
1073 bValidChar = i > 0;
1074 break;
1078 if( bValidChar )
1080 aBuffer.append( c );
1082 else
1084 aBuffer.append( static_cast< sal_Unicode >( '_' ) );
1085 if( c > 0x0fff )
1086 aBuffer.append( static_cast< sal_Unicode >(
1087 aHexTab[ (c >> 12) & 0x0f ] ) );
1088 if( c > 0x00ff )
1089 aBuffer.append( static_cast< sal_Unicode >(
1090 aHexTab[ (c >> 8) & 0x0f ] ) );
1091 if( c > 0x000f )
1092 aBuffer.append( static_cast< sal_Unicode >(
1093 aHexTab[ (c >> 4) & 0x0f ] ) );
1094 aBuffer.append( static_cast< sal_Unicode >(
1095 aHexTab[ c & 0x0f ] ) );
1096 aBuffer.append( static_cast< sal_Unicode >( '_' ) );
1097 bEncoded = sal_True;
1101 if( aBuffer.getLength() > (1<<15)-1 )
1102 bEncoded = sal_False;
1104 if( bEncoded )
1105 rName = aBuffer.makeStringAndClear();
1106 return bEncoded;
1109 sal_Bool XMLTransformerBase::DecodeStyleName( OUString& rName )
1111 sal_Bool bEncoded = sal_False;
1113 sal_Int32 nLen = rName.getLength();
1114 OUStringBuffer aBuffer( nLen );
1116 sal_Bool bWithinHex = sal_False;
1117 sal_Unicode cEnc = 0;
1118 for( sal_Int32 i = 0; i < nLen; i++ )
1120 sal_Unicode c = rName[i];
1121 if( '_' == c )
1123 if( bWithinHex )
1125 aBuffer.append( cEnc );
1126 cEnc = 0;
1128 else
1130 bEncoded = sal_True;
1132 bWithinHex = !bWithinHex;
1134 else if( bWithinHex )
1136 sal_Unicode cDigit;
1137 if( c >= '0' && c <= '9' )
1139 cDigit = c - '0';
1141 else if( c >= 'a' && c <= 'f' )
1143 cDigit = c - 'a' + 10;
1145 else if( c >= 'A' && c <= 'F' )
1147 cDigit = c - 'A' + 10;
1149 else
1151 // error
1152 bEncoded = sal_False;
1153 break;
1155 cEnc = (cEnc << 4) + cDigit;
1157 else
1159 aBuffer.append( c );
1163 if( bEncoded )
1164 rName = aBuffer.makeStringAndClear();
1165 return bEncoded;
1168 sal_Bool XMLTransformerBase::NegPercent( OUString& rValue )
1170 sal_Bool bRet = sal_False;
1171 sal_Bool bNeg = sal_False;
1172 double nVal = 0;
1174 sal_Int32 nPos = 0;
1175 sal_Int32 nLen = rValue.getLength();
1177 // skip white space
1178 while( nPos < nLen && sal_Unicode(' ') == rValue[nPos] )
1179 nPos++;
1181 if( nPos < nLen && sal_Unicode('-') == rValue[nPos] )
1183 bNeg = sal_True;
1184 nPos++;
1187 // get number
1188 while( nPos < nLen &&
1189 sal_Unicode('0') <= rValue[nPos] &&
1190 sal_Unicode('9') >= rValue[nPos] )
1192 // TODO: check overflow!
1193 nVal *= 10;
1194 nVal += (rValue[nPos] - sal_Unicode('0'));
1195 nPos++;
1197 double nDiv = 1.;
1198 if( nPos < nLen && sal_Unicode('.') == rValue[nPos] )
1200 nPos++;
1202 while( nPos < nLen &&
1203 sal_Unicode('0') <= rValue[nPos] &&
1204 sal_Unicode('9') >= rValue[nPos] )
1206 // TODO: check overflow!
1207 nDiv *= 10;
1208 nVal += ( static_cast<double>(rValue[nPos] - sal_Unicode('0')) / nDiv );
1209 nPos++;
1213 // skip white space
1214 while( nPos < nLen && sal_Unicode(' ') == rValue[nPos] )
1215 nPos++;
1217 if( nPos < nLen && sal_Unicode('%') == rValue[nPos] )
1219 if( bNeg )
1220 nVal = -nVal;
1221 nVal += .5;
1223 sal_Int32 nIntVal = 100 - static_cast<sal_Int32>( nVal );
1225 OUStringBuffer aNewValBuffer;
1226 aNewValBuffer.append( nIntVal );
1227 aNewValBuffer.append( sal_Unicode('%' ) );
1229 rValue = aNewValBuffer.makeStringAndClear();
1230 bRet = sal_True;
1233 return bRet;
1236 sal_Bool XMLTransformerBase::AddNamespacePrefix( OUString& rName,
1237 sal_uInt16 nPrefix ) const
1239 rName = GetNamespaceMap().GetQNameByKey( nPrefix, rName, sal_False );
1240 return sal_True;
1243 sal_Bool XMLTransformerBase::RemoveNamespacePrefix( OUString& rName,
1244 sal_uInt16 nPrefixOnly ) const
1246 OUString aLocalName;
1247 sal_uInt16 nPrefix =
1248 GetNamespaceMap()._GetKeyByAttrName( rName, &aLocalName, sal_False );
1249 sal_Bool bRet = XML_NAMESPACE_UNKNOWN != nPrefix &&
1250 (USHRT_MAX == nPrefixOnly || nPrefix == nPrefixOnly);
1251 if( bRet )
1252 rName = aLocalName;
1254 return bRet;
1257 sal_Bool XMLTransformerBase::ConvertURIToOASIS( OUString& rURI,
1258 sal_Bool bSupportPackage ) const
1260 sal_Bool bRet = sal_False;
1261 if( !m_aExtPathPrefix.isEmpty() && !rURI.isEmpty() )
1263 sal_Bool bRel = sal_False;
1264 switch( rURI[0] )
1266 case '#':
1267 // no rel path, but
1268 // for package URIs, the '#' has to be removed
1269 if( bSupportPackage )
1271 rURI = rURI.copy( 1 );
1272 bRet = sal_True;
1274 break;
1275 case '/':
1276 // no rel path; nothing to do
1277 break;
1278 case '.':
1279 // a rel path; to keep URI simple, remove './', if there
1280 bRel = sal_True;
1281 if( rURI.getLength() > 1 && '/' == rURI[1] )
1283 rURI = rURI.copy( 2 );
1284 bRet = sal_True;
1286 break;
1287 default:
1288 // check for a RFC2396 schema
1290 bRel = sal_True;
1291 sal_Int32 nPos = 1;
1292 sal_Int32 nLen = rURI.getLength();
1293 while( nPos < nLen )
1295 switch( rURI[nPos] )
1297 case '/':
1298 // a relative path segement
1299 nPos = nLen; // leave loop
1300 break;
1301 case ':':
1302 // a schema
1303 bRel = sal_False;
1304 nPos = nLen; // leave loop
1305 break;
1306 default:
1307 // we don't care about any other characters
1308 break;
1310 ++nPos;
1315 if( bRel )
1317 OUString sTmp( m_aExtPathPrefix );
1318 sTmp += rURI;
1319 rURI = sTmp;
1320 bRet = sal_True;
1324 return bRet;
1327 sal_Bool XMLTransformerBase::ConvertURIToOOo( OUString& rURI,
1328 sal_Bool bSupportPackage ) const
1330 sal_Bool bRet = sal_False;
1331 if( !rURI.isEmpty() )
1333 sal_Bool bPackage = sal_False;
1334 switch( rURI[0] )
1336 case '/':
1337 // no rel path; nothing to to
1338 break;
1339 case '.':
1340 // a rel path
1341 if( rURI.startsWith( m_aExtPathPrefix ) )
1343 // an external URI; remove '../'
1344 rURI = rURI.copy( m_aExtPathPrefix.getLength() );
1345 bRet = sal_True;
1347 else
1349 bPackage = sal_True;
1351 break;
1352 default:
1353 // check for a RFC2396 schema
1355 bPackage = sal_True;
1356 sal_Int32 nPos = 1;
1357 sal_Int32 nLen = rURI.getLength();
1358 while( nPos < nLen )
1360 switch( rURI[nPos] )
1362 case '/':
1363 // a relative path segement within the package
1364 nPos = nLen; // leave loop
1365 break;
1366 case ':':
1367 // a schema
1368 bPackage = sal_False;
1369 nPos = nLen; // leave loop
1370 break;
1371 default:
1372 // we don't care about any other characters
1373 break;
1375 ++nPos;
1380 if( bPackage && bSupportPackage )
1382 OUString sTmp( OUString::valueOf( sal_Unicode( '#' ) ) );
1383 if( rURI.startsWith( "./" ) )
1384 rURI = rURI.copy( 2 );
1385 sTmp += rURI;
1386 rURI = sTmp;
1387 bRet = sal_True;
1391 return bRet;
1394 sal_Bool XMLTransformerBase::RenameAttributeValue(
1395 OUString& rOutAttributeValue,
1396 sal_Int32 nParam1,
1397 sal_Int32 nParam2,
1398 sal_Int32 nParam3 )
1400 return ( lcl_ConvertAttr( rOutAttributeValue, nParam1) ||
1401 lcl_ConvertAttr( rOutAttributeValue, nParam2) ||
1402 lcl_ConvertAttr( rOutAttributeValue, nParam3) );
1405 // static
1406 bool XMLTransformerBase::ConvertRNGDateTimeToISO( OUString& rDateTime )
1408 if( !rDateTime.isEmpty() &&
1409 rDateTime.indexOf( sal_Unicode('.')) != -1 )
1411 rDateTime = rDateTime.replace( sal_Unicode('.'), sal_Unicode(','));
1412 return true;
1415 return false;
1418 XMLTokenEnum XMLTransformerBase::GetToken( const OUString& rStr ) const
1420 XMLTransformerTokenMap::const_iterator aIter =
1421 m_pTokenMap->find( rStr );
1422 if( aIter == m_pTokenMap->end() )
1423 return XML_TOKEN_END;
1424 else
1425 return (*aIter).second;
1430 const XMLTransformerContext *XMLTransformerBase::GetCurrentContext() const
1432 OSL_ENSURE( !m_pContexts->empty(), "empty stack" );
1435 return m_pContexts->empty() ? 0 : m_pContexts->back().get();
1438 const XMLTransformerContext *XMLTransformerBase::GetAncestorContext(
1439 sal_uInt32 n ) const
1441 XMLTransformerContextVector::size_type nSize =
1442 m_pContexts->size();
1443 XMLTransformerContextVector::size_type nPos =
1444 static_cast<XMLTransformerContextVector::size_type>( n );
1446 OSL_ENSURE( nSize >nPos+2 , "invalid context" );
1448 return nSize > nPos+2 ? (*m_pContexts)[nSize-(nPos+2)].get() : 0;
1451 bool XMLTransformerBase::isWriter() const
1453 Reference< XServiceInfo > xSI( mxModel, UNO_QUERY );
1454 return xSI.is() &&
1455 ( xSI->supportsService( OUString( "com.sun.star.text.TextDocument" ) ) ||
1456 xSI->supportsService( OUString( "com.sun.star.text.WebDocument" ) ) ||
1457 xSI->supportsService( OUString( "com.sun.star.text.GlobalDocument" ) ) );
1460 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */