21#include <rtl/ustrbuf.hxx>
24#include <osl/diagnose.h>
25#include <com/sun/star/i18n/CharacterClassification.hpp>
26#include <com/sun/star/i18n/UnicodeType.hpp>
27#include <com/sun/star/util/MeasureUnit.hpp>
58bool lcl_ConvertAttr( OUString & rOutAttribute, sal_Int32 nParam )
76 const OUString& rLocalName,
const OUString& rQName )
78 XMLTransformerActions::key_type aKey( nPrefix, rLocalName );
79 XMLTransformerActions::const_iterator aIter =
84 sal_uInt32 nActionType = (*aIter).second.m_nActionType;
91 "unknown or not persistent action" );
104 (*aIter).second.GetQNamePrefixFromParam1(),
105 (*aIter).second.GetQNameTokenFromParam1() );
108 (*aIter).second.GetQNamePrefixFromParam1(),
109 (*aIter).second.GetQNameTokenFromParam1(),
110 (*aIter).second.GetQNamePrefixFromParam2(),
111 (*aIter).second.GetQNameTokenFromParam2(),
112 static_cast< XMLTokenEnum >( (*aIter).second.m_nParam3 ) );
115 (*aIter).second.GetQNamePrefixFromParam1(),
116 (*aIter).second.GetQNameTokenFromParam1(),
117 static_cast< sal_uInt16
>( (*aIter).second.m_nParam2 ) );
120 (*aIter).second.GetQNamePrefixFromParam1(),
121 (*aIter).second.GetQNameTokenFromParam1(),
122 static_cast< sal_uInt16
>(
123 (*aIter).second.m_nParam3 >> 16 ),
124 (*aIter).second.GetQNamePrefixFromParam2(),
125 (*aIter).second.GetQNameTokenFromParam2(),
127 (*aIter).second.m_nParam3 & 0xffff ) );
132 (*aIter).second.GetQNamePrefixFromParam3(),
133 (*aIter).second.GetQNameTokenFromParam3() ) )
135 (*aIter).second.GetQNamePrefixFromParam1(),
136 (*aIter).second.GetQNameTokenFromParam1(),
137 static_cast< sal_uInt16
>( (*aIter).second.m_nParam2 ) );
140 static_cast< sal_uInt16
>( (*aIter).second.m_nParam2 ) );
144 static_cast< sal_uInt16
>( (*aIter).second.m_nParam1 ) );
149 (*aIter).second.GetQNamePrefixFromParam1(),
150 (*aIter).second.GetQNameTokenFromParam1() ) )
152 static_cast< sal_uInt16
>( (*aIter).second.m_nParam2 ) );
157 static_cast< sal_uInt16
>( (*aIter).second.m_nParam1 ) );
160 static_cast< sal_uInt16
>( (*aIter).second.m_nParam1 ) );
162 OSL_ENSURE(
false,
"unknown action" );
180 m_ElemActions( pInit ),
181 m_TokenMap( pTKMapInit )
207 const Reference< XAttributeList >& rAttrList )
209 std::unique_ptr<SvXMLNamespaceMap> pRewindMap;
214 Reference< XAttributeList > xAttrList( rAttrList );
215 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
216 for( sal_Int16
i=0;
i < nAttrCount;
i++ )
218 const OUString& rAttrName = xAttrList->getNameByIndex(
i );
219 if( ( rAttrName.getLength() >= 5 ) &&
220 ( rAttrName.startsWith(
GetXMLToken(XML_XMLNS) ) ) &&
221 ( rAttrName.getLength() == 5 ||
':' == rAttrName[5] ) )
228 const OUString& rAttrValue = xAttrList->getValueByIndex(
i );
230 OUString aPrefix( ( rAttrName.getLength() == 5 )
232 : rAttrName.copy( 6 ) );
239 OUString aTestName( rAttrValue );
248 if( !rRepName.isEmpty() )
250 if( !pMutableAttrList )
253 xAttrList = pMutableAttrList;
256 pMutableAttrList->SetValueByIndex(
i, rRepName );
271 xContext =
m_vContexts.back()->CreateChildContext( nPrefix,
281 OSL_ENSURE( xContext.is(),
"XMLTransformerBase::startElement: missing context" );
287 xContext->PutRewindMap( std::move(pRewindMap) );
293 xContext->StartElement( xAttrList );
297#
if OSL_DEBUG_LEVEL > 0
308#if OSL_DEBUG_LEVEL > 0
309 OSL_ENSURE( xContext->GetQName() == rName,
310 "XMLTransformerBase::endElement: popped context has wrong lname" );
314 xContext->EndElement();
320 std::unique_ptr<SvXMLNamespaceMap> pRewindMap = xContext->TakeRewindMap();
342 m_xHandler->ignorableWhitespace( rWhitespaces );
346 const OUString& rData )
387 css::uno::Reference< XFastDocumentHandler > xFastHandler;
388 if( (rArgument >>= xFastHandler) && xFastHandler )
390 SvXMLImport *pFastHandler =
static_cast<SvXMLImport*
>( xFastHandler.get() );
403 mxModel.set( rArgument, UNO_QUERY );
409 OUString sRelPath,
sName;
410 Reference< XPropertySetInfo > xPropSetInfo =
412 OUString sPropName(
"StreamRelPath" );
413 if( xPropSetInfo->hasPropertyByName(sPropName) )
415 aAny =
m_xPropSet->getPropertyValue(sPropName);
418 sPropName =
"StreamName";
419 if( xPropSetInfo->hasPropertyByName(sPropName) )
421 aAny =
m_xPropSet->getPropertyValue(sPropName);
424 if( !
sName.isEmpty() )
432 if( !sRelPath.isEmpty() )
434 sal_Int32 nColPos = sRelPath.indexOf(
':' );
435 OSL_ENSURE( -1 == nColPos,
436 "StreamRelPath contains ':', absolute URI?" );
445 nPos = sRelPath.indexOf(
'/',
nPos + 1 );
460 return util::MeasureUnit::CM;
462 return util::MeasureUnit::MM;
464 return util::MeasureUnit::INCH;
468 Reference< XAttributeList >& rAttrList, sal_uInt16 nActionMap,
473 OSL_ENSURE( pActions,
"go no actions" );
476 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
477 for( sal_Int16
i=0;
i < nAttrCount; ++
i )
479 const OUString& rAttrName = rAttrList->getNameByIndex(
i );
480 const OUString& rAttrValue = rAttrList->getValueByIndex(
i );
485 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
486 XMLTransformerActions::const_iterator aIter =
487 pActions->find( aKey );
488 if( aIter != pActions->end() )
490 if( !pMutableAttrList )
494 rAttrList = pMutableAttrList;
497 sal_uInt32 nAction = (*aIter).second.m_nActionType;
498 bool bRename =
false;
508 pMutableAttrList->RemoveAttributeByIndex(
i );
517 OUString aAttrValue( rAttrValue );
519 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
524 OUString aAttrValue( rAttrValue );
526 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
534 OUString aAttrValue( rAttrValue );
536 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
541 OUString aAttrValue( rAttrValue );
543 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
548 OUString aAttrValue( rAttrValue );
553 sal_Int16
const nDestUnit =
lcl_getUnit(aAttrValue);
564 nMeasure, util::MeasureUnit::MM_100TH,
566 aAttrValue =
aBuffer.makeStringAndClear();
570 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
579 OUString aAttrValue( rAttrValue );
581 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
586 OUString aAttrValue( rAttrValue );
589 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
590 OUString aNewAttrQName(
595 pMutableAttrList->AddAttribute( aNewAttrQName,
605 OUString aAttrValue( rAttrValue );
607 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
615 OUString aAttrValue( rAttrValue );
617 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
625 OUString aAttrValue( rAttrValue );
626 sal_uInt16 nValPrefix =
627 static_cast<sal_uInt16
>(
628 bRename ? (*aIter).second.m_nParam2
629 : (*aIter).second.m_nParam1);
631 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
636 OUString aAttrValue( rAttrValue );
637 sal_uInt16 nValPrefix =
638 static_cast<sal_uInt16
>((*aIter).second.m_nParam1);
644 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
652 OUString aAttrValue( rAttrValue );
653 sal_uInt16 nValPrefix =
654 static_cast<sal_uInt16
>(
655 bRename ? (*aIter).second.m_nParam2
656 : (*aIter).second.m_nParam1);
658 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
663 OUString aAttrValue( rAttrValue );
665 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
670 OUString aAttrValue( rAttrValue );
672 static_cast< bool >((*aIter).second.m_nParam1)))
673 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
678 OUString aAttrValue( rAttrValue );
680 static_cast< bool >((*aIter).second.m_nParam1)))
681 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
686 OUString aAttrValue( rAttrValue );
689 (*aIter).second.m_nParam1,
690 (*aIter).second.m_nParam2,
691 (*aIter).second.m_nParam3 );
692 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
697 OUString aAttrValue( rAttrValue );
699 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
704 OUString aAttrValue( rAttrValue );
706 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
712 OUString aAttrValue( rAttrValue );
717 sal_Int16
const nDestUnit =
lcl_getUnit(aAttrValue);
728 nMeasure, util::MeasureUnit::MM_100TH,
730 aAttrValue =
aBuffer.makeStringAndClear();
734 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
739 OUString aAttrValue( rAttrValue );
742 sal_Int16
const nDestUnit =
lcl_getUnit( aAttrValue );
751 else if( nMeasure < 0 )
757 util::MeasureUnit::MM_100TH, nDestUnit);
758 aAttrValue =
aBuffer.makeStringAndClear();
761 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
766 OUString aAttrValue( rAttrValue );
769 sal_Int16
const nDestUnit =
lcl_getUnit( aAttrValue );
778 else if( nMeasure < 0 )
784 util::MeasureUnit::MM_100TH, nDestUnit );
785 aAttrValue =
aBuffer.makeStringAndClear();
788 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
793 const sal_Int32 nLen = rAttrValue.getLength();
800 if( (c >=
'0') && (c <=
'9') )
803 aBuffer.append(
static_cast<sal_Int32
>(c) );
806 pMutableAttrList->SetValueByIndex(
i,
aBuffer.makeStringAndClear() );
815 OUString aFirstContextLocalName;
818 &aFirstContextLocalName );
819 bool bIsDocumentStyle(
826 if ( !bIsDocumentStyle )
828 OUString aAttrValue( rAttrValue );
830 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
837 OUString sNewValue =
"shape" + rAttrValue;
838 pMutableAttrList->SetValueByIndex(
i, sNewValue );
843 OSL_ENSURE(
false,
"unknown action" );
849 OUString aNewAttrQName(
851 (*aIter).second.GetQNamePrefixFromParam1(),
853 (*aIter).second.GetQNameTokenFromParam1()) ) );
854 pMutableAttrList->RenameAttributeByIndex(
i,
861 return pMutableAttrList.get();
867 sal_Int32
nPos = rValue.getLength();
868 while(
nPos && rValue[
nPos-1] <=
' ' )
871 (
'c'==rValue[
nPos-2] ||
'C'==rValue[
nPos-2]) &&
872 (
'h'==rValue[
nPos-1] ||
'H'==rValue[
nPos-1]) )
874 rValue =rValue.copy( 0,
nPos-2 );
885 while(
nPos < rValue.getLength()-3 )
888 if(
'i'==c ||
'I'==c )
891 if( (c >=
'0' && c <=
'9') ||
'.' == c )
894 if(
'n'==c ||
'N'==c )
897 if(
'c'==c ||
'C'==c )
900 if(
'h'==c ||
'H'==c )
902 rValue = rValue.replaceAt(
nPos,
922 sal_Int32
nPos = rValue.getLength();
923 while(
nPos && rValue[
nPos-1] <=
' ' )
926 (
'i'==rValue[
nPos-2] ||
927 'I'==rValue[
nPos-2]) &&
928 (
'n'==rValue[
nPos-1] ||
929 'N'==rValue[
nPos-1]) )
932 rValue = rValue.replaceAt(
nPos, rValue.getLength() -
nPos,
944 while(
nPos < rValue.getLength()-1 )
947 if(
'i'==c ||
'I'==c )
950 if( (c >=
'0' && c <=
'9') ||
'.' == c )
953 if(
'n'==c ||
'N'==c )
955 rValue = rValue.replaceAt(
nPos,
971 static const char aHexTab[] =
"0123456789abcdef";
973 bool bEncoded =
false;
975 sal_Int32 nLen = rName.getLength();
976 OUStringBuffer
aBuffer( nLen );
978 for( sal_Int32
i = 0;
i < nLen;
i++ )
981 bool bValidChar =
false;
985 (c >= 0x0041 && c <= 0x005a) ||
986 (c >= 0x0061 && c <= 0x007a) ||
987 (c >= 0x00c0 && c <= 0x00d6) ||
988 (c >= 0x00d8 && c <= 0x00f6) ||
989 (c >= 0x00f8 && c <= 0x00ff) ||
990 (
i > 0 && ( (c >= 0x0030 && c <= 0x0039) ||
991 c == 0x00b7 || c ==
'-' || c ==
'.') );
995 if( (c >= 0xf900U && c <= 0xfffeU) ||
996 (c >= 0x20ddU && c <= 0x20e0U))
1000 else if( (c >= 0x02bbU && c <= 0x02c1U) || c == 0x0559 ||
1001 c == 0x06e5 || c == 0x06e6 )
1005 else if( c == 0x0387 )
1020 case UnicodeType::UPPERCASE_LETTER:
1021 case UnicodeType::LOWERCASE_LETTER:
1022 case UnicodeType::TITLECASE_LETTER:
1023 case UnicodeType::OTHER_LETTER:
1024 case UnicodeType::LETTER_NUMBER:
1027 case UnicodeType::NON_SPACING_MARK:
1028 case UnicodeType::ENCLOSING_MARK:
1029 case UnicodeType::COMBINING_SPACING_MARK:
1030 case UnicodeType::MODIFIER_LETTER:
1031 case UnicodeType::DECIMAL_DIGIT_NUMBER:
1046 aHexTab[ (c >> 12) & 0x0f ] ) );
1049 aHexTab[ (c >> 8) & 0x0f ] ) );
1052 aHexTab[ (c >> 4) & 0x0f ] ) );
1060 if(
aBuffer.getLength() > (1<<15)-1 )
1064 rName =
aBuffer.makeStringAndClear();
1070 bool bEncoded =
false;
1072 sal_Int32 nLen = rName.getLength();
1073 OUStringBuffer
aBuffer( nLen );
1075 bool bWithinHex =
false;
1077 for( sal_Int32
i = 0;
i < nLen;
i++ )
1091 bWithinHex = !bWithinHex;
1093 else if( bWithinHex )
1096 if( c >=
'0' && c <=
'9' )
1100 else if( c >=
'a' && c <=
'f' )
1102 cDigit = c -
'a' + 10;
1104 else if( c >=
'A' && c <=
'F' )
1106 cDigit = c -
'A' + 10;
1114 cEnc = (cEnc << 4) + cDigit;
1123 rName =
aBuffer.makeStringAndClear();
1134 sal_Int32 nLen = rValue.getLength();
1137 while(
nPos < nLen &&
' ' == rValue[
nPos] )
1140 if(
nPos < nLen &&
'-' == rValue[
nPos] )
1147 while(
nPos < nLen &&
1148 '0' <= rValue[
nPos] &&
1149 '9' >= rValue[
nPos] )
1153 nVal += (rValue[
nPos] -
'0');
1156 if(
nPos < nLen &&
'.' == rValue[
nPos] )
1161 while(
nPos < nLen &&
1162 '0' <= rValue[
nPos] &&
1163 '9' >= rValue[
nPos] )
1167 nVal += (
static_cast<double>(rValue[
nPos] -
'0') / nDiv );
1173 while(
nPos < nLen &&
' ' == rValue[
nPos] )
1176 if(
nPos < nLen &&
'%' == rValue[
nPos] )
1182 sal_Int32 nIntVal = 100 -
static_cast<sal_Int32
>( nVal );
1184 rValue = OUString::number(nIntVal) +
"%";
1193 sal_uInt16 nPrefix )
const
1199 sal_uInt16 nPrefixOnly )
const
1201 OUString aLocalName;
1202 sal_uInt16 nPrefix =
1205 (USHRT_MAX == nPrefixOnly || nPrefix == nPrefixOnly);
1213 bool bSupportPackage )
const
1224 if( bSupportPackage )
1226 rURI = rURI.copy( 1 );
1236 if( rURI.getLength() > 1 &&
'/' == rURI[1] )
1238 rURI = rURI.copy( 2 );
1247 sal_Int32 nLen = rURI.getLength();
1248 while(
nPos < nLen )
1250 switch( rURI[
nPos] )
1281 bool bSupportPackage )
const
1284 if( !rURI.isEmpty() )
1286 bool bPackage =
false;
1310 sal_Int32 nLen = rURI.getLength();
1311 while(
nPos < nLen )
1313 switch( rURI[
nPos] )
1333 if( bPackage && bSupportPackage )
1335 if( rURI.startsWith(
"./" ) )
1336 rURI = rURI.copy( 2 );
1346 OUString& rOutAttributeValue,
1351 return ( lcl_ConvertAttr( rOutAttributeValue, nParam1) ||
1352 lcl_ConvertAttr( rOutAttributeValue, nParam2) ||
1353 lcl_ConvertAttr( rOutAttributeValue, nParam3) );
1359 if( !rDateTime.isEmpty() &&
1360 rDateTime.indexOf(
'.' ) != -1 )
1362 rDateTime = rDateTime.replace(
'.',
',');
1371 XMLTransformerTokenMap::const_iterator aIter =
1376 return (*aIter).second;
1382 OSL_ENSURE( !
m_vContexts.empty(),
"empty stack" );
1389 sal_uInt32 n )
const
1393 OSL_ENSURE( nSize >
n + 2 ,
"invalid context" );
1400 Reference< XServiceInfo > xSI(
mxModel, UNO_QUERY );
1402 ( xSI->supportsService(
"com.sun.star.text.TextDocument") ||
1403 xSI->supportsService(
"com.sun.star.text.WebDocument") ||
1404 xSI->supportsService(
"com.sun.star.text.GlobalDocument") );
@ XML_ATACTION_WRITER_BACK_GRAPHIC_TRANSPARENCY
constexpr auto convertTwipToMm100(N n)
OUString GetQNameByKey(sal_uInt16 nKey, const OUString &rLocalName, bool bCache=true) const
const OUString & GetNameByKey(sal_uInt16 nKey) const
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
static bool NormalizeOasisURN(OUString &rName)
sal_uInt16 GetKeyByAttrValueQName(const OUString &rAttrName, OUString *pLocalName) const
bool HasQName(sal_uInt16 nPrefix, ::xmloff::token::XMLTokenEnum eToken) const
const OUString & GetQName() const
virtual bool IsPersistent() const
static bool convertMeasure(sal_Int32 &rValue, std::u16string_view rString, sal_Int16 nTargetUnit=css::util::MeasureUnit::MM_100TH, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
Sequence< PropertyValue > aArguments
Reference< XComponentContext > getProcessComponentContext()
const sal_uInt16 XML_NAMESPACE_UNKNOWN
bool endsWithIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2, std::u16string_view *rest=nullptr)
constexpr auto toTwips(N number, Length from)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
std::unique_ptr< char[]> aBuffer
constexpr sal_uInt16 XML_NAMESPACE_DC
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_OOOC
constexpr sal_uInt16 XML_NAMESPACE_DOM
constexpr sal_uInt16 XML_NAMESPACE_OOOW
constexpr sal_uInt16 XML_NAMESPACE_OOO
constexpr sal_uInt16 XML_NAMESPACE_MATH