1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #ifndef INCLUDED_XMLOFF_XMLICTXT_HXX 21 #define INCLUDED_XMLOFF_XMLICTXT_HXX 22 23 #include <sal/config.h> 24 #include <xmloff/dllapi.h> 25 #include <sal/types.h> 26 #include <com/sun/star/xml/sax/XFastContextHandler.hpp> 27 #include <com/sun/star/lang/XTypeProvider.hpp> 28 #include <rtl/ustring.hxx> 29 #include <xmloff/nmspmap.hxx> 30 #include <memory> 31 32 namespace com { namespace sun { namespace star { namespace xml { namespace sax { class XAttributeList; } } } } } 33 34 class SvXMLImport; 35 36 class SvXMLImportContext; 37 38 typedef rtl::Reference<SvXMLImportContext> SvXMLImportContextRef; 39 40 /** 41 This class deliberately does not support XWeak, to improve performance when loading 42 large documents. 43 */ 44 class XMLOFF_DLLPUBLIC SvXMLImportContext : public css::xml::sax::XFastContextHandler, 45 public css::lang::XTypeProvider 46 47 { 48 friend class SvXMLImport; 49 50 oslInterlockedCount m_nRefCount; 51 SvXMLImport& mrImport; 52 sal_uInt16 mnPrefix; 53 OUString maLocalName; 54 std::unique_ptr<SvXMLNamespaceMap> m_pRewindMap; 55 TakeRewindMap()56 SAL_DLLPRIVATE std::unique_ptr<SvXMLNamespaceMap> TakeRewindMap() { return std::move(m_pRewindMap); } PutRewindMap(std::unique_ptr<SvXMLNamespaceMap> p)57 SAL_DLLPRIVATE void PutRewindMap(std::unique_ptr<SvXMLNamespaceMap> p) { m_pRewindMap = std::move(p); } 58 59 protected: 60 GetImport()61 SvXMLImport& GetImport() { return mrImport; } GetImport() const62 const SvXMLImport& GetImport() const { return mrImport; } 63 64 public: 65 GetPrefix() const66 sal_uInt16 GetPrefix() const { return mnPrefix; } GetLocalName() const67 const OUString& GetLocalName() const { return maLocalName; } 68 69 /** A contexts constructor does anything that is required if an element 70 * starts. Namespace processing has been done already. 71 * Note that virtual methods cannot be used inside constructors. Use 72 * StartElement instead if this is required. */ 73 SvXMLImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, 74 const OUString& rLName ); 75 76 SvXMLImportContext( SvXMLImport& rImport ); 77 78 /** A contexts destructor does anything that is required if an element 79 * ends. By default, nothing is done. 80 * Note that virtual methods cannot be used inside destructors. Use 81 * EndElement instead if this is required. */ 82 virtual ~SvXMLImportContext(); 83 84 /** Create a children element context. By default, the import's 85 * CreateContext method is called to create a new default context. */ 86 virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, 87 const OUString& rLocalName, 88 const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ); 89 90 /** StartElement is called after a context has been constructed and 91 * before an elements context is parsed. It may be used for actions that 92 * require virtual methods. The default is to do nothing. */ 93 virtual void StartElement( const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ); 94 95 /** EndElement is called before a context will be destructed, but 96 * after an elements context has been parsed. It may be used for actions 97 * that require virtual methods. The default is to do nothing. */ 98 virtual void EndElement(); 99 100 /** This method is called for all characters that are contained in the 101 * current element. The default is to ignore them. */ 102 virtual void Characters( const OUString& rChars ); 103 104 // css::xml::sax::XFastContextHandler: 105 virtual void SAL_CALL startFastElement (sal_Int32 Element, 106 const css::uno::Reference< css::xml::sax::XFastAttributeList >& Attribs) override; 107 108 virtual void SAL_CALL startUnknownElement(const OUString & Namespace, const OUString & Name, 109 const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; 110 111 virtual void SAL_CALL endFastElement(sal_Int32 Element) override; 112 113 virtual void SAL_CALL endUnknownElement(const OUString & Namespace, const OUString & Name) override; 114 115 virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, 116 const css::uno::Reference<css::xml::sax::XFastAttributeList>& Attribs) override; 117 118 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext( 119 const OUString & Namespace, const OUString & Name, 120 const css::uno::Reference< css::xml::sax::XFastAttributeList > & Attribs) override; 121 122 virtual void SAL_CALL characters(const OUString & aChars) override; 123 124 // XInterface 125 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) final override; acquire()126 virtual void SAL_CALL acquire() throw () final override 127 { osl_atomic_increment(&m_nRefCount); } release()128 virtual void SAL_CALL release() throw () final override 129 { if (osl_atomic_decrement(&m_nRefCount) == 0) delete this; } 130 131 // XTypeProvider 132 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) final override; 133 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) final override; 134 }; 135 136 #endif // INCLUDED_XMLOFF_XMLICTXT_HXX 137 138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 139