1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 OOX_HELPER_ATTRIBUTELIST_HXX
21 #define OOX_HELPER_ATTRIBUTELIST_HXX
23 #include <com/sun/star/util/DateTime.hpp>
24 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
25 #include "oox/helper/helper.hxx"
26 #include "oox/token/namespaces.hxx"
27 #include "oox/token/tokens.hxx"
28 #include "oox/dllapi.h"
32 // ============================================================================
34 /** Static helpers for conversion of strings to attribute values of various
37 class OOX_DLLPUBLIC AttributeConversion
40 /** Returns the XML token identifier from the passed string. */
41 static sal_Int32
decodeToken( const OUString
& rValue
);
43 /** Returns the decoded string value. All characters in the format
44 '_xHHHH_' (H being a hexadecimal digit), will be decoded. */
45 static OUString
decodeXString( const OUString
& rValue
);
47 /** Returns the double value from the passed string. */
48 static double decodeDouble( const OUString
& rValue
);
50 /** Returns the 32-bit signed integer value from the passed string (decimal). */
51 static sal_Int32
decodeInteger( const OUString
& rValue
);
53 /** Returns the 32-bit unsigned integer value from the passed string (decimal). */
54 static sal_uInt32
decodeUnsigned( const OUString
& rValue
);
56 /** Returns the 64-bit signed integer value from the passed string (decimal). */
57 static sal_Int64
decodeHyper( const OUString
& rValue
);
59 /** Returns the 32-bit signed integer value from the passed string (hexadecimal). */
60 static sal_Int32
decodeIntegerHex( const OUString
& rValue
);
63 // ============================================================================
65 /** Provides access to attribute values of an element.
67 Wraps a com.sun.star.xml.sax.XFastAttributeList object. Provides
68 convenience functions that convert the string value of an attribute to
69 various other data types.
71 class OOX_DLLPUBLIC AttributeList
74 explicit AttributeList(
75 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XFastAttributeList
>& rxAttribs
);
77 /** Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object. */
78 inline ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XFastAttributeList
>
79 getFastAttributeList() const { return mxAttribs
; }
81 /** Returns true, if the specified attribute is present. */
82 bool hasAttribute( sal_Int32 nAttrToken
) const;
84 // optional return values -------------------------------------------------
86 /** Returns the token identifier of the value of the specified attribute. */
87 OptValue
< sal_Int32
> getToken( sal_Int32 nAttrToken
) const;
89 /** Returns the string value of the specified attribute. */
90 OptValue
< OUString
> getString( sal_Int32 nAttrToken
) const;
92 /** Returns the string value of the specified attribute. All characters in
93 the format '_xHHHH_' (H being a hexadecimal digit), will be decoded. */
94 OptValue
< OUString
> getXString( sal_Int32 nAttrToken
) const;
96 /** Returns the double value of the specified attribute. */
97 OptValue
< double > getDouble( sal_Int32 nAttrToken
) const;
99 /** Returns the 32-bit signed integer value of the specified attribute (decimal). */
100 OptValue
< sal_Int32
> getInteger( sal_Int32 nAttrToken
) const;
102 /** Returns the 32-bit unsigned integer value of the specified attribute (decimal). */
103 OptValue
< sal_uInt32
> getUnsigned( sal_Int32 nAttrToken
) const;
105 /** Returns the 64-bit signed integer value of the specified attribute (decimal). */
106 OptValue
< sal_Int64
> getHyper( sal_Int32 nAttrToken
) const;
108 /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal). */
109 OptValue
< sal_Int32
> getIntegerHex( sal_Int32 nAttrToken
) const;
111 /** Returns the boolean value of the specified attribute. */
112 OptValue
< bool > getBool( sal_Int32 nAttrToken
) const;
114 /** Returns the date/time value of the specified attribute. */
115 OptValue
< ::com::sun::star::util::DateTime
> getDateTime( sal_Int32 nAttrToken
) const;
117 // defaulted return values ------------------------------------------------
119 /** Returns the token identifier of the value of the specified attribute,
120 or the passed default identifier if the attribute is missing. */
121 sal_Int32
getToken( sal_Int32 nAttrToken
, sal_Int32 nDefault
) const;
123 /** Returns the string value of the specified attribute, or the passed
124 default string if the attribute is missing. */
125 OUString
getString( sal_Int32 nAttrToken
, const OUString
& rDefault
) const;
127 /** Returns the decoded string value of the specified attribute, or the
128 passed default string if the attribute is missing. */
129 OUString
getXString( sal_Int32 nAttrToken
, const OUString
& rDefault
) const;
131 /** Returns the double value of the specified attribute, or the passed
132 default value if the attribute is missing or not convertible to a double. */
133 double getDouble( sal_Int32 nAttrToken
, double fDefault
) const;
135 /** Returns the 32-bit signed integer value of the specified attribute, or the
136 passed default value if the attribute is missing or not convertible to integer. */
137 sal_Int32
getInteger( sal_Int32 nAttrToken
, sal_Int32 nDefault
) const;
139 /** Returns the 32-bit unsigned integer value of the specified attribute, or the
140 passed default value if the attribute is missing or not convertible to unsigned. */
141 sal_uInt32
getUnsigned( sal_Int32 nAttrToken
, sal_uInt32 nDefault
) const;
143 /** Returns the 64-bit signed integer value of the specified attribute, or the
144 passed default value if the attribute is missing or not convertible to integer. */
145 sal_Int64
getHyper( sal_Int32 nAttrToken
, sal_Int64 nDefault
) const;
147 /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal),
148 or the passed default value if the attribute is missing or not convertible. */
149 sal_Int32
getIntegerHex( sal_Int32 nAttrToken
, sal_Int32 nDefault
) const;
151 /** Returns the boolean value of the specified attribute, or the passed
152 default value if the attribute is missing or not convertible to bool. */
153 bool getBool( sal_Int32 nAttrToken
, bool bDefault
) const;
155 /** Returns the date/time value of the specified attribute, or the default
156 value if the attribute is missing or not convertible to a date/time value. */
157 ::com::sun::star::util::DateTime
getDateTime( sal_Int32 nAttrToken
, const ::com::sun::star::util::DateTime
& rDefault
) const;
160 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XFastAttributeList
>
164 // ============================================================================
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */