android: Update app-specific/MIME type icons
[LibreOffice.git] / include / oox / helper / attributelist.hxx
blob65e7f4ee2cf3afd30df3eac43553cbbfa9c210c6
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 #ifndef INCLUDED_OOX_HELPER_ATTRIBUTELIST_HXX
21 #define INCLUDED_OOX_HELPER_ATTRIBUTELIST_HXX
23 #include <sal/config.h>
25 #include <string_view>
26 #include <vector>
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <com/sun/star/util/DateTime.hpp>
30 #include <oox/helper/helper.hxx>
31 #include <oox/dllapi.h>
32 #include <rtl/ustring.hxx>
33 #include <sal/types.h>
34 #include <oox/drawingml/color.hxx>
36 namespace com::sun::star {
37 namespace xml::sax { class XFastAttributeList; }
40 namespace sax_fastparser {
41 class FastAttributeList;
44 namespace oox {
46 /* Get the color tokens from their string representatives. */
47 sal_Int32 getHighlightColorTokenFromString(std::u16string_view sColorName);
49 /** Static helpers for conversion of strings to attribute values of various
50 different data types.
52 class OOX_DLLPUBLIC AttributeConversion
54 public:
55 /** Returns the XML token identifier from the passed string. */
56 static sal_Int32 decodeToken( std::u16string_view rValue );
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 );
62 /** Returns the 32-bit signed integer value from the passed string (decimal). */
63 static sal_Int32 decodeInteger( std::u16string_view rValue );
65 /** Returns the 32-bit unsigned integer value from the passed string (decimal). */
66 static sal_uInt32 decodeUnsigned( std::u16string_view rValue );
68 /** Returns the 64-bit signed integer value from the passed string (decimal). */
69 static sal_Int64 decodeHyper( std::u16string_view rValue );
71 /** Returns the 32-bit signed integer value from the passed string (hexadecimal). */
72 static sal_Int32 decodeIntegerHex( std::u16string_view rValue );
76 /** Provides access to attribute values of an element.
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.
82 class OOX_DLLPUBLIC AttributeList
84 public:
85 explicit AttributeList(
86 const css::uno::Reference< css::xml::sax::XFastAttributeList >& rxAttribs );
88 /** Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object. */
89 const css::uno::Reference< css::xml::sax::XFastAttributeList >&
90 getFastAttributeList() const { return mxAttribs; }
92 /** Returns true, if the specified attribute is present. */
93 bool hasAttribute( sal_Int32 nAttrToken ) const;
95 // optional return values -------------------------------------------------
97 /** Returns the token identifier of the value of the specified attribute. */
98 std::optional< sal_Int32 > getToken( sal_Int32 nAttrToken ) const;
100 /** Returns the Color object of highlight of the text. */
101 oox::drawingml::Color getHighlightColor(sal_Int32 nAttrToken) const;
103 /** Returns the string value of the specified attribute. */
104 std::optional< OUString > getString( sal_Int32 nAttrToken ) const;
106 /** Returns the string value of the specified attribute, returns an empty string if attribute not present. */
107 OUString getStringDefaulted( sal_Int32 nAttrToken ) const;
109 /** Returns the string value of the specified attribute. All characters in
110 the format '_xHHHH_' (H being a hexadecimal digit), will be decoded. */
111 std::optional< OUString > getXString( sal_Int32 nAttrToken ) const;
113 /** Returns the double value of the specified attribute. */
114 std::optional< double > getDouble( sal_Int32 nAttrToken ) const;
116 /** Returns the 32-bit signed integer value of the specified attribute (decimal). */
117 std::optional< sal_Int32 > getInteger( sal_Int32 nAttrToken ) const;
119 /** Returns the 32-bit unsigned integer value of the specified attribute (decimal). */
120 std::optional< sal_uInt32 > getUnsigned( sal_Int32 nAttrToken ) const;
122 /** Returns the 64-bit signed integer value of the specified attribute (decimal). */
123 std::optional< sal_Int64 > getHyper( sal_Int32 nAttrToken ) const;
125 /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal). */
126 std::optional< sal_Int32 > getIntegerHex( sal_Int32 nAttrToken ) const;
128 /** Returns the boolean value of the specified attribute. */
129 std::optional< bool > getBool( sal_Int32 nAttrToken ) const;
131 /** Returns the date/time value of the specified attribute. */
132 std::optional< css::util::DateTime > getDateTime( sal_Int32 nAttrToken ) const;
134 // defaulted return values ------------------------------------------------
136 /** Returns the token identifier of the value of the specified attribute,
137 or the passed default identifier if the attribute is missing. */
138 sal_Int32 getToken( sal_Int32 nAttrToken, sal_Int32 nDefault ) const;
140 /** Returns the string value of the specified attribute, or the passed
141 default string if the attribute is missing. */
142 OUString getString( sal_Int32 nAttrToken, const OUString& rDefault ) const;
144 /** Returns the decoded string value of the specified attribute, or the
145 passed default string if the attribute is missing. */
146 OUString getXString( sal_Int32 nAttrToken, const OUString& rDefault ) const;
148 std::string_view getView( sal_Int32 nAttrToken ) const;
151 /** Returns the double value of the specified attribute, or the passed
152 default value if the attribute is missing or not convertible to a double. */
153 double getDouble( sal_Int32 nAttrToken, double fDefault ) const;
155 /** Returns the 32-bit signed integer value of the specified attribute, or the
156 passed default value if the attribute is missing or not convertible to integer. */
157 sal_Int32 getInteger( sal_Int32 nAttrToken, sal_Int32 nDefault ) const;
159 /** Returns the 32-bit unsigned integer value of the specified attribute, or the
160 passed default value if the attribute is missing or not convertible to unsigned. */
161 sal_uInt32 getUnsigned( sal_Int32 nAttrToken, sal_uInt32 nDefault ) const;
163 /** Returns the 64-bit signed integer value of the specified attribute, or the
164 passed default value if the attribute is missing or not convertible to integer. */
165 sal_Int64 getHyper( sal_Int32 nAttrToken, sal_Int64 nDefault ) const;
167 /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal),
168 or the passed default value if the attribute is missing or not convertible. */
169 sal_Int32 getIntegerHex( sal_Int32 nAttrToken, sal_Int32 nDefault ) const;
171 sal_uInt32 getUnsignedHex( sal_Int32 nAttrToken, sal_uInt32 nDefault ) const;
173 /** Returns the boolean value of the specified attribute, or the passed
174 default value if the attribute is missing or not convertible to bool. */
175 bool getBool( sal_Int32 nAttrToken, bool bDefault ) const;
177 /** Returns the date/time value of the specified attribute, or the default
178 value if the attribute is missing or not convertible to a date/time value. */
179 css::util::DateTime getDateTime( sal_Int32 nAttrToken, const css::util::DateTime& rDefault ) const;
181 std::vector<sal_Int32> getTokenList(sal_Int32 nAttrToken) const;
183 private:
184 css::uno::Reference< css::xml::sax::XFastAttributeList >
185 mxAttribs;
186 mutable sax_fastparser::FastAttributeList *mpAttribList;
187 sax_fastparser::FastAttributeList *getAttribList() const;
191 } // namespace oox
193 #endif
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */