20 #include <rtl/ref.hxx>
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>
47 using namespace ::
osl;
58 bool 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 )
348 m_xHandler->processingInstruction( rTarget, rData );
379 for(
const auto& rArgument : aArguments )
387 css::uno::Reference< XFastDocumentHandler > xFastHandler;
388 if( (rArgument >>= xFastHandler) && xFastHandler )
404 mxModel.set( rArgument, UNO_QUERY );
410 OUString sRelPath,
sName;
411 Reference< XPropertySetInfo > xPropSetInfo =
413 OUString sPropName(
"StreamRelPath" );
414 if( xPropSetInfo->hasPropertyByName(sPropName) )
416 aAny =
m_xPropSet->getPropertyValue(sPropName);
419 sPropName =
"StreamName";
420 if( xPropSetInfo->hasPropertyByName(sPropName) )
422 aAny =
m_xPropSet->getPropertyValue(sPropName);
425 if( !sName.isEmpty() )
433 if( !sRelPath.isEmpty() )
435 sal_Int32 nColPos = sRelPath.indexOf(
':' );
436 OSL_ENSURE( -1 == nColPos,
437 "StreamRelPath contains ':', absolute URI?" );
446 nPos = sRelPath.indexOf(
'/', nPos + 1 );
460 if( rValue.endsWithIgnoreAsciiCase(
"cm" ) )
461 return util::MeasureUnit::CM;
462 else if ( rValue.endsWithIgnoreAsciiCase(
"mm" ) )
463 return util::MeasureUnit::MM;
465 return util::MeasureUnit::INCH;
469 Reference< XAttributeList >& rAttrList, sal_uInt16 nActionMap,
474 OSL_ENSURE( pActions,
"go no actions" );
477 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
478 for( sal_Int16
i=0;
i < nAttrCount; ++
i )
480 const OUString& rAttrName = rAttrList->getNameByIndex(
i );
481 const OUString& rAttrValue = rAttrList->getValueByIndex(
i );
486 XMLTransformerActions::key_type aKey( nPrefix, aLocalName );
487 XMLTransformerActions::const_iterator aIter =
488 pActions->find( aKey );
489 if( aIter != pActions->end() )
491 if( !pMutableAttrList )
495 rAttrList = pMutableAttrList;
498 sal_uInt32 nAction = (*aIter).second.m_nActionType;
499 bool bRename =
false;
509 pMutableAttrList->RemoveAttributeByIndex(
i );
518 OUString aAttrValue( rAttrValue );
520 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
525 OUString aAttrValue( rAttrValue );
527 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
535 OUString aAttrValue( rAttrValue );
537 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
542 OUString aAttrValue( rAttrValue );
544 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
549 OUString aAttrValue( rAttrValue );
554 sal_Int16
const nDestUnit =
lcl_getUnit(aAttrValue);
565 nMeasure, util::MeasureUnit::MM_100TH,
567 aAttrValue = aBuffer.makeStringAndClear();
571 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
580 OUString aAttrValue( rAttrValue );
582 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
587 OUString aAttrValue( rAttrValue );
590 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
591 OUString aNewAttrQName(
596 pMutableAttrList->AddAttribute( aNewAttrQName,
606 OUString aAttrValue( rAttrValue );
608 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
616 OUString aAttrValue( rAttrValue );
618 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
626 OUString aAttrValue( rAttrValue );
627 sal_uInt16 nValPrefix =
628 static_cast<sal_uInt16
>(
629 bRename ? (*aIter).second.m_nParam2
630 : (*aIter).second.m_nParam1);
632 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
637 OUString aAttrValue( rAttrValue );
638 sal_uInt16 nValPrefix =
639 static_cast<sal_uInt16
>((*aIter).second.m_nParam1);
645 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
653 OUString aAttrValue( rAttrValue );
654 sal_uInt16 nValPrefix =
655 static_cast<sal_uInt16
>(
656 bRename ? (*aIter).second.m_nParam2
657 : (*aIter).second.m_nParam1);
659 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
664 OUString aAttrValue( rAttrValue );
666 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
671 OUString aAttrValue( rAttrValue );
673 static_cast< bool >((*aIter).second.m_nParam1)))
674 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
679 OUString aAttrValue( rAttrValue );
681 static_cast< bool >((*aIter).second.m_nParam1)))
682 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
687 OUString aAttrValue( rAttrValue );
690 (*aIter).second.m_nParam1,
691 (*aIter).second.m_nParam2,
692 (*aIter).second.m_nParam3 );
693 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
698 OUString aAttrValue( rAttrValue );
700 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
705 OUString aAttrValue( rAttrValue );
707 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
713 OUString aAttrValue( rAttrValue );
718 sal_Int16
const nDestUnit =
lcl_getUnit(aAttrValue);
729 nMeasure, util::MeasureUnit::MM_100TH,
731 aAttrValue = aBuffer.makeStringAndClear();
735 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
740 OUString aAttrValue( rAttrValue );
743 sal_Int16
const nDestUnit =
lcl_getUnit( aAttrValue );
752 else if( nMeasure < 0 )
758 util::MeasureUnit::MM_100TH, nDestUnit);
759 aAttrValue = aBuffer.makeStringAndClear();
762 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
767 OUString aAttrValue( rAttrValue );
770 sal_Int16
const nDestUnit =
lcl_getUnit( aAttrValue );
779 else if( nMeasure < 0 )
785 util::MeasureUnit::MM_100TH, nDestUnit );
786 aAttrValue = aBuffer.makeStringAndClear();
789 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
794 const sal_Int32 nLen = rAttrValue.getLength();
798 for( pos = 0; pos < nLen; pos++ )
801 if( (c >=
'0') && (c <=
'9') )
804 aBuffer.append( static_cast<sal_Int32>(c) );
807 pMutableAttrList->SetValueByIndex(
i, aBuffer.makeStringAndClear() );
816 OUString aFirstContextLocalName;
819 &aFirstContextLocalName );
820 bool bIsDocumentStyle(
827 if ( !bIsDocumentStyle )
829 OUString aAttrValue( rAttrValue );
831 pMutableAttrList->SetValueByIndex(
i, aAttrValue );
838 OUString sNewValue =
"shape" + rAttrValue;
839 pMutableAttrList->SetValueByIndex(
i, sNewValue );
844 OSL_ENSURE(
false,
"unknown action" );
850 OUString aNewAttrQName(
852 (*aIter).second.GetQNamePrefixFromParam1(),
854 (*aIter).second.GetQNameTokenFromParam1()) ) );
855 pMutableAttrList->RenameAttributeByIndex(
i,
862 return pMutableAttrList.get();
868 sal_Int32
nPos = rValue.getLength();
869 while( nPos && rValue[nPos-1] <=
' ' )
872 (
'c'==rValue[nPos-2] ||
'C'==rValue[nPos-2]) &&
873 (
'h'==rValue[nPos-1] ||
'H'==rValue[nPos-1]) )
875 rValue =rValue.copy( 0, nPos-2 );
886 while( nPos < rValue.getLength()-3 )
889 if(
'i'==c ||
'I'==c )
892 if( (c >=
'0' && c <=
'9') ||
'.' == c )
895 if(
'n'==c ||
'N'==c )
898 if(
'c'==c ||
'C'==c )
901 if(
'h'==c ||
'H'==c )
903 rValue = rValue.replaceAt( nPos,
923 sal_Int32
nPos = rValue.getLength();
924 while( nPos && rValue[nPos-1] <=
' ' )
927 (
'i'==rValue[nPos-2] ||
928 'I'==rValue[nPos-2]) &&
929 (
'n'==rValue[nPos-1] ||
930 'N'==rValue[nPos-1]) )
933 rValue = rValue.replaceAt( nPos, rValue.getLength() - nPos,
945 while( nPos < rValue.getLength()-1 )
948 if(
'i'==c ||
'I'==c )
951 if( (c >=
'0' && c <=
'9') ||
'.' == c )
954 if(
'n'==c ||
'N'==c )
956 rValue = rValue.replaceAt( nPos,
972 static const char aHexTab[] =
"0123456789abcdef";
974 bool bEncoded =
false;
976 sal_Int32 nLen = rName.getLength();
977 OUStringBuffer
aBuffer( nLen );
979 for( sal_Int32
i = 0;
i < nLen;
i++ )
982 bool bValidChar =
false;
986 (c >= 0x0041 && c <= 0x005a) ||
987 (c >= 0x0061 && c <= 0x007a) ||
988 (c >= 0x00c0 && c <= 0x00d6) ||
989 (c >= 0x00d8 && c <= 0x00f6) ||
990 (c >= 0x00f8 && c <= 0x00ff) ||
991 (
i > 0 && ( (c >= 0x0030 && c <= 0x0039) ||
992 c == 0x00b7 || c ==
'-' || c ==
'.') );
996 if( (c >= 0xf900U && c <= 0xfffeU) ||
997 (c >= 0x20dd
U && c <= 0x20e0
U))
1001 else if( (c >= 0x02bbU && c <= 0x02c1U) || c == 0x0559 ||
1002 c == 0x06e5 || c == 0x06e6 )
1006 else if( c == 0x0387 )
1021 case UnicodeType::UPPERCASE_LETTER:
1022 case UnicodeType::LOWERCASE_LETTER:
1023 case UnicodeType::TITLECASE_LETTER:
1024 case UnicodeType::OTHER_LETTER:
1025 case UnicodeType::LETTER_NUMBER:
1028 case UnicodeType::NON_SPACING_MARK:
1029 case UnicodeType::ENCLOSING_MARK:
1030 case UnicodeType::COMBINING_SPACING_MARK:
1031 case UnicodeType::MODIFIER_LETTER:
1032 case UnicodeType::DECIMAL_DIGIT_NUMBER:
1040 aBuffer.append( c );
1044 aBuffer.append(
'_' );
1046 aBuffer.append( static_cast< sal_Unicode >(
1047 aHexTab[ (c >> 12) & 0x0f ] ) );
1049 aBuffer.append( static_cast< sal_Unicode >(
1050 aHexTab[ (c >> 8) & 0x0f ] ) );
1052 aBuffer.append( static_cast< sal_Unicode >(
1053 aHexTab[ (c >> 4) & 0x0f ] ) );
1054 aBuffer.append( static_cast< sal_Unicode >(
1055 aHexTab[ c & 0x0f ] ) );
1056 aBuffer.append(
'_' );
1061 if( aBuffer.getLength() > (1<<15)-1 )
1065 rName = aBuffer.makeStringAndClear();
1071 bool bEncoded =
false;
1073 sal_Int32 nLen = rName.getLength();
1074 OUStringBuffer
aBuffer( nLen );
1076 bool bWithinHex =
false;
1078 for( sal_Int32
i = 0;
i < nLen;
i++ )
1085 aBuffer.append( cEnc );
1092 bWithinHex = !bWithinHex;
1094 else if( bWithinHex )
1097 if( c >=
'0' && c <=
'9' )
1101 else if( c >=
'a' && c <=
'f' )
1103 cDigit = c -
'a' + 10;
1105 else if( c >=
'A' && c <=
'F' )
1107 cDigit = c -
'A' + 10;
1115 cEnc = (cEnc << 4) + cDigit;
1119 aBuffer.append( c );
1124 rName = aBuffer.makeStringAndClear();
1135 sal_Int32 nLen = rValue.getLength();
1138 while( nPos < nLen &&
' ' == rValue[nPos] )
1141 if( nPos < nLen &&
'-' == rValue[nPos] )
1148 while( nPos < nLen &&
1149 '0' <= rValue[nPos] &&
1150 '9' >= rValue[nPos] )
1154 nVal += (rValue[nPos] -
'0');
1157 if( nPos < nLen &&
'.' == rValue[nPos] )
1162 while( nPos < nLen &&
1163 '0' <= rValue[nPos] &&
1164 '9' >= rValue[nPos] )
1168 nVal += (
static_cast<double>(rValue[nPos] -
'0') / nDiv );
1174 while( nPos < nLen &&
' ' == rValue[nPos] )
1177 if( nPos < nLen &&
'%' == rValue[nPos] )
1183 sal_Int32 nIntVal = 100 -
static_cast<sal_Int32
>( nVal );
1185 rValue = OUString::number(nIntVal) +
"%";
1194 sal_uInt16 nPrefix )
const
1200 sal_uInt16 nPrefixOnly )
const
1202 OUString aLocalName;
1203 sal_uInt16 nPrefix =
1206 (
USHRT_MAX == nPrefixOnly || nPrefix == nPrefixOnly);
1214 bool bSupportPackage )
const
1225 if( bSupportPackage )
1227 rURI = rURI.copy( 1 );
1237 if( rURI.getLength() > 1 &&
'/' == rURI[1] )
1239 rURI = rURI.copy( 2 );
1248 sal_Int32 nLen = rURI.getLength();
1249 while( nPos < nLen )
1251 switch( rURI[nPos] )
1282 bool bSupportPackage )
const
1285 if( !rURI.isEmpty() )
1287 bool bPackage =
false;
1311 sal_Int32 nLen = rURI.getLength();
1312 while( nPos < nLen )
1314 switch( rURI[nPos] )
1334 if( bPackage && bSupportPackage )
1336 OUString sTmp(
'#' );
1337 if( rURI.startsWith(
"./" ) )
1338 rURI = rURI.copy( 2 );
1349 OUString& rOutAttributeValue,
1354 return ( lcl_ConvertAttr( rOutAttributeValue, nParam1) ||
1355 lcl_ConvertAttr( rOutAttributeValue, nParam2) ||
1356 lcl_ConvertAttr( rOutAttributeValue, nParam3) );
1362 if( !rDateTime.isEmpty() &&
1363 rDateTime.indexOf(
'.' ) != -1 )
1365 rDateTime = rDateTime.replace(
'.',
',');
1374 XMLTransformerTokenMap::const_iterator aIter =
1379 return (*aIter).second;
1385 OSL_ENSURE( !
m_vContexts.empty(),
"empty stack" );
1392 sal_uInt32 n )
const
1396 OSL_ENSURE( nSize > n + 2 ,
"invalid context" );
1398 return nSize > n + 2 ?
m_vContexts[nSize - (n + 2)].
get() :
nullptr;
1403 Reference< XServiceInfo > xSI(
mxModel, UNO_QUERY );
1405 ( xSI->supportsService(
"com.sun.star.text.TextDocument") ||
1406 xSI->supportsService(
"com.sun.star.text.WebDocument") ||
1407 xSI->supportsService(
"com.sun.star.text.GlobalDocument") );
constexpr sal_uInt16 XML_NAMESPACE_MATH
constexpr sal_uInt16 XML_NAMESPACE_OOOC
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_OOO
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
constexpr sal_uInt16 XML_NAMESPACE_DOM
sal_uInt16 GetKeyByAttrName(const OUString &rAttrName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace) const
constexpr auto convertTwipToMm100(N n)
const sal_uInt16 XML_NAMESPACE_UNKNOWN
css::uno::Any const & rValue
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
bool isAssignableFrom(const Type &_rAssignable, const Type &_rFrom)
sal_uInt16 GetKeyByAttrValueQName(const OUString &rAttrName, OUString *pLocalName) const
XMLTokenEnum
The enumeration of all XML tokens.
bool HasQName(sal_uInt16 nPrefix,::xmloff::token::XMLTokenEnum eToken) 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)
constexpr auto convertMm100ToTwip(N n)
OUString GetQNameByKey(sal_uInt16 nKey, const OUString &rLocalName, bool bCache=true) const
constexpr sal_uInt16 XML_NAMESPACE_DC
enumrange< T >::Iterator end(enumrange< T >)
const OUString & GetNameByKey(sal_uInt16 nKey) const
static bool NormalizeOasisURN(OUString &rName)
std::unique_ptr< char[]> aBuffer
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Handling of tokens in XML:
Reference< XComponentContext > getProcessComponentContext()
virtual bool IsPersistent() const
const OUString & GetQName() const
constexpr sal_uInt16 XML_NAMESPACE_OOOW