/src/libreoffice/include/oox/helper/attributelist.hxx
Line | Count | Source |
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_OOX_HELPER_ATTRIBUTELIST_HXX |
21 | | #define INCLUDED_OOX_HELPER_ATTRIBUTELIST_HXX |
22 | | |
23 | | #include <sal/config.h> |
24 | | |
25 | | #include <string_view> |
26 | | #include <vector> |
27 | | |
28 | | #include <com/sun/star/uno/Reference.hxx> |
29 | | #include <com/sun/star/util/DateTime.hpp> |
30 | | #include <oox/dllapi.h> |
31 | | #include <rtl/ustring.hxx> |
32 | | #include <rtl/ref.hxx> |
33 | | #include <sal/types.h> |
34 | | #include <oox/drawingml/color.hxx> |
35 | | |
36 | | namespace com::sun::star { |
37 | | namespace xml::sax { class XFastAttributeList; } |
38 | | } |
39 | | |
40 | | namespace sax_fastparser { |
41 | | class FastAttributeList; |
42 | | }; |
43 | | |
44 | | namespace oox { |
45 | | |
46 | | /* Get the color tokens from their string representatives. */ |
47 | | sal_Int32 getHighlightColorTokenFromString(std::u16string_view sColorName); |
48 | | |
49 | | /** Static helpers for conversion of strings to attribute values of various |
50 | | different data types. |
51 | | */ |
52 | | class OOX_DLLPUBLIC AttributeConversion |
53 | | { |
54 | | public: |
55 | | /** Returns the XML token identifier from the passed string. */ |
56 | | static sal_Int32 decodeToken( std::u16string_view rValue ); |
57 | | |
58 | | /** Returns the decoded string value. All characters in the format |
59 | | '_xHHHH_' (H being a hexadecimal digit), will be decoded. */ |
60 | | static OUString decodeXString( const OUString& rValue ); |
61 | | |
62 | | /** Returns the 32-bit signed integer value from the passed string (decimal). */ |
63 | | static sal_Int32 decodeInteger( std::u16string_view rValue ); |
64 | | |
65 | | /** Returns the 32-bit unsigned integer value from the passed string (decimal). */ |
66 | | static sal_uInt32 decodeUnsigned( std::u16string_view rValue ); |
67 | | |
68 | | /** Returns the 64-bit signed integer value from the passed string (decimal). */ |
69 | | static sal_Int64 decodeHyper( std::u16string_view rValue ); |
70 | | |
71 | | /** Returns the 32-bit signed integer value from the passed string (hexadecimal). */ |
72 | | static sal_Int32 decodeIntegerHex( std::u16string_view rValue ); |
73 | | }; |
74 | | |
75 | | |
76 | | /** Provides access to attribute values of an element. |
77 | | |
78 | | Wraps a com.sun.star.xml.sax.XFastAttributeList object. Provides |
79 | | convenience functions that convert the string value of an attribute to |
80 | | various other data types. |
81 | | */ |
82 | | class OOX_DLLPUBLIC AttributeList |
83 | | { |
84 | | public: |
85 | | explicit AttributeList( |
86 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& rxAttribs ); |
87 | | ~AttributeList(); |
88 | | |
89 | 487k | const rtl::Reference<sax_fastparser::FastAttributeList> & getFastAttributeList() const { return mxAttribs; } |
90 | | |
91 | | /** Returns true, if the specified attribute is present. */ |
92 | | bool hasAttribute( sal_Int32 nAttrToken ) const; |
93 | | |
94 | | // optional return values ------------------------------------------------- |
95 | | |
96 | | /** Returns the token identifier of the value of the specified attribute. */ |
97 | | std::optional< sal_Int32 > getToken( sal_Int32 nAttrToken ) const; |
98 | | |
99 | | /** Returns the Color object of highlight of the text. */ |
100 | | oox::drawingml::Color getHighlightColor(sal_Int32 nAttrToken) const; |
101 | | |
102 | | /** Returns the string value of the specified attribute. */ |
103 | | std::optional< OUString > getString( sal_Int32 nAttrToken ) const; |
104 | | |
105 | | /** Returns the string value of the specified attribute, returns an empty string if attribute not present. */ |
106 | | OUString getStringDefaulted( sal_Int32 nAttrToken ) const; |
107 | | |
108 | | /** Returns the string value of the specified attribute. All characters in |
109 | | the format '_xHHHH_' (H being a hexadecimal digit), will be decoded. */ |
110 | | std::optional< OUString > getXString( sal_Int32 nAttrToken ) const; |
111 | | |
112 | | /** Returns the double value of the specified attribute. */ |
113 | | std::optional< double > getDouble( sal_Int32 nAttrToken ) const; |
114 | | |
115 | | /** Returns the 32-bit signed integer value of the specified attribute (decimal). */ |
116 | | std::optional< sal_Int32 > getInteger( sal_Int32 nAttrToken ) const; |
117 | | |
118 | | /** Returns the 32-bit unsigned integer value of the specified attribute (decimal). */ |
119 | | std::optional< sal_uInt32 > getUnsigned( sal_Int32 nAttrToken ) const; |
120 | | |
121 | | /** Returns the 64-bit signed integer value of the specified attribute (decimal). */ |
122 | | std::optional< sal_Int64 > getHyper( sal_Int32 nAttrToken ) const; |
123 | | |
124 | | /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal). */ |
125 | | std::optional< sal_Int32 > getIntegerHex( sal_Int32 nAttrToken ) const; |
126 | | |
127 | | /** Returns the boolean value of the specified attribute. */ |
128 | | std::optional< bool > getBool( sal_Int32 nAttrToken ) const; |
129 | | |
130 | | /** Returns the date/time value of the specified attribute. */ |
131 | | std::optional< css::util::DateTime > getDateTime( sal_Int32 nAttrToken ) const; |
132 | | |
133 | | // defaulted return values ------------------------------------------------ |
134 | | |
135 | | /** Returns the token identifier of the value of the specified attribute, |
136 | | or the passed default identifier if the attribute is missing. */ |
137 | | sal_Int32 getToken( sal_Int32 nAttrToken, sal_Int32 nDefault ) const; |
138 | | |
139 | | /** Returns the string value of the specified attribute, or the passed |
140 | | default string if the attribute is missing. */ |
141 | | OUString getString( sal_Int32 nAttrToken, const OUString& rDefault ) const; |
142 | | |
143 | | /** Returns the decoded string value of the specified attribute, or the |
144 | | passed default string if the attribute is missing. */ |
145 | | OUString getXString( sal_Int32 nAttrToken, const OUString& rDefault ) const; |
146 | | |
147 | | std::string_view getView( sal_Int32 nAttrToken ) const; |
148 | | |
149 | | |
150 | | /** Returns the double value of the specified attribute, or the passed |
151 | | default value if the attribute is missing or not convertible to a double. */ |
152 | | double getDouble( sal_Int32 nAttrToken, double fDefault ) const; |
153 | | |
154 | | /** Returns the 32-bit signed integer value of the specified attribute, or the |
155 | | passed default value if the attribute is missing or not convertible to integer. */ |
156 | | sal_Int32 getInteger( sal_Int32 nAttrToken, sal_Int32 nDefault ) const; |
157 | | |
158 | | /** Returns the 32-bit unsigned integer value of the specified attribute, or the |
159 | | passed default value if the attribute is missing or not convertible to unsigned. */ |
160 | | sal_uInt32 getUnsigned( sal_Int32 nAttrToken, sal_uInt32 nDefault ) const; |
161 | | |
162 | | /** Returns the 64-bit signed integer value of the specified attribute, or the |
163 | | passed default value if the attribute is missing or not convertible to integer. */ |
164 | | sal_Int64 getHyper( sal_Int32 nAttrToken, sal_Int64 nDefault ) const; |
165 | | |
166 | | /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal), |
167 | | or the passed default value if the attribute is missing or not convertible. */ |
168 | | sal_Int32 getIntegerHex( sal_Int32 nAttrToken, sal_Int32 nDefault ) const; |
169 | | |
170 | | sal_uInt32 getUnsignedHex( sal_Int32 nAttrToken, sal_uInt32 nDefault ) const; |
171 | | |
172 | | /** Returns the boolean value of the specified attribute, or the passed |
173 | | default value if the attribute is missing or not convertible to bool. */ |
174 | | bool getBool( sal_Int32 nAttrToken, bool bDefault ) const; |
175 | | |
176 | | /** Returns the date/time value of the specified attribute, or the default |
177 | | value if the attribute is missing or not convertible to a date/time value. */ |
178 | | css::util::DateTime getDateTime( sal_Int32 nAttrToken, const css::util::DateTime& rDefault ) const; |
179 | | |
180 | | std::vector<sal_Int32> getTokenList(sal_Int32 nAttrToken) const; |
181 | | |
182 | | private: |
183 | | AttributeList(const AttributeList&) = delete; |
184 | | AttributeList(AttributeList&&) = delete; |
185 | | void operator=(const AttributeList&) = delete; |
186 | | void operator=(AttributeList&&) = delete; |
187 | | |
188 | | rtl::Reference<sax_fastparser::FastAttributeList> mxAttribs; |
189 | | }; |
190 | | |
191 | | |
192 | | } // namespace oox |
193 | | |
194 | | #endif |
195 | | |
196 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |