34#include <com/sun/star/frame/XModel.hpp>
35#include <com/sun/star/text/SetVariableType.hpp>
36#include <com/sun/star/text/XDependentTextField.hpp>
37#include <com/sun/star/text/XTextFieldsSupplier.hpp>
38#include <com/sun/star/beans/XPropertySet.hpp>
39#include <com/sun/star/beans/XPropertySetInfo.hpp>
40#include <com/sun/star/lang/XMultiServiceFactory.hpp>
41#include <com/sun/star/xml/sax/XAttributeList.hpp>
42#include <com/sun/star/style/NumberingType.hpp>
43#include <com/sun/star/container/XIndexReplace.hpp>
47#include <rtl/ustring.hxx>
48#include <osl/diagnose.h>
60constexpr OUStringLiteral
sAPI_database =
u"com.sun.star.text.TextField.Database";
83 const OUString& pServiceName,
84 bool bFormula,
bool bFormulaDefault,
85 bool bDescription,
bool bHelp,
bool bHint,
bool bVisible,
86 bool bIsDisplayFormula,
87 bool bType,
bool bStyle,
bool bValue,
90 aValueHelper(rImport, rHlp, bType, bStyle, bValue, false),
91 bDisplayFormula(false),
94 bDescriptionOK(false),
98 bSetFormula(bFormula),
99 bSetFormulaDefault(bFormulaDefault),
100 bSetDescription(bDescription),
104 bSetDisplayFormula(bIsDisplayFormula),
105 bSetPresentation(bPresentation)
110 sal_Int32 nAttrToken,
111 std::string_view sAttrValue )
116 sName = OUString::fromUtf8(sAttrValue);
124 sHelp = OUString::fromUtf8(sAttrValue);
128 sHint = OUString::fromUtf8(sAttrValue);
134 sal_uInt16 nPrefix =
GetImport().GetNamespaceMap().
135 GetKeyByAttrValueQName(OUString::fromUtf8(sAttrValue), &sTmp);
142 sFormula = OUString::fromUtf8(sAttrValue);
165 "illegal display values");
175 const Reference<XPropertySet> & xPropertySet)
200 xPropertySet->setPropertyValue(
"Help",
Any(
sHelp));
205 xPropertySet->setPropertyValue(
"Tooltip",
Any(
sHint));
215 if (xPropertySet->getPropertySetInfo()->
216 hasPropertyByName(
"IsShowFormula") &&
227 xPropertySet->setPropertyValue(
"IsShowFormula",
Any(bTmp));
249 const OUString& pServiceName,
VarType eVarType,
250 bool bFormula,
bool bFormulaDefault,
251 bool bDescription,
bool bHelp,
bool bHint,
bool bVisible,
bool bIsDisplayFormula,
252 bool bType,
bool bStyle,
bool bValue,
bool bPresentation) :
254 bFormula, bFormulaDefault,
255 bDescription, bHelp, bHint,
bVisible, bIsDisplayFormula,
256 bType, bStyle, bValue, bPresentation),
276 Reference<XPropertySet> xMaster;
280 Reference<XPropertySet> xPropSet;
283 Reference<XDependentTextField> xDepTextField(xPropSet, UNO_QUERY);
284 if (xDepTextField.is())
287 xDepTextField->attachTextFieldMaster(xMaster);
290 Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY);
291 if (xTextContent.is())
297 }
catch (lang::IllegalArgumentException & )
314 Reference<XPropertySet> & xMaster)
335 false, false, false, false,
337 false, false, false, true),
339 sNumFormat(OUString(
'1')),
346 sal_Int32 nAttrToken, std::string_view sAttrValue )
357 sRefName = OUString::fromUtf8(sAttrValue);
369 const Reference<XPropertySet> & xPropertySet)
375 sal_Int16
nNumType = NumberingType::ARABIC;
382 Any aAny = xPropertySet->getPropertyValue(
"SequenceValue");
408 const Reference<XPropertySet> & xPropertySet)
412 aAny <<= (
IsStringValue()? SetVariableType::STRING : SetVariableType::VAR);
438 const Reference<XPropertySet> & xPropertySet)
442 xPropertySet->setPropertyValue(
"Input",
Any(
true));
445 aAny <<= (
IsStringValue()? SetVariableType::STRING : SetVariableType::VAR);
462 false, false, false, true,
487 const Reference<XPropertySet> & xPropertySet)
512 const Reference<XPropertySet> & xPropertySet)
540 const Reference<XPropertySet> & xPropertySet)
542 xPropertySet->setPropertyValue(
sAPI_sub_type,
Any(sal_Int16(SetVariableType::FORMULA)));
566 const Reference<XPropertySet> & xPropertySet)
578 SvXMLImport& rImport,
581 aValueHelper(rImport, rHlp, false, true, false, true),
582 bIsShowFormula(false)
587 sal_Int32 nAttrToken,
588 std::string_view sAttrValue )
601 if ( sAttrValue ==
"formula" )
612 const Reference<XPropertySet> & xPropertySet)
623 xPropertySet->setPropertyValue(
"CurrentPresentation", aAny );
638 eVarDeclsContextType(eVarType),
645 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
662 OSL_FAIL(
"unknown field type!");
686 const Reference<xml::sax::XFastAttributeList> & xAttrList,
707 switch (aIter.getToken())
710 sName = aIter.toString();
716 nLevel, aIter.toView(), 0,
717 GetImport().GetTextImport()->GetChapterNumbering()->
721 nNumLevel =
static_cast< sal_Int8 >( nLevel-1 );
727 static_cast<char>(aIter.toString().toChar());
737 Reference<XPropertySet> xFieldMaster;
748 xFieldMaster->setPropertyValue(
"ChapterNumberingLevel",
Any(nNumLevel));
752 OUString sStr(&cSeparationChar, 1);
753 xFieldMaster->setPropertyValue(
754 "NumberingSeparator",
Any(sStr));
763 ? SetVariableType::STRING : SetVariableType::VAR;
770 xFieldMaster->setPropertyValue(
"IsExpression",
Any(bTmp));
775 OSL_FAIL(
"unknown varfield type");
781 Reference<XPropertySet> & xMaster, SvXMLImport& rImport,
783 const OUString& sVarName,
enum VarType eVarType)
785 static sal_Int32 nCollisionCount = 0;
790 sal::static_int_cast< sal_uInt16 >(eVarType), sVarName);
793 Reference<XTextFieldsSupplier> xTextFieldsSupp(rImport.GetModel(),
795 Reference<container::XNameAccess> xFieldMasterNameAccess =
796 xTextFieldsSupp->getTextFieldMasters();
798 OUString sVarServiceName =
804 OUString sUserServiceName =
810 if (xFieldMasterNameAccess->hasByName(sVarServiceName)) {
813 Any aAny = xFieldMasterNameAccess->getByName(sVarServiceName);
821 (SetVariableType::SEQUENCE ==
nType) ?
824 if (eFMVarType != eVarType)
827 OUString sNew(
sName +
"_renamed_" + OUString::number(nCollisionCount));
832 sal::static_int_cast< sal_uInt16 >(eVarType),
sName, sNew);
838 }
else if (xFieldMasterNameAccess->hasByName(sUserServiceName)) {
840 Any aAny = xFieldMasterNameAccess->getByName(sUserServiceName);
846 OUString sNew(
sName +
"_renamed_" + OUString::number(nCollisionCount));
851 sal::static_int_cast< sal_uInt16 >(eVarType),
sName, sNew);
861 Reference<lang::XMultiServiceFactory>
862 xFactory(rImport.GetModel(),UNO_QUERY);
868 Reference<XInterface> xIfc =
869 xFactory->createInstance( sService );
871 Reference<XPropertySet> xTmp( xIfc, UNO_QUERY );
875 xMaster->setPropertyValue(
"Name",
Any(
sName));
881 SetVariableType::VAR :
882 SetVariableType::SEQUENCE);
894 DBG_ASSERT(xMaster.is(),
"no field master found!?!");
905 aValueHelper(rImport, rHlp, false, true, false, false),
913 sal_Int32 nAttrToken, std::string_view sAttrValue )
956 Reference<XPropertySet> xMaster;
960 "com.sun.star.text.FieldMaster.Database"))
969 Reference<XPropertySet> xField;
974 Reference<XDependentTextField> xDepField(xField, UNO_QUERY);
978 xDepField->attachTextFieldMaster(xMaster);
981 Reference<XTextContent> xTextContent(xField, UNO_QUERY);
982 if (xTextContent.is())
991 xField->setPropertyValue(
"DataBaseFormat",
Any(bTmp));
1009 catch (
const lang::IllegalArgumentException&)
1031 XML_VALUE_TYPE_STRING,
1032 XML_VALUE_TYPE_FLOAT,
1033 XML_VALUE_TYPE_CURRENCY,
1034 XML_VALUE_TYPE_PERCENTAGE,
1035 XML_VALUE_TYPE_DATE,
1036 XML_VALUE_TYPE_TIME,
1037 XML_VALUE_TYPE_BOOLEAN
1055 SvXMLImport& rImprt,
1057 bool bType,
bool bStyle,
bool bValue,
bool bFormula) :
1064 bIsDefaultLanguage(true),
1068 bStringValueOK(false),
1074 bSetFormula(bFormula)
1079 sal_Int32 nAttrToken, std::string_view sAttrValue )
1087 ValueType eValueType = XML_VALUE_TYPE_STRING;
1094 case XML_VALUE_TYPE_STRING:
1097 case XML_VALUE_TYPE_FLOAT:
1098 case XML_VALUE_TYPE_CURRENCY:
1099 case XML_VALUE_TYPE_PERCENTAGE:
1100 case XML_VALUE_TYPE_DATE:
1101 case XML_VALUE_TYPE_TIME:
1102 case XML_VALUE_TYPE_BOOLEAN:
1107 OSL_FAIL(
"unknown value type");
1140 bool bRet =
rImport.GetMM100UnitConverter().
1141 convertDateTime(fTmp,sAttrValue);
1153 fValue = (bTmp ? 1.0 : 0.0);
1168 sValue = OUString::fromUtf8(sAttrValue);
1175 sal_uInt16 nPrefix =
rImport.GetNamespaceMap().
1176 GetKeyByAttrValueQName(OUString::fromUtf8(sAttrValue), &sTmp);
1183 sFormula = OUString::fromUtf8(sAttrValue);
1204 const Reference<XPropertySet> & xPropertySet)
1224 if( xPropertySet->getPropertySetInfo()->
1225 hasPropertyByName(
"IsFixedLanguage" ) )
1228 xPropertySet->setPropertyValue(
"IsFixedLanguage",
Any(bIsFixedLanguage) );
1242 xPropertySet->setPropertyValue(
"Value",
Any(
fValue));
void Add(sal_uInt16 nKind, const OUString &rName, const OUString &rNewName)
const OUString & Get(sal_uInt16 nKind, const OUString &rName) const
This class deliberately does not support XWeak, to improve performance when loading large documents.
SvXMLImport & GetImport()
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
XMLValueImportHelper aValueHelper
XMLDatabaseDisplayImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp)
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
create, prepare and insert database field master and database field
virtual void ProcessAttribute(sal_Int32 nAttrToken, std::string_view sAttrValue) override
text import helper
superclass for database fields: handle database and table names
virtual void ProcessAttribute(sal_Int32 nAttrToken, std::string_view sAttrValue) override
process attribute values
virtual void PrepareField(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet) override
prepare XTextField for insertion into document
XMLExpressionFieldImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp)
virtual void PrepareField(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet) override
Text import helper.
virtual void ProcessAttribute(sal_Int32 nAttrToken, std::string_view sAttrValue) override
Text import helper.
virtual void PrepareField(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet) override
prepare XTextField for insertion into document
XMLSequenceFieldImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp)
upperclass for variable/user-set, var/user-input, and sequence fields inds field master of appropriat...
bool FindFieldMaster(css::uno::Reference< css::beans::XPropertySet > &xMaster)
find appropriate field master
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
see XMLTextFieldImportContext
XMLSetVarFieldImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp, const OUString &pServiceName, VarType eVarType, bool bFormula, bool bFormulaDefault, bool bDescription, bool bHelp, bool bHint, bool bVisible, bool bDisplayFormula, bool bType, bool bStyle, bool bValue, bool bPresentation)
virtual void ProcessAttribute(sal_Int32 nAttrToken, std::string_view sAttrValue) override
text import helper
virtual void PrepareField(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet) override
prepare XTextField for insertion into document
XMLTableFormulaImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp)
XMLValueImportHelper aValueHelper
abstract class for text field import
XMLTextImportHelper & GetImportHelper()
get helper
const OUString & GetServiceName() const
OUString const & GetContent()
bool CreateField(css::uno::Reference< css::beans::XPropertySet > &xField, const OUString &sServiceName)
create field from ServiceName
void InsertTextContent(css::uno::Reference< css::text::XTextContent > const &xContent)
SvI18NMap & GetRenameMap()
sal_Int32 GetDataStyleKey(const OUString &sStyleName, bool *pIsSystemLanguage=nullptr)
return key appropriate for use with NumberFormat property return -1 if style is not found (may return...
void InsertString(const OUString &rChars)
void InsertSequenceID(const OUString &sXMLId, const OUString &sName, sal_Int16 nAPIId)
insert new sequence ID Also fixup open references from backpatch list to this ID.
virtual void PrepareField(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet) override
Text import helper.
XMLTextInputFieldImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp)
XMLUserFieldImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp)
virtual void PrepareField(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet) override
Text import helper.
XMLUserFieldInputImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp)
void PrepareField(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet)
prepare XTextField for insertion into document
const bool bSetType
have we read the formula attribute?
bool bFormatOK
is this a string (or a float) type?
bool bFormulaOK
have we read a string-value attr.?
bool IsFormatOK() const
has format been read?
bool bIsDefaultLanguage
default (see bStringDefault/bFormulaDef.)
OUString sFormula
format key (only valid of bFormatOK)
bool bStringType
format (of nFormatKey) has system language?
OUString sDefault
formula string
XMLValueImportHelper(SvXMLImport &rImprt, XMLTextImportHelper &rHlp, bool bType, bool bStyle, bool bValue, bool bFormula)
should PrepareField set Formula?
const bool bSetStyle
should PrepareField set content/value?
sal_Int32 nFormatKey
double value (only valid if bFloatValueOK)
XMLTextImportHelper & rHelper
const bool bSetFormula
should PrepareField set NumberFormat?
void ProcessAttribute(sal_Int32 nAttrToken, std::string_view sAttrValue)
process formula (Prep.F.)
bool IsStringValue() const
is value a string (rather than double)?
double fValue
string value (only valid if bStringValueOK)
bool bStringValueOK
have we read a style:data-style-name attr.?
void SetDefault(const OUString &sStr)
const bool bSetValue
should PrepareField set the SetExp subtype?
abstract parent class for all variable related fields
XMLVarFieldImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp, const OUString &pServiceName, bool bFormula, bool bFormulaDefault, bool bDescription, bool bHelp, bool bHint, bool bVisible, bool bDisplayFormula, bool bType, bool bStyle, bool bValue, bool bPresentation)
set presentation frm elem. content?
const OUString & GetName() const
OUString sFormula
name attribute
bool bDisplayOK
sHint was set
OUString sHelp
description
bool bSetDisplayFormula
set IsVisible
bool bSetDescription
use content as default for formula
bool bDisplayFormula
value, value-type, and style
virtual void ProcessAttribute(sal_Int32 nAttrToken, std::string_view sAttrValue) override
set presentation from elem. content
bool bSetHelp
set sDescription with Hint-property
XMLValueImportHelper aValueHelper
hint
OUString sDescription
formula attribute
bool bHintOK
sHelp was set
bool bDescriptionOK
sFormula was set
bool bSetPresentation
set DisplayFormula (sub type???)
bool bFormulaOK
hide field?
bool bDisplayNone
display formula?(rather than value)
bool bSetFormulaDefault
set Formula property
bool bSetFormula
sDisplayFormula/-None were set
bool IsStringValue() const
bool bHelpOK
sDescription was set
virtual void PrepareField(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet) override
prepare XTextField for insertion into document
variable field declarations (variable-decl, user-field-decl, sequence-decl)
static bool FindFieldMaster(css::uno::Reference< css::beans::XPropertySet > &xMaster, SvXMLImport &rImport, XMLTextImportHelper &rHelper, const OUString &sVarName, enum VarType eVarType)
variable type
XMLVariableDeclImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList, enum VarType eVarType)
enum VarType eVarDeclsContextType
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
variable type
XMLVariableDeclsImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp, enum VarType eVarType)
XMLTextImportHelper & rImportHelper
virtual void PrepareField(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet) override
Text import helper.
XMLVariableGetFieldImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp)
virtual void PrepareField(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet) override
Text import helper.
XMLVariableInputFieldImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp)
virtual void PrepareField(const css::uno::Reference< css::beans::XPropertySet > &xPropertySet) override
Text import helper.
XMLVariableSetFieldImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp)
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
static bool convertBool(bool &rBool, std::u16string_view rString)
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XSingleServiceFactory > xFactory
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
@ XML_SEPARATION_CHARACTER
@ XML_DISPLAY_OUTLINE_LEVEL
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
VarType
variable type (for XMLSetVarFieldImportContext)
SvXMLEnumMapEntry< ValueType > const aValueTypeMap[]
constexpr char16_t sAPI_fieldmaster_prefix[]
#file
constexpr OUStringLiteral sAPI_database
constexpr OUStringLiteral sAPI_current_presentation
constexpr OUStringLiteral sAPI_sub_type
constexpr OUStringLiteral sAPI_user
constexpr OUStringLiteral sAPI_number_format
constexpr OUStringLiteral sAPI_get_expression
constexpr OUStringLiteral sAPI_set_expression
constexpr OUStringLiteral sAPI_content
constexpr OUStringLiteral sAPI_is_visible
#define XMLOFF_WARN_UNKNOWN_ATTR(area, token, value)
#define XML_ELEMENT(prefix, name)
constexpr bool IsTokenInNamespace(sal_Int32 nToken, sal_uInt16 nNamespacePrefix)
constexpr sal_uInt16 XML_NAMESPACE_TEXT
constexpr sal_uInt16 XML_NAMESPACE_OOOW