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>
41 using com::sun::star::uno::XComponentContext;
44 using com::sun::star::uno::UNO_QUERY;
45 using com::sun::star::uno::UNO_QUERY_THROW;
46 using com::sun::star::xml::dom::DocumentBuilder;
47 using com::sun::star::xml::dom::XDocument;
48 using com::sun::star::xml::dom::XDocumentBuilder;
49 using com::sun::star::xml::dom::XNode;
50 using com::sun::star::xml::dom::XElement;
51 using com::sun::star::xml::sax::XAttributeList;
52 using 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 );
180 aSeq[0] = rLocalName;
191 xElement->setAttributeNS( namespaceURI, qualifiedName, aValue );
196 const css::uno::Sequence< css::xml::Attribute > unknownAttribs = xAttrList->getUnknownAttributes();
197 for (
const auto& rUnknownAttrib : unknownAttribs )
202 if (!rUnknownAttrib.NamespaceURL.isEmpty())
206 aSeq[0] = rUnknownAttrib.Name;
207 aSeq[1] = rUnknownAttrib.Value;
214 xElement->setAttribute( rUnknownAttrib.Name, rUnknownAttrib.Value );
229 mxNode->getOwnerDocument()->createTextNode( rCharacters ),
231 mxNode->appendChild( xNew );
241 SAL_WARN_IF( !xContext.is(),
"xmloff",
"can't get service factory" );
252 SAL_WARN_IF( !xParent.is(),
"xmloff",
"need parent node" );
255 SAL_WARN_IF( !xDocument.is(),
"xmloff",
"no XDocument found!" );
269 xElement = xDocument->createElement( rLocalName );
274 xElement = xDocument->createElement( rLocalName );
288 xElement = xDocument->createElementNS(namespaceURI, qualifiedName);
291 SAL_WARN_IF( !xElement.is(),
"xmloff",
"can't create element" );
294 xParent->appendChild( xElement );
299 const OUString & rNamespace,
const OUString & rName,
302 SAL_WARN_IF( !xParent.is(),
"xmloff",
"need parent node" );
305 SAL_WARN_IF( !xDocument.is(),
"xmloff",
"no XDocument found!" );
312 if (rNamespace.isEmpty())
315 xElement = xDocument->createElement( rName );
319 xElement = xDocument->createElementNS(rNamespace, rName);
323 xParent->appendChild( xElement );
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)
SvXMLImport & GetImport()
SvXMLNamespaceMap & GetNamespaceMap()
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
const sal_uInt16 XML_NAMESPACE_UNKNOWN
const sal_uInt16 XML_NAMESPACE_XMLNS
static OUString getNamespaceURIFromToken(sal_Int32 nToken)
DomBuilderContext(SvXMLImport &rImport, sal_Int32 nElement)
default constructor: create new DOM tree
static constexpr OUStringLiteral aNamespaceSeparator
#define XMLERROR_FLAG_WARNING
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
#define XMLERROR_NAMESPACE_TROUBLE
constexpr size_t NMSP_SHIFT
static OUString getNamespacePrefixFromToken(sal_Int32 nToken, const SvXMLNamespaceMap *pMap)
const sal_uInt16 XML_NAMESPACE_NONE
static const OUString & getNameFromToken(sal_Int32 nToken)
This class deliberately does not support XWeak, to improve performance when loading large documents...
virtual ~DomBuilderContext() override
#define SAL_WARN_IF(condition, area, stream)
OReadImagesDocumentHandler::Image_XML_Namespace nNamespace
Reference< XComponentContext > getProcessComponentContext()
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
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
virtual void SAL_CALL startUnknownElement(const OUString &Namespace, const OUString &Name, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
css::uno::Reference< css::xml::dom::XDocument > getTree()
access the DOM tree
static Reference< XNode > lcl_createDomInstance()
css::uno::Reference< css::xml::dom::XNode > mxNode
virtual void SAL_CALL characters(const OUString &rChars) override
This method is called for all characters that are contained in the current element.