23 #include <rtl/ustring.hxx>
25 #include <osl/diagnose.h>
33 #include <com/sun/star/frame/XModel.hpp>
34 #include <com/sun/star/xml/sax/XAttributeList.hpp>
35 #include <com/sun/star/text/ControlCharacter.hpp>
36 #include <com/sun/star/text/XTextContent.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <com/sun/star/container/XNamed.hpp>
40 #include <com/sun/star/rdf/XMetadatable.hpp>
42 #include <com/sun/star/text/XFormField.hpp>
73 switch (aIter.getToken())
76 sName = aIter.toString();
79 sValue = aIter.toString();
94 uno::Reference<uno::XInterface> & io_rxCrossRefHeadingBookmark )
97 , m_rxCrossRefHeadingBookmark(io_rxCrossRefHeadingBookmark)
104 enum lcl_MarkType { TypeReference, TypeReferenceStart, TypeReferenceEnd,
106 TypeFieldmark, TypeFieldmarkStart, TypeFieldmarkEnd
129 name ==
u"msoffice.field.FORMCHECKBOX" ||
130 name ==
u"ecma.office-open-xml.field.FORMCHECKBOX")
133 name ==
u"ecma.office-open-xml.field.FORMDROPDOWN")
141 if (name ==
"msoffice.field.FORMTEXT" ||
142 name ==
"ecma.office-open-xml.field.FORMTEXT")
150 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
178 assert(rHelper.hasCurrentFieldCtx());
181 OUString
const type(rHelper.getCurrentFieldType());
186 SAL_INFO(
"xmloff.text",
"invalid fieldmark-start/fieldmark-end ignored");
191 rImport,
"com.sun.star.text.Fieldmark",
192 rName, rHelper.GetCursorAsRange());
198 Reference<text::XFormField>
const xFormField(xContent, UNO_QUERY);
200 xFormField->setFieldType(fieldmarkTypeName);
201 rHelper.setCurrentFieldParamsTo(xFormField);
203 rHelper.GetCursor()->gotoRange(xContent->getAnchor()->getEnd(),
false);
204 rHelper.GetCursor()->goLeft(1,
false);
208 rHelper.GetText()->insertControlCharacter(rHelper.GetCursor(),
209 text::ControlCharacter::PARAGRAPH_BREAK,
false);
210 rHelper.GetCursor()->goLeft(1,
false);
216 uno::Reference<text::XTextContent>
const xField(rHelper.popFieldCtx(),
221 if (rHelper.GetText() == xField->getAnchor()->getText())
225 rHelper.GetCursor()->goRight(1,
true);
226 rHelper.GetCursor()->setString(OUString());
227 rHelper.GetCursor()->gotoRange(xField->getAnchor()->getEnd(),
false);
229 catch (uno::Exception
const&)
236 SAL_INFO(
"xmloff.text",
"fieldmark has invalid positions");
244 static constexpr OUStringLiteral sAPI_bookmark =
u"com.sun.star.text.Bookmark";
258 "com.sun.star.text.ReferenceMark",
270 uno::Reference<container::XNamed>
const xNamed(
282 bool bImportAsField = (nTmp==TypeFieldmark && formFieldmarkName!=
nullptr);
284 const Reference<XInterface>
xContent(
286 (bImportAsField ? OUString(
"com.sun.star.text.FormFieldmark") : OUString(sAPI_bookmark)),
290 if (nTmp==TypeFieldmark) {
291 if (xContent.is() && bImportAsField) {
293 Reference< css::text::XFormField> xFormField(xContent, UNO_QUERY);
294 xFormField->setFieldType(OUString(formFieldmarkName));
310 case TypeBookmarkStart:
313 std::shared_ptr< ::xmloff::ParsedRDFaAttributes >
329 case TypeBookmarkEnd:
336 uno::Reference<container::XNamed>
const xNamed(
345 Reference<XTextRange> xStartRange;
346 std::shared_ptr< ::xmloff::ParsedRDFaAttributes >
352 Reference<XTextRange> xEndRange(
356 if (xStartRange.is() && xEndRange.is() && xStartRange->getText() == xEndRange->getText())
359 Reference<XTextCursor> xInsertionCursor =
363 xInsertionCursor->gotoRange(xStartRange,
true);
364 }
catch (uno::Exception&) {
366 "cannot go to end position of bookmark");
384 const Reference<rdf::XMetadatable>
385 xMeta(xContent, UNO_QUERY);
387 xMeta, xRDFaAttributes);
390 if (xPropertySet.is())
406 case TypeFieldmarkStart:
411 case TypeFieldmarkEnd:
416 case TypeReferenceStart:
417 case TypeReferenceEnd:
418 OSL_FAIL(
"reference start/end are handled in txtparai !");
422 OSL_FAIL(
"unknown mark type");
429 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
437 const OUString& sServiceName,
438 const OUString& sMarkName,
439 const Reference<XTextRange> & rRange,
440 const OUString& i_rXmlId)
445 Reference<XInterface> xIfc;
449 xIfc =
xFactory->createInstance(sServiceName);
453 OSL_FAIL(
"CreateAndInsertMark: cannot create service?");
458 const Reference<XNamed> xNamed(xIfc, UNO_QUERY);
461 xNamed->setName(sMarkName);
465 if (!sMarkName.isEmpty())
467 OSL_FAIL(
"name given, but XNamed not supported?");
473 const Reference<XTextContent> xTextContent(xIfc, UNO_QUERY);
474 if (xTextContent.is())
480 rImport.
GetTextImport()->GetText()->insertTextContent(rRange,
488 catch (css::lang::IllegalArgumentException &)
490 OSL_FAIL(
"CreateAndInsertMark: cannot insert?");
499 const Reference<XFastAttributeList> & xAttrList)
501 bool bNameOK =
false;
506 OUString sValue = aIter.toString();
507 switch(aIter.getToken())
SAL_DLLPRIVATE::xmloff::RDFaImportHelper & GetRDFaImportHelper()
do not dllexport this; only for advanced cases (bookmark-start)
void AddCrossRefHeadingMapping(OUString const &rFrom, OUString const &rTo)
SvXMLImport & GetImport()
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
SvXMLEnumMapEntry< lcl_MarkType > const lcl_aMarkTypeMap[]
static auto InsertFieldmark(SvXMLImport &rImport, XMLTextImportHelper &rHelper, OUString const &rName) -> void
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
static css::uno::Reference< css::text::XTextContent > CreateAndInsertMark(SvXMLImport &rImport, const OUString &sServiceName, const OUString &sMarkName, const css::uno::Reference< css::text::XTextRange > &rRange, const OUString &i_rXmlId=OUString())
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
const OUString & getBookmarkCondition(OUString const &bookmark) const
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
void addFieldParam(const OUString &name, const OUString &value)
css::uno::Reference< css::text::XText > & GetText()
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
css::uno::Reference< css::text::XTextRange > & GetCursorAsRange()
static OUString lcl_getFieldmarkName(OUString const &name)
bool FindAndRemoveBookmarkStartRange(const OUString &sName, css::uno::Reference< css::text::XTextRange > &o_rRange, OUString &o_rXmlId, std::shared_ptr< ::xmloff::ParsedRDFaAttributes > &o_rpRDFaAttributes)
process the start of a range reference
static auto PopFieldmark(XMLTextImportHelper &rHelper) -> void
XMLTextImportHelper & m_rHelper
bool getBookmarkHidden(OUString const &bookmark) const
bool hasCurrentFieldCtx() const
bool FindName(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
static const sal_Unicode * lcl_getFormFieldmarkName(std::u16string_view name)
void SetXmlId(css::uno::Reference< css::uno::XInterface > const &i_xIfc, OUString const &i_rXmlId)
set the XmlId attribute of given UNO object (for RDF metadata)
static const OUString & getNameFromToken(sal_Int32 nToken)
This class deliberately does not support XWeak, to improve performance when loading large documents...
void InsertBookmarkStartRange(const OUString &sName, const css::uno::Reference< css::text::XTextRange > &rRange, OUString const &i_rXmlId, std::shared_ptr< ::xmloff::ParsedRDFaAttributes > &i_rpRDFaAttributes)
save the start of a range reference
Map an XMLTokenEnum to an enum value.
css::uno::Reference< css::text::XFormField > popFieldCtx()
Handling of tokens in XML:
#define SAL_INFO(area, stream)
void pushFieldCtx(const OUString &name, const OUString &type)
#define XML_ELEMENT(prefix, name)
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...
const css::uno::Reference< css::frame::XModel > & GetModel() const
XMLTextImportHelper & rHelper
css::uno::Reference< css::uno::XInterface > & m_rxCrossRefHeadingBookmark
uno::Reference< ucb::XContent > xContent
Reference< XSingleServiceFactory > xFactory
constexpr sal_Int32 TOKEN_MASK
XMLFieldParamImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp)
void setBookmarkAttributes(OUString const &bookmark, bool hidden, OUString const &condition)
void setCurrentFieldParamsTo(css::uno::Reference< css::text::XFormField > const &xFormField)
XMLTextMarkImportContext(SvXMLImport &rImport, XMLTextImportHelper &rHlp, css::uno::Reference< css::uno::XInterface > &io_rxCrossRefHeadingBookmark)