Avoid potential negative array index access to cached text.
[LibreOffice.git] / framework / inc / xml / statusbardocumenthandler.hxx
blobba1ef7c364f80d24a675ff20614e7547aa217005
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <statusbarconfiguration.hxx>
24 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
26 #include <rtl/ustring.hxx>
27 #include <cppuhelper/implbase.hxx>
29 #include <unordered_map>
31 namespace framework{
33 // Hash code function for using in all hash maps of follow implementation.
35 // workaround for incremental linking bugs in MSVC2015
36 class SAL_DLLPUBLIC_TEMPLATE OReadStatusBarDocumentHandler_Base : public cppu::WeakImplHelper< css::xml::sax::XDocumentHandler > {};
38 class OReadStatusBarDocumentHandler final : public OReadStatusBarDocumentHandler_Base
40 public:
41 enum StatusBar_XML_Entry
43 SB_ELEMENT_STATUSBAR,
44 SB_ELEMENT_STATUSBARITEM,
45 SB_ATTRIBUTE_URL,
46 SB_ATTRIBUTE_ALIGN,
47 SB_ATTRIBUTE_STYLE,
48 SB_ATTRIBUTE_AUTOSIZE,
49 SB_ATTRIBUTE_OWNERDRAW,
50 SB_ATTRIBUTE_WIDTH,
51 SB_ATTRIBUTE_OFFSET,
52 SB_ATTRIBUTE_HELPURL,
53 SB_ATTRIBUTE_MANDATORY,
54 SB_XML_ENTRY_COUNT
57 enum StatusBar_XML_Namespace
59 SB_NS_STATUSBAR,
60 SB_NS_XLINK
63 OReadStatusBarDocumentHandler( const css::uno::Reference< css::container::XIndexContainer >& aStatusBarItems );
64 virtual ~OReadStatusBarDocumentHandler() override;
66 // XDocumentHandler
67 virtual void SAL_CALL startDocument() override;
69 virtual void SAL_CALL endDocument() override;
71 virtual void SAL_CALL startElement(
72 const OUString& aName,
73 const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override;
75 virtual void SAL_CALL endElement(const OUString& aName) override;
77 virtual void SAL_CALL characters(const OUString& aChars) override;
79 virtual void SAL_CALL ignorableWhitespace(const OUString& aWhitespaces) override;
81 virtual void SAL_CALL processingInstruction(const OUString& aTarget,
82 const OUString& aData) override;
84 virtual void SAL_CALL setDocumentLocator(
85 const css::uno::Reference< css::xml::sax::XLocator > &xLocator) override;
87 private:
88 OUString getErrorLineString();
90 class StatusBarHashMap : public std::unordered_map<OUString,
91 StatusBar_XML_Entry >
95 bool m_bStatusBarStartFound;
96 bool m_bStatusBarItemStartFound;
97 StatusBarHashMap m_aStatusBarMap;
98 css::uno::Reference< css::container::XIndexContainer > m_aStatusBarItems;
99 css::uno::Reference< css::xml::sax::XLocator > m_xLocator;
102 class OWriteStatusBarDocumentHandler final
104 public:
105 OWriteStatusBarDocumentHandler(
106 const css::uno::Reference< css::container::XIndexAccess >& rStatusBarItems,
107 const css::uno::Reference< css::xml::sax::XDocumentHandler >& rWriteDocHandler );
108 ~OWriteStatusBarDocumentHandler();
110 /// @throws css::xml::sax::SAXException
111 /// @throws css::uno::RuntimeException
112 void WriteStatusBarDocument();
114 private:
115 /// @throws css::xml::sax::SAXException
116 /// @throws css::uno::RuntimeException
117 void WriteStatusBarItem(
118 const OUString& rCommandURL,
119 sal_Int16 nOffset,
120 sal_Int16 nStyle,
121 sal_Int16 nWidth );
123 css::uno::Reference< css::container::XIndexAccess > m_aStatusBarItems;
124 css::uno::Reference< css::xml::sax::XDocumentHandler > m_xWriteDocumentHandler;
125 css::uno::Reference< css::xml::sax::XAttributeList > m_xEmptyList;
126 OUString m_aXMLStatusBarNS;
127 OUString m_aXMLXlinkNS;
128 OUString m_aAttributeURL;
131 } // namespace framework
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */