1*ecfe53c5SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ecfe53c5SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ecfe53c5SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ecfe53c5SAndrew Rist * distributed with this work for additional information 6*ecfe53c5SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ecfe53c5SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ecfe53c5SAndrew Rist * "License"); you may not use this file except in compliance 9*ecfe53c5SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*ecfe53c5SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*ecfe53c5SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ecfe53c5SAndrew Rist * software distributed under the License is distributed on an 15*ecfe53c5SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ecfe53c5SAndrew Rist * KIND, either express or implied. See the License for the 17*ecfe53c5SAndrew Rist * specific language governing permissions and limitations 18*ecfe53c5SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*ecfe53c5SAndrew Rist *************************************************************/ 21*ecfe53c5SAndrew Rist 22*ecfe53c5SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _XMLOFF_FORMS_PROPERTYIMPORT_HXX_ 25cdf0e10cSrcweir #define _XMLOFF_FORMS_PROPERTYIMPORT_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx> 28cdf0e10cSrcweir #include "formattributes.hxx" 29cdf0e10cSrcweir #include <vos/ref.hxx> 30cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 31cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 32cdf0e10cSrcweir #include "layerimport.hxx" 33cdf0e10cSrcweir 34cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace util { 35cdf0e10cSrcweir struct Time; 36cdf0e10cSrcweir struct Date; 37cdf0e10cSrcweir } } } } 38cdf0e10cSrcweir 39cdf0e10cSrcweir //......................................................................... 40cdf0e10cSrcweir namespace xmloff 41cdf0e10cSrcweir { 42cdf0e10cSrcweir //......................................................................... 43cdf0e10cSrcweir 44cdf0e10cSrcweir //===================================================================== 45cdf0e10cSrcweir //= PropertyConversion 46cdf0e10cSrcweir //===================================================================== 47cdf0e10cSrcweir class PropertyConversion 48cdf0e10cSrcweir { 49cdf0e10cSrcweir public: 50cdf0e10cSrcweir static ::com::sun::star::uno::Any convertString( 51cdf0e10cSrcweir SvXMLImport& _rImporter, 52cdf0e10cSrcweir const ::com::sun::star::uno::Type& _rExpectedType, 53cdf0e10cSrcweir const ::rtl::OUString& _rReadCharacters, 54cdf0e10cSrcweir const SvXMLEnumMapEntry* _pEnumMap = NULL, 55cdf0e10cSrcweir const sal_Bool _bInvertBoolean = sal_False 56cdf0e10cSrcweir ); 57cdf0e10cSrcweir 58cdf0e10cSrcweir static ::com::sun::star::uno::Type xmlTypeToUnoType( const ::rtl::OUString& _rType ); 59cdf0e10cSrcweir }; 60cdf0e10cSrcweir 61cdf0e10cSrcweir class OFormLayerXMLImport_Impl; 62cdf0e10cSrcweir //===================================================================== 63cdf0e10cSrcweir //= OPropertyImport 64cdf0e10cSrcweir //===================================================================== 65cdf0e10cSrcweir /** Helper class for importing property values 66cdf0e10cSrcweir 67cdf0e10cSrcweir <p>This class imports properties which are stored as attributes as well as properties which 68cdf0e10cSrcweir are stored in </em><form:properties></em> elements.</p> 69cdf0e10cSrcweir */ 70cdf0e10cSrcweir class OPropertyImport : public SvXMLImportContext 71cdf0e10cSrcweir { 72cdf0e10cSrcweir friend class OSinglePropertyContext; 73cdf0e10cSrcweir friend class OListPropertyContext; 74cdf0e10cSrcweir 75cdf0e10cSrcweir protected: 76cdf0e10cSrcweir typedef ::std::vector< ::com::sun::star::beans::PropertyValue > PropertyValueArray; 77cdf0e10cSrcweir PropertyValueArray m_aValues; 78cdf0e10cSrcweir PropertyValueArray m_aGenericValues; 79cdf0e10cSrcweir // the values which the instance collects between StartElement and EndElement 80cdf0e10cSrcweir 81cdf0e10cSrcweir DECLARE_STL_STDKEY_SET( ::rtl::OUString, StringSet ); 82cdf0e10cSrcweir StringSet m_aEncounteredAttributes; 83cdf0e10cSrcweir 84cdf0e10cSrcweir OFormLayerXMLImport_Impl& m_rContext; 85cdf0e10cSrcweir 86cdf0e10cSrcweir sal_Bool m_bTrackAttributes; 87cdf0e10cSrcweir 88cdf0e10cSrcweir // TODO: think about the restriction that the class does not know anything about the object it is importing. 89cdf0e10cSrcweir // Perhaps this object should be known to the class, so setting the properties ('normal' ones as well as 90cdf0e10cSrcweir // style properties) can be done in our own EndElement instead of letting derived classes do this. 91cdf0e10cSrcweir 92cdf0e10cSrcweir public: 93cdf0e10cSrcweir OPropertyImport(OFormLayerXMLImport_Impl& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName); 94cdf0e10cSrcweir 95cdf0e10cSrcweir virtual SvXMLImportContext* CreateChildContext( 96cdf0e10cSrcweir sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName, 97cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList); 98cdf0e10cSrcweir 99cdf0e10cSrcweir virtual void StartElement( 100cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList); 101cdf0e10cSrcweir virtual void Characters(const ::rtl::OUString& _rChars); 102cdf0e10cSrcweir 103cdf0e10cSrcweir protected: 104cdf0e10cSrcweir /** handle one single attribute. 105cdf0e10cSrcweir 106cdf0e10cSrcweir <p>This is called for every attribute of the element. This class' implementaion checks if the attribute 107cdf0e10cSrcweir describes a property, if so, it is added to <member>m_aValues</member>.</p> 108cdf0e10cSrcweir 109cdf0e10cSrcweir <p>All non-property attributes should be handled in derived classes.</p> 110cdf0e10cSrcweir 111cdf0e10cSrcweir @param _nNamespaceKey 112cdf0e10cSrcweir key of the namespace used in the attribute 113cdf0e10cSrcweir @param _rLocalName 114cdf0e10cSrcweir local (relative to the namespace) attribute name 115cdf0e10cSrcweir @param _rValue 116cdf0e10cSrcweir attribute value 117cdf0e10cSrcweir */ 118cdf0e10cSrcweir virtual bool handleAttribute(sal_uInt16 _nNamespaceKey, 119cdf0e10cSrcweir const ::rtl::OUString& _rLocalName, 120cdf0e10cSrcweir const ::rtl::OUString& _rValue); 121cdf0e10cSrcweir 122cdf0e10cSrcweir /** determine if the element imported by the object had an given attribute. 123cdf0e10cSrcweir <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace. 124cdf0e10cSrcweir All form relevant attributes are in the same namespace, so this would be an redundant information.</p> 125cdf0e10cSrcweir */ 126cdf0e10cSrcweir sal_Bool encounteredAttribute(const ::rtl::OUString& _rAttributeName) const; 127cdf0e10cSrcweir 128cdf0e10cSrcweir /** determine if the element imported by the object had an given attribute. 129cdf0e10cSrcweir <p>Please be aware of the fact that the name given must be a local name, i.e. not contain a namespace. 130cdf0e10cSrcweir All form relevant attributes are in the same namespace, so this would be an redundant information.</p> 131cdf0e10cSrcweir */ encounteredAttribute(const sal_Char * _pAttributeName) const132cdf0e10cSrcweir sal_Bool encounteredAttribute(const sal_Char* _pAttributeName) const { return encounteredAttribute(::rtl::OUString::createFromAscii(_pAttributeName)); } 133cdf0e10cSrcweir 134cdf0e10cSrcweir /** enables the tracking of the encountered attributes 135cdf0e10cSrcweir <p>The tracking will raise the import costs a little bit, but it's cheaper than 136cdf0e10cSrcweir derived classes tracking this themself.</p> 137cdf0e10cSrcweir */ enableTrackAttributes()138cdf0e10cSrcweir void enableTrackAttributes() { m_bTrackAttributes = sal_True; } 139cdf0e10cSrcweir implPushBackPropertyValue(const::com::sun::star::beans::PropertyValue & _rProp)140cdf0e10cSrcweir inline void implPushBackPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir m_aValues.push_back(_rProp); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir implPushBackPropertyValue(const::rtl::OUString & _rName,const::com::sun::star::uno::Any & _rValue)145cdf0e10cSrcweir inline void implPushBackPropertyValue( const ::rtl::OUString& _rName, const ::com::sun::star::uno::Any& _rValue ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir m_aValues.push_back( ::com::sun::star::beans::PropertyValue( 148cdf0e10cSrcweir _rName, -1, _rValue, ::com::sun::star::beans::PropertyState_DIRECT_VALUE ) ); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir implPushBackGenericPropertyValue(const::com::sun::star::beans::PropertyValue & _rProp)151cdf0e10cSrcweir inline void implPushBackGenericPropertyValue(const ::com::sun::star::beans::PropertyValue& _rProp) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir m_aGenericValues.push_back(_rProp); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir }; 156cdf0e10cSrcweir SV_DECL_IMPL_REF( OPropertyImport ) 157cdf0e10cSrcweir 158cdf0e10cSrcweir //===================================================================== 159cdf0e10cSrcweir //= OPropertyElementsContext 160cdf0e10cSrcweir //===================================================================== 161cdf0e10cSrcweir /** helper class for importing the <form:properties> element 162cdf0e10cSrcweir */ 163cdf0e10cSrcweir class OPropertyElementsContext : public SvXMLImportContext 164cdf0e10cSrcweir { 165cdf0e10cSrcweir protected: 166cdf0e10cSrcweir OPropertyImportRef m_xPropertyImporter; // to add the properties 167cdf0e10cSrcweir 168cdf0e10cSrcweir public: 169cdf0e10cSrcweir OPropertyElementsContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName, 170cdf0e10cSrcweir const OPropertyImportRef& _rPropertyImporter); 171cdf0e10cSrcweir 172cdf0e10cSrcweir virtual SvXMLImportContext* CreateChildContext( 173cdf0e10cSrcweir sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName, 174cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList); 175cdf0e10cSrcweir 176cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 177cdf0e10cSrcweir virtual void StartElement( 178cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList); 179cdf0e10cSrcweir virtual void Characters(const ::rtl::OUString& _rChars); 180cdf0e10cSrcweir #endif 181cdf0e10cSrcweir }; 182cdf0e10cSrcweir 183cdf0e10cSrcweir //===================================================================== 184cdf0e10cSrcweir //= OSinglePropertyContext 185cdf0e10cSrcweir //===================================================================== 186cdf0e10cSrcweir /** helper class for importing a single <form:property> element 187cdf0e10cSrcweir */ 188cdf0e10cSrcweir class OSinglePropertyContext : public SvXMLImportContext 189cdf0e10cSrcweir { 190cdf0e10cSrcweir OPropertyImportRef m_xPropertyImporter; // to add the properties 191cdf0e10cSrcweir 192cdf0e10cSrcweir public: 193cdf0e10cSrcweir OSinglePropertyContext(SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName, 194cdf0e10cSrcweir const OPropertyImportRef& _rPropertyImporter); 195cdf0e10cSrcweir 196cdf0e10cSrcweir virtual SvXMLImportContext* CreateChildContext( 197cdf0e10cSrcweir sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName, 198cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList); 199cdf0e10cSrcweir 200cdf0e10cSrcweir virtual void StartElement( 201cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList); 202cdf0e10cSrcweir }; 203cdf0e10cSrcweir 204cdf0e10cSrcweir //===================================================================== 205cdf0e10cSrcweir //= OListPropertyContext 206cdf0e10cSrcweir //===================================================================== 207cdf0e10cSrcweir class OListPropertyContext : public SvXMLImportContext 208cdf0e10cSrcweir { 209cdf0e10cSrcweir OPropertyImportRef m_xPropertyImporter; 210cdf0e10cSrcweir ::rtl::OUString m_sPropertyName; 211cdf0e10cSrcweir ::rtl::OUString m_sPropertyType; 212cdf0e10cSrcweir ::std::vector< ::rtl::OUString > m_aListValues; 213cdf0e10cSrcweir 214cdf0e10cSrcweir public: 215cdf0e10cSrcweir OListPropertyContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName, 216cdf0e10cSrcweir const OPropertyImportRef& _rPropertyImporter ); 217cdf0e10cSrcweir 218cdf0e10cSrcweir virtual void StartElement( 219cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList ); 220cdf0e10cSrcweir 221cdf0e10cSrcweir virtual void EndElement(); 222cdf0e10cSrcweir 223cdf0e10cSrcweir virtual SvXMLImportContext* CreateChildContext( 224cdf0e10cSrcweir sal_uInt16 _nPrefix, const ::rtl::OUString& _rLocalName, 225cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList); 226cdf0e10cSrcweir }; 227cdf0e10cSrcweir 228cdf0e10cSrcweir //===================================================================== 229cdf0e10cSrcweir //= OListValueContext 230cdf0e10cSrcweir //===================================================================== 231cdf0e10cSrcweir class OListValueContext : public SvXMLImportContext 232cdf0e10cSrcweir { 233cdf0e10cSrcweir ::rtl::OUString& m_rListValueHolder; 234cdf0e10cSrcweir 235cdf0e10cSrcweir public: 236cdf0e10cSrcweir OListValueContext( SvXMLImport& _rImport, sal_uInt16 _nPrefix, const ::rtl::OUString& _rName, 237cdf0e10cSrcweir ::rtl::OUString& _rListValueHolder ); 238cdf0e10cSrcweir 239cdf0e10cSrcweir virtual void StartElement( 240cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& _rxAttrList ); 241cdf0e10cSrcweir }; 242cdf0e10cSrcweir 243cdf0e10cSrcweir //......................................................................... 244cdf0e10cSrcweir } // namespace xmloff 245cdf0e10cSrcweir //......................................................................... 246cdf0e10cSrcweir 247cdf0e10cSrcweir #endif // _XMLOFF_FORMS_PROPERTYIMPORT_HXX_ 248cdf0e10cSrcweir 249cdf0e10cSrcweir 250