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::sax::XAttributeList;
52using com::sun::star::xml::dom::NodeType_ELEMENT_NODE;
61 const OUString & rNamespace,
const OUString & rName,
65 sal_Int32 nElement ) :
72 SAL_WARN_IF(
mxNode->getNodeType() != NodeType_ELEMENT_NODE,
"xmloff",
"need element" );
76 const OUString & rNamespace,
const OUString & rName ) :
83 SAL_WARN_IF(
mxNode->getNodeType() != NodeType_ELEMENT_NODE,
"xmloff",
"need element" );
94 SAL_WARN_IF(
mxNode->getNodeType() != NodeType_ELEMENT_NODE,
"xmloff",
"need element" );
98 const OUString & rNamespace,
const OUString & rName,
105 SAL_WARN_IF(
mxNode->getNodeType() != NodeType_ELEMENT_NODE,
"xmloff",
"need element" );
115 return mxNode->getOwnerDocument();
119 sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
126 const OUString & rNamespace,
const OUString &rName,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
134 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
137 SAL_WARN_IF( !
mxNode->getOwnerDocument().is(),
"xmloff",
"XNode must have XDocument" );
143 const OUString & ,
const OUString & ,
144 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
147 SAL_WARN_IF( !
mxNode->getOwnerDocument().is(),
"xmloff",
"XNode must have XDocument" );
152 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
157 sal_Int32 nAttrToken = aIter.getToken();
162 OUString aValue = aIter.toString();
170 xElement->setAttribute( rLocalName, aValue );
188 xElement->setAttributeNS( namespaceURI, qualifiedName, aValue );
193 const css::uno::Sequence< css::xml::Attribute > unknownAttribs = xAttrList->getUnknownAttributes();
194 for (
const auto& rUnknownAttrib : unknownAttribs )
199 if (!rUnknownAttrib.NamespaceURL.isEmpty())
208 xElement->setAttribute( rUnknownAttrib.Name, rUnknownAttrib.Value );
223 mxNode->getOwnerDocument()->createTextNode( rCharacters ),
225 mxNode->appendChild( xNew );
235 SAL_WARN_IF( !xContext.is(),
"xmloff",
"can't get service factory" );
246 SAL_WARN_IF( !xParent.is(),
"xmloff",
"need parent node" );
249 SAL_WARN_IF( !xDocument.is(),
"xmloff",
"no XDocument found!" );
263 xElement = xDocument->createElement( rLocalName );
268 xElement = xDocument->createElement( rLocalName );
282 xElement = xDocument->createElementNS(namespaceURI, qualifiedName);
285 SAL_WARN_IF( !xElement.is(),
"xmloff",
"can't create element" );
288 xParent->appendChild( xElement );
293 const OUString & rNamespace,
const OUString & rName,
296 SAL_WARN_IF( !xParent.is(),
"xmloff",
"need parent node" );
299 SAL_WARN_IF( !xDocument.is(),
"xmloff",
"no XDocument found!" );
306 if (rNamespace.isEmpty())
309 xElement = xDocument->createElement( rName );
313 xElement = xDocument->createElementNS(rNamespace, rName);
317 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()
static OUString getNamespaceURIFromToken(sal_Int32 nToken)
static OUString getNamespacePrefixFromToken(sal_Int32 nToken, const SvXMLNamespaceMap *pMap)
SvXMLNamespaceMap & GetNamespaceMap()
static const OUString & getNameFromToken(sal_Int32 nToken)
static constexpr OUStringLiteral aNamespaceSeparator
void SetError(sal_Int32 nId, const css::uno::Sequence< OUString > &rMsgParams, const OUString &rExceptionMessage, const css::uno::Reference< css::xml::sax::XLocator > &rLocator)
Record an error condition that occurred during import.
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