27#include <com/sun/star/uno/Reference.hxx>
28#include <com/sun/star/uno/Sequence.hxx>
29#include <com/sun/star/xml/dom/DocumentBuilder.hpp>
30#include <com/sun/star/xml/dom/XNode.hpp>
31#include <com/sun/star/xml/dom/XElement.hpp>
32#include <com/sun/star/xml/sax/XAttributeList.hpp>
33#include <com/sun/star/xml/dom/NodeType.hpp>
35#include <rtl/ustring.hxx>
41using com::sun::star::uno::XComponentContext;
44using com::sun::star::uno::UNO_QUERY;
45using com::sun::star::uno::UNO_QUERY_THROW;
46using com::sun::star::xml::dom::DocumentBuilder;
47using com::sun::star::xml::dom::XDocument;
48using com::sun::star::xml::dom::XDocumentBuilder;
49using com::sun::star::xml::dom::XNode;
50using com::sun::star::xml::dom::XElement;
51using com::sun::star::xml::dom::NodeType_ELEMENT_NODE;
60 const OUString & rNamespace,
const OUString & rName,
64 sal_Int32 nElement ) :
71 SAL_WARN_IF(
mxNode->getNodeType() != NodeType_ELEMENT_NODE,
"xmloff",
"need element" );
75 const OUString & rNamespace,
const OUString & rName ) :
82 SAL_WARN_IF(
mxNode->getNodeType() != NodeType_ELEMENT_NODE,
"xmloff",
"need element" );
93 SAL_WARN_IF(
mxNode->getNodeType() != NodeType_ELEMENT_NODE,
"xmloff",
"need element" );
97 const OUString & rNamespace,
const OUString & rName,
104 SAL_WARN_IF(
mxNode->getNodeType() != NodeType_ELEMENT_NODE,
"xmloff",
"need element" );
114 return mxNode->getOwnerDocument();
118 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
125 const OUString & rNamespace,
const OUString &rName,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
133 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
136 SAL_WARN_IF( !
mxNode->getOwnerDocument().is(),
"xmloff",
"XNode must have XDocument" );
142 const OUString & ,
const OUString & ,
143 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
146 SAL_WARN_IF( !
mxNode->getOwnerDocument().is(),
"xmloff",
"XNode must have XDocument" );
151 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
156 sal_Int32 nAttrToken = aIter.getToken();
159 const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken(nAttrToken, &
GetImport().GetNamespaceMap());
160 const OUString& rLocalName = SvXMLImport::getNameFromToken( nAttrToken );
161 OUString aValue = aIter.toString();
169 xElement->setAttribute( rLocalName, aValue );
185 OUString namespaceURI = SvXMLImport::getNamespaceURIFromToken(aIter.getToken());
186 OUString qualifiedName = rPrefix.isEmpty() ? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName;
187 xElement->setAttributeNS( namespaceURI, qualifiedName, aValue );
192 const css::uno::Sequence< css::xml::Attribute > unknownAttribs = xAttrList->getUnknownAttributes();
193 for (
const auto& rUnknownAttrib : unknownAttribs )
198 if (!rUnknownAttrib.NamespaceURL.isEmpty())
207 xElement->setAttribute( rUnknownAttrib.Name, rUnknownAttrib.Value );
222 mxNode->getOwnerDocument()->createTextNode( rCharacters ),
224 mxNode->appendChild( xNew );
234 SAL_WARN_IF( !xContext.is(),
"xmloff",
"can't get service factory" );
245 SAL_WARN_IF( !xParent.is(),
"xmloff",
"need parent node" );
248 SAL_WARN_IF( !xDocument.is(),
"xmloff",
"no XDocument found!" );
256 const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken(nElement, &rImport.GetNamespaceMap());
257 const OUString& rLocalName = SvXMLImport::getNameFromToken( nElement );
262 xElement = xDocument->createElement( rLocalName );
267 xElement = xDocument->createElement( rLocalName );
279 OUString namespaceURI = SvXMLImport::getNamespaceURIFromToken(nElement);
280 OUString qualifiedName = rPrefix.isEmpty() ? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName;
281 xElement = xDocument->createElementNS(namespaceURI, qualifiedName);
284 SAL_WARN_IF( !xElement.is(),
"xmloff",
"can't create element" );
287 xParent->appendChild( xElement );
292 const OUString & rNamespace,
const OUString & rName,
295 SAL_WARN_IF( !xParent.is(),
"xmloff",
"need parent node" );
298 SAL_WARN_IF( !xDocument.is(),
"xmloff",
"no XDocument found!" );
305 if (rNamespace.isEmpty())
308 xElement = xDocument->createElement( rName );
312 xElement = xDocument->createElementNS(rNamespace, rName);
316 xParent->appendChild( xElement );
static Reference< XNode > lcl_createDomInstance()
static Reference< XNode > lcl_createElement(SvXMLImport &rImport, sal_Int32 nElement, const Reference< XNode > &xParent)
void HandleAttributes(const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs)
virtual void SAL_CALL startUnknownElement(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual void SAL_CALL characters(const OUString &rChars) override
This method is called for all characters that are contained in the current element.
css::uno::Reference< css::xml::dom::XDocument > getTree()
access the DOM tree
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
css::uno::Reference< css::xml::dom::XNode > mxNode
virtual ~DomBuilderContext() override
DomBuilderContext(SvXMLImport &rImport, sal_Int32 nElement)
default constructor: create new DOM tree
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
This class deliberately does not support XWeak, to improve performance when loading large documents.
SvXMLImport & GetImport()
Sequence< sal_Int8 > aSeq
#define SAL_WARN_IF(condition, area, stream)
Reference< XComponentContext > getProcessComponentContext()
const sal_uInt16 XML_NAMESPACE_NONE
const sal_uInt16 XML_NAMESPACE_UNKNOWN
const sal_uInt16 XML_NAMESPACE_XMLNS
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
OReadStatusBarDocumentHandler::StatusBar_XML_Namespace nNamespace
#define XMLERROR_NAMESPACE_TROUBLE
#define XMLERROR_FLAG_WARNING
constexpr size_t NMSP_SHIFT