1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef OOX_HELPER_ATTRIBUTELIST_HXX 25 #define OOX_HELPER_ATTRIBUTELIST_HXX 26 27 #include <com/sun/star/util/DateTime.hpp> 28 #include <com/sun/star/xml/sax/XFastAttributeList.hpp> 29 #include "oox/helper/helper.hxx" 30 #include "oox/token/namespaces.hxx" 31 #include "oox/token/tokens.hxx" 32 33 namespace oox { 34 35 // ============================================================================ 36 37 /** Static helpers for conversion of strings to attribute values of various 38 different data types. 39 */ 40 class AttributeConversion 41 { 42 public: 43 /** Returns the XML token identifier from the passed string. */ 44 static sal_Int32 decodeToken( const ::rtl::OUString& rValue ); 45 46 /** Returns the decoded string value. All characters in the format 47 '_xHHHH_' (H being a hexadecimal digit), will be decoded. */ 48 static ::rtl::OUString decodeXString( const ::rtl::OUString& rValue ); 49 50 /** Returns the double value from the passed string. */ 51 static double decodeDouble( const ::rtl::OUString& rValue ); 52 53 /** Returns the 32-bit signed integer value from the passed string (decimal). */ 54 static sal_Int32 decodeInteger( const ::rtl::OUString& rValue ); 55 56 /** Returns the 32-bit unsigned integer value from the passed string (decimal). */ 57 static sal_uInt32 decodeUnsigned( const ::rtl::OUString& rValue ); 58 59 /** Returns the 64-bit signed integer value from the passed string (decimal). */ 60 static sal_Int64 decodeHyper( const ::rtl::OUString& rValue ); 61 62 /** Returns the 32-bit signed integer value from the passed string (hexadecimal). */ 63 static sal_Int32 decodeIntegerHex( const ::rtl::OUString& rValue ); 64 65 /** Returns the 32-bit unsigned integer value from the passed string (hexadecimal). */ 66 static sal_uInt32 decodeUnsignedHex( const ::rtl::OUString& rValue ); 67 68 /** Returns the 64-bit signed integer value from the passed string (hexadecimal). */ 69 static sal_Int64 decodeHyperHex( const ::rtl::OUString& rValue ); 70 }; 71 72 // ============================================================================ 73 74 /** Provides access to attribute values of an element. 75 76 Wraps a com.sun.star.xml.sax.XFastAttributeList object. Provides 77 convenience functions that convert the string value of an attribute to 78 various other data types. 79 */ 80 class AttributeList 81 { 82 public: 83 explicit AttributeList( 84 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& rxAttribs ); 85 86 /** Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object. */ 87 inline ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList > getFastAttributeList() const88 getFastAttributeList() const { return mxAttribs; } 89 90 /** Returns true, if the specified attribute is present. */ 91 bool hasAttribute( sal_Int32 nAttrToken ) const; 92 93 // optional return values ------------------------------------------------- 94 95 /** Returns the token identifier of the value of the specified attribute. */ 96 OptValue< sal_Int32 > getToken( sal_Int32 nAttrToken ) const; 97 98 /** Returns the string value of the specified attribute. */ 99 OptValue< ::rtl::OUString > getString( sal_Int32 nAttrToken ) const; 100 101 /** Returns the string value of the specified attribute. All characters in 102 the format '_xHHHH_' (H being a hexadecimal digit), will be decoded. */ 103 OptValue< ::rtl::OUString > getXString( sal_Int32 nAttrToken ) const; 104 105 /** Returns the double value of the specified attribute. */ 106 OptValue< double > getDouble( sal_Int32 nAttrToken ) const; 107 108 /** Returns the 32-bit signed integer value of the specified attribute (decimal). */ 109 OptValue< sal_Int32 > getInteger( sal_Int32 nAttrToken ) const; 110 111 /** Returns the 32-bit unsigned integer value of the specified attribute (decimal). */ 112 OptValue< sal_uInt32 > getUnsigned( sal_Int32 nAttrToken ) const; 113 114 /** Returns the 64-bit signed integer value of the specified attribute (decimal). */ 115 OptValue< sal_Int64 > getHyper( sal_Int32 nAttrToken ) const; 116 117 /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal). */ 118 OptValue< sal_Int32 > getIntegerHex( sal_Int32 nAttrToken ) const; 119 120 /** Returns the 32-bit unsigned integer value of the specified attribute (hexadecimal). */ 121 OptValue< sal_uInt32 > getUnsignedHex( sal_Int32 nAttrToken ) const; 122 123 /** Returns the 64-bit signed integer value of the specified attribute (hexadecimal). */ 124 OptValue< sal_Int64 > getHyperHex( sal_Int32 nAttrToken ) const; 125 126 /** Returns the boolean value of the specified attribute. */ 127 OptValue< bool > getBool( sal_Int32 nAttrToken ) const; 128 129 /** Returns the date/time value of the specified attribute. */ 130 OptValue< ::com::sun::star::util::DateTime > getDateTime( sal_Int32 nAttrToken ) const; 131 132 // defaulted return values ------------------------------------------------ 133 134 /** Returns the token identifier of the value of the specified attribute, 135 or the passed default identifier if the attribute is missing. */ 136 sal_Int32 getToken( sal_Int32 nAttrToken, sal_Int32 nDefault ) const; 137 138 /** Returns the string value of the specified attribute, or the passed 139 default string if the attribute is missing. */ 140 ::rtl::OUString getString( sal_Int32 nAttrToken, const ::rtl::OUString& rDefault ) const; 141 142 /** Returns the decoded string value of the specified attribute, or the 143 passed default string if the attribute is missing. */ 144 ::rtl::OUString getXString( sal_Int32 nAttrToken, const ::rtl::OUString& rDefault ) const; 145 146 /** Returns the double value of the specified attribute, or the passed 147 default value if the attribute is missing or not convertible to a double. */ 148 double getDouble( sal_Int32 nAttrToken, double fDefault ) const; 149 150 /** Returns the 32-bit signed integer value of the specified attribute, or the 151 passed default value if the attribute is missing or not convertible to integer. */ 152 sal_Int32 getInteger( sal_Int32 nAttrToken, sal_Int32 nDefault ) const; 153 154 /** Returns the 32-bit unsigned integer value of the specified attribute, or the 155 passed default value if the attribute is missing or not convertible to unsigned. */ 156 sal_uInt32 getUnsigned( sal_Int32 nAttrToken, sal_uInt32 nDefault ) const; 157 158 /** Returns the 64-bit signed integer value of the specified attribute, or the 159 passed default value if the attribute is missing or not convertible to integer. */ 160 sal_Int64 getHyper( sal_Int32 nAttrToken, sal_Int64 nDefault ) const; 161 162 /** Returns the 32-bit signed integer value of the specified attribute (hexadecimal), 163 or the passed default value if the attribute is missing or not convertible. */ 164 sal_Int32 getIntegerHex( sal_Int32 nAttrToken, sal_Int32 nDefault ) const; 165 166 /** Returns the 32-bit unsigned integer value of the specified attribute (hexadecimal), 167 or the passed default value if the attribute is missing or not convertible. */ 168 sal_uInt32 getUnsignedHex( sal_Int32 nAttrToken, sal_uInt32 nDefault ) const; 169 170 /** Returns the 64-bit signed integer value of the specified attribute (hexadecimal), 171 or the passed default value if the attribute is missing or not convertible. */ 172 sal_Int64 getHyperHex( sal_Int32 nAttrToken, sal_Int64 nDefault ) const; 173 174 /** Returns the boolean value of the specified attribute, or the passed 175 default value if the attribute is missing or not convertible to bool. */ 176 bool getBool( sal_Int32 nAttrToken, bool bDefault ) const; 177 178 /** Returns the date/time value of the specified attribute, or the default 179 value if the attribute is missing or not convertible to a date/time value. */ 180 ::com::sun::star::util::DateTime getDateTime( sal_Int32 nAttrToken, const ::com::sun::star::util::DateTime& rDefault ) const; 181 182 private: 183 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList > 184 mxAttribs; 185 }; 186 187 // ============================================================================ 188 189 } // namespace oox 190 191 #endif 192